public override TypeReference ResolveType(Application app, Page page) { MethodDefinition meth = page.GetMethod (Name); ResolvedType = meth.ReturnType; return ResolvedType; }
public Page(Application application, AssemblyDefinition assembly, TypeDefinition definition, string path) { this.application = application; this.assembly = assembly; this.path = path; Definition = definition; ctor = new MethodDefinition (".ctor", MethodAttributes.Public, assembly.MainModule.Import (typeof (void))); Definition.Methods.Add (ctor); ValueToStringMethod = AddValueToStringMethod (); render_to_stream = AddRenderToResponseMethod ("RenderToResponse"); ILProcessor p = render_to_stream.Body.GetILProcessor (); first_instruction = p.Create (OpCodes.Nop); p.Append (first_instruction); method_stack = new Stack<MethodDefinition> (); method_stack.Push (render_to_stream); forloop_stack = new Stack<ForLoopContext> (); }
public override TypeReference ResolveType(Application app, Page page) { ResolvedType = app.Assembly.MainModule.Import (typeof (string)); return ResolvedType; }
public override void Emit(Application app, Page page, ILProcessor processor) { MethodDefinition meth = page.GetMethod (Name); processor.Emit (OpCodes.Ldarg_0); processor.Emit (OpCodes.Ldarg_1); processor.Emit (OpCodes.Ldarg_2); for (int i = 2; i < meth.Parameters.Count; i++) { if (i - 2 < Arguments.Count) { Arguments [i - 2].Emit (app, page, processor); continue; } ParameterDefinition p = meth.Parameters [i]; if (!p.HasConstant) throw new Exception ("Illegal invoke statement, incorrect number of parameters."); object constant = p.Constant; if (constant is string) processor.Emit (OpCodes.Ldstr, (string) constant); else if (constant is int) processor.Emit (OpCodes.Ldc_I4, (int) constant); else if (constant is double) processor.Emit (OpCodes.Ldc_R4, (double) constant); else throw new Exception (String.Format ("Illegal default argument type {0}", constant)); } processor.Emit (OpCodes.Call, meth); }
public virtual TypeReference ResolveType(Application app, Page page) { if (filters.Count < 1) ResolvedType = Value.ResolveType (app, page); else ResolvedType = app.Assembly.MainModule.Import (typeof (string)); return ResolvedType; }
public override void Emit(Application app, Page page, ILProcessor processor) { var filter = MingeFilterManager.GetFilter (Name); if (filter == null) return; for (int i = 0; i < Arguments.Count; i++) { Arguments [i].Emit (app, page, processor); } processor.Emit (OpCodes.Call, app.Assembly.MainModule.Import (filter)); }
public override void Emit(Application app, Page page, ILProcessor processor) { processor.Emit (OpCodes.Ldstr, Value); }
public override void Emit(Application app, Page page, ILProcessor processor) { Target.Emit (app, page, processor); // Attempt to resolve the property on the resolved type PropertyDefinition prop = Target.ResolvedType.Resolve ().Properties.Where (p => p.Name == Property).FirstOrDefault (); if (prop != null) { MethodReference get_method = app.Assembly.MainModule.Import (prop.GetMethod); processor.Emit (OpCodes.Call, get_method); return; } processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetTypeMethod); processor.Emit (OpCodes.Ldstr, Property); processor.Emit (OpCodes.Ldc_I4, (int) (System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)); processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyMethod); Target.Emit (app, page, processor); processor.Emit (OpCodes.Ldnull); processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyValueMethod); }
public override void Emit(Application app, Page page, ILProcessor processor) { if (page.IsForLoopVariable (Name.Name)) { page.EmitForLoopVariableAccess (); return; } if (page.IsBuiltInVariable (Name.Name)) { page.EmitBuiltInVariable (Name.Name); return; } ParameterDefinition pvar = page.FindParameter (Name.Name); if (pvar != null) { ResolvedType = pvar.ParameterType; processor.Emit (OpCodes.Ldarg, pvar); return; } VariableDefinition localvar = page.FindLocalVariable (Name.Name); if (localvar != null) { ResolvedType = localvar.VariableType; processor.Emit (OpCodes.Ldloc, localvar); return; } // Attempt to resolve the property on the resolved type PropertyDefinition prop = page.Definition.Properties.Where (p => p.Name == Name.Name).FirstOrDefault (); if (prop != null) { MethodReference get_method = app.Assembly.MainModule.Import (prop.GetMethod); processor.Emit (OpCodes.Call, get_method); return; } // // Attempt to load it from the supplied type, look for a property // on the type with the correct name. // processor.Emit (OpCodes.Ldarg_2); processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetTypeMethod); processor.Emit (OpCodes.Ldstr, Name.Name); processor.Emit (OpCodes.Ldc_I4, (int) (System.Reflection.BindingFlags.IgnoreCase | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)); processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyMethod); processor.Emit (OpCodes.Ldarg_2); processor.Emit (OpCodes.Ldnull); processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetPropertyValueMethod); /* ResolvedType = app.Assembly.MainModule.Import (typeof (object)); processor.Emit (OpCodes.Ldarg_2); processor.Emit (OpCodes.Ldstr, Name.Name); processor.Emit (OpCodes.Callvirt, app.CommonMethods.ContainsKeyMethod); Instruction contains_branch = processor.Emit (OpCodes.Brfalse, processor.Create (OpCodes.Nop)); processor.Emit (OpCodes.Ldarg_2); processor.Emit (OpCodes.Ldstr, Name.Name); processor.Emit (OpCodes.Callvirt, app.CommonMethods.GetArgMethod); Instruction gotarg_branch = processor.Emit (OpCodes.Br, processor.Create (OpCodes.Nop)); Instruction load_empty_target = processor.Emit (OpCodes.Ldsfld, app.CommonMethods.StringEmptyField); contains_branch.Operand = load_empty_target; Instruction completed_target = processor.Emit (OpCodes.Nop); gotarg_branch.Operand = completed_target; */ }
public override TypeReference ResolveType(Application app, Page page) { ParameterDefinition pvar = page.FindParameter (Name.Name); if (pvar != null) { ResolvedType = pvar.ParameterType; return ResolvedType; } VariableDefinition localvar = page.FindLocalVariable (Name.Name); if (localvar != null) { ResolvedType = localvar.VariableType; return ResolvedType; } ResolvedType = app.Assembly.MainModule.Import (typeof (object)); return ResolvedType; }
public abstract TypeReference ResolveType(Application app, Page page);
public abstract void Emit(Application app, Page page, ILProcessor processor);
public override TypeReference ResolveType(Application app, Page page) { PropertyDefinition prop = Target.ResolvedType.Resolve ().Properties.Where (p => p.Name == Property).FirstOrDefault (); if (prop != null) { MethodReference get_method = app.Assembly.MainModule.Import (prop.GetMethod); ResolvedType = prop.PropertyType; return ResolvedType; } ResolvedType = app.Assembly.MainModule.Import (typeof (object)); return ResolvedType; }
public MingeParser(MingeEnvironment environment, Application application) { this.application = application; this.environment = environment; }
public virtual void Emit(Application app, Page page, ILProcessor processor) { Value.Emit (app, page, processor); ResolveType (app, page); foreach (Filter filter in filters) { filter.Emit (app, page, processor); } }
private Application CreateApplication() { Application app = new Application (this, Environment.AssemblyName, Environment.AssemblyPath); return app; }
public void EmitToString(Application app, Page page, ILProcessor processor, TypeReference resolved) { if (resolved.FullName == "System.String") return; if (resolved.FullName == "System.Void") { processor.Emit (OpCodes.Ldsfld, application.CommonMethods.StringEmptyField); return; } if (resolved.IsValueType) { processor.Emit (OpCodes.Box, app.Assembly.MainModule.Import (resolved)); processor.Emit (OpCodes.Call, app.Assembly.MainModule.Import (page.ValueToStringMethod)); return; } TypeDefinition rtype = resolved.Resolve (); MethodReference method = rtype.Methods.Where (m => m.Name == "ToString").First (); // Import it so we get a method reference method = application.Assembly.MainModule.Import (method); Instruction inst = processor.Create (OpCodes.Callvirt, (MethodReference) method); processor.Append (inst); }