[cfe-commits] r126887 - in /cfe/trunk: include/clang/AST/Stmt.h lib/Sema/SemaDecl.cpp test/Index/annotate-tokens.c

Douglas Gregor dgregor at apple.com
Wed Mar 2 13:45:00 PST 2011


Author: dgregor
Date: Wed Mar  2 15:45:00 2011
New Revision: 126887

URL: http://llvm.org/viewvc/llvm-project?rev=126887&view=rev
Log:
Force CaseStmt to store its child statements in source-code order,
which is important for libclang's token-annotation and
where's-my-cursor functionality. Fixes <rdar://problem/9004439>.

Modified:
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/Index/annotate-tokens.c

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=126887&r1=126886&r2=126887&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Wed Mar  2 15:45:00 2011
@@ -530,7 +530,7 @@
 };
 
 class CaseStmt : public SwitchCase {
-  enum { SUBSTMT, LHS, RHS, END_EXPR };
+  enum { LHS, RHS, SUBSTMT, END_EXPR };
   Stmt* SubExprs[END_EXPR];  // The expression for the RHS is Non-null for
                              // GNU "case 1 ... 4" extension
   SourceLocation CaseLoc;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=126887&r1=126886&r2=126887&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Mar  2 15:45:00 2011
@@ -1,3 +1,12 @@
+template<typename T>
+struct vector {
+
+};
+
+void f() {
+  vector<int> v;
+}
+
 //===--- SemaDecl.cpp - Semantic Analysis for Declarations ----------------===//
 //
 //                     The LLVM Compiler Infrastructure

Modified: cfe/trunk/test/Index/annotate-tokens.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.c?rev=126887&r1=126886&r2=126887&view=diff
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens.c (original)
+++ cfe/trunk/test/Index/annotate-tokens.c Wed Mar  2 15:45:00 2011
@@ -8,9 +8,9 @@
   void *xx = ptr ? : &x;
   const char * hello = "Hello";
 }
-
+enum Color { Red, Green, Blue };
 typedef int Int;
-void g(int i, ...) {
+enum Color g(int i, ...) {
   __builtin_va_list va;
   (void)__builtin_va_arg(va, Int);
   (void)__builtin_types_compatible_p(Int, Int);
@@ -19,9 +19,21 @@
   do {
     x.a++;
   } while (x.a < 10);
+  
+  enum Color c;
+  switch (c) {
+  case Red:
+    return Green;
+
+  case Green:
+    return Blue;
+
+  case Blue:
+    return Red;
+  }
 }
 
-// RUN: c-index-test -test-annotate-tokens=%s:4:1:22:1 %s | FileCheck %s
+// RUN: c-index-test -test-annotate-tokens=%s:4:1:34:1 %s | FileCheck %s
 // CHECK: Identifier: "T" [4:3 - 4:4] TypeRef=T:1:13
 // CHECK: Punctuation: "*" [4:4 - 4:5] VarDecl=t_ptr:4:6 (Definition)
 // CHECK: Identifier: "t_ptr" [4:6 - 4:11] VarDecl=t_ptr:4:6 (Definition)
@@ -95,5 +107,33 @@
 // CHECK: Punctuation: "." [21:13 - 21:14] MemberRefExpr=a:2:16
 // CHECK: Identifier: "a" [21:14 - 21:15] MemberRefExpr=a:2:16
 
+// CHECK: Keyword: "enum" [23:3 - 23:7] UnexposedStmt=
+// CHECK: Identifier: "Color" [23:8 - 23:13] TypeRef=enum Color:11:6
+// CHECK: Identifier: "c" [23:14 - 23:15] VarDecl=c:23:14 (Definition)
+// CHECK: Punctuation: ";" [23:15 - 23:16] UnexposedStmt=
+// CHECK: Keyword: "switch" [24:3 - 24:9] UnexposedStmt=
+// CHECK: Punctuation: "(" [24:10 - 24:11] UnexposedStmt=
+// CHECK: Identifier: "c" [24:11 - 24:12] DeclRefExpr=c:23:14
+// CHECK: Punctuation: ")" [24:12 - 24:13] UnexposedStmt=
+// CHECK: Punctuation: "{" [24:14 - 24:15] UnexposedStmt=
+// CHECK: Keyword: "case" [25:3 - 25:7] UnexposedStmt=
+// CHECK: Identifier: "Red" [25:8 - 25:11] DeclRefExpr=Red:11:14
+// CHECK: Punctuation: ":" [25:11 - 25:12] UnexposedStmt=
+// CHECK: Keyword: "return" [26:5 - 26:11] UnexposedStmt=
+// CHECK: Identifier: "Green" [26:12 - 26:17] DeclRefExpr=Green:11:19
+// CHECK: Punctuation: ";" [26:17 - 26:18] UnexposedStmt=
+// CHECK: Keyword: "case" [28:3 - 28:7] UnexposedStmt=
+// CHECK: Identifier: "Green" [28:8 - 28:13] DeclRefExpr=Green:11:19
+// CHECK: Punctuation: ":" [28:13 - 28:14] UnexposedStmt=
+// CHECK: Keyword: "return" [29:5 - 29:11] UnexposedStmt=
+// CHECK: Identifier: "Blue" [29:12 - 29:16] DeclRefExpr=Blue:11:26
+// CHECK: Punctuation: ";" [29:16 - 29:17] UnexposedStmt=
+// CHECK: Keyword: "case" [31:3 - 31:7] UnexposedStmt=
+// CHECK: Identifier: "Blue" [31:8 - 31:12] DeclRefExpr=Blue:11:26
+// CHECK: Punctuation: ":" [31:12 - 31:13] UnexposedStmt=
+// CHECK: Keyword: "return" [32:5 - 32:11] UnexposedStmt=
+// CHECK: Identifier: "Red" [32:12 - 32:15] DeclRefExpr=Red:11:14
+// CHECK: Punctuation: ";" [32:15 - 32:16] UnexposedStmt=
+
 // RUN: c-index-test -test-annotate-tokens=%s:4:1:165:32 %s | FileCheck %s
 // RUN: c-index-test -test-annotate-tokens=%s:4:1:165:38 %s | FileCheck %s





More information about the cfe-commits mailing list