diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:40:32 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2009-07-29 23:40:32 +0000 |
commit | d219a9a763a6e4fd3317f5bef2a09828a1d0af97 (patch) | |
tree | d08a0cf9ccd1a76eac2f5ea9f7f64d5942874529 /clang/lib/Index/GlobalSelector.cpp | |
parent | ca8a0e24cb8edd0c5567dc9a984c1033a4bc9d09 (diff) | |
download | bcm5719-llvm-d219a9a763a6e4fd3317f5bef2a09828a1d0af97.tar.gz bcm5719-llvm-d219a9a763a6e4fd3317f5bef2a09828a1d0af97.zip |
Introduce the GlobalSelector class in the Indexing library.
GlobalSelector is an ASTContext-independent way to refer to Objective C selectors.
llvm-svn: 77538
Diffstat (limited to 'clang/lib/Index/GlobalSelector.cpp')
-rw-r--r-- | clang/lib/Index/GlobalSelector.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/clang/lib/Index/GlobalSelector.cpp b/clang/lib/Index/GlobalSelector.cpp new file mode 100644 index 00000000000..9b18741427a --- /dev/null +++ b/clang/lib/Index/GlobalSelector.cpp @@ -0,0 +1,72 @@ +//===-- 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)); + + llvm::SmallVector<IdentifierInfo *, 8> Ids; + for (unsigned i = 0, e = GlobSel.isUnarySelector() ? 1 : GlobSel.getNumArgs(); + i != e; ++i) { + IdentifierInfo *GlobII = GlobSel.getIdentifierInfoForSlot(i); + IdentifierInfo *II = &AST.Idents.get(GlobII->getName(), + GlobII->getName() + GlobII->getLength()); + Ids.push_back(II); + } + + return AST.Selectors.getSelector(Ids.size(), Ids.data()); +} + +/// \brief Get a printable name for debugging purpose. +std::string GlobalSelector::getPrintableName() const { + if (isInvalid()) + return "<< Invalid >>"; + + 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); + + llvm::SmallVector<IdentifierInfo *, 8> Ids; + for (unsigned i = 0, e = Sel.isUnarySelector() ? 1 : Sel.getNumArgs(); + i != e; ++i) { + IdentifierInfo *II = Sel.getIdentifierInfoForSlot(i); + IdentifierInfo *GlobII = &ProgImpl.getIdents().get(II->getName(), + II->getName() + II->getLength()); + Ids.push_back(GlobII); + } + + Selector GlobSel = ProgImpl.getSelectors().getSelector(Ids.size(),Ids.data()); + return GlobalSelector(GlobSel.getAsOpaquePtr()); +} + +unsigned +llvm::DenseMapInfo<GlobalSelector>::getHashValue(GlobalSelector Sel) { + return DenseMapInfo<void*>::getHashValue(Sel.getAsOpaquePtr()); +} |