private ObjectLookupExpression ParseStaticLookupExpression(ExpressionNode left) { ObjectLookupExpression ret = NewNode <ObjectLookupExpression>(); NextToken(); ExpectToken(TokenType.IDENTIFIER); ret.Object = left; ret.Lookup = StrVal; NextToken(); return(ret); }
public AstNode RefactorStaticLookups(ObjectLookupExpression exp) { return(new ArrayLookupExpression { Object = exp.Object, Lookup = new StringLiteral { Value = exp.Lookup } }); }
private Expression CompileLookupExpression(ObjectLookupExpression node) { Expression Object = CompileExpression(node.Object, ValueTypes.OBJECT); return(Expression.Call(Object, ReflectionConstants.MethodGetObjProp, Expression.Constant(node.Lookup))); }
private Expression CompileObjectLookupAssignment(TokenType token, ObjectLookupExpression var, ExpressionNode value) { ParameterExpression valueReference = Expression.Parameter(typeof(W_Type)); if (token == TokenType.ASSIGN) { /* Expression is of the following form * { * W_Type val = Right; * Left.Object[key] = val; * return val; * } */ return(Expression.Block(typeof(W_Type), new ParameterExpression[] { valueReference }, Expression.Assign(valueReference, CompileExpression(value, ValueTypes.BOXED)), Expression.Call(CompileExpression(var.Object, ValueTypes.OBJECT), ReflectionConstants.MethodSetObjProp, Expression.Constant(var.Lookup), valueReference), valueReference )); } ParameterExpression objectReference = Expression.Parameter(typeof(W_Object)); Expression Right = CompileExpression(value, ValueTypes.DOUBLE); //Expression of the following form //object["key"].Number Expression Left = UnboxExpression( Expression.Call( objectReference, ReflectionConstants.MethodGetObjProp, Expression.Constant(var.Lookup) ), ValueTypes.DOUBLE ); /* Expression is of the following form * { * W_Object obj = Left.Object; * W_Type val = obj[key].Number (op) Right.Number; * obj[key] = val; * return val; * } */ Expression retval = Expression.Block( typeof(W_Type), new ParameterExpression[] { objectReference, valueReference }, Expression.Assign( objectReference, CompileExpression(var.Object, ValueTypes.OBJECT) ), Expression.Assign( valueReference, BoxExpression(CompileAssignmentInfix(token, Left, Right)) ), Expression.Call( objectReference, ReflectionConstants.MethodSetObjProp, Expression.Constant(var.Lookup), valueReference ), valueReference ); Console.WriteLine(retval.Type); return(retval); }