data: basic template parsing
* Implemented basic parsing and storage of template parameter types, template classes and template functions * Added template specialization edge. * Implemented handling of partial specializations. Needs some more tweaking. * Added a lot of test code for template stuff (still needs some cases to be tested) * Removed the isTemplateParameterType from DataType, since it shouldn't be needed * Function qualTypeToDataType uses clang PrintingPolicy to fetch the desired format. * Merged a lot of code for getting the correct names and name hierarchies of definitions * Removed TokenComponentDataType * Merged both of the Storage::addTypeEdge(...) functions * Added "-fno-delayed-template-parsing" flag to parser for parsing test code.
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "data/graph/Node.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
#include "data/graph/token_component/TokenComponentDataType.h"
|
||||
#include "utility/logging/logging.h"
|
||||
|
||||
Edge::Edge(EdgeType type, Node* from, Node* to)
|
||||
@@ -93,24 +92,6 @@ void Edge::addComponentAccess(std::shared_ptr<TokenComponentAccess> component)
|
||||
}
|
||||
}
|
||||
|
||||
void Edge::addComponentDataType(std::shared_ptr<TokenComponentDataType> component)
|
||||
{
|
||||
if (getComponent<TokenComponentDataType>())
|
||||
{
|
||||
LOG_ERROR("TokenComponentDataType has been set before!");
|
||||
}
|
||||
else if (m_type != EDGE_TYPEDEF_OF && m_type != EDGE_TYPE_OF &&
|
||||
m_type != EDGE_RETURN_TYPE_OF && m_type != EDGE_PARAMETER_TYPE_OF &&
|
||||
m_type != EDGE_TYPE_USAGE)
|
||||
{
|
||||
LOG_ERROR("TokenComponentDataType can't be set on edge of type: " + getTypeString());
|
||||
}
|
||||
else
|
||||
{
|
||||
addComponent(component);
|
||||
}
|
||||
}
|
||||
|
||||
std::string Edge::getTypeString(EdgeType type) const
|
||||
{
|
||||
switch (type)
|
||||
@@ -133,6 +114,10 @@ std::string Edge::getTypeString(EdgeType type) const
|
||||
return "usage";
|
||||
case EDGE_TYPEDEF_OF:
|
||||
return "typedef";
|
||||
case EDGE_TEMPLATE_PARAMETER_OF:
|
||||
return "template parameter";
|
||||
case EDGE_TEMPLATE_SPECIALIZATION_OF:
|
||||
return "template specialization";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
+11
-10
@@ -16,15 +16,17 @@ public:
|
||||
typedef int EdgeTypeMask;
|
||||
enum EdgeType : EdgeTypeMask
|
||||
{
|
||||
EDGE_MEMBER = 0x1,
|
||||
EDGE_TYPE_OF = 0x2,
|
||||
EDGE_RETURN_TYPE_OF = 0x4,
|
||||
EDGE_PARAMETER_TYPE_OF = 0x8,
|
||||
EDGE_TYPE_USAGE = 0x10,
|
||||
EDGE_USAGE = 0x20,
|
||||
EDGE_CALL = 0x40,
|
||||
EDGE_INHERITANCE = 0x80,
|
||||
EDGE_TYPEDEF_OF = 0x100
|
||||
EDGE_MEMBER = 0x1,
|
||||
EDGE_TYPE_OF = 0x2,
|
||||
EDGE_RETURN_TYPE_OF = 0x4,
|
||||
EDGE_PARAMETER_TYPE_OF = 0x8,
|
||||
EDGE_TYPE_USAGE = 0x10,
|
||||
EDGE_USAGE = 0x20,
|
||||
EDGE_CALL = 0x40,
|
||||
EDGE_INHERITANCE = 0x80,
|
||||
EDGE_TYPEDEF_OF = 0x100,
|
||||
EDGE_TEMPLATE_PARAMETER_OF = 0x200,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x400
|
||||
};
|
||||
|
||||
Edge(EdgeType type, Node* from, Node* to);
|
||||
@@ -45,7 +47,6 @@ public:
|
||||
|
||||
// Component setters
|
||||
void addComponentAccess(std::shared_ptr<TokenComponentAccess> component);
|
||||
void addComponentDataType(std::shared_ptr<TokenComponentDataType> component);
|
||||
|
||||
// Logging.
|
||||
std::string getTypeString(EdgeType type) const;
|
||||
|
||||
@@ -313,6 +313,8 @@ std::string Node::getTypeString(NodeType type) const
|
||||
return "enum";
|
||||
case NODE_TYPEDEF:
|
||||
return "typedef";
|
||||
case NODE_TEMPLATE_PARAMETER_TYPE:
|
||||
return "template parameter type";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
+15
-13
@@ -19,21 +19,23 @@ class Node: public Token
|
||||
{
|
||||
public:
|
||||
typedef int NodeTypeMask;
|
||||
// list undefined types first to ensure that they get replaced by their defined counterparts when it is parsed.
|
||||
enum NodeType : NodeTypeMask
|
||||
{
|
||||
NODE_UNDEFINED = 0x1,
|
||||
NODE_UNDEFINED_FUNCTION = 0x2,
|
||||
NODE_UNDEFINED_VARIABLE = 0x4,
|
||||
NODE_UNDEFINED_TYPE = 0x8,
|
||||
NODE_STRUCT = 0x10,
|
||||
NODE_CLASS = 0x20,
|
||||
NODE_GLOBAL_VARIABLE = 0x40,
|
||||
NODE_FIELD = 0x80,
|
||||
NODE_FUNCTION = 0x100,
|
||||
NODE_METHOD = 0x200,
|
||||
NODE_NAMESPACE = 0x400,
|
||||
NODE_ENUM = 0x800,
|
||||
NODE_TYPEDEF = 0x1000
|
||||
NODE_UNDEFINED = 0x1,
|
||||
NODE_UNDEFINED_FUNCTION = 0x2,
|
||||
NODE_UNDEFINED_VARIABLE = 0x4,
|
||||
NODE_UNDEFINED_TYPE = 0x8,
|
||||
NODE_STRUCT = 0x10,
|
||||
NODE_CLASS = 0x20,
|
||||
NODE_GLOBAL_VARIABLE = 0x40,
|
||||
NODE_FIELD = 0x80,
|
||||
NODE_FUNCTION = 0x100,
|
||||
NODE_METHOD = 0x200,
|
||||
NODE_NAMESPACE = 0x400,
|
||||
NODE_ENUM = 0x800,
|
||||
NODE_TYPEDEF = 0x1000,
|
||||
NODE_TEMPLATE_PARAMETER_TYPE = 0x2000
|
||||
};
|
||||
|
||||
Node(NodeType type, const std::string& name);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
#include "data/graph/token_component/TokenComponentAbstraction.h"
|
||||
#include "data/graph/token_component/TokenComponentAccess.h"
|
||||
#include "data/graph/token_component/TokenComponentConst.h"
|
||||
#include "data/graph/token_component/TokenComponentDataType.h"
|
||||
#include "data/graph/token_component/TokenComponentStatic.h"
|
||||
|
||||
/*
|
||||
@@ -87,18 +86,7 @@ protected:
|
||||
{
|
||||
addNode(node);
|
||||
}
|
||||
|
||||
Edge* edge = node->findEdgeOfType(Edge::EDGE_TYPE_OF);
|
||||
if (!edge)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TokenComponentDataType* type = edge->getComponent<TokenComponentDataType>();
|
||||
if (type && type->isConstQualified())
|
||||
{
|
||||
addNode(node);
|
||||
}
|
||||
// TODO: add const component to field and variable nodes..
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "data/graph/token_component/TokenComponentDataType.h"
|
||||
|
||||
#include "data/type/DataType.h"
|
||||
|
||||
TokenComponentDataType::TokenComponentDataType(
|
||||
const DataTypeQualifierList qualifierList, const DataTypeModifierStack modifierStack
|
||||
)
|
||||
: m_qualifierList(qualifierList)
|
||||
, m_modifierStack(modifierStack)
|
||||
{
|
||||
}
|
||||
|
||||
TokenComponentDataType::~TokenComponentDataType()
|
||||
{
|
||||
}
|
||||
|
||||
std::shared_ptr<TokenComponent> TokenComponentDataType::copy() const
|
||||
{
|
||||
return std::make_shared<TokenComponentDataType>(*this);
|
||||
}
|
||||
|
||||
DataType TokenComponentDataType::getDataType(const std::string& typeName) const
|
||||
{
|
||||
return DataType(typeName, m_qualifierList, m_modifierStack);
|
||||
}
|
||||
|
||||
std::string TokenComponentDataType::getQualifiedTypeName(const std::string& typeName) const
|
||||
{
|
||||
return m_modifierStack.applyTo(m_qualifierList.applyTo(typeName));
|
||||
}
|
||||
|
||||
bool TokenComponentDataType::isConstQualified() const
|
||||
{
|
||||
return m_qualifierList.hasQualifier(DataTypeQualifierList::QUALIFIER_CONST);
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef TOKEN_COMPONENT_DATA_TYPE_H
|
||||
#define TOKEN_COMPONENT_DATA_TYPE_H
|
||||
|
||||
#include "data/graph/token_component/TokenComponent.h"
|
||||
#include "data/type/DataTypeModifierStack.h"
|
||||
#include "data/type/DataTypeQualifierList.h"
|
||||
|
||||
class DataType;
|
||||
|
||||
class TokenComponentDataType
|
||||
: public TokenComponent
|
||||
{
|
||||
public:
|
||||
TokenComponentDataType(const DataTypeQualifierList qualifierList, const DataTypeModifierStack modifierStack);
|
||||
virtual ~TokenComponentDataType();
|
||||
|
||||
virtual std::shared_ptr<TokenComponent> copy() const;
|
||||
|
||||
DataType getDataType(const std::string& typeName) const;
|
||||
std::string getQualifiedTypeName(const std::string& typeName) const;
|
||||
|
||||
bool isConstQualified() const;
|
||||
|
||||
private:
|
||||
const DataTypeQualifierList m_qualifierList;
|
||||
const DataTypeModifierStack m_modifierStack;
|
||||
};
|
||||
|
||||
#endif // TOKEN_COMPONENT_DATA_TYPE_H
|
||||
Reference in New Issue
Block a user