Changeset 2405

Show
Ignore:
Timestamp:
07/28/08 20:20:58 (16 months ago)
Author:
sukyoungryu
Message:

[tool] Fixed arrays and also do.

Location:
trunk/ProjectFortress
Files:
5 modified

Legend:

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

    r2390 r2405  
    12631263                         * e.g.) [3 4 5; 6 7 8] 
    12641264                         */ 
    1265                         ArrayElements(int dimension, List<ArrayExpr> elements); 
     1265                        ArrayElements(int dimension, 
     1266                                      List<ArrayExpr> elements, 
     1267                                      boolean outermost = false); 
    12661268        /** 
    12671269         * type 
  • trunk/ProjectFortress/src/com/sun/fortress/Shell.java

    r2404 r2405  
    371371                Path path = sourcePath( s, name ); 
    372372 
    373                 /* 
    374                 Debug.debug( Debug.Type.REPOSITORY, 2, "True api name is " + name ); 
    375                 Debug.debug( Debug.Type.REPOSITORY, 2, "Path is " + s ); 
    376                 Path path = ProjectProperties.SOURCE_PATH; 
    377                 String source = new File( s ).getCanonicalPath().substring( 0, s.length() - (name.toString().length() + 4) ); 
    378                 path = path.prepend( source ); 
    379                 Debug.debug( Debug.Type.REPOSITORY, 2, "Source path is " + source ); 
    380                 Debug.debug( Debug.Type.REPOSITORY, 2, "Lookup path is " + path ); 
    381                 */ 
    382                 /* 
    383                 if (s.contains("/")) { 
    384                     String head = s.substring(0, s.lastIndexOf("/")); 
    385                     s = s.substring(s.lastIndexOf("/")+1, s.length()); 
    386                     path = path.prepend(head); 
    387                 } 
    388                 */ 
    389373                Iterable<? extends StaticError> errors = compile(path, name.toString() + (s.endsWith(".fss") ? ".fss" : ".fsi"), out ); 
    390374                if ( errors.iterator().hasNext() ){ 
     
    483467        throws UserError, Throwable { 
    484468        try { 
    485             /* 
    486             Path path = ProjectProperties.SOURCE_PATH; 
    487             if (fileName.contains("/")) { 
    488                 String head = fileName.substring(0, fileName.lastIndexOf("/")); 
    489                 fileName = fileName.substring(fileName.lastIndexOf("/")+1, fileName.length()); 
    490                 path = path.prepend(head); 
    491             } 
    492             APIName componentName = cuName(fileName); 
    493             */ 
    494  
    495469            APIName name = trueApiName( fileName ); 
    496470            Path path = sourcePath(fileName, name); 
    497              
     471 
    498472            GraphRepository bcr = specificRepository( path, defaultRepository ); 
    499473            Iterable<? extends StaticError> errors = IterUtil.empty(); 
     
    519493                System.err.println(error); 
    520494            } 
    521             // If there are no errors, all components will have been written to disk by the CacheBasedRepository. 
     495            // If there are no errors, 
     496            // all components will have been written to disk 
     497            // by the CacheBasedRepository. 
    522498        } catch ( StaticError e ){ 
    523499            System.err.println(e); 
  • trunk/ProjectFortress/src/com/sun/fortress/parser/Literal.rats

    r2327 r2405  
    4444 
    4545/* ArrayExpr ::= [ StaticArgs? w RectElements w ] */ 
    46 ArrayExpr ArrayExpr = 
     46ArrayElements ArrayExpr = 
    4747     void:opensquare a1:StaticArgs? w a2:RectElements w void:closesquare 
    48      { if (a1 == null) yyValue = a2; 
     48     { if (a1 == null) yyValue = FortressUtil.finalizeArrayExpr(a2); 
    4949       else            yyValue = FortressUtil.addStaticArgsToArrayExpr(a1, a2); 
    5050     }; 
    5151 
    5252/* RectElements ::= NoSpaceExpr MultiDimCons* */ 
    53 private ArrayExpr RectElements = 
     53private ArrayElements RectElements = 
    5454     a1:NoSpaceExpr a2s:MultiDimCons* 
    55      { if (a2s == null || a2s.isEmpty()) 
    56            yyValue = new ArrayElement(a1.getSpan(), false, a1); 
    57        else 
     55     { if (a2s == null || a2s.isEmpty()) { 
     56             List<ArrayExpr> list = new ArrayList<ArrayExpr>(); 
     57             list.add(new ArrayElement(a1.getSpan(), false, a1)); 
     58             yyValue = new ArrayElements(a1.getSpan(), false, 1, list); 
     59         } else 
    5860           yyValue = FortressUtil.multiDimCons(a1, a2s.list()); 
    5961     }; 
  • trunk/ProjectFortress/src/com/sun/fortress/parser_util/FortressUtil.java

    r2045 r2405  
    668668        } 
    669669    } 
    670     public static ArrayExpr multiDimCons(Expr init, 
     670    public static ArrayElements multiDimCons(Expr init, 
    671671                                        List<Pair<Integer,Expr>> rest) { 
    672672        ArrayExpr _init = multiDimElement(init); 
     
    691691    } 
    692692 
    693     public static ArrayExpr addStaticArgsToArrayExpr(List<StaticArg> sargs, 
    694                                               ArrayExpr a) { 
    695         if (a instanceof ArrayElement) { 
    696             ArrayElement arrayE = (ArrayElement)a; 
    697             return new ArrayElement(arrayE.getSpan(), arrayE.isParenthesized(), 
    698                                     sargs, arrayE.getElement()); 
    699         } else { // a instanceof ArrayElements 
    700             ArrayElements arrayE = (ArrayElements)a; 
    701             return new ArrayElements(arrayE.getSpan(), arrayE.isParenthesized(), 
    702                                      sargs, arrayE.getDimension(), 
    703                                      arrayE.getElements()); 
    704         } 
     693    public static ArrayElements finalizeArrayExpr(ArrayElements a) { 
     694        return new ArrayElements(a.getSpan(), a.isParenthesized(), 
     695                                 a.getStaticArgs(), a.getDimension(), 
     696                                 a.getElements(), true); 
     697    } 
     698 
     699    public static ArrayElements addStaticArgsToArrayExpr(List<StaticArg> sargs, 
     700                                                         ArrayElements a) { 
     701        return new ArrayElements(a.getSpan(), a.isParenthesized(), 
     702                                 sargs, a.getDimension(), 
     703                                 a.getElements(), true); 
    705704    } 
    706705 
  • trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java

    r2402 r2405  
    3434     */ 
    3535 
     36    /* indentation utilities *************************************************/ 
    3637    private int indent = 0; 
    3738 
     
    5960 
    6061    /* utility methods ********************************************************/ 
     62    /* returns number copies of s */ 
     63    private String makeCopies(int number, String s) { 
     64        String result = s; 
     65        for (int index = 1; index < number; index++) { 
     66            result += s; 
     67        } 
     68        return result; 
     69    } 
     70 
    6171    /* returns a string beginning with 'kind' followed by a sequence of elements 
    6272       in 'list' separated by commas and  enclosed by '{' and '}' 
     
    362372                                              List<String> decls_result) { 
    363373        StringBuilder s = new StringBuilder(); 
    364          
     374 
    365375        increaseIndent(); 
    366376 
     
    386396        s.append( indent(join(decls_result,"\n")) ); 
    387397        s.append( "\nend" ).append( "\n" ); 
    388          
     398 
    389399        decreaseIndent(); 
    390400 
     
    655665                                      List<String> fronts_result) { 
    656666        StringBuilder s = new StringBuilder(); 
    657         s.append( indent(join(fronts_result, "\n")) ); 
     667        s.append( indent(join(fronts_result, " also\n")) ); 
    658668        s.append( "\nend" ); 
    659669        return s.toString(); 
     
    10301040        StringBuilder s = new StringBuilder(); 
    10311041 
    1032         // s.append( op_result ); 
    10331042        s.append( join(args_result, " " + op_result + " ") ); 
    10341043 
     
    10941103//    @Override public String forMathPrimaryOnly( that, 
    10951104 
    1096     @Override public String forArrayElementOnly(ArrayElement that, List<String> staticArgs_result, String element_result) { 
    1097         StringBuilder s = new StringBuilder(); 
    1098  
    1099         s.append( element_result ); 
    1100         s.append( inOxfordBrackets(staticArgs_result)); 
    1101  
    1102         return s.toString(); 
    1103     } 
    1104  
    1105     @Override public String forArrayElementsOnly(ArrayElements that, List<String> staticArgs_result, List<String> elements_result) { 
    1106         StringBuilder s = new StringBuilder(); 
    1107  
    1108         s.append( "[ " ); 
    1109         s.append( join(elements_result, ", ") ); 
    1110         s.append( inOxfordBrackets( staticArgs_result ) ); 
    1111         s.append( " ]" ); 
     1105    @Override public String forArrayElementOnly(ArrayElement that, 
     1106                                                List<String> staticArgs_result, 
     1107                                                String element_result) { 
     1108        return element_result; 
     1109    } 
     1110 
     1111    @Override public String forArrayElementsOnly(ArrayElements that, 
     1112                                                 List<String> staticArgs_result, 
     1113                                                 List<String> elements_result) { 
     1114        StringBuilder s = new StringBuilder(); 
     1115 
     1116        if ( that.isOutermost() ) { 
     1117            s.append( "[" ); 
     1118            s.append( inOxfordBrackets( staticArgs_result ) ); 
     1119            s.append( " " ); 
     1120        } 
     1121        String separator; 
     1122        if ( that.getDimension() == 1 ) 
     1123            separator = " "; 
     1124        else 
     1125            separator = makeCopies(that.getDimension()-1, ";"); 
     1126        s.append( join(elements_result, separator) ); 
     1127        if ( that.isOutermost() ) 
     1128            s.append( " ]" ); 
    11121129 
    11131130        return s.toString(); 
     
    11311148//    @Override public String for_RewriteGenericSingletonTypeOnly( that, 
    11321149 
    1133     @Override public String forArrayTypeOnly(ArrayType that, String type_result, String indices_result) { 
     1150    @Override public String forArrayTypeOnly(ArrayType that, 
     1151                                             String type_result, 
     1152                                             String indices_result) { 
    11341153        StringBuilder s = new StringBuilder(); 
    11351154 
     
    17111730    @Override public String forAnonymousFnNameOnly(AnonymousFnName that, 
    17121731                                                   Option<String> api_result) { 
    1713         StringBuilder s = new StringBuilder(); 
    1714  
    1715         return s.toString(); 
    1716         /* 
    1717         return bug(that, "Anonymous function names are not supported " + 
    1718                    "in Fortress concrete syntax."); 
    1719                    */ 
     1732        return ""; 
    17201733    } 
    17211734 
     
    18121825    } 
    18131826 
    1814     @Override public String forExtentRangeOnly(ExtentRange that, Option<String> base_result, Option<String> size_result) { 
    1815             StringBuilder s = new StringBuilder(); 
    1816  
    1817             if ( base_result.isSome() ){ 
    1818                     s.append( base_result.unwrap() ); 
    1819             } 
    1820             if ( size_result.isSome() ){ 
    1821                     s.append( size_result.unwrap() ); 
    1822             } 
    1823  
    1824             return s.toString(); 
     1827    /* Possible differences in the original Fortress program and 
     1828       the unparsed program. 
     1829       In the Fortress source program, either "#" or ":" may be used. 
     1830       In AST, only "#" is used. 
     1831       In the Fortress source program, either "#size" or "size" may be used. 
     1832       In AST, only "#size" is used. 
     1833     */ 
     1834    @Override public String forExtentRangeOnly(ExtentRange that, 
     1835                                               Option<String> base_result, 
     1836                                               Option<String> size_result) { 
     1837        StringBuilder s = new StringBuilder(); 
     1838 
     1839        if ( base_result.isSome() ){ 
     1840            s.append( base_result.unwrap() ); 
     1841        } 
     1842        s.append( "#" ); 
     1843        if ( size_result.isSome() ){ 
     1844            s.append( size_result.unwrap() ); 
     1845        } 
     1846 
     1847        return s.toString(); 
    18251848    } 
    18261849 
     
    18561879//    @Override public String forTraitTypeWhereOnly( that, 
    18571880 
    1858     @Override public String forIndicesOnly(Indices that, List<String> extents_result) { 
     1881    @Override public String forIndicesOnly(Indices that, 
     1882                                           List<String> extents_result) { 
    18591883        StringBuilder s = new StringBuilder(); 
    18601884