[cfe-commits] r136572 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp test/Index/annotate-tokens-with-default-args.cpp test/Index/annotate-tokens-with-default-args.h

Argyrios Kyrtzidis akyrtzi at gmail.com
Sat Jul 30 10:23:26 PDT 2011


Author: akirtzidis
Date: Sat Jul 30 12:23:26 2011
New Revision: 136572

URL: http://llvm.org/viewvc/llvm-project?rev=136572&view=rev
Log:
[libclang] Annotation of parameters that got default args from a previous declarations was
broken because the end location of the parameter was the end location of the default arg,
resulting in a source range that could begin in one file and end in another.

Added:
    cfe/trunk/test/Index/annotate-tokens-with-default-args.cpp
    cfe/trunk/test/Index/annotate-tokens-with-default-args.h
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=136572&r1=136571&r2=136572&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Sat Jul 30 12:23:26 2011
@@ -1198,6 +1198,8 @@
                              StorageClass S, StorageClass SCAsWritten,
                              Expr *DefArg);
 
+  virtual SourceRange getSourceRange() const;
+
   void setObjCMethodScopeInfo(unsigned parameterIndex) {
     ParmVarDeclBits.IsObjCMethodParam = true;
 

Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=136572&r1=136571&r2=136572&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Sat Jul 30 12:23:26 2011
@@ -1388,6 +1388,16 @@
                              S, SCAsWritten, DefArg);
 }
 
+SourceRange ParmVarDecl::getSourceRange() const {
+  if (!hasInheritedDefaultArg()) {
+    SourceRange ArgRange = getDefaultArgRange();
+    if (ArgRange.isValid())
+      return SourceRange(getOuterLocStart(), ArgRange.getEnd());
+  }
+
+  return DeclaratorDecl::getSourceRange();
+}
+
 Expr *ParmVarDecl::getDefaultArg() {
   assert(!hasUnparsedDefaultArg() && "Default argument is not yet parsed!");
   assert(!hasUninstantiatedDefaultArg() &&

Added: cfe/trunk/test/Index/annotate-tokens-with-default-args.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens-with-default-args.cpp?rev=136572&view=auto
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens-with-default-args.cpp (added)
+++ cfe/trunk/test/Index/annotate-tokens-with-default-args.cpp Sat Jul 30 12:23:26 2011
@@ -0,0 +1,16 @@
+#include "annotate-tokens-with-default-args.h"
+
+void Foo::m(Foo *f) {}
+
+// RUN: c-index-test -test-annotate-tokens=%s:3:1:4:1 %s | FileCheck %s
+// CHECK: Keyword: "void" [3:1 - 3:5] CXXMethod=m:3:11 (Definition)
+// CHECK: Identifier: "Foo" [3:6 - 3:9] TypeRef=struct Foo:1:8
+// CHECK: Punctuation: "::" [3:9 - 3:11] CXXMethod=m:3:11 (Definition)
+// CHECK: Identifier: "m" [3:11 - 3:12] CXXMethod=m:3:11 (Definition)
+// CHECK: Punctuation: "(" [3:12 - 3:13] CXXMethod=m:3:11 (Definition)
+// CHECK: Identifier: "Foo" [3:13 - 3:16] TypeRef=struct Foo:1:8
+// CHECK: Punctuation: "*" [3:17 - 3:18] ParmDecl=f:3:18 (Definition)
+// CHECK: Identifier: "f" [3:18 - 3:19] ParmDecl=f:3:18 (Definition)
+// CHECK: Punctuation: ")" [3:19 - 3:20] CXXMethod=m:3:11 (Definition)
+// CHECK: Punctuation: "{" [3:21 - 3:22] UnexposedStmt=
+// CHECK: Punctuation: "}" [3:22 - 3:23] UnexposedStmt=

Added: cfe/trunk/test/Index/annotate-tokens-with-default-args.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens-with-default-args.h?rev=136572&view=auto
==============================================================================
--- cfe/trunk/test/Index/annotate-tokens-with-default-args.h (added)
+++ cfe/trunk/test/Index/annotate-tokens-with-default-args.h Sat Jul 30 12:23:26 2011
@@ -0,0 +1,3 @@
+struct Foo {
+  void m(Foo *f = 0);
+};





More information about the cfe-commits mailing list