[cfe-dev] Extend Stmt with proper end location?
via cfe-dev
cfe-dev at lists.llvm.org
Fri Mar 13 02:08:10 PDT 2020
Hello,
currently Stmt getEndLoc returns slightly different results depending on Stmt type.
Specifically DoWhile, GotoStmt, ContinueStmt, BreakStmt, ReturnStmt, AsmStmt and SEHLeaveStmt do not track the location of the mandatory semicolon at the end.
(Expr is out of scope of this mail thread)
This is not really a high priority problem, but it makes some replacements in clang-tidy unnecessarily difficult.
Currently one has to differentiate by statement type and then parse past it's end skipping comments until a tok::semicolon within checkers.
Of course based on the last Stmt in case of children like an IfStmt without parenthesis.
However I feel this is a kind of an ugly workaround and Stmt.getEndLoc() should just return the proper end location for all statements incl all mandatory tokens.
To accomplish this the beforementioned statements require a new SourceLocation member.
My assumption is that this has little impact on memory & cache-locality, since those are not really high-occurrence statements - but I'm no expert.
Proof of concept is available here: https://reviews.llvm.org/D76108 (it has many many flaws, don't take it as ready for any kind of review).
Does it make sense to continue that way?
Regards,
Alexander Lanin
More information about the cfe-dev
mailing list