diff --git a/bin/app/data/src/test/main.cpp b/bin/app/data/src/test/main.cpp index b1f839a9..83a6fc1a 100644 --- a/bin/app/data/src/test/main.cpp +++ b/bin/app/data/src/test/main.cpp @@ -15,7 +15,7 @@ int main() int b = diff(a, 3); int c = a * b; - int x = y; +// int x = y; return 0; } diff --git a/bin/test/data/log/test_log.txt b/bin/test/data/log/test_log.txt index 51cd5b6e..607c563e 100644 --- a/bin/test/data/log/test_log.txt +++ b/bin/test/data/log/test_log.txt @@ -1,22 +1,4 @@ ConfigManager.cpp ERROR: value path/to/nowhere is not present in config. -Token.cpp ERROR: Location Id was not referenced by this Token. -Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class -Edge.cpp ERROR: Nodes are not plain copies. -Storage.cpp INFO: class: A -Storage.cpp INFO: method: A::A -Storage.cpp INFO: global usage: A::A -> A::count -Storage.cpp INFO: method: A::getCount -Storage.cpp INFO: global usage: A::getCount -> A::count -Storage.cpp INFO: method: A::process -Storage.cpp INFO: field: A::count -Storage.cpp INFO: class: B -Storage.cpp INFO: inheritance: B : A -Storage.cpp INFO: method: B::process -Storage.cpp INFO: type usage: B::process -> int -Storage.cpp INFO: function: main -Storage.cpp INFO: type usage: main -> B -Storage.cpp INFO: call: main -> B::B -Storage.cpp INFO: call: main -> A::getCount Storage.cpp INFO: class: A Storage.cpp INFO: method: A::A Storage.cpp INFO: global usage: A::A -> A::count @@ -49,6 +31,24 @@ SearchMatch.cpp INFO: 237 A::A ^^^^ +Storage.cpp INFO: class: A +Storage.cpp INFO: method: A::A +Storage.cpp INFO: global usage: A::A -> A::count +Storage.cpp INFO: method: A::getCount +Storage.cpp INFO: global usage: A::getCount -> A::count +Storage.cpp INFO: method: A::process +Storage.cpp INFO: field: A::count +Storage.cpp INFO: class: B +Storage.cpp INFO: inheritance: B : A +Storage.cpp INFO: method: B::process +Storage.cpp INFO: type usage: B::process -> int +Storage.cpp INFO: function: main +Storage.cpp INFO: type usage: main -> B +Storage.cpp INFO: call: main -> B::B +Storage.cpp INFO: call: main -> A::getCount +Token.cpp ERROR: Location Id was not referenced by this Token. +Node.cpp WARNING: Cannot change NodeType after it was already set from namespace to class +Edge.cpp ERROR: Nodes are not plain copies. Settings.cpp WARNING: File for Settings not found. ConfigManager.cpp ERROR: value Bool is not present in config. ConfigManager.cpp ERROR: value Int is not present in config. @@ -64,6 +64,7 @@ ConfigManager.cpp ERROR: value Int is not present in config. ConfigManager.cpp ERROR: value Float is not present in config. ConfigManager.cpp ERROR: value String is not present in config. ConfigManager.cpp ERROR: value NewBool is not present in config. +Graph.cpp ERROR: Can't remove member edge, without removing the child node. Storage.cpp INFO: typedef: type -> int Storage.cpp INFO: class: Class Storage.cpp INFO: struct: Struct @@ -106,7 +107,6 @@ Storage.cpp INFO: global usage: isTrue -> global Storage.cpp INFO: function: isTrue Storage.cpp INFO: struct: Struct Storage.cpp INFO: type usage: isTrue -> Struct -Graph.cpp ERROR: Can't remove member edge, without removing the child node. TextAccess.cpp WARNING: Index 'firstLine' has to be lower or equal index 'lastLine', is 3 > 2 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 TextAccess.cpp WARNING: Tried to access index 10. Maximum index is 8 diff --git a/src/lib/data/parser/cxx/ASTVisitor.cpp b/src/lib/data/parser/cxx/ASTVisitor.cpp index e4e1065d..739058df 100644 --- a/src/lib/data/parser/cxx/ASTVisitor.cpp +++ b/src/lib/data/parser/cxx/ASTVisitor.cpp @@ -1,5 +1,6 @@ #include "data/parser/cxx/ASTVisitor.h" +#include #include #include "data/parser/cxx/ASTBodyVisitor.h" @@ -424,8 +425,47 @@ void ASTVisitor::VisitCallExprInDeclBody(clang::VarDecl* decl, clang::CallExpr* void ASTVisitor::VisitCXXConstructExprInDeclBody(clang::FunctionDecl* decl, clang::CXXConstructExpr* expr) { + std::string caller = decl->getNameAsString(); + std::string callee = expr->getConstructor()->getNameAsString(); + clang::SourceRange sourceRange = expr->getSourceRange(); +// expr->getParenOrBraceRange(); // is null when no parens found (for implicit constructor calls; maybe we will have to use this in the future) +// expr->getNumArgs(); // and maybe we will need this one, too.. for same reasons as above. + + const clang::SourceManager& sourceManager = m_context->getSourceManager(); + const clang::PresumedLoc& presumedBegin = sourceManager.getPresumedLoc(sourceRange.getBegin(), false); + const clang::PresumedLoc& presumedEnd = sourceManager.getPresumedLoc(sourceRange.getEnd(), false); + int endLocationOffset = 0; + + bool oneCharacterLocation = ( + presumedBegin.getLine() == presumedEnd.getLine() && presumedBegin.getColumn() == presumedEnd.getColumn() + ); + if (oneCharacterLocation) // get the exact range of name of declard variable + { + clang::ParentMap pm(decl->getBody()); + clang::Stmt* parentStmt = pm.getParent(expr); + if (parentStmt && parentStmt->getStmtClass() == clang::Stmt::DeclStmtClass) + { + clang::DeclStmt* declStmt = clang::dyn_cast(parentStmt); + clang::Decl* decl = declStmt->getSingleDecl(); + if (clang::isa(decl)) + { + clang::NamedDecl* namedDecl = clang::dyn_cast(decl); + int variableNameLength = namedDecl->getName().size(); + endLocationOffset = variableNameLength - 1; + } + } + } + + ParseLocation location( + presumedBegin.getFilename(), + presumedBegin.getLine(), + presumedBegin.getColumn(), + presumedEnd.getLine(), + presumedEnd.getColumn() + endLocationOffset + ); + m_client->onCallParsed( - getParseLocation(expr->getSourceRange()), + location, getParseFunction(decl), getParseFunction(expr->getConstructor()) ); diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 984f9d8c..d26040e3 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -710,7 +710,7 @@ public: ); TS_ASSERT_EQUALS(client->calls.size(), 1); - TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <8:6 8:6>"); + TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <8:6 8:8>"); } void test_cxx_parser_finds_constructor_without_definition_call() @@ -726,7 +726,7 @@ public: ); TS_ASSERT_EQUALS(client->calls.size(), 1); - TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <6:6 6:6>"); + TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <6:6 6:8>"); } void test_cxx_parser_finds_constructor_call_of_field() @@ -768,7 +768,7 @@ public: TS_ASSERT_EQUALS(client->calls[0], "void App::App() -> void Item::Item(int) <9:5 9:11>"); } - void test_cxx_parser_finds_function_call_within_constructor_call_of_field_in_initialization_list() + void test_cxx_parser_finds_function_call_as_parameter_of_constructor_call_of_field_in_initialization_list() { std::shared_ptr client = parseCode( "int one() { return 1; }\n" @@ -808,7 +808,7 @@ public: ); TS_ASSERT_EQUALS(client->calls.size(), 2); - TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <9:6 9:6>"); + TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <9:6 9:8>"); TS_ASSERT_EQUALS(client->calls[1], "int main() -> void App::App(App const &) <10:6 10:14>"); } @@ -856,7 +856,7 @@ public: ); TS_ASSERT_EQUALS(client->calls.size(), 2); - TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <10:6 10:6>"); + TS_ASSERT_EQUALS(client->calls[0], "int main() -> void App::App() <10:6 10:8>"); TS_ASSERT_EQUALS(client->calls[1], "int main() -> void App::operator+(int) <11:2 11:8>"); }