I agree with your reasoning from a semantic viewpoint, if we're not considering other use cases than code generation here. But the AST is being increasingly used in a lot more places than code generation, like for IDE support and refactoring, so it's a bit of tradeoff between syntax and semantic uses. In my experience it is much easier to consume this information for syntax purposes if it follows the syntax closely, instead of having to special case a lot of nodes that provide information in different ways.
I do have a question about this because I noticed lately a lot of nodes that do not provide locations for some syntactic elements. Should these be patched to provide them, or is it a goal for the AST tree nodes produced by the AST library to be kept as lightweight as possible and only suitable for semantic / code generation purposes? If so, should we provide another AST library that models nodes following syntax as close as possible? On Mon, Aug 13, 2012 at 9:36 PM, Chandler Carruth <[email protected]>wrote: > Just to explain perhaps a bit more, as I too agree with Eli and Chad > here... > > On Mon, Aug 13, 2012 at 4:36 AM, João Matos <[email protected]>wrote: > >> I agree, it would be best to store one node per statement in the AST, >> even if semantically they will be handled as one. >> > > This is a pretty fundamental deviation from the model for the AST. > > We have AST nodes to represent the structural semantics of the program. > Many of these do not even correspond to syntax in the source program. They > are there to expose the underlying semantics of the structure after parsing > has taken place. The inverse applies here: even though there may be syntax > recognized by the parser that resembles that of multiple statements, if the > actual semantic model is that of a single statement, the AST should reflect > that. > > When you say "It would be best to store one node per statement in the AST" > you are begging the question by assuming there are multiple statements in > the source program. I think what Eli and Chad are arguing is that there is > exactly one node per statement in the AST, and all of the inline asm > instructions are part of a single statement due to their semantic model. > > None of this should preclude us exposing source locations and other > information about the syntax used to spell the collection of assembly > instructions that goes into the statement. We have more tools available > than just Stmt nodes in the AST. =] > -- João Matos
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
