]> granicus.if.org Git - clang/commitdiff
Mark a struct definition in an objc container with the TopLevelDeclInObjCContainer...
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 29 Jan 2013 18:00:54 +0000 (18:00 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 29 Jan 2013 18:00:54 +0000 (18:00 +0000)
Fixes accurately getting a cursor inside an objc container containing a struct definition,
from a PCH/preamble file.

rdar://12584613

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173811 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Index/getcursor-preamble.h [new file with mode: 0644]
test/Index/getcursor-preamble.m [new file with mode: 0644]

index 56db548aa6d0cb23e7d39dea0029b3b1de6f13ff..33506401cfe8f68c6dc07475fb1b70117c04d095 100644 (file)
@@ -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/test/Index/getcursor-preamble.h b/test/Index/getcursor-preamble.h
new file mode 100644 (file)
index 0000000..519e655
--- /dev/null
@@ -0,0 +1,8 @@
+@interface I {
+  struct AA {
+    int x;
+  } aa;
+  int var;
+}
+-(id)foo;
+@end
diff --git a/test/Index/getcursor-preamble.m b/test/Index/getcursor-preamble.m
new file mode 100644 (file)
index 0000000..eb9d72e
--- /dev/null
@@ -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