Changeset 2132

Show
Ignore:
Timestamp:
06/29/08 06:06:23 (3 months ago)
Author:
sukyoungryu
Message:

[copyright] Fixed copyright notices.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Library/incomplete/SkipTreeTest.fss

    r2117 r2132  
     1(******************************************************************************* 
     2    Copyright 2008 Sun Microsystems, Inc., 
     3    4150 Network Circle, Santa Clara, California 95054, U.S.A. 
     4    All rights reserved. 
     5 
     6    U.S. Government Rights - Commercial software. 
     7    Government users are subject to the Sun Microsystems, Inc. standard 
     8    license agreement and applicable provisions of the FAR and its supplements. 
     9 
     10    Use is subject to license terms. 
     11 
     12    This distribution may include materials developed by third parties. 
     13 
     14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered 
     15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries. 
     16 ******************************************************************************) 
     17 
    118component SkipTreeTest 
    219import SkipTree.{...} 
     
    825    println leaf.toString() 
    926    println leaf.find(3) 
    10     println leaf.find(7)     
     27    println leaf.find(7) 
    1128    testList = emptyList[\ZZ32\]().addRight(5).addRight(10).addRight(15).addRight(20) 
    1229    assert(binarySearch[\ZZ32\](testList, 2), -1) 
     
    2037    assert(binarySearch[\ZZ32\](testList, 23), -5) 
    2138 
    22     println leaf.insert(5,2,4).toString()     
     39    println leaf.insert(5,2,4).toString() 
    2340    (** tree = SkipTree[\ZZ32,ZZ32\](Just[\Node[\ZZ32,ZZ32\]\](leaf)) *) 
    24      
    25      
    26          
    27      
     41 
     42 
     43 
     44 
    2845end (* run(args:String...):() *) 
    2946 
  • trunk/ProjectFortress/src/com/sun/fortress/Shell.java

    r2128 r2132  
    4343 
    4444public final class Shell { 
    45     // public static boolean debug; 
    4645    static boolean test; 
    47     private static String COMPONENT_SUFFIX = ".fss"; 
    48     private static String API_SUFFIX = ".fsi"; 
    49  
    50     public static String fortressLocation() { 
    51         return ProjectProperties.ANALYZED_CACHE_DIR; 
    52     } 
    5346 
    5447    /* Helper method to print usage message.*/ 
    5548    private static void printUsageMessage() { 
    5649        System.err.println("Usage:"); 
    57         System.err.println(" compile [-out file] [-debug [#]]somefile.fs{s,i}"); 
     50        System.err.println(" compile [-out file] [-debug [#]] somefile.fs{s,i}"); 
    5851        System.err.println(" [run] [-test] [-debug [#]] somefile.fss arg..."); 
    5952        System.err.println(" parse [-out file] [-debug [#]] somefile.fs{s,i}..."); 
     
    6558        System.err.println 
    6659        ("Invoked as script: fortress args\n"+ 
    67          "Invoked by java: java ... com.sun.fortress.shell.Shell args\n"+ 
     60         "Invoked by java: java ... com.sun.fortress.Shell args\n"+ 
     61         "fortress compile [-out file] [-debug [#]] somefile.fs{s,i}\n"+ 
     62         "  Compile somefile. If compilation succeeds no message will be printed.\n"+ 
     63         "   -out file : dumps the processed abstract syntax tree to a file.\n" + 
     64         "   -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 
     65         "   -debug # : sets debugging to the specified level, where # is a number.\n"+ 
     66         "\n"+ 
    6867         "fortress [run] [-test] [-debug [#]] somefile.fss arg ...\n"+ 
    6968         "  Runs somefile.fss through the Fortress interpreter, passing arg ... to the\n"+ 
    7069         "  run method of somefile.fss.\n"+ 
     70         "   -test : first runs test functions associated with the program.\n"+ 
    7171         "   -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 
    7272         "   -debug # : sets debugging to the specified level, where # is a number.\n"+ 
    73          "   -test : first runs test functions associated with the program.\n"+ 
    7473         "\n"+ 
    75          "fortress compile [-debug [#]] [-out file] somefile.fs{s,i}\n"+ 
    76          "  Compile somefile. If compilation succeeds no message will be printed.\n"+ 
     74         "fortress parse [-out file] [-debug [#]] somefile.fs{i,s}\n"+ 
     75         "  Parses a file. If parsing succeeds the message \"Ok\" will be printed.\n"+ 
     76         "  If -out file is given, a message about the file being written to will be printed.\n"+ 
     77         "   -out file : dumps the abstract syntax tree to a file.\n"+ 
    7778         "   -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 
    7879         "   -debug # : sets debugging to the specified level, where # is a number.\n"+ 
    79          "   -out file : dumps the processed abstract syntax tree to a file.\n" + 
    80          "\n"+ 
    81          "fortress parse [-out file] [-debug [#]] somefile.fs{i,s}\n"+ 
    82          "  Parses a file. If the parse succeeds the message \"Ok\" will be printed.\n"+ 
    83          "  If -out file is given, a message about the file being written to will be printed.\n"+ 
    84          "   -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 
    85          "   -debug # : sets debugging to the specified level, where # is a number.\n"+ 
    86          "   -out file : dumps the abstract syntax tree to a file.\n"+ 
    8780         "\n"+ 
    8881         "fortress typecheck [-out file] [-debug [#]] somefile.fs{i,s}\n"+ 
    89          "  Typechecks a file. If the typecheck succeeds no message will be printed.\n"+ 
     82         "  Typechecks a file. If type checking succeeds no message will be printed.\n"+ 
     83         "   -out file : dumps the processed abstract syntax tree to a file.\n"+ 
    9084         "   -debug : enables debugging to the maximum level and prints java stack traces.\n"+ 
    91          "   -debug # : sets debugging to the specified level, where # is a number.\n"+ 
    92          "   -out file : dumps the processed abstract syntax tree to a file\n" 
     85         "   -debug # : sets debugging to the specified level, where # is a number.\n" 
    9386        ); 
    9487    } 
     
    108101        try { 
    109102            String what = tokens[0]; 
    110             if (what.equals("run")) { 
    111                 run(Arrays.asList(tokens).subList(1, tokens.length)); 
    112             } else if (what.equals("compile")) { 
    113                 compile(false, Arrays.asList(tokens).subList(1, tokens.length), Option.<String>none()); 
     103            List<String> args = Arrays.asList(tokens).subList(1, tokens.length); 
     104            if (what.equals("compile")) { 
     105                compile(args, Option.<String>none()); 
     106            } else if (what.equals("run")) { 
     107                run(args); 
     108            } else if ( what.equals("parse" ) ){ 
     109                parse(args, Option.<String>none()); 
    114110            } else if (what.equals("typecheck")) { 
    115111                turnOnTypeChecking(); 
    116                 compile(false, Arrays.asList(tokens).subList(1, tokens.length), Option.<String>none()); 
    117             } else if (what.contains(COMPONENT_SUFFIX) || (what.startsWith("-") && tokens.length > 1)) { 
     112                compile(args, Option.<String>none()); 
     113            } else if (what.contains(ProjectProperties.COMP_SOURCE_SUFFIX) 
     114                       || (what.startsWith("-") && tokens.length > 1)) { 
    118115                // no "run" command. 
    119116                run(Arrays.asList(tokens)); 
    120             } else if ( what.equals("parse" ) ){ 
    121                 parse(Arrays.asList(tokens).subList(1, tokens.length), Option.<String>none()); 
    122117            } else if (what.equals("help")) { 
    123118                printHelpMessage(); 
     
    134129 
    135130    /** 
    136      * Parse a file. If the file parses ok it will say "Ok". If you want a dump then give 
    137      * -out somefile. 
     131     * Parse a file. If the file parses ok it will say "Ok". 
     132     * If you want a dump then give -out somefile. 
    138133     */ 
    139     private static void parse(List<String> args, Option<String> out){ 
     134    private static void parse(List<String> args, Option<String> out) 
     135        throws UserError, InterruptedException, IOException { 
     136        if (args.size() == 0) { 
     137            throw new UserError("Need a file to compile"); 
     138        } 
    140139        String s = args.get(0); 
    141140        List<String> rest = args.subList(1, args.size()); 
     
    155154                rest = rest.subList( 1, rest.size() ); 
    156155            } 
    157             if (s.equals("-test")) test = true; 
    158156            if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 
    159157 
     
    166164    private static void parse( String file, Option<String> out){ 
    167165        try{ 
    168             CompilationUnit unit = Parser.parseFile(apiName(file), new File(file)); 
    169             if ( ! out.isSome() ){ 
    170                 System.out.println( "Ok" ); 
    171             } else { 
     166            CompilationUnit unit = Parser.parseFile(cuName(file), new File(file)); 
     167            System.out.println( "Ok" ); 
     168            if ( out.isSome() ){ 
    172169                try{ 
    173170                    ASTIO.writeJavaAst(unit, out.unwrap()); 
     
    186183    } 
    187184 
     185    private static boolean isInteger( String s ){ 
     186        try{ 
     187            int i = Integer.valueOf(s); 
     188            return i == i; 
     189        } catch ( NumberFormatException n ){ 
     190            return false; 
     191        } 
     192    } 
     193 
    188194    private static boolean isApi(String file){ 
    189         return file.endsWith(API_SUFFIX); 
     195        return file.endsWith(ProjectProperties.API_SOURCE_SUFFIX); 
    190196    } 
    191197 
    192198    private static boolean isComponent(String file){ 
    193         return file.endsWith(COMPONENT_SUFFIX); 
    194     } 
    195  
    196     private static APIName apiName( String file ){ 
    197         if ( file.endsWith( COMPONENT_SUFFIX ) || file.endsWith( API_SUFFIX ) ){ 
     199        return file.endsWith(ProjectProperties.COMP_SOURCE_SUFFIX); 
     200    } 
     201 
     202    private static APIName cuName( String file ){ 
     203        if ( file.endsWith( ProjectProperties.COMP_SOURCE_SUFFIX ) || 
     204             file.endsWith( ProjectProperties.API_SOURCE_SUFFIX ) ){ 
    198205            return NodeFactory.makeAPIName(file.substring( 0, file.lastIndexOf(".") )); 
    199206        } 
    200207        return NodeFactory.makeAPIName(file); 
     208    } 
     209 
     210    /** 
     211     * Compile a file. 
     212     * If you want a dump then give -out somefile. 
     213     */ 
     214    static void compile(List<String> args, Option<String> out) 
     215        throws UserError, InterruptedException, IOException { 
     216        if (args.size() == 0) { 
     217            throw new UserError("Need a file to compile"); 
     218        } 
     219        String s = args.get(0); 
     220        List<String> rest = args.subList(1, args.size()); 
     221 
     222        if (s.startsWith("-")) { 
     223            if (s.equals("-debug")){ 
     224                Debug.setDebug( 99 ); 
     225                if ( ! rest.isEmpty() && isInteger( rest.get( 0 ) ) ){ 
     226                    Debug.setDebug( Integer.valueOf( rest.get( 0 ) ) ); 
     227                    rest = rest.subList( 1, rest.size() ); 
     228                } else { 
     229                    ProjectProperties.debug = true; 
     230                } 
     231            } 
     232            if (s.equals("-out") && ! rest.isEmpty() ){ 
     233                out = Option.<String>some(rest.get(0)); 
     234                rest = rest.subList(1, rest.size()); 
     235            } 
     236            if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 
     237            compile(rest, out); 
     238        } else { 
     239            compile(s, out ); 
     240        } 
    201241    } 
    202242 
     
    211251     * @throws IOException 
    212252     */ 
    213     static void compile(boolean doLink, String s, Option<String> out) throws UserError, InterruptedException, IOException { 
     253    static void compile(String s, Option<String> out) 
     254        throws UserError, InterruptedException { 
    214255        try { 
    215             //FortressRepository fileBasedRepository = new FileBasedRepository(shell.getPwd()); 
    216             FortressRepository repository = new CacheBasedRepository(fortressLocation()); 
     256            FortressRepository repository = new CacheBasedRepository(ProjectProperties.ANALYZED_CACHE_DIR); 
    217257            Fortress fortress = new Fortress(repository); 
    218258 
    219259            Path path = ProjectProperties.SOURCE_PATH; 
    220260 
     261            /* 1) Not for parse 
     262               2) What if there are multiple "/"s 
     263             */ 
    221264            if (s.contains("/")) { 
    222265                String head = s.substring(0, s.lastIndexOf("/")); 
     
    231274                    System.err.println(error); 
    232275                } 
     276            // If there are no errors, all components will have been written to disk by the CacheBasedRepository. 
    233277            } else if ( out.isSome() ){ 
    234278                try{ 
    235279                    if ( isApi(s) ){ 
    236                         ASTIO.writeJavaAst(repository.getApi(apiName(s)).ast(), out.unwrap()); 
     280                        ASTIO.writeJavaAst(repository.getApi(cuName(s)).ast(), out.unwrap()); 
    237281                    } else if ( isComponent(s) ){ 
    238                         ASTIO.writeJavaAst(repository.getComponent(apiName(s)).ast(), out.unwrap()); 
     282                        ASTIO.writeJavaAst(repository.getComponent(cuName(s)).ast(), out.unwrap()); 
    239283                    } else { 
    240284                        System.out.println( "Don't know what kind of file " + s + " is. Append .fsi or .fss." ); 
    241285                    } 
    242                 } catch ( FileNotFoundException e ){ 
    243                     System.out.println( "Could not find file " + s ); 
    244286                } catch ( IOException e ){ 
    245                     System.out.println( "Error while writing " + out.unwrap() ); 
    246                 } 
    247             } 
    248             // If there are no errors, all components will have been written to disk by the FileBasedRepository. 
    249         } 
    250         catch (RepositoryError error) { 
     287                    System.err.println( "Error while writing " + out.unwrap() ); 
     288                } 
     289            } 
     290        } catch (RepositoryError error) { 
    251291            System.err.println(error); 
    252292        } 
    253293    } 
    254294 
    255     static void compile(boolean doLink, List<String> args, Option<String> out) throws UserError, InterruptedException, IOException { 
     295    /** 
     296     * Run a file. 
     297     */ 
     298    static void run(List<String> args) 
     299        throws UserError, IOException, Throwable { 
    256300        if (args.size() == 0) { 
    257             throw new UserError("Need a file to compile"); 
     301            throw new UserError("Need a file to run"); 
    258302        } 
    259303        String s = args.get(0); 
     
    270314                } 
    271315            } 
    272             if (s.equals("-out") && ! rest.isEmpty() ){ 
    273                 out = Option.wrap(rest.get(0)); 
    274                 rest = rest.subList(1, rest.size()); 
    275             } 
    276316            if (s.equals("-test")) test = true; 
    277             if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 
    278             compile( doLink, rest, out); 
    279         } else { 
    280             compile( doLink, s, out ); 
    281         } 
    282     } 
    283  
    284     private static boolean isInteger( String s ){ 
    285         try{ 
    286             int i = Integer.valueOf(s); 
    287             return i == i; 
    288         } catch ( NumberFormatException n ){ 
    289             return false; 
    290         } 
    291     } 
    292  
    293     static void run(List<String> args) throws UserError, IOException, Throwable { 
    294         if (args.size() == 0) { 
    295             throw new UserError("Need a file to run"); 
    296         } 
    297         String s = args.get(0); 
    298         List<String> rest = args.subList(1, args.size()); 
    299  
    300         if (s.startsWith("-")) { 
    301             if (s.equals("-debug")){ 
    302                 Debug.setDebug( 99 ); 
    303                 if ( ! rest.isEmpty() && isInteger( rest.get( 0 ) ) ){ 
    304                     Debug.setDebug( Integer.valueOf( rest.get( 0 ) ) ); 
    305                     rest = rest.subList( 1, rest.size() ); 
    306                 } else { 
    307                     ProjectProperties.debug = true; 
    308                 } 
    309             } 
    310             if (s.equals("-test")) test= true; 
    311317            if (s.equals("-noPreparse")) ProjectProperties.noPreparse = true; 
    312318            run(rest); 
     
    315321        } 
    316322    } 
    317     static void run(String fileName, List<String> args) throws UserError, IOException, Throwable { 
     323 
     324    static void run(String fileName, List<String> args) 
     325        throws UserError, Throwable { 
    318326        try { 
    319             //FortressRepository fileBasedRepository = new FileBasedRepository(shell.getPwd()); 
    320327            Fortress fortress = new Fortress(new CacheBasedRepository(ProjectProperties.ANALYZED_CACHE_DIR)); 
    321328 
     
    328335            } 
    329336 
    330             /* 
    331              * Strip suffix to get a bare component name. 
    332              */ 
    333             if (fileName.endsWith("." + ProjectProperties.COMP_SOURCE_SUFFIX)) { 
    334                 fileName = fileName.substring(0, fileName.length() - ProjectProperties.COMP_SOURCE_SUFFIX.length()); 
    335             } 
    336  
    337             Iterable<? extends StaticError> errors = fortress.run(path, fileName, test, args); 
     337            Iterable<? extends StaticError> errors = fortress.run(path, cuName(fileName), test, args); 
    338338 
    339339            for (StaticError error: errors) { 
    340340                System.err.println(error); 
    341341            } 
    342             // If there are no errors, all components will have been written to disk by the FileBasedRepository. 
     342            // If there are no errors, all components will have been written to disk by the CacheBasedRepository. 
    343343        } catch ( StaticError e ){ 
    344344            System.err.println(e); 
  • trunk/ProjectFortress/src/com/sun/fortress/compiler/Fortress.java

    r2125 r2132  
    316316 } 
    317317 
    318  public Iterable<? extends StaticError>  run(Path path, String componentName, boolean test, List<String> args) { 
     318 public Iterable<? extends StaticError>  run(Path path, APIName componentName, boolean test, List<String> args) { 
    319319  FortressRepository bcr = Driver.specificRepository(path); 
    320320 
    321                 /* 
    322   if (! (_bcr instanceof BatchCachingAnalyzingRepository) ) { 
    323    throw new ProgramError("Please set property fortress.static.analysis=1."); 
    324   } 
    325                 */ 
    326  
    327   // BatchCachingAnalyzingRepository bcr = (BatchCachingAnalyzingRepository) _bcr; 
    328                 /* 
    329   bcr.setVerbose(ProjectProperties.debug); 
    330   Parser.Result result = compileInner(bcr, componentName); 
    331   if (!result.isSuccessful()) { return result.errors(); } 
    332  
    333   if (bcr.verbose()) 
    334    System.err.println("Parsing done."); 
    335                 */ 
    336  
    337321  try { 
    338    CompilationUnit cu = bcr.getLinkedComponent(NodeFactory.makeAPIName(componentName)).ast(); 
     322   CompilationUnit cu = bcr.getLinkedComponent(componentName).ast(); 
    339323   Driver.runProgram(bcr, cu, test, args); 
    340324  } catch (Throwable th) { 
  • trunk/ProjectFortress/src/com/sun/fortress/repository/CacheBasedRepository.java

    r2127 r2132  
    108108 
    109109        try { 
    110  
    111             if (ast instanceof Component) { 
    112                 ASTIO.writeJavaAst(ast, compFileName(ast.getName() )); 
    113             } 
    114             else { // ast instanceof Api 
    115                 ASTIO.writeJavaAst(ast, apiFileName(ast.getName() )); 
    116             } 
     110            ASTIO.writeJavaAst(ast, apiFileName(ast.getName() )); 
    117111        } catch (IOException e) { 
    118112            throw new ShellException(e); 
     
    125119        if (! actual.equals(name)) { 
    126120            boolean flag = actual.equals(name); 
    127             throw new RepositoryError(ast.getName() + " cannot be cached under name " + name); 
     121            throw new RepositoryError(actual + " cannot be cached under name " + name); 
    128122        } 
    129123    } 
     
    143137 
    144138        try { 
    145             name = ast.getName(); 
    146             ASTIO.writeJavaAst(ast, compFileName(name)); 
     139            ASTIO.writeJavaAst(ast, compFileName(ast.getName())); 
    147140        } catch (IOException e) { 
    148141            throw new ShellException(e); 
  • trunk/ProjectFortress/src/com/sun/fortress/unicode/OperatorStuffGenerator.java

    r2119 r2132  
    11/******************************************************************************* 
    2     Copyright 2007 Sun Microsystems, Inc., 
     2    Copyright 2008 Sun Microsystems, Inc., 
    33    4150 Network Circle, Santa Clara, California 95054, U.S.A. 
    44    All rights reserved. 
  • trunk/ProjectFortress/src/com/sun/fortress/useful/ConvenientStrings.java

    r2127 r2132  
    11/******************************************************************************* 
    2     Copyright 2007 Sun Microsystems, Inc., 
     2    Copyright 2008 Sun Microsystems, Inc., 
    33    4150 Network Circle, Santa Clara, California 95054, U.S.A. 
    44    All rights reserved.