internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { ilgen.BeginExceptionBlock(); @try.Generate(context, ilgen); if (@catch != null) { Type type; if (@catch.type != null) { type = StaticCompiler.GetTypeForMapXml(context.ClassLoader, @catch.type); } else { type = context.ClassLoader.LoadClassByDottedName(@catch.Class).TypeAsExceptionType; } ilgen.BeginCatchBlock(type); @catch.Generate(context, ilgen); } if (@finally != null) { ilgen.BeginFinallyBlock(); @finally.Generate(context, ilgen); } ilgen.EndExceptionBlock(); }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { if (typeType == null) { Debug.Assert(type != null); typeType = StaticCompiler.GetTypeForMapXml(context.ClassLoader, type); } ilgen.Emit(opcode, typeType); }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { if (Type != null) { ilgen.Emit(OpCodes.Ldsfld, StaticCompiler.GetTypeForMapXml(context.ClassLoader, Type).GetField(Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); } else { // we don't use fw.EmitGet because we don't want automatic unboxing and whatever ilgen.Emit(OpCodes.Ldsfld, StaticCompiler.GetFieldForMapXml(context.ClassLoader, Class, Name, Sig).GetField()); } }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { if (typeWrapper == null && typeType == null) { Debug.Assert(Class == null ^ type == null); if (Class != null) { typeWrapper = context.ClassLoader.LoadClassByDottedName(Class); } else { typeType = StaticCompiler.GetTypeForMapXml(context.ClassLoader, type); } } }
private MemberInfo Resolve(CodeGenContext context) { if (type != null) { if (Class != null || Method != null || Field != null || Sig != null) { throw new NotImplementedException(); } return(StaticCompiler.GetTypeForMapXml(context.ClassLoader, type)); } else if (Class != null) { TypeWrapper tw = context.ClassLoader.LoadClassByDottedNameFast(Class); if (tw == null) { return(null); } else if (Method != null) { MethodWrapper mw = tw.GetMethodWrapper(Method, Sig, false); if (mw == null) { return(null); } return(mw.GetMethod()); } else if (Field != null) { FieldWrapper fw = tw.GetFieldWrapper(Field, Sig); if (fw == null) { return(null); } return(fw.GetField()); } else { return(tw.TypeAsBaseType); } } else { return(null); } }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { CodeEmitterLocal lb = (CodeEmitterLocal)context[Name]; if (lb == null) { if (typeWrapper == null && typeType == null) { Debug.Assert(Class == null ^ type == null); if (type != null) { typeType = StaticCompiler.GetTypeForMapXml(context.ClassLoader, type); } else { typeWrapper = context.ClassLoader.LoadClassByDottedName(Class); } } lb = ilgen.DeclareLocal(typeType != null ? typeType : typeWrapper.TypeAsTBD); context[Name] = lb; } ilgen.Emit(OpCodes.Stloc, lb); }
internal sealed override void Generate(CodeGenContext context, CodeEmitter ilgen) { Debug.Assert(Name != null); if (Name == ".ctor") { Debug.Assert(Class == null && type != null); Type[] argTypes = context.ClassLoader.ArgTypeListFromSig(Sig); ConstructorInfo ci = StaticCompiler.GetTypeForMapXml(context.ClassLoader, type).GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, CallingConventions.Standard, argTypes, null); if (ci == null) { throw new InvalidOperationException("Missing .ctor: " + type + "..ctor" + Sig); } ilgen.Emit(opcode, ci); } else { Debug.Assert(Class == null ^ type == null); if (Class != null) { Debug.Assert(Sig != null); MethodWrapper method = context.ClassLoader.LoadClassByDottedName(Class).GetMethodWrapper(Name, Sig, false); if (method == null) { throw new InvalidOperationException("method not found: " + Class + "." + Name + Sig); } method.Link(); // TODO this code is part of what Compiler.CastInterfaceArgs (in compiler.cs) does, // it would be nice if we could avoid this duplication... TypeWrapper[] argTypeWrappers = method.GetParameters(); for (int i = 0; i < argTypeWrappers.Length; i++) { if (argTypeWrappers[i].IsGhost) { CodeEmitterLocal[] temps = new CodeEmitterLocal[argTypeWrappers.Length + (method.IsStatic ? 0 : 1)]; for (int j = temps.Length - 1; j >= 0; j--) { TypeWrapper tw; if (method.IsStatic) { tw = argTypeWrappers[j]; } else { if (j == 0) { tw = method.DeclaringType; } else { tw = argTypeWrappers[j - 1]; } } if (tw.IsGhost) { tw.EmitConvStackTypeToSignatureType(ilgen, null); } temps[j] = ilgen.DeclareLocal(tw.TypeAsSignatureType); ilgen.Emit(OpCodes.Stloc, temps[j]); } for (int j = 0; j < temps.Length; j++) { ilgen.Emit(OpCodes.Ldloc, temps[j]); } break; } } if (opcode.Value == OpCodes.Call.Value) { method.EmitCall(ilgen); } else if (opcode.Value == OpCodes.Callvirt.Value) { method.EmitCallvirt(ilgen); } else if (opcode.Value == OpCodes.Newobj.Value) { method.EmitNewobj(ilgen); } else { // ldftn or ldvirtftn ilgen.Emit(opcode, (MethodInfo)method.GetMethod()); } } else { Type[] argTypes; if (Sig.StartsWith("(")) { argTypes = context.ClassLoader.ArgTypeListFromSig(Sig); } else if (Sig == "") { argTypes = Type.EmptyTypes; } else { string[] types = Sig.Split(';'); argTypes = new Type[types.Length]; for (int i = 0; i < types.Length; i++) { argTypes[i] = StaticCompiler.GetTypeForMapXml(context.ClassLoader, types[i]); } } MethodInfo mi = StaticCompiler.GetTypeForMapXml(context.ClassLoader, type).GetMethod(Name, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static, null, argTypes, null); if (mi == null) { throw new InvalidOperationException("Missing method: " + type + "." + Name + Sig); } ilgen.Emit(opcode, mi); } } }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { ilgen.Emit(OpCodes.Ldtoken, StaticCompiler.GetTypeForMapXml(context.ClassLoader, type)); }