Changeset 3189

Show
Ignore:
Timestamp:
12/10/08 13:53:50 (12 months ago)
Author:
sukyoungryu
Message:

[ast refactoring] Removed optional fields of OpExpr? and AmbiguousMultifixOpExpr?.

Location:
trunk/ProjectFortress
Files:
8 modified

Legend:

Unmodified
Added
Removed
  • trunk/ProjectFortress/astgen/Fortress.ast

    r3187 r3189  
    932932                         * e.g.) 3 + 5 
    933933                         */ 
    934                         OpExpr(FunctionalRef op, 
    935                                List<Expr> args = Collections.<Expr>emptyList()); 
     934                        OpExpr(FunctionalRef op, List<Expr> args); 
    936935                        /** 
    937936                         * If an expression uses and operator, and that operator 
     
    944943                         * e.g.) 3+4+5+6 
    945944                         */ 
    946                         AmbiguousMultifixOpExpr(FunctionalRef infix_op, FunctionalRef multifix_op, 
    947                                                 List<Expr> args = Collections.<Expr>emptyList()) 
     945                        AmbiguousMultifixOpExpr(FunctionalRef infix_op, 
     946                                                FunctionalRef multifix_op, 
     947                                                List<Expr> args) 
    948948                                               implements OutAfterTypeChecking; 
    949949                        /** 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java

    r3186 r3189  
    2727import edu.rice.cs.plt.tuple.Option; 
    2828import edu.rice.cs.plt.tuple.Pair; 
     29import java.util.Arrays; 
    2930import java.util.ArrayList; 
    3031import java.util.Collections; 
     
    420421                        if ( that.getAssignOp().isSome() ) { 
    421422                            Expr _lhs = (Expr)lhs_that.accept(DesugaringVisitor.this); 
    422                             rhs = ExprFactory.makeOpExpr(span, lhs_that.getExprType(), 
     423                            rhs = ExprFactory.makeOpExpr(span, lhs_that.isParenthesized(), 
     424                                                         lhs_that.getExprType(), 
    423425                                                         that.getAssignOp().unwrap(), 
    424                                                          _lhs, rhs); 
     426                                                         Arrays.asList(_lhs, rhs)); 
    425427                        } 
    426428                        return ExprFactory.makeMethodInvocation(span, that.isParenthesized(), 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/PreDisambiguationDesugaringVisitor.java

    r3182 r3189  
    121121 
    122122        if( prefix || suffix ) { 
    123             OpExpr new_op = new OpExpr(that.getSpan(), that.isParenthesized(), that.getInfix_op(), that.getArgs()); 
     123            OpExpr new_op = ExprFactory.makeOpExpr(that.getSpan(), 
     124                                                   that.isParenthesized(), 
     125                                                   that.getExprType(), 
     126                                                   that.getInfix_op(), 
     127                                                   that.getArgs()); 
    124128            return recur(new_op); 
    125129        } 
     
    139143        } 
    140144        else { 
    141             new_op = new OpExpr(that.getSpan(), that.isParenthesized(), op_result, args_result); 
     145            new_op = ExprFactory.makeOpExpr(that.getSpan(), 
     146                                            that.isParenthesized(), 
     147                                            that.getExprType(), 
     148                                            op_result, 
     149                                            args_result); 
    142150        } 
    143151        return cleanupOpExpr(new_op); 
     
    179187                arg = thunk(arg); 
    180188            } 
    181             res = ExprFactory.makeOpExpr(sp,qop,res,arg); 
     189            res = ExprFactory.makeOpExpr(sp, qop, res, arg); 
    182190        } 
    183191        return res; 
     
    195203                                  List<StaticArg> staticArgs) { 
    196204        body = visitGenerators(span, gens, body); 
    197         Expr opexp = ExprFactory.makeOpExpr(span,op,staticArgs); 
     205        Expr opexp = ExprFactory.makeOpExpr(span, op, staticArgs); 
    198206        Expr res = ExprFactory.makeTightJuxt(span, false, 
    199207                                             Useful.list(BIGOP_NAME, 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3187 r3189  
    313313                                        last_non_fn = Option.some(chunk_element.second()); 
    314314                                else 
    315                                         last_non_fn = Option.<Expr>some(ExprFactory.makeOpExpr(infix_juxt, last_non_fn.unwrap(), chunk_element.second())); 
     315                                        last_non_fn = Option.<Expr>some(ExprFactory.makeOpExpr(infix_juxt, 
     316                                                                                               last_non_fn.unwrap(), 
     317                                                                                               chunk_element.second())); 
    316318                        } 
    317319                        else { 
     
    10061008                // See if we can successfully typecheck this expression as a multifix one. 
    10071009                TypeCheckerResult multi_result = 
    1008                         (new OpExpr(that.getSpan(),that.isParenthesized(),that.getMultifix_op(),that.getArgs()).accept(this)); 
     1010                        (ExprFactory.makeOpExpr(that.getSpan(), 
     1011                                                that.isParenthesized(), 
     1012                                                that.getExprType(), 
     1013                                                that.getMultifix_op(), 
     1014                                                that.getArgs()).accept(this)); 
    10091015 
    10101016                if( multi_result.isSuccessful() ) { 
     
    19861992 
    19871993                        // Check a temporary binary op, to see if the result is <: Boolean 
    1988                         OpExpr tempOpExpr = new OpExpr(new Span(prev.getSpan(),next.getSpan()), false , op, Useful.list(prev, next)); 
     1994                        OpExpr tempOpExpr = ExprFactory.makeOpExpr(FortressUtil.spanTwo(prev,next), 
     1995                                                                   op, prev, next); 
    19891996                        TypeCheckerResult temp_op_result = tempOpExpr.accept(this); 
    19901997                        temps_result.add(temp_op_result); 
     
    31173124                // TODO: Separate pass? 
    31183125                // (2) Treat the sequence that remains as a multifix application of the juxtaposition operator. The rules for multifix operators then apply: 
    3119                 OpExpr multi_op_expr = new OpExpr(that.getSpan(), that.getMultiJuxt(), new_juxt_exprs); 
     3126                OpExpr multi_op_expr = ExprFactory.makeOpExpr(that.getSpan(), 
     3127                                                              that.isParenthesized(), 
     3128                                                              that.getExprType(), 
     3129                                                              that.getMultiJuxt(), 
     3130                                                              new_juxt_exprs); 
    31203131                TypeCheckerResult multi_op_result = multi_op_expr.accept(this); 
    31213132                if( multi_op_result.type().isSome() ) { 
     
    31273138                Expr expr_1 = expr_iter.next(); // the fact that >= two items are here is guaranteed from above. 
    31283139                Expr expr_2 = expr_iter.next(); 
    3129                 OpExpr cur_op_expr = new OpExpr(new Span(expr_1.getSpan(),expr_2.getSpan()), that.getInfixJuxt(), Useful.list(expr_1,expr_2)); 
     3140                OpExpr cur_op_expr = ExprFactory.makeOpExpr(FortressUtil.spanTwo(expr_1,expr_2), 
     3141                                                            that.getInfixJuxt(), 
     3142                                                            expr_1, expr_2); 
    31303143                while( expr_iter.hasNext() ) { 
    31313144                    Expr next_expr = expr_iter.next(); 
    3132                     cur_op_expr = new OpExpr(new Span(cur_op_expr.getSpan(),next_expr.getSpan()), that.getInfixJuxt(), Useful.list(cur_op_expr, next_expr)); 
     3145                    cur_op_expr = ExprFactory.makeOpExpr(FortressUtil.spanTwo(cur_op_expr,next_expr), 
     3146                                                         that.getInfixJuxt(), 
     3147                                                         cur_op_expr, next_expr); 
    31333148                } 
    31343149                // typecheck this result instead 
     
    36993714                Type applicationType = app_result.unwrap().first(); 
    37003715 
    3701                 OpExpr new_node = new OpExpr(that.getSpan(), 
    3702                                 that.isParenthesized(), 
    3703                                 Option.<Type>some(applicationType), 
    3704                                 (FunctionalRef)op_result.ast(), 
    3705                                 (List<Expr>)TypeCheckerResult.astFromResults(args_result)); 
     3716                OpExpr new_node = ExprFactory.makeOpExpr(that.getSpan(), 
     3717                                                         that.isParenthesized(), 
     3718                                                         Option.<Type>some(applicationType), 
     3719                                                         (FunctionalRef)op_result.ast(), 
     3720                                                         (List<Expr>)TypeCheckerResult.astFromResults(args_result)); 
    37063721 
    37073722                // If we have a type, constraints must be propagated up. 
     
    46164631                // Moved this to seperate pass 
    46174632                // (2) Treat the sequence that remains as a multifix application of the juxtaposition operator. The rules for multifix operators then apply: 
    4618                 OpExpr multi_op_expr = new OpExpr(that.getSpan(),that.getMultiJuxt(),exprs); 
     4633                OpExpr multi_op_expr = ExprFactory.makeOpExpr(that.getSpan(),that.getMultiJuxt(),exprs); 
    46194634                TypeCheckerResult multi_op_result = multi_op_expr.accept(this); 
    46204635                if( multi_op_result.type().isSome() ) { 
     
    46264641                Expr expr_1 = expr_iter.next(); // the fact that >= two items are here is guaranteed from above. 
    46274642                Expr expr_2 = expr_iter.next(); 
    4628                 OpExpr cur_op_expr = new OpExpr(new Span(expr_1.getSpan(),expr_2.getSpan()), that.getInfixJuxt(), Useful.list(expr_1,expr_2)); 
     4643                OpExpr cur_op_expr = ExprFactory.makeOpExpr(FortressUtil.spanTwo(expr_1,expr_2), 
     4644                                                            that.getInfixJuxt(), 
     4645                                                            expr_1, expr_2); 
    46294646                while( expr_iter.hasNext() ) { 
    46304647                        Expr next_expr = expr_iter.next(); 
    4631                         cur_op_expr = new OpExpr(new Span(cur_op_expr.getSpan(),next_expr.getSpan()), that.getInfixJuxt(), Useful.list(cur_op_expr, next_expr)); 
     4648                        cur_op_expr = ExprFactory.makeOpExpr(FortressUtil.spanTwo(cur_op_expr,next_expr), 
     4649                                                             that.getInfixJuxt(), 
     4650                                                             cur_op_expr, next_expr); 
    46324651                } 
    46334652                // typecheck this result instead 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java

    r3182 r3189  
    10681068    @Override 
    10691069    public FValue forAmbiguousMultifixOpExpr(AmbiguousMultifixOpExpr that) { 
    1070         return this.forOpExpr(new OpExpr(that.getSpan(), that.isParenthesized(), that.getMultifix_op(), that.getArgs())); 
     1070        return this.forOpExpr(ExprFactory.makeOpExpr(that.getSpan(), 
     1071                                                     that.isParenthesized(), 
     1072                                                     that.getExprType(), 
     1073                                                     that.getMultifix_op(), 
     1074                                                     that.getArgs())); 
    10711075    } 
    10721076 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java

    r3187 r3189  
    678678        // remove these nodes and they should never appear at this 
    679679        // phase of execution. However, now we simply create an OpExpr. 
    680         Node node = new OpExpr(op.getSpan(), op.isParenthesized(), op.getInfix_op(), op.getArgs()); 
     680        Node node = ExprFactory.makeOpExpr(op.getSpan(), 
     681                                           op.isParenthesized(), 
     682                                           op.getExprType(), 
     683                                           op.getInfix_op(), 
     684                                           op.getArgs()); 
    681685        return visitNode(node); 
    682686    } 
     
    16071611                        visitedArgs.size() == 1 ? visitedArgs.get(0) : 
    16081612                            new TupleExpr(NodeFactory.makeSpan("impossible", visitedArgs), 
    1609                                     visitedArgs)); 
     1613                                          visitedArgs)); 
    16101614            } 
    16111615        } else  if (expr instanceof FieldRef) { 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r3187 r3189  
    122122        return new MethodInvocation(span, isParenthesized, type, obj, field, 
    123123                                    staticArgs, expr); 
     124    } 
     125 
     126    public static OpExpr makeOpExpr(Span span, Op op) { 
     127        return makeOpExpr(span, makeOpRef(op)); 
     128    } 
     129 
     130    public static OpExpr makeOpExpr(Span span, Op op, Expr arg) { 
     131        return makeOpExpr(span, false, Option.<Type>none(), makeOpRef(op), 
     132                          Collections.singletonList(arg)); 
     133    } 
     134 
     135    public static OpExpr makeOpExpr(Span span, Op op, Expr first, 
     136                                    Expr second) { 
     137        return makeOpExpr(span, false, Option.<Type>none(), makeOpRef(op), 
     138                          Arrays.asList(first, second)); 
     139    } 
     140 
     141    public static OpExpr makeOpExpr(Span span, Op op, List<StaticArg> staticArgs) { 
     142        return makeOpExpr(span, makeOpRef(op, staticArgs)); 
     143    } 
     144 
     145    public static OpExpr makeOpExpr(Span span, FunctionalRef op) { 
     146        return makeOpExpr(span, false, Option.<Type>none(), op, 
     147                          Collections.<Expr>emptyList()); 
     148    } 
     149 
     150    public static OpExpr makeOpExpr(Span span, FunctionalRef op, 
     151                                    List<Expr> args) { 
     152        return makeOpExpr(span, false, Option.<Type>none(), op, args); 
     153    } 
     154 
     155    public static OpExpr makeOpExpr(Span span, FunctionalRef op, 
     156                                    Expr first, Expr second) { 
     157        return makeOpExpr(span, false, Option.<Type>none(), 
     158                          op, Arrays.asList(first, second)); 
     159    } 
     160 
     161    public static OpExpr makeOpExpr(Span span, Option<Type> ty, FunctionalRef op, 
     162                                    Expr first, Expr second) { 
     163        return makeOpExpr(span, false, ty, op, Arrays.asList(first, second)); 
     164    } 
     165 
     166    public static OpExpr makeOpExpr(Span span, Op op, Expr arg, 
     167                                    List<StaticArg> staticArgs) { 
     168        return makeOpExpr(span, false, Option.<Type>none(), 
     169                          makeOpRef(op, staticArgs), 
     170                          Collections.singletonList(arg)); 
     171    } 
     172 
     173    public static OpExpr makeOpExpr(Expr e,FunctionalRef op) { 
     174        return makeOpExpr(FortressUtil.spanTwo(e, op), false, 
     175                          Option.<Type>none(), 
     176                          op, Useful.list(e)); 
     177    } 
     178 
     179    public static OpExpr makeOpExpr(FunctionalRef op, Expr e_1, Expr e_2) { 
     180        return makeOpExpr(FortressUtil.spanTwo(e_1, e_2), op, e_1, e_2); 
     181    } 
     182 
     183    public static OpExpr makeOpExpr(Span span, boolean isParenthesized, 
     184                                    Option<Type> ty, FunctionalRef op, 
     185                                    List<Expr> exprs) { 
     186        return new OpExpr(span, isParenthesized, ty, op, exprs); 
    124187    } 
    125188 
     
    368431    } 
    369432 
    370     public static OpExpr makeOpExpr(Span span, Option<Type> ty, FunctionalRef op, 
    371                                     Expr first, Expr second) { 
    372         return new OpExpr(span, false, ty, op, Arrays.asList(first, second)); 
    373     } 
    374  
    375     public static OpExpr makeOpExpr(Span span, Op op) { 
    376         return new OpExpr(span, false, makeOpRef(op)); 
    377     } 
    378  
    379     public static OpExpr makeOpExpr(Span span, Op op, Expr arg) { 
    380         return new OpExpr(span, false, makeOpRef(op), 
    381                 Collections.singletonList(arg)); 
    382     } 
    383  
    384     public static OpExpr makeOpExpr(Span span, Op op, Expr first, 
    385                                     Expr second) { 
    386         return new OpExpr(span, false, makeOpRef(op), 
    387                           Arrays.asList(first, second)); 
    388     } 
    389  
    390     public static OpExpr makeOpExpr(Span span, Op op, List<StaticArg> staticArgs) { 
    391         return new OpExpr(span, false, makeOpRef(op, staticArgs)); 
    392     } 
    393  
    394     public static OpExpr makeOpExpr(Span span, Op op, Expr arg, 
    395             List<StaticArg> staticArgs) { 
    396         return new OpExpr(span, false, makeOpRef(op, staticArgs), 
    397                           Collections.singletonList(arg)); 
    398     } 
    399  
    400     /** 
    401      * Creates an OpExpr using the Spans from e_1 and e_2. 
    402      */ 
    403     public static OpExpr makeOpExpr(FunctionalRef op, Expr e_1, Expr e_2) { 
    404      return new OpExpr(new Span(e_1.getSpan(), e_2.getSpan()), false, op, Useful.list(e_1, e_2)); 
    405     } 
    406  
    407     public static OpExpr makeOpExpr(Expr e,FunctionalRef op) { 
    408      return new OpExpr(new Span(e.getSpan(),op.getSpan()),false,op,Useful.list(e)); 
    409     } 
    410  
    411433    public static FnRef make_RewriteFnRefOverloading(Span span, FnRef original, Type type) { 
    412434        return new FnRef(span, original.isParenthesized(), original.getExprType(), 
     
    930952        } 
    931953        public Expr forOpExpr(OpExpr e) { 
    932             return new OpExpr(e.getSpan(), true, e.getOp(), e.getArgs()); 
     954            return makeOpExpr(e.getSpan(), true, e.getExprType(), e.getOp(), e.getArgs()); 
    933955        } 
    934956        @Override 
    935                 public Expr forAmbiguousMultifixOpExpr(AmbiguousMultifixOpExpr that) { 
    936                 return new AmbiguousMultifixOpExpr(that.getSpan(), true, 
    937                                                            that.getInfix_op(), that.getMultifix_op(), 
    938                                                            that.getArgs()); 
    939                 } 
     957            public Expr forAmbiguousMultifixOpExpr(AmbiguousMultifixOpExpr that) { 
     958            return new AmbiguousMultifixOpExpr(that.getSpan(), true, that.getExprType(), 
     959                                               that.getInfix_op(), that.getMultifix_op(), 
     960                                               that.getArgs()); 
     961        } 
    940962        public Expr forArrayElement(ArrayElement e) { 
    941963            return makeArrayElement(e.getSpan(), true, e.getExprType(), 
     
    10461068                              op.getLexicalDepth(),new_original_name,new_ops, 
    10471069                              Option.<Type>none()); 
    1048      return ExprFactory.makeOpExpr(new_op, lhs, rhs); 
     1070     return makeOpExpr(new_op, lhs, rhs); 
    10491071    } 
    10501072 
     
    10691091                              op.getLexicalDepth(),new_original_name,new_ops, 
    10701092                              Option.<Type>none()); 
    1071      return ExprFactory.makeOpExpr(e, new_op); 
     1093     return makeOpExpr(e, new_op); 
    10721094    } 
    10731095 
  • trunk/ProjectFortress/src/com/sun/fortress/parser_util/precedence_resolver/ASTUtil.java

    r3182 r3189  
    5959    public static Expr infix(Span span, Expr left, Op op, Expr right) { 
    6060        return ExprFactory.makeOpExpr(span, NodeFactory.makeOpInfix(op), 
    61                                        left, right); 
     61                                      left, right); 
    6262    } 
    6363 
     
    6666    static Expr prefix(Op op, Expr arg) { 
    6767        return ExprFactory.makeOpExpr(arg.getSpan(), 
    68                                        NodeFactory.makeOpPrefix(op), arg); 
     68                                      NodeFactory.makeOpPrefix(op), arg); 
    6969    } 
    7070 
     
    8989 
    9090        if (args.size() > 2) { 
    91                 return new AmbiguousMultifixOpExpr(span, false, infix_op, multifix_op, args); 
     91            return new AmbiguousMultifixOpExpr(span, false, Option.<Type>none(), 
     92                                               infix_op, multifix_op, args); 
    9293        } 
    9394        else if (args.size() == 2) { 
    94                 return new OpExpr(span, false, infix_op, args); 
    95  
     95                return ExprFactory.makeOpExpr(span, infix_op, args); 
    9696        } 
    9797        else { 
     
    117117                                  Collections.<IdOrOp>singletonList(en), 
    118118                                  Option.<Type>none()); 
    119             return new OpExpr(span, false, ref, args); 
     119            return ExprFactory.makeOpExpr(span, ref, args); 
    120120        } else { 
    121121            return error(right, "Mismatched Enclosers: " +