data: storing type modifiers in edges
- ASTVisitor uses DataType instead of string to pass on type information. - Edges can have EdgeComponents. - EdgeComponentDataType stores information that modifies the type a ...TYPE_OF edge points to. - EdgeComponentDataType can create a complete DataType using it's internal information. - Fixed a bug where DataTypeModifiers did not apply their qualifiers.
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#include "data/parser/ParseVariable.h"
|
||||
|
||||
ParseVariable::ParseVariable(const std::string& typeName, const std::string& fullName, bool isConst, bool isStatic)
|
||||
: typeName(typeName)
|
||||
|
||||
ParseVariable::ParseVariable(const DataType& type, const std::string& fullName, bool isStatic)
|
||||
: type(type)
|
||||
, fullName(fullName)
|
||||
, isConst(isConst)
|
||||
, isStatic(isStatic)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "data/type/DataType.h"
|
||||
|
||||
struct ParseVariable
|
||||
{
|
||||
ParseVariable(const std::string& typeName, const std::string& fullName, bool isConst, bool isStatic);
|
||||
ParseVariable(const DataType& type, const std::string& fullName, bool isStatic);
|
||||
|
||||
const std::string typeName;
|
||||
const DataType type;
|
||||
const std::string fullName;
|
||||
const bool isConst;
|
||||
const bool isStatic;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
struct ParseLocation;
|
||||
struct ParseVariable;
|
||||
struct DataType;
|
||||
|
||||
class ParserClient
|
||||
{
|
||||
@@ -27,9 +28,8 @@ public:
|
||||
virtual ~ParserClient();
|
||||
|
||||
virtual void onTypedefParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const std::string& underlyingFullName,
|
||||
AccessType access
|
||||
) = 0;
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& underlyingType,
|
||||
AccessType access) = 0;
|
||||
virtual void onClassParsed(const ParseLocation& location, const std::string& fullName, AccessType access) = 0;
|
||||
virtual void onStructParsed(const ParseLocation& location, const std::string& fullName, AccessType access) = 0;
|
||||
|
||||
@@ -37,11 +37,12 @@ public:
|
||||
virtual void onFieldParsed(const ParseLocation& location, const ParseVariable& variable, AccessType access) = 0;
|
||||
|
||||
virtual void onFunctionParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const std::string& returnTypeName,
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& returnType,
|
||||
const std::vector<ParseVariable>& parameters) = 0;
|
||||
virtual void onMethodParsed(const ParseLocation& location, const std::string& fullName,
|
||||
const std::string& returnTypeName, const std::vector<ParseVariable>& parameters, AccessType access,
|
||||
AbstractionType abstraction, bool isConst, bool isStatic) = 0;
|
||||
virtual void onMethodParsed(
|
||||
const ParseLocation& location, const std::string& fullName, const DataType& returnType,
|
||||
const std::vector<ParseVariable>& parameters, AccessType access, AbstractionType abstraction,
|
||||
bool isConst, bool isStatic) = 0;
|
||||
|
||||
virtual void onNamespaceParsed(const ParseLocation& location, const std::string& fullName) = 0;
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "data/parser/cxx/ASTVisitor.h"
|
||||
|
||||
#include "data/parser/cxx/ASTBodyVisitor.h"
|
||||
#include "data/parser/cxx/utilityCxx.h"
|
||||
#include "data/parser/ParseLocation.h"
|
||||
#include "data/parser/ParseVariable.h"
|
||||
#include "utility/utilityClang.h"
|
||||
#include "data/type/DataType.h"
|
||||
|
||||
ASTVisitor::ASTVisitor(clang::ASTContext* context, std::shared_ptr<ParserClient> client)
|
||||
@@ -28,7 +28,7 @@ bool ASTVisitor::VisitTypedefDecl(const clang::TypedefDecl* declaration)
|
||||
m_client->onTypedefParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
declaration->getUnderlyingType().getAsString(),
|
||||
utility::qualTypeToDataType(declaration->getUnderlyingType()),
|
||||
convertAccessType(declaration->getAccess())
|
||||
);
|
||||
}
|
||||
@@ -139,7 +139,7 @@ bool ASTVisitor::VisitFunctionDecl(clang::FunctionDecl* declaration)
|
||||
m_client->onFunctionParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
getTypeName(declaration->getReturnType()),
|
||||
utility::qualTypeToDataType(declaration->getReturnType()),
|
||||
getParameters(declaration)
|
||||
);
|
||||
|
||||
@@ -170,7 +170,7 @@ bool ASTVisitor::VisitCXXMethodDecl(clang::CXXMethodDecl* declaration)
|
||||
m_client->onMethodParsed(
|
||||
getParseLocation(declaration->getSourceRange()),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
getTypeName(declaration->getReturnType()),
|
||||
utility::qualTypeToDataType(declaration->getReturnType()),
|
||||
getParameters(declaration),
|
||||
convertAccessType(declaration->getAccess()),
|
||||
abstraction,
|
||||
@@ -301,7 +301,7 @@ ParseLocation ASTVisitor::getParseLocation(const clang::SourceRange& sourceRange
|
||||
|
||||
ParseVariable ASTVisitor::getParseVariable(clang::ValueDecl* declaration) const
|
||||
{
|
||||
clang::QualType type = declaration->getType();
|
||||
clang::QualType qualType = declaration->getType();
|
||||
|
||||
bool isStatic = false;
|
||||
if (clang::isa<clang::VarDecl>(declaration))
|
||||
@@ -311,9 +311,8 @@ ParseVariable ASTVisitor::getParseVariable(clang::ValueDecl* declaration) const
|
||||
}
|
||||
|
||||
return ParseVariable(
|
||||
getTypeName(type),
|
||||
utility::qualTypeToDataType(qualType),
|
||||
declaration->getQualifiedNameAsString(),
|
||||
type.isConstQualified(),
|
||||
isStatic
|
||||
);
|
||||
}
|
||||
@@ -332,7 +331,7 @@ std::vector<ParseVariable> ASTVisitor::getParameters(clang::FunctionDecl* declar
|
||||
|
||||
std::string ASTVisitor::getTypeName(const clang::QualType& qualType) const
|
||||
{
|
||||
DataType dataType(qualType);
|
||||
DataType dataType = utility::qualTypeToDataType(qualType);
|
||||
return dataType.getRawTypeName();
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ private:
|
||||
ParseLocation getParseLocation(const clang::SourceRange& sourceRange) const;
|
||||
ParseVariable getParseVariable(clang::ValueDecl* declaration) const;
|
||||
std::vector<ParseVariable> getParameters(clang::FunctionDecl* declaration) const;
|
||||
DataType qualTypeToDataType(clang::QualType qualType);
|
||||
std::string getTypeName(const clang::QualType& qualType) const;
|
||||
ParserClient::AccessType convertAccessType(clang::AccessSpecifier) const;
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
#include "data/parser/cxx/utilityCxx.h"
|
||||
|
||||
#include "data/type/DataType.h"
|
||||
#include "data/type/modifier/DataTypeModifierPointer.h"
|
||||
#include "data/type/DataTypeModifierStack.h"
|
||||
#include "data/type/DataTypeQualifierList.h"
|
||||
|
||||
namespace utility
|
||||
{
|
||||
DataType qualTypeToDataType(clang::QualType qualType)
|
||||
{
|
||||
std::string typeName;
|
||||
DataTypeQualifierList qualifierList;
|
||||
DataTypeModifierStack modifierStack;
|
||||
|
||||
while (true)
|
||||
{
|
||||
const clang::Type* type = qualType.getTypePtr();
|
||||
if (type->isPointerType())
|
||||
{
|
||||
std::shared_ptr<DataTypeModifier> modifier = std::make_shared<DataTypeModifierPointer>();
|
||||
if (qualType.isConstQualified())
|
||||
modifier->addQualifier(DataTypeQualifierList::QUALIFIER_CONST);
|
||||
modifierStack.push(modifier);
|
||||
|
||||
qualType = type->getPointeeType();
|
||||
}
|
||||
else if (type->isStructureOrClassType() || type->isEnumeralType())
|
||||
{
|
||||
typeName = qualType.getAsString();
|
||||
|
||||
// we are working on the string here to not lose the namespace information stored in the name.
|
||||
size_t nameStartPosition = typeName.find(' ');
|
||||
if (nameStartPosition != typeName.npos)
|
||||
{
|
||||
nameStartPosition += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
nameStartPosition = 0;
|
||||
}
|
||||
typeName = typeName.substr(nameStartPosition, typeName.size());
|
||||
|
||||
//m_typeName = qualType.getBaseTypeIdentifier()->getName(); // this one does not keep namespace information.
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
typeName = qualType.getUnqualifiedType().getAsString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (qualType.isConstQualified())
|
||||
qualifierList.addQualifier(DataTypeQualifierList::QUALIFIER_CONST);
|
||||
|
||||
return DataType(typeName, qualifierList, modifierStack);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
#ifndef UTILITY_CLANG_H
|
||||
#define UTILITY_CLANG_H
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "clang/AST/Type.h"
|
||||
|
||||
class DataType;
|
||||
|
||||
namespace utility
|
||||
{
|
||||
DataType qualTypeToDataType(clang::QualType qualType);
|
||||
}
|
||||
|
||||
#endif // UTILITY_CLANG_H
|
||||
Reference in New Issue
Block a user