mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-25 17:11:59 +00:00
support anonymous structs
This commit is contained in:
parent
2932b5d41b
commit
b33bd54922
22
main.cpp
22
main.cpp
@ -1052,16 +1052,24 @@ void indexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
case CXIdxEntity_Struct:
|
||||
case CXIdxEntity_CXXClass:
|
||||
{
|
||||
ns->RegisterQualifiedName(decl->entityInfo->USR, decl->semanticContainer, decl->entityInfo->name);
|
||||
|
||||
TypeId type_id = db->ToTypeId(decl->entityInfo->USR);
|
||||
TypeDef* type_def = db->Resolve(type_id);
|
||||
|
||||
// TODO: Eventually run with this if. Right now I want to iron out bugs this may shadow.
|
||||
// TODO: For type section, verify if this ever runs for non definitions?
|
||||
//if (!decl->isRedeclaration) {
|
||||
type_def->short_name = decl->entityInfo->name;
|
||||
|
||||
// name can be null in an anonymous struct (see tests/types/anonymous_struct.cc).
|
||||
if (decl->entityInfo->name) {
|
||||
ns->RegisterQualifiedName(decl->entityInfo->USR, decl->semanticContainer, decl->entityInfo->name);
|
||||
type_def->short_name = decl->entityInfo->name;
|
||||
}
|
||||
else {
|
||||
type_def->short_name = "<anonymous>";
|
||||
}
|
||||
|
||||
type_def->qualified_name = ns->QualifiedName(decl->semanticContainer, type_def->short_name);
|
||||
|
||||
// }
|
||||
|
||||
assert(decl->isDefinition);
|
||||
@ -1237,6 +1245,7 @@ void indexEntityReference(CXClientData client_data, const CXIdxEntityRefInfo* re
|
||||
}
|
||||
}
|
||||
|
||||
static bool DUMP_AST = true;
|
||||
|
||||
|
||||
ParsingDatabase Parse(std::string filename) {
|
||||
@ -1245,7 +1254,8 @@ ParsingDatabase Parse(std::string filename) {
|
||||
clang::Index index(0 /*excludeDeclarationsFromPCH*/, 0 /*displayDiagnostics*/);
|
||||
clang::TranslationUnit tu(index, filename, args);
|
||||
|
||||
Dump(tu.document_cursor());
|
||||
if (DUMP_AST)
|
||||
Dump(tu.document_cursor());
|
||||
|
||||
CXIndexAction index_action = clang_IndexAction_create(index.cx_index);
|
||||
|
||||
@ -1369,6 +1379,8 @@ int main(int argc, char** argv) {
|
||||
return 0;
|
||||
*/
|
||||
|
||||
DUMP_AST = true;
|
||||
|
||||
for (std::string path : GetFilesInFolder("tests")) {
|
||||
//if (path != "tests/declaration_vs_definition/class_member_static.cc") continue;
|
||||
//if (path != "tests/enums/enum_class_decl.cc") continue;
|
||||
@ -1385,7 +1397,7 @@ int main(int argc, char** argv) {
|
||||
//if (path != "tests/usage/type_usage_typedef_and_using.cc") continue;
|
||||
//if (path != "tests/usage/usage_inside_of_call.cc") continue;
|
||||
//if (path != "tests/foobar.cc") continue;
|
||||
//if (path != "tests/inheritance/class_inherit_templated_parent.cc") continue;
|
||||
//if (path != "tests/types/anonymous_struct.cc") continue;
|
||||
|
||||
// Parse expected output from the test, parse it into JSON document.
|
||||
std::string expected_output;
|
||||
|
61
tests/types/anonymous_struct.cc
Normal file
61
tests/types/anonymous_struct.cc
Normal file
@ -0,0 +1,61 @@
|
||||
union vector3 {
|
||||
struct { float x, y, z; };
|
||||
float v[3];
|
||||
};
|
||||
|
||||
/*
|
||||
OUTPUT:
|
||||
{
|
||||
"types": [{
|
||||
"id": 0,
|
||||
"usr": "c:@U@vector3",
|
||||
"short_name": "vector3",
|
||||
"qualified_name": "vector3",
|
||||
"definition": "1:1:7",
|
||||
"vars": [3],
|
||||
"uses": ["*1:1:7"]
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:@U@vector3@Sa",
|
||||
"short_name": "<anonymous>",
|
||||
"qualified_name": "vector3::<anonymous>",
|
||||
"definition": "1:2:3",
|
||||
"vars": [0, 1, 2],
|
||||
"uses": ["*1:2:3"]
|
||||
}],
|
||||
"functions": [],
|
||||
"variables": [{
|
||||
"id": 0,
|
||||
"usr": "c:@U@vector3@Sa@FI@x",
|
||||
"short_name": "x",
|
||||
"qualified_name": "x",
|
||||
"definition": "1:2:18",
|
||||
"declaring_type": 1,
|
||||
"uses": ["1:2:18"]
|
||||
}, {
|
||||
"id": 1,
|
||||
"usr": "c:@U@vector3@Sa@FI@y",
|
||||
"short_name": "y",
|
||||
"qualified_name": "y",
|
||||
"definition": "1:2:21",
|
||||
"declaring_type": 1,
|
||||
"uses": ["1:2:21"]
|
||||
}, {
|
||||
"id": 2,
|
||||
"usr": "c:@U@vector3@Sa@FI@z",
|
||||
"short_name": "z",
|
||||
"qualified_name": "z",
|
||||
"definition": "1:2:24",
|
||||
"declaring_type": 1,
|
||||
"uses": ["1:2:24"]
|
||||
}, {
|
||||
"id": 3,
|
||||
"usr": "c:@U@vector3@FI@v",
|
||||
"short_name": "v",
|
||||
"qualified_name": "vector3::v",
|
||||
"definition": "1:3:9",
|
||||
"declaring_type": 0,
|
||||
"uses": ["1:3:9"]
|
||||
}]
|
||||
}
|
||||
*/
|
Loading…
Reference in New Issue
Block a user