Changeset 3101

Show
Ignore:
Timestamp:
11/25/08 10:43:53 (12 months ago)
Author:
sukyoungryu
Message:

[ast refactoring] Eliminated nodes that extended concrete classes: _RewriteAssignment, _RewriteInstantiatedFnRefs, _RewriteInstantiatedOpRefs, and _RewriteCaseClause

Location:
trunk/ProjectFortress
Files:
6 modified

Legend:

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

    r3100 r3101  
    693693             * AssignOp ::= := | Op= 
    694694             * e.g.) x += 1 
    695              */ 
    696             Assignment(List<Lhs> lhs, Option<OpRef> opr, Expr rhs); 
    697                 /** 
    698                  * An assignment that has passed typechecking, and uses an operator. 
    699                  * Because different static args can be inferred for each Lhs assignment 
    700                  * opr, this node gives a separate OpRef for each Lhs. 
    701                  */ 
    702                 _RewriteAssignment(List<OpRef> opsForLhs); 
     695             * 
     696             * <opsForLhs> 
     697             * An assignment that has passed typechecking, and uses an operator. 
     698             * Because different static args can be inferred for each Lhs assignment 
     699             * opr, this node gives a separate OpRef for each Lhs. 
     700             */ 
     701            Assignment(List<Lhs> lhs, Option<OpRef> opr, Expr rhs, 
     702                       Option<List<OpRef>> opsForLhs = Option.<List<OpRef>>none()); 
    703703            /** 
    704704             * sequence of block elements implicitly enclosed by do/end 
     
    10871087                         * Primary ::= Id[\StaticArgList\] 
    10881088                         * e.g.) identity[\String\] 
     1089                         * 
     1090                         * <overloadings> 
     1091                         * A list of FnRefs used for infering static arguments. Used only between the two 
     1092                         * passes of the typechecker. Indicates that one of these FnRefs, which each have 
     1093                         * different instantiations of static arguments, should be the correct instantiation. 
    10891094                         */ 
    10901095                        FnRef(Id originalName, 
    1091                               List<Id> fns = Collections.<Id>singletonList(in_originalName)); 
    1092                             /** 
    1093                              * A list of FnRefs used for infering static arguments. Used only between the two 
    1094                              * passes of the typechecker. Indicates that one of these FnRefs, which each have 
    1095                              * different instantiations of static arguments, should be the correct instantiation. 
    1096                              */ 
    1097                             _RewriteInstantiatedFnRefs(List<_RewriteFnRefOverloading> overloadings 
    1098                                                            = Collections.<_RewriteFnRefOverloading>emptyList()); 
     1096                              List<Id> fns = Collections.<Id>singletonList(in_originalName), 
     1097                              Option<List<_RewriteFnRefOverloading>> overloadings 
     1098                                  = Option.<List<_RewriteFnRefOverloading>>none()); 
    10991099                        /** 
    11001100                         * operator name with (inferred) static instantiations 
     
    11021102                         * Primary ::= Op[\StaticArgList\] 
    11031103                         * e.g.) +[\String\] 
     1104                         * 
     1105                         * <overloadings> 
     1106                         * Similar to FnRef, this node is used for inferring static 
     1107                         * arguments to an Op call. This node only exists between the first and second 
     1108                         * passes of the typechecker. Holds several different instantiations of static args, 
     1109                         * one of which may be the correct insantiation. 
    11041110                         */ 
    11051111                        OpRef(OpName originalName, 
    1106                               List<OpName> ops = Collections.<OpName>singletonList(in_originalName)); 
    1107                             /** 
    1108                              * Similar to _RewriteInstantiatedFnRefs, this node is used for inferring static 
    1109                              * arguments to an Op call. This node only exists between the first and second 
    1110                              * passes of the typechecker. Holds several different instantiations of static args, 
    1111                              * one of which may be the correct insantiation. 
    1112                              */ 
    1113                             _RewriteInstantiatedOpRefs(List<_RewriteOpRefOverloading> overloadings = Collections.<_RewriteOpRefOverloading>emptyList()); 
     1112                              List<OpName> ops = Collections.<OpName>singletonList(in_originalName), 
     1113                              Option<List<_RewriteOpRefOverloading>> overloadings 
     1114                                  = Option.<List<_RewriteOpRefOverloading>>none()); 
    11141115                    /** 
    11151116                     * juxtaposition of expressions 
     
    19781979         * CaseClause ::= Expr => BlockElems 
    19791980         * e.g.) { Jupiter, Saturn, Uranus, Neptune } => "outer" 
    1980          */ 
    1981         CaseClause(Expr match, Block body); 
    1982             /** 
    1983              * A rewritten case clause that includes the operator that is used for this 
    1984              * particular case. Created in typechecking, because different ops can be 
    1985              * chosen for different clauses. 
    1986              */ 
    1987             _RewriteCaseClause(OpRef op); 
     1981         * 
     1982         * <op> 
     1983         * the operator that is used for this particular case. 
     1984         * Created in typechecking, 
     1985         * because different ops can be chosen for different clauses. 
     1986         */ 
     1987        CaseClause(Expr match, Block body, 
     1988                   Option<OpRef> op = Option.<OpRef>none()); 
    19881989        /** 
    19891990         * catch clause used in try expressions 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/OverloadRewriteVisitor.java

    r3092 r3101  
    3737    @Override 
    3838    public Node forFnRefOnly(FnRef that, Option<Type> exprType_result, 
    39             List<StaticArg> staticArgs, Id originalName, List<Id> fns) { 
     39                             List<StaticArg> staticArgs, Id originalName, List<Id> fns, 
     40                             Option<List<_RewriteFnRefOverloading>> overloadings) { 
    4041        if (fns.size() > 1) { 
    4142            Collections.<Id>sort(fns, NodeComparator.idComparer); 
     
    5758            fns = Collections.unmodifiableList(Collections.singletonList(overloadingId)); 
    5859        } 
    59         return super.forFnRefOnly(that, exprType_result, staticArgs , originalName, fns); 
     60        return super.forFnRefOnly(that, exprType_result, staticArgs , originalName, fns, 
     61                                  overloadings); 
    6062    } 
    6163 
     
    6365    @Override 
    6466    public Node forOpRefOnly(OpRef that, Option<Type> exprType_result, 
    65             List<StaticArg> staticArgs, OpName originalName, List<OpName> ops) { 
     67                             List<StaticArg> staticArgs, OpName originalName, List<OpName> ops, 
     68                             Option<List<_RewriteOpRefOverloading>> overloadings) { 
    6669        if (ops.size() > 1) { 
    6770            Collections.<OpName>sort(ops, NodeComparator.opNameComparer); 
     
    8386            ops = Collections.unmodifiableList(Collections.singletonList(overloadingOpName)); 
    8487        } 
    85         return super.forOpRefOnly(that, exprType_result, staticArgs, originalName, ops); 
     88        return super.forOpRefOnly(that, exprType_result, staticArgs, originalName, ops, 
     89                                  overloadings); 
    8690    } 
    8791 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/DesugaringVisitor.java

    r3098 r3101  
    518518    public Node forFnRefOnly(FnRef that, Option<Type> exprType_result, 
    519519                             List<StaticArg> staticArgs_result, 
    520                              Id fnResult, List<Id> fns_result) { 
     520                             Id fnResult, List<Id> fns_result, 
     521                             Option<List<_RewriteFnRefOverloading>> overloadings_result) { 
    521522        // After disambiguation, the Id in a FnRef should have an empty API. 
    522523        assert(fnResult.getApi().isNone()); 
     
    530531            return ExprFactory.makeFnRef(that, exprType_result, 
    531532                                         mangleName(fnResult), newFns, 
    532                                          staticArgs_result); 
     533                                         staticArgs_result, overloadings_result); 
    533534        } else { 
    534535            return that; 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3099 r3101  
    861861                TypeCheckerResult arg_result = recur(that.getArgument()); 
    862862 
    863                 if( postInference && that.getFunction() instanceof _RewriteInstantiatedFnRefs ) { 
     863                if( postInference && that.getFunction() instanceof FnRef && 
     864                    ((FnRef)that.getFunction()).getOverloadings().isSome() ) { 
     865                    FnRef fns = (FnRef)that.getFunction(); 
    864866                        // if we have finished typechecking, and we have encountered a reference to an overloaded function 
    865                         _RewriteInstantiatedFnRefs fns = (_RewriteInstantiatedFnRefs)that.getFunction(); 
    866867 
    867868                        if( !arg_result.isSuccessful() ) { 
     
    870871 
    871872                        Type arg_type = arg_result.type().unwrap(); 
    872                         TypeCheckerResult fn_result = findStaticallyMostApplicableFn(destructFnOverloadings(fns.getOverloadings()), arg_type, fns, fns.getOriginalName()); 
     873                        TypeCheckerResult fn_result = findStaticallyMostApplicableFn(destructFnOverloadings(fns.getOverloadings().unwrap()), 
     874                                                                                     arg_type, fns, fns.getOriginalName()); 
    873875                        // Now just check the rewritten expression by the normal means 
    874876                        return for_RewriteFnAppOnly(that,Option.<TypeCheckerResult>none(), fn_result, arg_result); 
     
    876878                else { 
    877879                        // Add constraints from the arguments, since they may affect overloading choice 
    878                         TypeCheckerResult fn_result = recur(that.getFunction()); 
     880                    TypeCheckerResult fn_result = recur(that.getFunction()); 
    879881                        Iterable<ConstraintFormula> arg_constraint = Collections.singletonList(arg_result.getNodeConstraints()); 
    880882                        //debugging 
     
    12761278        @Override 
    12771279        public TypeCheckerResult forAssignment(Assignment that) { 
     1280            if ( that.getOpsForLhs().isSome() ) // postInference pass 
     1281                return for_Assignment( that ); 
     1282 
    12781283                Pair<List<Type>, TypeCheckerResult> tuple_types_ = requireTupleType(that.getRhs(), that.getLhs().size()); 
    12791284 
     
    13031308                Assignment new_node; 
    13041309                if( that.getOpr().isSome() ) { 
    1305                         // Create a _RewriteAssignment, with an OpRef for each LHS 
    1306                         new_node = new _RewriteAssignment(that.getSpan(), 
    1307                                         that.isParenthesized(), 
    1308                                         Option.<Type>some(Types.VOID), 
    1309                                         (List<Lhs>)TypeCheckerResult.astFromResults(lhs_results), 
    1310                                         that.getOpr(), 
    1311                                         (Expr)rhs_result.ast(), 
    1312                                         op_refs); 
     1310                        // Create a new Assignment, with an OpRef for each LHS 
     1311                        new_node = new Assignment(that.getSpan(), 
     1312                                                  that.isParenthesized(), 
     1313                                                  Option.<Type>some(Types.VOID), 
     1314                                                  (List<Lhs>)TypeCheckerResult.astFromResults(lhs_results), 
     1315                                                  that.getOpr(), 
     1316                                                  (Expr)rhs_result.ast(), 
     1317                                                  Option.<List<OpRef>>some(op_refs)); 
    13131318                } 
    13141319                else { 
     
    13221327                } 
    13231328                // This case could not result in open constraints: If there is an OpRef, this must not be 
    1324                 // the postInference pass, because _RewriteAssignmentNodes should exist instead. If there is 
     1329                // the postInference pass, because AssignmentNodes should exist instead. If there is 
    13251330                // no OpRef, then no open constraints can be created. 
    13261331                return TypeCheckerResult.compose(new_node, Types.VOID, subtypeChecker, rhs_result, 
     
    13281333        } 
    13291334 
    1330  
    1331         @Override 
    1332         public TypeCheckerResult for_RewriteAssignment(_RewriteAssignment that) { 
     1335        private TypeCheckerResult for_Assignment(Assignment that) { 
    13331336                Pair<List<Type>, TypeCheckerResult> tuple_types_ = requireTupleType(that.getRhs(), that.getLhs().size()); 
    13341337 
     
    13561359                }; 
    13571360 
    1358                 // Create a _RewriteAssignment, with an OpRef for each LHS 
    1359                 Assignment new_node = new _RewriteAssignment(that.getSpan(), 
    1360                                 that.isParenthesized(), 
    1361                                 Option.<Type>some(Types.VOID), 
    1362                                 (List<Lhs>)TypeCheckerResult.astFromResults(lhs_results), 
    1363                                 that.getOpr(), 
    1364                                 (Expr)rhs_result.ast(), 
    1365                                 op_refs); 
     1361                // Create a Assignment, with an OpRef for each LHS 
     1362                Assignment new_node = new Assignment(that.getSpan(), 
     1363                                                     that.isParenthesized(), 
     1364                                                     Option.<Type>some(Types.VOID), 
     1365                                                     (List<Lhs>)TypeCheckerResult.astFromResults(lhs_results), 
     1366                                                     that.getOpr(), 
     1367                                                     (Expr)rhs_result.ast(), 
     1368                                                     Option.<List<OpRef>>some(op_refs)); 
    13661369 
    13671370                TypeCheckerResult result = TypeCheckerResult.compose(new_node, Types.VOID, subtypeChecker, rhs_result, 
     
    13721375                if( postInference && TypesUtil.containsInferenceVarTypes(new_node) ) { 
    13731376                        Pair<Boolean,Node> temp = TypesUtil.closeConstraints(new_node, result); 
    1374                         new_node = (_RewriteAssignment)temp.second(); 
     1377                        new_node = (Assignment)temp.second(); 
    13751378                        if(!temp.first()){ 
    13761379                                String err = "No overloading for " + that.getOpr().unwrap(); 
     
    15151518                // Find the arrow type of the opr, if it is some 
    15161519                Option<TypeCheckerResult> opr_type = (new NodeDepthFirstVisitor<TypeCheckerResult>() { 
    1517                         @Override public TypeCheckerResult for_RewriteInstantiatedOpRefs(_RewriteInstantiatedOpRefs that) { 
     1520                        @Override public TypeCheckerResult forOpRef(OpRef that) { 
     1521                            if ( that.getOverloadings().isSome() ) { 
    15181522                                Type args_type = NodeFactory.makeTupleType(Useful.list(arg_type, rhs_type)); 
    1519                                 return findStaticallyMostApplicableFn(TypeChecker.destructOpOverLoading(that.getOverloadings()), args_type, that, that.getOriginalName()); 
    1520                         } 
    1521                         @Override public TypeCheckerResult forOpRef(OpRef that) { 
     1523                                return findStaticallyMostApplicableFn(TypeChecker.destructOpOverLoading(that.getOverloadings().unwrap()), args_type, that, that.getOriginalName()); 
     1524                            } 
     1525 
    15221526                                TypeCheckerResult op_result = TypeChecker.this.recur(that); 
    15231527                                if( !op_result.isSuccessful() ) return op_result; 
     
    16481652                                TypeCheckerResult match_result = that.getMatch().accept(TypeChecker.this); 
    16491653                                TypeCheckerResult body_result = that.getBody().accept(TypeChecker.this); 
    1650                                 CaseClause new_node = new CaseClause(that.getSpan(), (Expr)match_result.ast(), (Block)body_result.ast()); 
    1651                                 return Triple.make(new_node, match_result, body_result); 
    1652                         } 
    1653  
    1654                         @Override 
    1655                         public Triple<CaseClause, TypeCheckerResult, TypeCheckerResult> for_RewriteCaseClause(_RewriteCaseClause that) { 
    1656                                 TypeCheckerResult match_result = that.getMatch().accept(TypeChecker.this); 
    1657                                 TypeCheckerResult body_result = that.getBody().accept(TypeChecker.this); 
    1658                                 _RewriteCaseClause new_node = new _RewriteCaseClause(that.getSpan(), (Expr)match_result.ast(), (Block)body_result.ast(), that.getOp()); 
     1654                                CaseClause new_node = new CaseClause(that.getSpan(), (Expr)match_result.ast(), (Block)body_result.ast(), 
     1655                                                                     that.getOp()); 
    16591656                                return Triple.<CaseClause,TypeCheckerResult,TypeCheckerResult>make(new_node, match_result, body_result); 
    16601657                        } 
     
    17221719 
    17231720                        if( postInference ) { 
    1724                                 // after inference, the case clause had better be a _RewriteCaseClause. 
    1725                                 if( !(clause instanceof _RewriteCaseClause) ) return bug("All case clauses should be rewritten to reflect the chosen compare op."); 
    1726  
    1727                                 _RewriteCaseClause rclause = (_RewriteCaseClause)clause; 
    1728                                 Pair<Type, TypeCheckerResult> p = for_RewriteCaseClauseGetType(rclause, param_result_); 
     1721                                // after inference, the case clause had better have the op field set 
     1722                            if( clause.getOp().isNone() ) 
     1723                                    return bug("All case clauses should be rewritten to reflect the chosen compare op."); 
     1724 
     1725                                Pair<Type, TypeCheckerResult> p = for_CaseClauseGetType(clause, param_result_); 
    17291726                                clause_results.add(p.second()); 
    17301727                                clause_types.add(p.first()); 
     
    17321729                        else { 
    17331730                                // during inference, we'll try to apply the given compare op (if there is one) and otherwise try 
    1734                                 // equals and in. We will remake the CaseClasue as a _RewriteCaseClause, with a chosen opr. 
     1731                                // equals and in. We will set the op field with a chosen opr. 
    17351732                                Pair<Type, TypeCheckerResult> p = forCaseClauseRewriteAndGetType(clause, param_result_, compare_result_, equals_result, in_result); 
    17361733                                clause_results.add(p.second()); 
     
    17751772        /** 
    17761773         * Typecheck the clause, using one of the ops (compare, equals, or in), return the type of the right-hand side block, and 
    1777          * rewrite the CaseClause as a _RewriteCaseClause. All TypeCheckerResults must contain types, and must contain the AST type 
     1774         * rewrite the CaseClause to set the op field. All TypeCheckerResults must contain types, and must contain the AST type 
    17781775         * that is reflected by their name. 
    17791776         */ 
     
    18311828                } 
    18321829                else { 
    1833                         _RewriteCaseClause new_node = new _RewriteCaseClause(clause.getSpan(), 
    1834                                         (Expr)match_result.ast(), 
    1835                                         (Block)block_result.ast(), 
    1836                                         chosen_op); 
     1830                        CaseClause new_node = new CaseClause(clause.getSpan(), 
     1831                                                             (Expr)match_result.ast(), 
     1832                                                             (Block)block_result.ast(), 
     1833                                                             Option.<OpRef>some(chosen_op)); 
    18371834                        TypeCheckerResult app_result = new TypeCheckerResult(new_node, application_result.unwrap().second()); 
    18381835                        Type app_type = application_result.unwrap().first(); 
     
    18441841        } 
    18451842        /** 
     1843         * pointInference pass 
    18461844         * Typecheck the clause AND return the type of the right-hand side. 
    18471845         */ 
    1848         private Pair<Type, TypeCheckerResult> for_RewriteCaseClauseGetType(_RewriteCaseClause clause, Option<TypeCheckerResult> param_result_) { 
     1846        private Pair<Type, TypeCheckerResult> for_CaseClauseGetType(CaseClause clause, Option<TypeCheckerResult> param_result_) { 
     1847            // after inference, the case clause had better have the op field set 
     1848            if( clause.getOp().isNone() ) 
     1849                return bug("All case clauses should be rewritten to reflect the chosen compare op."); 
     1850 
     1851            OpRef op = clause.getOp().unwrap(); 
     1852 
    18491853                TypeCheckerResult match_result = recur(clause.getMatch()); 
    18501854                TypeCheckerResult block_result = recur(clause.getBody()); 
     
    18581862                Type param_type = param_result_.unwrap().type().unwrap(); 
    18591863 
    1860                 if( clause.getOp() instanceof _RewriteInstantiatedOpRefs ) { 
     1864                if( op.getOverloadings().isSome() ) { 
    18611865                        // Our operator is an overloading, so we should find the statically most applicable one and rewrite 
    1862                         _RewriteInstantiatedOpRefs overloadings = (_RewriteInstantiatedOpRefs)clause.getOp(); 
    18631866                        Type arg_type = NodeFactory.makeTupleType(Useful.list(param_type, match_type)); 
    18641867                        TypeCheckerResult app_result_1 = 
    1865                                 findStaticallyMostApplicableFn(destructOpOverLoading(overloadings.getOverloadings()), arg_type, overloadings, overloadings.getOriginalName()); 
     1868                            findStaticallyMostApplicableFn(destructOpOverLoading(op.getOverloadings().unwrap()), 
     1869                                                           arg_type, op, op.getOriginalName()); 
    18661870 
    18671871                        if( app_result_1.isSuccessful() ) { 
     
    18711875 
    18721876                                if( app_result_2.isSome() ) { 
    1873                                         _RewriteCaseClause new_node = new _RewriteCaseClause(clause.getSpan(), 
    1874                                                         (Expr)match_result.ast(), 
    1875                                                         (Block)block_result.ast(), 
    1876                                                         (OpRef)app_result_1.ast()); 
     1877                                        CaseClause new_node = new CaseClause(clause.getSpan(), 
     1878                                                                             (Expr)match_result.ast(), 
     1879                                                                             (Block)block_result.ast(), 
     1880                                                                             Option.<OpRef>some((OpRef)app_result_1.ast())); 
    18771881                                        TypeCheckerResult app_result_3 = new TypeCheckerResult(new_node, app_result_2.unwrap().second()); 
    18781882                                        Type app_type = app_result_2.unwrap().first(); 
    18791883                                        // We still must ensure the type of the application is a Boolean 
    18801884                                        TypeCheckerResult bool_result = checkSubtype(app_type, Types.BOOLEAN, new_node, 
    1881                                                         "Result of application of " + clause.getOp() + " to param and match expression must have type boolean, but had type " + app_type + "."); 
     1885                                                                                     "Result of application of " + op + " to param and match expression must have type boolean, but had type " + app_type + "."); 
    18821886                                        return Pair.make(block_type, TypeCheckerResult.compose(new_node, subtypeChecker, bool_result, app_result_3, match_result, block_result)); 
    18831887                                } 
     
    18931897                else { 
    18941898                        // no overloading, so just do the normal thing 
    1895                         TypeCheckerResult op_result = recur(clause.getOp()); 
     1899                    TypeCheckerResult op_result = recur(op); 
    18961900                        if( !op_result.isSuccessful() ) return Pair.make(block_type, TypeCheckerResult.compose(clause, subtypeChecker, op_result)); 
    18971901                        Option<Pair<Type, ConstraintFormula>> app_result_1 = 
    18981902                                TypesUtil.applicationType(subtypeChecker, op_result.type().unwrap(), new ArgList(param_type, match_type), downwardConstraint); 
    18991903                        if( app_result_1.isSome() ) { 
    1900                                 _RewriteCaseClause new_node = new _RewriteCaseClause(clause.getSpan(), 
    1901                                                 (Expr)match_result.ast(), 
    1902                                                 (Block)block_result.ast(), 
    1903                                                 (OpRef)op_result.ast()); 
     1904                                CaseClause new_node = new CaseClause(clause.getSpan(), 
     1905                                                                     (Expr)match_result.ast(), 
     1906                                                                     (Block)block_result.ast(), 
     1907                                                                     Option.<OpRef>some((OpRef)op_result.ast())); 
    19041908                                TypeCheckerResult app_result_2 = new TypeCheckerResult(new_node, app_result_1.unwrap().second()); 
    19051909                                Type app_type = app_result_1.unwrap().first(); 
    19061910                                // We still must ensure the type of the application is a Boolean 
    19071911                                TypeCheckerResult bool_result = checkSubtype(app_type, Types.BOOLEAN, new_node, 
    1908                                                 "Result of application of " + clause.getOp() + " to param and match expression must have type boolean, but had type " + app_type + "."); 
     1912                                                                             "Result of application of " + op + " to param and match expression must have type boolean, but had type " + app_type + "."); 
    19091913                                return Pair.make(block_type, TypeCheckerResult.compose(new_node, subtypeChecker, bool_result, app_result_2, match_result, block_result)); 
    19101914                        } 
    19111915                        else { 
    19121916                                // error 
    1913                                 String err = "No overloading of the operator " + clause.getOp() + " could be found for arguments of type " + 
     1917                            String err = "No overloading of the operator " + op + " could be found for arguments of type " + 
    19141918                                param_type + " (Param Type)  and " + match_type + " (Match Type)."; 
    19151919                                TypeCheckerResult e_r = new TypeCheckerResult(clause, TypeError.make(err, clause)); 
     
    24452449        @Override 
    24462450        public TypeCheckerResult forFnRefOnly(final FnRef that, Option<TypeCheckerResult> exprType_result, 
    2447                 List<TypeCheckerResult> staticArgs_result, 
    2448                         TypeCheckerResult originalName_result, 
    2449                         List<TypeCheckerResult> fns_result) { 
     2451                                              List<TypeCheckerResult> staticArgs_result, 
     2452                                              TypeCheckerResult originalName_result, 
     2453                                              List<TypeCheckerResult> fns_result, 
     2454                                              Option<List<TypeCheckerResult>> overloadings_result) { 
    24502455 
    24512456                // Could we give a type to each of our fns? 
     
    24642469 
    24652470                // if no static args are provided, and we have several overloadings, we 
    2466                 // will create a _RewriteInstantiatedFnRef 
     2471                // will create a FnRef with the overloadings field set 
    24672472                if( that.getStaticArgs().isEmpty()  && TypesUtil.overloadingRequiresStaticArgs(overloaded_types) ) { 
    24682473                        // if there is an overloading that requires static args, and we don't have any, we'll 
     
    25192524                                                Option.<Type>some(new IntersectionType(NodeFactory.makeSetSpan("impossible", arrow_types), arrow_types)); 
    25202525                                        constraints = accumulated_constraints; 
    2521                                         new_node = new _RewriteInstantiatedFnRefs(that.getSpan(), 
    2522                                                         that.isParenthesized(), 
    2523                                                         type, 
    2524                                                          that.getStaticArgs(), 
    2525                                                          that.getLexicalDepth(), 
    2526                                                         that.getOriginalName(), 
    2527                                                         that.getFns(), 
    2528                                                          fn_overloadings); 
     2526                                        new_node = new FnRef(that.getSpan(), 
     2527                                                             that.isParenthesized(), 
     2528                                                             type, 
     2529                                                             that.getStaticArgs(), 
     2530                                                             that.getLexicalDepth(), 
     2531                                                            that.getOriginalName(), 
     2532                                                            that.getFns(), 
     2533                                                             Option.<List<_RewriteFnRefOverloading>>some(fn_overloadings)); 
    25292534                } 
    25302535                else { 
     
    35623567                List<TypeCheckerResult> args_result = recurOnListOfExpr(that.getArgs()); 
    35633568 
    3564                 if( postInference && that.getOp() instanceof _RewriteInstantiatedOpRefs ) { 
     3569                OpRef ops = that.getOp(); 
     3570 
     3571                if( postInference && ops.getOverloadings().isSome() ) { 
    35653572                        // if we have finished typechecking, and we have encountered a reference to an overloaded op 
    3566                         _RewriteInstantiatedOpRefs ops = (_RewriteInstantiatedOpRefs)that.getOp(); 
    3567  
    35683573 
    35693574                        for( TypeCheckerResult r : args_result ) { 
     
    35763581                        })); 
    35773582                        Type arg_type = NodeFactory.makeTupleType(that.getSpan(), arg_types); 
    3578                         TypeCheckerResult op_result = findStaticallyMostApplicableFn(destructOpOverLoading(ops.getOverloadings()), arg_type,ops, ops.getOriginalName()); 
     3583                        TypeCheckerResult op_result = findStaticallyMostApplicableFn(destructOpOverLoading(ops.getOverloadings().unwrap()), 
     3584                                                                                     arg_type,ops, ops.getOriginalName()); 
    35793585 
    35803586                        // Now just check the rewritten expression by the normal means 
     
    36593665        @Override 
    36603666        public TypeCheckerResult forOpRefOnly(final OpRef that, Option<TypeCheckerResult> exprType_result, 
    3661                 List<TypeCheckerResult> staticArgs_result, 
    3662                         TypeCheckerResult originalName_result, 
    3663                         List<TypeCheckerResult> ops_result) { 
     3667                                              List<TypeCheckerResult> staticArgs_result, 
     3668                                              TypeCheckerResult originalName_result, 
     3669                                              List<TypeCheckerResult> ops_result, 
     3670                                              Option<List<TypeCheckerResult>> overloadings_result) { 
    36643671                // Did all ops typecheck? 
    36653672                for( TypeCheckerResult o_r : ops_result ) { 
     
    36773684 
    36783685                // If no static args are given, but overloadings require them, we'll create a 
    3679                 // _RewriteInstantiatedOpRef. 
     3686                // OpRef with the overloading field set. 
    36803687                if( that.getStaticArgs().isEmpty() && TypesUtil.overloadingRequiresStaticArgs(overloaded_types) ) { 
    36813688                        List<_RewriteOpRefOverloading> overloadings = new ArrayList<_RewriteOpRefOverloading>(); 
     
    37303737                                        Option.<Type>none() : 
    37313738                                                Option.<Type>some(new IntersectionType(NodeFactory.makeSetSpan("impossible", arrow_types), arrow_types)); 
    3732                                         new_node = new _RewriteInstantiatedOpRefs(that.getSpan(), 
    3733                                                         that.isParenthesized(), 
    3734                                                         type, 
    3735                                                         that.getStaticArgs(), 
    3736                                                         that.getLexicalDepth(), 
    3737                                                         that.getOriginalName(), 
    3738                                                         that.getOps(), 
    3739                                                         overloadings); 
     3739                                        new_node = new OpRef(that.getSpan(), 
     3740                                                             that.isParenthesized(), 
     3741                                                             type, 
     3742                                                             that.getStaticArgs(), 
     3743                                                             that.getLexicalDepth(), 
     3744                                                             that.getOriginalName(), 
     3745                                                             that.getOps(), 
     3746                                                             Option.<List<_RewriteOpRefOverloading>>some(overloadings)); 
    37403747                                        constraints = accumulated_constraints; 
    37413748                } 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r3092 r3101  
    319319 
    320320    public static FnRef makeFnRef(FnRef that, Option<Type> ty, Id name, 
    321                                   List<Id> ids, List<StaticArg> sargs) { 
     321                                  List<Id> ids, List<StaticArg> sargs, 
     322                                  Option<List<_RewriteFnRefOverloading>> overloadings) { 
    322323        return new FnRef(that.getSpan(), that.isParenthesized(), ty, 
    323                 sargs, name, ids); 
     324                         sargs, name, ids, overloadings); 
    324325    } 
    325326 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r3099 r3101  
    11041104                                              List<String> lhs_result, 
    11051105                                              Option<String> opr_result, 
    1106                                               String rhs_result) { 
     1106                                              String rhs_result, 
     1107                                              Option<List<String>> opsForLhs_result) { 
    11071108        StringBuilder s = new StringBuilder(); 
    11081109 
     
    11171118        return handleParen( s.toString(), 
    11181119                            that.isParenthesized() ); 
    1119     } 
    1120  
    1121     @Override public String for_RewriteAssignmentOnly(_RewriteAssignment that, 
    1122                                                       Option<String> exprType_result, 
    1123                                                       List<String> lhs_result, 
    1124                                                       Option<String> opr_result, 
    1125                                                       String rhs_result, 
    1126                                                       List<String> opsForLhs_result) { 
    1127         return forAssignmentOnly(that, exprType_result, lhs_result, 
    1128                                   opr_result, rhs_result); 
    11291120    } 
    11301121 
     
    16971688                                         List<String> staticArgs_result, 
    16981689                                         String originalName_result, 
    1699                                          List<String> fns_result) { 
     1690                                         List<String> fns_result, 
     1691                                         Option<List<String>> overloadings_result) { 
    17001692        StringBuilder s = new StringBuilder(); 
    17011693 
     
    17221714                                         List<String> staticArgs_result, 
    17231715                                         String originalName_result, 
    1724                                          List<String> ops_result) { 
     1716                                         List<String> ops_result, 
     1717                                         Option<List<String>> overloadings_result) { 
    17251718        return handleParen( canonicalOp(originalName_result), 
    17261719                            that.isParenthesized() ); 
     
    17331726            _RewriteFnRefOverloading that, String fn_result, String ty_result) { 
    17341727        return "(* _RewriteFnRefOverloading *)"; 
    1735     } 
    1736  
    1737     @Override 
    1738     public String for_RewriteInstantiatedFnRefsOnly( 
    1739             _RewriteInstantiatedFnRefs that, Option<String> exprType_result, 
    1740             List<String> staticArgs_result, 
    1741             String originalName_result, List<String> fns_result, List<String> overloadings_result) { 
    1742         return "(* _RewriteInstantiatedFnRefs *)"; 
    1743     } 
    1744  
    1745     @Override 
    1746     public String for_RewriteInstantiatedOpRefsOnly( 
    1747             _RewriteInstantiatedOpRefs that, Option<String> exprType_result, 
    1748             List<String> staticArgs_result, 
    1749             String originalName_result, List<String> ops_result, List<String> overloadings_result) { 
    1750         return "(* _RewriteInstantiatedOpRefs *)"; 
    17511728    } 
    17521729 
     
    28452822    @Override public String forCaseClauseOnly(CaseClause that, 
    28462823                                              String match_result, 
    2847                                               String body_result) { 
     2824                                              String body_result, 
     2825                                              Option<String> op_result) { 
    28482826        return match_result + " => " + body_result; 
    2849     } 
    2850  
    2851     @Override public String for_RewriteCaseClauseOnly(_RewriteCaseClause that, 
    2852                                                       String match_result, 
    2853                                                       String body_result, 
    2854                                                       String op_result) { 
    2855         return forCaseClauseOnly(that, match_result, body_result); 
    28562827    } 
    28572828