Skip to content

Commit fb1ceda

Browse files
authored
Handle namespace alias declarations (#658)
1 parent d171d6b commit fb1ceda

File tree

4 files changed

+94
-11
lines changed

4 files changed

+94
-11
lines changed

plugins/cpp/model/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ set(ODB_SOURCES
66
include/model/cppfunction.h
77
include/model/cppinheritance.h
88
include/model/cppnamespace.h
9+
include/model/cppnamespacealias.h
910
include/model/cpprelation.h
1011
include/model/cpptypedef.h
1112
include/model/cpprecord.h

plugins/cpp/model/include/model/cppastnode.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct CppAstNode
3434
Enum,
3535
EnumConstant,
3636
Namespace,
37+
NamespaceAlias,
3738
StringLiteral,
3839
File = 500,
3940
Other = 1000
@@ -103,6 +104,7 @@ inline std::string symbolTypeToString(CppAstNode::SymbolType type_)
103104
case CppAstNode::SymbolType::Enum: return "Enum";
104105
case CppAstNode::SymbolType::EnumConstant: return "EnumConstant";
105106
case CppAstNode::SymbolType::Namespace: return "Namespace";
107+
case CppAstNode::SymbolType::NamespaceAlias: return "NamespaceAlias";
106108
case CppAstNode::SymbolType::StringLiteral: return "StringLiteral";
107109
case CppAstNode::SymbolType::File: return "File";
108110
case CppAstNode::SymbolType::Other: return "Other";
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef CC_MODEL_CPPNAMESPACEALIAS_H
2+
#define CC_MODEL_CPPNAMESPACEALIAS_H
3+
4+
#include "cppentity.h"
5+
6+
namespace cc
7+
{
8+
namespace model
9+
{
10+
11+
#pragma db object
12+
struct CppNamespaceAlias : CppEntity
13+
{
14+
std::string toString() const
15+
{
16+
std::string ret("CppNamespaceAlias");
17+
18+
ret
19+
.append("\nid = ").append(std::to_string(id))
20+
.append("\nentityHash = ").append(std::to_string(entityHash))
21+
.append("\nqualifiedName = ").append(qualifiedName);
22+
23+
if (!tags.empty())
24+
{
25+
ret.append("\ntags =");
26+
for (const Tag& tag : tags)
27+
ret.append(' ' + tagToString(tag));
28+
}
29+
30+
return ret;
31+
}
32+
};
33+
34+
typedef std::shared_ptr<CppNamespaceAlias> CppNamespaceAliasPtr;
35+
36+
}
37+
}
38+
39+
#endif

plugins/cpp/parser/src/clangastvisitor.h

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#include <model/cppinheritance-odb.hxx>
2626
#include <model/cppnamespace.h>
2727
#include <model/cppnamespace-odb.hxx>
28+
#include <model/cppnamespacealias.h>
29+
#include <model/cppnamespacealias-odb.hxx>
2830
#include <model/cpprelation.h>
2931
#include <model/cpprelation-odb.hxx>
3032
#include <model/cpprecord.h>
@@ -117,6 +119,7 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
117119
util::persistAll(_typedefs, _ctx.db);
118120
util::persistAll(_variables, _ctx.db);
119121
util::persistAll(_namespaces, _ctx.db);
122+
util::persistAll(_namespaceAliases, _ctx.db);
120123
util::persistAll(_members, _ctx.db);
121124
util::persistAll(_inheritances, _ctx.db);
122125
util::persistAll(_friends, _ctx.db);
@@ -958,6 +961,43 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
958961
return true;
959962
}
960963

964+
bool VisitNamespaceAliasDecl(clang::NamespaceAliasDecl* nad_)
965+
{
966+
//--- CppAstNode ---//
967+
968+
model::CppAstNodePtr astNode = std::make_shared<model::CppAstNode>();
969+
970+
astNode->astValue = getSourceText(
971+
_clangSrcMgr,
972+
nad_->getBeginLoc(),
973+
nad_->getLocation(),
974+
true);
975+
976+
astNode->location = getFileLoc(nad_->getBeginLoc(), nad_->getEndLoc());
977+
astNode->entityHash = util::fnvHash(getUSR(nad_->getAliasedNamespace()));
978+
astNode->symbolType = model::CppAstNode::SymbolType::NamespaceAlias;
979+
astNode->astType = model::CppAstNode::AstType::Definition;
980+
981+
astNode->id = model::createIdentifier(*astNode);
982+
983+
if (insertToCache(nad_, astNode))
984+
_astNodes.push_back(astNode);
985+
else
986+
return true;
987+
988+
//--- CppNamespaceAlias ---//
989+
990+
model::CppNamespaceAliasPtr nsa = std::make_shared<model::CppNamespaceAlias>();
991+
_namespaceAliases.push_back(nsa);
992+
993+
nsa->astNodeId = astNode->id;
994+
nsa->entityHash = astNode->entityHash;
995+
nsa->name = nad_->getNameAsString();
996+
nsa->qualifiedName = nad_->getQualifiedNameAsString();
997+
998+
return true;
999+
}
1000+
9611001
bool VisitCXXConstructExpr(clang::CXXConstructExpr* ce_)
9621002
{
9631003
model::CppAstNodePtr astNode = std::make_shared<model::CppAstNode>();
@@ -1469,18 +1509,19 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
14691509
return false;
14701510
}
14711511

1472-
std::vector<model::CppAstNodePtr> _astNodes;
1473-
std::vector<model::CppEnumConstantPtr> _enumConstants;
1474-
std::vector<model::CppEnumPtr> _enums;
1475-
std::vector<model::CppFunctionPtr> _functions;
1512+
std::vector<model::CppAstNodePtr> _astNodes;
1513+
std::vector<model::CppEnumConstantPtr> _enumConstants;
1514+
std::vector<model::CppEnumPtr> _enums;
1515+
std::vector<model::CppFunctionPtr> _functions;
14761516
std::vector<model::CppRecordPtr> _types;
1477-
std::vector<model::CppTypedefPtr> _typedefs;
1478-
std::vector<model::CppVariablePtr> _variables;
1479-
std::vector<model::CppNamespacePtr> _namespaces;
1480-
std::vector<model::CppMemberTypePtr> _members;
1481-
std::vector<model::CppInheritancePtr> _inheritances;
1482-
std::vector<model::CppFriendshipPtr> _friends;
1483-
std::vector<model::CppRelationPtr> _relations;
1517+
std::vector<model::CppTypedefPtr> _typedefs;
1518+
std::vector<model::CppVariablePtr> _variables;
1519+
std::vector<model::CppNamespacePtr> _namespaces;
1520+
std::vector<model::CppNamespaceAliasPtr> _namespaceAliases;
1521+
std::vector<model::CppMemberTypePtr> _members;
1522+
std::vector<model::CppInheritancePtr> _inheritances;
1523+
std::vector<model::CppFriendshipPtr> _friends;
1524+
std::vector<model::CppRelationPtr> _relations;
14841525

14851526
// TODO: Maybe we don't even need a stack, if functions can't be nested.
14861527
// Check lambda.

0 commit comments

Comments
 (0)