mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 15:45:08 +00:00
Fix Twine; index TypedefNameDecl to specialization; anonymous RecordDecl fields
This commit is contained in:
parent
3b997b12ad
commit
3be281416d
@ -65,11 +65,17 @@ OUTPUT:
|
|||||||
"types": [1428566502523368801],
|
"types": [1428566502523368801],
|
||||||
"funcs": [],
|
"funcs": [],
|
||||||
"vars": [{
|
"vars": [{
|
||||||
"L": 12549098950381705776,
|
|
||||||
"R": 0
|
|
||||||
}, {
|
|
||||||
"L": 1963212417280098348,
|
"L": 1963212417280098348,
|
||||||
"R": 0
|
"R": 0
|
||||||
|
}, {
|
||||||
|
"L": 3348817847649945564,
|
||||||
|
"R": 0
|
||||||
|
}, {
|
||||||
|
"L": 4821094820988543895,
|
||||||
|
"R": 32
|
||||||
|
}, {
|
||||||
|
"L": 15292551660437765731,
|
||||||
|
"R": 64
|
||||||
}],
|
}],
|
||||||
"instances": [],
|
"instances": [],
|
||||||
"uses": []
|
"uses": []
|
||||||
|
@ -81,7 +81,7 @@ OUTPUT:
|
|||||||
"declarations": [],
|
"declarations": [],
|
||||||
"spell": "5:19-5:23|0|1|2",
|
"spell": "5:19-5:23|0|1|2",
|
||||||
"extent": "5:1-5:23|0|1|0",
|
"extent": "5:1-5:23|0|1|0",
|
||||||
"alias_of": 0,
|
"alias_of": 14491685842684954828,
|
||||||
"bases": [],
|
"bases": [],
|
||||||
"derived": [],
|
"derived": [],
|
||||||
"types": [],
|
"types": [],
|
||||||
|
@ -207,7 +207,7 @@ QualType GetBaseType(QualType T, bool deduce_auto) {
|
|||||||
return BaseType;
|
return BaseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Decl* GetTypeDecl(QualType T) {
|
const Decl *GetTypeDecl(QualType T, bool *specialization = nullptr) {
|
||||||
Decl *D = nullptr;
|
Decl *D = nullptr;
|
||||||
T = GetBaseType(T.getUnqualifiedType(), true);
|
T = GetBaseType(T.getUnqualifiedType(), true);
|
||||||
const Type* TP = T.getTypePtrOrNull();
|
const Type* TP = T.getTypePtrOrNull();
|
||||||
@ -233,6 +233,8 @@ try_again:
|
|||||||
D = cast<TemplateTypeParmType>(TP)->getDecl();
|
D = cast<TemplateTypeParmType>(TP)->getDecl();
|
||||||
break;
|
break;
|
||||||
case Type::TemplateSpecialization:
|
case Type::TemplateSpecialization:
|
||||||
|
if (specialization)
|
||||||
|
*specialization = true;
|
||||||
if (const RecordType *Record = TP->getAs<RecordType>())
|
if (const RecordType *Record = TP->getAs<RecordType>())
|
||||||
D = Record->getDecl();
|
D = Record->getDecl();
|
||||||
else
|
else
|
||||||
@ -492,15 +494,14 @@ public:
|
|||||||
if (L.isMacroID() || !SM.isBeforeInTranslationUnit(L, R.getBegin()))
|
if (L.isMacroID() || !SM.isBeforeInTranslationUnit(L, R.getBegin()))
|
||||||
return;
|
return;
|
||||||
StringRef Buf = GetSourceInRange(SM, Lang, R);
|
StringRef Buf = GetSourceInRange(SM, Lang, R);
|
||||||
Twine Static("static ");
|
Twine Init = Buf.count('\n') <= kInitializerMaxLines - 1
|
||||||
Twine T = Buf.count('\n') <= kInitializerMaxLines - 1
|
? Buf.size() && Buf[0] == ':' ? Twine(" ", Buf)
|
||||||
? def.detailed_name + (Buf.size() && Buf[0] == ':'
|
: Twine(" = ", Buf)
|
||||||
? Twine(" ", Buf)
|
: Twine();
|
||||||
: Twine(" = ", Buf))
|
Twine T = def.detailed_name + Init;
|
||||||
: def.detailed_name;
|
|
||||||
def.hover =
|
def.hover =
|
||||||
def.storage == SC_Static && strncmp(def.detailed_name, "static ", 7)
|
def.storage == SC_Static && strncmp(def.detailed_name, "static ", 7)
|
||||||
? Intern((Static + T).str())
|
? Intern(("static " + T).str())
|
||||||
: Intern(T.str());
|
: Intern(T.str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -811,11 +812,21 @@ public:
|
|||||||
type->def.kind = RD->getTagKind() == TTK_Struct ? lsSymbolKind::Struct
|
type->def.kind = RD->getTagKind() == TTK_Struct ? lsSymbolKind::Struct
|
||||||
: lsSymbolKind::Class;
|
: lsSymbolKind::Class;
|
||||||
if (is_def) {
|
if (is_def) {
|
||||||
bool can_get_offset =
|
SmallVector<std::pair<const RecordDecl *, int>, 2> Stack{{RD, 0}};
|
||||||
RD->isCompleteDefinition() && !RD->isDependentType();
|
while (Stack.size()) {
|
||||||
for (FieldDecl *FD : RD->fields())
|
int offset;
|
||||||
type->def.vars.emplace_back(
|
std::tie(RD, offset) = Stack.back();
|
||||||
GetUsr(FD), can_get_offset ? Ctx->getFieldOffset(FD) : -1);
|
Stack.pop_back();
|
||||||
|
if (!RD->isCompleteDefinition() || RD->isDependentType())
|
||||||
|
offset = -1;
|
||||||
|
for (FieldDecl *FD : RD->fields()) {
|
||||||
|
int offset1 = offset >= 0 ? offset + Ctx->getFieldOffset(FD) : -1;
|
||||||
|
if (FD->getIdentifier())
|
||||||
|
type->def.vars.emplace_back(GetUsr(FD), offset1);
|
||||||
|
else if (const auto *RT1 = FD->getType()->getAs<RecordType>())
|
||||||
|
Stack.push_back({RT1->getDecl(), offset1});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -851,11 +862,19 @@ public:
|
|||||||
case Decl::UnresolvedUsingTypename:
|
case Decl::UnresolvedUsingTypename:
|
||||||
type->def.kind = lsSymbolKind::TypeAlias;
|
type->def.kind = lsSymbolKind::TypeAlias;
|
||||||
if (auto *TD = dyn_cast<TypedefNameDecl>(D)) {
|
if (auto *TD = dyn_cast<TypedefNameDecl>(D)) {
|
||||||
|
bool specialization = false;
|
||||||
QualType T = TD->getUnderlyingType();
|
QualType T = TD->getUnderlyingType();
|
||||||
if (const Decl* D1 = GetTypeDecl(T)) {
|
if (const Decl *D1 = GetTypeDecl(T, &specialization)) {
|
||||||
Usr usr1 = GetUsr(D1);
|
Usr usr1 = GetUsr(D1);
|
||||||
if (db->usr2type.count(usr1))
|
IndexType &type1 = db->ToType(usr1);
|
||||||
type->def.alias_of = usr1;
|
type->def.alias_of = usr1;
|
||||||
|
// Not visited template<class T> struct B {typedef A<T> t;};
|
||||||
|
if (specialization) {
|
||||||
|
const TypeSourceInfo *TSI = TD->getTypeSourceInfo();
|
||||||
|
SourceLocation L1 = TSI->getTypeLoc().getBeginLoc();
|
||||||
|
Range loc1 = FromTokenRange(SM, Lang, {L1, L1});
|
||||||
|
type1.uses.push_back(GetUse(db, loc1, LexDC, Role::Reference));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user