From c821f739b5a82da232e14c7e577edade68f763fd Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 29 Jan 2013 18:00:54 +0000 Subject: [PATCH] Mark a struct definition in an objc container with the TopLevelDeclInObjCContainer bit. Fixes accurately getting a cursor inside an objc container containing a struct definition, from a PCH/preamble file. rdar://12584613 llvm-svn: 173811 --- clang/lib/Sema/SemaDecl.cpp | 6 +++++- clang/test/Index/getcursor-preamble.h | 8 ++++++++ clang/test/Index/getcursor-preamble.m | 21 +++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 clang/test/Index/getcursor-preamble.h create mode 100644 clang/test/Index/getcursor-preamble.m diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 56db548aa6d0..33506401cfe8 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9761,7 +9761,11 @@ void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD, // Exit this scope of this tag's definition. PopDeclContext(); - + + if (getCurLexicalContext()->isObjCContainer() && + Tag->getDeclContext()->isFileContext()) + Tag->setTopLevelDeclInObjCContainer(); + // Notify the consumer that we've defined a tag. Consumer.HandleTagDeclDefinition(Tag); } diff --git a/clang/test/Index/getcursor-preamble.h b/clang/test/Index/getcursor-preamble.h new file mode 100644 index 000000000000..519e655c6ee3 --- /dev/null +++ b/clang/test/Index/getcursor-preamble.h @@ -0,0 +1,8 @@ +@interface I { + struct AA { + int x; + } aa; + int var; +} +-(id)foo; +@end diff --git a/clang/test/Index/getcursor-preamble.m b/clang/test/Index/getcursor-preamble.m new file mode 100644 index 000000000000..eb9d72e2b659 --- /dev/null +++ b/clang/test/Index/getcursor-preamble.m @@ -0,0 +1,21 @@ +#include "getcursor-preamble.h" + +// RUN: c-index-test -cursor-at=%S/getcursor-preamble.h:2:10 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:3:9 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:4:6 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:5:8 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:7:7 \ +// RUN: %s | FileCheck %s + +// RUN: CINDEXTEST_EDITING=1 c-index-test -cursor-at=%S/getcursor-preamble.h:2:10 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:3:9 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:4:6 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:5:8 \ +// RUN: -cursor-at=%S/getcursor-preamble.h:7:7 \ +// RUN: %s | FileCheck %s + +// CHECK: StructDecl=AA:2:10 +// CHECK: FieldDecl=x:3:9 +// CHECK: ObjCIvarDecl=aa:4:5 +// CHECK: ObjCIvarDecl=var:5:7 +// CHECK: ObjCInstanceMethodDecl=foo:7:6 -- GitLab