Changeset 3167

Show
Ignore:
Timestamp:
12/07/08 21:18:10 (12 months ago)
Author:
sukyoungryu
Message:

[ast refactoring] Restructured the DimExpr? hierarchy.

Location:
trunk/ProjectFortress
Files:
7 modified

Legend:

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

    r3163 r3167  
    423423                        NonterminalExtensionDef(); 
    424424            /** 
    425              * nonterminal header 
    426              */ 
    427             NonterminalHeader(Option<ModifierPrivate> modifier 
    428                                 = Option.<ModifierPrivate>none(), 
    429                               Id name, 
    430                               List<NonterminalParameter> params, 
    431                               List<StaticParam> staticParams 
    432                                 = Collections.<StaticParam>emptyList(), 
    433                               Option<Type> paramType, 
    434                               Option<WhereClause> whereClause 
    435                                 = Option.<WhereClause>none()); 
    436  
    437             /** 
    438              * nonterminal parameter 
    439              */ 
    440             NonterminalParameter(Id name, BaseType paramType); 
    441  
    442             /** 
    443              * syntax declaration 
    444              */ 
    445             abstract SyntaxDecl(Option<String> modifier); 
    446                 /** 
    447                  * syntax definition in syntax declarations 
    448                  */ 
    449                 SyntaxDef(List<SyntaxSymbol> syntaxSymbols, 
    450                           TransformerDecl transformer); 
    451  
    452                 SuperSyntaxDef(Id nonterminal, Id grammarId); 
    453  
    454             /** 
    455               * Transformation declaration 
    456               */ 
    457             abstract TransformerDecl(); 
    458                 /** 
    459                  * pre transformer definition in transformer declarations 
    460                  */ 
    461                 PreTransformerDef(Transformer transformer); 
    462                 /** 
    463                  * transformer definition in transformer declarations 
    464                  */ 
    465                 NamedTransformerDef(String name, List<NonterminalParameter> parameters, Transformer transformer); 
    466  
    467             /** 
    468              * Transformers 
    469              */ 
    470             abstract Transformer(); 
    471                 /** 
    472                  * Unparsed template 
    473                  */ 
    474                 UnparsedTransformer(String transformer, Id nonterminal); 
    475                 /** 
    476                  * Parsed template 
    477                  */ 
    478                 NodeTransformer(AbstractNode node); 
    479                 /** 
    480                  * Case-dispatch transformer expr 
    481                  */ 
    482                 CaseTransformer(Id gapName, List<CaseTransformerClause> clauses); 
    483  
    484             /** 
    485              * Case transformer clause 
    486              */ 
    487             CaseTransformerClause(Id constructor, List<Id> parameters, Transformer body); 
    488  
    489             /** 
    490              * syntax symbol 
    491              */ 
    492             abstract SyntaxSymbol(); 
    493                 /** 
    494                  * prefixed syntax symbol 
    495                  */ 
    496                 PrefixedSymbol(Id id, SyntaxSymbol symbol); 
    497                 /** 
    498                  * optional syntax symbol 
    499                  */ 
    500                 OptionalSymbol(SyntaxSymbol symbol); 
    501                 /** 
    502                  * repeat zero-or-more syntax symbol 
    503                  */ 
    504                 RepeatSymbol(SyntaxSymbol symbol); 
    505                 /** 
    506                  * repeat one-or-more syntax symbol 
    507                  */ 
    508                 RepeatOneOrMoreSymbol(SyntaxSymbol symbol); 
    509                 /** 
    510                  * ignore following whitespace syntax symbol 
    511                  */ 
    512                 NoWhitespaceSymbol(SyntaxSymbol symbol); 
    513                 /** 
    514                  * groups of symbols 
    515                  */ 
    516                 GroupSymbol(List<SyntaxSymbol> symbols); 
    517                 /** 
    518                  * special symbols syntax symbol 
    519                  */ 
    520                 abstract SpecialSymbol(); 
    521                     /** 
    522                      * any character syntax symbol 
    523                      */ 
    524                     AnyCharacterSymbol(); 
    525                     /** 
    526                      * whitespace syntax symbol 
    527                      */ 
    528                     WhitespaceSymbol(String s); 
    529                     /** 
    530                      * tab syntax symbol 
    531                      */ 
    532                     TabSymbol(); 
    533                     /** 
    534                      * formfeed syntax symbol 
    535                      */ 
    536                     FormfeedSymbol(); 
    537                     /** 
    538                      * carriage return syntax symbol 
    539                      */ 
    540                     CarriageReturnSymbol(); 
    541                     /** 
    542                      * backspace syntax symbol 
    543                      */ 
    544                     BackspaceSymbol(); 
    545                     /** 
    546                      * newline syntax symbol 
    547                      */ 
    548                     NewlineSymbol(); 
    549                     /** 
    550                      * breakline syntax symbol 
    551                      */ 
    552                     BreaklineSymbol(String s); 
    553                 /** 
    554                  * item syntax symbol; 
    555                  * may be either nonterminal or keyword 
    556                  */ 
    557                 ItemSymbol(String item); 
    558                 /** 
    559                  * non-terminal syntax symbol 
    560                  */ 
    561                 NonterminalSymbol(Id nonterminal); 
    562                 /** 
    563                  * keyword syntax symbol 
    564                  */ 
    565                 KeywordSymbol(String token); 
    566                 /** 
    567                  * token syntax symbol 
    568                  */ 
    569                 TokenSymbol(String token); 
    570                 /** 
    571                  * not predicate syntax symbol 
    572                  */ 
    573                 NotPredicateSymbol(SyntaxSymbol symbol); 
    574                 /** 
    575                  * and predicate syntax symbol 
    576                  */ 
    577                 AndPredicateSymbol(SyntaxSymbol symbol); 
    578                 /** 
    579                  * character class syntax symbol 
    580                  */ 
    581                 CharacterClassSymbol(List<CharacterSymbol> characters); 
    582                 /** 
    583                  * character symbols 
    584                  */ 
    585                 abstract CharacterSymbol(); 
    586                     /** 
    587                      * character 
    588                      */ 
    589                     CharSymbol(String string); 
    590                     /** 
    591                      * character interval 
    592                      */ 
    593                     CharacterInterval(String beginSymbol, String endSymbol); 
    594             /** 
    595425             * left-hand side of variable declaration or value parameter 
    596426             */ 
     
    12031033                 */ 
    12041034                abstract DimExpr(); 
    1205                     /* vector type or exponent dimemsion 
    1206                      * resolved during parsing 
    1207                      * e.g.) ZZ32^3 
    1208                      * e.g.) Time^2 
    1209                      */ 
    1210                     ExponentType(Type base, IntExpr power); 
    12111035                    /* base dimension 
    12121036                     * DimExpr ::= Unity 
    12131037                     * e.g.) Unity 
    12141038                     */ 
    1215                     BaseDim(); 
     1039                    DimBase(); 
    12161040                    /* dimension identifier 
    12171041                     * DimExpr ::= QualifiedName 
     
    12191043                     */ 
    12201044                    DimRef(Id name); 
    1221                     /* dimension multiplication 
     1045                    /* vector type or exponent dimemsion 
     1046                     * resolved during parsing 
     1047                     * after parsing the base field should be of type DimExpr 
     1048                     * e.g.) ZZ32^3 
     1049                     * 
     1050                     * dimension exponentiation 
     1051                     * DimExpr ::= DimExpr ^ IntExpr 
     1052                     * e.g.) Time^2 
     1053                     */ 
     1054                    DimExponent(Type base, IntExpr power); 
     1055                    /* dimension with an unary operator 
     1056                     * DimExpr ::= DimPrefixOp DimExpr 
     1057                     *           | DimExpr DimPostfixOp 
     1058                     * e.g.) Time squared 
     1059                     */ 
     1060                    DimUnaryOp(DimExpr dimVal, Op op); 
     1061                    /* dimension with a binary operator 
     1062                     * 
     1063                     * dimension multiplication 
    12221064                     * DimExpr ::= DimExpr DOT DimExpr 
    12231065                     *           | DimExpr DimExpr 
    12241066                     * e.g.) Length Mass 
    1225                      */ 
    1226                     ProductDim(DimExpr multiplier, DimExpr multiplicand); 
    1227                     /* dimension division 
     1067                     * 
     1068                     * dimension division 
    12281069                     * DimExpr ::= DimExpr / DimExpr 
    12291070                     *           | DimExpr per DimExpr 
     
    12311072                     * e.g.) Length / Time 
    12321073                     */ 
    1233                     QuotientDim(DimExpr numerator, DimExpr denominator); 
    1234                     /* dimension exponentiation 
    1235                      * DimExpr ::= DimExpr ^ IntExpr 
    1236                      * e.g.) Time^2 
    1237                      */ 
    1238                     ExponentDim(DimExpr base, IntExpr power); 
    1239                     /* dimension with operator 
    1240                      * DimExpr ::= DimPrefixOp DimExpr 
    1241                      *           | DimExpr DimPostfixOp 
    1242                      * e.g.) Time squared 
    1243                      */ 
    1244                     OpDim(DimExpr dimVal, Op op); 
     1074                    DimBinaryOp(DimExpr left, DimExpr right, Op op); 
    12451075                /** 
    12461076                 * base types: things that can be extended, excluded, thrown, etc. 
     
    19561786                    SubscriptingMI(Op op, List<Expr> exprs, 
    19571787                                   List<StaticArg> staticArgs); 
     1788            /** 
     1789             * nonterminal header 
     1790             */ 
     1791            NonterminalHeader(Option<ModifierPrivate> modifier 
     1792                                = Option.<ModifierPrivate>none(), 
     1793                              Id name, 
     1794                              List<NonterminalParameter> params, 
     1795                              List<StaticParam> staticParams 
     1796                                = Collections.<StaticParam>emptyList(), 
     1797                              Option<Type> paramType, 
     1798                              Option<WhereClause> whereClause 
     1799                                = Option.<WhereClause>none()); 
     1800 
     1801            /** 
     1802             * nonterminal parameter 
     1803             */ 
     1804            NonterminalParameter(Id name, BaseType paramType); 
     1805 
     1806            /** 
     1807             * syntax declaration 
     1808             */ 
     1809            abstract SyntaxDecl(Option<String> modifier); 
     1810                /** 
     1811                 * syntax definition in syntax declarations 
     1812                 */ 
     1813                SyntaxDef(List<SyntaxSymbol> syntaxSymbols, 
     1814                          TransformerDecl transformer); 
     1815 
     1816                SuperSyntaxDef(Id nonterminal, Id grammarId); 
     1817 
     1818            /** 
     1819              * Transformation declaration 
     1820              */ 
     1821            abstract TransformerDecl(); 
     1822                /** 
     1823                 * pre transformer definition in transformer declarations 
     1824                 */ 
     1825                PreTransformerDef(Transformer transformer); 
     1826                /** 
     1827                 * transformer definition in transformer declarations 
     1828                 */ 
     1829                NamedTransformerDef(String name, List<NonterminalParameter> parameters, Transformer transformer); 
     1830 
     1831            /** 
     1832             * Transformers 
     1833             */ 
     1834            abstract Transformer(); 
     1835                /** 
     1836                 * Unparsed template 
     1837                 */ 
     1838                UnparsedTransformer(String transformer, Id nonterminal); 
     1839                /** 
     1840                 * Parsed template 
     1841                 */ 
     1842                NodeTransformer(AbstractNode node); 
     1843                /** 
     1844                 * Case-dispatch transformer expr 
     1845                 */ 
     1846                CaseTransformer(Id gapName, List<CaseTransformerClause> clauses); 
     1847 
     1848            /** 
     1849             * Case transformer clause 
     1850             */ 
     1851            CaseTransformerClause(Id constructor, List<Id> parameters, Transformer body); 
     1852 
     1853            /** 
     1854             * syntax symbol 
     1855             */ 
     1856            abstract SyntaxSymbol(); 
     1857                /** 
     1858                 * prefixed syntax symbol 
     1859                 */ 
     1860                PrefixedSymbol(Id id, SyntaxSymbol symbol); 
     1861                /** 
     1862                 * optional syntax symbol 
     1863                 */ 
     1864                OptionalSymbol(SyntaxSymbol symbol); 
     1865                /** 
     1866                 * repeat zero-or-more syntax symbol 
     1867                 */ 
     1868                RepeatSymbol(SyntaxSymbol symbol); 
     1869                /** 
     1870                 * repeat one-or-more syntax symbol 
     1871                 */ 
     1872                RepeatOneOrMoreSymbol(SyntaxSymbol symbol); 
     1873                /** 
     1874                 * ignore following whitespace syntax symbol 
     1875                 */ 
     1876                NoWhitespaceSymbol(SyntaxSymbol symbol); 
     1877                /** 
     1878                 * groups of symbols 
     1879                 */ 
     1880                GroupSymbol(List<SyntaxSymbol> symbols); 
     1881                /** 
     1882                 * special symbols syntax symbol 
     1883                 */ 
     1884                abstract SpecialSymbol(); 
     1885                    /** 
     1886                     * any character syntax symbol 
     1887                     */ 
     1888                    AnyCharacterSymbol(); 
     1889                    /** 
     1890                     * whitespace syntax symbol 
     1891                     */ 
     1892                    WhitespaceSymbol(String s); 
     1893                    /** 
     1894                     * tab syntax symbol 
     1895                     */ 
     1896                    TabSymbol(); 
     1897                    /** 
     1898                     * formfeed syntax symbol 
     1899                     */ 
     1900                    FormfeedSymbol(); 
     1901                    /** 
     1902                     * carriage return syntax symbol 
     1903                     */ 
     1904                    CarriageReturnSymbol(); 
     1905                    /** 
     1906                     * backspace syntax symbol 
     1907                     */ 
     1908                    BackspaceSymbol(); 
     1909                    /** 
     1910                     * newline syntax symbol 
     1911                     */ 
     1912                    NewlineSymbol(); 
     1913                    /** 
     1914                     * breakline syntax symbol 
     1915                     */ 
     1916                    BreaklineSymbol(String s); 
     1917                /** 
     1918                 * item syntax symbol; 
     1919                 * may be either nonterminal or keyword 
     1920                 */ 
     1921                ItemSymbol(String item); 
     1922                /** 
     1923                 * non-terminal syntax symbol 
     1924                 */ 
     1925                NonterminalSymbol(Id nonterminal); 
     1926                /** 
     1927                 * keyword syntax symbol 
     1928                 */ 
     1929                KeywordSymbol(String token); 
     1930                /** 
     1931                 * token syntax symbol 
     1932                 */ 
     1933                TokenSymbol(String token); 
     1934                /** 
     1935                 * not predicate syntax symbol 
     1936                 */ 
     1937                NotPredicateSymbol(SyntaxSymbol symbol); 
     1938                /** 
     1939                 * and predicate syntax symbol 
     1940                 */ 
     1941                AndPredicateSymbol(SyntaxSymbol symbol); 
     1942                /** 
     1943                 * character class syntax symbol 
     1944                 */ 
     1945                CharacterClassSymbol(List<CharacterSymbol> characters); 
     1946                /** 
     1947                 * character symbols 
     1948                 */ 
     1949                abstract CharacterSymbol(); 
     1950                    /** 
     1951                     * character 
     1952                     */ 
     1953                    CharSymbol(String string); 
     1954                    /** 
     1955                     * character interval 
     1956                     */ 
     1957                    CharacterInterval(String beginSymbol, String endSymbol); 
    19581958            /* 
    19591959             * A Link in a ChainExpr is a pair of FunctionalRef and the next Expr in the chain. 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/SubtypeChecker.java

    r3148 r3167  
    600600     *        _InferenceVarType(Object id, int index = -1); 
    601601     *        abstract DimExpr(); 
    602      *            ExponentType(Type base, IntExpr power); 
    603      *            BaseDim(); 
     602     *            DimBase(); 
    604603     *            DimRef(Id name); 
    605      *            ProductDim(DimExpr multiplier, DimExpr multiplicand); 
    606      *            QuotientDim(DimExpr numerator, DimExpr denominator); 
    607      *            OpDim(DimExpr val, Op op); 
     604     *            DimUnaryOp(DimExpr val, Op op); 
     605     *            DimBinaryOp(DimExpr left, DimExpr right, Op op); 
    608606     *        abstract DimType(Type type); 
    609607     *            TaggedDimType(DimExpr dim, 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java

    r3155 r3167  
    262262    } 
    263263 
    264     public static ExponentType makeExponentType(ExponentType t, Type s) { 
    265         return new ExponentType(t.getSpan(), t.isParenthesized(), s, 
    266                 t.getPower()); 
    267     } 
    268  
    269     public static ProductDim makeProductDim(ProductDim t, DimExpr s, DimExpr u) { 
    270         return new ProductDim(t.getSpan(), t.isParenthesized(), s, u); 
    271     } 
    272  
    273     public static QuotientDim makeQuotientDim(QuotientDim t, DimExpr s, DimExpr u) { 
    274         return new QuotientDim(t.getSpan(), t.isParenthesized(), s, u); 
    275     } 
    276  
    277     public static ExponentDim makeExponentDim(ExponentDim t, DimExpr s) { 
    278         return new ExponentDim(t.getSpan(), t.isParenthesized(), s, 
    279                 t.getPower()); 
    280     } 
    281  
    282     public static OpDim makeOpDim(OpDim t, DimExpr s) { 
    283         return new OpDim(t.getSpan(), t.isParenthesized(), s, t.getOp()); 
     264    public static DimExponent makeDimExponent(DimExponent t, Type s) { 
     265        return new DimExponent(t.getSpan(), t.isParenthesized(), s, 
     266                               t.getPower()); 
     267    } 
     268 
     269    public static DimBinaryOp makeDimBinaryOp(DimBinaryOp t, DimExpr s, DimExpr u, Op o) { 
     270        return new DimBinaryOp(t.getSpan(), t.isParenthesized(), s, u, o); 
     271    } 
     272 
     273    public static DimUnaryOp makeDimUnaryOp(DimUnaryOp t, DimExpr s) { 
     274        return new DimUnaryOp(t.getSpan(), t.isParenthesized(), s, t.getOp()); 
    284275    } 
    285276 
     
    11661157    public static DimExpr makeInParentheses(DimExpr dim) { 
    11671158        return dim.accept(new NodeAbstractVisitor<DimExpr>() { 
    1168             public DimExpr forBaseDim(BaseDim t) { 
    1169                 return new BaseDim(t.getSpan(), true); 
     1159            public DimExpr forDimBase(DimBase t) { 
     1160                return new DimBase(t.getSpan(), true); 
    11701161            } 
    11711162            public DimExpr forDimRef(DimRef t) { 
    11721163                return new DimRef(t.getSpan(), true, t.getName()); 
    11731164            } 
    1174             public DimExpr forProductDim(ProductDim t) { 
    1175                 return new ProductDim(t.getSpan(), true, t.getMultiplier(), 
    1176                                       t.getMultiplicand()); 
    1177             } 
    1178             public DimExpr forQuotientDim(QuotientDim t) { 
    1179                 return new QuotientDim(t.getSpan(), true, t.getNumerator(), 
    1180                         t.getDenominator()); 
    1181             } 
    1182             public DimExpr forExponentDim(ExponentDim t) { 
    1183                 return new ExponentDim(t.getSpan(), true, t.getBase(), 
     1165            public DimExpr forDimBinaryOp(DimBinaryOp t) { 
     1166                return new DimBinaryOp(t.getSpan(), true, t.getLeft(), 
     1167                                       t.getRight(), t.getOp()); 
     1168            } 
     1169            public DimExpr forDimExponent(DimExponent t) { 
     1170                return new DimExponent(t.getSpan(), true, t.getBase(), 
    11841171                        t.getPower()); 
    11851172            } 
    1186             public DimExpr forOpDim(OpDim t) { 
    1187                 return new OpDim(t.getSpan(), true, t.getDimVal(), t.getOp()); 
     1173            public DimExpr forDimUnaryOp(DimUnaryOp t) { 
     1174                return new DimUnaryOp(t.getSpan(), true, t.getDimVal(), t.getOp()); 
    11881175            } 
    11891176            public DimExpr defaultCase(Node x) { 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java

    r3154 r3167  
    116116            } 
    117117        }; 
    118          
     118 
    119119        for (Import imp  : comp.getImports()) { 
    120120            imp.accept(collector); 
    121121        } 
    122          
     122 
    123123        for (APIName api : comp.getExports()) { 
    124124            all.add(api); 
     
    600600        return (type instanceof ArrayType || 
    601601                type instanceof MatrixType || 
    602                 type instanceof ExponentType || 
    603                 type instanceof ExponentDim); 
     602                type instanceof DimExponent); 
    604603    } 
    605604    public static boolean isExponentiation(IntExpr staticExpr) { 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/Type.rats

    r3144 r3167  
    151151   / TypeRef 
    152152   / VoidType 
    153    / one { yyValue = new BaseDim(createSpan(yyStart,1)); }; 
     153   / one { yyValue = new DimBase(createSpan(yyStart,1)); }; 
    154154 
    155155/* ParenthesizedType ::= ( w Type w ) */ 
     
    205205   / "Unity" 
    206206     { Span span = createSpan(yyStart,yyCount); 
    207        yyValue = new BaseDim(span); 
     207       yyValue = new DimBase(span); 
    208208     } 
    209209   / a1:Id a2:StaticArgs? 
     
    303303                                      "by an exponentiation."); 
    304304               if (base instanceof DimExpr) { 
    305                    return new ExponentDim(createSpan(yyStart,yyCount), 
     305                   return new DimExponent(createSpan(yyStart,yyCount), 
    306306                                          (DimExpr)base, a1); 
    307307               } else { // !(base instanceof DimExpr) 
    308                    return new ExponentType(createSpan(yyStart,yyCount), 
    309                                            (Type)base, a1); 
     308                   return new DimExponent(createSpan(yyStart,yyCount), 
     309                                          (Type)base, a1); 
    310310               } 
    311311           }}; 
  • trunk/ProjectFortress/src/com/sun/fortress/parser_util/precedence_resolver/TypeResolver.java

    r3123 r3167  
    6565    } 
    6666 
     67    private static Op product(Span span) { 
     68        return NodeFactory.makeOpInfix(span, " "); 
     69    } 
     70 
     71    private static Op quotient(Span span) { 
     72        return NodeFactory.makeOpInfix(span, "/"); 
     73    } 
     74 
    6775    private static Type makeProductDim(Span span, TaggedDimType expr0, 
    6876                                       DimExpr expr2) throws TypeConvertFailure { 
    69         DimExpr dim = new ProductDim(span, true, dimToDim(expr0.getDimExpr()), 
    70                                      dimToDim(expr2)); 
     77        DimExpr dim = new DimBinaryOp(span, true, dimToDim(expr0.getDimExpr()), 
     78                                      dimToDim(expr2), product(span)); 
    7179        return new TaggedDimType(span, true, 
    7280                                 typeToType(expr0.getElemType()), dim, 
     
    7785                                        DimExpr expr2) 
    7886        throws TypeConvertFailure { 
    79         DimExpr dim = new QuotientDim(span, true, dimToDim(expr0.getDimExpr()), 
    80                                       dimToDim(expr2)); 
     87        DimExpr dim = new DimBinaryOp(span, true, dimToDim(expr0.getDimExpr()), 
     88                                      dimToDim(expr2), quotient(span)); 
    8189        return new TaggedDimType(span, true, 
    8290                                 typeToType(expr0.getElemType()), dim, 
     
    260268                    DimExpr _first = typeToDim(first); 
    261269                    if (isDOT(op)) 
    262                         return new ProductDim(span, true, _first, _second); 
     270                        return new DimBinaryOp(span, true, _first, _second, 
     271                                               product(span)); 
    263272                    else // op.getText().equals("/") || 
    264273                         // op.getText().equals("per") 
    265                         return new QuotientDim(span, true, _first, _second); 
     274                        return new DimBinaryOp(span, true, _first, _second, 
     275                                               quotient(span)); 
    266276                    //                    throw new ReadError(op.getSpan(), "DimExpr is expected."); 
    267277                } 
     
    447457                        DimExpr e = 
    448458                            typeToDim(((RealType)__opTypes.getFirst()).getType()); 
    449                         return _rest.cons(new RealType(new OpDim(e.getSpan(), true, 
     459                        return _rest.cons(new RealType(new DimUnaryOp(e.getSpan(), true, 
    450460                                                                 e, op))); 
    451461                    } catch (TypeConvertFailure x) { 
     
    519529                            try { 
    520530                                DimExpr _expr0 = typeToDim(expr0); 
    521                                 e = new QuotientDim(span, true, 
    522                                                     _expr0, expr2); 
     531                                e = new DimBinaryOp(span, true, 
     532                                                    _expr0, expr2, 
     533                                                    quotient(span)); 
    523534                            } catch (TypeConvertFailure x) { 
    524535                                if (expr0 instanceof TaggedDimType) { 
     
    563574                    Op op = ((Postfix)(_rest.getFirst())).getOp(); 
    564575                    PureList<PostfixOpExpr> restRest = _rest.getRest(); 
    565                     DimExpr dim = new OpDim(_first.getSpan(), 
     576                    DimExpr dim = new DimUnaryOp(_first.getSpan(), 
    566577                                            _first.isParenthesized(), 
    567578                                            _first, op); 
     
    591602    private static Type typeToType(Type type) { 
    592603        return (Type) type.accept(new NodeUpdateVisitor() { 
    593             public Type forExponentType(ExponentType t) { 
     604            public Type forDimExponent(DimExponent t) { 
    594605                return makeMatrixType(t.getSpan(), typeToType(t.getBase()), 
    595606                                      t.getPower()); 
     
    617628                    return t; 
    618629                } 
    619                 public DimExpr forExponentType(ExponentType t) { 
     630                public DimExpr forDimExponent(DimExponent t) { 
    620631                    try { 
    621                         return new ExponentDim(t.getSpan(), 
     632                        return new DimExponent(t.getSpan(), 
    622633                                               t.isParenthesized(), 
    623634                                               typeToDim(t.getBase()), 
     
    636647                        ExtentRange dimension = dimensions.get(0); 
    637648                        IntArg power = (IntArg)dimension.getSize().unwrap(); 
    638                         return new ExponentDim(t.getSpan(), 
     649                        return new DimExponent(t.getSpan(), 
    639650                                               t.isParenthesized(), 
    640651                                               typeToDim(t.getElemType()), 
     
    648659                    try { 
    649660                        if (t.getUnitExpr().isNone()) { 
    650                             return new ProductDim(t.getSpan(), 
    651                                                   t.isParenthesized(), 
    652                                                   typeToDim(t.getElemType()), 
    653                                                   t.getDimExpr()); 
     661                            return new DimBinaryOp(t.getSpan(), 
     662                                                   t.isParenthesized(), 
     663                                                   typeToDim(t.getElemType()), 
     664                                                   t.getDimExpr(), 
     665                                                   product(t.getSpan())); 
    654666                        } else 
    655667                            return error(t, "A dimension is expected " + 
     
    677689    private static DimExpr dimToDim(DimExpr dim) { 
    678690        return dim.accept(new NodeAbstractVisitor<DimExpr>() { 
    679             public DimExpr forExponentType(ExponentType d) { 
     691            public DimExpr forDimExponent(DimExponent d) { 
    680692                try { 
    681                     return new ExponentDim(d.getSpan(), 
     693                    return new DimExponent(d.getSpan(), 
    682694                                           d.isParenthesized(), 
    683695                                           typeToDim(d.getBase()), 
     
    687699                } 
    688700            } 
    689             public DimExpr forProductDim(ProductDim d) { 
    690                 return new ProductDim(d.getSpan(), 
    691                                       d.isParenthesized(), 
    692                                       dimToDim(d.getMultiplier()), 
    693                                       dimToDim(d.getMultiplicand())); 
    694             } 
    695             public DimExpr forQuotientDim(QuotientDim d) { 
    696                 return new QuotientDim(d.getSpan(), 
     701            public DimExpr forDimBinaryOp(DimBinaryOp d) { 
     702                return new DimBinaryOp(d.getSpan(), 
    697703                                       d.isParenthesized(), 
    698                                        dimToDim(d.getNumerator()), 
    699                                        dimToDim(d.getDenominator())); 
    700             } 
    701             public DimExpr forOpDim(OpDim d) { 
    702                 return new OpDim(d.getSpan(), 
     704                                       dimToDim(d.getLeft()), 
     705                                       dimToDim(d.getRight()), 
     706                                       d.getOp()); 
     707            } 
     708            public DimExpr forDimUnaryOp(DimUnaryOp d) { 
     709                return new DimUnaryOp(d.getSpan(), 
    703710                                 d.isParenthesized(), 
    704711                                 dimToDim(d.getDimVal()), 
     
    719726                                       d.getName()); 
    720727                } 
    721                 public Type forProductDim(ProductDim d) { 
     728                public Type forDimBinaryOp(DimBinaryOp d) { 
    722729                    try { 
    723730                        return new TaggedDimType(d.getSpan(), 
    724731                                                 d.isParenthesized(), 
    725                                                  makeInParentheses(dimToType(d.getMultiplier())), 
    726                                                  dimToDim(d.getMultiplicand())); 
     732                                                 makeInParentheses(dimToType(d.getLeft())), 
     733                                                 dimToDim(d.getRight())); 
    727734                    } catch (TypeConvertFailure e) { 
    728735                        return error(e.getMessage()); 
    729736                    } 
    730737                } 
    731                 public Type forExponentDim(ExponentDim d) { 
    732                     try { 
    733                         return makeMatrixType(d.getSpan(), 
    734                                               dimToType(d.getBase()), 
    735                                               d.getPower()); 
    736                     } catch (TypeConvertFailure e) { 
    737                         return error(e.getMessage()); 
    738                     } 
    739                 } 
    740                 public Type forExponentType(ExponentType d) { 
    741                     return makeMatrixType(d.getSpan(), typeToType(d.getBase()), 
     738                public Type forDimExponent(DimExponent d) { 
     739                    return makeMatrixType(d.getSpan(), 
     740                                          typeToType(d.getBase()), 
    742741                                          d.getPower()); 
    743742                } 
     
    763762    } 
    764763 
     764    private static boolean isProductDim(DimBinaryOp dim) { 
     765        return dim.getOp().getText().equals(" "); 
     766    } 
     767 
    765768    private static DimExpr canonicalizeDim(DimExpr dim) { 
    766769        return dim.accept(new NodeAbstractVisitor<DimExpr>() { 
    767             public DimExpr forProductDim(ProductDim d) { 
    768                 DimExpr left = d.getMultiplier(); 
    769                 DimExpr right = d.getMultiplicand(); 
    770                 if (right instanceof ProductDim) { 
    771                     ProductDim _right = (ProductDim)right; 
    772                     DimExpr rleft = _right.getMultiplier(); 
    773                     left = new ProductDim(spanTwo(left, rleft), 
    774                                           true, left, rleft); 
    775                     left = canonicalizeDim(left); 
    776                     right = canonicalizeDim(_right.getMultiplicand()); 
    777                 } else 
    778                     left = canonicalizeDim(left); 
    779                 return new ProductDim(d.getSpan(), 
    780                                       d.isParenthesized(), 
    781                                       left, right); 
    782             } 
    783             public DimExpr forQuotientDim(QuotientDim d) { 
    784                 return new QuotientDim(d.getSpan(), 
     770            public DimExpr forDimBinaryOp(DimBinaryOp d) { 
     771                if ( isProductDim(d) ) { 
     772                    DimExpr left = d.getLeft(); 
     773                    DimExpr right = d.getRight(); 
     774                    if ( right instanceof DimBinaryOp && 
     775                         isProductDim((DimBinaryOp)right) ) { 
     776                        DimBinaryOp _right = (DimBinaryOp)right; 
     777                        DimExpr rleft = _right.getLeft(); 
     778                        Span span = spanTwo(left, rleft); 
     779                        left = new DimBinaryOp(span, 
     780                                               true, left, rleft, 
     781                                               product(span)); 
     782                        left = canonicalizeDim(left); 
     783                        right = canonicalizeDim(_right.getRight()); 
     784                    } else 
     785                        left = canonicalizeDim(left); 
     786                    return new DimBinaryOp(d.getSpan(), 
     787                                           d.isParenthesized(), 
     788                                           left, right, product(d.getSpan())); 
     789                } else { 
     790                    return new DimBinaryOp(d.getSpan(), 
     791                                           d.isParenthesized(), 
     792                                           canonicalizeDim(d.getLeft()), 
     793                                           canonicalizeDim(d.getRight()), 
     794                                           quotient(d.getSpan())); 
     795 
     796                } 
     797            } 
     798            public DimExpr forDimExponent(DimExponent d) { 
     799                return new DimExponent(d.getSpan(), 
    785800                                       d.isParenthesized(), 
    786                                        canonicalizeDim(d.getNumerator()), 
    787                                        canonicalizeDim(d.getDenominator())); 
    788             } 
    789             public DimExpr forExponentDim(ExponentDim d) { 
    790                 return new ExponentDim(d.getSpan(), 
    791                                        d.isParenthesized(), 
    792                                        canonicalizeDim(d.getBase()), 
     801                                       canonicalizeDim((DimExpr)d.getBase()), 
    793802                                       d.getPower()); 
    794803            } 
    795             public DimExpr forOpDim(OpDim d) { 
    796                 return new OpDim(d.getSpan(), 
     804            public DimExpr forDimUnaryOp(DimUnaryOp d) { 
     805                return new DimUnaryOp(d.getSpan(), 
    797806                                 d.isParenthesized(), 
    798807                                 canonicalizeDim(d.getDimVal()), 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r3155 r3167  
    19651965    } 
    19661966 
    1967     @Override public String forExponentTypeOnly(ExponentType that, 
    1968                                                 String base_result, 
    1969                                                 String power_result) { 
    1970         StringBuilder s = new StringBuilder(); 
    1971  
    1972         s.append( base_result ); 
    1973         s.append( "^" ); 
    1974         s.append( power_result ); 
    1975  
    1976         return handleParen( s.toString(), 
    1977                             that.isParenthesized() ); 
    1978     } 
    1979  
    1980     @Override public String forBaseDimOnly(BaseDim that) { 
     1967    @Override public String forDimBaseOnly(DimBase that) { 
    19811968        return handleParen( "Unity", 
    19821969                            that.isParenthesized() ); 
     
    19891976    } 
    19901977 
    1991     @Override public String forProductDimOnly(ProductDim that, 
    1992                                               String multiplier_result, 
    1993                                               String multiplicand_result) { 
    1994         StringBuilder s = new StringBuilder(); 
    1995  
    1996         s.append( multiplier_result ).append( " " ); 
    1997         s.append( multiplicand_result ); 
    1998  
    1999         return handleParen( s.toString(), 
    2000                             that.isParenthesized() ); 
    2001     } 
    2002  
    2003     @Override public String forQuotientDimOnly(QuotientDim that, 
    2004                                                String numerator_result, 
    2005                                                String denominator_result) { 
    2006         StringBuilder s = new StringBuilder(); 
    2007  
    2008         s.append( numerator_result ).append( "/" ); 
    2009         s.append( denominator_result ); 
    2010  
    2011         return handleParen( s.toString(), 
    2012                             that.isParenthesized() ); 
    2013     } 
    2014  
    2015     @Override public String forExponentDimOnly(ExponentDim that, 
     1978    @Override public String forDimBinaryOpOnly(DimBinaryOp that, 
     1979                                               String left, 
     1980                                               String right, 
     1981                                               String op) { 
     1982        StringBuilder s = new StringBuilder(); 
     1983 
     1984        s.append( left ); 
     1985        s.append( op ); 
     1986        s.append( right ); 
     1987 
     1988        return handleParen( s.toString(), 
     1989                            that.isParenthesized() ); 
     1990    } 
     1991 
     1992    @Override public String forDimExponentOnly(DimExponent that, 
    20161993                                               String base_result, 
    20171994                                               String power_result) { 
     
    20252002    } 
    20262003 
    2027     @Override public String forOpDimOnly(OpDim that, 
    2028                                          String val_result, 
    2029                                          String op_result) { 
     2004    @Override public String forDimUnaryOpOnly(DimUnaryOp that, 
     2005                                              String val_result, 
     2006                                              String op_result) { 
    20302007        StringBuilder s = new StringBuilder(); 
    20312008