Changeset 4291 for trunk/ProjectFortress/src
- Timestamp:
- 10/26/09 20:28:38 (4 weeks ago)
- Location:
- trunk/ProjectFortress/src/com/sun/fortress
- Files:
-
- 23 modified
-
compiler/OverloadRewriteVisitor.java (modified) (2 diffs)
-
compiler/codegen/CodeGen.java (modified) (17 diffs)
-
compiler/disambiguator/NameEnv.java (modified) (1 diff)
-
compiler/disambiguator/TopLevelEnv.java (modified) (2 diffs)
-
compiler/index/Coercion.java (modified) (1 diff)
-
compiler/index/Constructor.java (modified) (1 diff)
-
compiler/index/DeclaredFunction.java (modified) (1 diff)
-
compiler/index/DeclaredMethod.java (modified) (1 diff)
-
compiler/index/FieldGetterOrSetterMethod.java (modified) (1 diff)
-
compiler/index/Functional.java (modified) (1 diff)
-
compiler/index/FunctionalMethod.java (modified) (1 diff)
-
compiler/nativeInterface/FortressMethodAdapter.java (modified) (4 diffs)
-
compiler/nativeInterface/FortressTransformer.java (modified) (2 diffs)
-
exceptions/InterpreterBug.java (modified) (1 diff)
-
nodes_util/NodeFactory.java (modified) (6 diffs)
-
repository/ForeignJava.java (modified) (7 diffs)
-
runtimeSystem/Naming.java (modified) (1 diff)
-
scala_src/disambiguator/ExprDisambiguator.scala (modified) (3 diffs)
-
scala_src/linker/HygienicRenamer.scala (modified) (1 diff)
-
scala_src/typechecker/STypeChecker.scala (modified) (1 diff)
-
scala_src/typechecker/impls/Functionals.scala (modified) (3 diffs)
-
scala_src/typechecker/staticenv/STypeEnv.scala (modified) (9 diffs)
-
scala_src/useful/STypesUtil.scala (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/src/com/sun/fortress/compiler/OverloadRewriteVisitor.java
r4192 r4291 69 69 if (rc != 0) 70 70 return rc; 71 Option< Type> ot1 = o1.getType();72 Option< Type> ot2 = o2.getType();71 Option<ArrowType> ot1 = o1.getType(); 72 Option<ArrowType> ot2 = o2.getType(); 73 73 if (ot1.isNone()) { 74 74 if (ot2.isNone()) { … … 80 80 return 1; 81 81 } else { 82 Type t1 = ot1.unwrap();83 Type t2 = ot2.unwrap();82 ArrowType t1 = ot1.unwrap(); 83 ArrowType t2 = ot2.unwrap(); 84 84 return NodeComparator.typeComparer.compare(t1, t2); 85 85 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/codegen/CodeGen.java
r4283 r4291 62 62 import com.sun.fortress.useful.Useful; 63 63 64 import edu.rice.cs.plt.collect.CollectUtil; 65 import edu.rice.cs.plt.collect.Relation; 66 64 67 // Note we have a name clash with org.objectweb.asm.Type 65 68 // and com.sun.fortress.nodes.Type. If anyone has a better … … 80 83 private final FreeVariables fv; 81 84 private final Map<IdOrOpOrAnonymousName, MultiMap<Integer, Function>> topLevelOverloads; 85 private final MultiMap<String, Function> exportedToUnambiguous; 82 86 private Set<String> overloadedNamesAndSigs; 83 87 … … 116 120 this.fv = c.fv; 117 121 this.topLevelOverloads = c.topLevelOverloads; 122 this.exportedToUnambiguous = c.exportedToUnambiguous; 118 123 this.overloadedNamesAndSigs = c.overloadedNamesAndSigs; 119 124 … … 142 147 this.fv = fv; 143 148 this.ci = ci; 149 this.exportedToUnambiguous = new MultiMap<String, Function> (); 150 151 /* 152 * Find every exported name, and make an entry mapping name to 153 * API declarations, so that unambiguous names from APIs can 154 * also be emitted. 155 */ 156 List<APIName> exports = c.getExports(); 157 for (APIName apiname:exports) { 158 ApiIndex api_index = env.api(apiname); 159 Relation<IdOrOpOrAnonymousName, Function> fns = api_index.functions(); 160 for (IdOrOpOrAnonymousName name : fns.firstSet()) { 161 if (name instanceof IdOrOp) { 162 Set<Function> defs = fns.matchFirst(name); 163 for (Function def : defs) { 164 IdOrOpOrAnonymousName ua_name = def.unambiguousName(); 165 if (ua_name instanceof IdOrOp) { 166 IdOrOp ioo_name = (IdOrOp) name; 167 IdOrOp ioo_ua_name = (IdOrOp) ua_name; 168 if (! ioo_name.equals(ioo_ua_name)) { 169 // Add mapping ioo_name -> def to MultiMap 170 exportedToUnambiguous.putItem( 171 ioo_name.getText(), 172 def); 173 } 174 } 175 } 176 } 177 } 178 } 179 144 180 this.topLevelOverloads = 145 181 sizePartitionedOverloads(ci.functions()); 182 146 183 this.overloadedNamesAndSigs = new HashSet<String>(); 147 184 this.lexEnv = new BATree<String,VarCodeGen>(StringHashComparer.V); 148 185 this.env = env; 186 187 149 188 debug( "Compile: Compiling ", packageAndClassName ); 150 189 } … … 394 433 // answer depends upon how intersection types are normalized. 395 434 // conservative answer is "no". 396 methodName = Naming.mangleIdentifier(methodName);435 // methodName = Naming.mangleIdentifier(methodName); 397 436 signature = NamingCzar.jvmMethodDesc(arrow, component.getName()); 398 437 … … 400 439 IntersectionType it = (IntersectionType) arrow; 401 440 methodName = OverloadSet.actuallyOverloaded(it, paramCount) ? 402 OverloadSet.oMangle(methodName) : Naming.mangleIdentifier(methodName);441 OverloadSet.oMangle(methodName) : methodName; 403 442 404 443 signature = OverloadSet.getSignature(it, paramCount, ta); … … 566 605 567 606 // Must do this first, to get local decls right. 568 overloadedNamesAndSigs = generateTopLevelOverloads(thisApi(), topLevelOverloads, ta, cw); 569 607 overloadedNamesAndSigs = generateTopLevelOverloads(thisApi(), topLevelOverloads, ta, cw, this); 608 609 /* Need wrappers for the API, too. */ 610 generateUnambiguousWrappersForApi(); 611 570 612 // Must process top-level values next to make sure fields end up in scope. 571 613 for (Decl d : x.getDecls()) { … … 755 797 */ 756 798 799 757 800 // Dotted method; downcast self and 758 801 // forward to static method in springboard class … … 808 851 cg.generateActualMethodCode(modifiers, mname, sig, params, selfIndex, 809 852 inAMethod, body); 853 854 generateAllWrappersForFn(x, params, sig, modifiers, mname); 855 } 856 857 858 /** 859 * @param x 860 * @param params 861 * @param selfIndex 862 * @param sig 863 * @param modifiers 864 * @param mname 865 */ 866 private void generateAllWrappersForFn(FnDecl x, List<Param> params, 867 String sig, int modifiers, 868 String mname) { 869 CodeGen cg = new CodeGen(this); 870 /* This code generates forwarding wrappers for 871 * the (local) unambiguous name of the function. 872 */ 873 874 // unambiguous within component 875 String wname = idOrOpToString(x.getUnambiguousName()); 876 cg.generateWrapperMethodCode(modifiers, mname, wname, sig, params); 877 } 878 879 880 /** 881 * @param params 882 * @param sig 883 * @param modifiers 884 * @param mname 885 * @param cg 886 * @param sf 887 */ 888 private void generateUnambiguousWrappersForApi() { 889 890 for (Map.Entry<String, Set<Function>> entry : exportedToUnambiguous 891 .entrySet()) { 892 Set<Function> sf = entry.getValue(); 893 for (Function function : sf) { 894 List<Param> params = function.parameters(); 895 896 String sig = NamingCzar.jvmSignatureFor( 897 NodeUtil.getParamType(params, function.getSpan()), 898 function.getReturnType().unwrap(), 899 component.getName()); 900 901 String mname = idOrOpToString(function.name()); // entry.getKey(); 902 903 String function_ua_name = idOrOpToString(function.unambiguousName()); 904 generateWrapperMethodCode( 905 Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC, mname, 906 function_ua_name, sig, params); 907 } 908 } 909 } 910 911 /** Generate an actual Java method and body code from an Expr. 912 * Should be done within a nested codegen as follows: 913 * new CodeGen(this).generateActualMethodCode(...); 914 */ 915 private void generateWrapperMethodCode(int modifiers, String mname, String wname, String sig, 916 List<Param> params) { 917 918 // ignore virtual, now. 919 if (0 == (Opcodes.ACC_STATIC & modifiers)) 920 return; 921 922 mv = cw.visitCGMethod(modifiers, wname, sig, null, null); 923 mv.visitCode(); 924 925 // Need to copy the parameter across for the wrapper call. 926 // Modifiers should tell us how to do the call, maybe? 927 // Invokestatic, for now. 928 929 int i = 0; 930 931 for (Param p : params) { 932 // Type ty = p.getIdType().unwrap(); 933 mv.visitVarInsn(Opcodes.ALOAD, i); 934 i++; 935 } 936 937 mv.visitMethodInsn(Opcodes.INVOKESTATIC, packageAndClassName, mname, sig); 938 939 methodReturnAndFinish(); 810 940 } 811 941 … … 1197 1327 sig, params.size(), true); 1198 1328 1329 1330 generateAllWrappersForFn(x, params, sig, modifiers, mname); 1331 1199 1332 } 1200 1333 … … 1202 1335 * @param cg 1203 1336 */ 1337 1204 1338 private void methodReturnAndFinish() { 1205 1339 mv.visitInsn(Opcodes.ARETURN); … … 1302 1436 private String singleName(IdOrOpOrAnonymousName name) { 1303 1437 String nameString = idOrOpToString((IdOrOp)name); 1304 String mname = Naming.mangleIdentifier(nameString);1438 String mname = nameString; // Naming.mangleIdentifier(nameString); 1305 1439 return mname; 1306 1440 } … … 1471 1605 int lastDot = n.lastIndexOf("."); 1472 1606 calleePackageAndClass = n.substring(0, lastDot).replace(".", "/"); 1473 method = n.substring(lastDot+1); 1607 method = n.substring(lastDot+2); 1608 int foreign_tag = method.indexOf(Naming.FOREIGN_TAG); 1609 calleePackageAndClass = calleePackageAndClass + "/" + method.substring(0, foreign_tag); 1610 method = method.substring(foreign_tag+1); 1611 int paren_tag = method.indexOf("("); 1612 if (paren_tag != -1) 1613 method = method.substring(0, paren_tag); 1474 1614 } 1475 1615 } … … 1936 2076 1937 2077 mv.visitInsn(Opcodes.DUP); 1938 int taskVar = mv.createCompilerLocal( Naming.mangleIdentifier(task),2078 int taskVar = mv.createCompilerLocal(task, // Naming.mangleIdentifier(task), 1939 2079 NamingCzar.internalToDesc(task)); 1940 2080 taskVars[i] = taskVar; … … 2045 2185 mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, 2046 2186 NamingCzar.makeInnerClassName(id), 2047 Naming.mangleIdentifier(opToString(op)), 2187 // Naming.mangleIdentifier(opToString(op)), 2188 opToString(op), 2048 2189 "(Lcom/sun/fortress/compiler/runtimeValues/FZZ32;)Lcom/sun/fortress/compiler/runtimeValues/FString;"); 2049 2190 } … … 2388 2529 Map<IdOrOpOrAnonymousName,MultiMap<Integer, Function>> size_partitioned_overloads, 2389 2530 TypeAnalyzer ta, 2390 C lassWriter cw2531 CodeGenClassWriter cw, CodeGen cg 2391 2532 ) { 2392 2533 … … 2413 2554 2414 2555 os.generateAnOverloadDefinition(s2, cw); 2556 if (cg != null) { 2557 /* Need to check if the overloaded function happens to match 2558 * a name in an API that this component exports; if so, 2559 * generate a forwarding wrapper from the 2560 */ 2561 } 2415 2562 2416 2563 for (Map.Entry<String, OverloadSet> o_entry : os.getOverloadSubsets().entrySet()) { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/NameEnv.java
r3998 r4291 48 48 49 49 /** 50 * Produce the set of unqualified, unambiguous names corresponding to the 51 * given function name. Imported names are included. An undefined reference 52 * produces an empty set. 50 * Produce the set of qualified, unambiguous names corresponding to the 51 * given, possibly qualified function name. 53 52 */ 54 53 public abstract Set<IdOrOp> unambiguousFunctionNames(IdOrOp name); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/TopLevelEnv.java
r4211 r4291 446 446 public Set<IdOrOp> unambiguousFunctionNames(final IdOrOp name) { 447 447 448 // Function that gets an unambiguous name out of a Function. If it is 449 // not a DeclaredFunction or FunctionalMethod, the original name will 450 // be returned. 448 // Function that gets an unambiguous name out of a Function. 451 449 Lambda<Function, IdOrOp> unambiguousNameFromFunction = new Lambda<Function, IdOrOp>() { 450 @Override public IdOrOp value(Function fn) { 451 return fn.unambiguousName(); 452 } 453 }; 454 455 // Qualifies the given name with the given API. Create normal Lambdas 456 // by binding an API. 457 Lambda2<APIName, IdOrOp, IdOrOp> addApi = new Lambda2<APIName, IdOrOp, IdOrOp>() { 452 458 @Override 453 public IdOrOp value(Function fn) { 454 if (fn instanceof DeclaredFunction) { 455 return ((DeclaredFunction) fn).ast().getUnambiguousName(); 456 } else if (fn instanceof FunctionalMethod) { 457 return ((FunctionalMethod) fn).ast().getUnambiguousName(); 459 public IdOrOp value(APIName api, IdOrOp name) { 460 if (name instanceof Id) { 461 return NodeFactory.makeId(Option.some(api), (Id) name); 458 462 } else { 459 return name;463 return NodeFactory.makeOp(Option.some(api), (Op) name); 460 464 } 461 465 } 462 466 }; 467 468 // If this name is qualified, then lookup names only in that API. 469 if (name.getApiName().isSome()) { 470 APIName api = name.getApiName().unwrap(); 471 472 // Get the functions from this api with this name. 473 Set<? extends Function> functions = 474 _onDemandImportedApis.get(api).functions().matchFirst(name); 475 476 // Return their unambiguous names, qualified. 477 Lambda<IdOrOp, IdOrOp> addThisApi = LambdaUtil.bindFirst(addApi, api); 478 return CollectUtil.asSet(IterUtil.map(functions, 479 LambdaUtil.compose(unambiguousNameFromFunction, 480 addThisApi))); 481 } 463 482 464 483 // First get all the declarations from this compilation unit. … … 468 487 // Loop over all the imported APIs. 469 488 for (final ApiIndex api : _onDemandImportedApis.values()) { 470 471 // Qualifies the names with this API. 472 Lambda<IdOrOp, IdOrOp> addApi = new Lambda<IdOrOp, IdOrOp>() { 473 @Override 474 public IdOrOp value(IdOrOp name) { 475 if (name instanceof Id) { 476 return NodeFactory.makeId(api.ast().getName(), (Id) name, NodeUtil.getSpan(name)); 477 } else { 478 return NodeFactory.makeOp(api.ast().getName(), (Op) name); 479 } 480 } 481 }; 489 Lambda<IdOrOp, IdOrOp> addThisApi = LambdaUtil.bindFirst(addApi, api.ast().getName()); 482 490 483 491 // Get all the declarations from this API and qualify the names. 484 492 functions = api.functions().matchFirst(name); 485 results = IterUtil.compose(results, IterUtil.map(functions, LambdaUtil.compose(unambiguousNameFromFunction, 486 addApi))); 487 } 493 results = IterUtil.compose(results, 494 IterUtil.map(functions, 495 LambdaUtil.compose(unambiguousNameFromFunction, 496 addThisApi))); 497 } 498 499 // Add in the unambiguous names from the alias. 500 // TODO: Correct behavior? 501 if (_aliases.containsKey(name)) { 502 results = IterUtil.compose(results, 503 unambiguousFunctionNames((IdOrOp) _aliases.get(name))); 504 } 505 488 506 return CollectUtil.asSet(results); 489 507 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Coercion.java
r4280 r4291 118 118 return (IdOrOp) ast().getHeader().getName(); 119 119 } 120 121 public IdOrOp unambiguousName() { 122 return (IdOrOp) ast().getUnambiguousName(); 123 } 120 124 121 125 public Id declaringTrait() { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Constructor.java
r4280 r4291 91 91 return _declaringTrait; 92 92 } 93 94 public IdOrOp unambiguousName() { 95 return name(); 96 } 93 97 94 98 // public List<StaticParam> staticParams() { return _staticParams; } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredFunction.java
r4280 r4291 66 66 return (IdOrOp) NodeUtil.getName(_ast); 67 67 } 68 69 public IdOrOp unambiguousName() { 70 return (IdOrOp) _ast.getUnambiguousName(); 71 } 68 72 69 73 @Override -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredMethod.java
r4280 r4291 123 123 return (IdOrOp) NodeUtil.getName(_ast); 124 124 } 125 126 public IdOrOp unambiguousName() { 127 return (IdOrOp) _ast.getUnambiguousName(); 128 } 125 129 126 130 @Override -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FieldGetterOrSetterMethod.java
r4280 r4291 114 114 return _ast.getName(); 115 115 } 116 117 public IdOrOp unambiguousName() { 118 return name(); 119 } 116 120 } -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/Functional.java
r4280 r4291 45 45 46 46 public abstract IdOrOp name(); 47 48 public abstract IdOrOp unambiguousName(); 47 49 48 50 public String toString() { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/index/FunctionalMethod.java
r4280 r4291 98 98 return (IdOrOp) NodeUtil.getName(_ast); 99 99 } 100 101 public IdOrOp unambiguousName() { 102 return (IdOrOp) _ast.getUnambiguousName(); 103 } 100 104 101 105 public Id declaringTrait() { -
trunk/ProjectFortress/src/com/sun/fortress/compiler/nativeInterface/FortressMethodAdapter.java
r4283 r4291 24 24 25 25 import com.sun.fortress.compiler.codegen.CodeGen; 26 import com.sun.fortress.compiler.codegen.CodeGenClassWriter; 26 27 import com.sun.fortress.compiler.index.Function; 27 28 import com.sun.fortress.compiler.OverloadSet; … … 70 71 private Map<IdOrOpOrAnonymousName,MultiMap<Integer, Function>> sizePartitionedOverloads; 71 72 private TypeAnalyzer ta; 72 private C lassWriter cw;73 private CodeGenClassWriter cw; 73 74 private Set<String> overloadedNamesAndSigs; 74 75 … … 112 113 } 113 114 114 public FortressMethodAdapter(C lassWriter cv,115 public FortressMethodAdapter(CodeGenClassWriter cv, 115 116 String inputClassName, 116 117 String outputClassName, … … 129 130 130 131 public void visit(int version, int access, String name, String signature, 131 String superName, String[] interfaces) { 132 Debug.debug( Debug.Type.COMPILER, 1, 133 "visit:" + name + " generate " + inputClassName); 134 cv.visit(version, access, outputClassName, signature, superName, interfaces); 135 136 overloadedNamesAndSigs = CodeGen.generateTopLevelOverloads(apiName, sizePartitionedOverloads, ta, cw); 132 String superName, String[] interfaces) { 133 Debug.debug(Debug.Type.COMPILER, 1, "visit:" + name + " generate " 134 + inputClassName); 135 cv.visit(version, access, outputClassName, signature, superName, 136 interfaces); 137 138 /* 139 * TODO there may be more work be done in the method called below. 140 * cg=null allows a bunch of code reuse, but does not deal with the 141 * possibility of unambiguous reference to one of these 142 * adapter-generated overloaded (?) native methods. 143 */ 144 145 overloadedNamesAndSigs = CodeGen.generateTopLevelOverloads(apiName, 146 sizePartitionedOverloads, ta, cw, /* cg= */null); 137 147 } 138 148 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/nativeInterface/FortressTransformer.java
r4153 r4291 24 24 25 25 import com.sun.fortress.compiler.ByteCodeWriter; 26 import com.sun.fortress.compiler.codegen.CodeGenClassWriter; 26 27 import com.sun.fortress.compiler.index.Function; 27 28 import com.sun.fortress.compiler.OverloadSet; … … 45 46 try { 46 47 ClassReader cr = new ClassReader(inputClassName); 47 C lassWriter cw = newClassWriter(ClassWriter.COMPUTE_FRAMES);48 CodeGenClassWriter cw = new CodeGenClassWriter(ClassWriter.COMPUTE_FRAMES); 48 49 String outputClassName = Naming.NATIVE_PREFIX_DOT + inputClassName; 49 50 -
trunk/ProjectFortress/src/com/sun/fortress/exceptions/InterpreterBug.java
r1895 r4291 71 71 72 72 public static <T> T bug(String msg) { 73 throw new InterpreterBug( msg);73 throw new InterpreterBug("** bug! " + msg); 74 74 } 75 75 -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java
r4280 r4291 486 486 Option<Type> returnType, 487 487 Option<Expr> body) { 488 return makeFnDecl(span, mods, name, 488 return makeFnDecl(span, 489 mods, 490 name, 489 491 Collections.<StaticParam>emptyList(), 490 492 params, returnType, … … 494 496 body); 495 497 } 496 498 499 private static String uaName(String tag, Span span ) { 500 String s = span.toString(); 501 s = s.replaceAll("/", "|"); 502 return s; 503 } 504 497 505 public static FnDecl makeFnDecl(Span span, Modifiers mods, 498 506 IdOrOpOrAnonymousName name, … … 505 513 IdOrOp unambiguousName; 506 514 if (name instanceof Op) { 507 unambiguousName = makeOp((Op)name, "OP$"+span.toString());515 unambiguousName = makeOp((Op)name, uaName("OP", span)); 508 516 } else { 509 unambiguousName = makeId(span, "FN$"+span.toString());517 unambiguousName = makeId(span, uaName("FN", span)); 510 518 } 511 519 return makeFnDecl(span, mods, name, staticParams, params, returnType, … … 525 533 IdOrOp unambiguousName; 526 534 if (name instanceof Op) { 527 unambiguousName = makeOp((Op)name, "OP$"+span.toString());535 unambiguousName = makeOp((Op)name, uaName("OP", span)); 528 536 } else { 529 unambiguousName = makeId(span, "FN$"+span.toString());537 unambiguousName = makeId(span, uaName("FN", span)); 530 538 } 531 539 return makeFnDecl(span, mods, name, staticParams, params, returnType, … … 546 554 } 547 555 548 public static FnDecl makeFnDecl(Span span, Modifiers mods, 556 public static FnDecl makeFnDecl(Span span, 557 Modifiers mods, 549 558 IdOrOpOrAnonymousName name, 550 559 List<StaticParam> staticParams, … … 1767 1776 public static Op makeOp(final APIName api, Op op) { 1768 1777 return makeOp(NodeUtil.getSpan(op), Option.some(api), 1778 op.getText(), op.getFixity(), op.isEnclosing() ); 1779 } 1780 1781 public static Op makeOp(Option<APIName> api, Op op) { 1782 return makeOp(NodeUtil.getSpan(op), api, 1769 1783 op.getText(), op.getFixity(), op.isEnclosing() ); 1770 1784 } -
trunk/ProjectFortress/src/com/sun/fortress/repository/ForeignJava.java
r4275 r4291 32 32 import com.sun.fortress.repository.graph.ApiGraphNode; 33 33 import com.sun.fortress.repository.graph.GraphNode; 34 import com.sun.fortress.runtimeSystem.Naming; 34 35 import com.sun.fortress.scala_src.typechecker.IndexBuilder; 35 36 import com.sun.fortress.useful.*; … … 172 173 private static Span span() { 173 174 return NodeFactory.internalSpan; 174 }175 176 private static Span span(MethodNode m) {177 return NodeFactory.makeSpan(methodName(m));178 175 } 179 176 … … 413 410 414 411 public int compare(MethodNode o1, MethodNode o2) { 415 return methodName(o1).compareTo(methodName(o2));412 return justMethodName(o1).compareTo(justMethodName(o2)); 416 413 } 417 414 … … 489 486 490 487 private FnDecl recurOnMethod(APIName importing_package, ClassNode cl, MethodNode m, boolean is_static) { 491 String methodKey = methodName( m);488 String methodKey = methodName(cl, m); 492 489 if (methodToDecl.containsKey(methodKey)) return methodToDecl.get(methodKey); 493 490 … … 501 498 for (Type pt : pts) { 502 499 com.sun.fortress.nodes.Type type = recurOnOpaqueClass(importing_package, pt); 503 Span param_span = NodeFactory.makeSpan(span(m ) + " p#" + i);500 Span param_span = NodeFactory.makeSpan(span(methodKey) + " p#" + i); 504 501 Id id = NodeFactory.makeId(param_span, "p" + (i++)); 505 502 Param p = NodeFactory.makeParam(id, type); … … 507 504 } 508 505 509 Span fn_span = span(m );506 Span fn_span = span(methodKey); 510 507 Id id = is_static ? NodeFactory.makeId(fn_span, getSimpleName(cl) + "." + getName(m)) : NodeFactory.makeId( 511 508 fn_span, 512 509 getName(m)); 510 511 String uan = Naming.FOREIGN_TAG + methodKey ; 512 513 513 FnDecl fndecl = NodeFactory.makeFnDecl(fn_span, 514 514 Modifiers.None, 515 id, 515 (IdOrOpOrAnonymousName) id, 516 Collections.<StaticParam>emptyList(), 516 517 params, 517 518 Option.some(return_type), 518 Option.<Expr>none()); 519 Option.<List<com.sun.fortress.nodes.Type>>none(), 520 Option.<WhereClause>none(), 521 Option.<Contract>none(), 522 (IdOrOp) NodeFactory.makeId(fn_span, uan), 523 Option.<Expr>none(), 524 Option.<IdOrOp>none() 525 ); 526 519 527 methodToDecl.put(methodKey, fndecl); 520 528 return fndecl; … … 525 533 * @return 526 534 */ 527 private static String methodName(MethodNode m) { 535 private static String methodName(ClassNode cl, MethodNode m) { 536 String s = cl.name; 537 int i = s.lastIndexOf("/"); 538 s = s.substring(i+1); 539 return s + Naming.FOREIGN_TAG + m.name + m.desc; 540 } 541 542 private static String justMethodName(MethodNode m) { 528 543 return m.name + m.desc; 529 544 } -
trunk/ProjectFortress/src/com/sun/fortress/runtimeSystem/Naming.java
r4252 r4291 634 634 mangledString = "\\=" + mangledString; 635 635 636 // debugging check for double-mangling 637 if (mangledString.startsWith("\\-")) 638 mangledString = mangledString; 639 636 640 return mangledString; 637 641 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/disambiguator/ExprDisambiguator.scala
r4185 r4291 397 397 } else result = Some(SVarRef(info, newName, sargs, depth)) 398 398 case (0, f, _) if f > 0 => 399 var new_fns = setToList[IdOrOp](toSet(fns)) 399 val new_fns = setToList[IdOrOp](toSet(fns)) 400 val unambiguous_fns = setToList[IdOrOp](toSet(env.unambiguousFunctionNames(name))) 400 401 // Create a list of overloadings for this FnRef from the 401 402 // matching function names. 402 403 // TODO: insert correct number of to-infer arguments? 403 404 result = Some(SFnRef(info, sargs, depth, name, new_fns, None, 404 new_fns.map(new Overloading(info, _, None)),405 unambiguous_fns.map(new Overloading(info, _, None)), 405 406 None)) 406 407 case (1, 0, 1) => … … 443 444 } 444 445 else { 445 var new_fns = setToList[IdOrOp](toSet(fns)) 446 val new_fns = setToList[IdOrOp](toSet(fns)) 447 val unambiguous_fns = setToList[IdOrOp](toSet(env.unambiguousFunctionNames(fn_name))) 446 448 SFnRef(info, sargs, depth, fn_name.asInstanceOf[Id], new_fns, ovl, 447 449 // Create a list of overloadings for this FnRef from the matching 448 450 // function names. 449 new_fns.map(new Overloading(info, _, None)), ovlType)451 unambiguous_fns.map(new Overloading(info, _, None)), ovlType) 450 452 } 451 453 … … 801 803 if (ops.isEmpty) None 802 804 else { 803 var new_ops = setToList[IdOrOp](toSet(ops)) 805 val new_ops = setToList[IdOrOp](toSet(ops)) 806 val unambiguous_ops = setToList[IdOrOp](toSet(env.unambiguousFunctionNames(op_name))) 804 807 // Create a list of overloadings for this OpRef from the matching 805 808 // operator names. 806 809 Some(SOpRef(info, sargs, depth, op_name, new_ops, oldOvl, 807 new_ops.map(new Overloading(info, _, None)), ovlType))810 unambiguous_ops.map(new Overloading(info, _, None)), ovlType)) 808 811 } 809 812 case _ => None -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/linker/HygienicRenamer.scala
r4275 r4291 154 154 SOptionalSymbol(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getSymbol).asInstanceOf[com.sun.fortress.nodes.SyntaxSymbol]) 155 155 case SOverloading(getInfo, getUnambiguousName, getType) => 156 SOverloading(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getUnambiguousName).asInstanceOf[com.sun.fortress.nodes.IdOrOp], walk(getType).asInstanceOf[Option[com.sun.fortress.nodes. Type]])156 SOverloading(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getUnambiguousName).asInstanceOf[com.sun.fortress.nodes.IdOrOp], walk(getType).asInstanceOf[Option[com.sun.fortress.nodes.ArrowType]]) 157 157 case SParam(getInfo, getName, getMods, getIdType, getDefaultExpr, getVarargsType) => 158 158 SParam(walk(getInfo).asInstanceOf[com.sun.fortress.nodes.ASTNodeInfo], walk(getName).asInstanceOf[com.sun.fortress.nodes.Id], walk(getMods).asInstanceOf[com.sun.fortress.nodes_util.Modifiers], walk(getIdType).asInstanceOf[Option[com.sun.fortress.nodes.Type]], walk(getDefaultExpr).asInstanceOf[Option[com.sun.fortress.nodes.Expr]], walk(getVarargsType).asInstanceOf[Option[com.sun.fortress.nodes.Type]]) -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/STypeChecker.scala
r4285 r4291 337 337 } 338 338 339 /** 340 * Lookup the functional indices for the given name in the proper type 341 * environment. 342 */ 343 protected def getFnIndicesFromName(name: Name): Option[List[Functional]] = 344 getRealName(name, toList(current.ast.getImports)) match { 345 case id@SIdOrOp(_, Some(api), _) => getEnvFromApi(api).getFnIndices(id) 346 case id:IdOrOp => env.getFnIndices(id) 347 case _ => None 348 } 349 339 350 def getErrors(): List[StaticError] = errors.errors 340 351 -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/impls/Functionals.scala
r4251 r4291 21 21 import com.sun.fortress.compiler.index._ 22 22 import com.sun.fortress.exceptions._ 23 import com.sun.fortress.exceptions.InterpreterBug.bug 23 24 import com.sun.fortress.exceptions.StaticError.errorMsg 24 25 import com.sun.fortress.nodes._ … … 466 467 def checkFunctionals(node: Node): Node = node match { 467 468 468 case SOverloading(info, name, _) => { 469 val checkedName = check(name).asInstanceOf[IdOrOp] 469 case SOverloading(info, unambigName, _) => { 470 val checkedName = check(unambigName).asInstanceOf[IdOrOp] 471 472 // Should have one arrow type for this unambiguous name. 470 473 getTypeFromName(checkedName) match { 471 case Some(checkedType) => 472 SOverloading(info, checkedName, Some(normalize(checkedType))) 474 case Some(arrow: ArrowType) => 475 SOverloading(info, checkedName, Some(arrow)) 476 case Some(typ) => 477 bug("type env binds unambiguous name %s to non-arrow type %s".format(unambigName, typ)) 473 478 case None => node 474 479 } … … 557 562 case SOverloading(info, name, Some(ty)) => 558 563 instantiateStaticParams(sargs, ty). 559 map(t => SOverloading(info, name, Some(t )))564 map(t => SOverloading(info, name, Some(t.asInstanceOf[ArrowType]))) 560 565 case _ => hadNoType = true; None 561 566 } -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/typechecker/staticenv/STypeEnv.scala
r4166 r4291 31 31 import com.sun.fortress.scala_src.useful.Options._ 32 32 import com.sun.fortress.scala_src.useful.Sets._ 33 import com.sun.fortress.scala_src.useful.S TypesUtil34 import com.sun.fortress.scala_src.useful.STypesUtil. TypeThunk33 import com.sun.fortress.scala_src.useful.SNodeUtil._ 34 import com.sun.fortress.scala_src.useful.STypesUtil._ 35 35 import edu.rice.cs.plt.collect.Relation 36 36 … … 101 101 /** Get the modifiers for the given name, if it exists. */ 102 102 def getMods(x: Name): Option[Modifiers] = lookup(x).map(_.mods) 103 104 /** Get the functional indices for this name, if any. */ 105 def getFnIndices(x: Name): Option[List[Functional]] = 106 lookup(x).map(_.fnIndices) 103 107 } 104 108 … … 151 155 typeThunk: TypeThunk, 152 156 mods: Modifiers, 153 mutable: Boolean): TypeBinding = 154 TypeBinding(name, typeThunk, mods, mutable) 157 mutable: Boolean, 158 functions: Collection[Functional]): TypeBinding = 159 TypeBinding(name, typeThunk, mods, mutable, functions.toList) 155 160 156 161 /** … … 163 168 mutable: Boolean): TypeBinding = { 164 169 val typeThunk = new TypeThunk { def apply: Option[Type] = Some(typ) } 165 TypeBinding(name, typeThunk, mods, mutable )170 TypeBinding(name, typeThunk, mods, mutable, Nil) 166 171 } 167 172 … … 211 216 NF.makeArrowType(NU.getSpan(qualifiedName), 212 217 // Constructors must have all param types. 213 STypesUtil.makeDomainType(toList(params)).get,218 makeDomainType(toList(params)).get, 214 219 NF.makeTraitType(qualifiedName)) 215 220 case Some(params) => 216 221 // Generic arrow type for constructor. 217 val sargs = toList(sparams).map( STypesUtil.staticParamToArg)222 val sargs = toList(sparams).map(staticParamToArg) 218 223 NF.makeArrowType(NU.getSpan(decl), 219 224 false, 220 225 // Constructors must have all param types. 221 STypesUtil.makeDomainType(toList(params)).get,226 makeDomainType(toList(params)).get, 222 227 NF.makeTraitType(qualifiedName, 223 228 toJavaList(sargs)), … … 242 247 def apply: Option[Type] = v.getInferredType 243 248 } 244 makeBinding(x, lazyTypeEvaluation, v.modifiers, v.mutable )249 makeBinding(x, lazyTypeEvaluation, v.modifiers, v.mutable, Nil) 245 250 }) 246 251 } … … 259 264 (functions: Iterable[(S,Set[T])], 260 265 api: Option[APIName]): Iterable[TypeBinding] = { 261 functions.map{ tuple => 262 val (x,fns) = tuple 263 // Lazily compute the type for this function binding at the time of 264 // lookup. 265 val lazyTypeEvaluation: TypeThunk = new TypeThunk { 266 267 // Collect all bindings found among all these functions. 268 functions.flatMap { nameAndFunctions => 269 val (f, fnsSet) = nameAndFunctions 270 val fns = fnsSet.toList 271 272 // Create the binding for each overloading of the function named f. 273 val unambiguousBindings = fns.map { fn => 274 275 // Create a lazy computation for the type of this overloading. 276 val lazyType = new TypeThunk { 277 def apply: Option[Type] = makeArrowFromFunctional(fn) 278 } 279 280 // Bind the unambiguous name of this overloading to its type. 281 makeBinding(unqualifiedName(fn.unambiguousName), 282 lazyType, 283 fn.mods, 284 false, 285 List(fn)) 286 } 287 288 // Create a lazy computation for the type of the whole overloaded 289 // function named x. 290 val ambiguousThunk = new TypeThunk { 266 291 def apply: Option[Type] = { 267 // TODO: Currently ignoring any errors from makeArrowFromFunctional 268 val oTypes = fns.flatMap[Type](STypesUtil.makeArrowFromFunctional) 292 val oTypes = fns.flatMap[Type](makeArrowFromFunctional) 269 293 if (oTypes.isEmpty) 270 294 None … … 273 297 } 274 298 } 275 val mods = if ( fns.isEmpty ) Modifiers.None 276 else fns.find(_.mods != Modifiers.None) match { 277 case Some(f) => f.mods 278 case _ => Modifiers.None 279 } 280 makeBinding(x, lazyTypeEvaluation, mods, false) 299 300 // Create the modifiers for the whole binding. 301 val ambiguousMods = 302 if (fns.isEmpty) 303 Modifiers.None 304 else fns.find(_.mods != Modifiers.None) match { 305 case Some(f) => f.mods 306 case _ => Modifiers.None 307 } 308 309 // Bind the ambiguous, plain name of this function to the intersection 310 // of all its overloadings' types. 311 val ambiguousBinding = makeBinding(unqualifiedName(f), 312 ambiguousThunk, 313 ambiguousMods, 314 false, 315 fns) 316 317 // Return all the bindings. 318 ambiguousBinding :: unambiguousBindings 281 319 } 282 320 } … … 293 331 * @param mods Any modifiers for the binding. 294 332 * @param mutable Whether or not the binding is mutable. 333 * @param fnIndices A list of Functional indices, if any, to which this name 334 * refers. 295 335 */ 296 336 case class TypeBinding(name: Name, 297 337 typeThunk: TypeThunk, 298 338 mods: Modifiers, 299 mutable: Boolean) 339 mutable: Boolean, 340 fnIndices: List[Functional]) 300 341 301 342 /** -
trunk/ProjectFortress/src/com/sun/fortress/scala_src/useful/STypesUtil.scala
r4289 r4291 796 796 (implicit analyzer: TypeAnalyzer) 797 797 : Option[Overloading] = { 798 // Is this arrow type applicable.799 def arrowTypeIsApplicable(ovType: ArrowType): Option[Type] = { 800 801 // If static args, then instantiate the unlifted static params.802 val typ1 =803 i f (!sargs.isEmpty)804 instantiateStaticParams(sargs, ovType).getOrElse(return None)805 else806 ovType 807 808 // If there were lifted, inferred static args, then instantiate those.809 val typ2 =810 i f (!liftedInfSargs.isEmpty)811 instantiateLiftedStaticParams(liftedInfSargs, typ1).getOrElse(return None)812 else813 typ1 814 815 // If there are still some static params in it, then we can't infer them816 // so it's not applicable.817 val typ = typ2.asInstanceOf[ArrowType]798 val SOverloading(ovInfo, ovName, Some(ovType)) = overloading 799 800 // If static args, then instantiate the unlifted static params. 801 val typ1 = 802 if (!sargs.isEmpty) 803 instantiateStaticParams(sargs, ovType).getOrElse(return None) 804 else 805 ovType 806 807 // If there were lifted, inferred static args, then instantiate those. 808 val typ2 = 809 if (!liftedInfSargs.isEmpty) 810 instantiateLiftedStaticParams(liftedInfSargs, typ1).getOrElse(return None) 811 else 812 typ1 813 814 // If there are still some static params in it, then we can't infer them 815 // so it's not applicable. 816 val typ = typ2.asInstanceOf[ArrowType] 817 val newOvType = 818 818 if (!hasStaticParams(typ) && isSubtype(typ.getDomain, smaArrow.getDomain)) 819 Some(typ)819 typ 820 820 else 821 None 822 } 823 824 // If overloading type is an intersection, check that any of its 825 // constituents is applicable. 826 val applicableArrows = conjuncts(toOption(overloading.getType).get). 827 map(_.asInstanceOf[ArrowType]). 828 flatMap(arrowTypeIsApplicable). 829 toList 830 831 val overloadingType = applicableArrows match { 832 case Nil => return None 833 case t::Nil => t 834 case _ => NF.makeIntersectionType(toJavaList(applicableArrows)) 835 } 836 Some(SOverloading(overloading.getInfo, 837 overloading.getUnambiguousName, 838 Some(overloadingType))) 821 return None 822 823 Some(SOverloading(ovInfo, ovName, Some(newOvType))) 839 824 } 840 825

