From 8b534175f5b7368d6bf8a1a0a3cdd98b6aacef89 Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 19 Feb 2017 01:43:52 -0800 Subject: [PATCH] enable-ctors --- main.cpp | 29 ++++++++++----- tests/constructors/constructor.cc | 38 ++++++-------------- tests/usage/type_usage_declare_local.cc | 8 ++++- tests/usage/type_usage_declare_qualifiers.cc | 8 ++++- tests/usage/usage_inside_of_call.cc | 10 +++++- tests/usage/var_usage_class_member.cc | 7 +++- 6 files changed, 60 insertions(+), 40 deletions(-) diff --git a/main.cpp b/main.cpp index 47ab5c0f..c4df6ff8 100644 --- a/main.cpp +++ b/main.cpp @@ -628,16 +628,11 @@ clang::VisiterResult VarDeclVisitor(clang::Cursor cursor, clang::Cursor parent, } return clang::VisiterResult::Continue; + case CXCursor_CallExpr: case CXCursor_UnexposedExpr: case CXCursor_UnaryOperator: return clang::VisiterResult::Continue; - /* - case CXCursor_CallExpr: - // TODO: Add a test for parameters inside the call? We should probably recurse. - InsertReference(param->db, param->func_id, cursor); - return clang::VisiterResult::Continue; - */ default: std::cerr << "VarDeclVisitor unhandled " << cursor.ToString() << std::endl; return clang::VisiterResult::Continue; @@ -762,8 +757,25 @@ clang::VisiterResult VisitFuncDefinition(clang::Cursor cursor, clang::Cursor par */ case CXCursor_CallExpr: - // The called element is handled by DeclRefExpr below. - //InsertReference(param->db, param->func_id, cursor); + // When CallExpr points to a constructor, it does not have a child + // DeclRefExpr which also points to the constructor. Normal function calls + // (to a function of any type) look like this: + // + // CallExpr func_name + // ... (setup this pointer) + // *RefExpr func_name + // ... (setup arguments) + // + // Constructors, on the other hand, look like this: + // + // CallExpr func_name + // ... (setup arguments) + // + // We can't check the parent for a VarDecl, because a normal CallExpr could + // point to that. We simply check if the cursor references a constructor, + // and if so, insert the reference now, since it won't happen later. + if (cursor.get_referenced().get_kind() == CXCursor_Constructor) + InsertReference(param->db, param->func_id, cursor); return clang::VisiterResult::Recurse; case CXCursor_MemberRefExpr: @@ -1117,6 +1129,7 @@ int main(int argc, char** argv) { for (std::string path : GetFilesInFolder("tests")) { // TODO: Fix all existing tests. //if (path != "tests/constructors/constructor.cc") continue; + //if (path != "tests/usage/type_usage_declare_local.cc") continue; //if (path != "tests/usage/func_usage_addr_func.cc") continue; //if (path != "tests/usage/type_usage_on_return_type.cc") continue; diff --git a/tests/constructors/constructor.cc b/tests/constructors/constructor.cc index d0bdb2fb..e8227adf 100644 --- a/tests/constructors/constructor.cc +++ b/tests/constructors/constructor.cc @@ -1,18 +1,14 @@ -// TODO: Reenable -#if false class Foo { public: Foo() {} - ~Foo() {} }; void foo() { Foo f; } -#endif /* -O2UTPUT: +OUTPUT: { "types": [{ "id": 0, @@ -20,8 +16,8 @@ O2UTPUT: "short_name": "Foo", "qualified_name": "Foo", "definition": "tests/constructors/constructor.cc:1:7", - "funcs": [0, 1], - "uses": ["tests/constructors/constructor.cc:8:3"] + "funcs": [0], + "uses": ["tests/constructors/constructor.cc:7:3"] }], "functions": [{ "id": 0, @@ -30,38 +26,24 @@ O2UTPUT: "qualified_name": "Foo::Foo", "definition": "tests/constructors/constructor.cc:3:3", "declaring_type": 0, - "callers": ["2@tests/constructors/constructor.cc:8:7"], - "uses": ["tests/constructors/constructor.cc:8:7"] + "callers": ["1@tests/constructors/constructor.cc:7:7"], + "uses": ["tests/constructors/constructor.cc:7:7"] }, { "id": 1, - "usr": "c:@S@Foo@F@~Foo#", - "short_name": "~Foo", - "qualified_name": "Foo::~Foo", - "definition": "tests/constructors/constructor.cc:4:3", - "declaring_type": 0 - }, { - "id": 2, "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", - "definition": "tests/constructors/constructor.cc:7:6", - "callees": ["0@tests/constructors/constructor.cc:8:7"] + "definition": "tests/constructors/constructor.cc:6:6", + "callees": ["0@tests/constructors/constructor.cc:7:7"] }], "variables": [{ "id": 0, - "usr": "c:constructor.cc@69@F@foo#@f", + "usr": "c:constructor.cc@56@F@foo#@f", "short_name": "f", "qualified_name": "f", - "declaration": "tests/constructors/constructor.cc:8:7", - "initializations": ["tests/constructors/constructor.cc:8:7"], + "declaration": "tests/constructors/constructor.cc:7:7", + "initializations": ["tests/constructors/constructor.cc:7:7"], "variable_type": 0 }] } - -OUTPUT: -{ - "types": [], - "functions": [], - "variables": [] -} */ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_local.cc b/tests/usage/type_usage_declare_local.cc index 906ba578..c9ea581b 100644 --- a/tests/usage/type_usage_declare_local.cc +++ b/tests/usage/type_usage_declare_local.cc @@ -29,7 +29,13 @@ OUTPUT: "usr": "c:@F@Foo#", "short_name": "Foo", "qualified_name": "Foo", - "definition": "tests/usage/type_usage_declare_local.cc:4:6" + "definition": "tests/usage/type_usage_declare_local.cc:4:6", + "callees": ["1@tests/usage/type_usage_declare_local.cc:6:19"] + }, { + "id": 1, + "usr": "c:@S@ImplementedType@F@ImplementedType#", + "callers": ["0@tests/usage/type_usage_declare_local.cc:6:19"], + "uses": ["tests/usage/type_usage_declare_local.cc:6:19"] }], "variables": [{ "id": 0, diff --git a/tests/usage/type_usage_declare_qualifiers.cc b/tests/usage/type_usage_declare_qualifiers.cc index 2c063fdd..97969e6e 100644 --- a/tests/usage/type_usage_declare_qualifiers.cc +++ b/tests/usage/type_usage_declare_qualifiers.cc @@ -22,7 +22,13 @@ OUTPUT: "usr": "c:@F@foo#&$@S@Type#&1S1_#", "short_name": "foo", "qualified_name": "foo", - "definition": "tests/usage/type_usage_declare_qualifiers.cc:3:6" + "definition": "tests/usage/type_usage_declare_qualifiers.cc:3:6", + "callees": ["1@tests/usage/type_usage_declare_qualifiers.cc:4:8"] + }, { + "id": 1, + "usr": "c:@S@Type@F@Type#", + "callers": ["0@tests/usage/type_usage_declare_qualifiers.cc:4:8"], + "uses": ["tests/usage/type_usage_declare_qualifiers.cc:4:8"] }], "variables": [{ "id": 0, diff --git a/tests/usage/usage_inside_of_call.cc b/tests/usage/usage_inside_of_call.cc index 21491cf5..d19abfd2 100644 --- a/tests/usage/usage_inside_of_call.cc +++ b/tests/usage/usage_inside_of_call.cc @@ -45,8 +45,16 @@ OUTPUT: "short_name": "foo", "qualified_name": "foo", "definition": "tests/usage/usage_inside_of_call.cc:10:6", - "callees": ["0@tests/usage/usage_inside_of_call.cc:12:3", "1@tests/usage/usage_inside_of_call.cc:12:14"] + "callees": ["0@tests/usage/usage_inside_of_call.cc:12:3", "1@tests/usage/usage_inside_of_call.cc:12:14", "3@tests/usage/usage_inside_of_call.cc:12:22"] + }, { + "id": 3, + "usr": "c:@S@Foo@F@Foo#", + "callers": ["2@tests/usage/usage_inside_of_call.cc:12:22"], + "uses": ["tests/usage/usage_inside_of_call.cc:12:22"] }], + + + "variables": [{ "id": 0, "usr": "c:@S@Foo@static_var", diff --git a/tests/usage/var_usage_class_member.cc b/tests/usage/var_usage_class_member.cc index 6d1c54e8..322a2b36 100644 --- a/tests/usage/var_usage_class_member.cc +++ b/tests/usage/var_usage_class_member.cc @@ -51,7 +51,12 @@ OUTPUT: "short_name": "foo", "qualified_name": "foo", "definition": "tests/usage/var_usage_class_member.cc:10:6", - "callees": ["0@tests/usage/var_usage_class_member.cc:14:3", "0@tests/usage/var_usage_class_member.cc:15:3", "1@tests/usage/var_usage_class_member.cc:16:3", "0@tests/usage/var_usage_class_member.cc:17:3"] + "callees": ["3@tests/usage/var_usage_class_member.cc:11:7", "0@tests/usage/var_usage_class_member.cc:14:3", "0@tests/usage/var_usage_class_member.cc:15:3", "1@tests/usage/var_usage_class_member.cc:16:3", "0@tests/usage/var_usage_class_member.cc:17:3"] + }, { + "id": 3, + "usr": "c:@S@Foo@F@Foo#", + "callers": ["2@tests/usage/var_usage_class_member.cc:11:7"], + "uses": ["tests/usage/var_usage_class_member.cc:11:7"] }], "variables": [{ "id": 0,