Changeset 2990
- Timestamp:
- 10/28/08 19:15:15 (13 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 5 modified
-
Library/FortressLibrary.fsi (modified) (4 diffs)
-
Library/RangeInternals.fsi (modified) (13 diffs)
-
Library/RangeInternals.fss (modified) (2 diffs)
-
ProjectFortress/SunCopyright.fss (added)
-
ProjectFortress/src/com/sun/fortress/Shell.java (modified) (7 diffs)
-
ProjectFortress/src/com/sun/fortress/nodes_util/ApiMaker.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Library/FortressLibrary.fsi
r2989 r2990 18 18 api FortressLibrary 19 19 20 (* 20 21 import File.FileWriteStream 22 *) 21 23 22 24 (************************************************************ … … 2095 2097 getter depth() : ZZ32 2096 2098 getter asJavaString(): String 2099 (* 2097 2100 getter isBalanced(): Boolean 2098 2101 *) 2102 2099 2103 verify() : () (* Verify the data structure invaraints of self *) 2100 2104 showStructure() : () (* a debugging printout *) … … 2125 2129 **) 2126 2130 split(): Generator[\(ZZ32, String)\] 2127 2131 2132 (* 2128 2133 (** A balanced version of the reciever *) 2129 2134 balanced(): String ensures {outcome.isBalanced AND outcome = self} 2130 2135 *) 2136 2131 2137 (** The operator %||% with at least one String argument converts to string and 2132 2138 appends **) … … 2166 2172 print(self): () 2167 2173 println(self): () 2174 (* 2168 2175 writeOn(s: FileWriteStream): () 2176 *) 2169 2177 2170 2178 end String -
trunk/Library/RangeInternals.fsi
r2925 r2990 18 18 api RangeInternals 19 19 import TypeProxy.{...} 20 roundToStride[\I extends Integral[\I\]\](amt: I, stride: I) 20 roundToStride[\I extends Integral[\I\]\](amt: I, stride: I): I 21 21 22 22 atOrAboveGoingUp[\I extends Integral[\I\]\](start: I, bound: I, stride: I): I … … 143 143 imposeStride(s: I): OpenScalarRange[\I\] 144 144 atMost(n: I): ScalarRangeWithExtent[\I\] 145 opr =(self, b: OpenRange[\I\]): Boolean 145 146 opr CAP(self, other: ScalarRange[\I\]): ScalarRange[\I\] 146 147 intersectWithExtent(e: ExtentScalarRange[\I\]): ScalarRangeWithExtent[\I\] … … 182 183 end 183 184 184 open[\I extends Integral[\I\]\]() 185 open[\I extends Integral[\I\]\](): OpenScalarRange[\I\] 185 186 186 187 trait ScalarRangeWithExtent[\I extends Integral[\I\]\] … … 386 387 ScalarRangeWithExtent[\I\], 387 388 FullRange[\I\] } 389 getter extent(): Just[\I\] 388 390 getter bounds(): CompactFullScalarRange[\I\] 389 391 getter toString(): String … … 401 403 402 404 trait 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\]\] } 404 408 getter extent(): Just[\(I, J)\] 405 409 getter generator(): Generator[\(I, J)\] … … 416 420 trait FullRange3D[\I extends Integral[\I\], J extends Integral[\J\], 417 421 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\]\] } 419 426 getter extent(): Just[\(I, J, K)\] 420 427 getter generator(): Generator[\(I, J, K)\] … … 430 437 extends { FullScalarRange[\I\], CompactFullRange[\I\] } 431 438 getter stride(): I 432 getter extent(): Just[\I\]433 439 getter size(): ZZ32 434 440 getter isEmpty(): Boolean … … 468 474 469 475 object 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\] } 472 477 getter lower(): (I, J) 473 478 getter upper(): (I, J) … … 481 486 getter range2(): CompactFullScalarRange[\J\] 482 487 483 recombine(i: CompactFullScalarRange[\I\], j: CompactFullScalarRange[\J\]): CompactFullRange2D[\I, J\]488 recombine(i: FullScalarRange[\I\], j: FullScalarRange[\J\]): FullRange2D[\I, J\] 484 489 dump(): String 485 490 end … … 490 495 object CompactFullRange3D[\I extends Integral[\I\], J extends Integral[\J\], 491 496 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\] } 497 498 getter lower(): (I, J, K) 498 499 getter upper(): (I, J, K) … … 507 508 getter range3(): CompactFullScalarRange[\K\] 508 509 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\] 511 511 dump(): String 512 512 end … … 552 552 553 553 object 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\] } 556 555 getter bounds(): CompactFullRange2D[\I, J\] 557 556 getter indices(): Generator[\(I, J)\] … … 574 573 str_j: J, 575 574 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\] } 581 576 getter bounds(): CompactFullRange3D[\I, J, K\] 582 577 getter indices(): Generator[\(I, J, K)\] -
trunk/Library/RangeInternals.fss
r2944 r2990 34 34 35 35 (* Round to nearest multiple of stride towards 0. *) 36 roundToStride[\I extends Integral[\I\]\](amt:I, stride:I) =36 roundToStride[\I extends Integral[\I\]\](amt:I, stride:I): I = 37 37 stride (amt DIV stride) 38 38 … … 344 344 end 345 345 346 open[\I extends Integral[\I\]\]() = OpenScalarRange[\I\](1)346 open[\I extends Integral[\I\]\](): OpenScalarRange[\I\] = OpenScalarRange[\I\](1) 347 347 348 348 trait ScalarRangeWithExtent[\I extends Integral[\I\]\] -
trunk/ProjectFortress/src/com/sun/fortress/Shell.java
r2970 r2990 45 45 import com.sun.fortress.nodes.CompilationUnit; 46 46 import com.sun.fortress.nodes.Component; 47 import com.sun.fortress.nodes.Node; 47 48 import com.sun.fortress.nodes_util.NodeFactory; 48 49 import com.sun.fortress.nodes_util.ASTIO; … … 115 116 System.err.println(" test [-verbose] [-debug [type]* [#]] somefile.fss..."); 116 117 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"); 118 119 System.err.println(" compare [-debug [type]* [#]] somefile.fss anotherfile.fss"); 119 120 System.err.println(" unparse [-unqualified] [-unmangle] [-out file] [-debug [type]* [#]] somefile.tf{s,i}"); … … 158 159 "\n"+ 159 160 "\n"+ 160 "fortress api [-out file] [- debug [type]* [#]] somefile.fss\n"+161 "fortress api [-out file] [-prepend prependFile] [-debug [type]* [#]] somefile.fss\n"+ 161 162 " Automatically generate an API from a component.\n"+ 162 163 " 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"+ 163 165 "\n"+ 164 166 "fortress compare [-debug [type]* [#]] somefile.fss anotherfile.fss\n"+ … … 238 240 run(args); 239 241 } else if ( what.equals("api" ) ){ 240 api(args, Option.<String>none() );242 api(args, Option.<String>none(), Option.<String>none()); 241 243 } else if ( what.equals("compare" ) ){ 242 244 compare(args); … … 292 294 * Automatically generate an API from a component. 293 295 */ 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) 295 297 throws UserError, InterruptedException, IOException { 296 298 if (args.size() == 0) { … … 308 310 rest = rest.subList( 1, rest.size() ); 309 311 } 312 else if (s.equals("-prepend") && ! rest.isEmpty() ){ 313 prepend = Option.<String>some(rest.get(0)); 314 rest = rest.subList( 1, rest.size() ); 315 } 310 316 else 311 317 invalidFlag(s, "api"); 312 api( rest, out );318 api( rest, out, prepend ); 313 319 } 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 ) 319 325 throws UserError, IOException{ 320 326 if (! isComponent(file)) { … … 323 329 } 324 330 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(); 326 335 String code = a.accept( new FortressAstToConcrete() ); 327 336 if ( out.isSome() ){ 328 337 try{ 329 338 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 } 330 347 writer.write(code); 331 348 writer.close(); -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ApiMaker.java
r2916 r2990 20 20 import java.util.ArrayList; 21 21 import com.sun.fortress.nodes.*; 22 import edu.rice.cs.plt.tuple.Option; 23 import static com.sun.fortress.exceptions.ProgramError.error; 22 24 23 25 /** 24 26 * A visitor that makes an api from a component. 25 27 */ 26 public final class ApiMaker extends Node UpdateVisitor{28 public final class ApiMaker extends NodeDepthFirstVisitor<Option<Node>> { 27 29 private boolean inTrait = false; 28 30 private boolean inObject = false; … … 41 43 } 42 44 43 private Boolean isPrivate( AbsDecl decl) {45 private Boolean isPrivate(Decl decl) { 44 46 return decl.accept( new NodeDepthFirstVisitor<Boolean>() { 45 @Override public Boolean for AbsTraitDecl(AbsTraitDecl that) {47 @Override public Boolean forTraitDecl(TraitDecl that) { 46 48 return new Boolean(containsPrivate(that.getMods())); 47 49 } 48 50 49 @Override public Boolean for AbsObjectDecl(AbsObjectDecl that) {51 @Override public Boolean forObjectDecl(ObjectDecl that) { 50 52 return new Boolean(containsPrivate(that.getMods())); 51 53 } 52 54 53 @Override public Boolean for AbsVarDecl(AbsVarDecl that) {55 @Override public Boolean forVarDecl(VarDecl that) { 54 56 List<LValueBind> lhs = that.getLhs(); 55 57 boolean result = false; … … 61 63 } 62 64 63 @Override public Boolean for AbsFnDecl(AbsFnDeclthat) {65 @Override public Boolean forFnDef(FnDef that) { 64 66 return new Boolean(containsPrivate(that.getMods())); 65 67 } … … 75 77 List<AbsDecl> result = new java.util.ArrayList<AbsDecl>(0); 76 78 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()); 81 82 } 82 83 return result; 83 84 } 84 85 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(); 121 126 } 122 127 … … 124 129 the APIMaker leaves the "var" modifier off in the generated API. 125 130 */ 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 } 134 144 } 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(); 154 176 } 155 177 … … 157 179 the APIMaker puts the "abstract" modifier in the generated API. 158 180 */ 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(); 174 208 } 175 209 }

