Changeset 3146
- Timestamp:
- 12/04/08 07:22:05 (12 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 13 modified
-
astgen/Fortress.ast (modified) (2 diffs)
-
src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java (modified) (1 diff)
-
src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java (modified) (8 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeChecker.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/Evaluator.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java (modified) (6 diffs)
-
src/com/sun/fortress/interpreter/rewrite/RewriteInPresenceOfTypeInfoVisitor.java (modified) (3 diffs)
-
src/com/sun/fortress/nodes_util/ErrorMsgMaker.java (modified) (2 diffs)
-
src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (7 diffs)
-
src/com/sun/fortress/nodes_util/NodeUtil.java (modified) (1 diff)
-
src/com/sun/fortress/parser/Expression.rats (modified) (2 diffs)
-
src/com/sun/fortress/syntax_abstractions/phases/Transform.java (modified) (1 diff)
-
src/com/sun/fortress/tools/FortressAstToConcrete.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3145 r3146 992 992 * Primary ::= self 993 993 * e.g.) length 994 */ 995 VarRef(Id varId, int lexicalDepth=-2147483648) implements Lhs; 996 /** 994 * 995 * <staticArgs> 997 996 * A reference to a singleton object. Created at typechecking or disambiguation-time. 998 997 * Necessary because object references are initially parsed as FnRefs. … … 1001 1000 * object Foo[\T\] ... end 1002 1001 */ 1003 _RewriteObjectRef(Id obj, List<StaticArg> staticArgs); 1002 VarRef(Id varId, 1003 List<StaticArg> staticArgs, 1004 int lexicalDepth=-2147483648) implements Lhs; 1004 1005 /** 1005 1006 * Temporarily, until closure conversion is always on-line, -
trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java
r3123 r3146 498 498 @Override 499 499 public Node forVarRefOnly(VarRef that, Option<Type> exprType_result, 500 Id varResult ) {500 Id varResult, List<StaticArg> staticArg_result) { 501 501 // After disambiguation, the Id in a VarRef should have an empty API. 502 502 assert(varResult.getApiName().isNone()); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java
r3138 r3146 72 72 import com.sun.fortress.nodes.OpRef; 73 73 import com.sun.fortress.nodes.Param; 74 import com.sun.fortress.nodes.StaticArg; 74 75 import com.sun.fortress.nodes.StaticParam; 75 76 import com.sun.fortress.nodes.TaggedDimType; … … 87 88 import com.sun.fortress.nodes.VoidLiteralExpr; 88 89 import com.sun.fortress.nodes.While; 89 import com.sun.fortress.nodes._RewriteObjectRef;90 90 import com.sun.fortress.nodes_util.ExprFactory; 91 91 import com.sun.fortress.nodes_util.NodeFactory; … … 949 949 @Override public Node forVarRef(VarRef that) { 950 950 Id name = that.getVarId(); 951 952 // singleton object 953 if ( NodeUtil.isSingletonObject(that) ) { 954 Set<Id> objs = _env.explicitTypeConsNames(name); 955 if( objs.isEmpty() ) { 956 objs = _env.onDemandTypeConsNames(name); 957 } 958 959 if( objs.isEmpty() ) { 960 return that; 961 } 962 else if( objs.size() == 1 ) { 963 return new VarRef(that.getSpan(), IterUtil.first(objs), that.getStaticArgs()); 964 } 965 else { 966 error("Name may refer to: " + NodeUtil.namesString(objs), that); 967 return that; 968 } 969 } 970 951 971 Option<APIName> api = name.getApiName(); 952 972 ConsList<Id> fields = ConsList.empty(); … … 966 986 return that; 967 987 } 968 else { result = new VarRef(newId.getSpan(), newId); } 988 else { result = new VarRef(newId.getSpan(), newId, 989 Collections.<StaticArg>emptyList()); } 969 990 } 970 991 else if (_env.hasQualifiedFunction(newId)) { … … 1004 1025 return that; 1005 1026 } 1006 else { result = new VarRef(that.getSpan(), newName); } 1027 else { result = new VarRef(that.getSpan(), newName, 1028 Collections.<StaticArg>emptyList()); } 1007 1029 } 1008 1030 else if (vars.isEmpty() && !fns.isEmpty() ) { … … 1029 1051 } 1030 1052 else { 1031 result = new VarRef(name.getSpan(), name); 1053 result = new VarRef(name.getSpan(), name, 1054 Collections.<StaticArg>emptyList()); 1032 1055 } 1033 1056 // error("Unrecognized name: " + NodeUtil.nameString(name), that); … … 1047 1070 1048 1071 1049 1050 @Override1051 public Node for_RewriteObjectRef(_RewriteObjectRef that) {1052 Id obj_name = that.getObj();1053 1054 Set<Id> objs = _env.explicitTypeConsNames(obj_name);1055 if( objs.isEmpty() ) {1056 objs = _env.onDemandTypeConsNames(obj_name);1057 }1058 1059 if( objs.isEmpty() ) {1060 return that;1061 }1062 else if( objs.size() == 1 ) {1063 return new _RewriteObjectRef(that.getSpan(), IterUtil.first(objs), that.getStaticArgs());1064 }1065 else {1066 error("Name may refer to: " + NodeUtil.namesString(objs), that);1067 return that;1068 }1069 }1070 1072 1071 1073 @Override … … 1083 1085 if( !types.isEmpty() ) { 1084 1086 // create _RewriteObjectRef 1085 _RewriteObjectRef obj = new _RewriteObjectRef(that.getSpan(), fn_name, that.getStaticArgs());1087 VarRef obj = new VarRef(that.getSpan(), fn_name, that.getStaticArgs()); 1086 1088 return obj.accept(this); 1087 1089 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3145 r3146 946 946 } 947 947 948 @Override 949 public TypeCheckerResult for_RewriteObjectRefOnly(_RewriteObjectRef that, Option<TypeCheckerResult> exprType_result, 948 public TypeCheckerResult for_RewriteObjectRefOnly(VarRef that, Option<TypeCheckerResult> exprType_result, 950 949 TypeCheckerResult obj_result, 951 950 List<TypeCheckerResult> staticArgs_result) { … … 986 985 } 987 986 988 Node new_node = new _RewriteObjectRef(that.getSpan(), that.isParenthesized(),989 Option.<Type>some(t),990 (Id) obj_result.ast(),991 (List<StaticArg>) TypeCheckerResult.astFromResults(staticArgs_result));987 Node new_node = new VarRef(that.getSpan(), that.isParenthesized(), 988 Option.<Type>some(t), 989 (Id) obj_result.ast(), 990 (List<StaticArg>) TypeCheckerResult.astFromResults(staticArgs_result)); 992 991 return TypeCheckerResult.compose(new_node, t, subtypeChecker, obj_result, 993 992 TypeCheckerResult.compose(that, subtypeChecker, staticArgs_result), … … 4362 4361 4363 4362 @Override 4364 public TypeCheckerResult forVarRefOnly(VarRef that, Option<TypeCheckerResult> exprType_result, TypeCheckerResult var_result) { 4365 Option<Type> varType = var_result.type(); 4366 4367 VarRef new_node = new VarRef(that.getSpan(), 4368 varType, 4369 (Id)var_result.ast()); 4370 4371 return TypeCheckerResult.compose(new_node, varType, subtypeChecker, var_result); 4363 public TypeCheckerResult forVarRefOnly(VarRef that, 4364 Option<TypeCheckerResult> exprType_result, 4365 TypeCheckerResult var_result, 4366 List<TypeCheckerResult> staticArgs_result) { 4367 if ( NodeUtil.isSingletonObject(that) ) 4368 return for_RewriteObjectRefOnly(that, exprType_result, var_result, 4369 staticArgs_result); 4370 4371 Option<Type> varType = var_result.type(); 4372 4373 VarRef new_node = new VarRef(that.getSpan(), 4374 varType, 4375 (Id)var_result.ast(), 4376 Collections.<StaticArg>emptyList()); 4377 4378 return TypeCheckerResult.compose(new_node, varType, subtypeChecker, var_result); 4372 4379 } 4373 4380 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java
r3141 r3146 142 142 import com.sun.fortress.nodes._RewriteObjectExpr; 143 143 import com.sun.fortress.nodes._RewriteObjectExprRef; 144 import com.sun.fortress.nodes._RewriteObjectRef;145 144 import com.sun.fortress.nodes_util.ExprFactory; 146 145 import com.sun.fortress.nodes_util.NodeUtil; … … 1643 1642 1644 1643 public FValue forVarRef(VarRef x) { 1644 if ( NodeUtil.isSingletonObject(x) ) { 1645 Id name = x.getVarId(); 1646 FValue g = forIdOfTLRef(name); 1647 return applyToActualStaticArgs(g,x.getStaticArgs(),x); 1648 } 1649 1645 1650 // Id id = x.getVar(); 1646 1651 // String s= id.getText(); … … 1706 1711 } 1707 1712 1708 @Override1709 public FValue for_RewriteObjectRef(_RewriteObjectRef that) {1710 Id name = that.getObj();1711 FValue g = forIdOfTLRef(name);1712 1713 if( that.getStaticArgs().isEmpty() )1714 return g;1715 else1716 return applyToActualStaticArgs(g,that.getStaticArgs(),that);1717 }1718 1719 1713 private FValue forIdOfTLRef(Id x) { 1720 1714 FValue res = e.getValueNull(x, Environment.TOP_LEVEL); -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java
r3138 r3146 112 112 import com.sun.fortress.nodes._RewriteFnRef; 113 113 import com.sun.fortress.nodes._RewriteObjectExpr; 114 import com.sun.fortress.nodes._RewriteObjectRef;115 114 import com.sun.fortress.useful.BATree; 116 115 import com.sun.fortress.useful.BASet; … … 371 370 Expr newName(VarRef vre, String s) { 372 371 Thing t = rewrites.get(s); 373 if (t == null) { 374 noteUse(s, vre); 372 373 if ( NodeUtil.isSingletonObject(vre) ) { 374 if (t == null) { 375 return vre; 376 } else { 377 } 375 378 return vre; 376 379 } else { 377 return t.replacement(vre); 378 } 379 380 if (t == null) { 381 noteUse(s, vre); 382 return vre; 383 } else { 384 return t.replacement(vre); 385 } 386 } 380 387 } 381 388 … … 408 415 } 409 416 410 }411 412 Expr newName(_RewriteObjectRef vre, String s) {413 Thing t = rewrites.get(s);414 if (t == null) {415 return vre;416 } else {417 }418 return vre;419 417 } 420 418 … … 678 676 } 679 677 @Override 680 public Node for_RewriteObjectRef(_RewriteObjectRef vre) {681 String s = NodeUtil.stringName(vre.getObj());682 return visitNode(newName(vre, s));683 }684 @Override685 678 public Node forAmbiguousMultifixOpExpr(AmbiguousMultifixOpExpr op) { 686 679 // NEB: This code is temporary. Very soon the static end will … … 715 708 return visitNode(expr); 716 709 } 710 717 711 @Override 718 712 public Node forVarRef(VarRef vre) { 713 if ( NodeUtil.isSingletonObject(vre) ) { 714 String s = NodeUtil.stringName(vre.getVarId()); 715 return visitNode(newName(vre, s)); 716 } 717 719 718 String s = vrToString(vre); 720 719 StaticParam tp = visibleGenericParameters.get(s); … … 1104 1103 Node rewrittenExpr = visit(body); 1105 1104 1106 Expr in_fn = new VarRef(sp, NodeFactory.makeId(WellKnownNames.fortressBuiltin, WellKnownNames.thread)); 1105 Expr in_fn = new VarRef(sp, NodeFactory.makeId(WellKnownNames.fortressBuiltin, 1106 WellKnownNames.thread), 1107 Collections.<StaticArg>emptyList()); 1107 1108 List<StaticArg> args = new ArrayList<StaticArg>(); 1108 1109 args.add(new TypeArg(sp,new VarType(sp, -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/RewriteInPresenceOfTypeInfoVisitor.java
r2713 r3146 19 19 20 20 import java.util.List; 21 import java.util.Collections; 21 22 22 23 import com.sun.fortress.nodes.FnRef; … … 40 41 @Override 41 42 public Node forFnRef(FnRef fr) { 42 43 43 44 List<Id> fns = fr.getFns(); // ignore this for now. 44 45 List<StaticArg> sargs = fr.getStaticArgs(); … … 48 49 return (new _RewriteFnRef(fr.getSpan(), 49 50 fr.isParenthesized(), 50 new VarRef(idn.getSpan(), 51 idn), 51 new VarRef(idn.getSpan(), 52 idn, 53 Collections.<StaticArg>emptyList()), 52 54 sargs)).accept(this); 53 55 54 56 else { 55 57 //throw new Error("Unexpected FnRef " + fr); 56 return (new VarRef(idn.getSpan(), fr.isParenthesized(), idn)).accept(this); 58 return (new VarRef(idn.getSpan(), fr.isParenthesized(), idn, 59 Collections.<StaticArg>emptyList())).accept(this); 57 60 } 58 61 59 62 } 60 63 -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ErrorMsgMaker.java
r3133 r3146 222 222 223 223 public String forVarRef(VarRef node) { 224 return NodeUtil.nameString(node.getVarId()); 224 List<StaticArg> sargs = node.getStaticArgs(); 225 if ( NodeUtil.isSingletonObject(node) ) 226 return forId(node.getVarId()) + 227 (sargs.size() > 0 ? Useful.listInOxfords(sargs) : ""); 228 else 229 return NodeUtil.nameString(node.getVarId()); 225 230 } 226 231 … … 243 248 public String forExponentConstraint(ExponentConstraint node) { 244 249 return forOpConstraint(node, "^"); 245 }246 247 public String for_RewriteObjectRef(_RewriteObjectRef node) {248 List<StaticArg> sargs = node.getStaticArgs();249 return forId(node.getObj()) +250 (sargs.size() > 0 ? Useful.listInOxfords(sargs) : "");251 250 } 252 251 -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java
r3138 r3146 437 437 438 438 public static VarRef makeVarRef(VarRef old, int depth) { 439 return new VarRef(old.getSpan(), old.isParenthesized(), old.getVarId(), depth); 439 return new VarRef(old.getSpan(), old.isParenthesized(), old.getVarId(), 440 Collections.<StaticArg>emptyList(), 441 depth); 440 442 } 441 443 442 444 public static VarRef makeVarRef(VarRef var, Option<Type> type, Id name) { 443 return new VarRef(var.getSpan(), var.isParenthesized(), type, name); 445 return new VarRef(var.getSpan(), var.isParenthesized(), type, name, 446 Collections.<StaticArg>emptyList()); 444 447 } 445 448 446 449 public static VarRef makeVarRef(Span span, Option<Type> type, Id name) { 447 return new VarRef(span, false, type, name); 450 return new VarRef(span, false, type, name, 451 Collections.<StaticArg>emptyList()); 448 452 } 449 453 450 454 public static VarRef makeVarRef(Span span, String s) { 451 return new VarRef(span, false, NodeFactory.makeId(span, s)); 455 return new VarRef(span, false, NodeFactory.makeId(span, s), 456 Collections.<StaticArg>emptyList()); 452 457 } 453 458 454 459 public static VarRef makeVarRef(Span span, String s, int lexical_depth) { 455 return new VarRef(span, false, NodeFactory.makeId(span, s), lexical_depth); 460 return new VarRef(span, false, NodeFactory.makeId(span, s), 461 Collections.<StaticArg>emptyList(), 462 lexical_depth); 456 463 } 457 464 … … 465 472 466 473 public static VarRef makeVarRef(Span sp, Id id) { 467 return new VarRef(sp, false, id );474 return new VarRef(sp, false, id, Collections.<StaticArg>emptyList()); 468 475 } 469 476 470 477 public static VarRef makeVarRef(Span sp, Id id, Option<Type> type) { 471 return new VarRef(sp, false, type, id );478 return new VarRef(sp, false, type, id, Collections.<StaticArg>emptyList()); 472 479 } 473 480 474 481 public static VarRef makeVarRef(Id id) { 475 return new VarRef(id.getSpan(), false, id); 482 return new VarRef(id.getSpan(), false, id, 483 Collections.<StaticArg>emptyList()); 476 484 } 477 485 478 486 public static VarRef makeVarRef(Iterable<Id> apiIds, Id name) { 479 487 Id qName = NodeFactory.makeId(apiIds, name); 480 return new VarRef(qName.getSpan(), false, qName); 488 return new VarRef(qName.getSpan(), false, qName, 489 Collections.<StaticArg>emptyList()); 481 490 } 482 491 483 492 public static VarRef makeVarRef(Span span, Iterable<Id> apiIds, Id name) { 484 493 Id qName = NodeFactory.makeId(span, apiIds, name); 485 return new VarRef(span, false, qName); 494 return new VarRef(span, false, qName, 495 Collections.<StaticArg>emptyList()); 486 496 } 487 497 … … 489 499 public static VarRef makeVarRef(Iterable<Id> ids) { 490 500 Id qName = NodeFactory.makeId(ids); 491 return new VarRef(qName.getSpan(), false, qName); 501 return new VarRef(qName.getSpan(), false, qName, 502 Collections.<StaticArg>emptyList()); 492 503 } 493 504 494 505 public static VarRef makeVarRef(APIName api, Id name) { 495 506 Id qName = NodeFactory.makeId(api, name); 496 return new VarRef(qName.getSpan(), false, qName); 507 return new VarRef(qName.getSpan(), false, qName, 508 Collections.<StaticArg>emptyList()); 497 509 } 498 510 … … 705 717 return new _RewriteFnApp(that.getSpan(),true,that.getFunction(),that.getArgument()); 706 718 } 707 @Override708 public Expr for_RewriteObjectRef(_RewriteObjectRef that) {709 return new _RewriteObjectRef(that.getSpan(),true,that.getObj(),that.getStaticArgs());710 }711 719 public Expr forAsExpr(AsExpr e) { 712 720 return new AsExpr(e.getSpan(), true, e.getExpr(), e.getAnnType()); … … 842 850 } 843 851 public Expr forVarRef(VarRef e) { 844 return new VarRef(e.getSpan(), true, e.getVarId()); 852 return new VarRef(e.getSpan(), true, e.getVarId(), 853 e.getStaticArgs()); 845 854 } 846 855 public Expr forArrayComprehension(ArrayComprehension e) { … … 988 997 989 998 public static TemplateGapFnExpr makeTemplateGapFnExpr(Span s, Id id, List<Id> params) { 990 Expr body = new VarRef(id.getSpan(), id); 999 Expr body = new VarRef(id.getSpan(), id, 1000 Collections.<StaticArg>emptyList()); 991 1001 return new TemplateGapFnExpr(s, id, params); 992 1002 } … … 1033 1043 1034 1044 public static Expr make_RewriteObjectRef(boolean parenthesized, Id in_obj, List<StaticArg> static_args) { 1035 return new _RewriteObjectRef(in_obj.getSpan(), parenthesized, in_obj, static_args);1045 return new VarRef(in_obj.getSpan(), parenthesized, in_obj, static_args); 1036 1046 } 1037 1047 -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java
r3144 r3146 166 166 else if (def instanceof FnExpr) { return Option.some(((FnExpr)def).getBody()); } 167 167 else { return Option.none(); } 168 } 169 170 public static boolean isSingletonObject(VarRef v) { 171 return (! v.getStaticArgs().isEmpty()); 168 172 } 169 173 -
trunk/ProjectFortress/src/com/sun/fortress/parser/Expression.rats
r3132 r3146 110 110 } 111 111 / a1:QualifiedName 112 { yyValue = new VarRef(createSpan(yyStart,yyCount), false, a1); }; 112 { yyValue = new VarRef(createSpan(yyStart,yyCount), false, a1, 113 Collections.<StaticArg>emptyList()); }; 113 114 114 115 constant transient Action<Expr> AssignLeftTail = … … 439 440 / a1:Id a2:StaticArgs? 440 441 { if (a2 == null) 441 yyValue = new VarRef(createSpan(yyStart,yyCount),false,a1); 442 yyValue = new VarRef(createSpan(yyStart,yyCount),false,a1, 443 Collections.<StaticArg>emptyList()); 442 444 else yyValue = ExprFactory.makeFnRef(createSpan(yyStart,yyCount),a1,a2); 443 445 }; -
trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/phases/Transform.java
r3142 r3146 116 116 Id var_result = syntaxEnvironment.lookup(that.getVarId()); 117 117 Debug.debug(Debug.Type.SYNTAX, 2, "Looking up var ref " + that.getVarId() + " in hygiene environment = " + var_result); 118 return forVarRefOnly(that, exprType_result, var_result );118 return forVarRefOnly(that, exprType_result, var_result, that.getStaticArgs()); 119 119 } 120 120 -
trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java
r3145 r3146 1641 1641 1642 1642 @Override public String forVarRefOnly(VarRef that, Option<String> exprType_result, 1643 String var_result) { 1644 return handleParen( var_result, 1645 that.isParenthesized() ); 1646 } 1647 1648 @Override public String for_RewriteObjectRefOnly(_RewriteObjectRef that, Option<String> exprType_result, 1649 String obj_result, 1650 List<String> staticArgs_result) { 1651 StringBuilder s = new StringBuilder(); 1652 1653 s.append( obj_result ); 1654 inOxfordBrackets(s, staticArgs_result); 1655 1656 return handleParen( s.toString(), 1657 that.isParenthesized() ); 1643 String var_result, 1644 List<String> staticArgs_result) { 1645 if ( NodeUtil.isSingletonObject( that ) ) { 1646 StringBuilder s = new StringBuilder(); 1647 1648 s.append( var_result ); 1649 inOxfordBrackets(s, staticArgs_result); 1650 1651 return handleParen( s.toString(), 1652 that.isParenthesized() ); 1653 } else 1654 return handleParen( var_result, 1655 that.isParenthesized() ); 1658 1656 } 1659 1657

