diff options
Diffstat (limited to 'lib/Index')
-rw-r--r-- | lib/Index/CodegenNameGenerator.cpp | 39 | ||||
-rw-r--r-- | lib/Index/CommentToXML.cpp | 1 | ||||
-rw-r--r-- | lib/Index/IndexBody.cpp | 11 | ||||
-rw-r--r-- | lib/Index/IndexDecl.cpp | 36 | ||||
-rw-r--r-- | lib/Index/IndexSymbol.cpp | 38 | ||||
-rw-r--r-- | lib/Index/IndexTypeSourceInfo.cpp | 13 | ||||
-rw-r--r-- | lib/Index/IndexingAction.cpp | 22 | ||||
-rw-r--r-- | lib/Index/IndexingContext.cpp | 4 | ||||
-rw-r--r-- | lib/Index/USRGeneration.cpp | 74 |
9 files changed, 185 insertions, 53 deletions
diff --git a/lib/Index/CodegenNameGenerator.cpp b/lib/Index/CodegenNameGenerator.cpp index 92740b05703b5..bf52e2108baaf 100644 --- a/lib/Index/CodegenNameGenerator.cpp +++ b/lib/Index/CodegenNameGenerator.cpp @@ -68,7 +68,38 @@ struct CodegenNameGenerator::Implementation { return Name; } + enum ObjCKind { + ObjCClass, + ObjCMetaclass, + }; + + std::vector<std::string> getAllManglings(const ObjCContainerDecl *OCD) { + StringRef ClassName; + if (const auto *OID = dyn_cast<ObjCInterfaceDecl>(OCD)) + ClassName = OID->getObjCRuntimeNameAsString(); + else if (const auto *OID = dyn_cast<ObjCImplementationDecl>(OCD)) + ClassName = OID->getObjCRuntimeNameAsString(); + + if (ClassName.empty()) + return {}; + + auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string { + SmallString<40> Mangled; + auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext()); + llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL); + return Mangled.str(); + }; + + return { + Mangle(ObjCClass, ClassName), + Mangle(ObjCMetaclass, ClassName), + }; + } + std::vector<std::string> getAllManglings(const Decl *D) { + if (const auto *OCD = dyn_cast<ObjCContainerDecl>(D)) + return getAllManglings(OCD); + if (!(isa<CXXRecordDecl>(D) || isa<CXXMethodDecl>(D))) return {}; @@ -135,12 +166,14 @@ private: } void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) { - OS << getClassSymbolPrefix(); + OS << getClassSymbolPrefix(ObjCClass, D->getASTContext()); OS << D->getObjCRuntimeNameAsString(); } - static StringRef getClassSymbolPrefix() { - return "OBJC_CLASS_$_"; + static StringRef getClassSymbolPrefix(ObjCKind Kind, const ASTContext &Context) { + if (Context.getLangOpts().ObjCRuntime.isGNUFamily()) + return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_"; + return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_"; } std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType) { diff --git a/lib/Index/CommentToXML.cpp b/lib/Index/CommentToXML.cpp index e568c838b7b0f..918068a2405f7 100644 --- a/lib/Index/CommentToXML.cpp +++ b/lib/Index/CommentToXML.cpp @@ -579,6 +579,7 @@ void getSourceTextOfDeclaration(const DeclInfo *ThisDecl, PrintingPolicy PPolicy(LangOpts); PPolicy.PolishForDeclaration = true; PPolicy.TerseOutput = true; + PPolicy.ConstantsAsWritten = true; ThisDecl->CurrentDecl->print(OS, PPolicy, /*Indentation*/0, /*PrintInstantiation*/false); } diff --git a/lib/Index/IndexBody.cpp b/lib/Index/IndexBody.cpp index 6bbd38102509f..ac34956b24840 100644 --- a/lib/Index/IndexBody.cpp +++ b/lib/Index/IndexBody.cpp @@ -427,6 +427,17 @@ public: return true; } + + bool VisitOffsetOfExpr(OffsetOfExpr *S) { + for (unsigned I = 0, E = S->getNumComponents(); I != E; ++I) { + const OffsetOfNode &Component = S->getComponent(I); + if (Component.getKind() == OffsetOfNode::Field) + IndexCtx.handleReference(Component.getField(), Component.getLocEnd(), + Parent, ParentDC, SymbolRoleSet(), {}); + // FIXME: Try to resolve dependent field references. + } + return true; + } }; } // anonymous namespace diff --git a/lib/Index/IndexDecl.cpp b/lib/Index/IndexDecl.cpp index c5230c0f9acf8..e14750e046eb9 100644 --- a/lib/Index/IndexDecl.cpp +++ b/lib/Index/IndexDecl.cpp @@ -233,9 +233,8 @@ public: if (auto *CXXMD = dyn_cast<CXXMethodDecl>(D)) { if (CXXMD->isVirtual()) Roles |= (unsigned)SymbolRole::Dynamic; - for (auto I = CXXMD->begin_overridden_methods(), - E = CXXMD->end_overridden_methods(); I != E; ++I) { - Relations.emplace_back((unsigned)SymbolRole::RelationOverrideOf, *I); + for (const CXXMethodDecl *O : CXXMD->overridden_methods()) { + Relations.emplace_back((unsigned)SymbolRole::RelationOverrideOf, O); } } gatherTemplatePseudoOverrides(D, Relations); @@ -267,6 +266,10 @@ public: TypeNameInfo->getTypeLoc().getLocStart(), Dtor->getParent(), Dtor->getDeclContext()); } + } else if (const auto *Guide = dyn_cast<CXXDeductionGuideDecl>(D)) { + IndexCtx.handleReference(Guide->getDeducedTemplate()->getTemplatedDecl(), + Guide->getLocation(), Guide, + Guide->getDeclContext()); } // Template specialization arguments. if (const ASTTemplateArgumentListInfo *TemplateArgInfo = @@ -350,12 +353,10 @@ public: gatherTemplatePseudoOverrides(D, Relations); IndexCtx.indexTagDecl(D, Relations); } else { - auto *Parent = dyn_cast<NamedDecl>(D->getDeclContext()); SmallVector<SymbolRelation, 1> Relations; gatherTemplatePseudoOverrides(D, Relations); - return IndexCtx.handleReference(D, D->getLocation(), Parent, - D->getLexicalDeclContext(), - SymbolRoleSet(), Relations); + return IndexCtx.handleDecl(D, D->getLocation(), SymbolRoleSet(), + Relations, D->getLexicalDeclContext()); } } return true; @@ -607,6 +608,24 @@ public: SymbolRoleSet()); } + bool VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) { + TRY_DECL(D, IndexCtx.handleDecl(D)); + const DeclContext *DC = D->getDeclContext()->getRedeclContext(); + const NamedDecl *Parent = dyn_cast<NamedDecl>(DC); + IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent, + D->getLexicalDeclContext()); + return true; + } + + bool VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) { + TRY_DECL(D, IndexCtx.handleDecl(D)); + const DeclContext *DC = D->getDeclContext()->getRedeclContext(); + const NamedDecl *Parent = dyn_cast<NamedDecl>(DC); + IndexCtx.indexNestedNameSpecifierLoc(D->getQualifierLoc(), Parent, + D->getLexicalDeclContext()); + return true; + } + bool VisitClassTemplateSpecializationDecl(const ClassTemplateSpecializationDecl *D) { // FIXME: Notify subsequent callbacks if info comes from implicit @@ -644,7 +663,6 @@ public: } bool VisitTemplateDecl(const TemplateDecl *D) { - // FIXME: Template parameters. // Index the default values for the template parameters. const NamedDecl *Parent = D->getTemplatedDecl(); @@ -661,7 +679,7 @@ public: } else if (const auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(TP)) { if (TTPD->hasDefaultArgument()) handleTemplateArgumentLoc(TTPD->getDefaultArgument(), Parent, - /*DC=*/nullptr); + TP->getLexicalDeclContext()); } } } diff --git a/lib/Index/IndexSymbol.cpp b/lib/Index/IndexSymbol.cpp index 0dc3720208caf..03db0cd53f7a5 100644 --- a/lib/Index/IndexSymbol.cpp +++ b/lib/Index/IndexSymbol.cpp @@ -201,25 +201,22 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Properties |= (unsigned)SymbolProperty::UnitTest; break; } - case Decl::ObjCMethod: - if (cast<ObjCMethodDecl>(D)->isInstanceMethod()) { - const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D); - Info.Kind = SymbolKind::InstanceMethod; - if (MD->isPropertyAccessor()) { - if (MD->param_size()) - Info.SubKind = SymbolSubKind::AccessorSetter; - else - Info.SubKind = SymbolSubKind::AccessorGetter; - } - } else { - Info.Kind = SymbolKind::ClassMethod; + case Decl::ObjCMethod: { + const ObjCMethodDecl *MD = cast<ObjCMethodDecl>(D); + Info.Kind = MD->isInstanceMethod() ? SymbolKind::InstanceMethod : SymbolKind::ClassMethod; + if (MD->isPropertyAccessor()) { + if (MD->param_size()) + Info.SubKind = SymbolSubKind::AccessorSetter; + else + Info.SubKind = SymbolSubKind::AccessorGetter; } Info.Lang = SymbolLanguage::ObjC; - if (isUnitTest(cast<ObjCMethodDecl>(D))) + if (isUnitTest(MD)) Info.Properties |= (unsigned)SymbolProperty::UnitTest; if (D->hasAttr<IBActionAttr>()) Info.Properties |= (unsigned)SymbolProperty::IBAnnotated; break; + } case Decl::ObjCProperty: Info.Kind = SymbolKind::InstanceProperty; Info.Lang = SymbolLanguage::ObjC; @@ -303,6 +300,18 @@ SymbolInfo index::getSymbolInfo(const Decl *D) { Info.Kind = SymbolKind::TypeAlias; Info.Lang = SymbolLanguage::CXX; break; + case Decl::UnresolvedUsingTypename: + Info.Kind = SymbolKind::Using; + Info.SubKind = SymbolSubKind::UsingTypename; + Info.Lang = SymbolLanguage::CXX; + Info.Properties |= (unsigned)SymbolProperty::Generic; + break; + case Decl::UnresolvedUsingValue: + Info.Kind = SymbolKind::Using; + Info.SubKind = SymbolSubKind::UsingValue; + Info.Lang = SymbolLanguage::CXX; + Info.Properties |= (unsigned)SymbolProperty::Generic; + break; case Decl::Binding: Info.Kind = SymbolKind::Variable; Info.Lang = SymbolLanguage::CXX; @@ -451,6 +460,7 @@ StringRef index::getSymbolKindString(SymbolKind K) { case SymbolKind::Destructor: return "destructor"; case SymbolKind::ConversionFunction: return "coversion-func"; case SymbolKind::Parameter: return "param"; + case SymbolKind::Using: return "using"; } llvm_unreachable("invalid symbol kind"); } @@ -462,6 +472,8 @@ StringRef index::getSymbolSubKindString(SymbolSubKind K) { case SymbolSubKind::CXXMoveConstructor: return "cxx-move-ctor"; case SymbolSubKind::AccessorGetter: return "acc-get"; case SymbolSubKind::AccessorSetter: return "acc-set"; + case SymbolSubKind::UsingTypename: return "using-typename"; + case SymbolSubKind::UsingValue: return "using-value"; } llvm_unreachable("invalid symbol subkind"); } diff --git a/lib/Index/IndexTypeSourceInfo.cpp b/lib/Index/IndexTypeSourceInfo.cpp index ae27ebe6ea4c0..c8ff3d72d4be1 100644 --- a/lib/Index/IndexTypeSourceInfo.cpp +++ b/lib/Index/IndexTypeSourceInfo.cpp @@ -126,8 +126,9 @@ public: return true; } - bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { - if (const TemplateSpecializationType *T = TL.getTypePtr()) { + template<typename TypeLocType> + bool HandleTemplateSpecializationTypeLoc(TypeLocType TL) { + if (const auto *T = TL.getTypePtr()) { if (IndexCtx.shouldIndexImplicitTemplateInsts()) { if (CXXRecordDecl *RD = T->getAsCXXRecordDecl()) IndexCtx.handleReference(RD, TL.getTemplateNameLoc(), @@ -141,6 +142,14 @@ public: return true; } + bool VisitTemplateSpecializationTypeLoc(TemplateSpecializationTypeLoc TL) { + return HandleTemplateSpecializationTypeLoc(TL); + } + + bool VisitDeducedTemplateSpecializationTypeLoc(DeducedTemplateSpecializationTypeLoc TL) { + return HandleTemplateSpecializationTypeLoc(TL); + } + bool VisitDependentNameTypeLoc(DependentNameTypeLoc TL) { const DependentNameType *DNT = TL.getTypePtr(); const NestedNameSpecifier *NNS = DNT->getQualifier(); diff --git a/lib/Index/IndexingAction.cpp b/lib/Index/IndexingAction.cpp index 84d31200bab43..411657bf3dcdd 100644 --- a/lib/Index/IndexingAction.cpp +++ b/lib/Index/IndexingAction.cpp @@ -8,10 +8,11 @@ //===----------------------------------------------------------------------===// #include "clang/Index/IndexingAction.h" -#include "clang/Index/IndexDataConsumer.h" #include "IndexingContext.h" +#include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Frontend/MultiplexConsumer.h" +#include "clang/Index/IndexDataConsumer.h" #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" @@ -42,16 +43,18 @@ bool IndexDataConsumer::handleModuleOccurence(const ImportDecl *ImportD, namespace { class IndexASTConsumer : public ASTConsumer { + std::shared_ptr<Preprocessor> PP; IndexingContext &IndexCtx; public: - IndexASTConsumer(IndexingContext &IndexCtx) - : IndexCtx(IndexCtx) {} + IndexASTConsumer(std::shared_ptr<Preprocessor> PP, IndexingContext &IndexCtx) + : PP(std::move(PP)), IndexCtx(IndexCtx) {} protected: void Initialize(ASTContext &Context) override { IndexCtx.setASTContext(Context); IndexCtx.getDataConsumer().initialize(Context); + IndexCtx.getDataConsumer().setPreprocessor(PP); } bool HandleTopLevelDecl(DeclGroupRef DG) override { @@ -80,8 +83,10 @@ protected: : DataConsumer(std::move(dataConsumer)), IndexCtx(Opts, *DataConsumer) {} - std::unique_ptr<IndexASTConsumer> createIndexASTConsumer() { - return llvm::make_unique<IndexASTConsumer>(IndexCtx); + std::unique_ptr<IndexASTConsumer> + createIndexASTConsumer(CompilerInstance &CI) { + return llvm::make_unique<IndexASTConsumer>(CI.getPreprocessorPtr(), + IndexCtx); } void finish() { @@ -98,7 +103,7 @@ public: protected: std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI, StringRef InFile) override { - return createIndexASTConsumer(); + return createIndexASTConsumer(CI); } void EndSourceFileAction() override { @@ -142,7 +147,7 @@ WrappingIndexAction::CreateASTConsumer(CompilerInstance &CI, StringRef InFile) { std::vector<std::unique_ptr<ASTConsumer>> Consumers; Consumers.push_back(std::move(OtherConsumer)); - Consumers.push_back(createIndexASTConsumer()); + Consumers.push_back(createIndexASTConsumer(CI)); return llvm::make_unique<MultiplexConsumer>(std::move(Consumers)); } @@ -173,6 +178,7 @@ void index::indexASTUnit(ASTUnit &Unit, IndexingContext IndexCtx(Opts, *DataConsumer); IndexCtx.setASTContext(Unit.getASTContext()); DataConsumer->initialize(Unit.getASTContext()); + DataConsumer->setPreprocessor(Unit.getPreprocessorPtr()); indexTranslationUnit(Unit, IndexCtx); DataConsumer->finish(); } @@ -198,7 +204,7 @@ void index::indexModuleFile(serialization::ModuleFile &Mod, IndexCtx.setASTContext(Ctx); DataConsumer->initialize(Ctx); - for (const Decl *D :Reader.getModuleFileLevelDecls(Mod)) { + for (const Decl *D : Reader.getModuleFileLevelDecls(Mod)) { IndexCtx.indexTopLevelDecl(D); } DataConsumer->finish(); diff --git a/lib/Index/IndexingContext.cpp b/lib/Index/IndexingContext.cpp index addee691e8046..de9fe39df0310 100644 --- a/lib/Index/IndexingContext.cpp +++ b/lib/Index/IndexingContext.cpp @@ -231,8 +231,8 @@ static bool isDeclADefinition(const Decl *D, const DeclContext *ContainerDC, AST /// Whether the given NamedDecl should be skipped because it has no name. static bool shouldSkipNamelessDecl(const NamedDecl *ND) { - return ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) && - !isa<ObjCCategoryDecl>(ND); + return (ND->getDeclName().isEmpty() && !isa<TagDecl>(ND) && + !isa<ObjCCategoryDecl>(ND)) || isa<CXXDeductionGuideDecl>(ND); } static const Decl *adjustParent(const Decl *Parent) { diff --git a/lib/Index/USRGeneration.cpp b/lib/Index/USRGeneration.cpp index 21054b099a8e7..3a06554b256c6 100644 --- a/lib/Index/USRGeneration.cpp +++ b/lib/Index/USRGeneration.cpp @@ -99,6 +99,8 @@ public: void VisitVarDecl(const VarDecl *D); void VisitNonTypeTemplateParmDecl(const NonTypeTemplateParmDecl *D); void VisitTemplateTemplateParmDecl(const TemplateTemplateParmDecl *D); + void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D); + void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D); void VisitLinkageSpecDecl(const LinkageSpecDecl *D) { IgnoreResults = true; @@ -112,14 +114,6 @@ public: IgnoreResults = true; } - void VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) { - IgnoreResults = true; - } - - void VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) { - IgnoreResults = true; - } - bool ShouldGenerateLocation(const NamedDecl *D); bool isLocal(const NamedDecl *D) { @@ -609,6 +603,16 @@ bool USRGenerator::GenLoc(const Decl *D, bool IncludeOffset) { return IgnoreResults; } +static void printQualifier(llvm::raw_ostream &Out, ASTContext &Ctx, NestedNameSpecifier *NNS) { + // 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; + NNS->print(Out, PO); +} + 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 @@ -676,6 +680,7 @@ void USRGenerator::VisitType(QualType T) { c = 'K'; break; case BuiltinType::Int128: c = 'J'; break; + case BuiltinType::Float16: case BuiltinType::Half: c = 'h'; break; case BuiltinType::Float: @@ -749,8 +754,12 @@ void USRGenerator::VisitType(QualType T) { if (const FunctionProtoType *FT = T->getAs<FunctionProtoType>()) { Out << 'F'; VisitType(FT->getReturnType()); - for (const auto &I : FT->param_types()) + Out << '('; + for (const auto &I : FT->param_types()) { + Out << '#'; VisitType(I); + } + Out << ')'; if (FT->isVariadic()) Out << '.'; return; @@ -797,13 +806,7 @@ void USRGenerator::VisitType(QualType T) { } 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); + printQualifier(Out, Ctx, DNT->getQualifier()); Out << ':' << DNT->getIdentifier()->getName(); return; } @@ -817,6 +820,25 @@ void USRGenerator::VisitType(QualType T) { T = VT->getElementType(); continue; } + if (const auto *const AT = dyn_cast<ArrayType>(T)) { + Out << '{'; + switch (AT->getSizeModifier()) { + case ArrayType::Static: + Out << 's'; + break; + case ArrayType::Star: + Out << '*'; + break; + case ArrayType::Normal: + Out << 'n'; + break; + } + if (const auto *const CAT = dyn_cast<ConstantArrayType>(T)) + Out << CAT->getSize(); + + T = AT->getElementType(); + continue; + } // Unhandled type. Out << ' '; @@ -912,6 +934,26 @@ void USRGenerator::VisitTemplateArgument(const TemplateArgument &Arg) { } } +void USRGenerator::VisitUnresolvedUsingValueDecl(const UnresolvedUsingValueDecl *D) { + if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) + return; + VisitDeclContext(D->getDeclContext()); + Out << "@UUV@"; + printQualifier(Out, D->getASTContext(), D->getQualifier()); + EmitDeclName(D); +} + +void USRGenerator::VisitUnresolvedUsingTypenameDecl(const UnresolvedUsingTypenameDecl *D) { + if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) + return; + VisitDeclContext(D->getDeclContext()); + Out << "@UUT@"; + printQualifier(Out, D->getASTContext(), D->getQualifier()); + Out << D->getName(); // Simple name. +} + + + //===----------------------------------------------------------------------===// // USR generation functions. //===----------------------------------------------------------------------===// |