data: parsing and saving method overrides

This change parses method overrides and saves them in the Storage with type EDGE_OVERRIDE.
This commit is contained in:
Eberhard Graether
2015-02-10 12:18:40 +01:00
parent 53eab0a517
commit 51c6675464
14 changed files with 195 additions and 52 deletions
+85
View File
@@ -599,6 +599,84 @@ public:
TS_ASSERT_EQUALS(client->inheritances[1], "C : private B <5:4 5:12>");
}
void test_cxx_parser_finds_method_override_when_virtual()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class A {\n"
" virtual void foo();\n"
"};\n"
"class B : public A {\n"
" void foo();\n"
"};"
);
TS_ASSERT_EQUALS(client->overrides.size(), 1);
TS_ASSERT_EQUALS(client->overrides[0], "void A::foo() -> void B::foo()");
}
void test_cxx_parser_finds_no_method_override_when_not_virtual()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class A {\n"
" void foo();\n"
"};\n"
"class B : public A {\n"
" void foo();\n"
"};"
);
TS_ASSERT_EQUALS(client->overrides.size(), 0);
}
void test_cxx_parser_finds_all_method_overrides()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class A {\n"
" virtual void foo();\n"
"};\n"
"class B : public A {\n"
" void foo();\n"
"};\n"
"class C : public B {\n"
" void foo();\n"
"};"
);
TS_ASSERT_EQUALS(client->overrides.size(), 2);
TS_ASSERT_EQUALS(client->overrides[0], "void A::foo() -> void B::foo()");
TS_ASSERT_EQUALS(client->overrides[1], "void B::foo() -> void C::foo()");
}
void test_cxx_parser_finds_no_method_overrides_on_different_signatures()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class A {\n"
" virtual void foo(int a);\n"
"};\n"
"class B : public A {\n"
" int foo(int a, int b);\n"
"};\n"
);
TS_ASSERT_EQUALS(client->overrides.size(), 0);
}
void test_cxx_parser_finds_method_overrides_on_different_return_types()
{
std::shared_ptr<TestParserClient> client = parseCode(
"class A {\n"
" virtual void foo();\n"
"};\n"
"class B : public A {\n"
" int foo();\n"
"};\n"
);
TS_ASSERT_EQUALS(client->overrides.size(), 1);
TS_ASSERT_EQUALS(client->overrides[0], "void A::foo() -> int B::foo()");
TS_ASSERT_EQUALS(client->errors.size(), 1);
}
void test_cxx_parser_finds_call_in_function()
{
std::shared_ptr<TestParserClient> client = parseCode(
@@ -1678,6 +1756,12 @@ private:
return 0;
}
virtual Id onMethodOverrideParsed(const ParseFunction& base, const ParseFunction& overrider)
{
overrides.push_back(functionStr(base) + " -> " + functionStr(overrider));
return 0;
}
virtual Id onCallParsed(
const ParseLocation& location, const ParseFunction& caller, const ParseFunction& callee)
{
@@ -1812,6 +1896,7 @@ private:
std::vector<std::string> structs;
std::vector<std::string> inheritances;
std::vector<std::string> overrides;
std::vector<std::string> calls;
std::vector<std::string> usages; // for variables
std::vector<std::string> typeUses; // for types
+3 -3
View File
@@ -100,10 +100,10 @@ public:
"7 nodes: "
"class:A field:A::count undefined_type:int undefined_type:void class:B function:main "
"undefined_function:B::B\n"
"13 edges: "
"14 edges: "
"child:A->A::count aggregation:A->int aggregation:A->void type_use:A::count->int inheritance:B->A "
"aggregation:B->void aggregation:B->int return_type:main->int type_usage:main->B child:B->B::B "
"call:main->B::B aggregation:main->B aggregation:main->A\n"
"aggregation:B->void aggregation:A->B aggregation:B->int return_type:main->int type_usage:main->B "
"child:B->B::B call:main->B::B aggregation:main->B aggregation:main->A\n"
);
}
+19
View File
@@ -407,6 +407,25 @@ public:
TS_ASSERT(isValidLocation(locations[0], 5));
}
void test_storage_saves_method_override()
{
TestStorage storage;
ParseFunction a(typeUsage("void"), utility::splitToVector("A::isMethod", "::"), parameters("bool"));
ParseFunction b(typeUsage("void"), utility::splitToVector("B::isMethod", "::"), parameters("bool"));
storage.onMethodParsed(validLocation(9), a, ParserClient::ACCESS_PRIVATE, ParserClient::ABSTRACTION_VIRTUAL, validLocation(4));
storage.onMethodParsed(validLocation(7), b, ParserClient::ACCESS_PRIVATE, ParserClient::ABSTRACTION_NONE, validLocation(3));
Id id = storage.onMethodOverrideParsed(a, b);
Edge* edge = storage.getEdgeWithId(id);
TS_ASSERT(edge);
TS_ASSERT_EQUALS(edge->getType(), Edge::EDGE_OVERRIDE);
TS_ASSERT_EQUALS(edge->getFrom()->getFullName(), "A::isMethod");
TS_ASSERT_EQUALS(edge->getTo()->getFullName(), "B::isMethod");
}
void test_storage_saves_call()
{
TestStorage storage;