2013-08-17 02:17:55 +08:00
|
|
|
//===- USRGeneration.cpp - Routines for USR generation --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-17 08:40:41 +08:00
|
|
|
#include "clang/Index/USRGeneration.h"
|
2013-08-17 02:17:55 +08:00
|
|
|
#include "clang/AST/ASTContext.h"
|
|
|
|
#include "clang/AST/DeclTemplate.h"
|
|
|
|
#include "clang/AST/DeclVisitor.h"
|
2014-03-29 06:21:26 +08:00
|
|
|
#include "clang/Lex/PreprocessingRecord.h"
|
2013-08-17 02:17:55 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace clang;
|
2013-08-21 08:49:25 +08:00
|
|
|
using namespace clang::index;
|
2013-08-17 02:17:55 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// USR generation.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-03-29 06:21:26 +08:00
|
|
|
/// \returns true on error.
|
|
|
|
static bool printLoc(llvm::raw_ostream &OS, SourceLocation Loc,
|
|
|
|
const SourceManager &SM, bool IncludeOffset) {
|
|
|
|
if (Loc.isInvalid()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Loc = SM.getExpansionLoc(Loc);
|
|
|
|
const std::pair<FileID, unsigned> &Decomposed = SM.getDecomposedLoc(Loc);
|
|
|
|
const FileEntry *FE = SM.getFileEntryForID(Decomposed.first);
|
|
|
|
if (FE) {
|
|
|
|
OS << llvm::sys::path::filename(FE->getName());
|
|
|
|
} else {
|
|
|
|
// This case really isn't interesting.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (IncludeOffset) {
|
|
|
|
// Use the offest into the FileID to represent the location. Using
|
|
|
|
// a line/column can cause us to look back at the original source file,
|
|
|
|
// which is expensive.
|
|
|
|
OS << '@' << Decomposed.second;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
namespace {
|
|
|
|
class USRGenerator : public ConstDeclVisitor<USRGenerator> {
|
|
|
|
SmallVectorImpl<char> &Buf;
|
|
|
|
llvm::raw_svector_ostream Out;
|
|
|
|
bool IgnoreResults;
|
|
|
|
ASTContext *Context;
|
|
|
|
bool generatedLoc;
|
|
|
|
|
|
|
|
llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit USRGenerator(ASTContext *Ctx, SmallVectorImpl<char> &Buf)
|
|
|
|
: Buf(Buf),
|
|
|
|
Out(Buf),
|
|
|
|
IgnoreResults(false),
|
|
|
|
Context(Ctx),
|
|
|
|
generatedLoc(false)
|
|
|
|
{
|
|
|
|
// Add the USR space prefix.
|
2013-08-21 08:49:25 +08:00
|
|
|
Out << getUSRSpacePrefix();
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ignoreResults() const { return IgnoreResults; }
|
|
|
|
|
|
|
|
// Visitation methods from generating USRs from AST elements.
|
|
|
|
void VisitDeclContext(const DeclContext *D);
|
|
|
|
void VisitFieldDecl(const FieldDecl *D);
|
|
|
|
void VisitFunctionDecl(const FunctionDecl *D);
|
|
|
|
void VisitNamedDecl(const NamedDecl *D);
|
|
|
|
void VisitNamespaceDecl(const NamespaceDecl *D);
|
|
|
|
void VisitNamespaceAliasDecl(const NamespaceAliasDecl *D);
|
|
|
|
void VisitFunctionTemplateDecl(const FunctionTemplateDecl *D);
|
|
|
|
void VisitClassTemplateDecl(const ClassTemplateDecl *D);
|
|
|
|
void VisitObjCContainerDecl(const ObjCContainerDecl *CD);
|
|
|
|
void VisitObjCMethodDecl(const ObjCMethodDecl *MD);
|
|
|
|
void VisitObjCPropertyDecl(const ObjCPropertyDecl *D);
|
|
|
|
void VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D);
|
|
|
|
void VisitTagDecl(const TagDecl *D);
|
|
|
|
void VisitTypedefDecl(const TypedefDecl *D);
|
|
|
|
void VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D);
|
|
|
|
void VisitVarDecl(const VarDecl *D);
|
|
|
|
void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D);
|
|
|
|
void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D);
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
void VisitLinkageSpecDecl(const LinkageSpecDecl *D) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
void VisitUsingDirectiveDecl(const UsingDirectiveDecl *D) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
void VisitUsingDecl(const UsingDecl *D) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
2014-02-24 02:23:29 +08:00
|
|
|
|
|
|
|
bool ShouldGenerateLocation(const NamedDecl *D);
|
|
|
|
|
|
|
|
bool isLocal(const NamedDecl *D) {
|
2014-05-26 14:21:51 +08:00
|
|
|
return D->getParentFunctionOrMethod() != nullptr;
|
2014-02-24 02:23:29 +08:00
|
|
|
}
|
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
/// Generate the string component containing the location of the
|
|
|
|
/// declaration.
|
2014-02-24 02:23:29 +08:00
|
|
|
bool GenLoc(const Decl *D, bool IncludeOffset);
|
2013-08-17 02:17:55 +08:00
|
|
|
|
|
|
|
/// String generation methods used both by the visitation methods
|
|
|
|
/// and from other clients that want to directly generate USRs. These
|
|
|
|
/// methods do not construct complete USRs (which incorporate the parents
|
|
|
|
/// of an AST element), but only the fragments concerning the AST element
|
|
|
|
/// itself.
|
|
|
|
|
|
|
|
/// Generate a USR for an Objective-C class.
|
|
|
|
void GenObjCClass(StringRef cls) {
|
2013-08-21 08:49:25 +08:00
|
|
|
generateUSRForObjCClass(cls, Out);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
/// Generate a USR for an Objective-C class category.
|
|
|
|
void GenObjCCategory(StringRef cls, StringRef cat) {
|
2013-08-21 08:49:25 +08:00
|
|
|
generateUSRForObjCCategory(cls, cat, Out);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
/// Generate a USR fragment for an Objective-C property.
|
2016-07-16 06:18:19 +08:00
|
|
|
void GenObjCProperty(StringRef prop, bool isClassProp) {
|
|
|
|
generateUSRForObjCProperty(prop, isClassProp, Out);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
2016-02-13 06:53:10 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
/// Generate a USR for an Objective-C protocol.
|
|
|
|
void GenObjCProtocol(StringRef prot) {
|
2013-08-21 08:49:25 +08:00
|
|
|
generateUSRForObjCProtocol(prot, Out);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void VisitType(QualType T);
|
|
|
|
void VisitTemplateParameterList(const TemplateParameterList *Params);
|
|
|
|
void VisitTemplateName(TemplateName Name);
|
|
|
|
void VisitTemplateArgument(const TemplateArgument &Arg);
|
|
|
|
|
|
|
|
/// Emit a Decl's name using NamedDecl::printName() and return true if
|
|
|
|
/// the decl had no name.
|
|
|
|
bool EmitDeclName(const NamedDecl *D);
|
|
|
|
};
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// Generating USRs from ASTS.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
bool USRGenerator::EmitDeclName(const NamedDecl *D) {
|
|
|
|
const unsigned startSize = Buf.size();
|
|
|
|
D->printName(Out);
|
|
|
|
const unsigned endSize = Buf.size();
|
|
|
|
return startSize == endSize;
|
|
|
|
}
|
|
|
|
|
2014-02-24 02:23:29 +08:00
|
|
|
bool USRGenerator::ShouldGenerateLocation(const NamedDecl *D) {
|
|
|
|
if (D->isExternallyVisible())
|
|
|
|
return false;
|
|
|
|
if (D->getParentFunctionOrMethod())
|
|
|
|
return true;
|
|
|
|
const SourceManager &SM = Context->getSourceManager();
|
|
|
|
return !SM.isInSystemHeader(D->getLocation());
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitDeclContext(const DeclContext *DC) {
|
|
|
|
if (const NamedDecl *D = dyn_cast<NamedDecl>(DC))
|
|
|
|
Visit(D);
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitFieldDecl(const FieldDecl *D) {
|
|
|
|
// The USR for an ivar declared in a class extension is based on the
|
|
|
|
// ObjCInterfaceDecl, not the ObjCCategoryDecl.
|
|
|
|
if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
|
|
|
|
Visit(ID);
|
|
|
|
else
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
|
|
|
Out << (isa<ObjCIvarDecl>(D) ? "@" : "@FI@");
|
|
|
|
if (EmitDeclName(D)) {
|
|
|
|
// Bit fields can be anonymous.
|
|
|
|
IgnoreResults = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) {
|
2014-02-24 02:23:29 +08:00
|
|
|
if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
|
2013-08-17 02:17:55 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
2014-12-08 16:48:11 +08:00
|
|
|
bool IsTemplate = false;
|
2013-08-17 02:17:55 +08:00
|
|
|
if (FunctionTemplateDecl *FunTmpl = D->getDescribedFunctionTemplate()) {
|
2014-12-08 16:48:11 +08:00
|
|
|
IsTemplate = true;
|
2013-08-17 02:17:55 +08:00
|
|
|
Out << "@FT@";
|
|
|
|
VisitTemplateParameterList(FunTmpl->getTemplateParameters());
|
|
|
|
} else
|
|
|
|
Out << "@F@";
|
2016-02-15 09:32:36 +08:00
|
|
|
|
|
|
|
PrintingPolicy Policy(Context->getLangOpts());
|
|
|
|
// Forward references can have different template argument names. Suppress the
|
|
|
|
// template argument names in constructors to make their USR more stable.
|
|
|
|
Policy.SuppressTemplateArgsInCXXConstructors = true;
|
|
|
|
D->getDeclName().print(Out, Policy);
|
2013-08-17 02:17:55 +08:00
|
|
|
|
|
|
|
ASTContext &Ctx = *Context;
|
2016-03-04 15:17:48 +08:00
|
|
|
if ((!Ctx.getLangOpts().CPlusPlus || D->isExternC()) &&
|
|
|
|
!D->hasAttr<OverloadableAttr>())
|
2013-08-17 02:17:55 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (const TemplateArgumentList *
|
|
|
|
SpecArgs = D->getTemplateSpecializationArgs()) {
|
|
|
|
Out << '<';
|
|
|
|
for (unsigned I = 0, N = SpecArgs->size(); I != N; ++I) {
|
|
|
|
Out << '#';
|
|
|
|
VisitTemplateArgument(SpecArgs->get(I));
|
|
|
|
}
|
|
|
|
Out << '>';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mangle in type information for the arguments.
|
2016-06-24 12:05:48 +08:00
|
|
|
for (auto PD : D->parameters()) {
|
2013-08-17 02:17:55 +08:00
|
|
|
Out << '#';
|
2014-03-07 23:12:56 +08:00
|
|
|
VisitType(PD->getType());
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
if (D->isVariadic())
|
|
|
|
Out << '.';
|
2014-12-08 16:48:11 +08:00
|
|
|
if (IsTemplate) {
|
|
|
|
// Function templates can be overloaded by return type, for example:
|
|
|
|
// \code
|
|
|
|
// template <class T> typename T::A foo() {}
|
|
|
|
// template <class T> typename T::B foo() {}
|
|
|
|
// \endcode
|
|
|
|
Out << '#';
|
|
|
|
VisitType(D->getReturnType());
|
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
Out << '#';
|
|
|
|
if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(D)) {
|
|
|
|
if (MD->isStatic())
|
|
|
|
Out << 'S';
|
|
|
|
if (unsigned quals = MD->getTypeQualifiers())
|
|
|
|
Out << (char)('0' + quals);
|
2014-12-08 16:48:21 +08:00
|
|
|
switch (MD->getRefQualifier()) {
|
|
|
|
case RQ_None: break;
|
|
|
|
case RQ_LValue: Out << '&'; break;
|
|
|
|
case RQ_RValue: Out << "&&"; break;
|
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitNamedDecl(const NamedDecl *D) {
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
|
|
|
Out << "@";
|
|
|
|
|
|
|
|
if (EmitDeclName(D)) {
|
|
|
|
// The string can be empty if the declaration has no name; e.g., it is
|
|
|
|
// the ParmDecl with no name for declaration of a function pointer type,
|
|
|
|
// e.g.: void (*f)(void *);
|
|
|
|
// In this case, don't generate a USR.
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitVarDecl(const VarDecl *D) {
|
|
|
|
// VarDecls can be declared 'extern' within a function or method body,
|
|
|
|
// but their enclosing DeclContext is the function, not the TU. We need
|
|
|
|
// to check the storage class to correctly generate the USR.
|
2014-02-24 02:23:29 +08:00
|
|
|
if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
|
2013-08-17 02:17:55 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
|
|
|
|
|
|
|
// Variables always have simple names.
|
|
|
|
StringRef s = D->getName();
|
|
|
|
|
|
|
|
// The string can be empty if the declaration has no name; e.g., it is
|
|
|
|
// the ParmDecl with no name for declaration of a function pointer type, e.g.:
|
|
|
|
// void (*f)(void *);
|
|
|
|
// In this case, don't generate a USR.
|
|
|
|
if (s.empty())
|
|
|
|
IgnoreResults = true;
|
|
|
|
else
|
|
|
|
Out << '@' << s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitNonTypeTemplateParmDecl(
|
|
|
|
const NonTypeTemplateParmDecl *D) {
|
2014-02-24 02:23:29 +08:00
|
|
|
GenLoc(D, /*IncludeOffset=*/true);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTemplateTemplateParmDecl(
|
|
|
|
const TemplateTemplateParmDecl *D) {
|
2014-02-24 02:23:29 +08:00
|
|
|
GenLoc(D, /*IncludeOffset=*/true);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitNamespaceDecl(const NamespaceDecl *D) {
|
|
|
|
if (D->isAnonymousNamespace()) {
|
|
|
|
Out << "@aN";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
|
|
|
if (!IgnoreResults)
|
|
|
|
Out << "@N@" << D->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitFunctionTemplateDecl(const FunctionTemplateDecl *D) {
|
|
|
|
VisitFunctionDecl(D->getTemplatedDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitClassTemplateDecl(const ClassTemplateDecl *D) {
|
|
|
|
VisitTagDecl(D->getTemplatedDecl());
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitNamespaceAliasDecl(const NamespaceAliasDecl *D) {
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
|
|
|
if (!IgnoreResults)
|
|
|
|
Out << "@NA@" << D->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) {
|
|
|
|
const DeclContext *container = D->getDeclContext();
|
|
|
|
if (const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) {
|
|
|
|
Visit(pd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// The USR for a method declared in a class extension or category is based on
|
|
|
|
// the ObjCInterfaceDecl, not the ObjCCategoryDecl.
|
|
|
|
const ObjCInterfaceDecl *ID = D->getClassInterface();
|
|
|
|
if (!ID) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Visit(ID);
|
|
|
|
}
|
|
|
|
// Ideally we would use 'GenObjCMethod', but this is such a hot path
|
|
|
|
// for Objective-C code that we don't want to use
|
|
|
|
// DeclarationName::getAsString().
|
|
|
|
Out << (D->isInstanceMethod() ? "(im)" : "(cm)")
|
|
|
|
<< DeclarationName(D->getSelector());
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitObjCContainerDecl(const ObjCContainerDecl *D) {
|
|
|
|
switch (D->getKind()) {
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Invalid ObjC container.");
|
|
|
|
case Decl::ObjCInterface:
|
|
|
|
case Decl::ObjCImplementation:
|
|
|
|
GenObjCClass(D->getName());
|
|
|
|
break;
|
|
|
|
case Decl::ObjCCategory: {
|
|
|
|
const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D);
|
|
|
|
const ObjCInterfaceDecl *ID = CD->getClassInterface();
|
|
|
|
if (!ID) {
|
|
|
|
// Handle invalid code where the @interface might not
|
|
|
|
// have been specified.
|
|
|
|
// FIXME: We should be able to generate this USR even if the
|
|
|
|
// @interface isn't available.
|
|
|
|
IgnoreResults = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Specially handle class extensions, which are anonymous categories.
|
|
|
|
// We want to mangle in the location to uniquely distinguish them.
|
|
|
|
if (CD->IsClassExtension()) {
|
|
|
|
Out << "objc(ext)" << ID->getName() << '@';
|
2014-02-24 02:23:29 +08:00
|
|
|
GenLoc(CD, /*IncludeOffset=*/true);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
GenObjCCategory(ID->getName(), CD->getName());
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ObjCCategoryImpl: {
|
|
|
|
const ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D);
|
|
|
|
const ObjCInterfaceDecl *ID = CD->getClassInterface();
|
|
|
|
if (!ID) {
|
|
|
|
// Handle invalid code where the @interface might not
|
|
|
|
// have been specified.
|
|
|
|
// FIXME: We should be able to generate this USR even if the
|
|
|
|
// @interface isn't available.
|
|
|
|
IgnoreResults = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GenObjCCategory(ID->getName(), CD->getName());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Decl::ObjCProtocol:
|
|
|
|
GenObjCProtocol(cast<ObjCProtocolDecl>(D)->getName());
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitObjCPropertyDecl(const ObjCPropertyDecl *D) {
|
|
|
|
// The USR for a property declared in a class extension or category is based
|
|
|
|
// on the ObjCInterfaceDecl, not the ObjCCategoryDecl.
|
|
|
|
if (const ObjCInterfaceDecl *ID = Context->getObjContainingInterface(D))
|
|
|
|
Visit(ID);
|
|
|
|
else
|
|
|
|
Visit(cast<Decl>(D->getDeclContext()));
|
2016-07-16 06:18:19 +08:00
|
|
|
GenObjCProperty(D->getName(), D->isClassProperty());
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) {
|
|
|
|
if (ObjCPropertyDecl *PD = D->getPropertyDecl()) {
|
|
|
|
VisitObjCPropertyDecl(PD);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IgnoreResults = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTagDecl(const TagDecl *D) {
|
|
|
|
// Add the location of the tag decl to handle resolution across
|
|
|
|
// translation units.
|
2016-03-04 15:17:53 +08:00
|
|
|
if (!isa<EnumDecl>(D) &&
|
|
|
|
ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
|
2013-08-17 02:17:55 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
D = D->getCanonicalDecl();
|
|
|
|
VisitDeclContext(D->getDeclContext());
|
|
|
|
|
|
|
|
bool AlreadyStarted = false;
|
|
|
|
if (const CXXRecordDecl *CXXRecord = dyn_cast<CXXRecordDecl>(D)) {
|
|
|
|
if (ClassTemplateDecl *ClassTmpl = CXXRecord->getDescribedClassTemplate()) {
|
|
|
|
AlreadyStarted = true;
|
|
|
|
|
|
|
|
switch (D->getTagKind()) {
|
|
|
|
case TTK_Interface:
|
2014-12-08 16:48:33 +08:00
|
|
|
case TTK_Class:
|
2013-08-17 02:17:55 +08:00
|
|
|
case TTK_Struct: Out << "@ST"; break;
|
|
|
|
case TTK_Union: Out << "@UT"; break;
|
|
|
|
case TTK_Enum: llvm_unreachable("enum template");
|
|
|
|
}
|
|
|
|
VisitTemplateParameterList(ClassTmpl->getTemplateParameters());
|
|
|
|
} else if (const ClassTemplatePartialSpecializationDecl *PartialSpec
|
|
|
|
= dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) {
|
|
|
|
AlreadyStarted = true;
|
|
|
|
|
|
|
|
switch (D->getTagKind()) {
|
|
|
|
case TTK_Interface:
|
2014-12-08 16:48:33 +08:00
|
|
|
case TTK_Class:
|
2013-08-17 02:17:55 +08:00
|
|
|
case TTK_Struct: Out << "@SP"; break;
|
|
|
|
case TTK_Union: Out << "@UP"; break;
|
|
|
|
case TTK_Enum: llvm_unreachable("enum partial specialization");
|
|
|
|
}
|
|
|
|
VisitTemplateParameterList(PartialSpec->getTemplateParameters());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!AlreadyStarted) {
|
|
|
|
switch (D->getTagKind()) {
|
|
|
|
case TTK_Interface:
|
2014-12-08 16:48:33 +08:00
|
|
|
case TTK_Class:
|
2013-08-17 02:17:55 +08:00
|
|
|
case TTK_Struct: Out << "@S"; break;
|
|
|
|
case TTK_Union: Out << "@U"; break;
|
|
|
|
case TTK_Enum: Out << "@E"; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Out << '@';
|
|
|
|
assert(Buf.size() > 0);
|
|
|
|
const unsigned off = Buf.size() - 1;
|
|
|
|
|
|
|
|
if (EmitDeclName(D)) {
|
|
|
|
if (const TypedefNameDecl *TD = D->getTypedefNameForAnonDecl()) {
|
|
|
|
Buf[off] = 'A';
|
|
|
|
Out << '@' << *TD;
|
|
|
|
}
|
2014-12-08 16:48:37 +08:00
|
|
|
else {
|
|
|
|
if (D->isEmbeddedInDeclarator() && !D->isFreeStanding()) {
|
|
|
|
printLoc(Out, D->getLocation(), Context->getSourceManager(), true);
|
2016-03-04 15:17:53 +08:00
|
|
|
} else {
|
2013-08-17 02:17:55 +08:00
|
|
|
Buf[off] = 'a';
|
2016-03-04 15:17:53 +08:00
|
|
|
if (auto *ED = dyn_cast<EnumDecl>(D)) {
|
|
|
|
// Distinguish USRs of anonymous enums by using their first enumerator.
|
|
|
|
auto enum_range = ED->enumerators();
|
|
|
|
if (enum_range.begin() != enum_range.end()) {
|
|
|
|
Out << '@' << **enum_range.begin();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
2014-12-08 16:48:37 +08:00
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
|
|
|
|
// For a class template specialization, mangle the template arguments.
|
|
|
|
if (const ClassTemplateSpecializationDecl *Spec
|
|
|
|
= dyn_cast<ClassTemplateSpecializationDecl>(D)) {
|
|
|
|
const TemplateArgumentList &Args = Spec->getTemplateInstantiationArgs();
|
|
|
|
Out << '>';
|
|
|
|
for (unsigned I = 0, N = Args.size(); I != N; ++I) {
|
|
|
|
Out << '#';
|
|
|
|
VisitTemplateArgument(Args.get(I));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTypedefDecl(const TypedefDecl *D) {
|
2014-02-24 02:23:29 +08:00
|
|
|
if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D)))
|
2013-08-17 02:17:55 +08:00
|
|
|
return;
|
|
|
|
const DeclContext *DC = D->getDeclContext();
|
|
|
|
if (const NamedDecl *DCN = dyn_cast<NamedDecl>(DC))
|
|
|
|
Visit(DCN);
|
|
|
|
Out << "@T@";
|
|
|
|
Out << D->getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTemplateTypeParmDecl(const TemplateTypeParmDecl *D) {
|
2014-02-24 02:23:29 +08:00
|
|
|
GenLoc(D, /*IncludeOffset=*/true);
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
2014-02-24 02:23:29 +08:00
|
|
|
bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) {
|
2013-08-17 02:17:55 +08:00
|
|
|
if (generatedLoc)
|
|
|
|
return IgnoreResults;
|
|
|
|
generatedLoc = true;
|
2014-03-29 06:21:26 +08:00
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
// Guard against null declarations in invalid code.
|
|
|
|
if (!D) {
|
|
|
|
IgnoreResults = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use the location of canonical decl.
|
|
|
|
D = D->getCanonicalDecl();
|
|
|
|
|
2014-03-29 06:21:26 +08:00
|
|
|
IgnoreResults =
|
|
|
|
IgnoreResults || printLoc(Out, D->getLocStart(),
|
|
|
|
Context->getSourceManager(), IncludeOffset);
|
|
|
|
|
2013-08-17 02:17:55 +08:00
|
|
|
return IgnoreResults;
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitType(QualType T) {
|
|
|
|
// This method mangles in USR information for types. It can possibly
|
|
|
|
// just reuse the naming-mangling logic used by codegen, although the
|
|
|
|
// requirements for USRs might not be the same.
|
|
|
|
ASTContext &Ctx = *Context;
|
|
|
|
|
|
|
|
do {
|
|
|
|
T = Ctx.getCanonicalType(T);
|
|
|
|
Qualifiers Q = T.getQualifiers();
|
|
|
|
unsigned qVal = 0;
|
|
|
|
if (Q.hasConst())
|
|
|
|
qVal |= 0x1;
|
|
|
|
if (Q.hasVolatile())
|
|
|
|
qVal |= 0x2;
|
|
|
|
if (Q.hasRestrict())
|
|
|
|
qVal |= 0x4;
|
|
|
|
if(qVal)
|
|
|
|
Out << ((char) ('0' + qVal));
|
|
|
|
|
|
|
|
// Mangle in ObjC GC qualifiers?
|
|
|
|
|
|
|
|
if (const PackExpansionType *Expansion = T->getAs<PackExpansionType>()) {
|
|
|
|
Out << 'P';
|
|
|
|
T = Expansion->getPattern();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const BuiltinType *BT = T->getAs<BuiltinType>()) {
|
|
|
|
unsigned char c = '\0';
|
|
|
|
switch (BT->getKind()) {
|
|
|
|
case BuiltinType::Void:
|
|
|
|
c = 'v'; break;
|
|
|
|
case BuiltinType::Bool:
|
|
|
|
c = 'b'; break;
|
|
|
|
case BuiltinType::UChar:
|
|
|
|
c = 'c'; break;
|
|
|
|
case BuiltinType::Char16:
|
|
|
|
c = 'q'; break;
|
|
|
|
case BuiltinType::Char32:
|
|
|
|
c = 'w'; break;
|
|
|
|
case BuiltinType::UShort:
|
|
|
|
c = 's'; break;
|
|
|
|
case BuiltinType::UInt:
|
|
|
|
c = 'i'; break;
|
|
|
|
case BuiltinType::ULong:
|
|
|
|
c = 'l'; break;
|
|
|
|
case BuiltinType::ULongLong:
|
|
|
|
c = 'k'; break;
|
|
|
|
case BuiltinType::UInt128:
|
|
|
|
c = 'j'; break;
|
2014-12-08 17:09:05 +08:00
|
|
|
case BuiltinType::Char_U:
|
2013-08-17 02:17:55 +08:00
|
|
|
case BuiltinType::Char_S:
|
|
|
|
c = 'C'; break;
|
2014-12-08 16:48:17 +08:00
|
|
|
case BuiltinType::SChar:
|
|
|
|
c = 'r'; break;
|
2013-08-17 02:17:55 +08:00
|
|
|
case BuiltinType::WChar_S:
|
|
|
|
case BuiltinType::WChar_U:
|
|
|
|
c = 'W'; break;
|
|
|
|
case BuiltinType::Short:
|
|
|
|
c = 'S'; break;
|
|
|
|
case BuiltinType::Int:
|
|
|
|
c = 'I'; break;
|
|
|
|
case BuiltinType::Long:
|
|
|
|
c = 'L'; break;
|
|
|
|
case BuiltinType::LongLong:
|
|
|
|
c = 'K'; break;
|
|
|
|
case BuiltinType::Int128:
|
|
|
|
c = 'J'; break;
|
|
|
|
case BuiltinType::Half:
|
|
|
|
c = 'h'; break;
|
|
|
|
case BuiltinType::Float:
|
|
|
|
c = 'f'; break;
|
|
|
|
case BuiltinType::Double:
|
|
|
|
c = 'd'; break;
|
|
|
|
case BuiltinType::LongDouble:
|
|
|
|
c = 'D'; break;
|
2016-05-09 16:52:33 +08:00
|
|
|
case BuiltinType::Float128:
|
|
|
|
c = 'Q'; break;
|
2013-08-17 02:17:55 +08:00
|
|
|
case BuiltinType::NullPtr:
|
|
|
|
c = 'n'; break;
|
|
|
|
#define BUILTIN_TYPE(Id, SingletonId)
|
|
|
|
#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
|
|
|
|
#include "clang/AST/BuiltinTypes.def"
|
|
|
|
case BuiltinType::Dependent:
|
2016-04-08 21:40:33 +08:00
|
|
|
#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
|
|
|
|
case BuiltinType::Id:
|
2016-04-13 16:33:41 +08:00
|
|
|
#include "clang/Basic/OpenCLImageTypes.def"
|
2013-08-17 02:17:55 +08:00
|
|
|
case BuiltinType::OCLEvent:
|
2015-09-15 19:18:52 +08:00
|
|
|
case BuiltinType::OCLClkEvent:
|
|
|
|
case BuiltinType::OCLQueue:
|
|
|
|
case BuiltinType::OCLNDRange:
|
|
|
|
case BuiltinType::OCLReserveID:
|
2013-08-17 02:17:55 +08:00
|
|
|
case BuiltinType::OCLSampler:
|
|
|
|
IgnoreResults = true;
|
|
|
|
return;
|
|
|
|
case BuiltinType::ObjCId:
|
|
|
|
c = 'o'; break;
|
|
|
|
case BuiltinType::ObjCClass:
|
|
|
|
c = 'O'; break;
|
|
|
|
case BuiltinType::ObjCSel:
|
|
|
|
c = 'e'; break;
|
|
|
|
}
|
|
|
|
Out << c;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have already seen this (non-built-in) type, use a substitution
|
|
|
|
// encoding.
|
|
|
|
llvm::DenseMap<const Type *, unsigned>::iterator Substitution
|
|
|
|
= TypeSubstitutions.find(T.getTypePtr());
|
|
|
|
if (Substitution != TypeSubstitutions.end()) {
|
|
|
|
Out << 'S' << Substitution->second << '_';
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
// Record this as a substitution.
|
|
|
|
unsigned Number = TypeSubstitutions.size();
|
|
|
|
TypeSubstitutions[T.getTypePtr()] = Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (const PointerType *PT = T->getAs<PointerType>()) {
|
|
|
|
Out << '*';
|
|
|
|
T = PT->getPointeeType();
|
|
|
|
continue;
|
|
|
|
}
|
2016-03-04 15:17:43 +08:00
|
|
|
if (const ObjCObjectPointerType *OPT = T->getAs<ObjCObjectPointerType>()) {
|
|
|
|
Out << '*';
|
|
|
|
T = OPT->getPointeeType();
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-08 16:48:27 +08:00
|
|
|
if (const RValueReferenceType *RT = T->getAs<RValueReferenceType>()) {
|
|
|
|
Out << "&&";
|
|
|
|
T = RT->getPointeeType();
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
|
|
|
|
Out << '&';
|
|
|
|
T = RT->getPointeeType();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) {
|
|
|
|
Out << 'F';
|
2014-01-26 00:55:45 +08:00
|
|
|
VisitType(FT->getReturnType());
|
2014-03-17 23:23:01 +08:00
|
|
|
for (const auto &I : FT->param_types())
|
|
|
|
VisitType(I);
|
2013-08-17 02:17:55 +08:00
|
|
|
if (FT->isVariadic())
|
|
|
|
Out << '.';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const BlockPointerType *BT = T->getAs<BlockPointerType>()) {
|
|
|
|
Out << 'B';
|
|
|
|
T = BT->getPointeeType();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (const ComplexType *CT = T->getAs<ComplexType>()) {
|
|
|
|
Out << '<';
|
|
|
|
T = CT->getElementType();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (const TagType *TT = T->getAs<TagType>()) {
|
|
|
|
Out << '$';
|
|
|
|
VisitTagDecl(TT->getDecl());
|
|
|
|
return;
|
|
|
|
}
|
2016-03-04 15:17:43 +08:00
|
|
|
if (const ObjCInterfaceType *OIT = T->getAs<ObjCInterfaceType>()) {
|
|
|
|
Out << '$';
|
|
|
|
VisitObjCInterfaceDecl(OIT->getDecl());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const ObjCObjectType *OIT = T->getAs<ObjCObjectType>()) {
|
|
|
|
Out << 'Q';
|
|
|
|
VisitType(OIT->getBaseType());
|
|
|
|
for (auto *Prot : OIT->getProtocols())
|
|
|
|
VisitObjCProtocolDecl(Prot);
|
|
|
|
return;
|
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
if (const TemplateTypeParmType *TTP = T->getAs<TemplateTypeParmType>()) {
|
|
|
|
Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (const TemplateSpecializationType *Spec
|
|
|
|
= T->getAs<TemplateSpecializationType>()) {
|
|
|
|
Out << '>';
|
|
|
|
VisitTemplateName(Spec->getTemplateName());
|
|
|
|
Out << Spec->getNumArgs();
|
|
|
|
for (unsigned I = 0, N = Spec->getNumArgs(); I != N; ++I)
|
|
|
|
VisitTemplateArgument(Spec->getArg(I));
|
|
|
|
return;
|
|
|
|
}
|
2014-12-08 16:48:11 +08:00
|
|
|
if (const DependentNameType *DNT = T->getAs<DependentNameType>()) {
|
|
|
|
Out << '^';
|
|
|
|
// FIXME: Encode the qualifier, don't just print it.
|
|
|
|
PrintingPolicy PO(Ctx.getLangOpts());
|
|
|
|
PO.SuppressTagKeyword = true;
|
|
|
|
PO.SuppressUnwrittenScope = true;
|
|
|
|
PO.ConstantArraySizeAsWritten = false;
|
|
|
|
PO.AnonymousTagLocations = false;
|
|
|
|
DNT->getQualifier()->print(Out, PO);
|
|
|
|
Out << ':' << DNT->getIdentifier()->getName();
|
|
|
|
return;
|
|
|
|
}
|
2014-12-08 16:48:43 +08:00
|
|
|
if (const InjectedClassNameType *InjT = T->getAs<InjectedClassNameType>()) {
|
|
|
|
T = InjT->getInjectedSpecializationType();
|
|
|
|
continue;
|
|
|
|
}
|
2013-08-17 02:17:55 +08:00
|
|
|
|
|
|
|
// Unhandled type.
|
|
|
|
Out << ' ';
|
|
|
|
break;
|
|
|
|
} while (true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTemplateParameterList(
|
|
|
|
const TemplateParameterList *Params) {
|
|
|
|
if (!Params)
|
|
|
|
return;
|
|
|
|
Out << '>' << Params->size();
|
|
|
|
for (TemplateParameterList::const_iterator P = Params->begin(),
|
|
|
|
PEnd = Params->end();
|
|
|
|
P != PEnd; ++P) {
|
|
|
|
Out << '#';
|
|
|
|
if (isa<TemplateTypeParmDecl>(*P)) {
|
|
|
|
if (cast<TemplateTypeParmDecl>(*P)->isParameterPack())
|
|
|
|
Out<< 'p';
|
|
|
|
Out << 'T';
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (NonTypeTemplateParmDecl *NTTP = dyn_cast<NonTypeTemplateParmDecl>(*P)) {
|
|
|
|
if (NTTP->isParameterPack())
|
|
|
|
Out << 'p';
|
|
|
|
Out << 'N';
|
|
|
|
VisitType(NTTP->getType());
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
TemplateTemplateParmDecl *TTP = cast<TemplateTemplateParmDecl>(*P);
|
|
|
|
if (TTP->isParameterPack())
|
|
|
|
Out << 'p';
|
|
|
|
Out << 't';
|
|
|
|
VisitTemplateParameterList(TTP->getTemplateParameters());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTemplateName(TemplateName Name) {
|
|
|
|
if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
|
|
|
|
if (TemplateTemplateParmDecl *TTP
|
|
|
|
= dyn_cast<TemplateTemplateParmDecl>(Template)) {
|
|
|
|
Out << 't' << TTP->getDepth() << '.' << TTP->getIndex();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Visit(Template);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: Visit dependent template names.
|
|
|
|
}
|
|
|
|
|
|
|
|
void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) {
|
|
|
|
switch (Arg.getKind()) {
|
|
|
|
case TemplateArgument::Null:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Declaration:
|
|
|
|
Visit(Arg.getAsDecl());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::NullPtr:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::TemplateExpansion:
|
|
|
|
Out << 'P'; // pack expansion of...
|
|
|
|
// Fall through
|
|
|
|
case TemplateArgument::Template:
|
|
|
|
VisitTemplateName(Arg.getAsTemplateOrTemplatePattern());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Expression:
|
|
|
|
// FIXME: Visit expressions.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Pack:
|
|
|
|
Out << 'p' << Arg.pack_size();
|
2014-07-16 05:32:31 +08:00
|
|
|
for (const auto &P : Arg.pack_elements())
|
|
|
|
VisitTemplateArgument(P);
|
2013-08-17 02:17:55 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Type:
|
|
|
|
VisitType(Arg.getAsType());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TemplateArgument::Integral:
|
|
|
|
Out << 'V';
|
|
|
|
VisitType(Arg.getIntegralType());
|
|
|
|
Out << Arg.getAsIntegral();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// USR generation functions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-21 08:49:25 +08:00
|
|
|
void clang::index::generateUSRForObjCClass(StringRef Cls, raw_ostream &OS) {
|
2013-08-17 02:17:55 +08:00
|
|
|
OS << "objc(cs)" << Cls;
|
|
|
|
}
|
|
|
|
|
2013-08-21 08:49:25 +08:00
|
|
|
void clang::index::generateUSRForObjCCategory(StringRef Cls, StringRef Cat,
|
|
|
|
raw_ostream &OS) {
|
2013-08-17 02:17:55 +08:00
|
|
|
OS << "objc(cy)" << Cls << '@' << Cat;
|
|
|
|
}
|
|
|
|
|
2013-08-21 08:49:25 +08:00
|
|
|
void clang::index::generateUSRForObjCIvar(StringRef Ivar, raw_ostream &OS) {
|
2013-08-17 02:17:55 +08:00
|
|
|
OS << '@' << Ivar;
|
|
|
|
}
|
|
|
|
|
2013-08-21 08:49:25 +08:00
|
|
|
void clang::index::generateUSRForObjCMethod(StringRef Sel,
|
|
|
|
bool IsInstanceMethod,
|
|
|
|
raw_ostream &OS) {
|
2013-08-17 02:17:55 +08:00
|
|
|
OS << (IsInstanceMethod ? "(im)" : "(cm)") << Sel;
|
|
|
|
}
|
|
|
|
|
2016-07-16 06:18:19 +08:00
|
|
|
void clang::index::generateUSRForObjCProperty(StringRef Prop, bool isClassProp,
|
|
|
|
raw_ostream &OS) {
|
|
|
|
OS << (isClassProp ? "(cpy)" : "(py)") << Prop;
|
2013-08-17 02:17:55 +08:00
|
|
|
}
|
|
|
|
|
2013-08-21 08:49:25 +08:00
|
|
|
void clang::index::generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS) {
|
2013-08-17 02:17:55 +08:00
|
|
|
OS << "objc(pl)" << Prot;
|
|
|
|
}
|
|
|
|
|
2013-08-21 08:49:25 +08:00
|
|
|
bool clang::index::generateUSRForDecl(const Decl *D,
|
|
|
|
SmallVectorImpl<char> &Buf) {
|
2013-08-17 02:17:55 +08:00
|
|
|
// Don't generate USRs for things with invalid locations.
|
|
|
|
if (!D || D->getLocStart().isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
USRGenerator UG(&D->getASTContext(), Buf);
|
|
|
|
UG.Visit(D);
|
|
|
|
return UG.ignoreResults();
|
|
|
|
}
|
2014-03-29 06:21:26 +08:00
|
|
|
|
2015-05-04 10:25:31 +08:00
|
|
|
bool clang::index::generateUSRForMacro(const MacroDefinitionRecord *MD,
|
2014-03-29 06:21:26 +08:00
|
|
|
const SourceManager &SM,
|
|
|
|
SmallVectorImpl<char> &Buf) {
|
|
|
|
// Don't generate USRs for things with invalid locations.
|
|
|
|
if (!MD || MD->getLocation().isInvalid())
|
|
|
|
return true;
|
|
|
|
|
|
|
|
llvm::raw_svector_ostream Out(Buf);
|
|
|
|
|
|
|
|
// Assume that system headers are sane. Don't put source location
|
|
|
|
// information into the USR if the macro comes from a system header.
|
|
|
|
SourceLocation Loc = MD->getLocation();
|
|
|
|
bool ShouldGenerateLocation = !SM.isInSystemHeader(Loc);
|
|
|
|
|
|
|
|
Out << getUSRSpacePrefix();
|
|
|
|
if (ShouldGenerateLocation)
|
|
|
|
printLoc(Out, Loc, SM, /*IncludeOffset=*/true);
|
|
|
|
Out << "@macro@";
|
2014-06-08 07:30:53 +08:00
|
|
|
Out << MD->getName()->getName();
|
2014-03-29 06:21:26 +08:00
|
|
|
return false;
|
|
|
|
}
|