This source range covers the list of parameters of a function
declaration.
This adds a SourceLocation trailing object to FunctionProtoType,
and the getEllipsisLoc and getParametersSourceRange methods to
FunctionDecl.
Details
- Reviewers
rsmith steveire aaron.ballman
Diff Detail
Event Timeline
clang/include/clang/AST/Decl.h | ||
---|---|---|
2331 | Why does this omit the ellipsis? It's part of the parameter list and it seems like a strange design decision to leave that out of the source range for the parameter list. | |
clang/lib/AST/Decl.cpp | ||
3305 | Please don't use auto here (or below); the type is not spelled out in the initialization. | |
clang/unittests/AST/SourceLocationTest.cpp | ||
676 | I'd like to see tests that include an ellipsis, as well as tests that use the preprocessor in creative ways. e.g., #define FOO int a, int b void func(FOO); void bar(float f, FOO, float g); void baz(FOO, float f); void quux(float f, FOO); Also, tests for member functions (both static and instance functions) and parameters with leading attributes would be useful. e.g., void func([[]] int *i); |
- Added tests of instance and static functions
- Added tests of parameters with cv qualifiers
- Added tests of parameters with attributes
- Removed auto
clang/include/clang/AST/Decl.h | ||
---|---|---|
2331 | I haven't found a correct way to access the position of the ellipsis. There is no corresponding ParmVarDecl in ParamInfo. | |
clang/unittests/AST/SourceLocationTest.cpp | ||
676 | Source locations with macros always looked inconsistent to me. For example: #define RET int RET f(void); Here, getReturnTypeSourceRange returns <input.cc:2:1 <Spelling=input.cc:1:13>-input.cc:2:1 <Spelling=input.cc:1:13>>, where I would expect (and I could be wrong) <input.cc:2:1 <Spelling=input.cc:1:13>-input.cc:2:3 <Spelling=input.cc:1:16>> The same thing happens with getParametersSourceRange. Should I test the current behavior? I added the other tests you requested. |
clang/include/clang/AST/Decl.h | ||
---|---|---|
2331 | I don't think you've missed anything; I think we need to track/dig out that information in order for this API to be usefully correct. I don't see a lot of value in getting a source range that's sometimes wrong. I would recommend seeing if you can go back to the function type location information as-needed to figure out where the ellipsis is and include it in the range here. | |
clang/unittests/AST/SourceLocationTest.cpp | ||
676 | I'd test current behavior. |
I added the SourceLocation of the ellipsis to FunctionProtoType in addition to the Variadic boolean.
clang/include/clang/AST/Decl.h | ||
---|---|---|
1933 | Why a source range? The ellipsis is a single token, so a range should be unnecessary. I would just have this return FPT->getEllipsisLoc(). | |
2331 | Can you add "excluding the parentheses" to this as well, to make it crystal clear what is covered? | |
clang/lib/AST/Decl.cpp | ||
3306 | Don't use auto unless the type is explicitly spelled out in the initialization (elsewhere as well). |
- getEllipsisSourceRange -> getEllipsisLoc
- Updated the doc comment
- Removed auto where necessary
clang/include/clang/AST/Type.h | ||
---|---|---|
4048 ↗ | (On Diff #212055) | And what if there is no ellipsis ? Shouldn't you do something like return isVariadic() ? *getTrailingObjects<SourceLocation>() : SourceLocation(); instead ? |
Phab looked to be having disk issues when I added my comments, so I'm pinging this review just to be sure the latest comments make it to the mailing list.
I've been looking at a way to get the ellipsis location so I'd like this patch to move forward. @nicolas are you still working on this patch?
Hi @Mordante, thanks for the interest.
Here's an updated patch that addresses @aaron.ballman's comments.
LGTM aside from a minor commenting request.
clang/include/clang/AST/Decl.h | ||
---|---|---|
2331 | You should make the comment clear that this will include the ellipsis (which is sort of a parameter, sort of not). |
Hi, if this patch still LGTY, could you commit it on my behalf?
I don't have commit access.
Thanks a lot!
I committed on your behalf in cc3c935da24c8ebe4fd92638574462b762d92335, thank you for the patch!
Why a source range? The ellipsis is a single token, so a range should be unnecessary. I would just have this return FPT->getEllipsisLoc().