root/trunk/ProjectFortress/src/com/sun/fortress/compiler/NamingCzar.java @ 3912

Revision 3912, 27.7 KB (checked in by chf, 5 months ago)

First pass at parallel task generation

Line 
1/*******************************************************************************
2    Copyright 2009 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16******************************************************************************/
17
18package com.sun.fortress.compiler;
19
20import java.lang.StringBuffer;
21import java.math.BigInteger;
22import java.util.ArrayList;
23import java.util.Collections;
24import java.util.HashMap;
25import java.util.List;
26import java.util.Map;
27
28import com.sun.fortress.compiler.environments.TopLevelEnvGen;
29import com.sun.fortress.compiler.index.Function;
30import com.sun.fortress.compiler.phases.OverloadSet;
31import com.sun.fortress.exceptions.CompilerError;
32import com.sun.fortress.nodes.ASTNode;
33import com.sun.fortress.nodes.APIName;
34import com.sun.fortress.nodes.AnyType;
35import com.sun.fortress.nodes.ArrowType;
36import com.sun.fortress.nodes.BaseType;
37import com.sun.fortress.nodes.BottomType;
38import com.sun.fortress.nodes.FnDecl;
39import com.sun.fortress.nodes.FnHeader;
40import com.sun.fortress.nodes.Id;
41import com.sun.fortress.nodes.IdOrOp;
42import com.sun.fortress.nodes.IdOrOpOrAnonymousName;
43import com.sun.fortress.nodes.NamedType;
44import com.sun.fortress.nodes.Param;
45import com.sun.fortress.nodes.TraitType;
46import com.sun.fortress.nodes.TraitTypeWhere;
47import com.sun.fortress.nodes.TupleType;
48import com.sun.fortress.nodes.VarType;
49import com.sun.fortress.nodes.NodeAbstractVisitor;
50import com.sun.fortress.nodes_util.NodeFactory;
51import com.sun.fortress.nodes_util.NodeUtil;
52import com.sun.fortress.nodes_util.Span;
53import com.sun.fortress.repository.ForeignJava;
54import com.sun.fortress.repository.GraphRepository;
55import com.sun.fortress.repository.ProjectProperties;
56import com.sun.fortress.useful.BATree;
57import com.sun.fortress.useful.Debug;
58import com.sun.fortress.useful.Useful;
59
60import edu.rice.cs.plt.tuple.Option;
61
62import org.objectweb.asm.Type;
63
64import static com.sun.fortress.exceptions.InterpreterBug.bug;
65import static com.sun.fortress.exceptions.ProgramError.error;
66import static com.sun.fortress.exceptions.ProgramError.errorMsg;
67
68public class NamingCzar {
69    public static final NamingCzar only = new NamingCzar(ForeignJava.only);
70
71    private final ForeignJava fj;
72
73    private NamingCzar(ForeignJava fj) {
74        this.fj = fj;
75    }
76
77    public static final String springBoard = "$SpringBoard";
78    public static final String make = "make";
79
80    public static final String cache = ProjectProperties.BYTECODE_CACHE_DIR + "/";
81
82    //Asm requires you to call visitMaxs for every method
83    // but ignores the arguments.
84    public static final int ignore = 1;
85
86    // fortress types
87    public static final String fortressPackage = "fortress";
88    public static final String fortressAny = fortressPackage + "/" +
89                                              WellKnownNames.anyTypeLibrary() +
90                                             "$" + WellKnownNames.anyTypeName;
91
92    // java.lang.Object correctly formatted for asm generation
93    public static final String javaObject = "java/lang/Object";
94
95    // Base class for all executable Fortress Components
96    public static final String fortressExecutable = "com/sun/fortress/runtimeSystem/FortressExecutable";
97    public static final String fortressExecutableRun = "runExecutable";
98    public static final String fortressExecutableRunType = "([Ljava/lang/String;)V";
99
100    // Base class for tasks
101    public static final String fortressBaseTask = "com/sun/fortress/runtimeSystem/BaseTask";
102
103    // Base class for non-executable Fortress Components
104    public static final String fortressComponent = javaObject;
105
106    public static final String primordialTask    = "com/sun/fortress/runtimeSystem/PrimordialTask";
107
108    // Classes: internal names
109    // (Section 2.1.2 in ASM 3.0: A Java bytecode engineering library)
110    public static final String internalFloat      = org.objectweb.asm.Type.getInternalName(float.class);
111    public static final String internalInt        = org.objectweb.asm.Type.getInternalName(int.class);
112    public static final String internalDouble     = org.objectweb.asm.Type.getInternalName(double.class);
113    public static final String internalLong       = org.objectweb.asm.Type.getInternalName(long.class);
114    public static final String internalBoolean    = org.objectweb.asm.Type.getInternalName(boolean.class);
115    public static final String internalChar       = org.objectweb.asm.Type.getInternalName(char.class);
116    public static final String internalObject     = org.objectweb.asm.Type.getInternalName(Object.class);
117    public static final String internalString     = org.objectweb.asm.Type.getInternalName(String.class);
118
119    public static final String descFloat         = org.objectweb.asm.Type.getDescriptor(float.class);
120    public static final String descInt           = org.objectweb.asm.Type.getDescriptor(int.class);
121    public static final String descDouble        = org.objectweb.asm.Type.getDescriptor(double.class);
122    public static final String descLong          = org.objectweb.asm.Type.getDescriptor(long.class);
123    public static final String descBoolean       = org.objectweb.asm.Type.getDescriptor(boolean.class);
124    public static final String descChar          = org.objectweb.asm.Type.getDescriptor(char.class);
125    public static final String descString        = internalToDesc(internalString);
126    public static final String descVoid          = org.objectweb.asm.Type.getDescriptor(void.class);
127    public static final String stringArrayToVoid = makeMethodDesc(makeArrayDesc(descString), descVoid);
128    public static final String voidToVoid        = makeMethodDesc("", descVoid);
129
130    public static final String internalFortressZZ32  = makeFortressInternal("ZZ32");
131    public static final String internalFortressZZ64  = makeFortressInternal("ZZ64");
132    public static final String internalFortressRR32  = makeFortressInternal("RR32");
133    public static final String internalFortressRR64  = makeFortressInternal("RR64");
134    public static final String internalFortressBoolean  = makeFortressInternal("Boolean");
135    public static final String internalFortressChar  = makeFortressInternal("Char");
136    public static final String internalFortressString = makeFortressInternal("String");
137    public static final String internalFortressVoid   = makeFortressInternal("Void");
138
139    // fortress interpreter types: type descriptors
140    public static final String descFortressZZ32  = internalToDesc(internalFortressZZ32);
141    public static final String descFortressZZ64  = internalToDesc(internalFortressZZ64);
142    public static final String descFortressRR32  = internalToDesc(internalFortressRR32);
143    public static final String descFortressRR64  = internalToDesc(internalFortressRR64);
144    public static final String descFortressBoolean  = internalToDesc(internalFortressBoolean);
145    public static final String descFortressChar  = internalToDesc(internalFortressChar);
146    public static final String descFortressString = internalToDesc(internalFortressString);
147    public static final String descFortressVoid   = internalToDesc(internalFortressVoid);
148    public static final String descFortressAny        = internalToDesc(fortressAny);
149
150    public static final String voidToFortressVoid = makeMethodDesc("", descFortressVoid);
151
152    private static final List<String> extendsObject =
153        Collections.singletonList(internalObject);
154
155    public static String deCase(String s) {
156        return "_" + Integer.toString(s.hashCode()&0x7fffffff,16);
157    }
158
159    public static String deCaseName(PathTaggedApiName ptan) {
160        return deCaseName(ptan.name, ptan.source_path);
161    }
162
163    public static String deCaseName(APIName s, String sourcePath) {
164        return s + "-" + Integer.toString(sourcePath.hashCode()&0x7fffffff,16);
165    }
166
167    public static String cachedPathNameForApiAst(String passedPwd, String sourcePath, APIName name) {
168        return ProjectProperties.apiFileName(passedPwd,  deCaseName(name, sourcePath));
169    }
170
171    public static String cachedPathNameForCompAst(String passedPwd, String sourcePath, APIName name) {
172        return ProjectProperties.compFileName(passedPwd,  deCaseName(name, sourcePath));
173    }
174
175    public static String dependenceFileNameForCompAst(APIName name, String sourcePath) {
176        return ProjectProperties.compFileName(ProjectProperties.ANALYZED_CACHE_DEPENDS_DIR, deCaseName(name, sourcePath));
177    }
178
179    public static String dependenceFileNameForApiAst(APIName name, String sourcePath) {
180        return ProjectProperties.apiFileName(ProjectProperties.ANALYZED_CACHE_DEPENDS_DIR, deCaseName(name, sourcePath));
181    }
182
183    /* Converting names of Fortress entities into Java entities.
184     *
185     1. FortressLibrary.ZZ32
186     what we call it in Fortress
187
188     2. L/com/sun/fortress/compiler/runtimeValues/FZZ32
189     the signature encoding of the Java type that we use to represent that.
190
191     3. I
192     the signature encoding of Java int.
193
194     4. int
195     Java int.
196
197     5. org.objectweb.asm.Type.INT_TYPE
198     The asm representation of the type of Java int.
199
200     6. java.lang.Integer.TYPE
201     The name of that "class" (int) in a running Java program.
202
203     *
204     * For foreign interfaces, there's two translations.  From the foreign
205     * type, to the Fortress type we choose for the Fortress interfaces,
206     * and then (same as other types) from the Fortress type to the type
207     * of its bytecode encoding.
208     *
209     */
210
211    static Span span = NodeFactory.internalSpan;
212
213    static APIName fortLib =
214        NodeFactory.makeAPIName(span, WellKnownNames.fortressBuiltin());
215
216    /**
217     * Given an ASM Type t from foreign Java, what is the corresponding type
218     * in Fortress (expressed as an AST Type node)?
219     *
220     * If it is not defined in the current foreign interface implementation,
221     * null is returned.
222     */
223    public static com.sun.fortress.nodes.Type fortressTypeForForeignJavaType(Type t) {
224        return fortressTypeForForeignJavaType(t.getDescriptor());
225    }
226
227    /**
228     * Given a Java type String descriptor ("Ljava/lang/Object;", V, [J, etc),
229     * what is the corresponding type in Fortress
230     * (expressed as an AST Type node)?
231     *
232     * If it is not defined in the current foreign interface implementation,
233     * null is returned.
234     */
235    public static com.sun.fortress.nodes.Type fortressTypeForForeignJavaType(String s) {
236        return specialForeignJavaTranslations.get(s);
237    }
238
239    // Translate among Java type names
240    // (Section 2.1.3 in ASM 3.0: A Java bytecode engineering library)
241
242    public static String internalToDesc(String type) {
243        return "L" + type + ";";
244    }
245    public static String makeMethodDesc(String param, String result) {
246        return "(" + param + ")" + result;
247    }
248    public static String makeMethodDesc(List<String> params, String result) {
249        String desc ="(";
250        for (String param : params) {
251            desc += param;
252        }
253        desc += ")" + result;
254        return desc;
255    }
256    public static String makeArrayDesc(String element) {
257        return "[" + element;
258    }
259
260    // fortress runtime types: internal names
261    public static String makeFortressInternal(String type) {
262        return "com/sun/fortress/compiler/runtimeValues/F" + type;
263    }
264
265
266    static Map<String, com.sun.fortress.nodes.Type> specialForeignJavaTranslations = new HashMap<String, com.sun.fortress.nodes.Type>();
267
268    /* Minor hackery here -- because we know these types are already loaded
269     * and not eligible for ASM-wrapping, we just go ahead and refer to the
270     * loaded class.
271     */
272    static void s(Class cl, APIName api, String str) {
273        s(Type.getType(cl), api, str);
274    }
275
276    static void s(Type cl, APIName api, String str) {
277        s(cl.getDescriptor(), api, str);
278    }
279
280    static void s(String cl, APIName api, String str) {
281        specialForeignJavaTranslations.put(cl,
282                NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, api, str))); /* api was commented out before... */
283    }
284
285    static {
286        s(Boolean.class, fortLib, "Boolean");
287        s(Type.BOOLEAN_TYPE, fortLib, "Boolean");
288        s(Integer.class, fortLib, "ZZ32");
289        s(Type.INT_TYPE, fortLib, "ZZ32");
290        s(Long.class, fortLib, "ZZ64");
291        s(Type.LONG_TYPE, fortLib, "ZZ64");
292        s(Float.class, fortLib, "RR32");
293        s(Type.FLOAT_TYPE, fortLib, "RR32");
294        s(Double.class, fortLib, "RR64");
295        s(Type.DOUBLE_TYPE, fortLib, "RR64");
296        s(Object.class, fortLib, "Any");
297        s(String.class, fortLib, "String");
298        s(BigInteger.class, fortLib, "ZZ");
299        specialForeignJavaTranslations.put("V", NodeFactory.makeVoidType(span));
300    }
301
302    static final String runtimeValues = "com/sun/fortress/compiler/runtimeValues/";
303
304    static final String FValueType = runtimeValues + "FValue";
305    static final String FValueDesc = "L" + FValueType + ";";
306
307    /**
308     * Java descriptors for (boxed) Fortress types, INCLUDING leading L and trailing ;
309     */
310    static Map<com.sun.fortress.nodes.Type, String> specialFortressDescriptors = new HashMap<com.sun.fortress.nodes.Type, String>();
311    /**
312     * Java descriptors for (boxed) Fortress types, WITHOUT leading L and trailing ;
313     */
314    static Map<com.sun.fortress.nodes.Type, String> specialFortressTypes = new HashMap<com.sun.fortress.nodes.Type, String>();
315
316    static void bl(APIName api, String str, String cl) {
317        b(api,str, runtimeValues+cl);
318    }
319
320    static void bl(com.sun.fortress.nodes.Type t, String cl) {
321        b(t, runtimeValues+cl);
322    }
323
324    static void b(APIName api, String str, String cl) {
325        b(NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, api, str)), cl);
326        b(NodeFactory.makeTraitType(span, false, NodeFactory.makeId(span, /* api, */ str)), cl);
327    }
328
329    static void b(com.sun.fortress.nodes.Type t, String cl) {
330        specialFortressDescriptors.put(t, "L" + cl + ";");
331        specialFortressTypes.put(t, cl );
332    }
333
334    static {
335        bl(fortLib, "Boolean", "FBoolean");
336        bl(fortLib, "Char", "FChar");
337        bl(fortLib, "RR32", "FRR32");
338        bl(fortLib, "RR64", "FRR64");
339        bl(fortLib, "ZZ32", "FZZ32");
340        bl(fortLib, "ZZ64", "FZZ64");
341        bl(fortLib, "String", "FString");
342        bl(NodeFactory.makeVoidType(span), "FVoid");
343    }
344
345
346    /**
347     * If a type occurs in a parameter list or return type, it
348     * is necessary to determine its name for purpose of generating
349     * the signature portion of a Java method name.
350     *
351     * The Java type that is generated will be an interface type for all
352     * trait types, and a final class for all object types.
353     *
354     * Generic object types yield non-final classes; they are extended by their
355     * instantiations (which are final classes).
356     */
357    public static String boxedImplDesc(com.sun.fortress.nodes.Type t, APIName ifNone) {
358        return jvmTypeDesc(t, ifNone);
359    }
360
361    public static String boxedImplType( com.sun.fortress.nodes.Type t ) {
362        // TODO: refactor to be like boxedImplDesc.  Somehow.
363        String desc = specialFortressTypes.get(t);
364
365        if (desc != null)
366            return desc;
367
368        if (t instanceof ArrowType) {
369
370        } else if (t instanceof BaseType) {
371            if (t instanceof AnyType) {
372                return FValueType;
373            } else if (t instanceof BottomType) {
374                return bug("Not sure how bottom type translates into Java");
375            } else if (t instanceof NamedType) {
376                if (t instanceof TraitType) {
377                    return FValueType;
378                } else if (t instanceof VarType) {
379                    return bug("Need a binding to translate a VarType into Java");
380                }
381            }
382        }
383        return bug ("unhandled type translation, Fortress type " + t);
384
385    }
386
387    public String apiNameToPackageName(APIName name) {
388        if (fj.definesApi(name)) {
389            return name.getText();
390        } else {
391            return javaPackageClassForApi(name.getText(), ".").toString();
392        }
393    }
394
395    public String apiAndMethodToMethodOwner(APIName name, Function method) {
396        String p;
397        String m = method.toUndecoratedName().toString();
398        if (fj.definesApi(name)) {
399             p = name.getText();
400             int idot = m.lastIndexOf(".");
401             if (idot != -1) {
402                 p = p + "/" + m.substring(0,idot);
403             }
404
405        } else {
406             p = javaPackageClassForApi(name.getText(), ".").toString();
407        }
408        p = Useful.replace(p, ".", "/") ;
409        return p;
410    }
411
412    public String apiAndMethodToMethod(APIName name, Function method) {
413        String m = method.toUndecoratedName().toString();
414        if (fj.definesApi(name)) {
415            int idot = m.lastIndexOf(".");
416            if (idot != -1) {
417                m = m.substring(idot+1);
418            }
419        }
420        return m;
421    }
422
423    /**
424     * @param componentName
425     * @return the name of the class implementing the compiled top-level
426     *         environment for component componentName.
427     */
428    public static String classNameForComponentEnvironment(APIName componentName) {
429        return classNameForComponentEnvironment(NodeUtil.nameString(componentName));
430    }
431
432    /**
433     * @param componentName
434     * @return the name of the class implementing the compiled top-level
435     *         environment for component componentName.
436     */
437    public static String classNameForComponentEnvironment(String componentName) {
438        componentName = componentName + TopLevelEnvGen.COMPONENT_ENV_SUFFIX;
439        componentName = mangleClassIdentifier(componentName);  // Need to mangle the name if it contains "."
440        return componentName;
441    }
442
443    /**
444     *
445     * @param apiName
446     * @return the name of the class implementing the compiled top-level
447     *         environment for api apiName
448     */
449    public static String classNameForApiEnvironment(APIName apiName) {
450        return classNameForApiEnvironment(NodeUtil.nameString(apiName));
451    }
452
453    /**
454     *
455     * @param apiName
456     * @return the name of the class implementing the compiled top-level
457     *         environment for apiName
458     */
459    public static String classNameForApiEnvironment(String apiName) {
460        apiName = apiName + TopLevelEnvGen.API_ENV_SUFFIX;
461        apiName = mangleClassIdentifier(apiName);  // Need to mangle the name if it contains "."
462        return apiName;
463    }
464
465    public static String mangleClassIdentifier(String identifier) {
466        String mangledString = identifier.replaceAll("\\.", "\\$");
467        return mangledString+deCase(mangledString);
468    }
469
470    /**
471     * @param extendsC
472     * @return The names of the Java interfaces providing the mentioned types;
473     *         if the extends clause is empty, fills in Object as required.
474     */
475    public static String [] extendsClauseToInterfaces(List<TraitTypeWhere> extendsC, APIName ifMissing) {
476        String [] result = new String[extendsC.size()];
477        int i = -1;
478        for (TraitTypeWhere ttw : extendsC) {
479            i++;
480            BaseType parentType = ttw.getBaseType();
481            if ( !(parentType instanceof TraitType) ) {
482                if ( parentType instanceof AnyType ) {
483                    result[i] = fortressAny;
484                    continue;
485                }
486                throw new CompilerError(NodeUtil.getSpan(parentType),
487                              errorMsg("Invalid type ",parentType," in extends clause."));
488            }
489            Id name = ((TraitType)parentType).getName();
490            Option<APIName> apiName = name.getApiName();
491
492//            if (apiName.isNone()) {
493//                // DRC -- This looks wrong to me: it should be the component/api containing the trait, not empty.
494//                result[i] = name.toString();
495//                continue;
496//            }
497            String api = apiName.unwrap(ifMissing).getText();
498
499            StringBuilder parent = javaPackageClassForApi(api, "/");  parent.append("$");  parent.append(name.getText());
500            result[i] = parent.toString();
501        }
502        return result;
503    }
504
505    /**
506     * @param api
507     * @return
508     */
509    public static StringBuilder javaPackageClassForApi(String api, String sep) {
510        StringBuilder parent = new StringBuilder();
511        if ( WellKnownNames.exportsDefaultLibrary( api ) ) {
512            parent.append(fortressPackage);  parent.append(sep);
513        }
514        if (!(sep.equals("."))) {
515            api = Useful.replace(api, ".", sep);
516        }
517        parent.append(api);
518        return parent;
519    }
520
521    /**
522     * Convert a string identifier into something that will be legal in a
523     * JVM.
524     *
525     * http://blogs.sun.com/jrose/entry/symbolic_freedom_in_the_vm
526     * Dangerous characters are the union of all characters forbidden
527     * or otherwise restricted by the JVM specification, plus their mates,
528     * if they are brackets.
529
530     * @param identifier
531     * @return
532     */
533    public static String mangleIdentifier(String identifier) {
534
535        // 1. In each accidental escape, replace the backslash with an escape sequence (\-)
536        String mangledString = identifier.replaceAll("\\\\", "\\\\-");
537
538        // 2. Replace each dangerous character with an escape sequence (\| for /, etc.)
539
540        mangledString = mangledString.replaceAll("/", "\\\\|");
541        mangledString = mangledString.replaceAll("\\.", "\\\\,");
542        mangledString = mangledString.replaceAll(";", "\\\\?");
543        mangledString = mangledString.replaceAll("\\$", "\\\\%");
544        mangledString = mangledString.replaceAll("<", "\\\\^");
545        mangledString = mangledString.replaceAll(">", "\\\\_");
546        mangledString = mangledString.replaceAll("\\[", "\\\\{");
547        mangledString = mangledString.replaceAll("\\]", "\\\\}");
548        mangledString = mangledString.replaceAll(":", "\\\\!");
549
550        // Non-standard name-mangling convention.  Michael Spiegel 6/16/2008
551        mangledString = mangledString.replaceAll("\\ ", "\\\\~");
552
553        // 3. If the first two steps introduced any change, <em>and</em> if the
554        // string does not already begin with a backslash, prepend a null prefix (\=)
555        if (!mangledString.equals(identifier) && !(mangledString.charAt(0) == '\\')) {
556            mangledString = "\\=" + mangledString;
557        }
558        return mangledString;
559    }
560
561    public String mangleAwayFromOverload(String mname) {
562            mname += "$SINGLE";
563        return mname;
564    }
565
566    private static int taskCount = 0;
567    public static String gensymTaskName(String packageAndClassName) {
568        return packageAndClassName + "$" + "task" + taskCount++;
569    }
570
571    public static String makeInnerClassName(Id id) {
572        return makeInnerClassName(jvmClassForSymbol(id), id.getText());
573    }
574
575    public static String makeInnerClassName(String packageAndClassName, String t) {
576        return packageAndClassName + "$" + t;
577    }
578
579    public static String jvmSignatureFor(com.sun.fortress.nodes.Type domain,
580                                         com.sun.fortress.nodes.Type range,
581                                         APIName ifNone) {
582        return makeMethodDesc(
583                   NodeUtil.isVoidType(domain) ? "" : jvmTypeDesc(domain, ifNone),
584                   jvmTypeDesc(range, ifNone));
585    }
586
587    public static String jvmSignatureFor(List<com.sun.fortress.nodes.Param> domain,
588                                         com.sun.fortress.nodes.Type range,
589                                         APIName ifNone) {
590        String args = "";
591        // This special case handles single void argument type properly.
592        if (domain.size() == 1)
593            return jvmSignatureFor(domain.get(0).getIdType().unwrap(), range, ifNone);
594        for (Param p : domain) {
595            args += jvmTypeDesc(p.getIdType(), ifNone);
596        }
597        return makeMethodDesc(args, jvmTypeDesc(range, ifNone));
598    }
599
600    public static String jvmSignatureFor(Function f, APIName ifNone) {
601        return jvmSignatureFor(f.parameters(), f.getReturnType(), ifNone);
602    }
603
604    public static String jvmSignatureFor(FnDecl f, APIName ifNone) {
605        FnHeader h = f.getHeader();
606        return jvmSignatureFor(h.getParams(), h.getReturnType().unwrap(), ifNone);
607    }
608
609    public static String jvmClassForSymbol(IdOrOp fnName) {
610        Option<APIName> maybe_api = fnName.getApiName();
611        String result = "";
612        if (maybe_api.isSome()) {
613            APIName apiName = maybe_api.unwrap();
614            if (WellKnownNames.exportsDefaultLibrary(apiName.getText()))
615                result = result + "fortress/";
616            result = result + apiName.getText();
617        }
618        //        result = result + fnName.getText();
619
620        Debug.debug(Debug.Type.CODEGEN, 1,
621                    "jvmClassForSymbol(" + fnName +")=" + result);
622        return result;
623    }
624
625    public static String jvmTypeDesc(com.sun.fortress.nodes.Type type,
626            final APIName ifNone) {
627        return type.accept(new NodeAbstractVisitor<String>() {
628            public void defaultCase(ASTNode x) {
629                throw new CompilerError(NodeUtil.getSpan(x),
630                                        "emitDesc of type failed");
631            }
632            public String forArrowType(ArrowType t) {
633                if (NodeUtil.isVoidType(t.getDomain()))
634                    return makeMethodDesc("", jvmTypeDesc(t.getRange(), ifNone));
635                else return makeMethodDesc(jvmTypeDesc(t.getDomain(), ifNone),
636                                           jvmTypeDesc(t.getRange(), ifNone));
637            }
638            public String forTupleType(TupleType t) {
639                if ( NodeUtil.isVoidType(t) )
640                    return descFortressVoid;
641                if (t.getVarargs().isSome())
642                    throw new CompilerError(NodeUtil.getSpan(t),
643                                            "Can't compile VarArgs yet");
644                if (!t.getKeywords().isEmpty())
645                    throw new CompilerError(NodeUtil.getSpan(t),
646                                            "Can't compile Keyword args yet");
647                String res = "";
648                for (com.sun.fortress.nodes.Type ty : t.getElements()) {
649                    res += jvmTypeDesc(ty, ifNone);
650                }
651                return res;
652            }
653            public String forAnyType (AnyType t) {
654                return descFortressAny;
655            }
656            public String forTraitType(TraitType t) {
657                Id id = t.getName();
658                String name = id.getText();
659                String result = specialFortressDescriptors.get(t);
660                if (result != null) {
661                    Debug.debug(Debug.Type.CODEGEN, 1, "forTrait Type ", t ,
662                                " builtin ", result);
663                    return result;
664                }
665                Option<APIName> maybeApi = id.getApiName();
666                if (ifNone == null && !maybeApi.isSome()) {
667                    throw new CompilerError(NodeUtil.getSpan(id),
668                                            "no api name given for id");
669                }
670                APIName api = maybeApi.unwrap(ifNone);
671                result = "L" + makeInnerClassName(api.getText(), name) + ";";
672
673                Debug.debug(Debug.Type.CODEGEN, 1, "forTrait Type ", t, " = ", result);
674
675                return result;
676            }
677            });
678    }
679
680    public static String jvmTypeDesc(Option<com.sun.fortress.nodes.Type> otype, APIName ifNone) {
681        if (!otype.isSome()) {
682            throw new CompilerError("Expected type information was absent.");
683        }
684        return jvmTypeDesc(otype.unwrap(), ifNone);
685    }
686
687}
Note: See TracBrowser for help on using the browser.