From 4c8b24812ddcd1dedaca343a6d4e76f91f398981 Mon Sep 17 00:00:00 2001 From: Roman Divacky Date: Wed, 14 Oct 2009 18:03:49 +0000 Subject: Update clang to r84119. --- lib/Index/GlobalSelector.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/Index/GlobalSelector.cpp (limited to 'lib/Index/GlobalSelector.cpp') diff --git a/lib/Index/GlobalSelector.cpp b/lib/Index/GlobalSelector.cpp new file mode 100644 index 0000000000000..f3ec41d44ffeb --- /dev/null +++ b/lib/Index/GlobalSelector.cpp @@ -0,0 +1,73 @@ +//===-- 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(Val)); + + llvm::SmallVector 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(GlobSel.getNumArgs(), Ids.data()); +} + +/// \brief Get a printable name for debugging purpose. +std::string GlobalSelector::getPrintableName() const { + if (isInvalid()) + return "<< Invalid >>"; + + Selector GlobSel = Selector(reinterpret_cast(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(Prog.Impl); + + llvm::SmallVector 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(Sel.getNumArgs(), + Ids.data()); + return GlobalSelector(GlobSel.getAsOpaquePtr()); +} + +unsigned +llvm::DenseMapInfo::getHashValue(GlobalSelector Sel) { + return DenseMapInfo::getHashValue(Sel.getAsOpaquePtr()); +} -- cgit v1.2.3