From 9c79ff5ab38d9901e5b01d8d8fabdb3645245be2 Mon Sep 17 00:00:00 2001 From: ykiko Date: Thu, 31 Oct 2024 17:21:33 +0800 Subject: [PATCH] Add some new AST nodes for indexer. --- src/Index/Indexer.cpp | 82 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 11 deletions(-) diff --git a/src/Index/Indexer.cpp b/src/Index/Indexer.cpp index 834053d1..241e582f 100644 --- a/src/Index/Indexer.cpp +++ b/src/Index/Indexer.cpp @@ -193,6 +193,47 @@ public: /// ============================================================================ bool VisitNamespaceDecl(const clang::NamespaceDecl* decl) { + /// `namespace Foo {}` + /// ^~~~ definition + if(Location location = indexer.toLocation(decl->getLocation())) { + auto symbol = indexer.addSymbol(decl); + symbol.addOccurrence(location); + symbol.addDefinition(location); + } + return true; + } + + bool VisitNamespaceAliasDecl(const clang::NamespaceAliasDecl* decl) { + /// `namespace Foo = Bar` + /// ^ ^~~~ reference + /// ^~~~ definition + if(Location location = indexer.toLocation(decl->getLocation())) { + auto symbol = indexer.addSymbol(decl); + symbol.addOccurrence(location); + symbol.addDefinition(location); + } + if(Location location = indexer.toLocation(decl->getTargetNameLoc())) { + auto symbol = indexer.addSymbol(decl->getNamespace()); + symbol.addOccurrence(location); + symbol.addReference(location); + } + return true; + } + + bool VisitUsingDirectiveDecl(const clang::UsingDirectiveDecl* decl) { + /// `using namespace Foo` + /// ^^^~~~~~~ reference + if(Location location = indexer.toLocation(decl->getLocation())) { + auto symbol = indexer.addSymbol(decl->getNominatedNamespace()); + symbol.addOccurrence(location); + symbol.addReference(location); + } + return true; + } + + bool VisitLabelDecl(const clang::LabelDecl* decl) { + /// `label:` + /// ^~~~ definition if(Location location = indexer.toLocation(decl->getLocation())) { auto symbol = indexer.addSymbol(decl); symbol.addOccurrence(location); @@ -220,6 +261,9 @@ public: return true; } + /// `TypedefDecl` and `TypedefNameDecl` are both inherited from `TypedefNameDecl`. + /// So we only need to handle `TypedefNameDecl`. + /// FIXME: `TypeAliasTemplateDecl`. bool VisitTypedefNameDecl(const clang::TypedefNameDecl* TND) { if(Location location = indexer.toLocation(TND->getLocation())) { auto symbol = indexer.addSymbol(TND); @@ -236,6 +280,8 @@ public: symbol.addOccurrence(location); symbol.addDeclarationOrDefinition(decl->isThisDeclarationADefinition(), location); symbol.addTypeDefinition(decl->getType()); + + // FIXME: ParamVarDecl } return true; } @@ -252,23 +298,16 @@ public: if(auto CCD = llvm::dyn_cast(CMD)) { symbol.addTypeDefinition(CCD->getThisType()); } + + // FIXME: CXXConversionDecl, CXXDestructorDecl } + + // FIXME: CXXDeductionGuideDecl } currentFunction = decl; return true; } - bool VisitUsingDirectiveDecl(const clang::UsingDirectiveDecl* decl) { - /// `using namespace Foo` - /// ^^^~~~~~~ reference - if(Location location = indexer.toLocation(decl->getLocation())) { - auto symbol = indexer.addSymbol(decl->getNominatedNamespace()); - symbol.addOccurrence(location); - symbol.addReference(location); - } - return true; - } - /// FIXME: how to resolve shadow decls? a name could refer to multiple decls. /// Don't need to handle UsingEnumDecl, it's handled by VisitTypeLoc. bool VisitUsingDecl(const clang::UsingDecl* decl) { @@ -282,6 +321,27 @@ public: return true; } + bool VisitBindingDecl(const clang::BindingDecl* decl) { + /// `auto [a, b] = std::make_pair(1, 2);` + /// ^~~~ definition + if(Location location = indexer.toLocation(decl->getLocation())) { + auto symbol = indexer.addSymbol(decl); + symbol.addOccurrence(location); + symbol.addDefinition(location); + symbol.addTypeDefinition(decl->getType()); + } + return true; + } + + bool VisitConceptDecl(const clang::ConceptDecl* decl) { + if(Location location = indexer.toLocation(decl->getLocation())) { + auto symbol = indexer.addSymbol(decl); + symbol.addOccurrence(location); + symbol.addDefinition(location); + } + return true; + } + /// ============================================================================ /// Statement /// ============================================================================