You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of the key features of the Nanopass framework is automating the "boring-parts" of transformation between passes. I think our equivalent could be a generated visitor base class for each pass. By default, it would do a catamorphic transformation on unchanged nodes - that you can still override, if you need -, and would require the user to write the ones that were affected.
abstractclassPass1ToPass2Base{// Generate dispatch functionalitypublicPass2.ExprApply(Pass1.Exprexpr)=>exprswitch{Pass1.Expr.Unite=>Apply(e),Pass1.Expr.IfElsee=>Apply(e),Pass1.Expr.Ife=>Apply(e),Pass1.Expr.Namee=>Apply(e),
_ =>thrownewInvalidOperationException(),};// Unchanged nodes are just translated trivially// The user can still override them, if neededpublicvirtualPass2.ExprApply(Pass1.Expr.Unite)=>newPass2.Expr.Unit();publicvirtualPass2.ExprApply(Pass1.Expr.IfElsee)=>newPass2.Expr.IfElse(Apply(e..Cond),Apply(e.Then),Apply(e.Else));// Changed or removed nodes are required to be handled by the userpublicabstractPass2.ExprApply(Pass1.Expr.Ife);publicabstractPass2.ExprApply(Pass1.Expr.Namee);}
One of the key features of the Nanopass framework is automating the "boring-parts" of transformation between passes. I think our equivalent could be a generated visitor base class for each pass. By default, it would do a catamorphic transformation on unchanged nodes - that you can still override, if you need -, and would require the user to write the ones that were affected.
For example, let's say we have this AST:
And then we do the following modifications:
Then the next generated AST would look like:
And the generated visitor base could be:
Then all the user needs to implement is:
The text was updated successfully, but these errors were encountered: