1 //===-- GlobalSelector.cpp - Cross-translation-unit "token" for selectors -===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // GlobalSelector is a ASTContext-independent way to refer to selectors.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Index/GlobalSelector.h"
15 #include "ProgramImpl.h"
16 #include "clang/Index/Program.h"
17 #include "clang/AST/ASTContext.h"
18 using namespace clang;
21 /// \brief Get the ASTContext-specific selector.
22 Selector GlobalSelector::getSelector(ASTContext &AST) const {
26 Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val));
28 SmallVector<IdentifierInfo *, 8> Ids;
29 for (unsigned i = 0, e = GlobSel.isUnarySelector() ? 1 : GlobSel.getNumArgs();
31 IdentifierInfo *GlobII = GlobSel.getIdentifierInfoForSlot(i);
32 IdentifierInfo *II = &AST.Idents.get(GlobII->getName());
36 return AST.Selectors.getSelector(GlobSel.getNumArgs(), Ids.data());
39 /// \brief Get a printable name for debugging purpose.
40 std::string GlobalSelector::getPrintableName() const {
42 return "<< Invalid >>";
44 Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val));
45 return GlobSel.getAsString();
48 /// \brief Get a GlobalSelector for the ASTContext-specific selector.
49 GlobalSelector GlobalSelector::get(Selector Sel, Program &Prog) {
51 return GlobalSelector();
53 ProgramImpl &ProgImpl = *static_cast<ProgramImpl*>(Prog.Impl);
55 SmallVector<IdentifierInfo *, 8> Ids;
56 for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs();
58 IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i);
59 IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName());
60 Ids.push_back(GlobII);
63 Selector GlobSel = ProgImpl.getSelectors().getSelector(Sel.getNumArgs(),
65 return GlobalSelector(GlobSel.getAsOpaquePtr());
69 llvm::DenseMapInfo<GlobalSelector>::getHashValue(GlobalSelector Sel) {
70 return DenseMapInfo<void*>::getHashValue(Sel.getAsOpaquePtr());