public static void Assign(this BlockStatement block, Expression left, Expression right)
 {
     if (left == null)
         throw new ArgumentNullException("left");
     if (right == null)
         throw new ArgumentNullException("right");
     AddStatement(block, new AssignmentExpression(left, AssignmentOperatorType.Assign, right));
 }
 public LocalLookupVariable(string name, TypeReference typeRef, Location startPos, Location endPos, bool isConst, bool isLoopVariable, Expression initializer, LambdaExpression parentLambdaExpression, bool isQueryContinuation)
 {
     this.Name = name;
     this.TypeRef = typeRef;
     this.StartPos = startPos;
     this.EndPos = endPos;
     this.IsConst = isConst;
     this.IsLoopVariable = isLoopVariable;
     this.Initializer = initializer;
     this.ParentLambdaExpression = parentLambdaExpression;
     this.IsQueryContinuation = isQueryContinuation;
 }
Example #3
0
        /// <summary>
        /// Returns the existing expression plus the specified integer value.
        /// The old <paramref name="expr"/> object is not modified, but might be a subobject on the new expression
        /// (and thus its parent property is modified).
        /// </summary>
        public static Expression AddInteger(Expression expr, int value)
        {
            PrimitiveExpression pe = expr as PrimitiveExpression;
            if (pe != null && pe.Value is int) {
                int newVal = (int)pe.Value + value;
                return new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
            }
            BinaryOperatorExpression boe = expr as BinaryOperatorExpression;
            if (boe != null && boe.Op == BinaryOperatorType.Add) {
                // clone boe:
                boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right);

                boe.Right = AddInteger(boe.Right, value);
                if (boe.Right is PrimitiveExpression && ((PrimitiveExpression)boe.Right).Value is int) {
                    int newVal = (int)((PrimitiveExpression)boe.Right).Value;
                    if (newVal == 0) {
                        return boe.Left;
                    } else if (newVal < 0) {
                        ((PrimitiveExpression)boe.Right).Value = -newVal;
                        boe.Op = BinaryOperatorType.Subtract;
                    }
                }
                return boe;
            }
            if (boe != null && boe.Op == BinaryOperatorType.Subtract) {
                pe = boe.Right as PrimitiveExpression;
                if (pe != null && pe.Value is int) {
                    int newVal = (int)pe.Value - value;
                    if (newVal == 0)
                        return boe.Left;

                    // clone boe:
                    boe = new BinaryOperatorExpression(boe.Left, boe.Op, boe.Right);

                    if (newVal < 0) {
                        newVal = -newVal;
                        boe.Op = BinaryOperatorType.Add;
                    }
                    boe.Right = new PrimitiveExpression(newVal, newVal.ToString(System.Globalization.NumberFormatInfo.InvariantInfo));
                    return boe;
                }
            }
            BinaryOperatorType opType = BinaryOperatorType.Add;
            if (value < 0) {
                value = -value;
                opType = BinaryOperatorType.Subtract;
            }
            return new BinaryOperatorExpression(expr, opType, new PrimitiveExpression(value, value.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)));
        }
Example #4
0
 public CatchClause(Statement statementBlock)
 {
     StatementBlock = statementBlock;
     typeReference = TypeReference.Null;
     variableName = "";
     condition = Expression.Null;
 }
Example #5
0
 public AddressOfExpression(Expression expression)
 {
     Expression = expression;
 }
        void AddEventHandler(Expression eventExpr, Expression handler, object data)
        {
            methodReference = true;
            CodeExpression methodInvoker = (CodeExpression)handler.AcceptVisitor(this, data);
            methodReference = false;
            if (!(methodInvoker is CodeObjectCreateExpression)) {
                // we need to create an event handler here
                methodInvoker = new CodeObjectCreateExpression(new CodeTypeReference("System.EventHandler"), methodInvoker);
            }

            if (eventExpr is IdentifierExpression) {
                AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), ((IdentifierExpression)eventExpr).Identifier),
                                                     methodInvoker));
            } else {
                MemberReferenceExpression fr = (MemberReferenceExpression)eventExpr;
                AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression((CodeExpression)fr.TargetObject.AcceptVisitor(this, data), fr.MemberName),
                                                     methodInvoker));
            }
        }
Example #7
0
 public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label)
 {
     BinaryOperatorType = binaryOperatorType;
     Label = label;
     toExpression = Expression.Null;
 }
        public void AddVariable(TypeReference typeRef, string name,
		                        Location startPos, Location endPos, bool isConst,
		                        bool isLoopVariable, Expression initializer,
		                        LambdaExpression parentLambdaExpression,
		                        bool isQueryContinuation)
        {
            if (name == null || name.Length == 0) {
                return;
            }
            List<LocalLookupVariable> list;
            if (!variables.ContainsKey(name)) {
                variables[name] = list = new List<LocalLookupVariable>();
            } else {
                list = (List<LocalLookupVariable>)variables[name];
            }
            list.Add(new LocalLookupVariable(name, typeRef, startPos, endPos, isConst, isLoopVariable, initializer, parentLambdaExpression, isQueryContinuation));
        }
Example #9
0
 public TypeOfIsExpression(Expression expression, TypeReference typeReference)
 {
     Expression = expression;
     TypeReference = typeReference;
 }
Example #10
0
 public static Expression CheckNull(Expression expression)
 {
     return expression == null ? NullExpression.Instance : expression;
 }
Example #11
0
 public UnaryOperatorExpression(Expression expression, UnaryOperatorType op)
 {
     Expression = expression;
     Op = op;
 }
Example #12
0
 public XmlAttributeExpression()
 {
     name = "";
     literalValue = "";
     expressionValue = Expression.Null;
 }
Example #13
0
 public CastExpression(TypeReference castTo)
 {
     CastTo = castTo;
     expression = Expression.Null;
 }
Example #14
0
 public WithStatement(Expression expression)
 {
     Expression = expression;
     body = BlockStatement.Null;
 }
Example #15
0
 public VariableDeclaration(string name, Expression initializer, TypeReference typeReference)
 {
     Name = name;
     Initializer = initializer;
     TypeReference = typeReference;
     fixedArrayInitialization = Expression.Null;
 }
Example #16
0
 public VariableDeclaration(string name)
 {
     Name = name;
     initializer = Expression.Null;
     typeReference = TypeReference.Null;
     fixedArrayInitialization = Expression.Null;
 }
Example #17
0
 public CollectionRangeVariable()
 {
     identifier = "";
     expression = Expression.Null;
     type = TypeReference.Null;
 }
 /// <summary>
 /// Just calls the BinaryOperatorExpression constructor,
 /// but being an extension method; this allows for a nicer
 /// infix syntax in some cases.
 /// </summary>
 public static BinaryOperatorExpression Operator(this Expression left, BinaryOperatorType op, Expression right)
 {
     return new BinaryOperatorExpression(left, op, right);
 }
Example #19
0
 public XmlElementExpression()
 {
     content = Expression.Null;
     nameExpression = Expression.Null;
     xmlName = "";
     attributes = new List<XmlExpression>();
 }
Example #20
0
 public UnaryOperatorExpression(UnaryOperatorType op)
 {
     Op = op;
     expression = Expression.Null;
 }
 void CheckMemberReferenceExpression(Expression expr, string memberName, string targetObjectIdentifier)
 {
     Assert.IsTrue(expr is MemberReferenceExpression);
     Assert.IsTrue((expr as MemberReferenceExpression).MemberName == memberName &&
                   (expr as MemberReferenceExpression).TargetObject is IdentifierExpression &&
                   ((expr as MemberReferenceExpression).TargetObject as IdentifierExpression).Identifier == targetObjectIdentifier);
 }
Example #22
0
 public CastExpression(TypeReference castTo, Expression expression, CastType castType)
 {
     CastTo = castTo;
     Expression = expression;
     CastType = castType;
 }
Example #23
0
 public XmlEmbeddedExpression()
 {
     inlineVBExpression = Expression.Null;
 }
Example #24
0
 public XmlMemberAccessExpression(Expression targetObject, XmlAxisType axisType, string identifier, bool isXmlIdentifier)
 {
     TargetObject = targetObject;
     AxisType = axisType;
     Identifier = identifier;
     IsXmlIdentifier = isXmlIdentifier;
 }
 public static void AddStatement(this BlockStatement block, Expression expressionStatement)
 {
     if (expressionStatement == null)
         throw new ArgumentNullException("expressionStatement");
     AddStatement(block, new ExpressionStatement(expressionStatement));
 }
Example #26
0
 public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock)
 {
     TypeReference = typeReference;
     VariableName = variableName;
     StatementBlock = statementBlock;
     condition = Expression.Null;
 }
 public static void Throw(this BlockStatement block, Expression expression)
 {
     if (expression == null)
         throw new ArgumentNullException("expression");
     AddStatement(block, new ThrowStatement(expression));
 }
Example #28
0
 public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock, Expression condition)
 {
     TypeReference = typeReference;
     VariableName = variableName;
     StatementBlock = statementBlock;
     Condition = condition;
 }
 Expression CheckPropertyInitializationExpression(Expression e, string name)
 {
     Assert.IsInstanceOf(typeof(MemberInitializerExpression), e);
     Assert.AreEqual(name, ((MemberInitializerExpression)e).Name);
     return ((MemberInitializerExpression)e).Expression;
 }
Example #30
0
 public CaseLabel(Expression label, Expression toExpression)
 {
     Label = label;
     ToExpression = toExpression;
 }