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.GetType(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.GetType(context.ClassLoader, type); } ilgen.Emit(opcode, typeType); }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { if (Type != null) { ilgen.Emit(OpCodes.Ldsfld, StaticCompiler.GetType(context.ClassLoader, Type).GetField(Name, BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)); } else { FieldWrapper fw = ClassLoaderWrapper.LoadClassCritical(Class).GetFieldWrapper(Name, Sig); fw.Link(); // we don't use fw.EmitGet because we don't want automatic unboxing and whatever ilgen.Emit(OpCodes.Ldsfld, fw.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.GetType(context.ClassLoader, type); } } }
internal override void Generate(CodeGenContext context, CodeEmitter ilgen) { LocalBuilder lb = (LocalBuilder)context[Name]; if (lb == null) { if (typeWrapper == null && typeType == null) { Debug.Assert(Class == null ^ type == null); if (type != null) { typeType = StaticCompiler.GetType(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.GetType(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) { LocalBuilder[] temps = new LocalBuilder[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 { throw new InvalidOperationException(); } } else { Type[] argTypes; if (Sig.StartsWith("(")) { argTypes = context.ClassLoader.ArgTypeListFromSig(Sig); } else { string[] types = Sig.Split(';'); argTypes = new Type[types.Length]; for (int i = 0; i < types.Length; i++) { argTypes[i] = StaticCompiler.GetType(context.ClassLoader, types[i]); } } MethodInfo mi = StaticCompiler.GetType(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.GetType(context.ClassLoader, type)); }