2009-07-30 07:40:32 +08:00
|
|
|
//===-- GlobalSelector.cpp - Cross-translation-unit "token" for selectors -===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// GlobalSelector is a ASTContext-independent way to refer to selectors.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Index/GlobalSelector.h"
|
|
|
|
#include "ProgramImpl.h"
|
|
|
|
#include "clang/Index/Program.h"
|
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
using namespace clang;
|
|
|
|
using namespace idx;
|
|
|
|
|
|
|
|
/// \brief Get the ASTContext-specific selector.
|
|
|
|
Selector GlobalSelector::getSelector(ASTContext &AST) const {
|
|
|
|
if (isInvalid())
|
|
|
|
return Selector();
|
|
|
|
|
|
|
|
Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val));
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<IdentifierInfo *, 8> Ids;
|
2009-07-30 07:40:32 +08:00
|
|
|
for (unsigned i = 0, e = GlobSel.isUnarySelector() ? 1 : GlobSel.getNumArgs();
|
|
|
|
i != e; ++i) {
|
|
|
|
IdentifierInfo *GlobII = GlobSel.getIdentifierInfoForSlot(i);
|
2010-03-12 17:33:31 +08:00
|
|
|
IdentifierInfo *II = &AST.Idents.get(GlobII->getName());
|
2009-07-30 07:40:32 +08:00
|
|
|
Ids.push_back(II);
|
|
|
|
}
|
|
|
|
|
2009-07-30 11:42:08 +08:00
|
|
|
return AST.Selectors.getSelector(GlobSel.getNumArgs(), Ids.data());
|
2009-07-30 07:40:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Get a printable name for debugging purpose.
|
|
|
|
std::string GlobalSelector::getPrintableName() const {
|
|
|
|
if (isInvalid())
|
|
|
|
return "<< Invalid >>";
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-07-30 07:40:32 +08:00
|
|
|
Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val));
|
|
|
|
return GlobSel.getAsString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Get a GlobalSelector for the ASTContext-specific selector.
|
|
|
|
GlobalSelector GlobalSelector::get(Selector Sel, Program &Prog) {
|
|
|
|
if (Sel.isNull())
|
|
|
|
return GlobalSelector();
|
|
|
|
|
|
|
|
ProgramImpl &ProgImpl = *static_cast<ProgramImpl*>(Prog.Impl);
|
|
|
|
|
2011-07-23 18:55:15 +08:00
|
|
|
SmallVector<IdentifierInfo *, 8> Ids;
|
2009-07-30 07:40:32 +08:00
|
|
|
for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs();
|
|
|
|
i != e; ++i) {
|
|
|
|
IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i);
|
2010-03-12 17:33:31 +08:00
|
|
|
IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName());
|
2009-07-30 07:40:32 +08:00
|
|
|
Ids.push_back(GlobII);
|
|
|
|
}
|
|
|
|
|
2009-07-30 11:42:08 +08:00
|
|
|
Selector GlobSel = ProgImpl.getSelectors().getSelector(Sel.getNumArgs(),
|
|
|
|
Ids.data());
|
2009-07-30 07:40:32 +08:00
|
|
|
return GlobalSelector(GlobSel.getAsOpaquePtr());
|
|
|
|
}
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
unsigned
|
2009-07-30 07:40:32 +08:00
|
|
|
llvm::DenseMapInfo<GlobalSelector>::getHashValue(GlobalSelector Sel) {
|
|
|
|
return DenseMapInfo<void*>::getHashValue(Sel.getAsOpaquePtr());
|
|
|
|
}
|