clang API Documentation
00001 //===-- GlobalSelector.cpp - Cross-translation-unit "token" for selectors -===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // GlobalSelector is a ASTContext-independent way to refer to selectors. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "clang/Index/GlobalSelector.h" 00015 #include "ProgramImpl.h" 00016 #include "clang/Index/Program.h" 00017 #include "clang/AST/ASTContext.h" 00018 using namespace clang; 00019 using namespace idx; 00020 00021 /// \brief Get the ASTContext-specific selector. 00022 Selector GlobalSelector::getSelector(ASTContext &AST) const { 00023 if (isInvalid()) 00024 return Selector(); 00025 00026 Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val)); 00027 00028 SmallVector<IdentifierInfo *, 8> Ids; 00029 for (unsigned i = 0, e = GlobSel.isUnarySelector() ? 1 : GlobSel.getNumArgs(); 00030 i != e; ++i) { 00031 IdentifierInfo *GlobII = GlobSel.getIdentifierInfoForSlot(i); 00032 IdentifierInfo *II = &AST.Idents.get(GlobII->getName()); 00033 Ids.push_back(II); 00034 } 00035 00036 return AST.Selectors.getSelector(GlobSel.getNumArgs(), Ids.data()); 00037 } 00038 00039 /// \brief Get a printable name for debugging purpose. 00040 std::string GlobalSelector::getPrintableName() const { 00041 if (isInvalid()) 00042 return "<< Invalid >>"; 00043 00044 Selector GlobSel = Selector(reinterpret_cast<uintptr_t>(Val)); 00045 return GlobSel.getAsString(); 00046 } 00047 00048 /// \brief Get a GlobalSelector for the ASTContext-specific selector. 00049 GlobalSelector GlobalSelector::get(Selector Sel, Program &Prog) { 00050 if (Sel.isNull()) 00051 return GlobalSelector(); 00052 00053 ProgramImpl &ProgImpl = *static_cast<ProgramImpl*>(Prog.Impl); 00054 00055 SmallVector<IdentifierInfo *, 8> Ids; 00056 for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs(); 00057 i != e; ++i) { 00058 IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i); 00059 IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName()); 00060 Ids.push_back(GlobII); 00061 } 00062 00063 Selector GlobSel = ProgImpl.getSelectors().getSelector(Sel.getNumArgs(), 00064 Ids.data()); 00065 return GlobalSelector(GlobSel.getAsOpaquePtr()); 00066 } 00067 00068 unsigned 00069 llvm::DenseMapInfo<GlobalSelector>::getHashValue(GlobalSelector Sel) { 00070 return DenseMapInfo<void*>::getHashValue(Sel.getAsOpaquePtr()); 00071 }