]> granicus.if.org Git - clang/commitdiff
Fix the source-range information for an EnumConstantDecl; previously,
authorDouglas Gregor <dgregor@apple.com>
Wed, 1 Sep 2010 20:41:53 +0000 (20:41 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 1 Sep 2010 20:41:53 +0000 (20:41 +0000)
it did not include the initializer expression.

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

include/clang/AST/Decl.h
lib/AST/Decl.cpp
test/Index/load-decls.c [new file with mode: 0644]

index 7fb6978d2582afb9506130388dcf3b2f864a5020..6749255322109d457834dec94f3dd2908a6955da 100644 (file)
@@ -1697,6 +1697,8 @@ public:
   void setInitExpr(Expr *E) { Init = (Stmt*) E; }
   void setInitVal(const llvm::APSInt &V) { Val = V; }
 
+  SourceRange getSourceRange() const;
+  
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Decl *D) { return classofKind(D->getKind()); }
   static bool classof(const EnumConstantDecl *D) { return true; }
index 9d9f27e1a07b027af8c4b96817848b6568cf5d3c..b7be02d74533e8bdba82ffb31553a7c2306da79e 100644 (file)
@@ -1766,6 +1766,13 @@ EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
   return new (C) EnumConstantDecl(CD, L, Id, T, E, V);
 }
 
+SourceRange EnumConstantDecl::getSourceRange() const {
+  SourceLocation End = getLocation();
+  if (Init)
+    End = Init->getLocEnd();
+  return SourceRange(getLocation(), End);
+}
+
 TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation L, IdentifierInfo *Id,
                                  TypeSourceInfo *TInfo) {
diff --git a/test/Index/load-decls.c b/test/Index/load-decls.c
new file mode 100644 (file)
index 0000000..cf88f42
--- /dev/null
@@ -0,0 +1,16 @@
+enum Color {
+  Red,
+  Green,
+  Blue,
+
+  Rouge = Red
+};
+
+// RUN: c-index-test -test-load-source all %s | FileCheck %s
+// CHECK: load-decls.c:1:6: EnumDecl=Color:1:6 (Definition) Extent=[1:1 - 7:2]
+// CHECK: load-decls.c:2:3: EnumConstantDecl=Red:2:3 (Definition) Extent=[2:3 - 2:6]
+// CHECK: load-decls.c:3:3: EnumConstantDecl=Green:3:3 (Definition) Extent=[3:3 - 3:8]
+// CHECK: load-decls.c:4:3: EnumConstantDecl=Blue:4:3 (Definition) Extent=[4:3 - 4:7]
+// CHECK: load-decls.c:6:3: EnumConstantDecl=Rouge:6:3 (Definition) Extent=[6:3 - 6:14]
+// CHECK: load-decls.c:6:11: UnexposedExpr=Red:2:3 Extent=[6:11 - 6:14]
+// CHECK: load-decls.c:6:11: DeclRefExpr=Red:2:3 Extent=[6:11 - 6:14]