public Expression ToExpression(ParseContext context) { switch (AssignType) { case (AssignementOperator.Assign): { //if (RValue.ParsedType.IsValueType) { return Expression.Assign(LValue.ToExpression(context),Expression.Convert(RValue.ToExpression(context),LValue.ParsedType)); } //return Expression.Assign(LValue.ToExpression(context), RValue.ToExpression(context)); } case (AssignementOperator.MultiplyAssign): return Expression.MultiplyAssign(LValue.ToExpression(context), RValue.ToExpression(context)); case (AssignementOperator.SubtractAssign): return Expression.SubtractAssign(LValue.ToExpression(context), RValue.ToExpression(context)); case (AssignementOperator.SumAssign): { if (LValue.ParsedType == typeof(string) || RValue.ParsedType == typeof(string)) { Expression<Func<object, object, string>> func = ((a, b) => SumAssign(a, b)); return Expression.Assign(LValue.ToExpression(context), Expression.Invoke(func, LValue.ToExpression(context), RValue.ToExpression(context))); } return Expression.AddAssign(LValue.ToExpression(context), RValue.ToExpression(context)); } } throw new InvalidEnumArgumentException(); }
public void PreParseExpression(ParseContext context) { RValue.PreParseExpression(context); LValue.PreParseExpression(context); ParsedType = LValue.ParsedType; }
public void PreParseExpression(ParseContext context) { _paramTypes = new List<Type>(); for (int i = 0; i < Parameters.Length; i++) { Parameters[i].PreParseExpression(context); _paramTypes.Add(Parameters[i].ParsedType); } Type type = StaticDataType; if (StaticDataType == null) { type = Variable.ParsedType; if (Variable is OperationVariable) { var variable = context.GetVariable(((OperationVariable)Variable).Name); type = variable.DataType; } } var methodInfo = type.GetMethod( MethodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance |BindingFlags.Static, null, _paramTypes.ToArray(), null); ParsedType = methodInfo.ReturnType; }
public void PreParseExpression(ParseContext context) { if (_value == null) ParsedType = typeof(object); else ParsedType = _value.GetType(); }
public override void PreParseExpression(ParseContext context) { RValue.PreParseExpression(context); _rType = RValue.ParsedType; LValue.PreParseExpression(context); _lType = LValue.ParsedType; ParsedType = typeof(bool); }
public override void PreParseExpression(ParseContext context) { for (int i = 0; i < SubConditions.Count; i++) { SubConditions[i].PreParseExpression(context); } ParsedType = typeof(bool); }
internal Expression DefaultInitialize(ParseContext context) { if (VariableDeclaration.Expression == null) { VariableDeclaration.Expression = ToExpression(context); } return Expression.Assign(VariableDeclaration.Expression, Expression.Default(VariableDeclaration.DataType)); }
public string ToString(ParseContext context) { if (!string.IsNullOrWhiteSpace(context.ReturnVariable)) { return "return " + context.ReturnVariable; } return "return"; }
public string ToString(ParseContext context) { var result = "new " + ReflectionUtil.TypeToString(DataType) + "("; for (int i = 0; i < Variables.Length; i++) { if (i > 0) result += ", "; result += Variables[i].ToString(context); } return result + ")"; }
public void PreParseExpression(ParseContext context) { _constructorTypes = new List<Type>(); foreach (var param in Variables) { param.PreParseExpression(context); _constructorTypes.Add(param.ParsedType); } ParsedType = DataType; }
public string ToString(ParseContext context) { if (_value == null) return "null"; var type = _value.GetType(); if (type.IsValueType || type.IsEnum) { return _value.ToString(); } return "\"" + _value + "\""; }
public override string ToString(ParseContext context) { var res = "("; var operation = IsAnd ? "&&" : "||"; for (int i = 0; i < SubConditions.Count; i++) { if (i > 0) res += operation; res += SubConditions[i].ToString(context); } return res + ")"; }
public Expression ToExpression(ParseContext context) { var pars = new List<Expression>(); foreach (var param in Variables) { pars.Add(param.ToExpression(context)); } return Expression.NewArrayInit(DataType.GetElementType(), pars); }
public void PreParseExpression(ParseContext context) { _paramTypes = new List<Type>(); for (int i = 0; i < Parameters.Length; i++) { Parameters[i].PreParseExpression(context); _paramTypes.Add(Parameters[i].ParsedType); } ParsedType = null; }
public Expression ToExpression(ParseContext context) { var variable = context.GetVariable(Name); if (variable != null) { if (variable.Expression == null) { variable.Expression = Expression.Parameter(ParsedType, Name); } return variable.Expression; } return Expression.Parameter(ParsedType, Name); }
public void PreParseExpression(ParseContext context) { //var pl = context.Current; Condition.PreParseExpression(context); context.AddLevel(); foreach (var line in CodeLines) { line.PreParseExpression(context); } context.RemoveLevel(); }
public override Expression ToExpression(ParseContext context) { Expression result = null; for (int index = (SubConditions.Count - 2); index >= 0; index--) { if (result == null) { var l = SubConditions[index].ToExpression(context); var r = SubConditions[index + 1].ToExpression(context); result = BuildOperation(l, r); } else { var l = SubConditions[index].ToExpression(context); result = BuildOperation(l, result); } } return result; }
public string ToString(ParseContext context) { var result = string.Empty; if (StaticDataType == null) { result = Variable.ToString(context); } else { result = ReflectionUtil.TypeToString(StaticDataType); } result += "." + MethodName + "("; for (int i = 0; i < Parameters.Length; i++) { if (i > 0) result += ", "; result += Parameters[i].ToString(context); } return result + ")"; }
public string ToString(ParseContext context) { var result = "while(" + Condition.ToString(context) + ")\n"; result += context.Pad + "{\n"; context.AddLevel(); foreach (var line in CodeLines) { var createVariable = line as CreateVariable; if (createVariable != null) { createVariable.DefaultInitialize(context); } result += context.Pad + line.ToString(context) + ";\n"; } context.RemoveLevel(); result += context.Pad + "}"; return result; }
public Expression ToExpression(ParseContext context) { var pars = new List<Expression>(); foreach (var param in Variables) { pars.Add(param.ToExpression(context)); } var constructor = ReflectionUtil.GetConstructor(DataType, _constructorTypes); if (constructor.GoodFrom >= 0) { var startDefault = constructor.GoodFrom; while (startDefault < constructor.ParamValues.Count) { pars.Add(Operation.Constant(constructor.ParamValues[constructor.GoodFrom]).ToExpression(context)); startDefault++; } } return Expression.New(constructor.Method as ConstructorInfo, pars); }
public ParseLevel(ParseContext parseContext) { _variables = new Dictionary<string, Variable>(StringComparer.InvariantCultureIgnoreCase); _parseContext = parseContext; }
public Expression ToExpression(ParseContext context) { var conditionExpression = Condition.ToExpression(context); context.AddLevel(); var thenLine = new List<Expression>(); var listOfThenVars = new List<ParameterExpression>(); foreach (var line in ThenCodeLines) { var expLine = line.ToExpression(context); var createVariable = line as CreateVariable; if (createVariable != null) { listOfThenVars.Add((ParameterExpression)expLine); expLine = createVariable.DefaultInitialize(context); } thenLine.Add(expLine); } var thenBlock = Expression.Block(listOfThenVars.ToArray(), thenLine); context.RemoveLevel(); var elseLine = new List<Expression>(); if (ElseCodeLines.Count > 0) { context.AddLevel(); var listOfElseVars = new List<ParameterExpression>(); foreach (var line in ElseCodeLines) { var expLine = line.ToExpression(context); var createVariable = line as CreateVariable; if (createVariable != null) { listOfElseVars.Add((ParameterExpression)expLine); expLine = createVariable.DefaultInitialize(context); } elseLine.Add(expLine); } context.RemoveLevel(); var elseBlock = Expression.Block(listOfElseVars, elseLine); return Expression.IfThenElse(conditionExpression, thenBlock, elseBlock); } return Expression.IfThen(conditionExpression, thenBlock); }
public Expression ToExpression(ParseContext context) { var pars = new List<Expression>(); foreach (var param in Parameters) { pars.Add(param.ToExpression(context)); } if (_paramTypes == null) { _paramTypes = new List<Type>(); for (int i = 0; i < Parameters.Length; i++) { Parameters[i].PreParseExpression(context); _paramTypes.Add(Parameters[i].ParsedType); } } Type type = StaticDataType; if (StaticDataType == null) { type = Variable.ParsedType; if (Variable is OperationVariable) { var variable = context.GetVariable(((OperationVariable)Variable).Name); type = variable.DataType; } } var method = ReflectionUtil.GetMethod(type, MethodName, _paramTypes); if (method.GoodFrom >= 0) { var startDefault = method.GoodFrom; while (startDefault < method.ParamValues.Count) { pars.Add(Operation.Constant(method.ParamValues[method.GoodFrom]).ToExpression(context)); startDefault++; } } var my = (MethodInfo)method.Method; if ((my.Attributes & MethodAttributes.Static)==0) { return Expression.Call(Variable.ToExpression(context), method.Method as MethodInfo, pars); } return Expression.Call(method.Method as MethodInfo, pars); }
public abstract Expression ToExpression(ParseContext context);
public Expression ToExpression(ParseContext context) { context.Current.AddVariable(VariableDeclaration); VariableDeclaration.Expression = Expression.Variable(VariableDeclaration.DataType, VariableDeclaration.Name); return VariableDeclaration.Expression; }
public void PreParseExpression(ParseContext context) { context.Current.AddVariable(VariableDeclaration); ParsedType = VariableDeclaration.DataType; }
public Expression ToExpression(ParseContext context) { return Expression.Constant(_value); }
public abstract void PreParseExpression(ParseContext context);
public Expression ToExpression(ParseContext context) { var conditionExpression = Condition.ToExpression(context); context.AddLevel(); var thenLine = new List<Expression>(); var listOfThenVars = new List<ParameterExpression>(); foreach (var line in CodeLines) { var expLine = line.ToExpression(context); var createVariable = line as CreateVariable; if (createVariable != null) { listOfThenVars.Add((ParameterExpression)expLine); expLine = createVariable.DefaultInitialize(context); } thenLine.Add(expLine); } var thenBlock = Expression.Block(listOfThenVars.ToArray(), thenLine); context.RemoveLevel(); LabelTarget label = Expression.Label(Guid.NewGuid().ToString()); var ifThenElse = Expression.IfThenElse( conditionExpression, thenBlock, Expression.Break(label)); return Expression.Loop(ifThenElse, label); }
public string ToString(ParseContext context) { return ReflectionUtil.TypeToString(VariableDeclaration.DataType) + " " + VariableDeclaration.Name; }