v.g.vassilev added inline comments.
================
Comment at: clang/lib/Parse/Parser.cpp:1033
+ !isDeclarationStatement(/*DisambiguatingWithExpression=*/true))
+ SingleDecl = ParseTopLevelStmtDecl();
+
----------------
There is a remaining challenge which probably could be addressed outside of
this patch.
Consider this statement block:
```
int i = 12;
++i;
i--;
template<typename T> struct A { };
```
Ideally we should model `++i; i--;` as a single `TopLevelStmtDecl` as the
statement block is contiguous. That would require the creation of 2 AST nodes
per block (one for the `TopLevelStmtDecl` and one for its conversion to
`FunctionDecl`). This will give us also a nice property on the REPL side where
the user could decide to squash multiple statements into a statement block to
save on memory.
To do so, we will need to use `isDeclarationStatement` as a stop rule in
`ParseTopLevelDecl`. In turn, this would mean that we should duplicate all of
the switch cases described in the `ParseExternalDeclaration` function here. [We
need teach `isDeclarationStatement` everything we know about declarations, eg.
it must tell us to stop when we see definition `struct A`].
The last version of this patch goes in the opposite direction, trying to
minimize the code duplication (bloat?) by wrapping each global statement into a
`TopLevelStmtDecl`, reusing the logic in `ParseExternalDeclaration`. However,
we pay the price for 2 AST node allocations per global statement. That is a
serious hit for people that want to control the parsing granularity of an
interpreter.
I wonder if we can do something better hitting both requirements in some smart
way I cannot see...
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127284/new/
https://reviews.llvm.org/D127284
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits