logic: add type information of variable decl to name hierarchy
* implemented this feature for both, CXX and Java * adjusted tests to reflect these changes * added NameElement and NameHierarchy to Java code * created more specialized JavaDeclName classes: JavaFunctionDeclName and JavaVariableDeclName * implemented recording static modifier for Java methods and variables fortune cookie message = You will enjoy true success in whatever you do.
This commit is contained in:
@@ -24,6 +24,8 @@ add_files(
|
||||
data/parser/cxx/name/CxxQualifierFlags.h
|
||||
data/parser/cxx/name/CxxTypeName.cpp
|
||||
data/parser/cxx/name/CxxTypeName.h
|
||||
data/parser/cxx/name/CxxVariableDeclName.cpp
|
||||
data/parser/cxx/name/CxxVariableDeclName.h
|
||||
|
||||
data/parser/cxx/name_resolver/CxxDeclNameResolver.cpp
|
||||
data/parser/cxx/name_resolver/CxxDeclNameResolver.h
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#include "data/parser/cxx/name/CxxVariableDeclName.h"
|
||||
|
||||
CxxVariableDeclName::CxxVariableDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> typeName,
|
||||
bool isStatic
|
||||
)
|
||||
: CxxDeclName(name, templateParameterNames)
|
||||
, m_typeName(typeName)
|
||||
, m_isStatic(isStatic)
|
||||
{
|
||||
}
|
||||
|
||||
CxxVariableDeclName::CxxVariableDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> typeName,
|
||||
bool isStatic,
|
||||
std::shared_ptr<CxxName> parent
|
||||
)
|
||||
: CxxDeclName(name, templateParameterNames, parent)
|
||||
, m_typeName(typeName)
|
||||
, m_isStatic(isStatic)
|
||||
{
|
||||
}
|
||||
|
||||
CxxVariableDeclName::~CxxVariableDeclName()
|
||||
{
|
||||
}
|
||||
|
||||
NameHierarchy CxxVariableDeclName::toNameHierarchy() const
|
||||
{
|
||||
std::string signaturePrefix = "";
|
||||
if (m_isStatic)
|
||||
{
|
||||
signaturePrefix += "static ";
|
||||
}
|
||||
signaturePrefix += CxxTypeName::makeUnsolvedIfNull(m_typeName)->toString();
|
||||
|
||||
const std::string signaturePostfix = "";
|
||||
|
||||
NameHierarchy ret = CxxDeclName::toNameHierarchy();
|
||||
std::shared_ptr<NameElement> nameElement = std::make_shared<NameElement>(
|
||||
ret.back()->getName(),
|
||||
NameElement::Signature(signaturePrefix, signaturePostfix)
|
||||
);
|
||||
|
||||
ret.pop();
|
||||
ret.push(nameElement);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#ifndef CXX_VARIABLE_DECL_NAME_H
|
||||
#define CXX_VARIABLE_DECL_NAME_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "data/parser/cxx/name/CxxDeclName.h"
|
||||
#include "data/parser/cxx/name/CxxTypeName.h"
|
||||
|
||||
class CxxVariableDeclName: public CxxDeclName
|
||||
{
|
||||
public:
|
||||
CxxVariableDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> typeName,
|
||||
bool isStatic
|
||||
);
|
||||
|
||||
CxxVariableDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> typeName,
|
||||
bool isStatic,
|
||||
std::shared_ptr<CxxName> parent
|
||||
);
|
||||
|
||||
virtual ~CxxVariableDeclName();
|
||||
|
||||
virtual NameHierarchy toNameHierarchy() const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<CxxTypeName> m_typeName;
|
||||
bool m_isStatic;
|
||||
};
|
||||
|
||||
#endif // CXX_VARIABLE_DECL_NAME_H
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <clang/AST/ASTContext.h>
|
||||
|
||||
#include "data/parser/cxx/name/CxxFunctionDeclName.h"
|
||||
#include "data/parser/cxx/name/CxxVariableDeclName.h"
|
||||
#include "data/parser/cxx/name_resolver/CxxSpecifierNameResolver.h"
|
||||
#include "data/parser/cxx/name_resolver/CxxTemplateArgumentNameResolver.h"
|
||||
#include "data/parser/cxx/name_resolver/CxxTypeNameResolver.h"
|
||||
@@ -270,6 +271,14 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
|
||||
}
|
||||
return std::make_shared<CxxDeclName>(declNameString, templateParameters);
|
||||
}
|
||||
else if (clang::isa<clang::FieldDecl>(declaration))
|
||||
{
|
||||
const clang::FieldDecl* fieldDecl = clang::dyn_cast<clang::FieldDecl>(declaration);
|
||||
CxxTypeNameResolver typenNameResolver(getIgnoredContextDecls());
|
||||
typenNameResolver.ignoreContextDecl(fieldDecl);
|
||||
std::shared_ptr<CxxTypeName> typeName = CxxTypeName::makeUnsolvedIfNull(typenNameResolver.getName(fieldDecl->getType()));
|
||||
return std::make_shared<CxxVariableDeclName>(declNameString, std::vector<std::string>(), typeName, false);
|
||||
}
|
||||
else if (clang::isa<clang::NamespaceDecl>(declaration) && clang::dyn_cast<clang::NamespaceDecl>(declaration)->isAnonymousNamespace())
|
||||
{
|
||||
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
|
||||
@@ -299,6 +308,28 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
|
||||
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("parameter", presumedBegin), std::vector<std::string>());
|
||||
}
|
||||
else if (clang::isa<clang::VarDecl>(declaration))
|
||||
{
|
||||
const clang::VarDecl* varDecl = clang::dyn_cast<clang::VarDecl>(declaration);
|
||||
if (varDecl->getParentFunctionOrMethod() == NULL)
|
||||
{
|
||||
bool isStatic = false;
|
||||
if (varDecl->getAccess() != clang::AS_none)
|
||||
{
|
||||
// var is declared inside a type and must be static (non-statics are stored as clang::FieldDecl)
|
||||
isStatic = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing todo, varDecl is global (and non-static)
|
||||
}
|
||||
|
||||
CxxTypeNameResolver typenNameResolver(getIgnoredContextDecls());
|
||||
typenNameResolver.ignoreContextDecl(varDecl);
|
||||
std::shared_ptr<CxxTypeName> typeName = CxxTypeName::makeUnsolvedIfNull(typenNameResolver.getName(varDecl->getType()));
|
||||
return std::make_shared<CxxVariableDeclName>(declNameString, std::vector<std::string>(), typeName, isStatic);
|
||||
}
|
||||
}
|
||||
|
||||
if (declNameString.size() > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user