Coverage Report - com.sun.tools.javafx.code.JavafxSymtab
 
Classes in this File Line Coverage Branch Coverage Complexity
JavafxSymtab
100%
83/83
91%
20/22
0
JavafxSymtab$1
100%
2/2
N/A
0
 
 1  
 /*
 2  
  * Copyright 2007 Sun Microsystems, Inc.  All Rights Reserved.
 3  
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  
  *
 5  
  * This code is free software; you can redistribute it and/or modify it
 6  
  * under the terms of the GNU General Public License version 2 only, as
 7  
  * published by the Free Software Foundation.  Sun designates this
 8  
  * particular file as subject to the "Classpath" exception as provided
 9  
  * by Sun in the LICENSE file that accompanied this code.
 10  
  *
 11  
  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  
  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  
  * version 2 for more details (a copy is included in the LICENSE file that
 15  
  * accompanied this code).
 16  
  *
 17  
  * You should have received a copy of the GNU General Public License version
 18  
  * 2 along with this work; if not, write to the Free Software Foundation,
 19  
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  
  *
 21  
  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 22  
  * CA 95054 USA or visit www.sun.com if you need additional information or
 23  
  * have any questions.
 24  
  */
 25  
 
 26  
 package com.sun.tools.javafx.code;
 27  
 
 28  
 import com.sun.tools.javac.code.Symtab;
 29  
 import com.sun.tools.javac.code.Type;
 30  
 import com.sun.tools.javac.code.Types;
 31  
 import com.sun.tools.javac.code.Symbol;
 32  
 import com.sun.tools.javac.util.Context;
 33  
 import com.sun.tools.javac.code.Type.*;
 34  
 import static com.sun.tools.javac.jvm.ByteCodes.*;
 35  
 import com.sun.tools.javac.util.*;
 36  
 import com.sun.tools.javac.code.Symbol.TypeSymbol;
 37  
 import com.sun.tools.javac.code.TypeTags;
 38  
 import com.sun.tools.javafx.comp.JavafxDefs;
 39  
 
 40  
 /**
 41  
  *
 42  
  * @author Robert Field
 43  
  */
 44  12
 public class JavafxSymtab extends Symtab {
 45  
     
 46  
 
 47  
     // Javafx types
 48  
     public final Type javafx_IntegerType;
 49  
     public final Type javafx_NumberType;
 50  
     public final Type javafx_AnyType;
 51  
     public final Type javafx_UnspecifiedType;
 52  
     public final Type javafx_StringType;
 53  
     public final Type javafx_BooleanType;
 54  
     public final Type javafx_DurationType;
 55  
     public final Type javafx_VoidType;
 56  
     public final Type javafx_java_lang_VoidType;
 57  
     public final Type javafx_SequenceType;
 58  
     public final Type javafx_SequenceTypeErasure;
 59  
     static public final int MAX_FIXED_PARAM_LENGTH = 8;
 60  399
     public final Type[] javafx_FunctionTypes = new Type[MAX_FIXED_PARAM_LENGTH+1];
 61  
     public final Type javafx_FXObjectType;
 62  
     public final Type javafx_SequencesType;
 63  
     public final Type javafx_ColorType;
 64  
     public final Type javafx_KeyValueType;
 65  
     public final Type javafx_PointerType;
 66  
     public final Type javafx_LocationType;
 67  
     public final Type javafx_ColorInterpolatorType;
 68  
     public final Type javafx_NumberInterpolatorType;
 69  
     
 70  
     public final Type javafx_privateAnnotationType;
 71  
     public final Type javafx_protectedAnnotationType;
 72  
     public final Type javafx_publicAnnotationType;
 73  
     public final Type javafx_staticAnnotationType;
 74  
     
 75  
     public final Name runMethodName;
 76  
     
 77  
     /** The type of expressions that never returns a value to its parent.
 78  
      * E.g. an expression that always throws an Exception.
 79  
      * Likewise, a "return expression" returns from the outer function,
 80  
      * which makes any following/surrounding code unreachable.
 81  
      */
 82  
     public final Type unreachableType;
 83  
 
 84  
     private Types types;
 85  
 
 86  
     public static final String functionClassPrefix =
 87  
             "com.sun.javafx.functions.Function";
 88  
 
 89  
     public static void preRegister(final Context context) {
 90  798
         context.put(symtabKey, new Context.Factory<Symtab>() {
 91  
             public Symtab make() {
 92  399
                 return new JavafxSymtab(context);
 93  
             }
 94  
         });
 95  399
     }
 96  
     
 97  
     /** Creates a new instance of JavafxSymtab */
 98  
     JavafxSymtab(Context context) {
 99  399
         super(context);
 100  
 
 101  
         // FIXME It would be better to make 'names' in super-class be protected.
 102  399
         Name.Table names = Name.Table.instance(context);
 103  399
         types = Types.instance(context);
 104  
         
 105  399
         javafx_IntegerType = intType;
 106  399
         javafx_NumberType = doubleType;
 107  399
         javafx_AnyType = objectType;
 108  399
         javafx_UnspecifiedType = unknownType;
 109  399
         javafx_StringType = stringType;
 110  399
         javafx_BooleanType = booleanType;
 111  399
         javafx_VoidType = voidType;
 112  399
         javafx_DurationType = enterClass("javafx.lang.Duration");
 113  399
         unreachableType = new Type(TypeTags.VOID, null);
 114  399
         unreachableType.tsym = new TypeSymbol(0, names.fromString("<unreachable>"), Type.noType, rootPackage);
 115  399
         javafx_java_lang_VoidType = types.boxedClass(voidType).type;
 116  399
         javafx_SequenceType = enterClass("com.sun.javafx.runtime.sequence.Sequence");
 117  399
         javafx_SequencesType = enterClass("com.sun.javafx.runtime.sequence.Sequences");
 118  399
         javafx_SequenceTypeErasure = types.erasure(javafx_SequenceType);
 119  399
         javafx_ColorType = enterClass("javafx.ui.Color");
 120  399
         javafx_KeyValueType = enterClass("javafx.animation.KeyValue");
 121  399
         javafx_PointerType = enterClass("com.sun.javafx.runtime.Pointer");
 122  399
         javafx_LocationType = enterClass("ccom.sun.javafx.runtime.location.Location");
 123  399
         javafx_ColorInterpolatorType = enterClass("javafx.ui.animation.ColorInterpolator");
 124  399
         javafx_NumberInterpolatorType = enterClass("javafx.ui.animation.NumberInterpolator");
 125  399
         javafx_privateAnnotationType = enterClass("com.sun.javafx.runtime.Private");
 126  399
         javafx_protectedAnnotationType = enterClass("com.sun.javafx.runtime.Protected");
 127  399
         javafx_publicAnnotationType = enterClass("com.sun.javafx.runtime.Public");
 128  399
         javafx_staticAnnotationType = enterClass("com.sun.javafx.runtime.Static");
 129  399
         for (int i = MAX_FIXED_PARAM_LENGTH; --i >= 0;  ) {
 130  3192
             javafx_FunctionTypes[i] = enterClass(functionClassPrefix+i);
 131  
         }
 132  
         
 133  399
         runMethodName = names.fromString(JavafxDefs.runMethodString);
 134  
         
 135  399
         javafx_FXObjectType = enterClass("com.sun.javafx.runtime.FXObject");
 136  399
         enterOperators();
 137  399
     }
 138  
     
 139  
     public void enterOperators() {
 140  399
         super.enterOperators();
 141  
         
 142  399
         enterBinop("<>", objectType, objectType, booleanType, if_acmpne);
 143  399
         enterBinop("<>", booleanType, booleanType, booleanType, if_icmpne);
 144  399
         enterBinop("<>", doubleType, doubleType, booleanType, dcmpl, ifne);
 145  399
         enterBinop("<>", floatType, floatType, booleanType, fcmpl, ifne);
 146  399
         enterBinop("<>", longType, longType, booleanType, lcmp, ifne);
 147  399
         enterBinop("<>", intType, intType, booleanType, if_icmpne);
 148  
 
 149  399
         enterBinop("and", booleanType, booleanType, booleanType, bool_and);
 150  399
         enterBinop("or", booleanType, booleanType, booleanType, bool_or);
 151  
         
 152  
         // Enter JavaFX operators.
 153  399
         enterUnop("sizeof", javafx_SequenceType, javafx_IntegerType, 0);
 154  
         
 155  399
         enterUnop("lazy", doubleType, doubleType, 0);
 156  399
         enterUnop("lazy", intType, intType, 0);
 157  399
         enterUnop("lazy", booleanType, booleanType, 0);
 158  399
         enterUnop("lazy", objectType, objectType, 0);
 159  
 
 160  399
         enterUnop("bind", doubleType, doubleType, 0);
 161  399
         enterUnop("bind", intType, intType, 0);
 162  399
         enterUnop("bind", booleanType, booleanType, 0);
 163  399
         enterUnop("bind", objectType, objectType, 0);
 164  399
     }
 165  
 
 166  
     public boolean isRunMethod(Symbol sym) {
 167  1165
         return sym.name == runMethodName;
 168  
     }
 169  
 
 170  
     public Type boxIfNeeded(Type elemType) {
 171  1996
         if (elemType.isPrimitive() || elemType == voidType)
 172  566
             return types.boxedClass(elemType).type;
 173  
         else
 174  1430
             return elemType;
 175  
     }
 176  
     
 177  
     public FunctionType makeFunctionType(List<Type> typarams) {
 178  2756
         ListBuffer<Type> argtypes = new ListBuffer<Type>();
 179  2756
         Type restype = null;
 180  8118
         for (List<Type> l = typarams; l.nonEmpty();  l = l.tail) {
 181  5362
             Type a = l.head;
 182  5362
             if (a instanceof WildcardType)
 183  2842
                 a = ((WildcardType) a).type;
 184  5362
             if (restype == null) {
 185  2756
                 if (a.tsym.name == javafx_java_lang_VoidType.tsym.name) {
 186  2520
                     a = voidType;
 187  
                 }
 188  2756
                 restype = a;
 189  
             }
 190  
             else
 191  2606
                 argtypes.append(a);
 192  
         }
 193  2756
         MethodType mtype = new MethodType(argtypes.toList(), restype, null, methodClass);
 194  2756
         return makeFunctionType(typarams, mtype);
 195  
     }
 196  
 
 197  
     public FunctionType makeFunctionType(List<Type> typarams, MethodType mtype) {
 198  2972
         int nargs = typarams.size()-1;
 199  
         assert nargs <= MAX_FIXED_PARAM_LENGTH
 200  2972
                 : "NOT IMPLEMENTED - functions with >"+MAX_FIXED_PARAM_LENGTH+" parameters";
 201  2972
         Type funtype = javafx_FunctionTypes[nargs];
 202  2972
         return new FunctionType(funtype.getEnclosingType(), typarams, funtype.tsym, mtype);
 203  
     }
 204  
 
 205  
     /** Given a MethodType, create the corresponding FunctionType.
 206  
      */
 207  
     public FunctionType makeFunctionType(MethodType mtype) {
 208  183
         Type rtype = mtype.restype;
 209  183
         ListBuffer<Type> typarams = new ListBuffer<Type>();
 210  183
         typarams.append(boxIfNeeded(rtype));
 211  220
         for (List<Type> l = mtype.argtypes; l.nonEmpty(); l = l.tail) {
 212  37
             typarams.append(boxIfNeeded(l.head));
 213  
         }
 214  183
         return makeFunctionType(typarams.toList(), mtype);
 215  
     }
 216  
 }