data: saving locations of return and parameter types
This change introduces the structure ParseTypeUsage for passing information about type usage from the parser to it's client. It is used for passing data type and location information about return types and parameter types, which now get saved to the corresponding edges in the Storage.
This commit is contained in:
@@ -12,3 +12,8 @@ ParseLocation::ParseLocation(
|
||||
, endColumnNumber(endColumnNumber)
|
||||
{
|
||||
}
|
||||
|
||||
bool ParseLocation::isValid() const
|
||||
{
|
||||
return startLineNumber > 0 && endLineNumber >= startLineNumber;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ struct ParseLocation
|
||||
unsigned int startLineNumber, unsigned int startColumnNumber,
|
||||
unsigned int endLineNumber, unsigned int endColumnNumber);
|
||||
|
||||
bool isValid() const;
|
||||
|
||||
const std::string filePath;
|
||||
unsigned int startLineNumber;
|
||||
unsigned int startColumnNumber;
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#include "data/parser/ParseTypeUsage.h"
|
||||
|
||||
ParseTypeUsage::ParseTypeUsage(const ParseLocation& location, const DataType& type)
|
||||
: location(location)
|
||||
, type(type)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef PARSE_TYPE_USAGE_H
|
||||
#define PARSE_TYPE_USAGE_H
|
||||
|
||||
#include "data/type/DataType.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
|
||||
struct ParseTypeUsage
|
||||
{
|
||||
ParseTypeUsage(const ParseLocation& location, const DataType& type);
|
||||
|
||||
const ParseLocation location;
|
||||
const DataType type;
|
||||
};
|
||||
|
||||
#endif // PARSE_TYPE_USAGE_H
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "data/parser/ParseVariable.h"
|
||||
|
||||
|
||||
ParseVariable::ParseVariable(const DataType& type, const std::string& fullName, bool isStatic)
|
||||
: type(type)
|
||||
, fullName(fullName)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/parser/ParseTypeUsage.h"
|
||||
#include "data/parser/ParseVariable.h"
|
||||
#include "data/type/DataType.h"
|
||||
|
||||
@@ -60,22 +61,18 @@ std::string ParserClient::addLocationSuffix(const std::string& str, const ParseL
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::string ParserClient::variableStr(const ParseVariable& variable, bool withName)
|
||||
std::string ParserClient::variableStr(const ParseVariable& variable)
|
||||
{
|
||||
std::string str = variable.type.getFullTypeName();
|
||||
if (withName)
|
||||
{
|
||||
str += " " + variable.fullName;
|
||||
}
|
||||
std::string str = variable.type.getFullTypeName() + " " + variable.fullName;
|
||||
return addStaticPrefix(str, variable.isStatic);
|
||||
}
|
||||
|
||||
std::string ParserClient::parameterStr(const std::vector<ParseVariable> parameters, bool withName)
|
||||
std::string ParserClient::parameterStr(const std::vector<ParseTypeUsage> parameters)
|
||||
{
|
||||
std::string str = "(";
|
||||
for (size_t i = 0; i < parameters.size(); i++)
|
||||
{
|
||||
str += variableStr(parameters[i], withName);
|
||||
str += parameters[i].type.getFullTypeName();
|
||||
if (i < parameters.size() - 1)
|
||||
{
|
||||
str += ", ";
|
||||
@@ -87,7 +84,7 @@ std::string ParserClient::parameterStr(const std::vector<ParseVariable> paramete
|
||||
std::string ParserClient::functionStr(
|
||||
const DataType& returnType,
|
||||
const std::string& fullName,
|
||||
const std::vector<ParseVariable>& parameters,
|
||||
const std::vector<ParseTypeUsage>& parameters,
|
||||
bool isConst
|
||||
){
|
||||
return addConstPrefix(
|
||||
@@ -100,10 +97,10 @@ std::string ParserClient::functionStr(
|
||||
std::string ParserClient::functionSignatureStr(
|
||||
const DataType& returnType,
|
||||
const std::string& fullName,
|
||||
const std::vector<ParseVariable>& parameters,
|
||||
const std::vector<ParseTypeUsage>& parameters,
|
||||
bool isConst
|
||||
){
|
||||
return addConstPrefix(fullName + parameterStr(parameters, false), isConst, false);
|
||||
return addConstPrefix(fullName + parameterStr(parameters), isConst, false);
|
||||
}
|
||||
|
||||
ParserClient::ParserClient()
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
struct ParseLocation;
|
||||
struct ParseTypeUsage;
|
||||
struct ParseVariable;
|
||||
class DataType;
|
||||
|
||||
@@ -29,18 +30,18 @@ public:
|
||||
static std::string addStaticPrefix(const std::string& str, bool isStatic);
|
||||
static std::string addConstPrefix(const std::string& str, bool isConst, bool atFront);
|
||||
static std::string addLocationSuffix(const std::string& str, const ParseLocation& location);
|
||||
static std::string variableStr(const ParseVariable& variable, bool withName = true);
|
||||
static std::string parameterStr(const std::vector<ParseVariable> parameters, bool withName = true);
|
||||
static std::string variableStr(const ParseVariable& variable);
|
||||
static std::string parameterStr(const std::vector<ParseTypeUsage> parameters);
|
||||
static std::string functionStr(
|
||||
const DataType& returnType,
|
||||
const std::string& fullName,
|
||||
const std::vector<ParseVariable>& parameters,
|
||||
const std::vector<ParseTypeUsage>& parameters,
|
||||
bool isConst
|
||||
);
|
||||
static std::string functionSignatureStr(
|
||||
const DataType& returnType,
|
||||
const std::string& fullName,
|
||||
const std::vector<ParseVariable>& parameters,
|
||||
const std::vector<ParseTypeUsage>& parameters,
|
||||
bool isConst
|
||||
);
|
||||
|
||||
@@ -57,11 +58,11 @@ public:
|
||||
virtual void onFieldParsed(const ParseLocation& location, const ParseVariable& variable, AccessType access) = 0;
|
||||
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& returnType,
|
||||
const std::vector<ParseVariable>& parameters) = 0;
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters) = 0;
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& returnType,
|
||||
const std::vector<ParseVariable>& parameters, AccessType access, AbstractionType abstraction,
|
||||
const ParseLocation& location, const std::string& fullName, const ParseTypeUsage& returnType,
|
||||
const std::vector<ParseTypeUsage>& parameters, AccessType access, AbstractionType abstraction,
|
||||
bool isConst, bool isStatic) = 0;
|
||||
|
||||
virtual void onNamespaceParsed(const ParseLocation& location, const std::string& fullName) = 0;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "data/parser/cxx/ASTBodyVisitor.h"
|
||||
#include "data/parser/cxx/utilityCxx.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/parser/ParseTypeUsage.h"
|
||||
#include "data/parser/ParseVariable.h"
|
||||
#include "data/type/DataType.h"
|
||||
|
||||
@@ -139,7 +140,7 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration)
|
||||
m_client->onFunctionParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
utility::qualTypeToDataType(declaration->getReturnType()),
|
||||
getParseTypeUsageOfReturnType(declaration),
|
||||
getParameters(declaration)
|
||||
);
|
||||
|
||||
@@ -170,7 +171,7 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration)
|
||||
m_client->onMethodParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
utility::qualTypeToDataType(declaration->getReturnType()),
|
||||
getParseTypeUsageOfReturnType(declaration),
|
||||
getParameters(declaration),
|
||||
convertAccessType(declaration->getAccess()),
|
||||
abstraction,
|
||||
@@ -285,6 +286,11 @@ bool ASTVisitor::hasValidLocation(const clang::Decl* declaration) const
|
||||
|
||||
ParseLocation ASTVisitor::getParseLocation(const clang::SourceRange& sourceRange) const
|
||||
{
|
||||
if (sourceRange.isInvalid())
|
||||
{
|
||||
return ParseLocation("", 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
const clang::SourceManager& sourceManager = m_context->getSourceManager();
|
||||
|
||||
const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin());
|
||||
@@ -299,10 +305,16 @@ ParseLocation ASTVisitor::getParseLocation(const clang::SourceRange& sourceRange
|
||||
);
|
||||
}
|
||||
|
||||
ParseTypeUsage ASTVisitor::getParseTypeUsage(clang::ValueDecl* declaration) const
|
||||
{
|
||||
return ParseTypeUsage(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
utility::qualTypeToDataType(declaration->getType())
|
||||
);
|
||||
}
|
||||
|
||||
ParseVariable ASTVisitor::getParseVariable(clang::ValueDecl* declaration) const
|
||||
{
|
||||
clang::QualType qualType = declaration->getType();
|
||||
|
||||
bool isStatic = false;
|
||||
if (clang::isa<clang::VarDecl>(declaration))
|
||||
{
|
||||
@@ -311,19 +323,43 @@ ParseVariable ASTVisitor::getParseVariable(clang::ValueDecl* declaration) const
|
||||
}
|
||||
|
||||
return ParseVariable(
|
||||
utility::qualTypeToDataType(qualType),
|
||||
utility::qualTypeToDataType(declaration->getType()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
isStatic
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<ParseVariable> ASTVisitor::getParameters(clang::FunctionDecl* declaration) const
|
||||
ParseTypeUsage ASTVisitor::getParseTypeUsageOfReturnType(clang::FunctionDecl* declaration) const
|
||||
{
|
||||
std::vector<ParseVariable> parameters;
|
||||
// TODO: use FunctionDecl::getReturnTypeSourceRange() in newer clang version
|
||||
clang::SourceRange range;
|
||||
const clang::TypeSourceInfo *TSI = declaration->getTypeSourceInfo();
|
||||
if (TSI)
|
||||
{
|
||||
clang::FunctionTypeLoc FTL = TSI->getTypeLoc().IgnoreParens().getAs<clang::FunctionTypeLoc>();
|
||||
if (FTL)
|
||||
{
|
||||
// Skip self-referential return types.
|
||||
range = clang::SourceRange(
|
||||
FTL.getReturnLoc().getLocStart(),
|
||||
declaration->getNameInfo().getLocStart().getLocWithOffset(-2)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return ParseTypeUsage(
|
||||
getParseLocation(range),
|
||||
utility::qualTypeToDataType(declaration->getReturnType())
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<ParseTypeUsage> ASTVisitor::getParameters(clang::FunctionDecl* declaration) const
|
||||
{
|
||||
std::vector<ParseTypeUsage> parameters;
|
||||
|
||||
for (unsigned i = 0; i < declaration->getNumParams(); i++)
|
||||
{
|
||||
parameters.push_back(getParseVariable(declaration->getParamDecl(i)));
|
||||
parameters.push_back(getParseTypeUsage(declaration->getParamDecl(i)));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
|
||||
@@ -45,8 +45,10 @@ public:
|
||||
private:
|
||||
bool hasValidLocation(const clang::Decl* declaration) const;
|
||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
||||
ParseTypeUsage getParseTypeUsage(clang::ValueDecl* declaration) const;
|
||||
ParseVariable getParseVariable(clang::ValueDecl* declaration) const;
|
||||
std::vector<ParseVariable> getParameters(clang::FunctionDecl* declaration) const;
|
||||
ParseTypeUsage getParseTypeUsageOfReturnType(clang::FunctionDecl* declaration) const;
|
||||
std::vector<ParseTypeUsage> getParameters(clang::FunctionDecl* declaration) const;
|
||||
DataType qualTypeToDataType(clang::QualType qualType);
|
||||
std::string getTypeName(const clang::QualType& qualType) const;
|
||||
ParserClient::AccessType convertAccessType(clang::AccessSpecifier) const;
|
||||
|
||||
Reference in New Issue
Block a user