This is an archive of the discontinued LLVM Phabricator instance.

Store paren locations in IfStmt, WhileStmt, SwitchStmt.
AbandonedPublic

Authored by alexfh on Sep 29 2014, 10:41 AM.

Details

Reviewers
rsmith
Summary

Storing the locations of parentheses in the if/while/switch statements
makes it much more straightforward for the tools (e.g. clang-tidy checks) to
operate on these locations. On the other hand, this increases memory usage
somewhat. I'm not sure what the right tradeoff here is, but my gut feeling is
that memory becomes cheaper, while developers' time doesn't.

Diff Detail

Event Timeline

alexfh updated this revision to Diff 14179.Sep 29 2014, 10:41 AM
alexfh retitled this revision from to Store paren locations in IfStmt, WhileStmt, SwitchStmt..
alexfh updated this object.
alexfh edited the test plan for this revision. (Show Details)
alexfh added a reviewer: rsmith.
alexfh added subscribers: curdeius, Unknown Object (MLST).

In non-macro cases, one can extract the locations of the parentheses using the lexer. Personally, I don't think the benefits of being able to extract the locations of the parentheses efficiently or in the macro cases outweigh the disadvantages of bloating the AST further.

alexfh added a comment.Oct 1 2014, 3:12 PM

In non-macro cases, one can extract the locations of the parentheses using the lexer. Personally, I don't think the benefits of being able to extract the locations of the parentheses efficiently or in the macro cases outweigh the disadvantages of bloating the AST further.

For the context: this patch resulted from the discussion on D5395.

I understand your concerns about bloating the AST. Some locations can be relatively easy found by re-lexing small parts of the input. One problem with this approach is that everyone who needs these locations spends time looking for a way to get them and then writing their own implementation. Is there a document or a comment describing the high-level approach to what is considered worthy storing in the AST?

Also, it may be reasonable to add utility methods in the AST classes (or free-standing functions in clang/AST headers) for retrieving some less frequently used locations of syntactic constructs in non-macro cases (e.g. WhileStmt::findRParenLoc() which would find the first non-comment token after getCond()->getLocEnd()). What do you think?

And while you're here, one more question related to D5395:
what is the reason why the statements ending with a semicolon do not include the semicolon in their source range (with exception of the NullStmt)? Is it feasible to extend the source range to include it? (and what would you expect to break in this case?)

alexfh abandoned this revision.Feb 2 2017, 7:26 AM