diff --git a/plugins/cpp/model/CMakeLists.txt b/plugins/cpp/model/CMakeLists.txt index b914f115a..3e3d76ab8 100644 --- a/plugins/cpp/model/CMakeLists.txt +++ b/plugins/cpp/model/CMakeLists.txt @@ -6,6 +6,7 @@ set(ODB_SOURCES include/model/cppfunction.h include/model/cppinheritance.h include/model/cppnamespace.h + include/model/cppnamespacealias.h include/model/cpprelation.h include/model/cpptypedef.h include/model/cpprecord.h diff --git a/plugins/cpp/model/include/model/cppastnode.h b/plugins/cpp/model/include/model/cppastnode.h index ab6a8bc48..21e3dd7dd 100644 --- a/plugins/cpp/model/include/model/cppastnode.h +++ b/plugins/cpp/model/include/model/cppastnode.h @@ -34,6 +34,7 @@ struct CppAstNode Enum, EnumConstant, Namespace, + NamespaceAlias, StringLiteral, File = 500, Other = 1000 @@ -103,6 +104,7 @@ inline std::string symbolTypeToString(CppAstNode::SymbolType type_) case CppAstNode::SymbolType::Enum: return "Enum"; case CppAstNode::SymbolType::EnumConstant: return "EnumConstant"; case CppAstNode::SymbolType::Namespace: return "Namespace"; + case CppAstNode::SymbolType::NamespaceAlias: return "NamespaceAlias"; case CppAstNode::SymbolType::StringLiteral: return "StringLiteral"; case CppAstNode::SymbolType::File: return "File"; case CppAstNode::SymbolType::Other: return "Other"; diff --git a/plugins/cpp/model/include/model/cppnamespacealias.h b/plugins/cpp/model/include/model/cppnamespacealias.h new file mode 100644 index 000000000..facc6548f --- /dev/null +++ b/plugins/cpp/model/include/model/cppnamespacealias.h @@ -0,0 +1,39 @@ +#ifndef CC_MODEL_CPPNAMESPACEALIAS_H +#define CC_MODEL_CPPNAMESPACEALIAS_H + +#include "cppentity.h" + +namespace cc +{ +namespace model +{ + +#pragma db object +struct CppNamespaceAlias : CppEntity +{ + std::string toString() const + { + std::string ret("CppNamespaceAlias"); + + ret + .append("\nid = ").append(std::to_string(id)) + .append("\nentityHash = ").append(std::to_string(entityHash)) + .append("\nqualifiedName = ").append(qualifiedName); + + if (!tags.empty()) + { + ret.append("\ntags ="); + for (const Tag& tag : tags) + ret.append(' ' + tagToString(tag)); + } + + return ret; + } +}; + +typedef std::shared_ptr CppNamespaceAliasPtr; + +} +} + +#endif diff --git a/plugins/cpp/parser/src/clangastvisitor.h b/plugins/cpp/parser/src/clangastvisitor.h index 0321f66ef..41665bef0 100644 --- a/plugins/cpp/parser/src/clangastvisitor.h +++ b/plugins/cpp/parser/src/clangastvisitor.h @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include #include #include @@ -117,6 +119,7 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor util::persistAll(_typedefs, _ctx.db); util::persistAll(_variables, _ctx.db); util::persistAll(_namespaces, _ctx.db); + util::persistAll(_namespaceAliases, _ctx.db); util::persistAll(_members, _ctx.db); util::persistAll(_inheritances, _ctx.db); util::persistAll(_friends, _ctx.db); @@ -958,6 +961,43 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor return true; } + bool VisitNamespaceAliasDecl(clang::NamespaceAliasDecl* nad_) + { + //--- CppAstNode ---// + + model::CppAstNodePtr astNode = std::make_shared(); + + astNode->astValue = getSourceText( + _clangSrcMgr, + nad_->getBeginLoc(), + nad_->getLocation(), + true); + + astNode->location = getFileLoc(nad_->getBeginLoc(), nad_->getEndLoc()); + astNode->entityHash = util::fnvHash(getUSR(nad_->getAliasedNamespace())); + astNode->symbolType = model::CppAstNode::SymbolType::NamespaceAlias; + astNode->astType = model::CppAstNode::AstType::Definition; + + astNode->id = model::createIdentifier(*astNode); + + if (insertToCache(nad_, astNode)) + _astNodes.push_back(astNode); + else + return true; + + //--- CppNamespaceAlias ---// + + model::CppNamespaceAliasPtr nsa = std::make_shared(); + _namespaceAliases.push_back(nsa); + + nsa->astNodeId = astNode->id; + nsa->entityHash = astNode->entityHash; + nsa->name = nad_->getNameAsString(); + nsa->qualifiedName = nad_->getQualifiedNameAsString(); + + return true; + } + bool VisitCXXConstructExpr(clang::CXXConstructExpr* ce_) { model::CppAstNodePtr astNode = std::make_shared(); @@ -1464,18 +1504,19 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor return false; } - std::vector _astNodes; - std::vector _enumConstants; - std::vector _enums; - std::vector _functions; + std::vector _astNodes; + std::vector _enumConstants; + std::vector _enums; + std::vector _functions; std::vector _types; - std::vector _typedefs; - std::vector _variables; - std::vector _namespaces; - std::vector _members; - std::vector _inheritances; - std::vector _friends; - std::vector _relations; + std::vector _typedefs; + std::vector _variables; + std::vector _namespaces; + std::vector _namespaceAliases; + std::vector _members; + std::vector _inheritances; + std::vector _friends; + std::vector _relations; // TODO: Maybe we don't even need a stack, if functions can't be nested. // Check lambda.