test: Replaced DumpParserClient and TestParserClient with TestIntermediateStorage to ease switch to new ParserClient API

This commit is contained in:
Eberhard Graether
2018-10-15 15:05:15 +02:00
parent 3d5b90364a
commit aab29b241e
167 changed files with 51652 additions and 49716 deletions
+10
View File
@@ -66,6 +66,16 @@ std::shared_ptr<TextAccess> TextAccess::createFromString(const std::string& text
return result;
}
std::shared_ptr<TextAccess> TextAccess::createFromLines(const std::vector<std::string>& lines, const FilePath& filePath)
{
std::shared_ptr<TextAccess> result(new TextAccess());
result->m_lines = lines;
result->m_filePath = filePath;
return result;
}
TextAccess::~TextAccess()
{
}
+1
View File
@@ -12,6 +12,7 @@ class TextAccess
public:
static std::shared_ptr<TextAccess> createFromFile(const FilePath& filePath);
static std::shared_ptr<TextAccess> createFromString(const std::string& text, const FilePath& filePath = FilePath());
static std::shared_ptr<TextAccess> createFromLines(const std::vector<std::string>& lines, const FilePath& filePath = FilePath());
virtual ~TextAccess();
+1 -2
View File
@@ -1,10 +1,9 @@
add_files(
TEST
helper/DumpParserClient.h
helper/TestFileRegister.cpp
helper/TestFileRegister.h
helper/TestParserClient.h
helper/TestIntermediateStorage.h
TestSuiteFixture.cpp
TestSuiteFixture.h
+32 -8
View File
@@ -3,11 +3,13 @@
#include <fstream>
#include <iostream>
#include "IndexerCommandCxx.h"
#include "CxxParser.h"
#include "DumpParserClient.h"
#include "ApplicationSettings.h"
#include "CxxParser.h"
#include "FileRegister.h"
#include "IndexerCommandCxx.h"
#include "IndexerStateInfo.h"
#include "ParserClientImpl.h"
#include "TestIntermediateStorage.h"
#include "TextAccess.h"
#include "utility.h"
#include "utilityString.h"
@@ -18,6 +20,23 @@ public:
static const bool s_updateExpectedOutput = false;
static const bool s_trackTime = true;
void test_index_tictactoe_project()
{
#ifdef NDEBUG
processSourceFiles(
L"TicTacToe",
{
FilePath("artificial_player.cpp"),
FilePath("field.cpp"),
FilePath("player.cpp"),
FilePath("tictactoe.cpp"),
FilePath("human_player.cpp"),
FilePath("main.cpp"),
}
);
#endif // NDEBUG
}
void test_index_box2d_project()
{
#ifdef _WIN32
@@ -164,7 +183,11 @@ private:
utility::append(compilerFlags, IndexerCommandCxx::getCompilerFlagsForFrameworkSearchPaths(
ApplicationSettings::getInstance()->getFrameworkSearchPathsExpanded()
));
compilerFlags.emplace_back(L"--target=x86_64-pc-windows-msvc");
#ifdef _WIN32
// compilerFlags.emplace_back(L"--target=x86_64-pc-windows-msvc");
#else // _WIN32
compilerFlags.emplace_back(L"-xc++");
#endif // _WIN32
compilerFlags.emplace_back(L"-std=c++1z");
compilerFlags.emplace_back(sourceFilePath.wstr());
@@ -174,9 +197,8 @@ private:
excludedFilters
);
std::shared_ptr<DumpParserClient> parserClient = std::make_shared<DumpParserClient>();
CxxParser parser(parserClient, fileRegister, std::make_shared<IndexerStateInfo>());
TestIntermediateStorage storage;
CxxParser parser(std::make_shared<ParserClientImpl>(&storage), fileRegister, std::make_shared<IndexerStateInfo>());
std::shared_ptr<IndexerCommandCxx> command = std::make_shared<IndexerCommandCxx>(
sourceFilePath,
@@ -191,7 +213,9 @@ private:
parser.buildIndex(command);
m_duration += TimeStamp::now().deltaMS(startTime);
return TextAccess::createFromString(utility::encodeToUtf8(parserClient->m_lines));
storage.generateStringLists();
return TextAccess::createFromLines(storage.m_lines);
}
size_t m_duration;
File diff suppressed because it is too large Load Diff
+9 -7
View File
@@ -3,12 +3,13 @@
#include <fstream>
#include <iostream>
#include "ApplicationSettings.h"
#include "FileRegister.h"
#include "IndexerCommandJava.h"
#include "JavaEnvironmentFactory.h"
#include "JavaParser.h"
#include "DumpParserClient.h"
#include "ApplicationSettings.h"
#include "FileRegister.h"
#include "ParserClientImpl.h"
#include "TestIntermediateStorage.h"
#include "TextAccess.h"
#include "utility.h"
#include "utilityJava.h"
@@ -271,16 +272,17 @@ private:
std::shared_ptr<TextAccess> parseCode(const FilePath& sourceFilePath, const FilePath& projectDataSrcRoot, const std::vector<FilePath>& classpath)
{
std::shared_ptr<DumpParserClient> parserClient = std::make_shared<DumpParserClient>();
JavaParser parser(parserClient, std::make_shared<IndexerStateInfo>());
TestIntermediateStorage storage;
JavaParser parser(std::make_shared<ParserClientImpl>(&storage), std::make_shared<IndexerStateInfo>());
std::shared_ptr<IndexerCommandJava> command = std::make_shared<IndexerCommandJava>(sourceFilePath, L"8", classpath);
TimeStamp startTime = TimeStamp::now();
parser.buildIndex(command);
m_duration += TimeStamp::now().deltaMS(startTime);
return TextAccess::createFromString(utility::encodeToUtf8(parserClient->m_lines));
storage.generateStringLists();
return TextAccess::createFromLines(storage.m_lines);
}
size_t m_duration;
+114 -114
View File
@@ -1,15 +1,15 @@
#include <cxxtest/TestSuite.h>
#include "ApplicationSettings.h"
#include "JavaEnvironmentFactory.h"
#include "JavaParser.h"
#include "TestParserClient.h"
#include "ApplicationSettings.h"
#include "utilityPathDetection.h"
#include "ParserClientImpl.h"
#include "TextAccess.h"
#include "utility.h"
#include "utilityJava.h"
#include "utilityPathDetection.h"
#include "TestIntermediateStorage.h"
class JavaParserTestSuite: public CxxTest::TestSuite
{
@@ -44,7 +44,7 @@ public:
void test_java_parser_finds_package_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
);
@@ -55,7 +55,7 @@ public:
void test_java_parser_finds_anotation_declaration_in_defaut_package()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
"}\n"
@@ -68,7 +68,7 @@ public:
void test_java_parser_finds_anotation_member_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int value() default 0;\n"
@@ -82,7 +82,7 @@ public:
void test_java_parser_finds_class_declaration_in_defaut_package()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
"}\n"
@@ -95,7 +95,7 @@ public:
void test_java_parser_finds_interface_declaration_in_defaut_package()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public interface A\n"
"{\n"
"}\n"
@@ -108,7 +108,7 @@ public:
void test_java_parser_finds_class_declaration_in_named_package()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -122,7 +122,7 @@ public:
void test_java_parser_finds_class_declaration_in_nested_named_package()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -136,7 +136,7 @@ public:
void test_java_parser_finds_enum_declaration_in_named_package()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public enum A\n"
"{\n"
@@ -150,7 +150,7 @@ public:
void test_java_parser_finds_enum_constant_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public enum A\n"
"{\n"
@@ -165,7 +165,7 @@ public:
void test_java_parser_finds_constructor_declaration_without_parameters()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -176,13 +176,13 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public foo.A.A() <4:2 <4:2 <4:9 4:9> 4:11> 6:2>"
client->methods, L"public foo.A.A() <4:2 <4:2 <4:9 4:9> 4:11> 6:2>"
));
}
void test_java_parser_finds_method_declaration_with_custom_type_in_signature()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -193,13 +193,13 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public void foo.A.bar(foo.A) <4:2 <4:2 <4:14 4:16> 4:21> 6:2>"
client->methods, L"public void foo.A.bar(foo.A) <4:2 <4:2 <4:14 4:16> 4:21> 6:2>"
));
}
void test_java_parser_finds_anonymous_class_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -218,7 +218,7 @@ public:
void test_java_parser_finds_method_declaration_in_anonymous_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -236,13 +236,13 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public void foo.A.bar.anonymous class (input.cc<10:3>).foo() <11:4 <11:4 <11:16 11:18> 11:20> 11:23>"
client->methods, L"public void foo.A.bar.anonymous class (input.cc<10:3>).foo() <11:4 <11:4 <11:16 11:18> 11:20> 11:23>"
));
}
void test_java_parser_finds_method_declaration_with_static_keyword_in_signature()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -253,13 +253,13 @@ public:
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->methods, L"public static void foo.A.bar() <4:2 <4:2 <4:21 4:23> 4:25> 6:2>"
client->methods, L"public static void foo.A.bar() <4:2 <4:2 <4:21 4:23> 4:25> 6:2>"
));
}
void test_java_parser_finds_field_declaration_with_initial_assignment()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -274,7 +274,7 @@ public:
void test_java_parser_finds_public_access_specifier_in_field_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -289,7 +289,7 @@ public:
void test_java_parser_finds_protected_access_specifier_in_field_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -304,7 +304,7 @@ public:
void test_java_parser_finds_private_access_specifier_in_field_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -319,7 +319,7 @@ public:
void test_java_parser_finds_static_keyword_in_field_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -334,7 +334,7 @@ public:
void test_java_parser_finds_declaration_of_method_parameter()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -351,7 +351,7 @@ public:
void test_java_parser_finds_declaration_of_local_variable()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -369,7 +369,7 @@ public:
void test_java_parser_finds_declaration_of_type_parameter_of_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A <T>\n"
"{\n"
"}\n"
@@ -382,7 +382,7 @@ public:
void test_java_parser_finds_declaration_of_type_parameter_of_method()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public <T> void foo()\n"
@@ -398,7 +398,7 @@ public:
void test_java_parser_finds_field_of_interface_to_be_implicitly_static()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public interface A\n"
"{\n"
" int b = 5;\n"
@@ -412,7 +412,7 @@ public:
void test_java_parser_finds_line_comment()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"// this is a line comment\n"
"package foo;\n"
);
@@ -424,7 +424,7 @@ public:
void test_java_parser_finds_block_comment()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"/* this is a line comment*/\n"
"package foo;\n"
);
@@ -436,35 +436,36 @@ public:
void test_java_parser_finds_missing_semicolon_as_parse_error()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->errors, L"Syntax error on token \"foo\", ; expected after this token <1:9 1:11>"
client->errors, L"Syntax error on token \"foo\", ; expected after this token <1:9 1:9>"
));
}
void test_java_parser_finds_missing_import_as_error()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"import foo;\n"
);
TS_ASSERT(utility::containsElement<std::wstring>(
client->errors, L"The import foo cannot be resolved <1:8 1:10>"
client->errors, L"The import foo cannot be resolved <1:8 1:8>"
));
}
///////////////////////////////////////////////////////////////////////////////
// test finding nested symbol definitions and declarations
void test_java_parser_finds_class_declaration_nested_in_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -481,7 +482,7 @@ public:
void test_java_parser_finds_class_declaration_nested_in_method()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -505,7 +506,7 @@ public:
void test_java_parser_finds_no_qualifier_location_of_standalone_this_expression()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -521,7 +522,7 @@ public:
void test_java_parser_finds_qualifier_location_of_import_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"import foo.bar;\n"
);
@@ -532,7 +533,7 @@ public:
void test_java_parser_finds_qualifier_location_of_simple_type()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo.bar;\n"
"public class A\n"
"{\n"
@@ -553,7 +554,7 @@ public:
void test_java_parser_finds_qualifier_location_of_field_access()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -573,7 +574,7 @@ public:
void test_java_parser_finds_qualifier_location_of_super_field_access()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"class A\n"
"{\n"
@@ -600,7 +601,7 @@ public:
void test_java_parser_finds_qualifier_location_of_this_expression()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"class A\n"
"{\n"
@@ -620,7 +621,7 @@ public:
void test_java_parser_finds_qualifier_location_of_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -642,7 +643,7 @@ public:
void test_java_parser_finds_qualifier_location_of_method_invocation_on_this()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -660,7 +661,7 @@ public:
void test_java_parser_finds_qualifier_location_of_super_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -700,7 +701,7 @@ public:
void test_java_parser_finds_qualifier_location_of_creation_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -730,7 +731,7 @@ public:
void test_java_parser_finds_qualifier_location_of_expression_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -759,7 +760,7 @@ public:
void test_java_parser_finds_qualifier_location_of_super_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -785,7 +786,7 @@ public:
void test_java_parser_finds_qualifier_location_of_class_instance_creation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -810,7 +811,7 @@ public:
void test_java_parser_finds_usage_of_marker_annotation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
"}\n"
@@ -828,7 +829,7 @@ public:
void test_java_parser_finds_usage_of_single_member_annotation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int value() default 0;\n"
@@ -847,7 +848,7 @@ public:
void test_java_parser_finds_usage_of_normal_annotation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int a() default 0;\n"
@@ -867,7 +868,7 @@ public:
void test_java_parser_finds_usage_of_normal_annotation_member_in_initialization()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public @interface SampleAnnotation\n"
"{\n"
" public int a() default 0;\n"
@@ -887,7 +888,7 @@ public:
void test_java_parser_finds_inheritance_using_extends_keyword()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -905,7 +906,7 @@ public:
void test_java_parser_finds_inheritance_using_implements_keyword()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -923,7 +924,7 @@ public:
void test_java_parser_finds_inheritance_of_anonymous_class_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Base\n"
@@ -946,7 +947,7 @@ public:
void test_java_parser_finds_usage_of_string_for_var_type()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public void foo(){\n"
@@ -962,7 +963,7 @@ public:
void test_java_parser_finds_type_parameter_in_signature_of_method()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A <T>\n"
"{\n"
" public A<Void> foo(A<Void> a){\n"
@@ -981,7 +982,7 @@ public:
void test_parser_finds_usage_of_type_defined_in_base_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class Foo {\n"
" public class Base {\n"
" public class X {\n"
@@ -1000,7 +1001,7 @@ public:
void test_java_parser_finds_correct_location_of_qualified_type_usage()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public class B\n"
@@ -1020,7 +1021,7 @@ public:
void test_java_parser_finds_type_argument_of_parameterized_type()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A <T> {\n"
" T t;\n"
"}\n"
@@ -1042,7 +1043,7 @@ public:
void test_java_parser_finds_type_argument_of_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1066,7 +1067,7 @@ public:
void test_java_parser_finds_type_argument_of_super_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1098,7 +1099,7 @@ public:
void test_java_parser_finds_type_argument_of_constructor_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class Bar\n"
"{\n"
@@ -1124,7 +1125,7 @@ public:
void test_java_parser_finds_type_argument_of_super_constructor_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public class Base\n"
@@ -1152,7 +1153,7 @@ public:
void test_java_parser_finds_type_argument_of_creation_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1182,7 +1183,7 @@ public:
void test_java_parser_finds_type_argument_of_expression_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1212,7 +1213,7 @@ public:
void test_java_parser_finds_type_argument_of_super_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -1242,7 +1243,7 @@ public:
void test_java_parser_finds_type_argument_of_type_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" \n"
" void foo() {\n"
@@ -1260,7 +1261,7 @@ public:
void test_java_parser_finds_type_argument_of_class_instance_creation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -1287,7 +1288,7 @@ public:
void test_java_parser_finds_super_method_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1315,7 +1316,7 @@ public:
void test_java_parser_finds_constructor_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class Bar\n"
"{\n"
@@ -1337,7 +1338,7 @@ public:
void test_java_parser_finds_super_constructor_invocation()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public class Base\n"
@@ -1361,7 +1362,7 @@ public:
void test_java_parser_finds_invocation_of_method_of_anonymous_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"class Main {\n"
" public interface Interfaze {\n"
" public void foo();\n"
@@ -1385,7 +1386,7 @@ public:
void test_java_parser_finds_overridden_method_with_same_signature()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"class Main {\n"
" public interface Interfaze {\n"
" public void foo(int t);\n"
@@ -1405,7 +1406,7 @@ public:
void test_java_parser_finds_overridden_method_with_generic_signature()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"class Main <X> {\n"
" public interface Interfaze <T> {\n"
" public void foo(T t);\n"
@@ -1425,7 +1426,7 @@ public:
void test_java_parser_finds_method_usage_for_creation_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1451,7 +1452,7 @@ public:
void test_java_parser_finds_method_usage_for_expression_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Functor\n"
@@ -1480,7 +1481,7 @@ public:
void test_java_parser_finds_method_usage_for_super_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" public interface Functor {\n"
" public void doSomething();\n"
@@ -1506,7 +1507,7 @@ public:
void test_java_parser_finds_no_method_usage_for_type_method_reference()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A {\n"
" void foo() {\n"
" Functor method = int []::clone;\n"
@@ -1520,7 +1521,7 @@ public:
void test_java_parser_finds_no_usage_of_field_within_that_fields_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1533,7 +1534,7 @@ public:
void test_java_parser_finds_no_usage_of_enum_constant_within_that_enum_constants_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public enum X\n"
"{\n"
@@ -1546,7 +1547,7 @@ public:
void test_java_parser_finds_usage_of_field_with_same_name_as_method_parameter()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1565,7 +1566,7 @@ public:
void test_java_parser_does_not_confuse_method_name_with_field_name()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class X\n"
"{\n"
@@ -1584,7 +1585,7 @@ public:
void test_java_parser_finds_assignment_of_method_parameter()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -1602,7 +1603,7 @@ public:
void test_java_parser_finds_assignment_of_local_variable()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"package foo;\n"
"public class A\n"
"{\n"
@@ -1621,7 +1622,7 @@ public:
void test_java_parser_finds_scope_of_class_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
"}\n"
@@ -1637,7 +1638,7 @@ public:
void test_java_parser_finds_scope_of_enum_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public enum A\n"
"{\n"
"}\n"
@@ -1653,7 +1654,7 @@ public:
void test_java_parser_finds_scope_of_constructor_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public A()\n"
@@ -1672,7 +1673,7 @@ public:
void test_java_parser_finds_scope_of_method_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public void a()\n"
@@ -1691,7 +1692,7 @@ public:
void test_java_parser_finds_scope_of_switch_statement()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public void a()\n"
@@ -1715,7 +1716,7 @@ public:
void test_java_parser_finds_scope_of_block_statement()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public void a()\n"
@@ -1736,7 +1737,7 @@ public:
void test_java_parser_finds_scope_of_array_initialization_list()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" private int[] array = {1, 2};\n"
@@ -1753,7 +1754,7 @@ public:
void test_java_parser_finds_scope_of_anonymous_class_declaration()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public interface Base\n"
@@ -1779,7 +1780,7 @@ public:
void test_java_parser_finds_usage_of_type_parameter_of_class()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A <T>\n"
"{\n"
" T t;\n"
@@ -1793,7 +1794,7 @@ public:
void test_java_parser_finds_usage_of_type_parameter_of_method()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A\n"
"{\n"
" public <T> void foo(T t){};\n"
@@ -1807,7 +1808,7 @@ public:
void test_java_parser_finds_correct_location_of_generic_type_usage()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A <T>\n"
"{\n"
" A<Void> t;\n"
@@ -1821,7 +1822,7 @@ public:
void test_java_parser_finds_bound_type_of_type_parameter()
{
std::shared_ptr<TestParserClient> client = parseCode(
std::shared_ptr<TestIntermediateStorage> client = parseCode(
"public class A <T extends Void>\n"
"{\n"
"}\n"
@@ -1835,7 +1836,7 @@ public:
//void test_cxx_parser_catches_error()
//{
// std::shared_ptr<TestParserClient> client = parseCode(
// std::shared_ptr<TestIntermediateStorage> client = parseCode(
// "int a = b;\n",
// false
// );
@@ -1846,7 +1847,7 @@ public:
//void test_cxx_parser_finds_location_of_line_comment()
//{
// std::shared_ptr<TestParserClient> client = parseCode(
// std::shared_ptr<TestIntermediateStorage> client = parseCode(
// "// this is a line comment\n"
// );
@@ -1856,7 +1857,7 @@ public:
//void test_cxx_parser_finds_location_of_block_comment()
//{
// std::shared_ptr<TestParserClient> client = parseCode(
// std::shared_ptr<TestIntermediateStorage> client = parseCode(
// "/* this is a\n"
// "block comment */\n"
// );
@@ -1901,17 +1902,16 @@ private:
return "";
}
std::shared_ptr<TestParserClient> parseCode(std::string code, bool logErrors = true)
std::shared_ptr<TestIntermediateStorage> parseCode(std::string code, bool logErrors = true)
{
std::shared_ptr<TestParserClient> parserClient = std::make_shared<TestParserClient>();
std::shared_ptr<TextAccess> textAccess = TextAccess::createFromString(code);
setupJavaEnvironmentFactory();
JavaParser parser(parserClient, std::make_shared<IndexerStateInfo>());
parser.buildIndex(FilePath(L"input.cc"), textAccess);
std::shared_ptr<TestIntermediateStorage> storage = std::make_shared<TestIntermediateStorage>();
JavaParser parser(std::make_shared<ParserClientImpl>(storage.get()), std::make_shared<IndexerStateInfo>());
parser.buildIndex(FilePath(L"input.cc"), TextAccess::createFromString(code));
return parserClient;
storage->generateStringLists();
return storage;
}
};
-208
View File
@@ -1,208 +0,0 @@
#ifndef DUMP_PARSER_CLIENT_H
#define DUMP_PARSER_CLIENT_H
#include "ParseLocation.h"
#include "ParserClient.h"
#include <boost/filesystem.hpp>
class DumpParserClient : public ParserClient
{
public:
DumpParserClient()
: m_lines(L"")
{
}
Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) override
{
recordLine(symbolKindToString(symbolKind) + L" " + addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access) + L"\n");
return 0;
}
Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) override
{
recordLine(symbolKindToString(symbolKind) + L" " + addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access) + L" [" + location.filePath.fileName(), location) + L"]\n");
return 0;
}
Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) override
{
recordLine(symbolKindToString(symbolKind) + L" " + addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access) + L" [" + location.filePath.fileName(), location, scopeLocation) + L"]\n");
return 0;
}
Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) override
{
recordLine(symbolKindToString(symbolKind) + L" " + addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access) + L" [" + location.filePath.fileName(), location, scopeLocation, signatureLocation) + L"]\n");
return 0;
}
void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) override
{
std::wstring referencedNameString = referencedName.getQualifiedNameWithSignature();
try
{
if (FilePath(referencedNameString).exists())
{
referencedNameString = FilePath(referencedNameString).fileName();
}
}
catch (const boost::filesystem::filesystem_error&)
{
// do nothing and use the old contectNameString
}
std::wstring contextNameString = contextName.getQualifiedNameWithSignature();
try
{
if (FilePath(contextNameString).exists())
{
contextNameString = FilePath(contextNameString).fileName();
}
}
catch (const boost::filesystem::filesystem_error&)
{
// do nothing and use the old contectNameString
}
recordLine(referenceKindToString(referenceKind) + L" " + addLocationSuffix(contextNameString + L" -> " + referencedNameString + L" [" + location.filePath.fileName(), location) + L"]\n");
}
void recordQualifierLocation(const NameHierarchy& qualifierName, const ParseLocation& location) override
{
recordLine(L"QUALIFIER: " + addLocationSuffix(qualifierName.getQualifiedNameWithSignature() + L" [" + location.filePath.fileName(), location) + L"]\n");
}
void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override
{
recordLine(L"LOCAL_SYMBOL: " + addLocationSuffix(name + L" [" + location.filePath.fileName(), location) + L"]\n");
}
void recordFile(const FilePath& filePath, bool indexed) override
{
recordLine(L"FILE: " + filePath.fileName() + (indexed ? L"" : L" non-indexed") + L"\n");
}
void recordComment(const ParseLocation& location) override
{
recordLine(L"COMMENT: " + addLocationSuffix(L"comment [" + location.filePath.fileName(), location) + L"]\n");
}
std::wstring m_lines;
private:
void doRecordError(const ParseLocation& location, const std::wstring& message,
bool fatal, bool indexed, const FilePath& translationUnit) override
{
recordLine(L"ERROR: " + addLocationSuffix(message + L" [" + location.filePath.fileName(), location) + L"]\n");
}
void recordLine(const std::wstring& message)
{
if (m_recordedLines.find(message) == m_recordedLines.end())
{
m_recordedLines.insert(message);
m_lines += message;
}
}
std::wstring symbolKindToString(SymbolKind symbolKind) const
{
switch (symbolKind)
{
case SYMBOL_BUILTIN_TYPE:
return L"SYMBOL_BUILTIN_TYPE";
case SYMBOL_CLASS:
return L"SYMBOL_CLASS";
case SYMBOL_ENUM:
return L"SYMBOL_ENUM";
case SYMBOL_ENUM_CONSTANT:
return L"SYMBOL_ENUM_CONSTANT";
case SYMBOL_FIELD:
return L"SYMBOL_FIELD";
case SYMBOL_FUNCTION:
return L"SYMBOL_FUNCTION";
case SYMBOL_GLOBAL_VARIABLE:
return L"SYMBOL_GLOBAL_VARIABLE";
case SYMBOL_INTERFACE:
return L"SYMBOL_INTERFACE";
case SYMBOL_MACRO:
return L"SYMBOL_MACRO";
case SYMBOL_METHOD:
return L"SYMBOL_METHOD";
case SYMBOL_NAMESPACE:
return L"SYMBOL_NAMESPACE";
case SYMBOL_PACKAGE:
return L"SYMBOL_PACKAGE";
case SYMBOL_STRUCT:
return L"SYMBOL_STRUCT";
case SYMBOL_TEMPLATE_PARAMETER:
return L"SYMBOL_TEMPLATE_PARAMETER";
case SYMBOL_TYPEDEF:
return L"SYMBOL_TYPEDEF";
case SYMBOL_TYPE_PARAMETER:
return L"SYMBOL_TYPE_PARAMETER";
case SYMBOL_UNION:
return L"SYMBOL_UNION";
default:
break;
}
return L"SYMBOL_NON_INDEXED";
}
std::wstring referenceKindToString(ReferenceKind referenceKind) const
{
switch (referenceKind)
{
case REFERENCE_TYPE_USAGE:
return L"REFERENCE_TYPE_USAGE";
case REFERENCE_USAGE:
return L"REFERENCE_USAGE";
case REFERENCE_CALL:
return L"REFERENCE_CALL";
case REFERENCE_INHERITANCE:
return L"REFERENCE_INHERITANCE";
case REFERENCE_OVERRIDE:
return L"REFERENCE_OVERRIDE";
case REFERENCE_TEMPLATE_ARGUMENT:
return L"REFERENCE_TEMPLATE_ARGUMENT";
case REFERENCE_TYPE_ARGUMENT:
return L"REFERENCE_TYPE_ARGUMENT";
case REFERENCE_TEMPLATE_DEFAULT_ARGUMENT:
return L"REFERENCE_TEMPLATE_DEFAULT_ARGUMENT";
case REFERENCE_TEMPLATE_SPECIALIZATION:
return L"REFERENCE_TEMPLATE_SPECIALIZATION";
case REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION:
return L"REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION";
case REFERENCE_INCLUDE:
return L"REFERENCE_INCLUDE";
case REFERENCE_IMPORT:
return L"REFERENCE_IMPORT";
case REFERENCE_MACRO_USAGE:
return L"REFERENCE_MACRO_USAGE";
case REFERENCE_ANNOTATION_USAGE:
return L"REFERENCE_ANNOTATION_USAGE";
default:
break;
}
return L"REFERENCE_UNDEFINED";
}
std::set<std::wstring> m_recordedLines;
};
#endif // DUMP_PARSER_CLIENT_H
+530
View File
@@ -0,0 +1,530 @@
#ifndef TEST_INTERMEDIATE_STORAGE_H
#define TEST_INTERMEDIATE_STORAGE_H
#include <boost/filesystem.hpp>
#include "AccessKind.h"
#include "Edge.h"
#include "IntermediateStorage.h"
#include "LocationType.h"
#include "NameHierarchy.h"
#include "NodeType.h"
#include "utilityString.h"
class TestIntermediateStorage
: public IntermediateStorage
{
public:
void generateStringLists()
{
std::map<Id, FilePath> filePathMap;
for (const StorageFile& file : getStorageFiles())
{
filePathMap.emplace(file.id, file.filePath);
files.emplace(file.filePath);
addLine(L"FILE: " + FilePath(file.filePath).fileName() + (file.indexed ? L"" : L" non-indexed"));
}
std::map<Id, StorageComponentAccess> accessMap;
for (const StorageComponentAccess& access : getComponentAccesses())
{
accessMap.emplace(access.nodeId, access);
}
std::multimap<Id, Id> occurrenceMap;
for (const StorageOccurrence& occurence : getStorageOccurrences())
{
occurrenceMap.emplace(occurence.sourceLocationId, occurence.elementId);
}
std::multimap<Id, StorageSourceLocation> tokenLocationMap;
std::multimap<Id, StorageSourceLocation> scopeLocationMap;
std::multimap<Id, StorageSourceLocation> signatureLocationMap;
std::multimap<Id, StorageSourceLocation> localSymbolLocationMap;
std::multimap<Id, StorageSourceLocation> qualifierLocationMap;
std::vector<StorageSourceLocation> commentLocations;
for (const StorageSourceLocation& location : getStorageSourceLocations())
{
std::vector<Id> elementIds;
for (auto it = occurrenceMap.find(location.id); it != occurrenceMap.end() && it->first == location.id; it++)
{
elementIds.emplace_back(it->second);
}
if (!elementIds.size())
{
elementIds.emplace_back(0);
}
for (Id elementId : elementIds)
{
switch (intToLocationType(location.type))
{
case LOCATION_TOKEN:
if (elementId)
{
tokenLocationMap.emplace(elementId, location);
}
break;
case LOCATION_SCOPE:
if (elementId)
{
scopeLocationMap.emplace(elementId, location);
}
break;
case LOCATION_QUALIFIER:
if (elementId)
{
qualifierLocationMap.emplace(elementId, location);
}
break;
case LOCATION_LOCAL_SYMBOL:
if (elementId)
{
localSymbolLocationMap.emplace(elementId, location);
}
break;
case LOCATION_SIGNATURE:
if (elementId)
{
signatureLocationMap.emplace(elementId, location);
}
break;
case LOCATION_COMMENT:
commentLocations.emplace_back(location);
break;
default:
break;
}
}
}
std::map<Id, StorageNode> nodesMap;
for (const StorageNode& node : getStorageNodes())
{
nodesMap.emplace(node.id, node);
std::wstring nameStr = NameHierarchy::deserialize(node.serializedName).getQualifiedNameWithSignature();
for (auto qualifierLocationIt = qualifierLocationMap.find(node.id);
qualifierLocationIt != qualifierLocationMap.end() && qualifierLocationIt->first == node.id;
qualifierLocationIt++)
{
std::wstring locStr = addLocationStr(L"", qualifierLocationIt->second);
qualifiers.emplace_back(nameStr + locStr);
addLine(L"QUALIFIER: " + nameStr + addFileName(locStr, filePathMap[qualifierLocationIt->second.fileNodeId]));
}
std::vector<std::wstring>* bin = getBinForNodeType(node.type);
if (bin != nullptr)
{
auto accessIt = accessMap.find(node.id);
if (accessIt != accessMap.end())
{
if (intToAccessKind(accessIt->second.type) != ACCESS_TEMPLATE_PARAMETER &&
intToAccessKind(accessIt->second.type) != ACCESS_TYPE_PARAMETER)
{
nameStr = accessKindToString(intToAccessKind(accessIt->second.type)) + L' ' + nameStr;
}
}
bool added = false;
for (auto tokenLocationIt = tokenLocationMap.find(node.id);
tokenLocationIt != tokenLocationMap.end() && tokenLocationIt->first == node.id;
tokenLocationIt++)
{
added = false;
std::wstring locationStr = addLocationStr(L"", tokenLocationIt->second);
auto signatureLocationIt = signatureLocationMap.find(node.id);
if (signatureLocationIt != signatureLocationMap.end() &&
containsLocation(signatureLocationIt->second, tokenLocationIt->second))
{
locationStr = addLocationStr(locationStr, signatureLocationIt->second);
}
for (auto scopeLocationIt = scopeLocationMap.find(node.id);
scopeLocationIt != scopeLocationMap.end() && scopeLocationIt->first == node.id;
scopeLocationIt++)
{
if (containsLocation(scopeLocationIt->second, tokenLocationIt->second))
{
std::wstring locStr = addLocationStr(locationStr, scopeLocationIt->second);
bin->emplace_back(nameStr + locStr);
addLine(nodeTypeToString(node.type) + L": " + nameStr + addFileName(locStr, filePathMap[tokenLocationIt->second.fileNodeId]));
added = true;
}
}
if (!added)
{
bin->emplace_back(nameStr + locationStr);
addLine(nodeTypeToString(node.type) + L": " + nameStr + addFileName(locationStr, filePathMap[tokenLocationIt->second.fileNodeId]));
added = true;
}
}
if (!added)
{
bin->emplace_back(nameStr);
addLine(nodeTypeToString(node.type) + L": " + nameStr);
}
}
}
for (const StorageEdge& edge : getStorageEdges())
{
auto targetIt = nodesMap.find(edge.targetNodeId);
if (targetIt == nodesMap.end())
{
continue;
}
auto sourceIt = nodesMap.find(edge.sourceNodeId);
if (sourceIt == nodesMap.end())
{
continue;
}
const StorageNode& target = targetIt->second;
const StorageNode& source = sourceIt->second;
std::vector<std::wstring>* bin = getBinForEdgeType(edge.type);
if (bin != nullptr)
{
std::wstring sourceName = NameHierarchy::deserialize(source.serializedName).getQualifiedNameWithSignature();
try
{
if (FilePath(sourceName).exists())
{
sourceName = FilePath(sourceName).fileName();
}
}
catch (const boost::filesystem::filesystem_error&) {}
std::wstring targetName = NameHierarchy::deserialize(target.serializedName).getQualifiedNameWithSignature();
try
{
if (FilePath(targetName).exists())
{
targetName = FilePath(targetName).fileName();
}
}
catch (const boost::filesystem::filesystem_error&) {}
std::wstring nameStr = sourceName + L" -> " + targetName;
bool added = false;
for (auto tokenLocationIt = tokenLocationMap.find(edge.id);
tokenLocationIt != tokenLocationMap.end() && tokenLocationIt->first == edge.id;
tokenLocationIt++)
{
std::wstring locStr = addLocationStr(L"", tokenLocationIt->second);
bin->emplace_back(nameStr + locStr);
addLine(edgeTypeToString(edge.type) + L": " + nameStr + addFileName(locStr, filePathMap[tokenLocationIt->second.fileNodeId]));
added = true;
}
if (!added)
{
bin->emplace_back(nameStr);
addLine(edgeTypeToString(edge.type) + L": " + nameStr);
}
}
}
for (const StorageLocalSymbol& localSymbol : getStorageLocalSymbols())
{
bool added = false;
for (auto localSymbolLocationIt = localSymbolLocationMap.find(localSymbol.id);
localSymbolLocationIt != localSymbolLocationMap.end() && localSymbolLocationIt->first == localSymbol.id;
localSymbolLocationIt++)
{
std::wstring locStr = addLocationStr(L"", localSymbolLocationIt->second);
localSymbols.emplace_back(localSymbol.name + locStr);
addLine(L"LOCAL_SYMBOL: " + localSymbol.name + addFileName(locStr, filePathMap[localSymbolLocationIt->second.fileNodeId]));
added = true;
}
if (!added)
{
localSymbols.emplace_back(localSymbol.name);
addLine(L"LOCAL_SYMBOL: " + localSymbol.name);
}
}
for (const StorageSourceLocation& location : commentLocations)
{
std::wstring locStr = addLocationStr(L"", location);
comments.emplace_back(L"comment" + locStr);
addLine(L"COMMENT: comment" + addFileName(locStr, filePathMap[location.fileNodeId]));
}
for (const StorageErrorData& error : getErrors())
{
std::wstring locStr = addLocationStr(
L"",
StorageSourceLocation(
0, 0, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber,
locationTypeToInt(LOCATION_ERROR)
)
);
errors.emplace_back(error.message + locStr);
addLine(L"ERROR: " + error.message + addFileName(locStr, FilePath(error.filePath)));
}
}
std::vector<std::wstring> errors;
std::vector<std::wstring> qualifiers;
std::vector<std::wstring> packages;
std::vector<std::wstring> typedefs;
std::vector<std::wstring> builtinTypes;
std::vector<std::wstring> classes;
std::vector<std::wstring> unions;
std::vector<std::wstring> interfaces;
std::vector<std::wstring> annotations;
std::vector<std::wstring> enums;
std::vector<std::wstring> enumConstants;
std::vector<std::wstring> functions;
std::vector<std::wstring> fields;
std::vector<std::wstring> globalVariables;
std::vector<std::wstring> methods;
std::vector<std::wstring> namespaces;
std::vector<std::wstring> structs;
std::vector<std::wstring> macros;
std::vector<std::wstring> templateParameterTypes;
std::vector<std::wstring> typeParameters;
std::vector<std::wstring> localSymbols;
std::set<std::wstring> files;
std::vector<std::wstring> comments;
std::vector<std::wstring> inheritances;
std::vector<std::wstring> overrides;
std::vector<std::wstring> calls;
std::vector<std::wstring> usages; // for variables
std::vector<std::wstring> typeUses; // for types
std::vector<std::wstring> macroUses;
std::vector<std::wstring> annotationUses;
std::vector<std::wstring> templateArgumentTypes;
std::vector<std::wstring> typeArguments;
std::vector<std::wstring> templateDefaultArgumentTypes;
std::vector<std::wstring> templateSpecializations;
std::vector<std::wstring> templateMemberSpecializations;
std::vector<std::wstring> includes;
std::vector<std::wstring> imports;
std::vector<std::string> m_lines;
private:
std::wstring nodeTypeToString(int nodeType) const
{
switch (NodeType::intToType(nodeType))
{
case NodeType::NODE_BUILTIN_TYPE:
return L"SYMBOL_BUILTIN_TYPE";
case NodeType::NODE_CLASS:
return L"SYMBOL_CLASS";
case NodeType::NODE_ENUM:
return L"SYMBOL_ENUM";
case NodeType::NODE_ENUM_CONSTANT:
return L"SYMBOL_ENUM_CONSTANT";
case NodeType::NODE_FIELD:
return L"SYMBOL_FIELD";
case NodeType::NODE_FUNCTION:
return L"SYMBOL_FUNCTION";
case NodeType::NODE_GLOBAL_VARIABLE:
return L"SYMBOL_GLOBAL_VARIABLE";
case NodeType::NODE_INTERFACE:
return L"SYMBOL_INTERFACE";
case NodeType::NODE_MACRO:
return L"SYMBOL_MACRO";
case NodeType::NODE_METHOD:
return L"SYMBOL_METHOD";
case NodeType::NODE_NAMESPACE:
return L"SYMBOL_NAMESPACE";
case NodeType::NODE_PACKAGE:
return L"SYMBOL_PACKAGE";
case NodeType::NODE_STRUCT:
return L"SYMBOL_STRUCT";
case NodeType::NODE_TEMPLATE_PARAMETER_TYPE:
return L"SYMBOL_TEMPLATE_PARAMETER";
case NodeType::NODE_TYPEDEF:
return L"SYMBOL_TYPEDEF";
case NodeType::NODE_TYPE_PARAMETER:
return L"SYMBOL_TYPE_PARAMETER";
case NodeType::NODE_UNION:
return L"SYMBOL_UNION";
default:
break;
}
return L"SYMBOL_NON_INDEXED";
}
std::wstring edgeTypeToString(int edgeType) const
{
switch (Edge::intToType(edgeType))
{
case Edge::EDGE_TYPE_USAGE:
return L"REFERENCE_TYPE_USAGE";
case Edge::EDGE_USAGE:
return L"REFERENCE_USAGE";
case Edge::EDGE_CALL:
return L"REFERENCE_CALL";
case Edge::EDGE_INHERITANCE:
return L"REFERENCE_INHERITANCE";
case Edge::EDGE_OVERRIDE:
return L"REFERENCE_OVERRIDE";
case Edge::EDGE_TEMPLATE_ARGUMENT:
return L"REFERENCE_TEMPLATE_ARGUMENT";
case Edge::EDGE_TYPE_ARGUMENT:
return L"REFERENCE_TYPE_ARGUMENT";
case Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT:
return L"REFERENCE_TEMPLATE_DEFAULT_ARGUMENT";
case Edge::EDGE_TEMPLATE_SPECIALIZATION:
return L"REFERENCE_TEMPLATE_SPECIALIZATION";
case Edge::EDGE_TEMPLATE_MEMBER_SPECIALIZATION:
return L"REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION";
case Edge::EDGE_INCLUDE:
return L"REFERENCE_INCLUDE";
case Edge::EDGE_IMPORT:
return L"REFERENCE_IMPORT";
case Edge::EDGE_MACRO_USAGE:
return L"REFERENCE_MACRO_USAGE";
case Edge::EDGE_ANNOTATION_USAGE:
return L"REFERENCE_ANNOTATION_USAGE";
default:
break;
}
return L"REFERENCE_UNDEFINED";
}
std::vector<std::wstring>* getBinForNodeType(int nodeType)
{
switch (NodeType::intToType(nodeType))
{
case NodeType::NODE_PACKAGE:
return &packages;
case NodeType::NODE_TYPEDEF:
return &typedefs;
case NodeType::NODE_BUILTIN_TYPE:
return &builtinTypes;
case NodeType::NODE_CLASS:
return &classes;
case NodeType::NODE_UNION:
return &unions;
case NodeType::NODE_INTERFACE:
return &interfaces;
case NodeType::NODE_ANNOTATION:
return &annotations;
case NodeType::NODE_ENUM:
return &enums;
case NodeType::NODE_ENUM_CONSTANT:
return &enumConstants;
case NodeType::NODE_FUNCTION:
return &functions;
case NodeType::NODE_FIELD:
return &fields;
case NodeType::NODE_GLOBAL_VARIABLE:
return &globalVariables;
case NodeType::NODE_METHOD:
return &methods;
case NodeType::NODE_NAMESPACE:
return &namespaces;
case NodeType::NODE_STRUCT:
return &structs;
case NodeType::NODE_MACRO:
return &macros;
case NodeType::NODE_TEMPLATE_PARAMETER_TYPE:
return &templateParameterTypes;
case NodeType::NODE_TYPE_PARAMETER:
return &typeParameters;
default:
break;
}
return nullptr;
}
std::vector<std::wstring>* getBinForEdgeType(int edgeType)
{
switch (Edge::intToType(edgeType))
{
case Edge::EDGE_TYPE_USAGE:
return &typeUses;
case Edge::EDGE_USAGE:
return &usages;
case Edge::EDGE_CALL:
return &calls;
case Edge::EDGE_INHERITANCE:
return &inheritances;
case Edge::EDGE_OVERRIDE:
return &overrides;
case Edge::EDGE_TEMPLATE_ARGUMENT:
return &templateArgumentTypes;
case Edge::EDGE_TYPE_ARGUMENT:
return &typeArguments;
case Edge::EDGE_TEMPLATE_DEFAULT_ARGUMENT:
return &templateDefaultArgumentTypes;
case Edge::EDGE_TEMPLATE_SPECIALIZATION:
return &templateSpecializations;
case Edge::EDGE_TEMPLATE_MEMBER_SPECIALIZATION:
return &templateMemberSpecializations;
case Edge::EDGE_INCLUDE:
return &includes;
case Edge::EDGE_IMPORT:
return &imports;
case Edge::EDGE_MACRO_USAGE:
return &macroUses;
case Edge::EDGE_ANNOTATION_USAGE:
return &annotationUses;
default:
break;
}
return nullptr;
}
std::wstring addLocationStr(const std::wstring& locationStr, const StorageSourceLocation& loc) const
{
return L" <" + std::to_wstring(loc.startLine) + L':' + std::to_wstring(loc.startCol) + locationStr
+ L' ' + std::to_wstring(loc.endLine) + L':' + std::to_wstring(loc.endCol) + L'>';
}
std::wstring addFileName(const std::wstring& locationStr, const FilePath& filePath) const
{
return L" [" + filePath.fileName() + locationStr + L']';
}
bool containsLocation(const StorageSourceLocation& out, const StorageSourceLocation& in) const
{
if (out.startLine > in.startLine)
{
return false;
}
if (out.startLine == in.startLine && out.startCol > in.startCol)
{
return false;
}
if (out.endLine < in.endLine)
{
return false;
}
if (out.endLine == in.endLine && out.endCol < in.endCol)
{
return false;
}
return true;
}
void addLine(const std::wstring& message)
{
m_lines.emplace_back(utility::encodeToUtf8(message) + '\n');
}
};
#endif // TEST_INTERMEDIATE_STORAGE_H
-243
View File
@@ -1,243 +0,0 @@
#ifndef TEST_PARSER_CLIENT_H
#define TEST_PARSER_CLIENT_H
#include "ParseLocation.h"
#include "ParserClient.h"
class TestParserClient: public ParserClient
{
public:
Id recordSymbol(
const NameHierarchy& symbolName, SymbolKind symbolKind,
AccessKind access, DefinitionKind definitionKind) override
{
std::vector<std::wstring>* bin = getBinForSymbolKind(symbolKind);
if (bin != nullptr)
{
bin->push_back(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access));
}
return 0;
}
Id recordSymbolWithLocation(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location,
AccessKind access, DefinitionKind definitionKind) override
{
std::vector<std::wstring>* bin = getBinForSymbolKind(symbolKind);
if (bin != nullptr)
{
bin->push_back(addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access), location));
}
return 0;
}
Id recordSymbolWithLocationAndScope(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation,
AccessKind access, DefinitionKind definitionKind) override
{
std::vector<std::wstring>* bin = getBinForSymbolKind(symbolKind);
if (bin != nullptr)
{
bin->push_back(addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access), location, scopeLocation));
}
return 0;
}
Id recordSymbolWithLocationAndScopeAndSignature(
const NameHierarchy& symbolName, SymbolKind symbolKind,
const ParseLocation& location, const ParseLocation& scopeLocation, const ParseLocation& signatureLocation,
AccessKind access, DefinitionKind definitionKind) override
{
std::vector<std::wstring>* bin = getBinForSymbolKind(symbolKind);
if (bin != nullptr)
{
bin->push_back(addLocationSuffix(addAccessPrefix(symbolName.getQualifiedNameWithSignature(), access), location, scopeLocation, signatureLocation));
}
return 0;
}
void recordReference(
ReferenceKind referenceKind, const NameHierarchy& referencedName, const NameHierarchy& contextName,
const ParseLocation& location) override
{
std::vector<std::wstring>* referenceContainer = nullptr;
switch (referenceKind)
{
case REFERENCE_TYPE_USAGE:
referenceContainer = &typeUses;
break;
case REFERENCE_USAGE:
referenceContainer = &usages;
break;
case REFERENCE_CALL:
referenceContainer = &calls;
break;
case REFERENCE_INHERITANCE:
referenceContainer = &inheritances;
break;
case REFERENCE_OVERRIDE:
referenceContainer = &overrides;
break;
case REFERENCE_TEMPLATE_ARGUMENT:
referenceContainer = &templateArgumentTypes;
break;
case REFERENCE_TYPE_ARGUMENT:
referenceContainer = &typeArguments;
break;
case REFERENCE_TEMPLATE_DEFAULT_ARGUMENT:
referenceContainer = &templateDefaultArgumentTypes;
break;
case REFERENCE_TEMPLATE_SPECIALIZATION:
referenceContainer = &templateSpecializations;
break;
case REFERENCE_TEMPLATE_MEMBER_SPECIALIZATION:
referenceContainer = &templateMemberSpecializations;
break;
case REFERENCE_INCLUDE:
referenceContainer = &includes;
break;
case REFERENCE_IMPORT:
referenceContainer = &imports;
break;
case REFERENCE_MACRO_USAGE:
referenceContainer = &macroUses;
break;
case REFERENCE_ANNOTATION_USAGE:
referenceContainer = &annotationUses;
break;
default:
break;
}
if (referenceContainer != nullptr)
{
referenceContainer->push_back(addLocationSuffix(
contextName.getQualifiedNameWithSignature() + L" -> " + referencedName.getQualifiedNameWithSignature(), location)
);
}
}
void recordQualifierLocation(
const NameHierarchy& qualifierName, const ParseLocation& location) override
{
qualifiers.push_back(addLocationSuffix(qualifierName.getQualifiedNameWithSignature(), location));
}
void recordLocalSymbol(const std::wstring& name, const ParseLocation& location) override
{
localSymbols.push_back(addLocationSuffix(name, location));
}
void recordFile(const FilePath& filePath, bool indexed) override
{
files.insert(filePath.wstr());
}
void recordComment(const ParseLocation& location) override
{
comments.push_back(addLocationSuffix(L"comment", location));
}
std::vector<std::wstring> errors;
std::vector<std::wstring> qualifiers;
std::vector<std::wstring> packages;
std::vector<std::wstring> typedefs;
std::vector<std::wstring> builtinTypes;
std::vector<std::wstring> classes;
std::vector<std::wstring> unions;
std::vector<std::wstring> interfaces;
std::vector<std::wstring> annotations;
std::vector<std::wstring> enums;
std::vector<std::wstring> enumConstants;
std::vector<std::wstring> functions;
std::vector<std::wstring> fields;
std::vector<std::wstring> globalVariables;
std::vector<std::wstring> methods;
std::vector<std::wstring> namespaces;
std::vector<std::wstring> structs;
std::vector<std::wstring> macros;
std::vector<std::wstring> templateParameterTypes;
std::vector<std::wstring> typeParameters;
std::vector<std::wstring> localSymbols;
std::set<std::wstring> files;
std::vector<std::wstring> comments;
std::vector<std::wstring> inheritances;
std::vector<std::wstring> overrides;
std::vector<std::wstring> calls;
std::vector<std::wstring> usages; // for variables
std::vector<std::wstring> typeUses; // for types
std::vector<std::wstring> macroUses;
std::vector<std::wstring> annotationUses;
std::vector<std::wstring> templateArgumentTypes;
std::vector<std::wstring> typeArguments;
std::vector<std::wstring> templateDefaultArgumentTypes;
std::vector<std::wstring> templateSpecializations;
std::vector<std::wstring> templateMemberSpecializations;
std::vector<std::wstring> includes;
std::vector<std::wstring> imports;
private:
void doRecordError(
const ParseLocation& location,
const std::wstring& message,
bool fatal,
bool indexed,
const FilePath& translationUnit) override
{
if (location.isValid())
{
errors.push_back(addLocationSuffix(message, location));
}
}
std::vector<std::wstring>* getBinForSymbolKind(SymbolKind symbolType)
{
switch (symbolType)
{
case SYMBOL_PACKAGE:
return &packages;
case SYMBOL_TYPEDEF:
return &typedefs;
case SYMBOL_BUILTIN_TYPE:
return &builtinTypes;
case SYMBOL_CLASS:
return &classes;
case SYMBOL_UNION:
return &unions;
case SYMBOL_INTERFACE:
return &interfaces;
case SYMBOL_ANNOTATION:
return &annotations;
case SYMBOL_ENUM:
return &enums;
case SYMBOL_ENUM_CONSTANT:
return &enumConstants;
case SYMBOL_FUNCTION:
return &functions;
case SYMBOL_FIELD:
return &fields;
case SYMBOL_GLOBAL_VARIABLE:
return &globalVariables;
case SYMBOL_METHOD:
return &methods;
case SYMBOL_NAMESPACE:
return &namespaces;
case SYMBOL_STRUCT:
return &structs;
case SYMBOL_MACRO:
return &macros;
case SYMBOL_TEMPLATE_PARAMETER:
return &templateParameterTypes;
case SYMBOL_TYPE_PARAMETER:
return &typeParameters;
default:
break;
}
return nullptr;
}
};
#endif // TEST_PARSER_CLIENT_H