Changeset 3167
- Timestamp:
- 12/07/08 21:18:10 (12 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 7 modified
-
astgen/Fortress.ast (modified) (5 diffs)
-
src/com/sun/fortress/compiler/typechecker/SubtypeChecker.java (modified) (1 diff)
-
src/com/sun/fortress/nodes_util/NodeFactory.java (modified) (2 diffs)
-
src/com/sun/fortress/nodes_util/NodeUtil.java (modified) (2 diffs)
-
src/com/sun/fortress/parser/Type.rats (modified) (3 diffs)
-
src/com/sun/fortress/parser_util/precedence_resolver/TypeResolver.java (modified) (14 diffs)
-
src/com/sun/fortress/tools/FortressAstToConcrete.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3163 r3167 423 423 NonterminalExtensionDef(); 424 424 /** 425 * nonterminal header426 */427 NonterminalHeader(Option<ModifierPrivate> modifier428 = Option.<ModifierPrivate>none(),429 Id name,430 List<NonterminalParameter> params,431 List<StaticParam> staticParams432 = Collections.<StaticParam>emptyList(),433 Option<Type> paramType,434 Option<WhereClause> whereClause435 = Option.<WhereClause>none());436 437 /**438 * nonterminal parameter439 */440 NonterminalParameter(Id name, BaseType paramType);441 442 /**443 * syntax declaration444 */445 abstract SyntaxDecl(Option<String> modifier);446 /**447 * syntax definition in syntax declarations448 */449 SyntaxDef(List<SyntaxSymbol> syntaxSymbols,450 TransformerDecl transformer);451 452 SuperSyntaxDef(Id nonterminal, Id grammarId);453 454 /**455 * Transformation declaration456 */457 abstract TransformerDecl();458 /**459 * pre transformer definition in transformer declarations460 */461 PreTransformerDef(Transformer transformer);462 /**463 * transformer definition in transformer declarations464 */465 NamedTransformerDef(String name, List<NonterminalParameter> parameters, Transformer transformer);466 467 /**468 * Transformers469 */470 abstract Transformer();471 /**472 * Unparsed template473 */474 UnparsedTransformer(String transformer, Id nonterminal);475 /**476 * Parsed template477 */478 NodeTransformer(AbstractNode node);479 /**480 * Case-dispatch transformer expr481 */482 CaseTransformer(Id gapName, List<CaseTransformerClause> clauses);483 484 /**485 * Case transformer clause486 */487 CaseTransformerClause(Id constructor, List<Id> parameters, Transformer body);488 489 /**490 * syntax symbol491 */492 abstract SyntaxSymbol();493 /**494 * prefixed syntax symbol495 */496 PrefixedSymbol(Id id, SyntaxSymbol symbol);497 /**498 * optional syntax symbol499 */500 OptionalSymbol(SyntaxSymbol symbol);501 /**502 * repeat zero-or-more syntax symbol503 */504 RepeatSymbol(SyntaxSymbol symbol);505 /**506 * repeat one-or-more syntax symbol507 */508 RepeatOneOrMoreSymbol(SyntaxSymbol symbol);509 /**510 * ignore following whitespace syntax symbol511 */512 NoWhitespaceSymbol(SyntaxSymbol symbol);513 /**514 * groups of symbols515 */516 GroupSymbol(List<SyntaxSymbol> symbols);517 /**518 * special symbols syntax symbol519 */520 abstract SpecialSymbol();521 /**522 * any character syntax symbol523 */524 AnyCharacterSymbol();525 /**526 * whitespace syntax symbol527 */528 WhitespaceSymbol(String s);529 /**530 * tab syntax symbol531 */532 TabSymbol();533 /**534 * formfeed syntax symbol535 */536 FormfeedSymbol();537 /**538 * carriage return syntax symbol539 */540 CarriageReturnSymbol();541 /**542 * backspace syntax symbol543 */544 BackspaceSymbol();545 /**546 * newline syntax symbol547 */548 NewlineSymbol();549 /**550 * breakline syntax symbol551 */552 BreaklineSymbol(String s);553 /**554 * item syntax symbol;555 * may be either nonterminal or keyword556 */557 ItemSymbol(String item);558 /**559 * non-terminal syntax symbol560 */561 NonterminalSymbol(Id nonterminal);562 /**563 * keyword syntax symbol564 */565 KeywordSymbol(String token);566 /**567 * token syntax symbol568 */569 TokenSymbol(String token);570 /**571 * not predicate syntax symbol572 */573 NotPredicateSymbol(SyntaxSymbol symbol);574 /**575 * and predicate syntax symbol576 */577 AndPredicateSymbol(SyntaxSymbol symbol);578 /**579 * character class syntax symbol580 */581 CharacterClassSymbol(List<CharacterSymbol> characters);582 /**583 * character symbols584 */585 abstract CharacterSymbol();586 /**587 * character588 */589 CharSymbol(String string);590 /**591 * character interval592 */593 CharacterInterval(String beginSymbol, String endSymbol);594 /**595 425 * left-hand side of variable declaration or value parameter 596 426 */ … … 1203 1033 */ 1204 1034 abstract DimExpr(); 1205 /* vector type or exponent dimemsion1206 * resolved during parsing1207 * e.g.) ZZ32^31208 * e.g.) Time^21209 */1210 ExponentType(Type base, IntExpr power);1211 1035 /* base dimension 1212 1036 * DimExpr ::= Unity 1213 1037 * e.g.) Unity 1214 1038 */ 1215 BaseDim();1039 DimBase(); 1216 1040 /* dimension identifier 1217 1041 * DimExpr ::= QualifiedName … … 1219 1043 */ 1220 1044 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 1222 1064 * DimExpr ::= DimExpr DOT DimExpr 1223 1065 * | DimExpr DimExpr 1224 1066 * e.g.) Length Mass 1225 */ 1226 ProductDim(DimExpr multiplier, DimExpr multiplicand); 1227 /* dimension division 1067 * 1068 * dimension division 1228 1069 * DimExpr ::= DimExpr / DimExpr 1229 1070 * | DimExpr per DimExpr … … 1231 1072 * e.g.) Length / Time 1232 1073 */ 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); 1245 1075 /** 1246 1076 * base types: things that can be extended, excluded, thrown, etc. … … 1956 1786 SubscriptingMI(Op op, List<Expr> exprs, 1957 1787 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); 1958 1958 /* 1959 1959 * 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 600 600 * _InferenceVarType(Object id, int index = -1); 601 601 * abstract DimExpr(); 602 * ExponentType(Type base, IntExpr power); 603 * BaseDim(); 602 * DimBase(); 604 603 * 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); 608 606 * abstract DimType(Type type); 609 607 * TaggedDimType(DimExpr dim, -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java
r3155 r3167 262 262 } 263 263 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()); 284 275 } 285 276 … … 1166 1157 public static DimExpr makeInParentheses(DimExpr dim) { 1167 1158 return dim.accept(new NodeAbstractVisitor<DimExpr>() { 1168 public DimExpr for BaseDim(BaseDimt) {1169 return new BaseDim(t.getSpan(), true);1159 public DimExpr forDimBase(DimBase t) { 1160 return new DimBase(t.getSpan(), true); 1170 1161 } 1171 1162 public DimExpr forDimRef(DimRef t) { 1172 1163 return new DimRef(t.getSpan(), true, t.getName()); 1173 1164 } 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(), 1184 1171 t.getPower()); 1185 1172 } 1186 public DimExpr for OpDim(OpDimt) {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()); 1188 1175 } 1189 1176 public DimExpr defaultCase(Node x) { -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java
r3154 r3167 116 116 } 117 117 }; 118 118 119 119 for (Import imp : comp.getImports()) { 120 120 imp.accept(collector); 121 121 } 122 122 123 123 for (APIName api : comp.getExports()) { 124 124 all.add(api); … … 600 600 return (type instanceof ArrayType || 601 601 type instanceof MatrixType || 602 type instanceof ExponentType || 603 type instanceof ExponentDim); 602 type instanceof DimExponent); 604 603 } 605 604 public static boolean isExponentiation(IntExpr staticExpr) { -
trunk/ProjectFortress/src/com/sun/fortress/parser/Type.rats
r3144 r3167 151 151 / TypeRef 152 152 / VoidType 153 / one { yyValue = new BaseDim(createSpan(yyStart,1)); };153 / one { yyValue = new DimBase(createSpan(yyStart,1)); }; 154 154 155 155 /* ParenthesizedType ::= ( w Type w ) */ … … 205 205 / "Unity" 206 206 { Span span = createSpan(yyStart,yyCount); 207 yyValue = new BaseDim(span);207 yyValue = new DimBase(span); 208 208 } 209 209 / a1:Id a2:StaticArgs? … … 303 303 "by an exponentiation."); 304 304 if (base instanceof DimExpr) { 305 return new ExponentDim(createSpan(yyStart,yyCount),305 return new DimExponent(createSpan(yyStart,yyCount), 306 306 (DimExpr)base, a1); 307 307 } 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); 310 310 } 311 311 }}; -
trunk/ProjectFortress/src/com/sun/fortress/parser_util/precedence_resolver/TypeResolver.java
r3123 r3167 65 65 } 66 66 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 67 75 private static Type makeProductDim(Span span, TaggedDimType expr0, 68 76 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)); 71 79 return new TaggedDimType(span, true, 72 80 typeToType(expr0.getElemType()), dim, … … 77 85 DimExpr expr2) 78 86 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)); 81 89 return new TaggedDimType(span, true, 82 90 typeToType(expr0.getElemType()), dim, … … 260 268 DimExpr _first = typeToDim(first); 261 269 if (isDOT(op)) 262 return new ProductDim(span, true, _first, _second); 270 return new DimBinaryOp(span, true, _first, _second, 271 product(span)); 263 272 else // op.getText().equals("/") || 264 273 // op.getText().equals("per") 265 return new QuotientDim(span, true, _first, _second); 274 return new DimBinaryOp(span, true, _first, _second, 275 quotient(span)); 266 276 // throw new ReadError(op.getSpan(), "DimExpr is expected."); 267 277 } … … 447 457 DimExpr e = 448 458 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, 450 460 e, op))); 451 461 } catch (TypeConvertFailure x) { … … 519 529 try { 520 530 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)); 523 534 } catch (TypeConvertFailure x) { 524 535 if (expr0 instanceof TaggedDimType) { … … 563 574 Op op = ((Postfix)(_rest.getFirst())).getOp(); 564 575 PureList<PostfixOpExpr> restRest = _rest.getRest(); 565 DimExpr dim = new OpDim(_first.getSpan(),576 DimExpr dim = new DimUnaryOp(_first.getSpan(), 566 577 _first.isParenthesized(), 567 578 _first, op); … … 591 602 private static Type typeToType(Type type) { 592 603 return (Type) type.accept(new NodeUpdateVisitor() { 593 public Type for ExponentType(ExponentTypet) {604 public Type forDimExponent(DimExponent t) { 594 605 return makeMatrixType(t.getSpan(), typeToType(t.getBase()), 595 606 t.getPower()); … … 617 628 return t; 618 629 } 619 public DimExpr for ExponentType(ExponentTypet) {630 public DimExpr forDimExponent(DimExponent t) { 620 631 try { 621 return new ExponentDim(t.getSpan(),632 return new DimExponent(t.getSpan(), 622 633 t.isParenthesized(), 623 634 typeToDim(t.getBase()), … … 636 647 ExtentRange dimension = dimensions.get(0); 637 648 IntArg power = (IntArg)dimension.getSize().unwrap(); 638 return new ExponentDim(t.getSpan(),649 return new DimExponent(t.getSpan(), 639 650 t.isParenthesized(), 640 651 typeToDim(t.getElemType()), … … 648 659 try { 649 660 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())); 654 666 } else 655 667 return error(t, "A dimension is expected " + … … 677 689 private static DimExpr dimToDim(DimExpr dim) { 678 690 return dim.accept(new NodeAbstractVisitor<DimExpr>() { 679 public DimExpr for ExponentType(ExponentTyped) {691 public DimExpr forDimExponent(DimExponent d) { 680 692 try { 681 return new ExponentDim(d.getSpan(),693 return new DimExponent(d.getSpan(), 682 694 d.isParenthesized(), 683 695 typeToDim(d.getBase()), … … 687 699 } 688 700 } 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(), 697 703 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(), 703 710 d.isParenthesized(), 704 711 dimToDim(d.getDimVal()), … … 719 726 d.getName()); 720 727 } 721 public Type for ProductDim(ProductDimd) {728 public Type forDimBinaryOp(DimBinaryOp d) { 722 729 try { 723 730 return new TaggedDimType(d.getSpan(), 724 731 d.isParenthesized(), 725 makeInParentheses(dimToType(d.get Multiplier())),726 dimToDim(d.get Multiplicand()));732 makeInParentheses(dimToType(d.getLeft())), 733 dimToDim(d.getRight())); 727 734 } catch (TypeConvertFailure e) { 728 735 return error(e.getMessage()); 729 736 } 730 737 } 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()), 742 741 d.getPower()); 743 742 } … … 763 762 } 764 763 764 private static boolean isProductDim(DimBinaryOp dim) { 765 return dim.getOp().getText().equals(" "); 766 } 767 765 768 private static DimExpr canonicalizeDim(DimExpr dim) { 766 769 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(), 785 800 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()), 793 802 d.getPower()); 794 803 } 795 public DimExpr for OpDim(OpDimd) {796 return new OpDim(d.getSpan(),804 public DimExpr forDimUnaryOp(DimUnaryOp d) { 805 return new DimUnaryOp(d.getSpan(), 797 806 d.isParenthesized(), 798 807 canonicalizeDim(d.getDimVal()), -
trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java
r3155 r3167 1965 1965 } 1966 1966 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) { 1981 1968 return handleParen( "Unity", 1982 1969 that.isParenthesized() ); … … 1989 1976 } 1990 1977 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, 2016 1993 String base_result, 2017 1994 String power_result) { … … 2025 2002 } 2026 2003 2027 @Override public String for OpDimOnly(OpDimthat,2028 String val_result,2029 String op_result) {2004 @Override public String forDimUnaryOpOnly(DimUnaryOp that, 2005 String val_result, 2006 String op_result) { 2030 2007 StringBuilder s = new StringBuilder(); 2031 2008

