Changeset 3146

Show
Ignore:
Timestamp:
12/04/08 07:22:05 (12 months ago)
Author:
sukyoungryu
Message:

[ast refactoring] Merged _RewriteObjectRef and VarRef?.

Location:
trunk/ProjectFortress
Files:
13 modified

Legend:

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

    r3145 r3146  
    992992                         * Primary ::= self 
    993993                         * e.g.) length 
    994                          */ 
    995                         VarRef(Id varId, int lexicalDepth=-2147483648) implements Lhs; 
    996                         /** 
     994                         * 
     995                         * <staticArgs> 
    997996                         * A reference to a singleton object. Created at typechecking or disambiguation-time. 
    998997                         * Necessary because object references are initially parsed as FnRefs. 
     
    10011000                         * object Foo[\T\] ... end 
    10021001                         */ 
    1003                         _RewriteObjectRef(Id obj, List<StaticArg> staticArgs); 
     1002                        VarRef(Id varId, 
     1003                               List<StaticArg> staticArgs, 
     1004                               int lexicalDepth=-2147483648) implements Lhs; 
    10041005                        /** 
    10051006                         * Temporarily, until closure conversion is always on-line, 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java

    r3123 r3146  
    498498    @Override 
    499499    public Node forVarRefOnly(VarRef that, Option<Type> exprType_result, 
    500                               Id varResult) { 
     500                              Id varResult, List<StaticArg> staticArg_result) { 
    501501        // After disambiguation, the Id in a VarRef should have an empty API. 
    502502        assert(varResult.getApiName().isNone()); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java

    r3138 r3146  
    7272import com.sun.fortress.nodes.OpRef; 
    7373import com.sun.fortress.nodes.Param; 
     74import com.sun.fortress.nodes.StaticArg; 
    7475import com.sun.fortress.nodes.StaticParam; 
    7576import com.sun.fortress.nodes.TaggedDimType; 
     
    8788import com.sun.fortress.nodes.VoidLiteralExpr; 
    8889import com.sun.fortress.nodes.While; 
    89 import com.sun.fortress.nodes._RewriteObjectRef; 
    9090import com.sun.fortress.nodes_util.ExprFactory; 
    9191import com.sun.fortress.nodes_util.NodeFactory; 
     
    949949    @Override public Node forVarRef(VarRef that) { 
    950950        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 
    951971        Option<APIName> api = name.getApiName(); 
    952972        ConsList<Id> fields = ConsList.empty(); 
     
    966986                        return that; 
    967987                    } 
    968                     else { result = new VarRef(newId.getSpan(), newId); } 
     988                    else { result = new VarRef(newId.getSpan(), newId, 
     989                                               Collections.<StaticArg>emptyList()); } 
    969990                } 
    970991                else if (_env.hasQualifiedFunction(newId)) { 
     
    10041025                    return that; 
    10051026                } 
    1006                 else { result = new VarRef(that.getSpan(), newName); } 
     1027                else { result = new VarRef(that.getSpan(), newName, 
     1028                                           Collections.<StaticArg>emptyList()); } 
    10071029            } 
    10081030            else if (vars.isEmpty() && !fns.isEmpty() ) { 
     
    10291051                } 
    10301052                else { 
    1031                     result = new VarRef(name.getSpan(), name); 
     1053                    result = new VarRef(name.getSpan(), name, 
     1054                                        Collections.<StaticArg>emptyList()); 
    10321055                } 
    10331056                // error("Unrecognized name: " + NodeUtil.nameString(name), that); 
     
    10471070 
    10481071 
    1049  
    1050     @Override 
    1051         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     } 
    10701072 
    10711073    @Override 
     
    10831085            if( !types.isEmpty() ) { 
    10841086                // create _RewriteObjectRef 
    1085                 _RewriteObjectRef obj = new _RewriteObjectRef(that.getSpan(), fn_name, that.getStaticArgs()); 
     1087                VarRef obj = new VarRef(that.getSpan(), fn_name, that.getStaticArgs()); 
    10861088                return obj.accept(this); 
    10871089            } 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3145 r3146  
    946946        } 
    947947 
    948         @Override 
    949         public TypeCheckerResult for_RewriteObjectRefOnly(_RewriteObjectRef that, Option<TypeCheckerResult> exprType_result, 
     948        public TypeCheckerResult for_RewriteObjectRefOnly(VarRef that, Option<TypeCheckerResult> exprType_result, 
    950949                                                          TypeCheckerResult obj_result, 
    951950                                                          List<TypeCheckerResult> staticArgs_result) { 
     
    986985            } 
    987986 
    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)); 
    992991            return TypeCheckerResult.compose(new_node, t, subtypeChecker, obj_result, 
    993992                                             TypeCheckerResult.compose(that, subtypeChecker, staticArgs_result), 
     
    43624361 
    43634362        @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); 
    43724379        } 
    43734380 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java

    r3141 r3146  
    142142import com.sun.fortress.nodes._RewriteObjectExpr; 
    143143import com.sun.fortress.nodes._RewriteObjectExprRef; 
    144 import com.sun.fortress.nodes._RewriteObjectRef; 
    145144import com.sun.fortress.nodes_util.ExprFactory; 
    146145import com.sun.fortress.nodes_util.NodeUtil; 
     
    16431642 
    16441643    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 
    16451650//        Id id = x.getVar(); 
    16461651//        String s= id.getText(); 
     
    17061711    } 
    17071712 
    1708     @Override 
    1709     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         else 
    1716             return applyToActualStaticArgs(g,that.getStaticArgs(),that); 
    1717     } 
    1718  
    17191713    private FValue forIdOfTLRef(Id x) { 
    17201714        FValue res = e.getValueNull(x, Environment.TOP_LEVEL); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java

    r3138 r3146  
    112112import com.sun.fortress.nodes._RewriteFnRef; 
    113113import com.sun.fortress.nodes._RewriteObjectExpr; 
    114 import com.sun.fortress.nodes._RewriteObjectRef; 
    115114import com.sun.fortress.useful.BATree; 
    116115import com.sun.fortress.useful.BASet; 
     
    371370    Expr newName(VarRef vre, String s) { 
    372371        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            } 
    375378            return vre; 
    376379        } 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        } 
    380387    } 
    381388 
     
    408415        } 
    409416 
    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; 
    419417    } 
    420418 
     
    678676    } 
    679677    @Override 
    680     public Node for_RewriteObjectRef(_RewriteObjectRef vre) { 
    681         String s = NodeUtil.stringName(vre.getObj()); 
    682         return visitNode(newName(vre, s)); 
    683     } 
    684     @Override 
    685678    public Node forAmbiguousMultifixOpExpr(AmbiguousMultifixOpExpr op) { 
    686679     // NEB: This code is temporary. Very soon the static end will 
     
    715708        return visitNode(expr); 
    716709    } 
     710 
    717711    @Override 
    718712    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 
    719718        String s = vrToString(vre); 
    720719        StaticParam tp = visibleGenericParameters.get(s); 
     
    11041103        Node rewrittenExpr =  visit(body); 
    11051104 
    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()); 
    11071108        List<StaticArg> args = new ArrayList<StaticArg>(); 
    11081109        args.add(new TypeArg(sp,new VarType(sp, 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/RewriteInPresenceOfTypeInfoVisitor.java

    r2713 r3146  
    1919 
    2020import java.util.List; 
     21import java.util.Collections; 
    2122 
    2223import com.sun.fortress.nodes.FnRef; 
     
    4041    @Override 
    4142    public Node forFnRef(FnRef fr) { 
    42          
     43 
    4344        List<Id> fns = fr.getFns(); // ignore this for now. 
    4445        List<StaticArg> sargs = fr.getStaticArgs(); 
     
    4849            return (new _RewriteFnRef(fr.getSpan(), 
    4950                fr.isParenthesized(), 
    50                                            new VarRef(idn.getSpan(), 
    51                                                       idn), 
     51                                      new VarRef(idn.getSpan(), 
     52                                                 idn, 
     53                                                 Collections.<StaticArg>emptyList()), 
    5254                sargs)).accept(this); 
    5355 
    5456        else { 
    5557            //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); 
    5760        } 
    58          
     61 
    5962    } 
    6063 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ErrorMsgMaker.java

    r3133 r3146  
    222222 
    223223    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()); 
    225230    } 
    226231 
     
    243248    public String forExponentConstraint(ExponentConstraint node) { 
    244249        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) : ""); 
    251250    } 
    252251 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r3138 r3146  
    437437 
    438438    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); 
    440442    } 
    441443 
    442444    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()); 
    444447    } 
    445448 
    446449    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()); 
    448452    } 
    449453 
    450454    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()); 
    452457    } 
    453458 
    454459    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); 
    456463    } 
    457464 
     
    465472 
    466473    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()); 
    468475    } 
    469476 
    470477    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()); 
    472479    } 
    473480 
    474481    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()); 
    476484    } 
    477485 
    478486    public static VarRef makeVarRef(Iterable<Id> apiIds, Id name) { 
    479487        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()); 
    481490    } 
    482491 
    483492    public static VarRef makeVarRef(Span span, Iterable<Id> apiIds, Id name) { 
    484493        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()); 
    486496    } 
    487497 
     
    489499    public static VarRef makeVarRef(Iterable<Id> ids) { 
    490500        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()); 
    492503    } 
    493504 
    494505    public static VarRef makeVarRef(APIName api, Id name) { 
    495506        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()); 
    497509    } 
    498510 
     
    705717                return new _RewriteFnApp(that.getSpan(),true,that.getFunction(),that.getArgument()); 
    706718            } 
    707         @Override 
    708             public Expr for_RewriteObjectRef(_RewriteObjectRef that) { 
    709                 return new _RewriteObjectRef(that.getSpan(),true,that.getObj(),that.getStaticArgs()); 
    710             } 
    711719        public Expr forAsExpr(AsExpr e) { 
    712720            return new AsExpr(e.getSpan(), true, e.getExpr(), e.getAnnType()); 
     
    842850        } 
    843851        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()); 
    845854        } 
    846855        public Expr forArrayComprehension(ArrayComprehension e) { 
     
    988997 
    989998    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()); 
    9911001        return new TemplateGapFnExpr(s, id, params); 
    9921002    } 
     
    10331043 
    10341044    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); 
    10361046    } 
    10371047 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java

    r3144 r3146  
    166166        else if (def instanceof FnExpr) { return Option.some(((FnExpr)def).getBody()); } 
    167167        else { return Option.none(); } 
     168    } 
     169 
     170    public static boolean isSingletonObject(VarRef v) { 
     171        return (! v.getStaticArgs().isEmpty()); 
    168172    } 
    169173 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/Expression.rats

    r3132 r3146  
    110110     } 
    111111   / a1:QualifiedName 
    112      { yyValue = new VarRef(createSpan(yyStart,yyCount), false, a1); }; 
     112     { yyValue = new VarRef(createSpan(yyStart,yyCount), false, a1, 
     113                            Collections.<StaticArg>emptyList()); }; 
    113114 
    114115constant transient Action<Expr> AssignLeftTail = 
     
    439440   / a1:Id a2:StaticArgs? 
    440441     { 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()); 
    442444       else yyValue = ExprFactory.makeFnRef(createSpan(yyStart,yyCount),a1,a2); 
    443445     }; 
  • trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/phases/Transform.java

    r3142 r3146  
    116116        Id var_result = syntaxEnvironment.lookup(that.getVarId()); 
    117117        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()); 
    119119    } 
    120120 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r3145 r3146  
    16411641 
    16421642    @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() ); 
    16581656    } 
    16591657