зеркало из https://github.com/microsoft/clang.git
[libclang] Fix getting a cursor that points inside tag definition that is part
of a type specifier. e.g. for: typedef struct _MyS { int foo; } MyS; pointing at field 'foo' would give a cursor for the typedef declaration 'MyS' instead of the field. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138593 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
46c03c3e74
Коммит
6f155de99c
|
@ -565,6 +565,12 @@ class TagTypeLoc : public InheritingConcreteTypeLoc<TypeSpecTypeLoc,
|
|||
TagType> {
|
||||
public:
|
||||
TagDecl *getDecl() const { return getTypePtr()->getDecl(); }
|
||||
|
||||
/// \brief True if the tag was defined in this type specifier.
|
||||
bool isDefinition() const {
|
||||
return getDecl()->isDefinition() &&
|
||||
(getNameLoc().isInvalid() || getNameLoc() == getDecl()->getLocation());
|
||||
}
|
||||
};
|
||||
|
||||
/// \brief Wrapper for source info for record types.
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
struct _MyS {
|
||||
int foo;
|
||||
} MyS;
|
||||
|
||||
struct _MyS ww;
|
||||
|
||||
// RUN: c-index-test -cursor-at=%s:1:9 \
|
||||
// RUN: -cursor-at=%s:2:9 \
|
||||
// RUN: -cursor-at=%s:5:9 \
|
||||
// RUN: %s | FileCheck %s
|
||||
|
||||
// CHECK: StructDecl=_MyS:1:8 (Definition)
|
||||
// CHECK: FieldDecl=foo:2:7 (Definition)
|
||||
// CHECK: TypeRef=struct _MyS:1:8
|
|
@ -150,11 +150,10 @@ int test_multi_declaration(void) {
|
|||
// CHECK-source: usrs.m:10:1: EnumDecl=:10:1 (Definition) Extent=[10:1 - 13:2]
|
||||
// CHECK-source: usrs.m:11:3: EnumConstantDecl=FOO:11:3 (Definition) Extent=[11:3 - 11:6]
|
||||
// CHECK-source: usrs.m:12:3: EnumConstantDecl=BAR:12:3 (Definition) Extent=[12:3 - 12:6]
|
||||
// CHECK-source: usrs.m:18:3: TypedefDecl=MyStruct:18:3 (Definition) Extent=[15:1 - 18:11]
|
||||
// CHECK-source: usrs.m:15:9: StructDecl=:15:9 (Definition) Extent=[15:9 - 18:2]
|
||||
// CHECK-source: usrs.m:16:7: FieldDecl=wa:16:7 (Definition) Extent=[16:3 - 16:9]
|
||||
// CHECK-source: usrs.m:17:7: FieldDecl=moo:17:7 (Definition) Extent=[17:3 - 17:10]
|
||||
// CHECK-source: usrs.m:18:3: TypedefDecl=MyStruct:18:3 (Definition) Extent=[15:1 - 18:11]
|
||||
// CHECK-source: usrs.m:15:9: TypeRef=MyStruct:15:9 Extent=[15:9 - 15:15]
|
||||
// CHECK-source: usrs.m:20:6: EnumDecl=Pizza:20:6 (Definition) Extent=[20:1 - 23:2]
|
||||
// CHECK-source: usrs.m:21:3: EnumConstantDecl=CHEESE:21:3 (Definition) Extent=[21:3 - 21:9]
|
||||
// CHECK-source: usrs.m:22:3: EnumConstantDecl=MUSHROOMS:22:3 (Definition) Extent=[22:3 - 22:12]
|
||||
|
|
|
@ -1445,6 +1445,9 @@ bool CursorVisitor::VisitUnresolvedUsingTypeLoc(UnresolvedUsingTypeLoc TL) {
|
|||
}
|
||||
|
||||
bool CursorVisitor::VisitTagTypeLoc(TagTypeLoc TL) {
|
||||
if (TL.isDefinition())
|
||||
return Visit(MakeCXCursor(TL.getDecl(), TU));
|
||||
|
||||
return Visit(MakeCursorTypeRef(TL.getDecl(), TL.getNameLoc(), TU));
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче