Changeset 2990

Show
Ignore:
Timestamp:
10/28/08 19:15:15 (13 months ago)
Author:
sukyoungryu
Message:

[tool] The api tool reports an error when a declaration in the given component does not have enough type information. If -prepend prependFile is given, the prependFile is prepended in the generated API file.
[copyright] Added ProjectFortress/SunCopyright?.fss to prepend the Sun copyright to generated API files.
[library] Added missing types, fixed mismatches between a component and its API, and reverted some problematic, inadvertent changes.

Location:
trunk
Files:
1 added
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/Library/FortressLibrary.fsi

    r2989 r2990  
    1818api FortressLibrary 
    1919 
     20(* 
    2021import File.FileWriteStream 
     22*) 
    2123 
    2224(************************************************************ 
     
    20952097    getter depth() : ZZ32 
    20962098    getter asJavaString(): String 
     2099(* 
    20972100    getter isBalanced(): Boolean 
    2098      
     2101*) 
     2102 
    20992103    verify() : ()       (* Verify the data structure invaraints of self *) 
    21002104    showStructure() : ()        (* a debugging printout *) 
     
    21252129    **) 
    21262130    split(): Generator[\(ZZ32, String)\] 
    2127      
     2131 
     2132(* 
    21282133    (**  A balanced version of the reciever  *) 
    21292134    balanced(): String ensures {outcome.isBalanced AND outcome = self} 
    2130      
     2135*) 
     2136 
    21312137    (** The operator %||% with at least one String argument converts to string and 
    21322138        appends **) 
     
    21662172    print(self): () 
    21672173    println(self): () 
     2174(* 
    21682175    writeOn(s: FileWriteStream): () 
     2176*) 
    21692177 
    21702178end String 
  • trunk/Library/RangeInternals.fsi

    r2925 r2990  
    1818api RangeInternals 
    1919import TypeProxy.{...} 
    20 roundToStride[\I extends Integral[\I\]\](amt: I, stride: I) 
     20roundToStride[\I extends Integral[\I\]\](amt: I, stride: I): I 
    2121 
    2222atOrAboveGoingUp[\I extends Integral[\I\]\](start: I, bound: I, stride: I): I 
     
    143143    imposeStride(s: I): OpenScalarRange[\I\] 
    144144    atMost(n: I): ScalarRangeWithExtent[\I\] 
     145    opr =(self, b: OpenRange[\I\]): Boolean 
    145146    opr CAP(self, other: ScalarRange[\I\]): ScalarRange[\I\] 
    146147    intersectWithExtent(e: ExtentScalarRange[\I\]): ScalarRangeWithExtent[\I\] 
     
    182183end 
    183184 
    184 open[\I extends Integral[\I\]\]() 
     185open[\I extends Integral[\I\]\](): OpenScalarRange[\I\] 
    185186 
    186187trait ScalarRangeWithExtent[\I extends Integral[\I\]\] 
     
    386387        ScalarRangeWithExtent[\I\], 
    387388        FullRange[\I\] } 
     389    getter extent(): Just[\I\] 
    388390    getter bounds(): CompactFullScalarRange[\I\] 
    389391    getter toString(): String 
     
    401403 
    402404trait FullRange2D[\I extends Integral[\I\], J extends Integral[\J\]\] 
    403     extends { FullRange[\(I, J)\], Range2D[\I, J\], DelegatedIndexed[\(I, J), (I, J)\] } 
     405    extends { FullRange[\(I, J)\], Range2D[\I, J\], DelegatedIndexed[\(I, J), (I, J)\], 
     406        ActualRange2D[\I, J, FullRange2D[\I, J\], FullScalarRange[\I\], 
     407        FullScalarRange[\J\]\] } 
    404408    getter extent(): Just[\(I, J)\] 
    405409    getter generator(): Generator[\(I, J)\] 
     
    416420trait FullRange3D[\I extends Integral[\I\], J extends Integral[\J\], 
    417421        K extends Integral[\K\]\] 
    418     extends { FullRange[\(I, J, K)\], Range3D[\I, J, K\], DelegatedIndexed[\(I, J, K), (I, J, K)\] } 
     422    extends { FullRange[\(I, J, K)\], Range3D[\I, J, K\], DelegatedIndexed[\(I, J, K), (I, J, K)\], 
     423        ActualRange3D[\I, J, K, FullRange3D[\I, J, K\], FullScalarRange[\I\], 
     424        FullScalarRange[\J\], 
     425        FullScalarRange[\K\]\] } 
    419426    getter extent(): Just[\(I, J, K)\] 
    420427    getter generator(): Generator[\(I, J, K)\] 
     
    430437    extends { FullScalarRange[\I\], CompactFullRange[\I\] } 
    431438    getter stride(): I 
    432     getter extent(): Just[\I\] 
    433439    getter size(): ZZ32 
    434440    getter isEmpty(): Boolean 
     
    468474 
    469475object CompactFullRange2D[\I extends Integral[\I\], J extends Integral[\J\]\](l_i: I, l_j: J, r_i: I, r_j: J) 
    470     extends { CompactFullRange[\(I, J)\], FullRange2D[\I, J\], ActualRange2D[\I, J, CompactFullRange2D[\I, J\], CompactFullScalarRange[\I\], 
    471         CompactFullScalarRange[\J\]\] } 
     476    extends { CompactFullRange[\(I, J)\], FullRange2D[\I, J\] } 
    472477    getter lower(): (I, J) 
    473478    getter upper(): (I, J) 
     
    481486    getter range2(): CompactFullScalarRange[\J\] 
    482487 
    483     recombine(i: CompactFullScalarRange[\I\], j: CompactFullScalarRange[\J\]): CompactFullRange2D[\I, J\] 
     488    recombine(i: FullScalarRange[\I\], j: FullScalarRange[\J\]): FullRange2D[\I, J\] 
    484489    dump(): String 
    485490end 
     
    490495object CompactFullRange3D[\I extends Integral[\I\], J extends Integral[\J\], 
    491496        K extends Integral[\K\]\](l_i: I, l_j: J, l_k: K, r_i: I, r_j: J, r_k: K) 
    492     extends { CompactFullRange[\(I, J, K)\], FullRange3D[\I, J, K\], 
    493         ActualRange3D[\I, J, K, CompactFullRange3D[\I, J, K\], 
    494         CompactFullScalarRange[\I\], 
    495         CompactFullScalarRange[\J\], 
    496         CompactFullScalarRange[\K\]\] } 
     497    extends { CompactFullRange[\(I, J, K)\], FullRange3D[\I, J, K\] } 
    497498    getter lower(): (I, J, K) 
    498499    getter upper(): (I, J, K) 
     
    507508    getter range3(): CompactFullScalarRange[\K\] 
    508509 
    509     recombine(i: CompactFullScalarRange[\I\], j: CompactFullScalarRange[\J\], 
    510             k: CompactFullScalarRange[\K\]): CompactFullRange3D[\I, J, K\] 
     510    recombine(i: FullScalarRange[\I\], j: FullScalarRange[\J\], k: FullScalarRange[\K\]): FullRange3D[\I, J, K\] 
    511511    dump(): String 
    512512end 
     
    552552 
    553553object StridedFullRange2D[\I extends Integral[\I\], J extends Integral[\J\]\](l_i: I, l_j: J, r_i: I, r_j: J, str_i: I, str_j: J) 
    554     extends { StridedFullRange[\(I, J)\], FullRange2D[\I, J\], ActualRange2D[\I, J, StridedFullRange2D[\I, J\], FullScalarRange[\I\], 
    555         FullScalarRange[\J\]\] } 
     554    extends { StridedFullRange[\(I, J)\], FullRange2D[\I, J\] } 
    556555    getter bounds(): CompactFullRange2D[\I, J\] 
    557556    getter indices(): Generator[\(I, J)\] 
     
    574573        str_j: J, 
    575574        str_k: K) 
    576     extends { StridedFullRange[\(I, J, K)\], FullRange3D[\I, J, K\], 
    577         ActualRange3D[\I, J, K, StridedFullRange3D[\I, J, K\], 
    578         FullScalarRange[\I\], 
    579         FullScalarRange[\J\], 
    580         FullScalarRange[\K\]\] } 
     575    extends { StridedFullRange[\(I, J, K)\], FullRange3D[\I, J, K\] } 
    581576    getter bounds(): CompactFullRange3D[\I, J, K\] 
    582577    getter indices(): Generator[\(I, J, K)\] 
  • trunk/Library/RangeInternals.fss

    r2944 r2990  
    3434 
    3535(* Round to nearest multiple of stride towards 0. *) 
    36 roundToStride[\I extends Integral[\I\]\](amt:I, stride:I) = 
     36roundToStride[\I extends Integral[\I\]\](amt:I, stride:I): I = 
    3737    stride (amt DIV stride) 
    3838 
     
    344344end 
    345345 
    346 open[\I extends Integral[\I\]\]() = OpenScalarRange[\I\](1) 
     346open[\I extends Integral[\I\]\](): OpenScalarRange[\I\] = OpenScalarRange[\I\](1) 
    347347 
    348348trait ScalarRangeWithExtent[\I extends Integral[\I\]\] 
  • trunk/ProjectFortress/src/com/sun/fortress/Shell.java

    r2970 r2990  
    4545import com.sun.fortress.nodes.CompilationUnit; 
    4646import com.sun.fortress.nodes.Component; 
     47import com.sun.fortress.nodes.Node; 
    4748import com.sun.fortress.nodes_util.NodeFactory; 
    4849import com.sun.fortress.nodes_util.ASTIO; 
     
    115116        System.err.println(" test [-verbose] [-debug [type]* [#]] somefile.fss..."); 
    116117        System.err.println(""); 
    117         System.err.println(" api [-out file] [-debug [type]* [#]] somefile.fss"); 
     118        System.err.println(" api [-out file] [-prepend prependFile] [-debug [type]* [#]] somefile.fss"); 
    118119        System.err.println(" compare [-debug [type]* [#]] somefile.fss anotherfile.fss"); 
    119120        System.err.println(" unparse [-unqualified] [-unmangle] [-out file] [-debug [type]* [#]] somefile.tf{s,i}"); 
     
    158159         "\n"+ 
    159160         "\n"+ 
    160          "fortress api [-out file] [-debug [type]* [#]] somefile.fss\n"+ 
     161         "fortress api [-out file] [-prepend prependFile] [-debug [type]* [#]] somefile.fss\n"+ 
    161162         "  Automatically generate an API from a component.\n"+ 
    162163         "  If -out file is given, a message about the file being written to will be printed.\n"+ 
     164         "  If -prepend prependFile is given, the prependFile is prepended to the generated API.\n"+ 
    163165         "\n"+ 
    164166         "fortress compare [-debug [type]* [#]] somefile.fss anotherfile.fss\n"+ 
     
    238240                run(args); 
    239241            } else if ( what.equals("api" ) ){ 
    240                 api(args, Option.<String>none()); 
     242                api(args, Option.<String>none(), Option.<String>none()); 
    241243            } else if ( what.equals("compare" ) ){ 
    242244                compare(args); 
     
    292294     * Automatically generate an API from a component. 
    293295     */ 
    294     private static void api(List<String> args, Option<String> out) 
     296    private static void api(List<String> args, Option<String> out, Option<String> prepend) 
    295297        throws UserError, InterruptedException, IOException { 
    296298        if (args.size() == 0) { 
     
    308310                rest = rest.subList( 1, rest.size() ); 
    309311            } 
     312            else if (s.equals("-prepend") && ! rest.isEmpty() ){ 
     313                prepend = Option.<String>some(rest.get(0)); 
     314                rest = rest.subList( 1, rest.size() ); 
     315            } 
    310316            else 
    311317                invalidFlag(s, "api"); 
    312             api( rest, out ); 
     318            api( rest, out, prepend ); 
    313319        } else { 
    314             api( s, out ); 
    315         } 
    316     } 
    317  
    318     private static void api( String file, Option<String> out ) 
     320            api( s, out, prepend ); 
     321        } 
     322    } 
     323 
     324    private static void api( String file, Option<String> out, Option<String> prepend ) 
    319325        throws UserError, IOException{ 
    320326        if (! isComponent(file)) { 
     
    323329        } 
    324330        Component c = (Component) Parser.parseFile(cuName(file), new File(file)); 
    325         Api a = (Api) c.accept( ApiMaker.ONLY ); 
     331        Option<Node> result = c.accept( ApiMaker.ONLY ); 
     332        if ( result.isNone() ) 
     333            throw new UserError("api command needs a Fortress component file."); 
     334        Api a = (Api) result.unwrap(); 
    326335        String code = a.accept( new FortressAstToConcrete() ); 
    327336        if ( out.isSome() ){ 
    328337            try{ 
    329338                BufferedWriter writer = Useful.filenameToBufferedWriter(out.unwrap()); 
     339                if ( prepend.isSome() ) { 
     340                    BufferedReader reader = Useful.filenameToBufferedReader(prepend.unwrap()); 
     341                    String line = reader.readLine(); 
     342                    while ( line != null ) { 
     343                        writer.write( line + "\n" ); 
     344                        line = reader.readLine(); 
     345                    } 
     346                } 
    330347                writer.write(code); 
    331348                writer.close(); 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ApiMaker.java

    r2916 r2990  
    2020import java.util.ArrayList; 
    2121import com.sun.fortress.nodes.*; 
     22import edu.rice.cs.plt.tuple.Option; 
     23import static com.sun.fortress.exceptions.ProgramError.error; 
    2224 
    2325/** 
    2426 * A visitor that makes an api from a component. 
    2527 */ 
    26 public final class ApiMaker extends NodeUpdateVisitor { 
     28public final class ApiMaker extends NodeDepthFirstVisitor<Option<Node>> { 
    2729    private boolean inTrait = false; 
    2830    private boolean inObject = false; 
     
    4143    } 
    4244 
    43     private Boolean isPrivate(AbsDecl decl) { 
     45    private Boolean isPrivate(Decl decl) { 
    4446        return decl.accept( new NodeDepthFirstVisitor<Boolean>() { 
    45                 @Override public Boolean forAbsTraitDecl(AbsTraitDecl that) { 
     47                @Override public Boolean forTraitDecl(TraitDecl that) { 
    4648                    return new Boolean(containsPrivate(that.getMods())); 
    4749                } 
    4850 
    49                 @Override public Boolean forAbsObjectDecl(AbsObjectDecl that) { 
     51                @Override public Boolean forObjectDecl(ObjectDecl that) { 
    5052                    return new Boolean(containsPrivate(that.getMods())); 
    5153                } 
    5254 
    53                 @Override public Boolean forAbsVarDecl(AbsVarDecl that) { 
     55                @Override public Boolean forVarDecl(VarDecl that) { 
    5456                    List<LValueBind> lhs = that.getLhs(); 
    5557                    boolean result = false; 
     
    6163                } 
    6264 
    63                 @Override public Boolean forAbsFnDecl(AbsFnDecl that) { 
     65                @Override public Boolean forFnDef(FnDef that) { 
    6466                    return new Boolean(containsPrivate(that.getMods())); 
    6567                } 
     
    7577        List<AbsDecl> result = new java.util.ArrayList<AbsDecl>(0); 
    7678        for (Decl elt : that) { 
    77             AbsDecl elt_result = (AbsDecl) elt.accept(this); 
    78             if ( ! isPrivate(elt_result) ) { 
    79                 result.add(elt_result); 
    80             } 
     79            Option<Node> elt_result = elt.accept(this); 
     80            if ( elt_result.isSome() ) 
     81                result.add((AbsDecl)elt_result.unwrap()); 
    8182        } 
    8283        return result; 
    8384    } 
    8485 
    85     public Api forComponent(Component that) { 
    86         return new Api(that.getSpan(), 
    87                        that.getName(), 
    88                        that.getImports(), 
    89                        declsToAbsDecls(that.getDecls())); 
    90     } 
    91  
    92     public AbsTraitDecl forTraitDecl(TraitDecl that) { 
    93         inTrait = true; 
    94         List<AbsDecl> absDecls = declsToAbsDecls(that.getDecls()); 
    95         inTrait = false; 
    96         return new AbsTraitDecl(that.getSpan(), 
    97                                 that.getMods(), 
    98                                 that.getName(), 
    99                                 that.getStaticParams(), 
    100                                 that.getExtendsClause(), 
    101                                 that.getWhere(), 
    102                                 that.getExcludes(), 
    103                                 that.getComprises(), 
    104                                 absDecls); 
    105     } 
    106  
    107     public AbsObjectDecl forObjectDecl(ObjectDecl that) { 
    108         inObject = true; 
    109         List<AbsDecl> absDecls = declsToAbsDecls(that.getDecls()); 
    110         inObject = false; 
    111         return new AbsObjectDecl(that.getSpan(), 
    112                                  that.getMods(), 
    113                                  that.getName(), 
    114                                  that.getStaticParams(), 
    115                                  that.getExtendsClause(), 
    116                                  that.getWhere(), 
    117                                  that.getParams(), 
    118                                  that.getThrowsClause(), 
    119                                  that.getContract(), 
    120                                  absDecls); 
     86    public Option<Node> forComponent(Component that) { 
     87        return Option.<Node>some(new Api(that.getSpan(), 
     88                                         that.getName(), 
     89                                         that.getImports(), 
     90                                         declsToAbsDecls(that.getDecls()))); 
     91    } 
     92 
     93    public Option<Node> forTraitDecl(TraitDecl that) { 
     94        if ( ! isPrivate(that) ) { 
     95            inTrait = true; 
     96            List<AbsDecl> absDecls = declsToAbsDecls(that.getDecls()); 
     97            inTrait = false; 
     98            return Option.<Node>some(new AbsTraitDecl(that.getSpan(), 
     99                                                      that.getMods(), 
     100                                                      that.getName(), 
     101                                                      that.getStaticParams(), 
     102                                                      that.getExtendsClause(), 
     103                                                      that.getWhere(), 
     104                                                      that.getExcludes(), 
     105                                                      that.getComprises(), 
     106                                                      absDecls)); 
     107        } else return Option.<Node>none(); 
     108    } 
     109 
     110    public Option<Node> forObjectDecl(ObjectDecl that) { 
     111        if ( ! isPrivate(that) ) { 
     112            inObject = true; 
     113            List<AbsDecl> absDecls = declsToAbsDecls(that.getDecls()); 
     114            inObject = false; 
     115            return Option.<Node>some(new AbsObjectDecl(that.getSpan(), 
     116                                                       that.getMods(), 
     117                                                       that.getName(), 
     118                                                       that.getStaticParams(), 
     119                                                       that.getExtendsClause(), 
     120                                                       that.getWhere(), 
     121                                                       that.getParams(), 
     122                                                       that.getThrowsClause(), 
     123                                                       that.getContract(), 
     124                                                       absDecls)); 
     125        } else return Option.<Node>none(); 
    121126    } 
    122127 
     
    124129       the APIMaker leaves the "var" modifier off in the generated API. 
    125130     */ 
    126     public AbsVarDecl forVarDecl(VarDecl that) { 
    127         List<LValueBind> lhs = new ArrayList<LValueBind>(); 
    128         for (LValueBind lvb : that.getLhs()) { 
    129             if ( inObject && NodeUtil.isVar(lvb.getMods()) ) { 
    130                 List<Modifier> mods = new ArrayList<Modifier>(); 
    131                 for (Modifier mod : lvb.getMods()) { 
    132                     if ( ! (mod instanceof ModifierVar) ) { 
    133                         mods.add( mod ); 
     131    public Option<Node> forVarDecl(VarDecl that) { 
     132        if ( ! isPrivate(that) ) { 
     133            List<LValueBind> lhs = new ArrayList<LValueBind>(); 
     134            for (LValueBind lvb : that.getLhs()) { 
     135                if ( lvb.getType().isNone() ) 
     136                    return error(lvb, "The type of " + lvb.getName() + 
     137                                 " is required to generate an API."); 
     138                if ( inObject && NodeUtil.isVar(lvb.getMods()) ) { 
     139                    List<Modifier> mods = new ArrayList<Modifier>(); 
     140                    for (Modifier mod : lvb.getMods()) { 
     141                        if ( ! (mod instanceof ModifierVar) ) { 
     142                            mods.add( mod ); 
     143                        } 
    134144                    } 
    135                 } 
    136                 lhs.add( NodeFactory.makeLValue(lvb, mods, false) ); 
    137             } else 
    138                 lhs.add( lvb ); 
    139         } 
    140         return new AbsVarDecl(that.getSpan(), lhs); 
    141     } 
    142  
    143     public AbsFnDecl forFnDef(FnDef that) { 
    144         return new AbsFnDecl(that.getSpan(), 
    145                              that.getMods(), 
    146                              that.getName(), 
    147                              that.getStaticParams(), 
    148                              that.getParams(), 
    149                              that.getReturnType(), 
    150                              that.getThrowsClause(), 
    151                              that.getWhere(), 
    152                              that.getContract(), 
    153                              that.getSelfName()); 
     145                    lhs.add( NodeFactory.makeLValue(lvb, mods, false) ); 
     146                } else 
     147                    lhs.add( lvb ); 
     148            } 
     149            return Option.<Node>some(new AbsVarDecl(that.getSpan(), lhs)); 
     150        } else return Option.<Node>none(); 
     151    } 
     152 
     153    public Option<Node> forFnDef(FnDef that) { 
     154        if ( ! isPrivate(that) ) { 
     155            if ( that.getReturnType().isNone() ) 
     156                return error(that, "The return type of " + that.getName() + 
     157                             " is required to generate an API."); 
     158            for ( Param p : that.getParams() ) { 
     159                if ( p instanceof NormalParam && 
     160                     ((NormalParam)p).getType().isNone() && 
     161                     ! p.getName().getText().equals("self") ) 
     162                    return error(p, "The type of " + p.getName() + 
     163                                 " is required to generate an API."); 
     164            } 
     165            return Option.<Node>some(new AbsFnDecl(that.getSpan(), 
     166                                                   that.getMods(), 
     167                                                   that.getName(), 
     168                                                   that.getStaticParams(), 
     169                                                   that.getParams(), 
     170                                                   that.getReturnType(), 
     171                                                   that.getThrowsClause(), 
     172                                                   that.getWhere(), 
     173                                                   that.getContract(), 
     174                                                   that.getSelfName())); 
     175        } else return Option.<Node>none(); 
    154176    } 
    155177 
     
    157179       the APIMaker puts the "abstract" modifier in the generated API. 
    158180     */ 
    159     public AbsFnDecl forAbsFnDecl(AbsFnDecl that) { 
    160         List<Modifier> mods = that.getMods(); 
    161         if ( inTrait ) { 
    162             mods.add(0, new ModifierAbstract(that.getSpan())); 
    163         } 
    164         return new AbsFnDecl(that.getSpan(), 
    165                              mods, 
    166                              that.getName(), 
    167                              that.getStaticParams(), 
    168                              that.getParams(), 
    169                              that.getReturnType(), 
    170                              that.getThrowsClause(), 
    171                              that.getWhere(), 
    172                              that.getContract(), 
    173                              that.getSelfName()); 
     181    public Option<Node> forAbsFnDecl(AbsFnDecl that) { 
     182        if ( ! isPrivate(that) ) { 
     183            if ( that.getReturnType().isNone() ) 
     184                return error(that, "The return type of " + that.getName() + 
     185                             " is required to generate an API."); 
     186            for ( Param p : that.getParams() ) { 
     187                if ( p instanceof NormalParam && 
     188                     ((NormalParam)p).getType().isNone() && 
     189                     ! p.getName().getText().equals("self") ) 
     190                    return error(p, "The type of " + p.getName() + 
     191                                 " is required to generate an API."); 
     192            } 
     193            List<Modifier> mods = that.getMods(); 
     194            if ( inTrait ) { 
     195                mods.add(0, new ModifierAbstract(that.getSpan())); 
     196            } 
     197            return Option.<Node>some(new AbsFnDecl(that.getSpan(), 
     198                                                   mods, 
     199                                                   that.getName(), 
     200                                                   that.getStaticParams(), 
     201                                                   that.getParams(), 
     202                                                   that.getReturnType(), 
     203                                                   that.getThrowsClause(), 
     204                                                   that.getWhere(), 
     205                                                   that.getContract(), 
     206                                                   that.getSelfName())); 
     207        } else return Option.<Node>none(); 
    174208    } 
    175209}