Changeset 3137

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

[ast refactoring] Merged DoFront? and Block.

Location:
trunk/ProjectFortress
Files:
11 modified

Legend:

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

    r3133 r3137  
    683683                 * sequence of block elements implicitly enclosed by do/end 
    684684                 * BlockElems ::= BlockElem+ 
     685                 * DoFront ::= (at Expr)? atomic? do BlockElems? 
    685686                 * e.g.) y = x 
    686687                 *       z = 2x 
    687688                 *       y + z 
    688                  */ 
    689                 Block(List<Expr> exprs); 
     689                 * e.g.) at a.region(j) do w := a_j 
     690                 */ 
     691                Block(Option<Expr> loc = Option.<Expr>none(), 
     692                      boolean atomicBlock = false, 
     693                      boolean withinDo = false, 
     694                      List<Expr> exprs); 
     695                /** 
     696                 * do expression 
     697                 * Do ::= (DoFront also)* DoFront end 
     698                 * e.g.) do 
     699                 *         accum += treeSum(t.left) 
     700                 *       also do 
     701                 *         accum += treeSum(t.right) 
     702                 *       also do 
     703                 *         accum += t.datum 
     704                 *       end 
     705                 */ 
     706                Do(List<Block> fronts); 
    690707                /** 
    691708                 * case expression or extremum expression 
     
    706723                         Option<Block> elseClause = Option.<Block>none()); 
    707724                /** 
    708                  * do expression 
    709                  * Do ::= (DoFront also)* DoFront end 
    710                  * e.g.) do 
    711                  *         accum += treeSum(t.left) 
    712                  *       also do 
    713                  *         accum += treeSum(t.right) 
    714                  *       also do 
    715                  *         accum += t.datum 
    716                  *       end 
    717                  */ 
    718                 Do(List<DoFront> fronts); 
    719                 /** 
    720725                 * for expression 
    721726                 * DelimitedExpr ::= for GeneratorClauseList DoFront end 
     
    724729                 *       end 
    725730                 */ 
    726                 For(List<GeneratorClause> gens, DoFront body); 
     731                For(List<GeneratorClause> gens, Block body); 
    727732                /** 
    728733                 * if expression 
     
    19581963            CatchClause(BaseType matchType, Block body); 
    19591964            /** 
    1960              * block expression used in do expressions 
    1961              * DoFront ::= (at Expr)? atomic? do BlockElems? 
    1962              * e.g.) at a.region(j) do w := a_j 
    1963              */ 
    1964             DoFront(Option<Expr> loc = Option.<Expr>none(), 
    1965                     boolean atomicBlock = false, 
    1966                     Block expr); 
    1967             /** 
    19681965             * if clause used in if expressions 
    19691966             * DelimitedExpr ::= if Expr then BlockElems Elifs? Else? end 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java

    r3132 r3137  
    4242import com.sun.fortress.nodes.DimDecl; 
    4343import com.sun.fortress.nodes.Do; 
    44 import com.sun.fortress.nodes.DoFront; 
    4544import com.sun.fortress.nodes.Exit; 
    4645import com.sun.fortress.nodes.Expr; 
     
    938937        return forForOnly(that, type_result, 
    939938                          pair.first(), 
    940                           (DoFront)that.getBody().accept(new_disambiguator)); 
     939                          (Block)that.getBody().accept(new_disambiguator)); 
    941940    } 
    942941 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java

    r3136 r3137  
    16091609 
    16101610        @Override 
    1611         public TypeCheckerResult forBlockOnly(Block that, Option<TypeCheckerResult> exprType_result, List<TypeCheckerResult> exprs_result) { 
    1612                 // Type is type of last expression or void if none. 
    1613                 if ( exprs_result.isEmpty() ) { 
    1614                         Block new_node = new Block(that.getSpan(), that.isParenthesized(), Option.<Type>some(Types.VOID), Collections.<Expr>emptyList()); 
    1615                         return TypeCheckerResult.compose(new_node, Types.VOID, subtypeChecker, exprs_result); 
    1616                 } else { 
    1617                         List<TypeCheckerResult> body_void = allVoidButLast(exprs_result,that.getExprs()); 
    1618                         Option<Type> result_type = IterUtil.last(exprs_result).type(); 
    1619                         Block new_node = new Block(that.getSpan(), 
    1620                                         that.isParenthesized(), 
    1621                                         result_type, 
    1622                                         (List<Expr>)TypeCheckerResult.astFromResults(exprs_result)); 
    1623                         return TypeCheckerResult.compose(new_node, result_type, subtypeChecker, 
    1624                                         TypeCheckerResult.compose(new_node, subtypeChecker, body_void), 
    1625                                         TypeCheckerResult.compose(new_node, subtypeChecker, exprs_result)); 
    1626                 } 
    1627         } 
    1628  
    1629         @Override 
    16301611        public TypeCheckerResult forCaseExpr(CaseExpr that) { 
    16311612                Option<TypeCheckerResult> param_result = this.recurOnOptionOfExpr(that.getParam()); 
     
    20652046        } 
    20662047 
    2067         public TypeCheckerResult forDoFront(DoFront that) { 
    2068                 TypeCheckerResult bodyResult = 
    2069                         that.isAtomicBlock() ? forAtomic( 
    2070                                         that.getExpr(), 
    2071                                         errorMsg("A 'spawn' expression must not occur inside", 
    2072                                         "an 'atomic' do block.")) 
    2073                                         : that.getExpr().accept(this); 
    2074  
    2075                                         Option<TypeCheckerResult> loc_result_ = this.recurOnOptionOfExpr(that.getLoc()); 
    2076                                         TypeCheckerResult loc_result = loc_result_.isNone() ? new TypeCheckerResult(that) : 
    2077                                                 loc_result_.unwrap(); 
    2078  
    2079                                         TypeCheckerResult region_result = new TypeCheckerResult(that); 
    2080                                         if (loc_result_.isSome() && loc_result_.unwrap().type().isSome()) { 
    2081                                                 Type locType = loc_result_.unwrap().type().unwrap(); 
    2082                                                 region_result = checkSubtype(locType, 
    2083                                                                 Types.REGION, 
    2084                                                                 that.getLoc().unwrap(), 
    2085                                                                 errorMsg("Location of 'do' block must ", 
    2086                                                                                 "have type Region: ", locType)); 
    2087  
    2088                                         } 
    2089  
    2090                                         DoFront new_node = new DoFront(that.getSpan(), 
    2091                                                         (Option<Expr>)TypeCheckerResult.astFromResult(loc_result_), 
    2092                                                         that.isAtomicBlock(), 
    2093                                                         (Block)bodyResult.ast()); 
    2094                                         return TypeCheckerResult.compose(new_node, 
    2095                                                         bodyResult.type(), 
    2096                                                         subtypeChecker, 
    2097                                                         bodyResult, 
    2098                                                         loc_result, 
    2099                                                         region_result); 
     2048        public TypeCheckerResult forBlock(Block that) { 
     2049            if ( that.isAtomicBlock() ) 
     2050                return forAtomic(new Block(that.getSpan(), that.isParenthesized(), 
     2051                                                           that.getExprType(), that.getLoc(), 
     2052                                                           false, that.isWithinDo(), that.getExprs()), 
     2053                                                 errorMsg("A 'spawn' expression must not occur inside", 
     2054                                                          "an 'atomic' do block.")); 
     2055 
     2056            Option<TypeCheckerResult> loc_result_ = this.recurOnOptionOfExpr(that.getLoc()); 
     2057            TypeCheckerResult loc_result = loc_result_.isNone() ? new TypeCheckerResult(that) : 
     2058                loc_result_.unwrap(); 
     2059 
     2060            TypeCheckerResult region_result = new TypeCheckerResult(that); 
     2061            if (loc_result_.isSome() && loc_result_.unwrap().type().isSome()) { 
     2062                Type locType = loc_result_.unwrap().type().unwrap(); 
     2063                region_result = checkSubtype(locType, 
     2064                                             Types.REGION, 
     2065                                             that.getLoc().unwrap(), 
     2066                                             errorMsg("Location of 'do' block must ", 
     2067                                                      "have type Region: ", locType)); 
     2068            } 
     2069            List<TypeCheckerResult> exprs_result = this.recurOnListOfExpr(that.getExprs()); 
     2070            // Type is type of last expression or void if none. 
     2071            Option<Type> result_type; 
     2072            List<Expr> es; 
     2073            List<TypeCheckerResult> body_void; 
     2074            if ( exprs_result.isEmpty() ) { 
     2075                result_type = Option.<Type>some(Types.VOID); 
     2076                es = Collections.<Expr>emptyList(); 
     2077                body_void = Collections.<TypeCheckerResult>emptyList(); 
     2078            } else { 
     2079                result_type = IterUtil.last(exprs_result).type(); 
     2080                es = (List<Expr>)TypeCheckerResult.astFromResults(exprs_result); 
     2081                body_void = allVoidButLast(exprs_result,that.getExprs()); 
     2082            } 
     2083            Block new_node = new Block(that.getSpan(), 
     2084                                           that.isParenthesized(), 
     2085                                           result_type, 
     2086                                           (Option<Expr>)TypeCheckerResult.astFromResult(loc_result_), 
     2087                                           that.isAtomicBlock(), that.isWithinDo(), 
     2088                                           (List<Expr>)TypeCheckerResult.astFromResults(exprs_result)); 
     2089            return TypeCheckerResult.compose(new_node, 
     2090                                             result_type, 
     2091                                             subtypeChecker, 
     2092                                             TypeCheckerResult.compose(new_node, subtypeChecker, body_void), 
     2093                                             loc_result, 
     2094                                             region_result, 
     2095                                             TypeCheckerResult.compose(new_node, subtypeChecker, exprs_result)); 
    21002096        } 
    21012097 
     
    21142110                                that.isParenthesized(), 
    21152111                                some(result_type), 
    2116                                 (List<DoFront>)TypeCheckerResult.astFromResults(fronts_result)); 
     2112                                (List<Block>)TypeCheckerResult.astFromResults(fronts_result)); 
    21172113 
    21182114                return TypeCheckerResult.compose(new_node, result_type, subtypeChecker, fronts_result); 
     
    25702566                                Option.<Type>some(Types.VOID), 
    25712567                                (List<GeneratorClause>)TypeCheckerResult.astFromResults(gens_result), 
    2572                                 (DoFront)body_result.ast()); 
     2568                                (Block)body_result.ast()); 
    25732569 
    25742570                TypeCheckerResult result = TypeCheckerResult.compose(for_, subtypeChecker, body_void, body_result, 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java

    r3135 r3137  
    8888import com.sun.fortress.nodes.CharLiteralExpr; 
    8989import com.sun.fortress.nodes.Do; 
    90 import com.sun.fortress.nodes.DoFront; 
    9190import com.sun.fortress.nodes.Exit; 
    9291import com.sun.fortress.nodes.ExponentiationMI; 
     
    363362        if (s == 0) return FVoid.V; 
    364363        if (s == 1) { 
    365             DoFront f = x.getFronts().get(0); 
     364            Block f = x.getFronts().get(0); 
    366365            if (f.getLoc().isSome()) { 
    367366                Expr regionExp = f.getLoc().unwrap(); 
     
    370369            if (f.isAtomicBlock()) 
    371370                return forAtomicExpr(new AtomicExpr(x.getSpan(), false, 
    372                                                     f.getExpr())); 
    373             return f.getExpr().accept(new Evaluator(this)); 
     371                                                    f)); 
     372            return f.accept(new Evaluator(this)); 
    374373       } 
    375374 
     
    377376       List<Expr> locs = new ArrayList<Expr>(0); 
    378377       for (int i = 0; i < s; i++) { 
    379            DoFront f = x.getFronts().get(i); 
     378           Block f = x.getFronts().get(i); 
    380379           if (f.getLoc().isSome()) { 
    381380               locs.add(f.getLoc().unwrap()); 
     
    383382           if (f.isAtomicBlock()) 
    384383               tasks[i] = new TupleTask(new AtomicExpr(x.getSpan(), false, 
    385                                                        f.getExpr()), this); 
     384                                                       f), this); 
    386385           else 
    387                tasks[i] = new TupleTask(f.getExpr(), new Evaluator(this)); 
     386               tasks[i] = new TupleTask(f, new Evaluator(this)); 
    388387       } 
    389388       if (locs.size()>0) { 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java

    r3123 r3137  
    6060import com.sun.fortress.nodes.Decl; 
    6161import com.sun.fortress.nodes.Do; 
    62 import com.sun.fortress.nodes.DoFront; 
    6362import com.sun.fortress.nodes.EnsuresClause; 
    6463import com.sun.fortress.nodes.Expr; 
     
    10921091    @Override 
    10931092    public Node forFor(For f) { 
    1094         DoFront df = f.getBody(); 
     1093        Block df = f.getBody(); 
    10951094        Do doBlock = new Do(df.getSpan(),Useful.list(df)); 
    10961095        return visitLoop(f.getSpan(), f.getGens(), doBlock); 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r3132 r3137  
    577577        // Might not work; empty Do may be naughty. 
    578578        return new While(sp, makeGeneratorClause(cond.getSpan(), cond), 
    579                 new Do(sp, Collections.<DoFront>emptyList())); 
     579                new Do(sp, Collections.<Block>emptyList())); 
    580580    } 
    581581 
     
    592592    public static Do makeDo(Span sp, Option<Type> t, Expr e) { 
    593593        List<Expr> b = Collections.singletonList(e); 
    594         List<DoFront> body = new ArrayList<DoFront>(1); 
    595         body.add(new DoFront(sp, new Block(sp, t, b))); 
     594        List<Block> body = new ArrayList<Block>(1); 
     595        body.add(new Block(sp, t, false, true, b)); 
    596596        return new Do(sp, t, body); 
    597597    } 
    598598 
    599599    public static Do makeDo(Span sp, Option<Type> t, List<Expr> exprs) { 
    600         List<DoFront> body = new ArrayList<DoFront>(1); 
    601         body.add(new DoFront(sp, new Block(sp, t, exprs))); 
     600        List<Block> body = new ArrayList<Block>(1); 
     601        body.add(new Block(sp, t, false, true, exprs)); 
    602602        return new Do(sp, t, body); 
    603603    } 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/DelimitedExpr.rats

    r3132 r3137  
    168168 
    169169/* DoFront ::= (at w Expr w)? (atomic w)? do (w BlockElems)? */ 
    170 private DoFront DoFront = 
     170private Block DoFront = 
    171171     a1:(at w Expr w)? a2:(atomic w)? do a3:(w BlockElems)? 
    172172     { Span span = createSpan(yyStart,yyCount); 
    173173       Option<Expr> at = Option.wrap(a1); 
    174174       boolean atomic = (a2 == null) ? false : true; 
    175        if (a3 == null) a3 = FortressUtil.doBlock(span); 
    176        yyValue = new DoFront(span, at, atomic, a3); 
     175       List<Expr> es; 
     176       if (a3 == null) es = Collections.<Expr>emptyList(); 
     177       else es = a3.getExprs(); 
     178       yyValue = new Block(span, false, Option.<Type>none(), at, atomic, true, es); 
    177179     }; 
    178180 
  • trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/phases/Transform.java

    r3123 r3137  
    176176                } 
    177177            }); 
    178             DoFront body_result = (DoFront) recur(that.getBody()); 
     178            Block body_result = (Block) recur(that.getBody()); 
    179179            setSyntaxEnvironment(save); 
    180180            return forForOnly(that, exprType_result, gens_result, body_result); 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r3133 r3137  
    11251125 
    11261126    @Override public String forBlockOnly(Block that, Option<String> exprType_result, 
     1127                                         Option<String> loc_result, 
    11271128                                         List<String> exprs_result) { 
    11281129        StringBuilder s = new StringBuilder(); 
     1130 
     1131        increaseIndent(); 
     1132        if ( loc_result.isSome() ) { 
     1133            s.append( "at " ).append( loc_result.unwrap() ).append( " " ); 
     1134        } 
     1135        if ( that.isAtomicBlock() ) { 
     1136            s.append( "atomic " ); 
     1137        } 
     1138        if ( that.isWithinDo() ) { 
     1139            s.append( "do\n" ); 
     1140        } 
    11291141        s.append( join( exprs_result, "\n" ) ); 
     1142        decreaseIndent(); 
     1143 
    11301144        return handleParen( s.toString(), 
    11311145                            that.isParenthesized() ); 
     
    28142828    } 
    28152829 
    2816     @Override public String forDoFrontOnly(DoFront that, 
    2817                                            Option<String> loc_result, 
    2818                                            String expr_result) { 
    2819         StringBuilder s = new StringBuilder(); 
    2820         increaseIndent(); 
    2821  
    2822         if ( loc_result.isSome() ) { 
    2823             s.append( "at " ).append( loc_result.unwrap() ).append( " " ); 
    2824         } 
    2825         if ( that.isAtomicBlock() ) { 
    2826             s.append( "atomic " ); 
    2827         } 
    2828         s.append( "do\n" ).append( indent(expr_result) ); 
    2829  
    2830         decreaseIndent(); 
    2831  
    2832         return s.toString(); 
    2833     } 
    2834  
    28352830    @Override public String forIfClauseOnly(IfClause that, 
    28362831                                            String test_result, 
  • trunk/ProjectFortress/static_tests/static_arg_inference/opr_arg_1/Expected.fsg

    r2906 r3137  
    1111callSiteFn(): FortressLibrary.String = 
    1212do 
    13     a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string") 
    14     a + a 
     13a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string") 
     14a + a 
    1515end 
    1616 
  • trunk/ProjectFortress/static_tests/static_arg_inference/simple_arg_1/Expected.fsg

    r2906 r3137  
    1111callSiteFn(): FortressLibrary.String = 
    1212do 
    13     a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string") 
    14     topLevelFn[\FortressLibrary.String\](a) 
     13a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string") 
     14topLevelFn[\FortressLibrary.String\](a) 
    1515end 
    1616