From: Douglas Gregor Date: Wed, 2 Mar 2011 21:45:00 +0000 (+0000) Subject: Force CaseStmt to store its child statements in source-code order, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a9beb52baa6c990d45d638a177d9456e650282a;p=clang 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 . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126887 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h index d7934a1af3..6428594c8e 100644 --- a/include/clang/AST/Stmt.h +++ b/include/clang/AST/Stmt.h @@ -530,7 +530,7 @@ public: }; 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; diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 70c405c132..7e6602fedf 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -1,3 +1,12 @@ +template +struct vector { + +}; + +void f() { + vector v; +} + //===--- SemaDecl.cpp - Semantic Analysis for Declarations ----------------===// // // The LLVM Compiler Infrastructure diff --git a/test/Index/annotate-tokens.c b/test/Index/annotate-tokens.c index d692bd3bba..fc26b679f8 100644 --- a/test/Index/annotate-tokens.c +++ b/test/Index/annotate-tokens.c @@ -8,9 +8,9 @@ void f(void *ptr) { 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 @@ void g(int i, ...) { 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 @@ void g(int i, ...) { // 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