- Timestamp:
- 01/06/09 11:28:57 (11 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java
r3289 r3291 36 36 import com.sun.fortress.nodes.Api; 37 37 import com.sun.fortress.nodes.BaseType; 38 import com.sun.fortress.nodes.CompilationUnit; 38 39 import com.sun.fortress.nodes.Decl; 39 40 import com.sun.fortress.nodes.Expr; … … 56 57 import com.sun.fortress.nodes_util.Span; 57 58 import com.sun.fortress.useful.Bijection; 59 import com.sun.fortress.useful.F; 58 60 import com.sun.fortress.useful.HashBijection; 61 import com.sun.fortress.useful.IMultiMap; 62 import com.sun.fortress.useful.MapOfMapOfSet; 59 63 import com.sun.fortress.useful.MultiMap; 60 64 import com.sun.fortress.useful.Useful; … … 72 76 * Given a foreign API Name, what other (foreign) APIs does it import? 73 77 */ 74 M ultiMap<APIName, APIName> generatedImports = new MultiMap<APIName, APIName>();78 MapOfMapOfSet<APIName, APIName, Id> generatedImports = new MapOfMapOfSet<APIName, APIName, Id>(); 75 79 76 80 /** … … 126 130 127 131 static void s(Class cl, APIName api, String str) { 128 specialCases.put(cl, NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, api,str)));132 specialCases.put(cl, NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, str))); 129 133 } 130 134 … … 140 144 s(Double.class, fortLib, "RR64"); 141 145 s(Double.TYPE, fortLib, "RR64"); 142 s(String.class, fortLib, "String"); 146 s(Object.class, fortLib, "Any"); 147 s(String.class, fortLib, "FlatString"); 143 148 s(BigInteger.class, fortLib, "ZZ"); 144 149 specialCases.put(Void.TYPE, NodeFactory.makeVoidType(span)); … … 256 261 Package p = imported_class.getPackage(); 257 262 APIName api_name = packageToAPIName(p); 258 263 Id name = NodeFactory.makeId(span, imported_class.getSimpleName()); 264 259 265 /* Though the class may have been previously referenced, the import 260 266 * may still need to be recorded. Re-recording an existing import 261 267 * is harmless. 262 268 */ 263 generatedImports.putItem(importing_package, api_name );269 generatedImports.putItem(importing_package, api_name, name); 264 270 265 271 /* … … 268 274 javaImplementedAPIs.putItem(api_name,imported_class); 269 275 270 Id name = NodeFactory.makeId(span, imported_class.getSimpleName());271 276 272 277 /* … … 282 287 }; 283 288 284 name = NodeFactory.makeId(api_name, name); 289 // LOSE THE DOTTED REFERENCE, at least for now. 290 // name = NodeFactory.makeId(api_name, name); 285 291 // Note: a TraitType is a reference to a trait. 286 292 return NodeFactory.makeTraitType(span, false, name); … … 365 371 for (Class pt : pts) { 366 372 Type type = recurOnOpaqueClass(importing_package, pt); 367 Id id = NodeFactory.makeId(span, "p"+(i++)); 373 Span param_span = NodeFactory.makeSpan(m.toString() + " p#" + i); 374 Id id = NodeFactory.makeId(param_span, "p"+(i++)); 368 375 Param p = NodeFactory.makeParam(id, type); 369 376 params.add(p); 370 377 } 378 379 Span fn_span = NodeFactory.makeSpan(m.toString()); 371 380 Id id = is_static ? 372 NodeFactory.makeId( span, cl.getSimpleName()+"."+ m.getName()) :373 NodeFactory.makeId( span, m.getName());374 FnDecl fndecl = NodeFactory.makeFnDecl( span, Modifiers.None,381 NodeFactory.makeId(fn_span, cl.getSimpleName()+"."+ m.getName()) : 382 NodeFactory.makeId(fn_span, m.getName()); 383 FnDecl fndecl = NodeFactory.makeFnDecl(fn_span, Modifiers.None, 375 384 id, params,Option.some(return_type), Option.<Expr>none()); 376 385 methodToDecl.put(m, fndecl); … … 399 408 400 409 List<Import> imports = new ArrayList<Import>(); 401 Set<APIName> gi = generatedImports.get(name);410 IMultiMap<APIName, Id> gi = generatedImports.get(name); 402 411 if (gi != null) 403 for (APIName a : gi ) {404 importAnApi(imports, a );412 for (APIName a : gi.keySet()) { 413 importAnApi(imports, a, gi.get(a)); 405 414 } 406 // Implicitly import.407 importAnApi(imports, NodeFactory.makeAPIName(span, "FortressLibrary"));408 415 409 416 List<Decl> decls = new ArrayList<Decl>(); … … 420 427 } 421 428 422 private void importAnApi(List<Import> imports, APIName a) { 423 AliasedAPIName aan = NodeFactory.makeAliasedAPIName(a); 424 /* 425 * Hoping to lie, slightly, to static analysis. This is 426 * technically speaking a "foreign" import, but the import 427 * is already known to the ForeignJava data structures, and 428 * this allows use of fully qualified (hence unambiguous) 429 * references to classes from other packages in the 430 * generated API. 431 * 432 * So, one lie -- no foreign annotation. 433 */ 434 ImportApi iapi = NodeFactory.makeImportApi(span, Option 435 .<String> none(), Useful.list(aan)); 436 imports.add(iapi); 429 private void importAnApi(List<Import> imports, APIName a, Set<Id> items) { 430 431 List<AliasedSimpleName> lasn = new ArrayList<AliasedSimpleName>(); 432 lasn = Useful.applyToAllAppending(items, new F<Id, AliasedSimpleName>() { 433 @Override 434 public AliasedSimpleName apply(Id x) { 435 return NodeFactory.makeAliasedSimpleName(x); 436 } }, lasn); 437 438 ImportNames imp_names = NodeFactory.makeImportNames(span, Option.some("java"), a, lasn); 439 440 imports.add(imp_names); 437 441 } 438 442 … … 441 445 map.put(a, fakeApi(a)); 442 446 } 447 448 dumpGenerated(); 449 443 450 return map; 444 451 } 452 453 public void dumpGenerated() { 454 for (APIName a : javaImplementedAPIs.keySet()) { 455 System.out.println(a); 456 CompilationUnit cu = fakeApi(a).ast(); 457 System.out.println(cu.toStringVerbose()); 458 } 459 } 445 460 446 461 }

