Opened 20 months ago

Closed 5 months ago

#256 closed enhancement (fixed)

New Clause Node for Statements

Reported by: ajbeach Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:


For whatever reason, statements seem to have some cases where a child node is needed but it isn't its own statement. This problem has either been solved by making them their own statement anyways (such as the FinallyStmt?) or by packing a lot of data structures into one node (such as the WaitForStmt?).

The first solution (pretend it is a statement) does work as long as there are no mistakes confusing this node for a statement and none of the special machinery around statements is activated. There are also some speed and memory advantages but they are very small.

The second solution (make it all one node) requires a lot more manual work and introduces more special cases. A lot of that has already been done but new cases keep coming up.

The new solution is to add a new super node to Stmt.hpp:

// Represents a significant section of a statement.
class Clause : public ParseNode {
    Clause( const CodeLocation & loc ) : ParseNode(loc) {}

    Clause( const Clause & o ) : ParseNode( o ) {}

    const Clause * accept( Visitor & v ) const override = 0;
    Clause * clone() const override = 0;

All the new "Clause" types inherit from this node and could be given a new suffix. It inherits from ParseNode? so get a code location for debugging and error messages. Also the child clauses could inherit directly from ParseNode? but this helps with organization.

A similar solution could be used with expressions/Expr and declarations/Decl, but it just hasn't come up and even if it did there is less special cases around Expr and Decl as compared to Stmt, so the improvements would be fewer.

(This might be pushed back to after the old AST is removed to that maintaining symmetry between the new and old AST is not a factor in the rework.)

Change History (1)

comment:1 Changed 5 months ago by ajbeach

Resolution: fixed
Status: newclosed

We did not wait until the translation was complete. There were a few changes, such as the node being called StmtClause?, just for clarity and possibly to separate it from some DeclClause? that might come later, but the idea is the same as presented here.

Note: See TracTickets for help on using tickets.