I have added few heuristics to identify c style casting. Only side
effect of this patch is that single identifier wrapped with parentheses
(identifier) are getting treated as cast.
Details
Diff Detail
Event Timeline
Thank you for working on this!
lib/Format/TokenAnnotator.cpp | ||
---|---|---|
757 | Please add: // FIXME: Pull cast detection into its own function. | |
790 | Please use {} for the if, if there are {} for the else. | |
792 | I'd prefer to put this comment on its own line. And please make all comments here full sentences. | |
799 | I think we need to check that Current.Next is not null. Otherwise, this might crash if a line ends in a right parenthesis. On the other hand, I don't think "Prev &&" changes the behavior. How about writing this as: if (Current.Next && Current.Next->Next) { bool NextIsUnary = Current.Next->isUnaryOperator() || Current.Next->isOneOf(tok::amp, tok::star); IsCast = NextIsUnary && Current.Next->Next->isOneOf( tok::identifier, tok::numeric_constant); } I think then it is almost self-explanatory and you don't need the comment. | |
806 | What about:
? | |
808 | Further up in this function, we are using a for-loop for this, i.e. for ( ; Prev != Current.MatchingParen; Prev = Prev->Previous) { .. I think we should be consistent. |
updated patch as per comments
lib/Format/TokenAnnotator.cpp | ||
---|---|---|
757 | added comment | |
790 | updated | |
799 | updated. I am setting IsCast to true and then if it is not identified as cast, it is getting resetted. I am not sure if I have to check for Prev or can assume that it will always be non-null here. | |
806 | I did not get it. Do you mean something like *(my_int_ptr)+2 etc. I will look for other If you have anything specific in mind, which should be handled, please suggest. | |
808 | updated |
Please add: