[cfe-commits] r112739 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp test/Index/load-decls.c

Douglas Gregor dgregor at apple.com
Wed Sep 1 13:41:53 PDT 2010


Author: dgregor
Date: Wed Sep  1 15:41:53 2010
New Revision: 112739

URL: http://llvm.org/viewvc/llvm-project?rev=112739&view=rev
Log:
Fix the source-range information for an EnumConstantDecl; previously,
it did not include the initializer expression.

Added:
    cfe/trunk/test/Index/load-decls.c
Modified:
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/lib/AST/Decl.cpp

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=112739&r1=112738&r2=112739&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Sep  1 15:41:53 2010
@@ -1697,6 +1697,8 @@
   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; }

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=112739&r1=112738&r2=112739&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Wed Sep  1 15:41:53 2010
@@ -1766,6 +1766,13 @@
   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) {

Added: cfe/trunk/test/Index/load-decls.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-decls.c?rev=112739&view=auto
==============================================================================
--- cfe/trunk/test/Index/load-decls.c (added)
+++ cfe/trunk/test/Index/load-decls.c Wed Sep  1 15:41:53 2010
@@ -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]





More information about the cfe-commits mailing list