data: token locations for constructor calls
* fixed token locations for implicit constructor calls. * removed error line from test code.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "data/parser/cxx/ASTVisitor.h"
|
||||
|
||||
#include <clang/AST/ParentMap.h>
|
||||
#include <clang/Lex/Lexer.h>
|
||||
|
||||
#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<clang::DeclStmt>(parentStmt);
|
||||
clang::Decl* decl = declStmt->getSingleDecl();
|
||||
if (clang::isa<clang::NamedDecl>(decl))
|
||||
{
|
||||
clang::NamedDecl* namedDecl = clang::dyn_cast<clang::NamedDecl>(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())
|
||||
);
|
||||
|
||||
@@ -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<TestParserClient> 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>");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user