Changeset 3189
- Timestamp:
- 12/10/08 13:53:50 (12 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 8 modified
-
astgen/Fortress.ast (modified) (2 diffs)
-
src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/desugarer/PreDisambiguationDesugaringVisitor.java (modified) (4 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeChecker.java (modified) (8 diffs)
-
src/com/sun/fortress/interpreter/evaluator/Evaluator.java (modified) (1 diff)
-
src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java (modified) (2 diffs)
-
src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (5 diffs)
-
src/com/sun/fortress/parser_util/precedence_resolver/ASTUtil.java (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3187 r3189 932 932 * e.g.) 3 + 5 933 933 */ 934 OpExpr(FunctionalRef op, 935 List<Expr> args = Collections.<Expr>emptyList()); 934 OpExpr(FunctionalRef op, List<Expr> args); 936 935 /** 937 936 * If an expression uses and operator, and that operator … … 944 943 * e.g.) 3+4+5+6 945 944 */ 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) 948 948 implements OutAfterTypeChecking; 949 949 /** -
trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java
r3186 r3189 27 27 import edu.rice.cs.plt.tuple.Option; 28 28 import edu.rice.cs.plt.tuple.Pair; 29 import java.util.Arrays; 29 30 import java.util.ArrayList; 30 31 import java.util.Collections; … … 420 421 if ( that.getAssignOp().isSome() ) { 421 422 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(), 423 425 that.getAssignOp().unwrap(), 424 _lhs, rhs);426 Arrays.asList(_lhs, rhs)); 425 427 } 426 428 return ExprFactory.makeMethodInvocation(span, that.isParenthesized(), -
trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/PreDisambiguationDesugaringVisitor.java
r3182 r3189 121 121 122 122 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()); 124 128 return recur(new_op); 125 129 } … … 139 143 } 140 144 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); 142 150 } 143 151 return cleanupOpExpr(new_op); … … 179 187 arg = thunk(arg); 180 188 } 181 res = ExprFactory.makeOpExpr(sp, qop,res,arg);189 res = ExprFactory.makeOpExpr(sp, qop, res, arg); 182 190 } 183 191 return res; … … 195 203 List<StaticArg> staticArgs) { 196 204 body = visitGenerators(span, gens, body); 197 Expr opexp = ExprFactory.makeOpExpr(span, op,staticArgs);205 Expr opexp = ExprFactory.makeOpExpr(span, op, staticArgs); 198 206 Expr res = ExprFactory.makeTightJuxt(span, false, 199 207 Useful.list(BIGOP_NAME, -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3187 r3189 313 313 last_non_fn = Option.some(chunk_element.second()); 314 314 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())); 316 318 } 317 319 else { … … 1006 1008 // See if we can successfully typecheck this expression as a multifix one. 1007 1009 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)); 1009 1015 1010 1016 if( multi_result.isSuccessful() ) { … … 1986 1992 1987 1993 // 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); 1989 1996 TypeCheckerResult temp_op_result = tempOpExpr.accept(this); 1990 1997 temps_result.add(temp_op_result); … … 3117 3124 // TODO: Separate pass? 3118 3125 // (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); 3120 3131 TypeCheckerResult multi_op_result = multi_op_expr.accept(this); 3121 3132 if( multi_op_result.type().isSome() ) { … … 3127 3138 Expr expr_1 = expr_iter.next(); // the fact that >= two items are here is guaranteed from above. 3128 3139 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); 3130 3143 while( expr_iter.hasNext() ) { 3131 3144 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); 3133 3148 } 3134 3149 // typecheck this result instead … … 3699 3714 Type applicationType = app_result.unwrap().first(); 3700 3715 3701 OpExpr new_node = newOpExpr(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)); 3706 3721 3707 3722 // If we have a type, constraints must be propagated up. … … 4616 4631 // Moved this to seperate pass 4617 4632 // (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 = newOpExpr(that.getSpan(),that.getMultiJuxt(),exprs);4633 OpExpr multi_op_expr = ExprFactory.makeOpExpr(that.getSpan(),that.getMultiJuxt(),exprs); 4619 4634 TypeCheckerResult multi_op_result = multi_op_expr.accept(this); 4620 4635 if( multi_op_result.type().isSome() ) { … … 4626 4641 Expr expr_1 = expr_iter.next(); // the fact that >= two items are here is guaranteed from above. 4627 4642 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); 4629 4646 while( expr_iter.hasNext() ) { 4630 4647 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); 4632 4651 } 4633 4652 // typecheck this result instead -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java
r3182 r3189 1068 1068 @Override 1069 1069 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())); 1071 1075 } 1072 1076 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java
r3187 r3189 678 678 // remove these nodes and they should never appear at this 679 679 // 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()); 681 685 return visitNode(node); 682 686 } … … 1607 1611 visitedArgs.size() == 1 ? visitedArgs.get(0) : 1608 1612 new TupleExpr(NodeFactory.makeSpan("impossible", visitedArgs), 1609 visitedArgs));1613 visitedArgs)); 1610 1614 } 1611 1615 } else if (expr instanceof FieldRef) { -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java
r3187 r3189 122 122 return new MethodInvocation(span, isParenthesized, type, obj, field, 123 123 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); 124 187 } 125 188 … … 368 431 } 369 432 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 411 433 public static FnRef make_RewriteFnRefOverloading(Span span, FnRef original, Type type) { 412 434 return new FnRef(span, original.isParenthesized(), original.getExprType(), … … 930 952 } 931 953 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()); 933 955 } 934 956 @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 } 940 962 public Expr forArrayElement(ArrayElement e) { 941 963 return makeArrayElement(e.getSpan(), true, e.getExprType(), … … 1046 1068 op.getLexicalDepth(),new_original_name,new_ops, 1047 1069 Option.<Type>none()); 1048 return ExprFactory.makeOpExpr(new_op, lhs, rhs);1070 return makeOpExpr(new_op, lhs, rhs); 1049 1071 } 1050 1072 … … 1069 1091 op.getLexicalDepth(),new_original_name,new_ops, 1070 1092 Option.<Type>none()); 1071 return ExprFactory.makeOpExpr(e, new_op);1093 return makeOpExpr(e, new_op); 1072 1094 } 1073 1095 -
trunk/ProjectFortress/src/com/sun/fortress/parser_util/precedence_resolver/ASTUtil.java
r3182 r3189 59 59 public static Expr infix(Span span, Expr left, Op op, Expr right) { 60 60 return ExprFactory.makeOpExpr(span, NodeFactory.makeOpInfix(op), 61 left, right);61 left, right); 62 62 } 63 63 … … 66 66 static Expr prefix(Op op, Expr arg) { 67 67 return ExprFactory.makeOpExpr(arg.getSpan(), 68 NodeFactory.makeOpPrefix(op), arg);68 NodeFactory.makeOpPrefix(op), arg); 69 69 } 70 70 … … 89 89 90 90 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); 92 93 } 93 94 else if (args.size() == 2) { 94 return new OpExpr(span, false, infix_op, args); 95 95 return ExprFactory.makeOpExpr(span, infix_op, args); 96 96 } 97 97 else { … … 117 117 Collections.<IdOrOp>singletonList(en), 118 118 Option.<Type>none()); 119 return new OpExpr(span, false, ref, args);119 return ExprFactory.makeOpExpr(span, ref, args); 120 120 } else { 121 121 return error(right, "Mismatched Enclosers: " +

