Add call refs from ctor context

This commit is contained in:
Jacob Dufault 2017-04-08 11:36:32 -07:00
parent eec863da9a
commit f0e8d0110c
5 changed files with 102 additions and 7 deletions

View File

@ -7,11 +7,13 @@
-IC:/Users/jacob/Desktop/superindex/indexer/third_party
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/doctest
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/rapidjson/include
-IC:/Users/jacob/Desktop/superindex/indexer/third_party/sparsehash/src
-IC:/Program Files/LLVM/include
# OSX
#-I/Users/jdufault/Personal/super-clang-index/third_party
#-I/Users/jdufault/Personal/super-clang-index/third_party/doctest
#-I/Users/jdufault/Personal/super-clang-index/third_party/rapidjson/include
#-I/Users/jdufault/Personal/super-clang-index/third_party/sparsehash/src
#-I/Users/jdufault/Personal/super-clang-index/build/clang+llvm-4.0.0-x86_64-apple-darwin/include
# Use libcxx

View File

@ -1051,10 +1051,17 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
}
}
bool IsFunction(CXCursorKind kind) {
bool IsFunctionCallContext(CXCursorKind kind) {
switch (kind) {
case CXCursor_CXXMethod:
case CXCursor_FunctionDecl:
case CXCursor_CXXMethod:
case CXCursor_Constructor:
case CXCursor_Destructor:
case CXCursor_ConversionFunction:
case CXCursor_FunctionTemplate:
case CXCursor_OverloadedDeclRef:
// TODO: we need to test lambdas
case CXCursor_LambdaExpr:
return true;
}
@ -1069,6 +1076,17 @@ void indexEntityReference(CXClientData client_data,
// clang_Location_isInSystemHeader(
// clang_getCursorLocation(ref->referencedEntity->cursor)))
// return;
IndexParam* param = static_cast<IndexParam*>(client_data);
IndexedFile* db = param->db;
// ref->cursor mainFile=0
// ref->loc mainFile=1
// ref->referencedEntity mainFile=1
//
// Regardless, we need to do more advanced location processing to handle multiple output IndexedFile instances.
//bool mainFile = clang_Location_isFromMainFile(clang_indexLoc_getCXSourceLocation(ref->loc));
//Range loc_spelling = param->db->id_cache.ForceResolveSpelling(ref->cursor, false /*interesting*/);
//std::cerr << "mainFile: " << mainFile << ", loc: " << loc_spelling.ToString() << std::endl;
// Don't index references that are not from the main file.
if (!clang_Location_isFromMainFile(clang_getCursorLocation(ref->cursor)))
@ -1077,8 +1095,7 @@ void indexEntityReference(CXClientData client_data,
if (clang_Location_isInSystemHeader(clang_getCursorLocation(ref->referencedEntity->cursor)))
return;
IndexParam* param = static_cast<IndexParam*>(client_data);
IndexedFile* db = param->db;
clang::Cursor cursor(ref->cursor);
// std::cerr << "REF kind=" << ref->referencedEntity->kind << " at " <<
@ -1135,7 +1152,7 @@ void indexEntityReference(CXClientData client_data,
// Note: be careful, calling db->ToFuncId invalidates the FuncDef* ptrs.
IndexFuncId called_id = db->ToFuncId(ref->referencedEntity->USR);
if (IsFunction(ref->container->cursor.kind)) {
if (IsFunctionCallContext(ref->container->cursor.kind)) {
IndexFuncId caller_id = db->ToFuncId(ref->container->cursor);
IndexedFuncDef* caller_def = db->Resolve(caller_id);
IndexedFuncDef* called_def = db->Resolve(called_id);
@ -1257,7 +1274,7 @@ IndexedFile Parse(std::string filename,
clang::Index index(0 /*excludeDeclarationsFromPCH*/,
0 /*displayDiagnostics*/);
clang::TranslationUnit tu(index, filename, args, {} /*unsaved_files*/, CXTranslationUnit_None);
clang::TranslationUnit tu(index, filename, args, {} /*unsaved_files*/, CXTranslationUnit_KeepGoing);
if (dump_ast)
Dump(tu.document_cursor());

View File

@ -108,7 +108,7 @@ void RunTests() {
//if (path != "tests/templates/namespace_template_class_template_func_usage_folded_into_one.cc") continue;
//if (path != "tests/multi_file/header.h") continue;
//if (path != "tests/multi_file/impl.cc") continue;
//if (path != "tests/constructors/constructor.cc") continue;
//if (path != "tests/usage/func_called_from_macro_argument.cc") continue;
//if (path != "tests/templates/implicit_variable_instantiation.cc") continue;
//if (path != "tests/_empty_test.cc") continue;

View File

@ -0,0 +1,46 @@
void called() {}
struct Foo {
Foo();
};
Foo::Foo() {
called();
}
/*
OUTPUT:
{
"types": [{
"id": 0,
"usr": "c:@S@Foo",
"short_name": "Foo",
"qualified_name": "Foo",
"definition_spelling": "3:8-3:11",
"definition_extent": "3:1-5:2",
"funcs": [1],
"uses": ["*3:8-3:11", "4:3-4:6", "7:6-7:9", "7:1-7:4"]
}],
"funcs": [{
"id": 0,
"usr": "c:@F@called#",
"short_name": "called",
"qualified_name": "called",
"definition_spelling": "1:6-1:12",
"definition_extent": "1:1-1:17",
"callers": ["1@8:3-8:9"],
"uses": ["1:6-1:12", "8:3-8:9"]
}, {
"id": 1,
"usr": "c:@S@Foo@F@Foo#",
"short_name": "Foo",
"qualified_name": "Foo::Foo",
"declarations": ["4:3-4:6"],
"definition_spelling": "7:6-7:9",
"definition_extent": "7:1-9:2",
"declaring_type": 0,
"callees": ["0@8:3-8:9"],
"uses": ["4:3-4:6", "7:6-7:9"]
}]
}
*/

View File

@ -0,0 +1,30 @@
#define MACRO_CALL(e) e
bool called(bool a, bool b);
void caller() {
MACRO_CALL(called(true, true));
}
/*
// TODO FIXME: called() has no callers.
OUTPUT:
{
"funcs": [{
"id": 0,
"usr": "c:@F@called#b#b#",
"short_name": "called",
"qualified_name": "called",
"declarations": ["3:6-3:12"],
"uses": ["3:6-3:12"]
}, {
"id": 1,
"usr": "c:@F@caller#",
"short_name": "caller",
"qualified_name": "caller",
"definition_spelling": "5:6-5:12",
"definition_extent": "5:1-7:2",
"uses": ["5:6-5:12"]
}]
}
*/