Ejemplo n.º 1
0
        public void EmitIf(Expression expression)
        {
            if (IsChildTemplate)
                return;

            TypeReference string_type = application.Assembly.MainModule.Import (typeof (string));

            ILProcessor processor = CurrentMethod.Body.GetILProcessor ();
            expression.Emit (application, this, processor);
            Instruction null_branch = processor.Create (OpCodes.Brfalse, processor.Create (OpCodes.Nop));
            processor.Append (null_branch);

            expression.Emit (application, this, processor);
            processor.Emit (OpCodes.Isinst, string_type);
            Instruction isstr_branch = processor.Create (OpCodes.Brfalse, processor.Create (OpCodes.Nop));
            processor.Append (isstr_branch);

            expression.Emit (application, this, processor);
            processor.Emit (OpCodes.Castclass, string_type);
            processor.Emit (OpCodes.Call, application.CommonMethods.IsNullOrEmptyMethod);
            Instruction empty_branch = processor.Create (OpCodes.Brtrue, processor.Create (OpCodes.Nop));
            processor.Append (empty_branch);

            isstr_branch.Operand = processor.Create (OpCodes.Nop);
            processor.Append ((Instruction) isstr_branch.Operand);

            IfContext ifcontext = new IfContext ();
            ifcontext.NextConditionalBranches.Add (null_branch);
            ifcontext.NextConditionalBranches.Add (empty_branch);

            ifstack.Push (ifcontext);
        }
Ejemplo n.º 2
0
        public void EmitSinglePrint(Expression expression)
        {
            if (IsChildTemplate)
                return;

            ILProcessor processor = CurrentMethod.Body.GetILProcessor ();

            processor.Emit (OpCodes.Ldarg_1);
            expression.Emit (application, this, processor);
            EmitToString (application, this, processor, expression.ResolvedType);
            processor.Emit (OpCodes.Callvirt, application.CommonMethods.WriteStringMethod);
        }
Ejemplo n.º 3
0
        public void BeginForLoop(string name, Expression expression)
        {
            if (IsChildTemplate)
                return;

            TypeReference enum_type = assembly.MainModule.Import (typeof (System.Collections.IEnumerable));

            string local_enum_name = String.Format ("__enum_{0}", forloop_stack.Count);
            VariableDefinition enumeratorvar = FindLocalVariable (local_enum_name);
            if (enumeratorvar == null) {
                Mono.Collections.Generic.Collection<VariableDefinition> vars = CurrentMethod.Body.Variables;
                enumeratorvar = new VariableDefinition (local_enum_name, enum_type);
                vars.Add (enumeratorvar);
            }

            ILProcessor processor = CurrentMethod.Body.GetILProcessor ();
            expression.Emit (application, this, processor);
            processor.Emit (OpCodes.Castclass, assembly.MainModule.Import (typeof (System.Collections.IEnumerable)));
            processor.Emit (OpCodes.Callvirt, application.CommonMethods.GetEnumeratorMethod);

            processor.Emit (OpCodes.Stloc, enumeratorvar);

            Instruction begin_loop = processor.Create (OpCodes.Br, processor.Create (OpCodes.Nop));
            processor.Append (begin_loop);

            forloop_stack.Push (new ForLoopContext (name, begin_loop, enumeratorvar));

            processor.Emit (OpCodes.Nop);
        }
Ejemplo n.º 4
0
        public void EmitSet(NamedTarget target, Expression expression)
        {
            expression.ResolveType (application, this);

            PropertyDefinition property = FindProperty (target.Name, expression.ResolvedType);
            if (property == null)
                property = AddProperty (target.Name, expression.ResolvedType);

            //
            // Property setting happens in the ctor
            //

            ILProcessor processor = ctor.Body.GetILProcessor ();
            processor.Emit (OpCodes.Ldarg_0);
            expression.Emit (application, this, processor);
            processor.Emit (OpCodes.Call, property.SetMethod);
        }