[cfe-dev] SourceLocations of attribute list delimiters – [[ ... , ... ]] etc
Nico Weber via cfe-dev
cfe-dev at lists.llvm.org
Thu Sep 22 08:35:41 PDT 2016
when parsing C++11 [[...]] attributes and Microsoft [...] attributes, we
throw out the source locations of the commas separating the attributes, and
of the surrounding bracket tokens.
I'd like to write a fixit that suggests replacing [uuid(...)] with
__declspec(uuid(...)), but that requires knowing if uuid() is the only
thing in the  list, and if so deleting the whole [...], and if it's not
the only thing, deleting just the uuid() and either its trailing comma if
it's not the last attribute, or the preceding comma if it is the last one.
It's possible someone will want to do something similar with a C++11
attribute in the future.
Since all C++11 attributes are in the AST, one approach would be to check
if there's a preceding C++11 attribute and if so, start the removal after
the last token of the predecessor, and do the same at the other end. But I
think that can't differentiate between `[[good, remove_this, good]]` and
`[[good]] [[remove_this]] [[good]]`. Also, in either approach and the
locations of the [[ ]] delimiters aren't anywhere.
For  attributes, it's a bit harder still since we don't keep most of them
in the AST.
The cleanest way to do this I can think of is to have AttributeClusters (or
similar) in the AST and have them store the SourceLocs of the surrounding
brackets, and the number of attributes therein.
Does that sound useful? Doing this just for my fixit seems overkill :-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev