From 5640c86d21765efd41283d770d1ac0a1297a0c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bendeg=C3=BAz=20Fily=C3=B3?= Date: Fri, 30 Oct 2020 13:06:07 +0100 Subject: [PATCH 1/3] Ast visitor function for using declarations. --- plugins/cpp/parser/src/clangastvisitor.h | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugins/cpp/parser/src/clangastvisitor.h b/plugins/cpp/parser/src/clangastvisitor.h index 699d6334f..b5f83bae4 100644 --- a/plugins/cpp/parser/src/clangastvisitor.h +++ b/plugins/cpp/parser/src/clangastvisitor.h @@ -956,6 +956,33 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor return true; } + + + + bool VisitUsingDecl(clang::UsingDecl* ud_) + { + + //--- CppAstNode ---// + + model::CppAstNodePtr astNode = std::make_shared(); + + astNode->astValue = getSourceText( + _clangSrcMgr, + ud_->getBeginLoc(), + ud_->getLocation(), + true); + std::string usr = getUSR(ud_); + astNode->location = getFileLoc(ud_->getBeginLoc(), ud_->getEndLoc()); + astNode->entityHash = util::fnvHash(usr); + astNode->astType = model::CppAstNode::AstType::Definition; + astNode->id = model::createIdentifier(*astNode); + + if (insertToCache(ud_, astNode)) + _astNodes.push_back(astNode); + + return true; + } + bool VisitCXXConstructExpr(clang::CXXConstructExpr* ce_) { From 3c682a00baf37bfae35ca9a5abd285652cd59469 Mon Sep 17 00:00:00 2001 From: filbeofITK Date: Thu, 1 Jul 2021 12:20:57 +0200 Subject: [PATCH 2/3] Added the using directive definition visitor function, so it works with namespaces as well. --- plugins/cpp/parser/src/clangastvisitor.h | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugins/cpp/parser/src/clangastvisitor.h b/plugins/cpp/parser/src/clangastvisitor.h index b5f83bae4..fc4314822 100644 --- a/plugins/cpp/parser/src/clangastvisitor.h +++ b/plugins/cpp/parser/src/clangastvisitor.h @@ -983,6 +983,33 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor return true; } + + bool VisitUsingDirectiveDecl(clang::UsingDirectiveDecl* udd_) + { + //--- CppAstNode ---// + + model::CppAstNodePtr astNode = std::make_shared(); + + astNode->astValue = getSourceText( + _clangSrcMgr, + udd_->getBeginLoc(), + udd_->getLocation(), + true); + std::string usr = getUSR(udd_); + astNode->location = getFileLoc(udd_->getBeginLoc(), udd_->getEndLoc()); + astNode->entityHash = util::fnvHash(usr); + astNode->astType = model::CppAstNode::AstType::Definition; + astNode->id = model::createIdentifier(*astNode); + + if (insertToCache(udd_, astNode)) + _astNodes.push_back(astNode); + + return true; + + + } + + bool VisitCXXConstructExpr(clang::CXXConstructExpr* ce_) { From e3ecefa888f7126e9267180d592fc3fe554acc16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Cser=C3=A9p?= Date: Sat, 11 Feb 2023 00:42:10 +0100 Subject: [PATCH 3/3] Fix VisitUsingDirectiveDecl --- plugins/cpp/parser/src/clangastvisitor.h | 30 ++++++++++-------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/plugins/cpp/parser/src/clangastvisitor.h b/plugins/cpp/parser/src/clangastvisitor.h index fc4314822..306b9c360 100644 --- a/plugins/cpp/parser/src/clangastvisitor.h +++ b/plugins/cpp/parser/src/clangastvisitor.h @@ -957,24 +957,22 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor return true; } - - bool VisitUsingDecl(clang::UsingDecl* ud_) { - //--- CppAstNode ---// model::CppAstNodePtr astNode = std::make_shared(); - + astNode->astValue = getSourceText( _clangSrcMgr, ud_->getBeginLoc(), ud_->getLocation(), true); - std::string usr = getUSR(ud_); astNode->location = getFileLoc(ud_->getBeginLoc(), ud_->getEndLoc()); - astNode->entityHash = util::fnvHash(usr); - astNode->astType = model::CppAstNode::AstType::Definition; + astNode->entityHash = util::fnvHash(getUSR(ud_)); + astNode->symbolType = model::CppAstNode::SymbolType::Other; + astNode->astType = model::CppAstNode::AstType::Usage; + astNode->id = model::createIdentifier(*astNode); if (insertToCache(ud_, astNode)) @@ -983,34 +981,32 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor return true; } - bool VisitUsingDirectiveDecl(clang::UsingDirectiveDecl* udd_) { - //--- CppAstNode ---// + //--- CppAstNode ---// model::CppAstNodePtr astNode = std::make_shared(); - + + const clang::NamespaceDecl* nd = udd_->getNominatedNamespace(); + astNode->astValue = getSourceText( _clangSrcMgr, udd_->getBeginLoc(), udd_->getLocation(), true); - std::string usr = getUSR(udd_); astNode->location = getFileLoc(udd_->getBeginLoc(), udd_->getEndLoc()); - astNode->entityHash = util::fnvHash(usr); - astNode->astType = model::CppAstNode::AstType::Definition; + astNode->entityHash = util::fnvHash(getUSR(nd)); + astNode->symbolType = model::CppAstNode::SymbolType::Namespace; + astNode->astType = model::CppAstNode::AstType::Usage; + astNode->id = model::createIdentifier(*astNode); if (insertToCache(udd_, astNode)) _astNodes.push_back(astNode); return true; - - } - - bool VisitCXXConstructExpr(clang::CXXConstructExpr* ce_) { model::CppAstNodePtr astNode = std::make_shared();