data: template arguments default parameters
* implemented parsing of template argument default parameters. * added tests for default arguments of template parameters. fortune cookie message = If you continually give, you will continually have.
This commit is contained in:
@@ -496,6 +496,18 @@ Id Storage::onTemplateRecordArgumentTypeParsed(
|
||||
return 0;
|
||||
}
|
||||
|
||||
Id Storage::onTemplateDefaultArgumentTypeParsed(
|
||||
const ParseTypeUsage& defaultArgumentType, const std::vector<std::string>& templateArgumentTypeNameHierarchy)
|
||||
{
|
||||
log("template default argument", utility::join(defaultArgumentType.dataType.getTypeNameHierarchy(), "::") + " -> " + utility::join(templateArgumentTypeNameHierarchy, "::"), defaultArgumentType.location);
|
||||
Node* templateDefaultArgumentNode = addNodeHierarchy(Node::NODE_UNDEFINED_TYPE, defaultArgumentType.dataType.getTypeNameHierarchy());
|
||||
addTokenLocation(templateDefaultArgumentNode, defaultArgumentType.location);
|
||||
Node* templateArgumentNode = addNodeHierarchy(Node::NODE_UNDEFINED_TYPE, templateArgumentTypeNameHierarchy);
|
||||
Edge* edge = m_graph.createEdge(Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT_OF, templateDefaultArgumentNode, templateArgumentNode);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Id Storage::onTemplateRecordSpecializationParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& specializedRecordNameHierarchy,
|
||||
const RecordType specializedRecordType, const std::vector<std::string>& specializedFromNameHierarchy)
|
||||
|
||||
@@ -87,6 +87,8 @@ public:
|
||||
virtual Id onTemplateRecordArgumentTypeParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& templateArgumentTypeNameHierarchy,
|
||||
const std::vector<std::string>& templateRecordNameHierarchy);
|
||||
virtual Id onTemplateDefaultArgumentTypeParsed(
|
||||
const ParseTypeUsage& type, const std::vector<std::string>& templateArgumentTypeNameHierarchy);
|
||||
|
||||
virtual Id onTemplateRecordSpecializationParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& specializedRecordNameHierarchy,
|
||||
|
||||
+14
-13
@@ -17,20 +17,21 @@ 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_TEMPLATE_PARAMETER_OF = 0x200,
|
||||
EDGE_TEMPLATE_ARGUMENT_OF = 0x400,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x800,
|
||||
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_ARGUMENT_OF = 0x400,
|
||||
EDGE_TEMPLATE_DEFAULT_ARGUMENT_OF = 0x800,
|
||||
EDGE_TEMPLATE_SPECIALIZATION_OF = 0x1000,
|
||||
|
||||
EDGE_AGGREGATION = 0x1000
|
||||
EDGE_AGGREGATION = 0x2000
|
||||
};
|
||||
|
||||
Edge(EdgeType type, Node* from, Node* to);
|
||||
|
||||
@@ -103,6 +103,8 @@ public:
|
||||
virtual Id onTemplateRecordArgumentTypeParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& templateArgumentTypeNameHierarchy,
|
||||
const std::vector<std::string>& templateRecordNameHierarchy) = 0;
|
||||
virtual Id onTemplateDefaultArgumentTypeParsed(
|
||||
const ParseTypeUsage& type, const std::vector<std::string>& templateArgumentTypeNameHierarchy) = 0;
|
||||
virtual Id onTemplateRecordSpecializationParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& specializedRecordNameHierarchy,
|
||||
const RecordType specializedRecordType, const std::vector<std::string>& specializedFromNameHierarchy) = 0;
|
||||
|
||||
@@ -266,7 +266,18 @@ bool ASTVisitor::VisitEnumConstantDecl(clang::EnumConstantDecl* declaration)
|
||||
utility::getDeclNameHierarchy(declaration)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ASTVisitor::VisitTemplateTypeParmDecl(clang::TemplateTypeParmDecl *declaration)
|
||||
{
|
||||
if (declaration->hasDefaultArgument())
|
||||
{
|
||||
m_client->onTemplateDefaultArgumentTypeParsed(
|
||||
getParseTypeUsage(declaration->getDefaultArgumentInfo()->getTypeLoc(), declaration->getDefaultArgument()),
|
||||
utility::getDeclNameHierarchy(declaration)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ public:
|
||||
virtual bool VisitEnumDecl(clang::EnumDecl* declaration); // enums
|
||||
virtual bool VisitEnumConstantDecl(clang::EnumConstantDecl* declaration); // enum fields
|
||||
|
||||
virtual bool VisitTemplateTypeParmDecl(clang::TemplateTypeParmDecl *declaration);
|
||||
virtual bool VisitClassTemplateDecl(clang::ClassTemplateDecl* declaration);
|
||||
virtual bool VisitClassTemplatePartialSpecializationDecl(clang::ClassTemplatePartialSpecializationDecl* declaration);
|
||||
virtual bool VisitFunctionTemplateDecl(clang::FunctionTemplateDecl *declaration);
|
||||
|
||||
@@ -121,7 +121,14 @@ namespace utility
|
||||
LOG_ERROR("unhandled declaration type");
|
||||
}
|
||||
contextNameHierarchy = getContextNameHierarchy(declaration->getDeclContext());
|
||||
contextNameHierarchy.push_back(declName);
|
||||
if (clang::isa<clang::TemplateTypeParmDecl>(declaration))
|
||||
{
|
||||
contextNameHierarchy.back() += "::" + declName;
|
||||
}
|
||||
else
|
||||
{
|
||||
contextNameHierarchy.push_back(declName);
|
||||
}
|
||||
}
|
||||
return contextNameHierarchy;
|
||||
}
|
||||
|
||||
@@ -1445,6 +1445,19 @@ public:
|
||||
TS_ASSERT_EQUALS(client->methods[0], "private A<T>::T A<T>::foo() <4:4 4:6>");
|
||||
}
|
||||
|
||||
void test_cxx_parser_finds_template_default_argument_type_of_template_class()
|
||||
{
|
||||
std::shared_ptr<TestParserClient> client = parseCode(
|
||||
"template <typename T = int>\n"
|
||||
"class A\n"
|
||||
"{\n"
|
||||
"};\n"
|
||||
);
|
||||
|
||||
TS_ASSERT_EQUALS(client->templateDefaultArgumentTypes.size(), 1);
|
||||
TS_ASSERT_EQUALS(client->templateDefaultArgumentTypes[0], "int -> A<T>::T <1:24 1:26>");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1725,6 +1738,15 @@ private:
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Id onTemplateDefaultArgumentTypeParsed(
|
||||
const ParseTypeUsage& defaultArgumentType, const std::vector<std::string>& templateArgumentTypeNameHierarchy)
|
||||
{
|
||||
templateDefaultArgumentTypes.push_back(
|
||||
addLocationSuffix(utility::join(defaultArgumentType.dataType.getTypeNameHierarchy(), "::") + " -> " + utility::join(templateArgumentTypeNameHierarchy, "::"), defaultArgumentType.location)
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual Id onTemplateRecordSpecializationParsed(
|
||||
const ParseLocation& location, const std::vector<std::string>& specializedRecordNameHierarchy,
|
||||
const RecordType specializedRecordType, const std::vector<std::string>& specializedFromNameHierarchy)
|
||||
@@ -1774,6 +1796,7 @@ private:
|
||||
std::vector<std::string> typeUses; // for types
|
||||
std::vector<std::string> templateParameterTypes;
|
||||
std::vector<std::string> templateArgumentTypes;
|
||||
std::vector<std::string> templateDefaultArgumentTypes;
|
||||
std::vector<std::string> templateSpecializations;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user