AST Restructuring
We have been restructuring our ASTs. This page includes a list of the guiding principles.
Possible considerations
- Better match up / unify LetExpr and other declaration-level constructs. Why is LetExpr done nesting-style, while local mutable variables, and variable bindings in traits, objects, and at component level are not?
- Juxt.multiJuxt and Juxt.infixJuxt are used during type checking. Restructure them. (After FnRef/OpRef/_RewriteFnRef settle down.)
- Get rid of _RewriteFnRef. (After the interpreter's rewriter is cleaned up. trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java treats FnRef so special.)
- Merge FnRef and OpRef. Similarly, merge _RewriteFnRefOverloading and _RewriteOpRefOverloading. (After the interpreter's rewriter is cleaned up. trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java treats FnRef so special.)
- Get rid of _Rewrite nodes and replace with "this information is known" in extant AST nodes somehow.
- Top-level declarations (?)
- _RewriteFnOverloadDecl
- _RewriteFunctionalMethodDecl
- Will die after the closure conversion of object expressions is on-line
- _RewriteObjectExprDecl
- _RewriteObjectExpr
- _RewriteObjectExprRef
- Top-level declarations (?)
- Include FnExpr as a field of FnDecl and eliminate Applicable. (After the native story is cleaned up. trunk/ProjectFortress/src/com/sun/fortress/interpreter/glue/NativeApp.java muddies the water.)
- Somehow unify ObjectExpr and ObjectDecl. (After _RewriteObjectExpr is eliminated.)
- Treat CoercionInvocation as invocation of a special function named "coerce" (After coercion is implemented.)
- Consider adding interfaces that describe stuff that appears or disappears in different phases? This might make it easier to write and update consistency checks for ASTs. (After the phases settle down.)
- Use Scala option types instead of nulls or PLT option types. (After the work related to Scala code settles down.)
Done (These should remain true.)
General principles
Do not make the number of fields unwieldy. This would detract from the conciseness of pattern matching. (Note FnAbsDeclOrDecl and ObjectAbsDeclOrDecl violate this dictum rather egregiously; not obvious if / how to solve this. Perhaps we can at least pull out the fields these share in common in some way.)done in: r3246Remove optional fields. Instead of providing default values to the optional fields, provide static methods with the default values.done in: r3186, r3187, r3189~r3193, r3198~r3200, r3202, r3203, r3210Get rid of superclasses with one subclass (FnDecl etc.)done in: r3077Do not repeat field declarations in subclasses. The common fields between subclasses should appear in the same order.done in: r3092, r3098, r3099As it always has been (except for the syntax abstraction nodes), a concrete node class should not have any subclasses.done in: r3101Eliminate unnecessary interfaces.done in: r3116Use names (including field names) that are not Java reserved words, nor Scala reserved words, nor Fortress reserved words.done in: r3122, r3123Use only unboxed primitive types.done in: r3125
Ambiguous nodes and _Rewrite nodes
Add interfaces describing after which compiler phase the nodes are eliminated:AmbiguousMultifixOpExprdone in: r3178
Add interfaces describing after which compiler phase the nodes are introduced:_RewriteFnAppdone in: r3177
Get rid of _Rewrite nodes and replace with "this information is known" in extant AST nodes somehow:
Compilation units
Clean up "exports" story (may require syntax cleanup); right now we have export nodes that export a list of APIs, and every component has a list of these export nodes. One of these things shouldn't need a list. Should be able to axe Export node.done in: r3078Get rid of objectExprs and functionalMethodNames fields from Component, replace with appropriate top-level decl nodes.done in: r3112
Declarations
LocalVarDecl and VarDecl have different fields, and the former takes LValueBinds while the latter takes LValues.done in: r3082Remove distinctions between declarations in APIs (AbsDecl) and in components (Decl). Instead, use one node for both with an extra field to denote the context. It would be much preferable if we can eliminate the extra field. Visitors over ASTs might be able to keep track of whatever context they need to in order to determine this for themselves. Note we still need abstract declarations for variables (fields) and functions, but this distinction should be minimized.done in: r3093~r3096Consider making Decl a superclass rather than an interface.done in: r3097Consider treating varargs-ness as a parameter modifier, get rid of children of Param/TupleType/TupleExpr.done in: r3105, r3107, r3109, r3111Replace modifiers by a bucket of flags or enum.done in: r3207
Expressions
If FlowExpr and DelimitedExpr aren't being used for any purpose, get rid of these abstract supertypes. (Presently only used in parser.)done in: r3079Get rid of AppExpr entirely as it appears to be unused.done in: r3100Add optional op for CaseClause.done in: r3101Consider getting rid of Block and replacing by DoFront (best) or Do (gratuitously complicated). --> Replace DoFront with Block.done in: r3137Unify GeneratedExpr and For (or at least common them up in some fashion, perhaps along with other generator-y things).done in: r3138Merge tight and loose juxt.done in: r3182
Types
Unify Domain and TupleType somehow (or at least the varargs bits of them).done in: r3114Merge TupleType and VoidType.done in: r3133For type-level operators (dimensions, nats, booleans, etc), consider just having unary and binary operator nodes with actual operations indicated by an enum. We particularly miss this in DimExpr, but the others distinguish operators by type too (they just have a common supertype).done in: r3167~r3170

