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); }
public Expression ParseExpression(MingeTokenizer tk, TokenType end_token_type, bool allow_conditionals=true) { Value target_value = ParseRValue (tk); Expression expression = null; Token tok = NextNonWhiteSpaceToken (tk); if (tok.Type == TokenType.TOKEN_DOT) { tok = NextNonWhiteSpaceToken (tk); if (tok.Type != TokenType.TOKEN_NAME) RaiseFailure (tk, String.Format ("Invalid expression, token '{0}' found where a name was expected.", tok.Value)); expression = new Expression (new PropertyAccessValue (target_value, tok.Value)); NextNonWhiteSpaceToken (tk); } else if (tok.Type == TokenType.TOKEN_LBRACKET) { string prop_name = ParseSubscript (tk); expression = new Expression (new PropertyAccessValue (target_value, prop_name)); NextNonWhiteSpaceToken (tk); } else if (tok.Type == TokenType.TOKEN_LPAREN) { VariableValue target = target_value as VariableValue; if (target == null) RaiseFailure (tk, String.Format ("Invalid invoke expression, expected a name got a {0}", target_value)); List<Expression> args = ParseArguments (tk); if (tk.Current.Type != TokenType.TOKEN_RPAREN) RaiseFailure (tk, String.Format ("Invalid invoke expression, token '{0}' where a ) was expected.", tk.Current.Value)); expression = new Expression (new InvokeValue (target.Name.Name, args)); NextNonWhiteSpaceToken (tk); } else expression = new Expression (target_value); while (tok.Type != end_token_type && tok.Type != TokenType.TOKEN_EOF) { if (tok.Type == TokenType.TOKEN_PIPE) { Filter filter = ParseFilter (tk); expression.AddFilter (filter); } else if (allow_conditionals && IsConditionalToken (tok)) { CompareOperator compare = CompareOperatorFromToken (tok); // expression = new ConditionalExpression (expression, compare, ParseExpression (tk, end_token_type)); } else break; tok = tk.Current; } if (tok.Type == TokenType.TOKEN_EOF) RaiseFailure (tk, "Unexpected eof of file found while parsing expression."); return expression; }
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); }
public void EmitElseIf(Expression expression) { if (IsChildTemplate) return; }
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); }
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); }
public void EmitSinglePrint(Expression expression) { }
public void EmitPrint(Expression expression) { }
public void EmitIf(Expression expression) { }
public void EmitElse(Expression expression) { }
public void BeginForeachLoop(string var, Expression expression) { }