From d26cb81854526c1ddaf95d80ed5b8c984851e9be Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sun, 19 Feb 2017 22:31:25 -0800 Subject: [PATCH] dtors --- main.cpp | 6 ++-- tests/constructors/constructor.cc | 11 +++--- tests/constructors/destructor.cc | 60 ++++++++++++++++++++++++++++--- 3 files changed, 66 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index 48efbdc3..9333f676 100644 --- a/main.cpp +++ b/main.cpp @@ -1252,6 +1252,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { case CXIdxEntity_Function: case CXIdxEntity_CXXConstructor: + case CXIdxEntity_CXXDestructor: case CXIdxEntity_CXXInstanceMethod: case CXIdxEntity_CXXStaticMethod: { @@ -1323,7 +1324,7 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) { std::optional type_ref = FindChildOfKind(decl->cursor, CXCursor_TypeRef); assert(type_ref.has_value()); TypeId alias_of = db->ToTypeId(type_ref.value().get_referenced().get_usr()); - + TypeDef* type_def = db->Resolve(type_id); type_def->alias_of = alias_of; @@ -1424,6 +1425,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re case CXIdxEntity_CXXStaticMethod: case CXIdxEntity_CXXInstanceMethod: case CXIdxEntity_Function: + case CXIdxEntity_CXXConstructor: { // TODO: Redirect container to constructor for // int Gen() { return 5; } @@ -1704,7 +1706,7 @@ int main(int argc, char** argv) { for (std::string path : GetFilesInFolder("tests")) { // TODO: Fix all existing tests. //if (path == "tests/usage/type_usage_declare_extern.cc") continue; - if (path == "tests/constructors/constructor.cc") continue; + //if (path != "tests/constructors/destructor.cc") continue; //if (path != "tests/usage/usage_inside_of_call.cc") continue; //if (path != "tests/usage/type_usage_typedef_and_using.cc") continue; //if (path != "tests/usage/type_usage_declare_local.cc") continue; diff --git a/tests/constructors/constructor.cc b/tests/constructors/constructor.cc index 12eceb1b..cfc82647 100644 --- a/tests/constructors/constructor.cc +++ b/tests/constructors/constructor.cc @@ -17,7 +17,7 @@ OUTPUT: "qualified_name": "Foo", "definition": "tests/constructors/constructor.cc:1:7", "funcs": [0], - "all_uses": ["tests/constructors/constructor.cc:7:3"] + "all_uses": ["tests/constructors/constructor.cc:1:7", "tests/constructors/constructor.cc:7:3"], "interesting_uses": ["tests/constructors/constructor.cc:7:3"] }], "functions": [{ @@ -28,14 +28,15 @@ OUTPUT: "definition": "tests/constructors/constructor.cc:3:3", "declaring_type": 0, "callers": ["1@tests/constructors/constructor.cc:7:7"], - "uses": ["tests/constructors/constructor.cc:7:7"] + "all_uses": ["tests/constructors/constructor.cc:3:3", "tests/constructors/constructor.cc:7:7"] }, { "id": 1, "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", "definition": "tests/constructors/constructor.cc:6:6", - "callees": ["0@tests/constructors/constructor.cc:7:7"] + "callees": ["0@tests/constructors/constructor.cc:7:7"], + "all_uses": ["tests/constructors/constructor.cc:6:6"] }], "variables": [{ "id": 0, @@ -43,8 +44,8 @@ OUTPUT: "short_name": "f", "qualified_name": "f", "declaration": "tests/constructors/constructor.cc:7:7", - "initializations": ["tests/constructors/constructor.cc:7:7"], - "variable_type": 0 + "variable_type": 0, + "all_uses": ["tests/constructors/constructor.cc:7:7"] }] } */ \ No newline at end of file diff --git a/tests/constructors/destructor.cc b/tests/constructors/destructor.cc index fcae946f..0d245c48 100644 --- a/tests/constructors/destructor.cc +++ b/tests/constructors/destructor.cc @@ -1,4 +1,14 @@ -// TODO: Support destructors. +class Foo { +public: + Foo() {} + ~Foo() {}; +}; + +void foo() { + Foo f; +} + +// TODO: Support destructors (notice how the dtor has no usages listed). // - check if variable is a pointer. if so, do *not* insert dtor // - check if variable is normal type. if so, insert dtor // - scan for statements that look like dtors in function def handler @@ -6,8 +16,50 @@ /* OUTPUT: { - "types": [], - "functions": [], - "variables": [] + "types": [{ + "id": 0, + "usr": "c:@S@Foo", + "short_name": "Foo", + "qualified_name": "Foo", + "definition": "tests/constructors/destructor.cc:1:7", + "funcs": [0, 1], + "all_uses": ["tests/constructors/destructor.cc:1:7", "tests/constructors/destructor.cc:8:3"], + "interesting_uses": ["tests/constructors/destructor.cc:8:3"] + }], + "functions": [{ + "id": 0, + "usr": "c:@S@Foo@F@Foo#", + "short_name": "Foo", + "qualified_name": "Foo::Foo", + "definition": "tests/constructors/destructor.cc:3:3", + "declaring_type": 0, + "callers": ["2@tests/constructors/destructor.cc:8:7"], + "all_uses": ["tests/constructors/destructor.cc:3:3", "tests/constructors/destructor.cc:8:7"] + }, { + "id": 1, + "usr": "c:@S@Foo@F@~Foo#", + "short_name": "~Foo", + "qualified_name": "Foo::~Foo", + "definition": "tests/constructors/destructor.cc:4:3", + "declaring_type": 0, + "all_uses": ["tests/constructors/destructor.cc:4:3"] + }, { + "id": 2, + "usr": "c:@F@foo#", + "short_name": "foo", + "qualified_name": "foo", + "definition": "tests/constructors/destructor.cc:7:6", + "callees": ["0@tests/constructors/destructor.cc:8:7"], + "all_uses": ["tests/constructors/destructor.cc:7:6"] + }], + "variables": [{ + "id": 0, + "usr": "c:destructor.cc@70@F@foo#@f", + "short_name": "f", + "qualified_name": "f", + "declaration": "tests/constructors/destructor.cc:8:7", + "variable_type": 0, + "all_uses": ["tests/constructors/destructor.cc:8:7"] + }] } */ \ No newline at end of file