Changeset 3170

Show
Ignore:
Timestamp:
12/08/08 10:06:33 (12 months ago)
Author:
sukyoungryu
Message:

[ast refactoring] Restructured the UnitExpr? hierarchy.

Location:
trunk/ProjectFortress
Files:
5 modified

Legend:

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

    r3169 r3170  
    13471347                    /** 
    13481348                     * unit expression with an operator 
    1349                      */ 
    1350                     abstract UnitOpExpr(UnitExpr left, UnitExpr right); 
    1351                         /** 
    1352                          * unit multiplication 
    1353                          * UnitExpr ::= UnitExpr UnitExpr 
    1354                          *            | UnitExpr DOT UnitExpr 
    1355                          * e.g.) m DOT n 
    1356                          */ 
    1357                         ProductUnit(); 
    1358                         /* unit division 
    1359                          * UnitExpr ::= UnitExpr / UnitExpr 
    1360                          *            | UnitExpr per UnitExpr 
    1361                          * e.g.) meter / second 
    1362                          */ 
    1363                         QuotientUnit(); 
    1364                         /** 
    1365                          * unit exponentiation 
    1366                          * UnitExpr ::= UnitExpr caret UnitExpr 
    1367                          * e.g.) meter^2 
    1368                          */ 
    1369                         ExponentUnit(); 
     1349                     * 
     1350                     * unit multiplication 
     1351                     * UnitExpr ::= UnitExpr UnitExpr 
     1352                     *            | UnitExpr DOT UnitExpr 
     1353                     * e.g.) m DOT n 
     1354                     * 
     1355                     * unit division 
     1356                     * UnitExpr ::= UnitExpr / UnitExpr 
     1357                     *            | UnitExpr per UnitExpr 
     1358                     * e.g.) meter / second 
     1359                     * 
     1360                     * unit exponentiation 
     1361                     * UnitExpr ::= UnitExpr caret UnitExpr 
     1362                     * e.g.) meter^2 
     1363                     */ 
     1364                    UnitBinaryOp(UnitExpr left, UnitExpr right, Op op); 
    13701365            /** 
    13711366             * where clause used in trait, object, and functional declarations 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ErrorMsgMaker.java

    r3169 r3170  
    196196    } 
    197197 
    198     private String forUnitOpExpr(UnitOpExpr node, String op) { 
    199         return "(" + node.getLeft().accept(this) + op + node.getRight().accept(this) + ")"; 
    200     } 
    201  
    202     public String forProductUnit(ProductUnit node) { 
    203         return forUnitOpExpr(node, " "); 
    204     } 
    205  
    206     public String forQuotientUnit(QuotientUnit node) { 
    207         return forUnitOpExpr(node, "/"); 
    208     } 
    209  
    210     public String forExponentUnit(ExponentUnit node) { 
    211         return forUnitOpExpr(node, "^"); 
     198    public String forUnitBinaryOp(UnitBinaryOp node) { 
     199        return "(" + node.getLeft().accept(this) + 
     200                     node.getOp().accept(this) + 
     201                     node.getRight().accept(this) + ")"; 
    212202    } 
    213203 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java

    r3169 r3170  
    12051205                return new UnitRef(b.getSpan(), true, b.getName()); 
    12061206            } 
    1207             public UnitExpr forProductUnit(ProductUnit i) { 
    1208                 return new ProductUnit(i.getSpan(), true, i.getLeft(), 
    1209                         i.getRight()); 
    1210             } 
    1211             public UnitExpr forQuotientUnit(QuotientUnit t) { 
    1212                 return new QuotientUnit(t.getSpan(), true, t.getLeft(), 
    1213                         t.getRight()); 
    1214             } 
    1215             public UnitExpr forExponentUnit(ExponentUnit i) { 
    1216                 return new ExponentUnit(i.getSpan(), true, i.getLeft(), 
    1217                         i.getRight()); 
     1207            public UnitExpr forUnitBinaryOp(UnitBinaryOp i) { 
     1208                return new UnitBinaryOp(i.getSpan(), true, i.getLeft(), 
     1209                                        i.getRight(), i.getOp()); 
    12181210            } 
    12191211            public UnitExpr defaultCase(Node x) { 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/MayNewlineHeader.rats

    r3169 r3170  
    399399     { yyValue = new Action<UnitExpr>() { 
    400400           public UnitExpr run(UnitExpr base) { 
    401                return new ProductUnit(createSpan(yyStart,yyCount), 
    402                                       (UnitExpr)base, a1); 
     401               Op product = NodeFactory.makeOpInfix(a1.getSpan(), " "); 
     402               return new UnitBinaryOp(createSpan(yyStart,yyCount), 
     403                                       (UnitExpr)base, a1, product); 
    403404           }}; 
    404405     }; 
     
    408409     { yyValue = new Action<UnitExpr>() { 
    409410           public UnitExpr run(UnitExpr base) { 
    410                return new QuotientUnit(createSpan(yyStart,yyCount), 
    411                                       (UnitExpr)base, a1); 
     411               Op quotient = NodeFactory.makeOpInfix(a1.getSpan(), "/"); 
     412               return new UnitBinaryOp(createSpan(yyStart,yyCount), 
     413                                       (UnitExpr)base, a1, quotient); 
    412414           }}; 
    413415     }; 
     
    417419     { yyValue = new Action<UnitExpr>() { 
    418420           public UnitExpr run(UnitExpr base) { 
    419                return new ExponentUnit(createSpan(yyStart,yyCount), 
    420                                       (UnitExpr)base, a1); 
     421               Op exponent = NodeFactory.makeOpInfix(a1.getSpan(), "^"); 
     422               return new UnitBinaryOp(createSpan(yyStart,yyCount), 
     423                                       (UnitExpr)base, a1, exponent); 
    421424           }}; 
    422425     }; 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r3169 r3170  
    23002300    } 
    23012301 
    2302     @Override public String forProductUnitOnly(ProductUnit that, 
    2303                                                String left_result, 
    2304                                                String right_result) { 
    2305         return handleParen( left_result + " " + right_result, 
    2306                             that.isParenthesized() ); 
    2307     } 
    2308  
    2309     @Override public String forQuotientUnitOnly(QuotientUnit that, 
     2302    @Override public String forUnitBinaryOpOnly(UnitBinaryOp that, 
    23102303                                                String left_result, 
    2311                                                 String right_result) { 
    2312         return handleParen( left_result + "/" + right_result, 
    2313                             that.isParenthesized() ); 
    2314     } 
    2315  
    2316     @Override public String forExponentUnitOnly(ExponentUnit that, 
    2317                                                 String left_result, 
    2318                                                 String right_result) { 
    2319         return handleParen( left_result + "^" + right_result, 
     2304                                                String right_result, 
     2305                                                String op_result) { 
     2306        return handleParen( left_result + op_result + right_result, 
    23202307                            that.isParenthesized() ); 
    23212308    }