Changeset 3291
- Timestamp:
- 01/06/09 11:28:57 (11 months ago)
- Location:
- trunk/ProjectFortress/src/com/sun/fortress
- Files:
-
- 1 added
- 6 modified
-
interpreter/Driver.java (modified) (1 diff)
-
repository/ForeignJava.java (modified) (12 diffs)
-
useful/IMultiMap.java (modified) (2 diffs)
-
useful/MapOfMapOfSet.java (added)
-
useful/MultiMap.java (modified) (3 diffs)
-
useful/UsefulJUTest.java (modified) (2 diffs)
-
useful/UsefulPLT.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java
r3252 r3291 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. -
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 } -
trunk/ProjectFortress/src/com/sun/fortress/useful/IMultiMap.java
r2725 r3291 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 29 29 public Set<V> putItem(K k, V v); 30 30 31 public Set<V> putItems(K k, Set<V> vs);31 public Set<V> putItems(K k, Collection<V> vs); 32 32 33 33 public Set<V> removeItem(K k, V v); 34 35 public Set<V> putKey(K k); 34 36 35 37 public final static IMultiMap EMPTY_MULTIMAP = new IMultiMap() { 36 38 private <T> T error() { throw new IllegalStateException("Empty IMultiMap is immutable."); } 37 39 public void addInverse(Map m) { error(); } 40 public Set putKey(Object k) { return error(); } 38 41 public Set putItem(Object k, Object v) { return error(); } 39 public Set putItems(Object k, Setvs) { return error(); }42 public Set putItems(Object k, Collection vs) { return error(); } 40 43 public Set removeItem(Object k, Object v) { return error(); } 41 44 public void clear() { error(); } -
trunk/ProjectFortress/src/com/sun/fortress/useful/MultiMap.java
r3259 r3291 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 18 18 package com.sun.fortress.useful; 19 19 20 import java.util.Collection; 20 21 import java.util.HashMap; 21 22 import java.util.HashSet; … … 77 78 return s; 78 79 } 79 public Set<V> putItems(K k, Set<V> vs) {80 public Set<V> putItems(K k, Collection<V> vs) { 80 81 Set<V> s = get(k); 81 82 if (s == null) { -
trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulJUTest.java
r3259 r3291 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 227 227 map.remove("too"); 228 228 assertEquals(true, map.validate()); 229 230 231 } 229 } 230 231 public void testMOMOS() { 232 MapOfMapOfSet<String, String, String> reln = new MapOfMapOfSet<String, String, String>(); 233 234 reln.putItem("eats", "cow", "grass"); 235 reln.putItem("eats", "cow", "corn"); 236 reln.putItem("eats", "rat", "cheese"); 237 reln.putItem("chases", "dog", "cat"); 238 reln.putItem("chases", "cat", "rat"); 239 240 IMultiMap<String, String> eats = reln.get("eats"); 241 IMultiMap<String, String> chases = reln.get("chases"); 242 243 assertEquals(eats.get("cow"), Useful.set("grass", "corn")); 244 assertEquals(eats.get("rat"), Useful.set("cheese")); 245 assertEquals(chases.get("dog"), Useful.set("cat")); 246 assertEquals(chases.get("cat"), Useful.set("rat")); 247 } 248 232 249 } -
trunk/ProjectFortress/src/com/sun/fortress/useful/UsefulPLT.java
r3134 r3291 1 1 /******************************************************************************* 2 Copyright 200 8Sun Microsystems, Inc.,2 Copyright 2009 Sun Microsystems, Inc., 3 3 4150 Network Circle, Santa Clara, California 95054, U.S.A. 4 4 All rights reserved. … … 109 109 public void addInverse(Map<V, K> m) { error(); } 110 110 public Set<V> putItem(K k, V v) { return error(); } 111 public Set<V> putItems(K k, Set<V> vs) { return error(); }111 public Set<V> putItems(K k, Collection<V> vs) { return error(); } 112 112 public Set<V> removeItem(K k, V v) { return error(); } 113 public Set<V> putKey(K k) {return error();} 113 114 }; 114 115 }

