////////////////////////////////////////////////////////////////////////// // Is/As ////////////////////////////////////////////////////////////////////////// private void @is() { FTypeRef typeRef = pod.typeRef(u2()); // if a generic instance, we have to use a method call // because Fantom types don't map to Java classes exactly; // otherwise we can use straight bytecode if (typeRef.isGenericInstance()) { if (parent.IsViaType == null) { parent.IsViaType = emitter.findMethod("Fanx.Util.OpUtil", "is", new string[] { "System.Object", "Fan.Sys.Type" }, "System.Boolean"); } loadType(typeRef); code.MethInst(MethodOp.call, parent.IsViaType); } else { PERWAPI.Type type = emitter.findType(typeRef.nnameBoxed()); code.TypeInst(TypeOp.isinst, type); code.Inst(Op.ldnull); code.Inst(Op.cgt_un); } }
private void @as() { FTypeRef typeRef = pod.typeRef(u2()); PERWAPI.Type type = emitter.findType(typeRef.nnameBoxed()); code.TypeInst(TypeOp.isinst, type); }
/// <summary> /// Find the Method for this method on the given type. /// </summary> internal Method findMethod(string qname, string methodName, string[] paramTypes, string returnType) { string key = getMethodKey(qname, methodName, paramTypes); Method method = (Method)methods[key]; if (method == null) { // this stuff should be the same for both cases PERWAPI.Type rtype = findType(returnType); PERWAPI.Type[] pars = new PERWAPI.Type[paramTypes.Length]; for (int i = 0; i < paramTypes.Length; i++) { pars[i] = findType(paramTypes[i]); } // check for stubs object obj = findType(qname); if (obj is ClassDef) { // class is an internal stub, so we need to stub this // method out too, which should get flushed out later ClassDef cdef = obj as ClassDef; // TODO - need to fix attrs Param[] mpars = new Param[pars.Length]; for (int i = 0; i < mpars.Length; i++) { mpars[i] = new Param(ParamAttr.Default, "v" + i, pars[i]); } // TODO - fix param names // Use Public here for stub - real MethAttr will be set // when method is flushed out method = cdef.AddMethod(MethAttr.Public, ImplAttr.IL, methodName, rtype, mpars); } else if (obj is ClassRef) { // class is external, just get or add ref ClassRef cref = obj as ClassRef; method = cref.GetMethod(methodName, pars, new PERWAPI.Type[0]); if (method == null) { method = cref.AddMethod(methodName, rtype, pars); } } else { throw new System.Exception("Don't know how to handle: " + obj.GetType()); } // make sure we add method to hashtable methods[key] = method; } return(method); }
/// <summary> /// Find the Field for this field on the given type. /// </summary> internal Field findField(string qname, string fieldName, string fieldType) { string key = qname + "/F" + fieldName; Field field = (Field)fields[key]; if (field == null) { // should be same for both cases PERWAPI.Type ftype = findType(fieldType); // check for stubs object obj = findType(qname); if (obj is ClassDef) { // class is an internal stub, so we need to stub this field // out too, which is actually complete and not a stub ClassDef cdef = obj as ClassDef; // TODO - fix attr field = cdef.AddField(FieldAttr.Public, fieldName, ftype); } else if (obj is ClassRef) { // class is external, just get or add ref ClassRef cref = obj as ClassRef; field = cref.GetField(fieldName); if (field == null) { field = cref.AddField(fieldName, ftype); } } else { throw new System.Exception("Don't know how to handle: " + obj.GetType()); } // remember to add field to lookup table fields[key] = field; } return(field); }
////////////////////////////////////////////////////////////////////////// // Coercion ////////////////////////////////////////////////////////////////////////// private void cast() { PERWAPI.Type type = emitter.findType(pod.typeRef(u2()).nname()); code.TypeInst(TypeOp.castclass, type); }
////////////////////////////////////////////////////////////////////////// // Util ////////////////////////////////////////////////////////////////////////// /// <summary> /// Find the Type instance for this fully qualified type name. /// </summary> internal PERWAPI.Type findType(string qname) { // Always convert voids to native if (qname == "Fan.Sys.Void") { qname = "System.Void"; } PERWAPI.Type type = (PERWAPI.Type)types[qname]; if (type == null) { string aname = FanUtil.getPodName(qname); if (aname == null) { aname = "mscorlib"; } if (qname.StartsWith("Fanx.")) { aname = "sys"; // hack for support classes } if (qname.EndsWith("Peer")) { aname += "Native_"; // TODO } // first check if this is a type in this pod that // hasn't been defined yet if (aname == assemblyName) { // stub out type - fill get filled in later (we hope) string[] sn = FanUtil.splitQName(qname); ClassDef stub = null; if (qname.IndexOf("/") != -1) { // Nested class PERWAPI.ClassDef cdef = (PERWAPI.ClassDef)findType(sn[0]); stub = cdef.AddNestedClass(PERWAPI.TypeAttr.NestedPublic, sn[1]); } else { // Normal class stub = peFile.AddClass(PERWAPI.TypeAttr.Public, sn[0], sn[1]); } types[qname] = stub; return(stub); } AssemblyRef aref = (AssemblyRef)assemblies[aname]; if (aref == null) { aref = peFile.MakeExternAssembly(aname); assemblies[aname] = aref; } string[] s = FanUtil.splitQName(qname); if (qname.IndexOf("/") != -1) { // Nested class PERWAPI.ClassRef cref = (PERWAPI.ClassRef)findType(s[0]); type = cref.AddNestedClass(s[1]); } /* * else if (qname.IndexOf("<") != -1) * { * // Generic type * //if (type == null) type = aref.AddClass(s[0], s[1]); * PERWAPI.ClassRef cref = (PERWAPI.ClassRef)findType(s[0]); * cref.SetGenericParams(new GenericParam[] { cref.GetGenericParam(0) }); * type = cref; * } */ else { // Normal class, get/add type type = aref.GetClass(s[0], s[1]); if (type == null) { type = aref.AddClass(s[0], s[1]); } } types[qname] = type; } return(type); }
/// <summary> /// Find the Method for this method on the given type. /// </summary> internal Method findMethod(string qname, string methodName, string[] paramTypes, string returnType) { string key = getMethodKey(qname, methodName, paramTypes); Method method = (Method)methods[key]; if (method == null) { // this stuff should be the same for both cases PERWAPI.Type rtype = findType(returnType); PERWAPI.Type[] pars = new PERWAPI.Type[paramTypes.Length]; for (int i=0; i<paramTypes.Length; i++) pars[i] = findType(paramTypes[i]); // check for stubs object obj = findType(qname); if (obj is ClassDef) { // class is an internal stub, so we need to stub this // method out too, which should get flushed out later ClassDef cdef = obj as ClassDef; // TODO - need to fix attrs Param[] mpars = new Param[pars.Length]; for (int i=0; i<mpars.Length; i++) mpars[i] = new Param(ParamAttr.Default, "v"+i, pars[i]); // TODO - fix param names // Use Public here for stub - real MethAttr will be set // when method is flushed out method = cdef.AddMethod(MethAttr.Public, ImplAttr.IL, methodName, rtype, mpars); } else if (obj is ClassRef) { // class is external, just get or add ref ClassRef cref = obj as ClassRef; method = cref.GetMethod(methodName, pars, new PERWAPI.Type[0]); if (method == null) method = cref.AddMethod(methodName, rtype, pars); } else throw new System.Exception("Don't know how to handle: " + obj.GetType()); // make sure we add method to hashtable methods[key] = method; } return method; }
internal void ldtoken(Type aType) { buffer.TypeInst(TypeOp.ldtoken, aType); }