logic: add filename info to static functions (issue #515)
This commit is contained in:
@@ -8,7 +8,8 @@
|
||||
#include "utility/utilityString.h"
|
||||
|
||||
FilePath::FilePath()
|
||||
: m_exists(false)
|
||||
: m_path("")
|
||||
, m_exists(false)
|
||||
, m_checkedExists(false)
|
||||
, m_isDirectory(false)
|
||||
, m_checkedIsDirectory(false)
|
||||
|
||||
@@ -22,6 +22,8 @@ add_files(
|
||||
data/parser/cxx/name/CxxName.h
|
||||
data/parser/cxx/name/CxxQualifierFlags.cpp
|
||||
data/parser/cxx/name/CxxQualifierFlags.h
|
||||
data/parser/cxx/name/CxxStaticFunctionDeclName.cpp
|
||||
data/parser/cxx/name/CxxStaticFunctionDeclName.h
|
||||
data/parser/cxx/name/CxxTypeName.cpp
|
||||
data/parser/cxx/name/CxxTypeName.h
|
||||
data/parser/cxx/name/CxxVariableDeclName.cpp
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "data/parser/cxx/name/CxxFunctionDeclName.h"
|
||||
|
||||
CxxFunctionDeclName::CxxFunctionDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
std::vector<std::shared_ptr<CxxTypeName>> parameterTypeNames,
|
||||
bool isConst,
|
||||
bool isStatic
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const bool isConst,
|
||||
const bool isStatic
|
||||
)
|
||||
: CxxDeclName(name, templateParameterNames)
|
||||
, m_returnTypeName(returnTypeName)
|
||||
@@ -17,12 +17,12 @@ CxxFunctionDeclName::CxxFunctionDeclName(
|
||||
}
|
||||
|
||||
CxxFunctionDeclName::CxxFunctionDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
std::vector<std::shared_ptr<CxxTypeName>> parameterTypeNames,
|
||||
bool isConst,
|
||||
bool isStatic,
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const bool isConst,
|
||||
const bool isStatic,
|
||||
std::shared_ptr<CxxName> parent
|
||||
)
|
||||
: CxxDeclName(name, templateParameterNames, parent)
|
||||
|
||||
@@ -11,21 +11,21 @@ class CxxFunctionDeclName: public CxxDeclName
|
||||
{
|
||||
public:
|
||||
CxxFunctionDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
std::vector<std::shared_ptr<CxxTypeName>> parameterTypeNames,
|
||||
bool isConst,
|
||||
bool isStatic
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const bool isConst,
|
||||
const bool isStatic
|
||||
);
|
||||
|
||||
CxxFunctionDeclName(
|
||||
std::string name,
|
||||
std::vector<std::string> templateParameterNames,
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
std::vector<std::shared_ptr<CxxTypeName>> parameterTypeNames,
|
||||
bool isConst,
|
||||
bool isStatic,
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const bool isConst,
|
||||
const bool isStatic,
|
||||
std::shared_ptr<CxxName> parent
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#include "data/parser/cxx/name/CxxStaticFunctionDeclName.h"
|
||||
|
||||
CxxStaticFunctionDeclName::CxxStaticFunctionDeclName(
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const std::string& translationUnitFileName
|
||||
)
|
||||
: CxxFunctionDeclName(name, templateParameterNames, returnTypeName, parameterTypeNames, false, true)
|
||||
, m_translationUnitFileName(translationUnitFileName)
|
||||
{
|
||||
}
|
||||
|
||||
CxxStaticFunctionDeclName::CxxStaticFunctionDeclName(
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const std::string& translationUnitFileName,
|
||||
std::shared_ptr<CxxName> parent
|
||||
)
|
||||
: CxxFunctionDeclName(name, templateParameterNames, returnTypeName, parameterTypeNames, false, true, parent)
|
||||
, m_translationUnitFileName(translationUnitFileName)
|
||||
{
|
||||
}
|
||||
|
||||
CxxStaticFunctionDeclName::~CxxStaticFunctionDeclName()
|
||||
{
|
||||
}
|
||||
|
||||
NameHierarchy CxxStaticFunctionDeclName::toNameHierarchy() const
|
||||
{
|
||||
NameHierarchy ret = CxxFunctionDeclName::toNameHierarchy();
|
||||
const NameElement::Signature sig = ret.back()->getSignature();
|
||||
|
||||
std::shared_ptr<NameElement> nameElement = std::make_shared<NameElement>(
|
||||
ret.back()->getName(),
|
||||
NameElement::Signature(sig.getPrefix(), sig.getPostfix() + " (" + m_translationUnitFileName + ")")
|
||||
);
|
||||
|
||||
ret.pop();
|
||||
ret.push(nameElement);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#ifndef CXX_STATIC_FUNCTION_DECL_NAME_H
|
||||
#define CXX_STATIC_FUNCTION_DECL_NAME_H
|
||||
|
||||
#include "data/parser/cxx/name/CxxFunctionDeclName.h"
|
||||
|
||||
class CxxStaticFunctionDeclName: public CxxFunctionDeclName
|
||||
{
|
||||
public:
|
||||
CxxStaticFunctionDeclName(
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const std::string& translationUnitFileName
|
||||
);
|
||||
|
||||
CxxStaticFunctionDeclName(
|
||||
const std::string& name,
|
||||
const std::vector<std::string>& templateParameterNames,
|
||||
std::shared_ptr<CxxTypeName> returnTypeName,
|
||||
const std::vector<std::shared_ptr<CxxTypeName>>& parameterTypeNames,
|
||||
const std::string& translationUnitFileName,
|
||||
std::shared_ptr<CxxName> parent
|
||||
);
|
||||
|
||||
virtual ~CxxStaticFunctionDeclName();
|
||||
|
||||
virtual NameHierarchy toNameHierarchy() const;
|
||||
|
||||
private:
|
||||
std::string m_translationUnitFileName;
|
||||
};
|
||||
|
||||
#endif // CXX_FUNCTION_DECL_NAME_H
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "data/parser/cxx/name/CxxFunctionDeclName.h"
|
||||
#include "data/parser/cxx/name/CxxVariableDeclName.h"
|
||||
#include "data/parser/cxx/name/CxxStaticFunctionDeclName.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"
|
||||
@@ -253,6 +254,17 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
|
||||
parameterTypeNames.push_back(CxxTypeName::makeUnsolvedIfNull(typenNameResolver.getName(functionDecl->parameters()[i]->getType())));
|
||||
}
|
||||
|
||||
if (!clang::isa<clang::CXXMethodDecl>(declaration) && isStatic)
|
||||
{
|
||||
return std::make_shared<CxxStaticFunctionDeclName>(
|
||||
functionName,
|
||||
templateArguments,
|
||||
returnTypeName,
|
||||
parameterTypeNames,
|
||||
getTranslationUnitMainFilePath(declaration).fileName()
|
||||
);
|
||||
}
|
||||
|
||||
return std::make_shared<CxxFunctionDeclName>(
|
||||
functionName,
|
||||
templateArguments,
|
||||
@@ -339,20 +351,13 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
|
||||
// different instances of the variable that all MUST contain the same value to be merged into a single node in Sourcetrail.
|
||||
std::string scopeFileName = "";
|
||||
{
|
||||
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
|
||||
if (varDecl->getType().isConstQualified())
|
||||
{
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
|
||||
scopeFileName = FilePath(presumedBegin.getFilename()).fileName();
|
||||
scopeFileName = getDeclarationFilePath(declaration).fileName();
|
||||
}
|
||||
else
|
||||
{
|
||||
clang::FileID fileId = sourceManager.getMainFileID();
|
||||
if (fileId.isValid())
|
||||
{
|
||||
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
|
||||
scopeFileName = FilePath(utility::getFileNameOfFileEntry(fileEntry)).fileName();
|
||||
}
|
||||
scopeFileName = getTranslationUnitMainFilePath(declaration).fileName();
|
||||
}
|
||||
}
|
||||
if (!scopeFileName.empty())
|
||||
@@ -377,6 +382,25 @@ std::shared_ptr<CxxDeclName> CxxDeclNameResolver::getDeclName(const clang::Named
|
||||
return std::make_shared<CxxDeclName>(getNameForAnonymousSymbol("symbol", presumedBegin), std::vector<std::string>());
|
||||
}
|
||||
|
||||
FilePath CxxDeclNameResolver::getTranslationUnitMainFilePath(const clang::Decl* declaration)
|
||||
{
|
||||
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
|
||||
clang::FileID fileId = sourceManager.getMainFileID();
|
||||
if (fileId.isValid())
|
||||
{
|
||||
const clang::FileEntry* fileEntry = sourceManager.getFileEntryForID(fileId);
|
||||
return FilePath(utility::getFileNameOfFileEntry(fileEntry));
|
||||
}
|
||||
return FilePath();
|
||||
}
|
||||
|
||||
FilePath CxxDeclNameResolver::getDeclarationFilePath(const clang::Decl* declaration)
|
||||
{
|
||||
const clang::SourceManager& sourceManager = declaration->getASTContext().getSourceManager();
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(declaration->getLocStart());
|
||||
return FilePath(presumedBegin.getFilename());
|
||||
}
|
||||
|
||||
std::string CxxDeclNameResolver::getNameForAnonymousSymbol(const std::string& symbolKindName, const clang::PresumedLoc& presumedBegin)
|
||||
{
|
||||
if (presumedBegin.isValid())
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "data/parser/cxx/name/CxxDeclName.h"
|
||||
#include "data/parser/cxx/name_resolver/CxxNameResolver.h"
|
||||
|
||||
class FilePath;
|
||||
|
||||
class CxxDeclNameResolver: public CxxNameResolver
|
||||
{
|
||||
public:
|
||||
@@ -16,6 +18,8 @@ public:
|
||||
private:
|
||||
std::shared_ptr<CxxName> getContextName(const clang::DeclContext* declaration);
|
||||
std::shared_ptr<CxxDeclName> getDeclName(const clang::NamedDecl* declaration);
|
||||
FilePath getTranslationUnitMainFilePath(const clang::Decl* declaration);
|
||||
FilePath getDeclarationFilePath(const clang::Decl* declaration);
|
||||
std::string getNameForAnonymousSymbol(const std::string& symbolKindName, const clang::PresumedLoc& presumedBegin);
|
||||
std::string getTemplateParameterString(const clang::NamedDecl* parameter);
|
||||
std::string getTemplateParameterTypeString(const clang::NonTypeTemplateParmDecl* parameter);
|
||||
|
||||
@@ -200,7 +200,7 @@ public:
|
||||
);
|
||||
|
||||
TS_ASSERT(utility::containsElement<std::string>(
|
||||
client->functions, "static int ceil(float) <1:1 <1:12 1:15> 4:1>"
|
||||
client->functions, "static int ceil(float) (input.cc) <1:1 <1:12 1:15> 4:1>"
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user