r200640 - Report a correct end location for nameless parameters.

Jordan Rose jordan_rose at apple.com
Mon Feb 3 09:25:06 PST 2014


Can't we just always provide a RangeEnd? For single-token types it should be the same as the start location, but that's fine. (Assuming these are token ranges, not character ranges.)


On Feb 2, 2014, at 7:28 , Benjamin Kramer <benny.kra at googlemail.com> wrote:

> Author: d0k
> Date: Sun Feb  2 09:28:46 2014
> New Revision: 200640
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=200640&view=rev
> Log:
> Report a correct end location for nameless parameters.
> 
> Ranges before:
> void test(void (*)(int), int, float);
>          ~~~~~~~~~~~~~  ~~~~ ~~~~~~
> 
> Ranges after:
> void test(void (*)(int), int, float);
>          ~~~~~~~~~~~~~  ~~~  ~~~~~
> 
> This does not change the actual location of the ParmVarDecl, it still
> points to the location where the name would be. PR17970.
> 
> Modified:
>    cfe/trunk/lib/AST/Decl.cpp
>    cfe/trunk/test/Index/annotate-tokens-cxx0x.cpp
>    cfe/trunk/test/Index/annotate-tokens.cpp
>    cfe/trunk/test/Index/index-templates.cpp
>    cfe/trunk/test/Index/load-decls.c
>    cfe/trunk/test/Index/load-namespaces.cpp
>    cfe/trunk/test/Index/preamble.c
>    cfe/trunk/test/Index/recursive-cxx-member-calls.cpp
>    cfe/trunk/test/Index/usrs.m
> 
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Sun Feb  2 09:28:46 2014
> @@ -1569,7 +1569,9 @@ bool typeIsPostfix(clang::QualType QT) {
> SourceRange DeclaratorDecl::getSourceRange() const {
>   SourceLocation RangeEnd = getLocation();
>   if (TypeSourceInfo *TInfo = getTypeSourceInfo()) {
> -    if (typeIsPostfix(TInfo->getType()))
> +    // If the declaration has no name or the type extends past the name take the
> +    // end location of the type.
> +    if (!getDeclName() || typeIsPostfix(TInfo->getType()))
>       RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd();
>   }
>   return SourceRange(getOuterLocStart(), RangeEnd);
> 
> Modified: cfe/trunk/test/Index/annotate-tokens-cxx0x.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens-cxx0x.cpp?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/annotate-tokens-cxx0x.cpp (original)
> +++ cfe/trunk/test/Index/annotate-tokens-cxx0x.cpp Sun Feb  2 09:28:46 2014
> @@ -83,14 +83,14 @@ void test2() {
> // CHECK-WITH-OVERRIDE: Identifier: "foo" [19:15 - 19:18] CXXMethod=foo:19:15 (virtual)
> // CHECK-WITH-OVERRIDE: Punctuation: "(" [19:18 - 19:19] CXXMethod=foo:19:15 (virtual)
> // CHECK-WITH-OVERRIDE: Identifier: "Int" [19:19 - 19:22] TypeRef=Int:16:13
> -// CHECK-WITH-OVERRIDE: Punctuation: ")" [19:22 - 19:23] ParmDecl=:19:22 (Definition)
> +// CHECK-WITH-OVERRIDE: Punctuation: ")" [19:22 - 19:23] CXXMethod=foo:19:15 (virtual)
> // CHECK-WITH-OVERRIDE: Punctuation: ";" [19:23 - 19:24] ClassDecl=B:18:7 (Definition)
> // CHECK-WITH-OVERRIDE: Keyword: "virtual" [23:3 - 23:10] CXXMethod=foo:23:16 (virtual) [Overrides @19:15]
> // CHECK-WITH-OVERRIDE: Keyword: "void" [23:11 - 23:15] CXXMethod=foo:23:16 (virtual) [Overrides @19:15]
> // CHECK-WITH-OVERRIDE: Identifier: "foo" [23:16 - 23:19] CXXMethod=foo:23:16 (virtual) [Overrides @19:15]
> // CHECK-WITH-OVERRIDE: Punctuation: "(" [23:19 - 23:20] CXXMethod=foo:23:16 (virtual) [Overrides @19:15]
> // CHECK-WITH-OVERRIDE: Identifier: "Int" [23:20 - 23:23] TypeRef=Int:16:13
> -// CHECK-WITH-OVERRIDE: Punctuation: ")" [23:23 - 23:24] ParmDecl=:23:23 (Definition)
> +// CHECK-WITH-OVERRIDE: Punctuation: ")" [23:23 - 23:24] CXXMethod=foo:23:16 (virtual) [Overrides @19:15]
> // CHECK-WITH-OVERRIDE: Keyword: "override" [23:25 - 23:33] attribute(override)=
> // CHECK-WITH-OVERRIDE: Punctuation: ";" [23:33 - 23:34] ClassDecl=S:22:7 (Definition)
> 
> 
> Modified: cfe/trunk/test/Index/annotate-tokens.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/annotate-tokens.cpp?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/annotate-tokens.cpp (original)
> +++ cfe/trunk/test/Index/annotate-tokens.cpp Sun Feb  2 09:28:46 2014
> @@ -71,8 +71,8 @@ void test4() {
> // CHECK: Keyword: "operator" [9:5 - 9:13] CXXMethod=operator++:9:5
> // CHECK: Punctuation: "++" [9:13 - 9:15] CXXMethod=operator++:9:5
> // CHECK: Punctuation: "(" [9:15 - 9:16] CXXMethod=operator++:9:5
> -// CHECK: Keyword: "int" [9:16 - 9:19] ParmDecl=:9:19 (Definition)
> -// CHECK: Punctuation: ")" [9:19 - 9:20] ParmDecl=:9:19 (Definition)
> +// CHECK: Keyword: "int" [9:16 - 9:19] ParmDecl=:9:19 (Definition
> +// CHECK: Punctuation: ")" [9:19 - 9:20] CXXMethod=operator++:9:5
> // CHECK: Punctuation: ";" [9:20 - 9:21] StructDecl=X:7:8 (Definition)
> // CHECK: Punctuation: "}" [10:1 - 10:2] StructDecl=X:7:8 (Definition)
> // CHECK: Punctuation: ";" [10:2 - 10:3]
> @@ -143,7 +143,7 @@ void test4() {
> // CHECK: Punctuation: "(" [23:22 - 23:23] NonTypeTemplateParameter=tfn:23:18 (Definition)
> // CHECK: Identifier: "X" [23:23 - 23:24] TypeRef=struct X:7:8
> // CHECK: Punctuation: "*" [23:24 - 23:25] ParmDecl=:23:25 (Definition)
> -// CHECK: Punctuation: ")" [23:25 - 23:26] ParmDecl=:23:25 (Definition)
> +// CHECK: Punctuation: ")" [23:25 - 23:26] NonTypeTemplateParameter=tfn:23:18 (Definition)
> // CHECK: Punctuation: ">" [23:26 - 23:27] ClassTemplate=TS:24:8 (Definition)
> // CHECK: Keyword: "struct" [24:1 - 24:7] ClassTemplate=TS:24:8 (Definition)
> // CHECK: Identifier: "TS" [24:8 - 24:10] ClassTemplate=TS:24:8 (Definition)
> @@ -165,7 +165,7 @@ void test4() {
> // CHECK: Punctuation: "(" [28:22 - 28:23] NonTypeTemplateParameter=tfn:28:18 (Definition)
> // CHECK: Identifier: "X" [28:23 - 28:24] TypeRef=struct X:7:8
> // CHECK: Punctuation: "*" [28:24 - 28:25] ParmDecl=:28:25 (Definition)
> -// CHECK: Punctuation: ")" [28:25 - 28:26] ParmDecl=:28:25 (Definition)
> +// CHECK: Punctuation: ")" [28:25 - 28:26] NonTypeTemplateParameter=tfn:28:18 (Definition)
> // CHECK: Punctuation: ">" [28:26 - 28:27] CXXMethod=foo:29:15 (Definition)
> // CHECK: Keyword: "void" [29:1 - 29:5] CXXMethod=foo:29:15 (Definition)
> // CHECK: Identifier: "TS" [29:6 - 29:8] TemplateRef=TS:24:8
> 
> Modified: cfe/trunk/test/Index/index-templates.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/index-templates.cpp?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/index-templates.cpp (original)
> +++ cfe/trunk/test/Index/index-templates.cpp Sun Feb  2 09:28:46 2014
> @@ -143,7 +143,7 @@ struct SuperPair : Pair<int, int>, Pair<
> // CHECK-LOAD: index-templates.cpp:40:8: ClassTemplate=storage:40:8 (Definition) Extent=[39:1 - 40:19]
> // CHECK-LOAD: index-templates.cpp:39:45: TemplateTemplateParameter=DataStructure:39:45 (Definition) Extent=[39:10 - 39:66]
> // CHECK-LOAD: index-templates.cpp:39:19: TemplateTypeParameter=:39:19 (Definition) Extent=[39:19 - 39:27]
> -// CHECK-LOAD: index-templates.cpp:39:37: NonTypeTemplateParameter=:39:37 (Definition) Extent=[39:29 - 39:38]
> +// CHECK-LOAD: index-templates.cpp:39:37: NonTypeTemplateParameter=:39:37 (Definition) Extent=[39:29 - 39:37]
> // CHECK-LOAD: index-templates.cpp:39:61: TemplateRef=array:37:8 Extent=[39:61 - 39:66]
> // CHECK-LOAD: index-templates.cpp:42:18: TypedefDecl=Unsigned:42:18 (Definition) Extent=[42:1 - 42:26]
> // CHECK-LOAD: index-templates.cpp:45:8: ClassTemplate=value_c:45:8 Extent=[44:1 - 45:15]
> 
> Modified: cfe/trunk/test/Index/load-decls.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-decls.c?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/load-decls.c (original)
> +++ cfe/trunk/test/Index/load-decls.c Sun Feb  2 09:28:46 2014
> @@ -6,6 +6,8 @@ enum Color {
>   Rouge = Red
> };
> 
> +void PR17970(void (*)(int), float);
> +
> // 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]
> @@ -13,3 +15,8 @@ enum Color {
> // 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: DeclRefExpr=Red:2:3 Extent=[6:11 - 6:14]
> +//
> +// CHECK: load-decls.c:9:6: FunctionDecl=PR17970:9:6 Extent=[9:1 - 9:35]
> +// CHECK: load-decls.c:9:21: ParmDecl=:9:21 (Definition) Extent=[9:14 - 9:27]
> +// CHECK: load-decls.c:9:26: ParmDecl=:9:26 (Definition) Extent=[9:23 - 9:26]
> +// CHECK: load-decls.c:9:34: ParmDecl=:9:34 (Definition) Extent=[9:29 - 9:34]
> 
> Modified: cfe/trunk/test/Index/load-namespaces.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/load-namespaces.cpp?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/load-namespaces.cpp (original)
> +++ cfe/trunk/test/Index/load-namespaces.cpp Sun Feb  2 09:28:46 2014
> @@ -40,7 +40,7 @@ namespace my_rel_ops = std::rel_ops;
> // CHECK: load-namespaces.cpp:16:17: NamespaceRef=std0x:14:11 Extent=[16:17 - 16:22]
> // CHECK: load-namespaces.cpp:18:11: Namespace=std:18:11 (Definition) Extent=[18:1 - 20:2]
> // CHECK: load-namespaces.cpp:19:7: FunctionDecl=g:19:7 Extent=[19:3 - 19:13]
> -// CHECK: load-namespaces.cpp:19:12: ParmDecl=:19:12 (Definition) Extent=[19:9 - 19:13]
> +// CHECK: load-namespaces.cpp:19:12: ParmDecl=:19:12 (Definition) Extent=[19:9 - 19:12]
> // CHECK: load-namespaces.cpp:22:12: UsingDeclaration=g[19:7, 10:8] Extent=[22:1 - 22:13]
> // CHECK: load-namespaces.cpp:22:7: NamespaceRef=std:18:11 Extent=[22:7 - 22:10]
> // CHECK: load-namespaces.cpp:24:11: FunctionDecl=g:24:11 (Definition) Extent=[24:1 - 25:2]
> 
> Modified: cfe/trunk/test/Index/preamble.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/preamble.c?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/preamble.c (original)
> +++ cfe/trunk/test/Index/preamble.c Sun Feb  2 09:28:46 2014
> @@ -17,7 +17,7 @@ void f(int x) {
> // CHECK: preamble.h:4:9: DeclRefExpr=ptr1:3:10 Extent=[4:9 - 4:13]
> // CHECK: preamble.h:5:10: IntegerLiteral= Extent=[5:10 - 5:11]
> // CHECK: preamble.c:5:5: FunctionDecl=wibble:5:5 Extent=[5:1 - 5:16]
> -// CHECK: preamble.c:5:15: ParmDecl=:5:15 (Definition) Extent=[5:12 - 5:16]
> +// CHECK: preamble.c:5:15: ParmDecl=:5:15 (Definition) Extent=[5:12 - 5:15]
> // CHECK-DIAG: preamble.h:4:7:{4:9-4:13}: warning: incompatible pointer types assigning to 'int *' from 'float *'
> // RUN: env CINDEXTEST_EDITING=1 c-index-test -code-completion-at=%s:8:1 -I %S/Inputs -include %t %s 2> %t.stderr.txt | FileCheck -check-prefix CHECK-CC %s
> // CHECK-CC: FunctionDecl:{ResultType int}{TypedText bar}{LeftParen (}{Placeholder int i}{RightParen )} (50)
> 
> Modified: cfe/trunk/test/Index/recursive-cxx-member-calls.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/recursive-cxx-member-calls.cpp?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/recursive-cxx-member-calls.cpp (original)
> +++ cfe/trunk/test/Index/recursive-cxx-member-calls.cpp Sun Feb  2 09:28:46 2014
> @@ -225,13 +225,13 @@ AttributeList::Kind AttributeList::getKi
> // CHECK-tokens: Keyword: "const" [7:14 - 7:19] ParmDecl=:7:26 (Definition)
> // CHECK-tokens: Keyword: "void" [7:20 - 7:24] ParmDecl=:7:26 (Definition)
> // CHECK-tokens: Punctuation: "*" [7:25 - 7:26] ParmDecl=:7:26 (Definition)
> -// CHECK-tokens: Punctuation: "," [7:26 - 7:27] ParmDecl=:7:26 (Definition)
> +// CHECK-tokens: Punctuation: "," [7:26 - 7:27] FunctionDecl=memcmp:7:7
> // CHECK-tokens: Keyword: "const" [7:28 - 7:33] ParmDecl=:7:40 (Definition)
> // CHECK-tokens: Keyword: "void" [7:34 - 7:38] ParmDecl=:7:40 (Definition)
> // CHECK-tokens: Punctuation: "*" [7:39 - 7:40] ParmDecl=:7:40 (Definition)
> -// CHECK-tokens: Punctuation: "," [7:40 - 7:41] ParmDecl=:7:40 (Definition)
> +// CHECK-tokens: Punctuation: "," [7:40 - 7:41] FunctionDecl=memcmp:7:7
> // CHECK-tokens: Identifier: "size_t" [7:42 - 7:48] TypeRef=size_t:2:25
> -// CHECK-tokens: Punctuation: ")" [7:48 - 7:49] ParmDecl=:7:48 (Definition)
> +// CHECK-tokens: Punctuation: ")" [7:48 - 7:49] FunctionDecl=memcmp:7:7
> // CHECK-tokens: Punctuation: ";" [7:49 - 7:50] UnexposedDecl=:6:8 (Definition)
> // CHECK-tokens: Identifier: "size_t" [8:3 - 8:9] TypeRef=size_t:2:25
> // CHECK-tokens: Identifier: "strlen" [8:10 - 8:16] FunctionDecl=strlen:8:10
> @@ -239,7 +239,7 @@ AttributeList::Kind AttributeList::getKi
> // CHECK-tokens: Keyword: "const" [8:17 - 8:22] ParmDecl=:8:29 (Definition)
> // CHECK-tokens: Keyword: "char" [8:23 - 8:27] ParmDecl=:8:29 (Definition)
> // CHECK-tokens: Punctuation: "*" [8:28 - 8:29] ParmDecl=:8:29 (Definition)
> -// CHECK-tokens: Punctuation: ")" [8:29 - 8:30] ParmDecl=:8:29 (Definition)
> +// CHECK-tokens: Punctuation: ")" [8:29 - 8:30] FunctionDecl=strlen:8:10
> // CHECK-tokens: Punctuation: ";" [8:30 - 8:31]
> // CHECK-tokens: Punctuation: "}" [9:1 - 9:2]
> // CHECK-tokens: Keyword: "namespace" [10:1 - 10:10]
> @@ -1534,13 +1534,13 @@ AttributeList::Kind AttributeList::getKi
> // CHECK: 4:55: FieldDecl=second:4:55 (Definition) Extent=[4:51 - 4:61]
> // CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:1 - 9:2]
> // CHECK: 7:7: FunctionDecl=memcmp:7:7 Extent=[7:3 - 7:49]
> -// CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:14 - 7:27]
> -// CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:28 - 7:41]
> -// CHECK: 7:48: ParmDecl=:7:48 (Definition) Extent=[7:42 - 7:49]
> +// CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:14 - 7:26]
> +// CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:28 - 7:40]
> +// CHECK: 7:48: ParmDecl=:7:48 (Definition) Extent=[7:42 - 7:48]
> // CHECK: 7:42: TypeRef=size_t:2:25 Extent=[7:42 - 7:48]
> // CHECK: 8:10: FunctionDecl=strlen:8:10 Extent=[8:3 - 8:30]
> // CHECK: 8:3: TypeRef=size_t:2:25 Extent=[8:3 - 8:9]
> -// CHECK: 8:29: ParmDecl=:8:29 (Definition) Extent=[8:17 - 8:30]
> +// CHECK: 8:29: ParmDecl=:8:29 (Definition) Extent=[8:17 - 8:29]
> // CHECK: 10:17: Namespace=clang:10:17 (Definition) Extent=[10:1 - 35:2]
> // CHECK: 11:9: ClassDecl=IdentifierInfo:11:9 Extent=[11:3 - 11:23]
> // CHECK: 12:9: ClassDecl=AttributeList:12:9 (Definition) Extent=[12:3 - 34:4]
> 
> Modified: cfe/trunk/test/Index/usrs.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/usrs.m?rev=200640&r1=200639&r2=200640&view=diff
> ==============================================================================
> --- cfe/trunk/test/Index/usrs.m (original)
> +++ cfe/trunk/test/Index/usrs.m Sun Feb  2 09:28:46 2014
> @@ -258,9 +258,9 @@ int test_multi_declaration(void) {
> // CHECK-source: usrs.m:69:23: UnexposedExpr= Extent=[69:23 - 69:24]
> // CHECK-source: usrs.m:69:23: IntegerLiteral= Extent=[69:23 - 69:24]
> // CHECK-source: usrs.m:72:6: FunctionDecl=aux_1:72:6 Extent=[72:1 - 72:26]
> -// CHECK-source: usrs.m:72:15: ParmDecl=:72:15 (Definition) Extent=[72:12 - 72:16]
> -// CHECK-source: usrs.m:72:20: ParmDecl=:72:20 (Definition) Extent=[72:17 - 72:21]
> -// CHECK-source: usrs.m:72:25: ParmDecl=:72:25 (Definition) Extent=[72:22 - 72:26]
> +// CHECK-source: usrs.m:72:15: ParmDecl=:72:15 (Definition) Extent=[72:12 - 72:15]
> +// CHECK-source: usrs.m:72:20: ParmDecl=:72:20 (Definition) Extent=[72:17 - 72:20]
> +// CHECK-source: usrs.m:72:25: ParmDecl=:72:25 (Definition) Extent=[72:22 - 72:25]
> // CHECK-source: usrs.m:73:5: FunctionDecl=test_multi_declaration:73:5 (Definition) Extent=[73:1 - 77:2]
> // CHECK-source: usrs.m:73:34: CompoundStmt= Extent=[73:34 - 77:2]
> // CHECK-source: usrs.m:74:3: DeclStmt= Extent=[74:3 - 74:33]
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits




More information about the cfe-commits mailing list