Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/cpp/model/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions plugins/cpp/model/include/model/cppastnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct CppAstNode
Enum,
EnumConstant,
Namespace,
NamespaceAlias,
StringLiteral,
File = 500,
Other = 1000
Expand Down Expand Up @@ -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";
Expand Down
39 changes: 39 additions & 0 deletions plugins/cpp/model/include/model/cppnamespacealias.h
Original file line number Diff line number Diff line change
@@ -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<CppNamespaceAlias> CppNamespaceAliasPtr;

}
}

#endif
63 changes: 52 additions & 11 deletions plugins/cpp/parser/src/clangastvisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <model/cppinheritance-odb.hxx>
#include <model/cppnamespace.h>
#include <model/cppnamespace-odb.hxx>
#include <model/cppnamespacealias.h>
#include <model/cppnamespacealias-odb.hxx>
#include <model/cpprelation.h>
#include <model/cpprelation-odb.hxx>
#include <model/cpprecord.h>
Expand Down Expand Up @@ -117,6 +119,7 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
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);
Expand Down Expand Up @@ -958,6 +961,43 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return true;
}

bool VisitNamespaceAliasDecl(clang::NamespaceAliasDecl* nad_)
{
//--- CppAstNode ---//

model::CppAstNodePtr astNode = std::make_shared<model::CppAstNode>();

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<model::CppNamespaceAlias>();
_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<model::CppAstNode>();
Expand Down Expand Up @@ -1464,18 +1504,19 @@ class ClangASTVisitor : public clang::RecursiveASTVisitor<ClangASTVisitor>
return false;
}

std::vector<model::CppAstNodePtr> _astNodes;
std::vector<model::CppEnumConstantPtr> _enumConstants;
std::vector<model::CppEnumPtr> _enums;
std::vector<model::CppFunctionPtr> _functions;
std::vector<model::CppAstNodePtr> _astNodes;
std::vector<model::CppEnumConstantPtr> _enumConstants;
std::vector<model::CppEnumPtr> _enums;
std::vector<model::CppFunctionPtr> _functions;
std::vector<model::CppRecordPtr> _types;
std::vector<model::CppTypedefPtr> _typedefs;
std::vector<model::CppVariablePtr> _variables;
std::vector<model::CppNamespacePtr> _namespaces;
std::vector<model::CppMemberTypePtr> _members;
std::vector<model::CppInheritancePtr> _inheritances;
std::vector<model::CppFriendshipPtr> _friends;
std::vector<model::CppRelationPtr> _relations;
std::vector<model::CppTypedefPtr> _typedefs;
std::vector<model::CppVariablePtr> _variables;
std::vector<model::CppNamespacePtr> _namespaces;
std::vector<model::CppNamespaceAliasPtr> _namespaceAliases;
std::vector<model::CppMemberTypePtr> _members;
std::vector<model::CppInheritancePtr> _inheritances;
std::vector<model::CppFriendshipPtr> _friends;
std::vector<model::CppRelationPtr> _relations;

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