From a8cdadc201620993ece0be8d8e2b3d200448701b Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 18 Feb 2017 15:58:40 -0800 Subject: [PATCH] wip --- libclangmm/Cursor.cc | 83 ++++ libclangmm/Cursor.h | 3 + main.cpp | 391 ++++++++++-------- tests/class_forward_declaration.cc | 9 +- tests/function_declaration.cc | 1 + tests/function_declaration_definition.cc | 10 +- tests/function_definition.cc | 11 +- tests/method_declaration.cc | 10 +- tests/method_definition.cc | 20 +- tests/method_inline_declaration.cc | 19 +- tests/namespaces/anonymous_function.cc | 1 + tests/namespaces/function_declaration.cc | 1 + tests/namespaces/function_definition.cc | 11 +- tests/namespaces/method_declaration.cc | 10 +- tests/namespaces/method_definition.cc | 18 +- tests/namespaces/method_inline_declaration.cc | 19 +- tests/usage/func_usage_addr_func.cc | 42 +- tests/usage/func_usage_addr_method.cc | 48 ++- tests/usage/func_usage_call_func.cc | 22 +- tests/usage/func_usage_call_method.cc | 48 ++- .../usage/func_usage_class_inline_var_def.cc | 41 +- tests/usage/func_usage_forward_decl_func.cc | 28 ++ tests/usage/func_usage_forward_decl_method.cc | 49 +++ tests/usage/type_usage_declare_extern.cc | 23 ++ ...rn_func.cc => type_usage_declare_field.cc} | 0 ..._method.cc => type_usage_declare_local.cc} | 0 tests/usage/type_usage_declare_param.cc | 8 + tests/usage/type_usage_declare_static.cc | 8 + tests/vars/class_member.cc | 18 +- tests/vars/class_static_member.cc | 18 +- tests/vars/class_static_member_decl_only.cc | 15 +- tests/vars/function_local.cc | 21 +- tests/vars/function_param.cc | 26 +- tests/vars/function_param_unnamed.cc | 37 +- tests/vars/function_shadow_local.cc | 26 +- tests/vars/function_shadow_param.cc | 26 +- tests/vars/global_variable.cc | 10 +- tests/vars/global_variable_decl_only.cc | 7 +- 38 files changed, 660 insertions(+), 478 deletions(-) create mode 100644 tests/usage/func_usage_forward_decl_func.cc create mode 100644 tests/usage/func_usage_forward_decl_method.cc create mode 100644 tests/usage/type_usage_declare_extern.cc rename tests/usage/{func_usage_extern_func.cc => type_usage_declare_field.cc} (100%) rename tests/usage/{func_usage_extern_method.cc => type_usage_declare_local.cc} (100%) create mode 100644 tests/usage/type_usage_declare_param.cc create mode 100644 tests/usage/type_usage_declare_static.cc diff --git a/libclangmm/Cursor.cc b/libclangmm/Cursor.cc index 703a843b..b7837178 100644 --- a/libclangmm/Cursor.cc +++ b/libclangmm/Cursor.cc @@ -165,6 +165,89 @@ std::string Cursor::get_type_description() const { return spelling; } +std::string Cursor::evaluate() const { + CXEvalResult eval = clang_Cursor_Evaluate(cx_cursor); + + std::string result; + auto kind = clang_EvalResult_getKind(eval); + switch (clang_EvalResult_getKind(eval)) { + case CXEval_Int: + result = std::to_string(clang_EvalResult_getAsInt(eval)); + break; + case CXEval_Float: + result = std::to_string(clang_EvalResult_getAsDouble(eval)); + break; + default: + { + const char* r = clang_EvalResult_getAsStr(eval); + if (r) + result = r; + break; + } + } + + clang_EvalResult_dispose(eval); + return result; + +#if false + typedef enum { + CXEval_Int = 1, + CXEval_Float = 2, + CXEval_ObjCStrLiteral = 3, + CXEval_StrLiteral = 4, + CXEval_CFStr = 5, + CXEval_Other = 6, + + CXEval_UnExposed = 0 + + } CXEvalResultKind; + + /** + * \brief Evaluation result of a cursor + */ + typedef void * CXEvalResult; + + /** + * \brief If cursor is a statement declaration tries to evaluate the + * statement and if its variable, tries to evaluate its initializer, + * into its corresponding type. + */ + CINDEX_LINKAGE CXEvalResult clang_Cursor_Evaluate(CXCursor C); + + /** + * \brief Returns the kind of the evaluated result. + */ + CINDEX_LINKAGE CXEvalResultKind clang_EvalResult_getKind(CXEvalResult E); + + /** + * \brief Returns the evaluation result as integer if the + * kind is Int. + */ + CINDEX_LINKAGE int clang_EvalResult_getAsInt(CXEvalResult E); + + /** + * \brief Returns the evaluation result as double if the + * kind is double. + */ + CINDEX_LINKAGE double clang_EvalResult_getAsDouble(CXEvalResult E); + + /** + * \brief Returns the evaluation result as a constant string if the + * kind is other than Int or float. User must not free this pointer, + * instead call clang_EvalResult_dispose on the CXEvalResult returned + * by clang_Cursor_Evaluate. + */ + CINDEX_LINKAGE const char* clang_EvalResult_getAsStr(CXEvalResult E); + + /** + * \brief Disposes the created Eval memory. + */ + CINDEX_LINKAGE void clang_EvalResult_dispose(CXEvalResult E); +#endif + + +} + std::string Cursor::get_comments() const { Cursor referenced = get_referenced(); if (referenced) diff --git a/libclangmm/Cursor.h b/libclangmm/Cursor.h index e5d18fe8..96bcc38b 100644 --- a/libclangmm/Cursor.h +++ b/libclangmm/Cursor.h @@ -57,6 +57,9 @@ public: Cursor get_semantic_parent() const; std::vector get_arguments() const; bool is_valid_kind() const; + + std::string evaluate() const; + std::string get_type_description() const; std::string get_comments() const; diff --git a/main.cpp b/main.cpp index c390c304..190c2604 100644 --- a/main.cpp +++ b/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -157,7 +158,7 @@ struct ParsingDatabase { FuncDef* Resolve(FuncId id); VarDef* Resolve(VarId id); - std::string ToString(bool for_test); + std::string ToString(); }; TypeId ParsingDatabase::ToTypeId(const std::string& usr) { @@ -201,64 +202,100 @@ VarDef* ParsingDatabase::Resolve(VarId id) { return &vars[id.local_id]; } -template -void WriteLocation(TWriter& writer, clang::SourceLocation location) { + +using Writer = rapidjson::PrettyWriter; + +void Write(Writer& writer, const char* key, clang::SourceLocation location) { + if (key) writer.Key(key); std::string s = location.ToString(); writer.String(s.c_str()); } -template -void WriteLocation(TWriter& writer, std::optional location) { - if (location) - WriteLocation(writer, location.value()); - else - writer.Null(); +void Write(Writer& writer, const char* key, std::optional location) { + if (location) { + Write(writer, key, location.value()); + } + //else { + // if (key) writer.Key(key); + // writer.Null(); + //} } -template -void WriteId(TWriter& writer, TId id) { +void Write(Writer& writer, const char* key, const std::vector& locs) { + if (locs.size() == 0) + return; + + if (key) writer.Key(key); + writer.StartArray(); + for (const clang::SourceLocation& loc : locs) + Write(writer, nullptr, loc); + writer.EndArray(); +} + +template +void Write(Writer& writer, const char* key, LocalId id) { + if (key) writer.Key(key); writer.Uint64(id.local_id); } -template -void WriteId(TWriter& writer, std::optional id) { - if (id) - WriteId(writer, id.value()); - else - writer.Null(); +template +void Write(Writer& writer, const char* key, std::optional> id) { + if (id) { + Write(writer, key, id.value()); + } + //else { + // if (key) writer.Key(key); + // writer.Null(); + //} } -template -void WriteRef(TWriter& writer, TRef ref) { +template +void Write(Writer& writer, const char* key, const std::vector>& ids) { + if (ids.size() == 0) + return; + + if (key) writer.Key(key); + writer.StartArray(); + for (LocalId id : ids) + Write(writer, nullptr, id); + writer.EndArray(); +} + +template +void Write(Writer& writer, const char* key, Ref ref) { + if (key) writer.Key(key); std::string s = std::to_string(ref.id.local_id) + "@" + ref.loc.ToString(); writer.String(s.c_str()); } -template -void WriteIdArray(TWriter& writer, const std::vector& ids) { +template +void Write(Writer& writer, const char* key, const std::vector>& refs) { + if (refs.size() == 0) + return; + + if (key) writer.Key(key); writer.StartArray(); - for (TId id : ids) - WriteId(writer, id); + for (Ref ref : refs) + Write(writer, nullptr, ref); writer.EndArray(); } -template -void WriteRefArray(TWriter& writer, const std::vector& refs) { - writer.StartArray(); - for (TRef ref : refs) - WriteRef(writer, ref); - writer.EndArray(); +void Write(Writer& writer, const char* key, const std::string& value) { + if (value.size() == 0) + return; + + if (key) writer.Key(key); + writer.String(value.c_str()); } -template -void WriteLocationArray(TWriter& writer, const std::vector& locs) { - writer.StartArray(); - for (const clang::SourceLocation& loc : locs) - WriteLocation(writer, loc); - writer.EndArray(); +void Write(Writer& writer, const char* key, uint64_t value) { + if (key) writer.Key(key); + writer.Uint64(value); } -std::string ParsingDatabase::ToString(bool for_test) { +std::string ParsingDatabase::ToString() { +#define WRITE(name) Write(writer, #name, def.name) + rapidjson::StringBuffer output; rapidjson::PrettyWriter writer(output); writer.SetFormatOptions( @@ -272,50 +309,18 @@ std::string ParsingDatabase::ToString(bool for_test) { writer.StartArray(); for (TypeDef& def : types) { writer.StartObject(); - - writer.String("id"); - writer.Uint64(def.id.local_id); - - if (!for_test) { - writer.String("usr"); - writer.String(def.usr.c_str()); - } - - writer.String("short_name"); - writer.String(def.short_name.c_str()); - - writer.String("qualified_name"); - writer.String(def.qualified_name.c_str()); - - writer.String("declaration"); - WriteLocation(writer, def.declaration); - - if (!def.definition) { - writer.EndObject(); - continue; - } - - writer.String("definition"); - WriteLocation(writer, def.definition); - - writer.String("parents"); - WriteIdArray(writer, def.parents); - - writer.String("derived"); - WriteIdArray(writer, def.derived); - - writer.String("types"); - WriteIdArray(writer, def.types); - - writer.String("funcs"); - WriteIdArray(writer, def.funcs); - - writer.String("vars"); - WriteIdArray(writer, def.vars); - - writer.String("uses"); - WriteLocationArray(writer, def.uses); - + WRITE(id); + WRITE(usr); + WRITE(short_name); + WRITE(qualified_name); + WRITE(declaration); + WRITE(definition); + WRITE(parents); + WRITE(derived); + WRITE(types); + WRITE(funcs); + WRITE(vars); + WRITE(uses); writer.EndObject(); } writer.EndArray(); @@ -325,54 +330,19 @@ std::string ParsingDatabase::ToString(bool for_test) { writer.StartArray(); for (FuncDef& def : funcs) { writer.StartObject(); - - writer.String("id"); - writer.Uint64(def.id.local_id); - - if (!for_test) { - writer.String("usr"); - writer.String(def.usr.c_str()); - } - - writer.String("short_name"); - writer.String(def.short_name.c_str()); - - writer.String("qualified_name"); - writer.String(def.qualified_name.c_str()); - - writer.String("declaration"); - WriteLocation(writer, def.declaration); - - if (def.definition) { - writer.String("definition"); - WriteLocation(writer, def.definition); - } - - if (def.definition || def.declaring_type) { - writer.String("declaring_type"); - WriteId(writer, def.declaring_type); - } - - if (def.definition) { - writer.String("base"); - WriteId(writer, def.base); - - writer.String("derived"); - WriteIdArray(writer, def.derived); - - writer.String("locals"); - WriteIdArray(writer, def.locals); - - writer.String("callers"); - WriteRefArray(writer, def.callers); - - writer.String("callees"); - WriteRefArray(writer, def.callees); - - writer.String("uses"); - WriteLocationArray(writer, def.uses); - } - + WRITE(id); + WRITE(usr); + WRITE(short_name); + WRITE(qualified_name); + WRITE(declaration); + WRITE(definition); + WRITE(declaring_type); + WRITE(base); + WRITE(derived); + WRITE(locals); + WRITE(callers); + WRITE(callees); + WRITE(uses); writer.EndObject(); } writer.EndArray(); @@ -382,36 +352,15 @@ std::string ParsingDatabase::ToString(bool for_test) { writer.StartArray(); for (VarDef& def : vars) { writer.StartObject(); - - writer.String("id"); - writer.Uint64(def.id.local_id); - - if (!for_test) { - writer.String("usr"); - writer.String(def.usr.c_str()); - } - - writer.String("short_name"); - writer.String(def.short_name.c_str()); - - writer.String("qualified_name"); - writer.String(def.qualified_name.c_str()); - - writer.String("declaration"); - WriteLocation(writer, def.declaration); - - writer.String("initializations"); - WriteLocationArray(writer, def.initializations); - - writer.String("variable_type"); - WriteId(writer, def.variable_type); - - writer.String("declaring_type"); - WriteId(writer, def.declaring_type); - - writer.String("uses"); - WriteLocationArray(writer, def.uses); - + WRITE(id); + WRITE(usr); + WRITE(short_name); + WRITE(qualified_name); + WRITE(declaration); + WRITE(initializations); + WRITE(variable_type); + WRITE(declaring_type); + WRITE(uses); writer.EndObject(); } writer.EndArray(); @@ -419,6 +368,8 @@ std::string ParsingDatabase::ToString(bool for_test) { writer.EndObject(); return output.GetString(); + +#undef WRITE } struct FileDef { @@ -580,7 +531,6 @@ void Dump(clang::Cursor cursor) { void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, std::optional declaring_type) { - //Dump(var); VarId var_id = db->ToVarId(var.get_usr()); @@ -622,25 +572,34 @@ void HandleVarDecl(ParsingDatabase* db, NamespaceStack* ns, clang::Cursor var, s // |func_id| is the function definition that is currently being processed. void InsertReference(ParsingDatabase* db, FuncId func_id, clang::Cursor referencer) { + clang::SourceLocation loc = referencer.get_source_location(); clang::Cursor referenced = referencer.get_referenced(); switch (referenced.get_kind()) { + case CXCursor_CXXMethod: case CXCursor_FunctionDecl: { FuncId referenced_id = db->ToFuncId(referenced.get_usr()); - clang::SourceLocation loc = referencer.get_source_location(); - - FuncDef* func_def = db->Resolve(func_id); FuncDef* referenced_def = db->Resolve(referenced_id); + FuncDef* func_def = db->Resolve(func_id); func_def->callees.push_back(FuncRef(referenced_id, loc)); referenced_def->callers.push_back(FuncRef(func_id, loc)); referenced_def->uses.push_back(loc); break; } + + case CXCursor_VarDecl: + { + VarId referenced_id = db->ToVarId(referenced.get_usr()); + VarDef* referenced_def = db->Resolve(referenced_id); + + referenced_def->uses.push_back(loc); + break; + } default: - std::cerr << "Unhandled reference from " << referencer.ToString() << " to " - << referenced.ToString() << std::endl; + std::cerr << "Unhandled reference from \"" << referencer.ToString() + << "\" to \"" << referenced.ToString() << "\"" << std::endl; break; } } @@ -656,21 +615,27 @@ struct FuncDefinitionParam { }; clang::VisiterResult VisitFuncDefinition(clang::Cursor cursor, clang::Cursor parent, FuncDefinitionParam* param) { - //std::cout << "VistFunc got " << cursor.ToString() << std::endl; + //std::cout << "VistFuncDefinition got " << cursor.ToString() << std::endl; switch (cursor.get_kind()) { - // TODO: Maybe we should default to recurse? - /* - case CXCursor_CompoundStmt: - case CXCursor_DeclStmt: - case CXCursor_CallExpr: - case CXCursor_UnexposedExpr: - case CXCursor_UnaryExpr: - return clang::VisiterResult::Recurse; - */ + // TODO: Maybe we should default to recurse? + /* + case CXCursor_CompoundStmt: + case CXCursor_DeclStmt: + case CXCursor_CallExpr: + case CXCursor_UnexposedExpr: + case CXCursor_UnaryExpr: + return clang::VisiterResult::Recurse; + */ + case CXCursor_CallExpr: + // The called element is handled by DeclRefExpr below. + //InsertReference(param->db, param->func_id, cursor); + return clang::VisiterResult::Recurse; + + case CXCursor_MemberRefExpr: case CXCursor_DeclRefExpr: InsertReference(param->db, param->func_id, cursor); - break; + return clang::VisiterResult::Continue; case CXCursor_VarDecl: case CXCursor_ParmDecl: @@ -832,6 +797,7 @@ clang::VisiterResult VisitFile(clang::Cursor cursor, clang::Cursor parent, FileP param->ns->Pop(); break; + case CXCursor_StructDecl: case CXCursor_ClassDecl: // TODO: Cleanup Handle* param order. HandleClassDecl(cursor, param->db, param->ns); @@ -900,12 +866,76 @@ void Write(const std::vector& strs) { } } +std::vector split_string(const std::string& str, const std::string& delimiter) { + // http://stackoverflow.com/a/13172514 + std::vector strings; + std::string::size_type pos = 0; + std::string::size_type prev = 0; + while ((pos = str.find(delimiter, prev)) != std::string::npos) { + strings.push_back(str.substr(prev, pos - prev)); + prev = pos + 1; + } + + // To get the last substring (or only, if delimiter is not found) + strings.push_back(str.substr(prev)); + + return strings; +} + +void DiffDocuments(rapidjson::Document& expected, rapidjson::Document& actual) { + std::vector actual_output; + { + rapidjson::StringBuffer buffer; + rapidjson::PrettyWriter writer(buffer); + writer.SetFormatOptions( + rapidjson::PrettyFormatOptions::kFormatSingleLineArray); + writer.SetIndent(' ', 2); + + buffer.Clear(); + actual.Accept(writer); + actual_output = split_string(buffer.GetString(), "\n"); + } + + std::vector expected_output; + { + rapidjson::StringBuffer buffer; + rapidjson::PrettyWriter writer(buffer); + writer.SetFormatOptions( + rapidjson::PrettyFormatOptions::kFormatSingleLineArray); + writer.SetIndent(' ', 2); + + buffer.Clear(); + expected.Accept(writer); + expected_output = split_string(buffer.GetString(), "\n"); + } + + int len = std::min(actual_output.size(), expected_output.size()); + for (int i = 0; i < len; ++i) { + if (actual_output[i] != expected_output[i]) { + std::cout << "Line " << i << " differs" << std::endl; + std::cout << " expected: " << expected_output[i] << std::endl; + std::cout << " actual: " << actual_output[i] << std::endl; + } + } + + if (actual_output.size() > len) { + std::cout << "Additional output in actual:" << std::endl; + for (int i = len; i < actual_output.size(); ++i) + std::cout << " " << actual_output[i] << std::endl; + } + + if (expected_output.size() > len) { + std::cout << "Additional output in expected:" << std::endl; + for (int i = len; i < expected_output.size(); ++i) + std::cout << " " << expected_output[i] << std::endl; + } +} int main(int argc, char** argv) { for (std::string path : GetFilesInFolder("tests")) { // TODO: Fix all existing tests. - if (path != "tests/usage/func_usage_addr_func.cc") continue; + //if (path != "tests/usage/func_usage_class_inline_var_def.cc") continue; // Parse expected output from the test, parse it into JSON document. std::string expected_output; @@ -916,7 +946,7 @@ int main(int argc, char** argv) { // Run test. std::cout << "[START] " << path << std::endl; ParsingDatabase db = Parse(path); - std::string actual_output = db.ToString(true /*for_test*/); + std::string actual_output = db.ToString(); rapidjson::Document actual; actual.Parse(actual_output.c_str()); @@ -929,10 +959,15 @@ int main(int argc, char** argv) { std::cout << expected_output; std::cout << "Actual output for " << path << ":" << std::endl; std::cout << actual_output; + std::cout << std::endl; + std::cout << std::endl; + DiffDocuments(expected, actual); break; } } std::cin.get(); return 0; -} \ No newline at end of file +} + +// TODO: ctor/dtor, copy ctor \ No newline at end of file diff --git a/tests/class_forward_declaration.cc b/tests/class_forward_declaration.cc index 5807fa67..fb49889c 100644 --- a/tests/class_forward_declaration.cc +++ b/tests/class_forward_declaration.cc @@ -8,16 +8,11 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", "declaration": "tests/class_forward_declaration.cc:1:7", - "definition": "tests/class_forward_declaration.cc:3:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [], - "vars": [], - "uses": [] + "definition": "tests/class_forward_declaration.cc:3:7" }], "functions": [], "variables": [] diff --git a/tests/function_declaration.cc b/tests/function_declaration.cc index 10599d20..9059e1c0 100644 --- a/tests/function_declaration.cc +++ b/tests/function_declaration.cc @@ -6,6 +6,7 @@ OUTPUT: "types": [], "functions": [{ "id": 0, + "usr": "c:@F@foo#I#I#", "short_name": "foo", "qualified_name": "foo", "declaration": "tests/function_declaration.cc:1:6" diff --git a/tests/function_declaration_definition.cc b/tests/function_declaration_definition.cc index eed9fbf8..92e5ef53 100644 --- a/tests/function_declaration_definition.cc +++ b/tests/function_declaration_definition.cc @@ -8,17 +8,11 @@ OUTPUT: "types": [], "functions": [{ "id": 0, + "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", "declaration": "tests/function_declaration_definition.cc:1:6", - "definition": "tests/function_declaration_definition.cc:3:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/function_declaration_definition.cc:3:6" }], "variables": [] } diff --git a/tests/function_definition.cc b/tests/function_definition.cc index 341cedd8..0ab8d667 100644 --- a/tests/function_definition.cc +++ b/tests/function_definition.cc @@ -6,17 +6,10 @@ OUTPUT: "types": [], "functions": [{ "id": 0, + "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", - "declaration": null, - "definition": "tests/function_definition.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/function_definition.cc:1:6" }], "variables": [] } diff --git a/tests/method_declaration.cc b/tests/method_declaration.cc index 6c9b50b5..c0ef6f46 100644 --- a/tests/method_declaration.cc +++ b/tests/method_declaration.cc @@ -7,19 +7,15 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", - "declaration": null, "definition": "tests/method_declaration.cc:1:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [0], - "vars": [], - "uses": [] + "funcs": [0] }], "functions": [{ "id": 0, + "usr": "c:@S@Foo@F@foo#", "short_name": "foo", "qualified_name": "Foo::foo", "declaration": "tests/method_declaration.cc:2:8", diff --git a/tests/method_definition.cc b/tests/method_definition.cc index ae2df2dd..91231489 100644 --- a/tests/method_definition.cc +++ b/tests/method_definition.cc @@ -5,36 +5,24 @@ class Foo { void Foo::foo() {} /* -// TODO: We are not inserting methods into declaring TypeDef. - OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", - "declaration": null, "definition": "tests/method_definition.cc:1:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [0], - "vars": [], - "uses": [] + "funcs": [0] }], "functions": [{ "id": 0, + "usr": "c:@S@Foo@F@foo#", "short_name": "foo", "qualified_name": "Foo::foo", "declaration": "tests/method_definition.cc:2:8", "definition": "tests/method_definition.cc:5:11", - "declaring_type": 0, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "declaring_type": 0 }], "variables": [] } diff --git a/tests/method_inline_declaration.cc b/tests/method_inline_declaration.cc index 35b93b3f..4e26a856 100644 --- a/tests/method_inline_declaration.cc +++ b/tests/method_inline_declaration.cc @@ -7,30 +7,19 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", - "declaration": null, "definition": "tests/method_inline_declaration.cc:1:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [0], - "vars": [], - "uses": [] + "funcs": [0] }], "functions": [{ "id": 0, + "usr": "c:@S@Foo@F@foo#", "short_name": "foo", "qualified_name": "Foo::foo", - "declaration": null, "definition": "tests/method_inline_declaration.cc:2:8", - "declaring_type": 0, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "declaring_type": 0 }], "variables": [] } diff --git a/tests/namespaces/anonymous_function.cc b/tests/namespaces/anonymous_function.cc index f47d5cdc..0abd7b20 100644 --- a/tests/namespaces/anonymous_function.cc +++ b/tests/namespaces/anonymous_function.cc @@ -8,6 +8,7 @@ OUTPUT: "types": [], "functions": [{ "id": 0, + "usr": "c:anonymous_function.cc@aN@F@foo#", "short_name": "foo", "qualified_name": "::foo", "declaration": "tests/namespaces/anonymous_function.cc:2:6" diff --git a/tests/namespaces/function_declaration.cc b/tests/namespaces/function_declaration.cc index 143dff84..dfa4d699 100644 --- a/tests/namespaces/function_declaration.cc +++ b/tests/namespaces/function_declaration.cc @@ -8,6 +8,7 @@ OUTPUT: "types": [], "functions": [{ "id": 0, + "usr": "c:@N@hello@F@foo#I#I#", "short_name": "foo", "qualified_name": "hello::foo", "declaration": "tests/namespaces/function_declaration.cc:2:6" diff --git a/tests/namespaces/function_definition.cc b/tests/namespaces/function_definition.cc index 628911e6..fdb59afe 100644 --- a/tests/namespaces/function_definition.cc +++ b/tests/namespaces/function_definition.cc @@ -8,17 +8,10 @@ OUTPUT: "types": [], "functions": [{ "id": 0, + "usr": "c:@N@hello@F@foo#", "short_name": "foo", "qualified_name": "hello::foo", - "declaration": null, - "definition": "tests/namespaces/function_definition.cc:2:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/namespaces/function_definition.cc:2:6" }], "variables": [] } diff --git a/tests/namespaces/method_declaration.cc b/tests/namespaces/method_declaration.cc index 43f4eb72..a41a2d21 100644 --- a/tests/namespaces/method_declaration.cc +++ b/tests/namespaces/method_declaration.cc @@ -9,19 +9,15 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@N@hello@S@Foo", "short_name": "Foo", "qualified_name": "hello::Foo", - "declaration": null, "definition": "tests/namespaces/method_declaration.cc:2:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [0], - "vars": [], - "uses": [] + "funcs": [0] }], "functions": [{ "id": 0, + "usr": "c:@N@hello@S@Foo@F@foo#", "short_name": "foo", "qualified_name": "hello::Foo::foo", "declaration": "tests/namespaces/method_declaration.cc:3:8", diff --git a/tests/namespaces/method_definition.cc b/tests/namespaces/method_definition.cc index b66cba72..b63e2b9a 100644 --- a/tests/namespaces/method_definition.cc +++ b/tests/namespaces/method_definition.cc @@ -11,30 +11,20 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@N@hello@S@Foo", "short_name": "Foo", "qualified_name": "hello::Foo", - "declaration": null, "definition": "tests/namespaces/method_definition.cc:2:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [0], - "vars": [], - "uses": [] + "funcs": [0] }], "functions": [{ "id": 0, + "usr": "c:@N@hello@S@Foo@F@foo#", "short_name": "foo", "qualified_name": "hello::Foo::foo", "declaration": "tests/namespaces/method_definition.cc:3:8", "definition": "tests/namespaces/method_definition.cc:6:11", - "declaring_type": 0, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "declaring_type": 0 }], "variables": [] } diff --git a/tests/namespaces/method_inline_declaration.cc b/tests/namespaces/method_inline_declaration.cc index 1f84442d..e845fa61 100644 --- a/tests/namespaces/method_inline_declaration.cc +++ b/tests/namespaces/method_inline_declaration.cc @@ -9,30 +9,19 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@N@hello@S@Foo", "short_name": "Foo", "qualified_name": "hello::Foo", - "declaration": null, "definition": "tests/namespaces/method_inline_declaration.cc:2:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [0], - "vars": [], - "uses": [] + "funcs": [0] }], "functions": [{ "id": 0, + "usr": "c:@N@hello@S@Foo@F@foo#", "short_name": "foo", "qualified_name": "hello::Foo::foo", - "declaration": null, "definition": "tests/namespaces/method_inline_declaration.cc:3:8", - "declaring_type": 0, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "declaring_type": 0 }], "variables": [] } diff --git a/tests/usage/func_usage_addr_func.cc b/tests/usage/func_usage_addr_func.cc index a174f5f6..b9b95d81 100644 --- a/tests/usage/func_usage_addr_func.cc +++ b/tests/usage/func_usage_addr_func.cc @@ -8,72 +8,50 @@ void user() { } /* +// NOTE: used only has one caller!! + OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [{ "id": 0, + "usr": "c:@F@consume#*v#", "short_name": "consume", "qualified_name": "consume", - "declaration": null, "definition": "tests/usage/func_usage_addr_func.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], "callers": ["2@tests/usage/func_usage_addr_func.cc:7:3"], - "callees": [], "uses": ["tests/usage/func_usage_addr_func.cc:7:3"] }, { "id": 1, + "usr": "c:@F@used#", "short_name": "used", "qualified_name": "used", - "declaration": null, "definition": "tests/usage/func_usage_addr_func.cc:3:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], "callers": ["2@tests/usage/func_usage_addr_func.cc:6:13", "2@tests/usage/func_usage_addr_func.cc:7:12"], - "callees": [], "uses": ["tests/usage/func_usage_addr_func.cc:6:13", "tests/usage/func_usage_addr_func.cc:7:12"] }, { "id": 2, + "usr": "c:@F@user#", "short_name": "user", "qualified_name": "user", - "declaration": null, "definition": "tests/usage/func_usage_addr_func.cc:5:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": ["1@tests/usage/func_usage_addr_func.cc:6:13", "0@tests/usage/func_usage_addr_func.cc:7:3", "1@tests/usage/func_usage_addr_func.cc:7:12"], - "uses": [] + "callees": ["1@tests/usage/func_usage_addr_func.cc:6:13", "0@tests/usage/func_usage_addr_func.cc:7:3", "1@tests/usage/func_usage_addr_func.cc:7:12"] }], "variables": [{ "id": 0, - "short_name": "", - "qualified_name": "", "declaration": "tests/usage/func_usage_addr_func.cc:1:19", "initializations": ["tests/usage/func_usage_addr_func.cc:1:19"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }, { "id": 1, + "usr": "c:func_usage_addr_func.cc@61@F@user#@x", "short_name": "x", "qualified_name": "x", "declaration": "tests/usage/func_usage_addr_func.cc:6:8", "initializations": ["tests/usage/func_usage_addr_func.cc:6:8"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/usage/func_usage_addr_method.cc b/tests/usage/func_usage_addr_method.cc index 4f70c7a9..7a7d5997 100644 --- a/tests/usage/func_usage_addr_method.cc +++ b/tests/usage/func_usage_addr_method.cc @@ -1,8 +1,50 @@ +struct Foo { + void Used(); +}; + +void user() { + auto x = &Foo::Used; +} + + /* OUTPUT: { - "types": [], - "functions": [], - "variables": [] + "types": [{ + "id": 0, + "usr": "c:@S@Foo", + "short_name": "Foo", + "qualified_name": "Foo", + "definition": "tests/usage/func_usage_addr_method.cc:1:8", + "funcs": [0] + }, { + "id": 1 + }], + "functions": [{ + "id": 0, + "usr": "c:@S@Foo@F@Used#", + "short_name": "Used", + "qualified_name": "Foo::Used", + "declaration": "tests/usage/func_usage_addr_method.cc:2:8", + "declaring_type": 0, + "callers": ["1@tests/usage/func_usage_addr_method.cc:6:18"], + "uses": ["tests/usage/func_usage_addr_method.cc:6:18"] + }, { + "id": 1, + "usr": "c:@F@user#", + "short_name": "user", + "qualified_name": "user", + "definition": "tests/usage/func_usage_addr_method.cc:5:6", + "callees": ["0@tests/usage/func_usage_addr_method.cc:6:18"] + }], + "variables": [{ + "id": 0, + "usr": "c:func_usage_addr_method.cc@53@F@user#@x", + "short_name": "x", + "qualified_name": "x", + "declaration": "tests/usage/func_usage_addr_method.cc:6:8", + "initializations": ["tests/usage/func_usage_addr_method.cc:6:8"], + "variable_type": 1 + }] } */ \ No newline at end of file diff --git a/tests/usage/func_usage_call_func.cc b/tests/usage/func_usage_call_func.cc index 4f70c7a9..94c88355 100644 --- a/tests/usage/func_usage_call_func.cc +++ b/tests/usage/func_usage_call_func.cc @@ -1,8 +1,28 @@ +void called() {} +void caller() { + called(); +} + /* OUTPUT: { "types": [], - "functions": [], + "functions": [{ + "id": 0, + "usr": "c:@F@called#", + "short_name": "called", + "qualified_name": "called", + "definition": "tests/usage/func_usage_call_func.cc:1:6", + "callers": ["1@tests/usage/func_usage_call_func.cc:3:3"], + "uses": ["tests/usage/func_usage_call_func.cc:3:3"] + }, { + "id": 1, + "usr": "c:@F@caller#", + "short_name": "caller", + "qualified_name": "caller", + "definition": "tests/usage/func_usage_call_func.cc:2:6", + "callees": ["0@tests/usage/func_usage_call_func.cc:3:3"] + }], "variables": [] } */ \ No newline at end of file diff --git a/tests/usage/func_usage_call_method.cc b/tests/usage/func_usage_call_method.cc index 4f70c7a9..9110d9a6 100644 --- a/tests/usage/func_usage_call_method.cc +++ b/tests/usage/func_usage_call_method.cc @@ -1,8 +1,50 @@ +struct Foo { + void Used(); +}; + +void user() { + Foo* f = nullptr; + f->Used(); +} + /* OUTPUT: { - "types": [], - "functions": [], - "variables": [] + "types": [{ + "id": 0, + "usr": "c:@S@Foo", + "short_name": "Foo", + "qualified_name": "Foo", + "definition": "tests/usage/func_usage_call_method.cc:1:8", + "funcs": [0] + }, { + "id": 1 + }], + "functions": [{ + "id": 0, + "usr": "c:@S@Foo@F@Used#", + "short_name": "Used", + "qualified_name": "Foo::Used", + "declaration": "tests/usage/func_usage_call_method.cc:2:8", + "declaring_type": 0, + "callers": ["1@tests/usage/func_usage_call_method.cc:7:6"], + "uses": ["tests/usage/func_usage_call_method.cc:7:6"] + }, { + "id": 1, + "usr": "c:@F@user#", + "short_name": "user", + "qualified_name": "user", + "definition": "tests/usage/func_usage_call_method.cc:5:6", + "callees": ["0@tests/usage/func_usage_call_method.cc:7:6"] + }], + "variables": [{ + "id": 0, + "usr": "c:func_usage_call_method.cc@53@F@user#@f", + "short_name": "f", + "qualified_name": "f", + "declaration": "tests/usage/func_usage_call_method.cc:6:8", + "initializations": ["tests/usage/func_usage_call_method.cc:6:8"], + "variable_type": 1 + }] } */ \ No newline at end of file diff --git a/tests/usage/func_usage_class_inline_var_def.cc b/tests/usage/func_usage_class_inline_var_def.cc index 4f70c7a9..02015589 100644 --- a/tests/usage/func_usage_class_inline_var_def.cc +++ b/tests/usage/func_usage_class_inline_var_def.cc @@ -1,8 +1,43 @@ +static int helper() { + return 5; +} + +class Foo { + int x = helper(); +}; + +// TODO(libclang): libclang doesn't expose the |helper| reference in the ast, +// so we can't add the |helper| usage. + /* OUTPUT: { - "types": [], - "functions": [], - "variables": [] + "types": [{ + "id": 0, + "usr": "c:@S@Foo", + "short_name": "Foo", + "qualified_name": "Foo", + "definition": "tests/usage/func_usage_class_inline_var_def.cc:5:7", + "vars": [0] + }, { + "id": 1 + }], + "functions": [{ + "id": 0, + "usr": "c:func_usage_class_inline_var_def.cc@F@helper#", + "short_name": "helper", + "qualified_name": "helper", + "definition": "tests/usage/func_usage_class_inline_var_def.cc:1:12" + }], + "variables": [{ + "id": 0, + "usr": "c:@S@Foo@FI@x", + "short_name": "x", + "qualified_name": "Foo::x", + "declaration": "tests/usage/func_usage_class_inline_var_def.cc:6:7", + "initializations": ["tests/usage/func_usage_class_inline_var_def.cc:6:7"], + "variable_type": 1, + "declaring_type": 0 + }] } */ \ No newline at end of file diff --git a/tests/usage/func_usage_forward_decl_func.cc b/tests/usage/func_usage_forward_decl_func.cc new file mode 100644 index 00000000..0535542a --- /dev/null +++ b/tests/usage/func_usage_forward_decl_func.cc @@ -0,0 +1,28 @@ +void foo(); + +void usage() { + foo(); +} +/* +OUTPUT: +{ + "types": [], + "functions": [{ + "id": 0, + "usr": "c:@F@foo#", + "short_name": "foo", + "qualified_name": "foo", + "declaration": "tests/usage/func_usage_forward_decl_func.cc:1:6", + "callers": ["1@tests/usage/func_usage_forward_decl_func.cc:4:3"], + "uses": ["tests/usage/func_usage_forward_decl_func.cc:4:3"] + }, { + "id": 1, + "usr": "c:@F@usage#", + "short_name": "usage", + "qualified_name": "usage", + "definition": "tests/usage/func_usage_forward_decl_func.cc:3:6", + "callees": ["0@tests/usage/func_usage_forward_decl_func.cc:4:3"] + }], + "variables": [] +} +*/ \ No newline at end of file diff --git a/tests/usage/func_usage_forward_decl_method.cc b/tests/usage/func_usage_forward_decl_method.cc new file mode 100644 index 00000000..9fa54efb --- /dev/null +++ b/tests/usage/func_usage_forward_decl_method.cc @@ -0,0 +1,49 @@ +struct Foo { + void foo(); +}; + +void usage() { + Foo* f = nullptr; + f->foo(); +} +/* +OUTPUT: +{ + "types": [{ + "id": 0, + "usr": "c:@S@Foo", + "short_name": "Foo", + "qualified_name": "Foo", + "definition": "tests/usage/func_usage_forward_decl_method.cc:1:8", + "funcs": [0] + }, { + "id": 1 + }], + "functions": [{ + "id": 0, + "usr": "c:@S@Foo@F@foo#", + "short_name": "foo", + "qualified_name": "Foo::foo", + "declaration": "tests/usage/func_usage_forward_decl_method.cc:2:8", + "declaring_type": 0, + "callers": ["1@tests/usage/func_usage_forward_decl_method.cc:7:6"], + "uses": ["tests/usage/func_usage_forward_decl_method.cc:7:6"] + }, { + "id": 1, + "usr": "c:@F@usage#", + "short_name": "usage", + "qualified_name": "usage", + "definition": "tests/usage/func_usage_forward_decl_method.cc:5:6", + "callees": ["0@tests/usage/func_usage_forward_decl_method.cc:7:6"] + }], + "variables": [{ + "id": 0, + "usr": "c:func_usage_forward_decl_method.cc@53@F@usage#@f", + "short_name": "f", + "qualified_name": "f", + "declaration": "tests/usage/func_usage_forward_decl_method.cc:6:8", + "initializations": ["tests/usage/func_usage_forward_decl_method.cc:6:8"], + "variable_type": 1 + }] +} +*/ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_extern.cc b/tests/usage/type_usage_declare_extern.cc new file mode 100644 index 00000000..1a400d87 --- /dev/null +++ b/tests/usage/type_usage_declare_extern.cc @@ -0,0 +1,23 @@ +struct T {}; + +extern T t; +/* +OUTPUT: +{ + "types": [{ + "id": 0, + "usr": "c:@S@T", + "short_name": "T", + "qualified_name": "T", + "definition": "tests/usage/type_usage_declare_extern.cc:1:8" + }], + "functions": [], + "variables": [{ + "id": 0, + "usr": "c:@t", + "short_name": "t", + "qualified_name": "t", + "declaration": "tests/usage/type_usage_declare_extern.cc:3:10" + }] +} +*/ \ No newline at end of file diff --git a/tests/usage/func_usage_extern_func.cc b/tests/usage/type_usage_declare_field.cc similarity index 100% rename from tests/usage/func_usage_extern_func.cc rename to tests/usage/type_usage_declare_field.cc diff --git a/tests/usage/func_usage_extern_method.cc b/tests/usage/type_usage_declare_local.cc similarity index 100% rename from tests/usage/func_usage_extern_method.cc rename to tests/usage/type_usage_declare_local.cc diff --git a/tests/usage/type_usage_declare_param.cc b/tests/usage/type_usage_declare_param.cc new file mode 100644 index 00000000..4f70c7a9 --- /dev/null +++ b/tests/usage/type_usage_declare_param.cc @@ -0,0 +1,8 @@ +/* +OUTPUT: +{ + "types": [], + "functions": [], + "variables": [] +} +*/ \ No newline at end of file diff --git a/tests/usage/type_usage_declare_static.cc b/tests/usage/type_usage_declare_static.cc new file mode 100644 index 00000000..4f70c7a9 --- /dev/null +++ b/tests/usage/type_usage_declare_static.cc @@ -0,0 +1,8 @@ +/* +OUTPUT: +{ + "types": [], + "functions": [], + "variables": [] +} +*/ \ No newline at end of file diff --git a/tests/vars/class_member.cc b/tests/vars/class_member.cc index 4deaf0dc..789951db 100644 --- a/tests/vars/class_member.cc +++ b/tests/vars/class_member.cc @@ -6,32 +6,24 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", - "declaration": null, "definition": "tests/vars/class_member.cc:1:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [], - "vars": [0], - "uses": [] + "vars": [0] }, { - "id": 1, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 1 }], "functions": [], "variables": [{ "id": 0, + "usr": "c:@S@Foo@FI@member", "short_name": "member", "qualified_name": "Foo::member", "declaration": "tests/vars/class_member.cc:2:7", "initializations": ["tests/vars/class_member.cc:2:7"], "variable_type": 1, - "declaring_type": 0, - "uses": [] + "declaring_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/class_static_member.cc b/tests/vars/class_static_member.cc index 0580dc17..951c1a0e 100644 --- a/tests/vars/class_static_member.cc +++ b/tests/vars/class_static_member.cc @@ -7,32 +7,24 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", - "declaration": null, "definition": "tests/vars/class_static_member.cc:1:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [], - "vars": [0], - "uses": [] + "vars": [0] }, { - "id": 1, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 1 }], "functions": [], "variables": [{ "id": 0, + "usr": "c:@S@Foo@member", "short_name": "member", "qualified_name": "Foo::member", "declaration": "tests/vars/class_static_member.cc:2:14", "initializations": ["tests/vars/class_static_member.cc:4:10"], "variable_type": 1, - "declaring_type": 0, - "uses": [] + "declaring_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/class_static_member_decl_only.cc b/tests/vars/class_static_member_decl_only.cc index e470fa31..b3ef0431 100644 --- a/tests/vars/class_static_member_decl_only.cc +++ b/tests/vars/class_static_member_decl_only.cc @@ -6,27 +6,20 @@ OUTPUT: { "types": [{ "id": 0, + "usr": "c:@S@Foo", "short_name": "Foo", "qualified_name": "Foo", - "declaration": null, "definition": "tests/vars/class_static_member_decl_only.cc:1:7", - "parents": [], - "derived": [], - "types": [], - "funcs": [], - "vars": [0], - "uses": [] + "vars": [0] }], "functions": [], "variables": [{ "id": 0, + "usr": "c:@S@Foo@member", "short_name": "member", "qualified_name": "Foo::member", "declaration": "tests/vars/class_static_member_decl_only.cc:2:14", - "initializations": [], - "variable_type": null, - "declaring_type": 0, - "uses": [] + "declaring_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/function_local.cc b/tests/vars/function_local.cc index 8ef4601b..92789ae0 100644 --- a/tests/vars/function_local.cc +++ b/tests/vars/function_local.cc @@ -5,34 +5,23 @@ void foo() { OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [{ "id": 0, + "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", - "declaration": null, - "definition": "tests/vars/function_local.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/vars/function_local.cc:1:6" }], "variables": [{ "id": 0, + "usr": "c:function_local.cc@16@F@foo#@a", "short_name": "a", "qualified_name": "a", "declaration": "tests/vars/function_local.cc:2:7", "initializations": ["tests/vars/function_local.cc:2:7"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/function_param.cc b/tests/vars/function_param.cc index acde6098..620f0d7d 100644 --- a/tests/vars/function_param.cc +++ b/tests/vars/function_param.cc @@ -3,43 +3,31 @@ void foo(int p0, int p1) {} OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [{ "id": 0, + "usr": "c:@F@foo#I#I#", "short_name": "foo", "qualified_name": "foo", - "declaration": null, - "definition": "tests/vars/function_param.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/vars/function_param.cc:1:6" }], "variables": [{ "id": 0, + "usr": "c:function_param.cc@9@F@foo#I#I#@p0", "short_name": "p0", "qualified_name": "p0", "declaration": "tests/vars/function_param.cc:1:14", "initializations": ["tests/vars/function_param.cc:1:14"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }, { "id": 1, + "usr": "c:function_param.cc@17@F@foo#I#I#@p1", "short_name": "p1", "qualified_name": "p1", "declaration": "tests/vars/function_param.cc:1:22", "initializations": ["tests/vars/function_param.cc:1:22"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/function_param_unnamed.cc b/tests/vars/function_param_unnamed.cc index 6aa7d673..7536b0da 100644 --- a/tests/vars/function_param_unnamed.cc +++ b/tests/vars/function_param_unnamed.cc @@ -2,47 +2,26 @@ void foo(int, int) {} /* // TODO: We should probably not emit variables for unnamed variables. But we // still need to emit reference information. +// TODO: This test is broken. Notice how we only emit one variable because +// unnamed vars have no usr! OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [{ "id": 0, + "usr": "c:@F@foo#I#I#", "short_name": "foo", "qualified_name": "foo", - "declaration": null, - "definition": "tests/vars/function_param.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/vars/function_param_unnamed.cc:1:6" }], "variables": [{ "id": 0, - "short_name": "p0", - "qualified_name": "p0", - "declaration": "tests/vars/function_param.cc:1:14", - "initializations": ["tests/vars/function_param.cc:1:14"], - "variable_type": 0, - "declaring_type": null, - "uses": [] - }, { - "id": 1, - "short_name": "p1", - "qualified_name": "p1", - "declaration": "tests/vars/function_param.cc:1:22", - "initializations": ["tests/vars/function_param.cc:1:22"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "declaration": "tests/vars/function_param_unnamed.cc:1:13", + "initializations": ["tests/vars/function_param_unnamed.cc:1:13", "tests/vars/function_param_unnamed.cc:1:18"], + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/function_shadow_local.cc b/tests/vars/function_shadow_local.cc index 39d8d666..d3e8543b 100644 --- a/tests/vars/function_shadow_local.cc +++ b/tests/vars/function_shadow_local.cc @@ -8,43 +8,31 @@ void foo() { OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [{ "id": 0, + "usr": "c:@F@foo#", "short_name": "foo", "qualified_name": "foo", - "declaration": null, - "definition": "tests/vars/function_shadow_local.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/vars/function_shadow_local.cc:1:6" }], "variables": [{ "id": 0, + "usr": "c:function_shadow_local.cc@16@F@foo#@a", "short_name": "a", "qualified_name": "a", "declaration": "tests/vars/function_shadow_local.cc:2:7", "initializations": ["tests/vars/function_shadow_local.cc:2:7"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }, { "id": 1, + "usr": "c:function_shadow_local.cc@33@F@foo#@a", "short_name": "a", "qualified_name": "a", "declaration": "tests/vars/function_shadow_local.cc:4:9", "initializations": ["tests/vars/function_shadow_local.cc:4:9"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/function_shadow_param.cc b/tests/vars/function_shadow_param.cc index 4ff7a5dd..b51422ef 100644 --- a/tests/vars/function_shadow_param.cc +++ b/tests/vars/function_shadow_param.cc @@ -5,43 +5,31 @@ void foo(int p) { OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [{ "id": 0, + "usr": "c:@F@foo#I#", "short_name": "foo", "qualified_name": "foo", - "declaration": null, - "definition": "tests/vars/function_shadow_param.cc:1:6", - "declaring_type": null, - "base": null, - "derived": [], - "locals": [], - "callers": [], - "callees": [], - "uses": [] + "definition": "tests/vars/function_shadow_param.cc:1:6" }], "variables": [{ "id": 0, + "usr": "c:function_shadow_param.cc@9@F@foo#I#@p", "short_name": "p", "qualified_name": "p", "declaration": "tests/vars/function_shadow_param.cc:1:14", "initializations": ["tests/vars/function_shadow_param.cc:1:14"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }, { "id": 1, + "usr": "c:function_shadow_param.cc@21@F@foo#I#@p", "short_name": "p", "qualified_name": "p", "declaration": "tests/vars/function_shadow_param.cc:2:7", "initializations": ["tests/vars/function_shadow_param.cc:2:7"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/global_variable.cc b/tests/vars/global_variable.cc index 43e7f826..540479e0 100644 --- a/tests/vars/global_variable.cc +++ b/tests/vars/global_variable.cc @@ -3,21 +3,17 @@ static int global = 0; OUTPUT: { "types": [{ - "id": 0, - "short_name": "", - "qualified_name": "", - "declaration": null + "id": 0 }], "functions": [], "variables": [{ "id": 0, + "usr": "c:global_variable.cc@global", "short_name": "global", "qualified_name": "global", "declaration": "tests/vars/global_variable.cc:1:12", "initializations": ["tests/vars/global_variable.cc:1:12"], - "variable_type": 0, - "declaring_type": null, - "uses": [] + "variable_type": 0 }] } */ \ No newline at end of file diff --git a/tests/vars/global_variable_decl_only.cc b/tests/vars/global_variable_decl_only.cc index 6fb38349..335126fa 100644 --- a/tests/vars/global_variable_decl_only.cc +++ b/tests/vars/global_variable_decl_only.cc @@ -6,13 +6,10 @@ OUTPUT: "functions": [], "variables": [{ "id": 0, + "usr": "c:@global", "short_name": "global", "qualified_name": "global", - "declaration": "tests/vars/global_variable_decl_only.cc:1:12", - "initializations": [], - "variable_type": null, - "declaring_type": null, - "uses": [] + "declaration": "tests/vars/global_variable_decl_only.cc:1:12" }] } */ \ No newline at end of file