예제 #1
0
 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));
 }
예제 #2
0
 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;
 }
예제 #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)));
        }
예제 #4
0
 public CatchClause(Statement statementBlock)
 {
     StatementBlock = statementBlock;
     typeReference = TypeReference.Null;
     variableName = "";
     condition = Expression.Null;
 }
예제 #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));
            }
        }
예제 #7
0
 public CaseLabel(BinaryOperatorType binaryOperatorType, Expression label)
 {
     BinaryOperatorType = binaryOperatorType;
     Label = label;
     toExpression = Expression.Null;
 }
예제 #8
0
        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));
        }
예제 #9
0
 public TypeOfIsExpression(Expression expression, TypeReference typeReference)
 {
     Expression = expression;
     TypeReference = typeReference;
 }
예제 #10
0
 public static Expression CheckNull(Expression expression)
 {
     return expression == null ? NullExpression.Instance : expression;
 }
예제 #11
0
 public UnaryOperatorExpression(Expression expression, UnaryOperatorType op)
 {
     Expression = expression;
     Op = op;
 }
예제 #12
0
 public XmlAttributeExpression()
 {
     name = "";
     literalValue = "";
     expressionValue = Expression.Null;
 }
예제 #13
0
 public CastExpression(TypeReference castTo)
 {
     CastTo = castTo;
     expression = Expression.Null;
 }
예제 #14
0
 public WithStatement(Expression expression)
 {
     Expression = expression;
     body = BlockStatement.Null;
 }
예제 #15
0
 public VariableDeclaration(string name, Expression initializer, TypeReference typeReference)
 {
     Name = name;
     Initializer = initializer;
     TypeReference = typeReference;
     fixedArrayInitialization = Expression.Null;
 }
예제 #16
0
 public VariableDeclaration(string name)
 {
     Name = name;
     initializer = Expression.Null;
     typeReference = TypeReference.Null;
     fixedArrayInitialization = Expression.Null;
 }
예제 #17
0
 public CollectionRangeVariable()
 {
     identifier = "";
     expression = Expression.Null;
     type = TypeReference.Null;
 }
예제 #18
0
 /// <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);
 }
예제 #19
0
 public XmlElementExpression()
 {
     content = Expression.Null;
     nameExpression = Expression.Null;
     xmlName = "";
     attributes = new List<XmlExpression>();
 }
예제 #20
0
 public UnaryOperatorExpression(UnaryOperatorType op)
 {
     Op = op;
     expression = Expression.Null;
 }
예제 #21
0
 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);
 }
예제 #22
0
 public CastExpression(TypeReference castTo, Expression expression, CastType castType)
 {
     CastTo = castTo;
     Expression = expression;
     CastType = castType;
 }
예제 #23
0
 public XmlEmbeddedExpression()
 {
     inlineVBExpression = Expression.Null;
 }
예제 #24
0
 public XmlMemberAccessExpression(Expression targetObject, XmlAxisType axisType, string identifier, bool isXmlIdentifier)
 {
     TargetObject = targetObject;
     AxisType = axisType;
     Identifier = identifier;
     IsXmlIdentifier = isXmlIdentifier;
 }
예제 #25
0
 public static void AddStatement(this BlockStatement block, Expression expressionStatement)
 {
     if (expressionStatement == null)
         throw new ArgumentNullException("expressionStatement");
     AddStatement(block, new ExpressionStatement(expressionStatement));
 }
예제 #26
0
 public CatchClause(TypeReference typeReference, string variableName, Statement statementBlock)
 {
     TypeReference = typeReference;
     VariableName = variableName;
     StatementBlock = statementBlock;
     condition = Expression.Null;
 }
예제 #27
0
 public static void Throw(this BlockStatement block, Expression expression)
 {
     if (expression == null)
         throw new ArgumentNullException("expression");
     AddStatement(block, new ThrowStatement(expression));
 }
예제 #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;
 }
예제 #30
0
 public CaseLabel(Expression label, Expression toExpression)
 {
     Label = label;
     ToExpression = toExpression;
 }