summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-30 17:23:26 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-07-30 17:23:26 +0000
commit4c6efa62e057da00d0645be3afccd922e43fa4d8 (patch)
treee916f994ef69678600ed4ad1d621ae9ce7e232ee /clang
parenteb5ea833ed7e095f13b93120114e9649767339fc (diff)
downloadbcm5719-llvm-4c6efa62e057da00d0645be3afccd922e43fa4d8.tar.gz
bcm5719-llvm-4c6efa62e057da00d0645be3afccd922e43fa4d8.zip
[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. llvm-svn: 136572
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/Decl.h2
-rw-r--r--clang/lib/AST/Decl.cpp10
-rw-r--r--clang/test/Index/annotate-tokens-with-default-args.cpp16
-rw-r--r--clang/test/Index/annotate-tokens-with-default-args.h3
4 files changed, 31 insertions, 0 deletions
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 938de814e28..1ff9e55cf46 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1198,6 +1198,8 @@ public:
StorageClass S, StorageClass SCAsWritten,
Expr *DefArg);
+ virtual SourceRange getSourceRange() const;
+
void setObjCMethodScopeInfo(unsigned parameterIndex) {
ParmVarDeclBits.IsObjCMethodParam = true;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index ed8171d3ef1..64fd355446a 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -1388,6 +1388,16 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
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() &&
diff --git a/clang/test/Index/annotate-tokens-with-default-args.cpp b/clang/test/Index/annotate-tokens-with-default-args.cpp
new file mode 100644
index 00000000000..2c8844156ff
--- /dev/null
+++ b/clang/test/Index/annotate-tokens-with-default-args.cpp
@@ -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=
diff --git a/clang/test/Index/annotate-tokens-with-default-args.h b/clang/test/Index/annotate-tokens-with-default-args.h
new file mode 100644
index 00000000000..323c519351f
--- /dev/null
+++ b/clang/test/Index/annotate-tokens-with-default-args.h
@@ -0,0 +1,3 @@
+struct Foo {
+ void m(Foo *f = 0);
+};
OpenPOWER on IntegriCloud