Change how function declarations are serialized so parameter info can be added.

This commit is contained in:
Jacob Dufault 2017-05-27 14:09:20 -07:00
parent b7f7987cb8
commit 3469850c98
37 changed files with 185 additions and 74 deletions

View File

@ -1008,7 +1008,26 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
func->def.definition_extent = ResolveExtent(decl->cursor);
}
else {
func->declarations.push_back(decl_spelling);
IndexFunc::Declaration declaration;
declaration.spelling = decl_spelling;
/*
for (clang::Cursor arg : decl_cursor.get_arguments()) {
switch (arg.get_kind()) {
case CXCursor_ParmDecl: {
IndexFunc::DeclarationVariable decl_var;
decl_var.content = arg.get_display_name(); // FIXME/TODO: scan actual tokens.
decl_var.spelling = ResolveSpelling(arg.cx_cursor);
declaration.vars.push_back(decl_var);
break;
}
default:
break;
}
}
*/
func->declarations.push_back(declaration);
}
// Emit definition data for the function. We do this even if it isn't a
@ -1074,32 +1093,6 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
clang_disposeOverriddenCursors(overridden);
}
}
// else {
// Add declaration.
// func_def->declarations.push_back(ResolveSpelling(decl->cursor));
/* TODO/FIXME: enable this block
IndexFunc::Declaration declaration;
declaration.extent = ResolveExtent(decl->cursor);
clang::Cursor cursor = decl->cursor;
for (clang::Cursor arg : cursor.get_arguments()) {
switch (arg.get_kind()) {
case CXCursor_ParmDecl: {
IndexFunc::DeclarationVariable decl_var;
// FIXME/TODO: scan actual tokens.
decl_var.extent_string = arg.get_display_name();
decl_var.spelling = ResolveSpelling(arg.cx_cursor);
declaration.vars.push_back(decl_var);
break;
}
default:
break;
}
}
func_def->declarations.push_back(declaration);
*/
// }
break;
}

View File

@ -316,8 +316,19 @@ struct IndexFunc {
IndexFuncId id;
struct DeclarationVariable {
// Spelled name of the variable.
Range spelling;
// Full text (including type) of the variable.
std::string content;
};
struct Declaration {
Range spelling;
std::vector<DeclarationVariable> vars;
};
// Places the function is forward-declared.
std::vector<Range> declarations;
std::vector<Declaration> declarations;
// Methods which directly override this one.
std::vector<IndexFuncId> derived;
@ -339,6 +350,8 @@ struct IndexFunc {
}
};
MAKE_HASHABLE(IndexFunc, t.def.usr);
MAKE_REFLECT_STRUCT(IndexFunc::DeclarationVariable, spelling, content);
MAKE_REFLECT_STRUCT(IndexFunc::Declaration, spelling, vars);
template <typename TypeId,
typename FuncId,
@ -447,7 +460,7 @@ MAKE_REFLECT_STRUCT(IndexInclude, line, resolved_path);
struct IndexFile {
IdCache id_cache;
static constexpr int kCurrentVersion = 3;
static constexpr int kCurrentVersion = 4;
int version = 0;
std::string path;

View File

@ -195,9 +195,10 @@ QueryFile::Def BuildFileDef(const IdMap& id_map, const IndexFile& indexed) {
add_all_symbols(id_map.ToSymbol(func.id), func.def.definition_spelling.value());
if (func.def.definition_extent.has_value())
add_outline(id_map.ToSymbol(func.id), func.def.definition_extent.value());
for (Range decl : func.declarations) {
add_all_symbols(id_map.ToSymbol(func.id), decl);
add_outline(id_map.ToSymbol(func.id), decl);
for (const IndexFunc::Declaration& decl : func.declarations) {
// TODO: add more outline info?
add_all_symbols(id_map.ToSymbol(func.id), decl.spelling);
add_outline(id_map.ToSymbol(func.id), decl.spelling);
}
for (const IndexFuncRef& caller : func.callers) {
if (caller.is_implicit) continue;
@ -320,7 +321,6 @@ IdMap::IdMap(QueryDatabase* query_db, const IdCache& local_ids)
QueryLocation IdMap::ToQuery(Range range) const {
return QueryLocation(primary_file, range);
}
QueryTypeId IdMap::ToQuery(IndexTypeId id) const {
assert(cached_type_ids_.find(id) != cached_type_ids_.end());
return QueryTypeId(cached_type_ids_.find(id)->second);
@ -337,6 +337,10 @@ QueryVarId IdMap::ToQuery(IndexVarId id) const {
QueryFuncRef IdMap::ToQuery(IndexFuncRef ref) const {
return QueryFuncRef(ToQuery(ref.id), ToQuery(ref.loc), ref.is_implicit);
}
QueryLocation IdMap::ToQuery(IndexFunc::Declaration decl) const {
// TODO: expose more than just QueryLocation.
return QueryLocation(primary_file, decl.spelling);
}
optional<QueryLocation> IdMap::ToQuery(optional<Range> range) const {
if (!range)
@ -363,6 +367,11 @@ optional<QueryFuncRef> IdMap::ToQuery(optional<IndexFuncRef> ref) const {
return nullopt;
return ToQuery(ref.value());
}
optional<QueryLocation> IdMap::ToQuery(optional<IndexFunc::Declaration> decl) const {
if (!decl)
return nullopt;
return ToQuery(decl.value());
}
template<typename In, typename Out>
std::vector<Out> ToQueryTransform(const IdMap& id_map, const std::vector<In>& input) {
@ -387,6 +396,9 @@ std::vector<QueryVarId> IdMap::ToQuery(std::vector<IndexVarId> ids) const {
std::vector<QueryFuncRef> IdMap::ToQuery(std::vector<IndexFuncRef> refs) const {
return ToQueryTransform<IndexFuncRef, QueryFuncRef>(*this, refs);
}
std::vector<QueryLocation> IdMap::ToQuery(std::vector<IndexFunc::Declaration> decls) const {
return ToQueryTransform<IndexFunc::Declaration, QueryLocation>(*this, decls);
}
SymbolIdx IdMap::ToSymbol(IndexTypeId id) const {
return SymbolIdx(SymbolKind::Type, ToQuery(id).id);

View File

@ -315,16 +315,19 @@ struct IdMap {
QueryFuncId ToQuery(IndexFuncId id) const;
QueryVarId ToQuery(IndexVarId id) const;
QueryFuncRef ToQuery(IndexFuncRef ref) const;
QueryLocation ToQuery(IndexFunc::Declaration decl) const;
optional<QueryLocation> ToQuery(optional<Range> range) const;
optional<QueryTypeId> ToQuery(optional<IndexTypeId> id) const;
optional<QueryFuncId> ToQuery(optional<IndexFuncId> id) const;
optional<QueryVarId> ToQuery(optional<IndexVarId> id) const;
optional<QueryFuncRef> ToQuery(optional<IndexFuncRef> ref) const;
optional<QueryLocation> ToQuery(optional<IndexFunc::Declaration> decl) const;
std::vector<QueryLocation> ToQuery(std::vector<Range> ranges) const;
std::vector<QueryTypeId> ToQuery(std::vector<IndexTypeId> ids) const;
std::vector<QueryFuncId> ToQuery(std::vector<IndexFuncId> ids) const;
std::vector<QueryVarId> ToQuery(std::vector<IndexVarId> ids) const;
std::vector<QueryFuncRef> ToQuery(std::vector<IndexFuncRef> refs) const;
std::vector<QueryLocation> ToQuery(std::vector<IndexFunc::Declaration> decls) const;
SymbolIdx ToSymbol(IndexTypeId id) const;
SymbolIdx ToSymbol(IndexFuncId id) const;

View File

@ -12,7 +12,13 @@ OUTPUT:
"usr": "c:@F@foo#",
"short_name": "foo",
"detailed_name": "void foo()",
"declarations": ["1:6-1:9", "2:6-2:9", "4:6-4:9"],
"declarations": [{
"spelling": "1:6-1:9"
}, {
"spelling": "2:6-2:9"
}, {
"spelling": "4:6-4:9"
}],
"definition_spelling": "3:6-3:9",
"definition_extent": "3:1-3:14"
}]

View File

@ -24,21 +24,27 @@ OUTPUT:
"usr": "c:@S@Foo@F@declonly#",
"short_name": "declonly",
"detailed_name": "void Foo::declonly()",
"declarations": ["2:8-2:16"],
"declarations": [{
"spelling": "2:8-2:16"
}],
"declaring_type": 0
}, {
"id": 1,
"usr": "c:@S@Foo@F@purevirtual#",
"short_name": "purevirtual",
"detailed_name": "void Foo::purevirtual()",
"declarations": ["3:16-3:27"],
"declarations": [{
"spelling": "3:16-3:27"
}],
"declaring_type": 0
}, {
"id": 2,
"usr": "c:@S@Foo@F@def#",
"short_name": "def",
"detailed_name": "void Foo::def()",
"declarations": ["4:8-4:11"],
"declarations": [{
"spelling": "4:8-4:11"
}],
"definition_spelling": "7:11-7:14",
"definition_extent": "7:1-7:19",
"declaring_type": 0

View File

@ -8,7 +8,9 @@ OUTPUT:
"usr": "c:@F@foo#I#I#",
"short_name": "foo",
"detailed_name": "void foo(int, int)",
"declarations": ["1:6-1:9"]
"declarations": [{
"spelling": "1:6-1:9"
}]
}]
}
*/

View File

@ -10,7 +10,9 @@ OUTPUT:
"usr": "c:@F@foo#",
"short_name": "foo",
"detailed_name": "void foo()",
"declarations": ["1:6-1:9"],
"declarations": [{
"spelling": "1:6-1:9"
}],
"definition_spelling": "3:6-3:9",
"definition_extent": "3:1-3:14"
}]

View File

@ -34,7 +34,9 @@ OUTPUT:
"usr": "c:@S@Root@F@foo#",
"short_name": "foo",
"detailed_name": "void Root::foo()",
"declarations": ["2:16-2:19"],
"declarations": [{
"spelling": "2:16-2:19"
}],
"declaring_type": 0,
"derived": [1]
}, {

View File

@ -24,7 +24,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@foo#",
"short_name": "foo",
"detailed_name": "void Foo::foo()",
"declarations": ["2:8-2:11"],
"declarations": [{
"spelling": "2:8-2:11"
}],
"declaring_type": 0
}]
}

View File

@ -22,7 +22,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@foo#",
"short_name": "foo",
"detailed_name": "void Foo::foo()",
"declarations": ["2:8-2:11"],
"declarations": [{
"spelling": "2:8-2:11"
}],
"definition_spelling": "5:11-5:14",
"definition_extent": "5:1-5:19",
"declaring_type": 0

View File

@ -12,7 +12,9 @@ OUTPUT: simple_header.h
"usr": "c:@F@header#",
"short_name": "header",
"detailed_name": "void header()",
"declarations": ["3:6-3:12"]
"declarations": [{
"spelling": "3:6-3:12"
}]
}]
}
OUTPUT: simple_impl.cc

View File

@ -20,7 +20,9 @@ OUTPUT: static.h
"usr": "c:@S@Buffer@F@CreateSharedBuffer#S",
"short_name": "CreateSharedBuffer",
"detailed_name": "void Buffer::CreateSharedBuffer()",
"declarations": ["4:15-4:33"],
"declarations": [{
"spelling": "4:15-4:33"
}],
"declaring_type": 0
}]
}

View File

@ -10,7 +10,9 @@ OUTPUT:
"usr": "c:anonymous_function.cc@aN@F@foo#",
"short_name": "foo",
"detailed_name": "void ::foo()",
"declarations": ["2:6-2:9"]
"declarations": [{
"spelling": "2:6-2:9"
}]
}]
}
*/

View File

@ -10,7 +10,9 @@ OUTPUT:
"usr": "c:@N@hello@F@foo#I#I#",
"short_name": "foo",
"detailed_name": "void hello::foo(int, int)",
"declarations": ["2:6-2:9"]
"declarations": [{
"spelling": "2:6-2:9"
}]
}]
}
*/

View File

@ -22,7 +22,9 @@ OUTPUT:
"usr": "c:@N@hello@S@Foo@F@foo#",
"short_name": "foo",
"detailed_name": "void hello::Foo::foo()",
"declarations": ["3:8-3:11"],
"declarations": [{
"spelling": "3:8-3:11"
}],
"declaring_type": 0
}]
}

View File

@ -24,7 +24,9 @@ OUTPUT:
"usr": "c:@N@hello@S@Foo@F@foo#",
"short_name": "foo",
"detailed_name": "void hello::Foo::foo()",
"declarations": ["3:8-3:11"],
"declarations": [{
"spelling": "3:8-3:11"
}],
"definition_spelling": "6:11-6:14",
"definition_extent": "6:1-6:19",
"declaring_type": 0

View File

@ -47,7 +47,9 @@ OUTPUT:
"usr": "c:@F@LoadCompilationEntriesFromDirectory#&1$@N@std@S@basic_string>#C#$@N@std@S@char_traits>#C#$@N@std@S@allocator>#C#",
"short_name": "LoadCompilationEntriesFromDirectory",
"detailed_name": "std::vector<CompilationEntry> LoadCompilationEntriesFromDirectory(const std::string &)",
"declarations": ["12:31-12:66"]
"declarations": [{
"spelling": "12:31-12:66"
}]
}],
"vars": [{
"id": 0,

View File

@ -33,7 +33,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@Bar#&$@S@Template>#d#",
"short_name": "Bar",
"detailed_name": "void Foo::Bar(Template<double> &)",
"declarations": ["5:8-5:11"],
"declarations": [{
"spelling": "5:8-5:11"
}],
"definition_spelling": "8:11-8:14",
"definition_extent": "8:1-8:36",
"declaring_type": 1

View File

@ -30,7 +30,11 @@ OUTPUT:
"usr": "c:@ST>1#T@Template@F@Foo#",
"short_name": "Foo",
"detailed_name": "void Template::Foo()",
"declarations": ["3:8-3:11", "9:22-9:25"],
"declarations": [{
"spelling": "3:8-3:11"
}, {
"spelling": "9:22-9:25"
}],
"definition_spelling": "7:19-7:22",
"definition_extent": "6:1-7:24",
"declaring_type": 0

View File

@ -34,7 +34,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@Foo#",
"short_name": "Foo",
"detailed_name": "void Foo::Foo()",
"declarations": ["4:3-4:6"],
"declarations": [{
"spelling": "4:3-4:6"
}],
"definition_spelling": "7:6-7:9",
"definition_extent": "7:1-9:2",
"declaring_type": 0,

View File

@ -14,7 +14,9 @@ OUTPUT:
"usr": "c:@F@called#b#b#",
"short_name": "called",
"detailed_name": "bool called(bool, bool)",
"declarations": ["3:6-3:12"],
"declarations": [{
"spelling": "3:6-3:12"
}],
"callers": ["1@6:14-6:20"]
}, {
"id": 1,

View File

@ -19,7 +19,9 @@ OUTPUT:
"usr": "c:@F@called#",
"short_name": "called",
"detailed_name": "void called()",
"declarations": ["1:6-1:12"],
"declarations": [{
"spelling": "1:6-1:12"
}],
"callers": ["1@5:3-5:9"]
}, {
"id": 1,

View File

@ -26,7 +26,9 @@ OUTPUT:
"usr": "c:@S@Wrapper@F@Wrapper#I#",
"short_name": "Wrapper",
"detailed_name": "void Wrapper::Wrapper(int)",
"declarations": ["2:3-2:10"],
"declarations": [{
"spelling": "2:3-2:10"
}],
"declaring_type": 0,
"callers": ["~2@8:10-8:16"]
}, {

View File

@ -25,7 +25,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@Used#",
"short_name": "Used",
"detailed_name": "void Foo::Used()",
"declarations": ["2:8-2:12"],
"declarations": [{
"spelling": "2:8-2:12"
}],
"declaring_type": 0,
"callers": ["1@6:18-6:22"]
}, {

View File

@ -26,7 +26,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@Used#",
"short_name": "Used",
"detailed_name": "void Foo::Used()",
"declarations": ["2:8-2:12"],
"declarations": [{
"spelling": "2:8-2:12"
}],
"declaring_type": 0,
"callers": ["1@7:6-7:10"]
}, {

View File

@ -11,7 +11,9 @@ OUTPUT:
"usr": "c:@F@foo#",
"short_name": "foo",
"detailed_name": "void foo()",
"declarations": ["1:6-1:9"],
"declarations": [{
"spelling": "1:6-1:9"
}],
"callers": ["1@4:3-4:6"]
}, {
"id": 1,

View File

@ -25,7 +25,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@foo#",
"short_name": "foo",
"detailed_name": "void Foo::foo()",
"declarations": ["2:8-2:11"],
"declarations": [{
"spelling": "2:8-2:11"
}],
"declaring_type": 0,
"callers": ["1@7:6-7:9"]
}, {

View File

@ -14,7 +14,9 @@ OUTPUT:
"usr": "c:@FT@>1#Taccept#t0.0#v#",
"short_name": "accept",
"detailed_name": "void accept(T)",
"declarations": ["2:6-2:12"],
"declarations": [{
"spelling": "2:6-2:12"
}],
"callers": ["1@5:3-5:9", "1@6:3-6:9"]
}, {
"id": 1,

View File

@ -131,7 +131,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@foo#",
"short_name": "foo",
"detailed_name": "unique_ptr<S1, S2> *Foo::foo()",
"declarations": ["65:23-65:26"],
"declarations": [{
"spelling": "65:23-65:26"
}],
"definition_spelling": "79:26-79:29",
"definition_extent": "79:1-79:51",
"declaring_type": 3

View File

@ -22,7 +22,9 @@ OUTPUT:
"usr": "c:@F@foo#*$@S@Foo#S0_#",
"short_name": "foo",
"detailed_name": "void foo(Foo *, Foo *)",
"declarations": ["3:6-3:9"],
"declarations": [{
"spelling": "3:6-3:9"
}],
"definition_spelling": "4:6-4:9",
"definition_extent": "4:1-4:26"
}],

View File

@ -39,7 +39,11 @@ OUTPUT:
"usr": "c:@F@foo#",
"short_name": "foo",
"detailed_name": "Type *foo()",
"declarations": ["3:7-3:10", "4:7-4:10"],
"declarations": [{
"spelling": "3:7-3:10"
}, {
"spelling": "4:7-4:10"
}],
"definition_spelling": "5:7-5:10",
"definition_extent": "5:1-5:15"
}, {
@ -47,7 +51,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@Get#I#",
"short_name": "Get",
"detailed_name": "Type *Foo::Get(int)",
"declarations": ["8:9-8:12"],
"declarations": [{
"spelling": "8:9-8:12"
}],
"definition_spelling": "12:12-12:15",
"definition_extent": "12:1-12:23",
"declaring_type": 1
@ -56,7 +62,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@Empty#",
"short_name": "Empty",
"detailed_name": "void Foo::Empty()",
"declarations": ["9:8-9:13"],
"declarations": [{
"spelling": "9:8-9:13"
}],
"definition_spelling": "13:11-13:16",
"definition_extent": "13:1-13:21",
"declaring_type": 1
@ -65,13 +73,17 @@ OUTPUT:
"usr": "c:@F@external#",
"short_name": "external",
"detailed_name": "const Type &external()",
"declarations": ["15:20-15:28"]
"declarations": [{
"spelling": "15:20-15:28"
}]
}, {
"id": 4,
"usr": "c:type_usage_on_return_type.cc@F@bar#",
"short_name": "bar",
"detailed_name": "Type *bar()",
"declarations": ["17:14-17:17"],
"declarations": [{
"spelling": "17:14-17:17"
}],
"definition_spelling": "18:14-18:17",
"definition_extent": "18:1-18:22"
}]

View File

@ -28,7 +28,9 @@ OUTPUT:
"usr": "c:@S@Foo@F@make#",
"short_name": "make",
"detailed_name": "Foo *Foo::make()",
"declarations": ["2:8-2:12"],
"declarations": [{
"spelling": "2:8-2:12"
}],
"definition_spelling": "5:11-5:15",
"definition_extent": "5:1-8:2",
"declaring_type": 0

View File

@ -32,14 +32,18 @@ OUTPUT:
"usr": "c:@F@called#I#",
"short_name": "called",
"detailed_name": "void called(int)",
"declarations": ["1:6-1:12"],
"declarations": [{
"spelling": "1:6-1:12"
}],
"callers": ["2@14:3-14:9"]
}, {
"id": 1,
"usr": "c:@F@gen#",
"short_name": "gen",
"detailed_name": "int gen()",
"declarations": ["3:5-3:8"],
"declarations": [{
"spelling": "3:5-3:8"
}],
"callers": ["2@14:14-14:17"]
}, {
"id": 2,

View File

@ -14,7 +14,9 @@ OUTPUT:
"usr": "c:@F@called#I#",
"short_name": "called",
"detailed_name": "void called(int)",
"declarations": ["1:6-1:12"],
"declarations": [{
"spelling": "1:6-1:12"
}],
"callers": ["2@6:3-6:9"]
}, {
"id": 1,

View File

@ -36,14 +36,18 @@ OUTPUT:
"usr": "c:@F@accept#I#",
"short_name": "accept",
"detailed_name": "void accept(int)",
"declarations": ["7:6-7:12"],
"declarations": [{
"spelling": "7:6-7:12"
}],
"callers": ["2@14:3-14:9", "2@15:3-15:9", "2@17:3-17:9"]
}, {
"id": 1,
"usr": "c:@F@accept#*I#",
"short_name": "accept",
"detailed_name": "void accept(int *)",
"declarations": ["8:6-8:12"],
"declarations": [{
"spelling": "8:6-8:12"
}],
"callers": ["2@16:3-16:9"]
}, {
"id": 2,

View File

@ -25,7 +25,9 @@ OUTPUT:
"usr": "c:@F@accept#I#",
"short_name": "accept",
"detailed_name": "void accept(int)",
"declarations": ["5:6-5:12"],
"declarations": [{
"spelling": "5:6-5:12"
}],
"callers": ["1@8:3-8:9"]
}, {
"id": 1,