mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
wip
This commit is contained in:
parent
46cec6f083
commit
a8cdadc201
@ -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)
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
Cursor get_semantic_parent() const;
|
||||
std::vector<Cursor> get_arguments() const;
|
||||
bool is_valid_kind() const;
|
||||
|
||||
std::string evaluate() const;
|
||||
|
||||
std::string get_type_description() const;
|
||||
std::string get_comments() const;
|
||||
|
||||
|
389
main.cpp
389
main.cpp
@ -1,3 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <optional>
|
||||
#include <iostream>
|
||||
#include <cstdint>
|
||||
@ -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<typename TWriter>
|
||||
void WriteLocation(TWriter& writer, clang::SourceLocation location) {
|
||||
|
||||
using Writer = rapidjson::PrettyWriter<rapidjson::StringBuffer>;
|
||||
|
||||
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<typename TWriter>
|
||||
void WriteLocation(TWriter& writer, std::optional<clang::SourceLocation> location) {
|
||||
if (location)
|
||||
WriteLocation(writer, location.value());
|
||||
else
|
||||
writer.Null();
|
||||
void Write(Writer& writer, const char* key, std::optional<clang::SourceLocation> location) {
|
||||
if (location) {
|
||||
Write(writer, key, location.value());
|
||||
}
|
||||
//else {
|
||||
// if (key) writer.Key(key);
|
||||
// writer.Null();
|
||||
//}
|
||||
}
|
||||
|
||||
template<typename TWriter, typename TId>
|
||||
void WriteId(TWriter& writer, TId id) {
|
||||
void Write(Writer& writer, const char* key, const std::vector<clang::SourceLocation>& 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<typename T>
|
||||
void Write(Writer& writer, const char* key, LocalId<T> id) {
|
||||
if (key) writer.Key(key);
|
||||
writer.Uint64(id.local_id);
|
||||
}
|
||||
|
||||
template<typename TWriter, typename TId>
|
||||
void WriteId(TWriter& writer, std::optional<TId> id) {
|
||||
if (id)
|
||||
WriteId(writer, id.value());
|
||||
else
|
||||
writer.Null();
|
||||
template<typename T>
|
||||
void Write(Writer& writer, const char* key, std::optional<LocalId<T>> id) {
|
||||
if (id) {
|
||||
Write(writer, key, id.value());
|
||||
}
|
||||
//else {
|
||||
// if (key) writer.Key(key);
|
||||
// writer.Null();
|
||||
//}
|
||||
}
|
||||
|
||||
template<typename TWriter, typename TRef>
|
||||
void WriteRef(TWriter& writer, TRef ref) {
|
||||
template<typename T>
|
||||
void Write(Writer& writer, const char* key, const std::vector<LocalId<T>>& ids) {
|
||||
if (ids.size() == 0)
|
||||
return;
|
||||
|
||||
if (key) writer.Key(key);
|
||||
writer.StartArray();
|
||||
for (LocalId<T> id : ids)
|
||||
Write(writer, nullptr, id);
|
||||
writer.EndArray();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Write(Writer& writer, const char* key, Ref<T> 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<typename TWriter, typename TId>
|
||||
void WriteIdArray(TWriter& writer, const std::vector<TId>& ids) {
|
||||
template<typename T>
|
||||
void Write(Writer& writer, const char* key, const std::vector<Ref<T>>& refs) {
|
||||
if (refs.size() == 0)
|
||||
return;
|
||||
|
||||
if (key) writer.Key(key);
|
||||
writer.StartArray();
|
||||
for (TId id : ids)
|
||||
WriteId(writer, id);
|
||||
for (Ref<T> ref : refs)
|
||||
Write(writer, nullptr, ref);
|
||||
writer.EndArray();
|
||||
}
|
||||
|
||||
template<typename TWriter, typename TRef>
|
||||
void WriteRefArray(TWriter& writer, const std::vector<TRef>& 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<typename TWriter>
|
||||
void WriteLocationArray(TWriter& writer, const std::vector<clang::SourceLocation>& 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<rapidjson::StringBuffer> 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<TypeId> 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<std::string>& strs) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> split_string(const std::string& str, const std::string& delimiter) {
|
||||
// http://stackoverflow.com/a/13172514
|
||||
std::vector<std::string> 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<std::string> actual_output;
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
|
||||
writer.SetFormatOptions(
|
||||
rapidjson::PrettyFormatOptions::kFormatSingleLineArray);
|
||||
writer.SetIndent(' ', 2);
|
||||
|
||||
buffer.Clear();
|
||||
actual.Accept(writer);
|
||||
actual_output = split_string(buffer.GetString(), "\n");
|
||||
}
|
||||
|
||||
std::vector<std::string> expected_output;
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> 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,6 +959,9 @@ 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;
|
||||
}
|
||||
}
|
||||
@ -936,3 +969,5 @@ int main(int argc, char** argv) {
|
||||
std::cin.get();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// TODO: ctor/dtor, copy ctor
|
@ -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": []
|
||||
|
@ -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"
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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",
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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": []
|
||||
}
|
||||
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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": []
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
28
tests/usage/func_usage_forward_decl_func.cc
Normal file
28
tests/usage/func_usage_forward_decl_func.cc
Normal file
@ -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": []
|
||||
}
|
||||
*/
|
49
tests/usage/func_usage_forward_decl_method.cc
Normal file
49
tests/usage/func_usage_forward_decl_method.cc
Normal file
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
23
tests/usage/type_usage_declare_extern.cc
Normal file
23
tests/usage/type_usage_declare_extern.cc
Normal file
@ -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"
|
||||
}]
|
||||
}
|
||||
*/
|
8
tests/usage/type_usage_declare_param.cc
Normal file
8
tests/usage/type_usage_declare_param.cc
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [],
|
||||
"functions": [],
|
||||
"variables": []
|
||||
}
|
||||
*/
|
8
tests/usage/type_usage_declare_static.cc
Normal file
8
tests/usage/type_usage_declare_static.cc
Normal file
@ -0,0 +1,8 @@
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [],
|
||||
"functions": [],
|
||||
"variables": []
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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
|
||||
}]
|
||||
}
|
||||
*/
|
@ -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"
|
||||
}]
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user