public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
			throw new global::System.NotImplementedException("UnaryOperatorExpression");
		}
		public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
			Debug.Assert((unaryOperatorExpression != null));
			Debug.Assert((unaryOperatorExpression.Expression != null));
			return unaryOperatorExpression.Expression.AcceptVisitor(this, data);
		}
Exemple #3
0
	void UnaryExpr(out Expression uExpr) {
		Expression expr;
		UnaryOperatorType uop = UnaryOperatorType.None;
		Location startLocation = la.Location;
		bool isUOp = false;

		while (la.kind == 30 || la.kind == 31 || la.kind == 34) {
			if (la.kind == 31) {
				Get();
				uop = UnaryOperatorType.Plus; isUOp = true;
			} else if (la.kind == 30) {
				Get();
				uop = UnaryOperatorType.Minus; isUOp = true;
			} else {
				Get();
				uop = UnaryOperatorType.Dereference;  isUOp = true;
			}
		}
		ExponentiationExpr(out expr);
		if (isUOp) {
				uExpr = new UnaryOperatorExpression(expr, uop) { StartLocation = startLocation, EndLocation = t.EndLocation };
			} else {
				uExpr = expr;
			}

	}
		public virtual object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
			Debug.Assert((unaryOperatorExpression != null));
			Debug.Assert((unaryOperatorExpression.Expression != null));
			nodeStack.Push(unaryOperatorExpression.Expression);
			unaryOperatorExpression.Expression.AcceptVisitor(this, data);
			unaryOperatorExpression.Expression = ((Expression)(nodeStack.Pop()));
			return null;
		}
Exemple #5
0
	void NotExpr(out Expression outExpr) {
		UnaryOperatorType uop = UnaryOperatorType.None;
		while (la.kind == 164) {
			Get();
			uop = UnaryOperatorType.Not;
		}
		ComparisonExpr(out outExpr);
		if (uop != UnaryOperatorType.None)
		    outExpr = new UnaryOperatorExpression(outExpr, uop);

	}
		public sealed override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
			this.BeginVisit(unaryOperatorExpression);
			object result = this.TrackedVisitUnaryOperatorExpression(unaryOperatorExpression, data);
			this.EndVisit(unaryOperatorExpression);
			return result;
		}
		public virtual object TrackedVisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data) {
			return base.VisitUnaryOperatorExpression(unaryOperatorExpression, data);
		}
		public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
		{
			CodeExpression var;
			CodeAssignStatement assign;

			switch (unaryOperatorExpression.Op) {
				case UnaryOperatorType.Minus:
					if (unaryOperatorExpression.Expression is PrimitiveExpression) {
						PrimitiveExpression expression = (PrimitiveExpression)unaryOperatorExpression.Expression;
						if (expression.Value is int) {
							return new CodePrimitiveExpression(- (int)expression.Value);
						}
						if (expression.Value is System.UInt32 || expression.Value is System.UInt16) {
							return new CodePrimitiveExpression(Int32.Parse("-" + expression.StringValue));
						}
						
						if (expression.Value is long) {
							return new CodePrimitiveExpression(- (long)expression.Value);
						}
						if (expression.Value is double) {
							return new CodePrimitiveExpression(- (double)expression.Value);
						}
						if (expression.Value is float) {
							return new CodePrimitiveExpression(- (float)expression.Value);
						}
						
					}
					return  new CodeBinaryOperatorExpression(new CodePrimitiveExpression(0),
					                                         CodeBinaryOperatorType.Subtract,
					                                         (CodeExpression)unaryOperatorExpression.Expression.AcceptVisitor(this, data));
				case UnaryOperatorType.Plus:
					return unaryOperatorExpression.Expression.AcceptVisitor(this, data);
					
				case UnaryOperatorType.PostIncrement:
					// emulate i++, with i = i + 1
					var = (CodeExpression)unaryOperatorExpression.Expression.AcceptVisitor(this, data);

					assign = new CodeAssignStatement(var,
					                                 new CodeBinaryOperatorExpression(var,
					                                                                  CodeBinaryOperatorType.Add,
					                                                                  new CodePrimitiveExpression(1)));

					AddStmt(assign);

					return assign;

					//return new CodeAssignStatement(var,
					//               new CodeBinaryOperatorExpression(var,
					//                                                CodeBinaryOperatorType.Add,
					//                                                new CodePrimitiveExpression(1)));

					// RG: needs to return an Expression - Not a Statement
					//return new CodeBinaryOperatorExpression(var,
					//                               CodeBinaryOperatorType.Assign,
					//                               new CodeBinaryOperatorExpression(var,
					//                                                                CodeBinaryOperatorType.Add,
					//                                                                new CodePrimitiveExpression(1)));
					
				case UnaryOperatorType.PostDecrement:
					// emulate i--, with i = i - 1
					var = (CodeExpression)unaryOperatorExpression.Expression.AcceptVisitor(this, data);

					assign = new CodeAssignStatement(var,
					                                 new CodeBinaryOperatorExpression(var,
					                                                                  CodeBinaryOperatorType.Subtract,
					                                                                  new CodePrimitiveExpression(1)));

					AddStmt(assign);

					return assign;
					
					//return new CodeAssignStatement(var,
					//                               new CodeBinaryOperatorExpression(var,
					//                                                                CodeBinaryOperatorType.Subtract,
					//                                                                new CodePrimitiveExpression(1)));

					// RG: needs to return an Expression - Not a Statement
					//return new CodeBinaryOperatorExpression(var,
					//               CodeBinaryOperatorType.Assign,
					//               new CodeBinaryOperatorExpression(var,
					//                                                CodeBinaryOperatorType.Subtract,
					//                                                new CodePrimitiveExpression(1)));
					
				case UnaryOperatorType.Decrement:
					// emulate --i, with i = i - 1
					var = (CodeExpression)unaryOperatorExpression.Expression.AcceptVisitor(this, data);

					assign = new CodeAssignStatement(var,
					                                 new CodeBinaryOperatorExpression(var,
					                                                                  CodeBinaryOperatorType.Subtract,
					                                                                  new CodePrimitiveExpression(1)));
					AddStmt(assign);

					return assign;
					//return new CodeAssignStatement(var,
					//                               new CodeBinaryOperatorExpression(var,
					//                                                                CodeBinaryOperatorType.Subtract,
					//                                                                new CodePrimitiveExpression(1)));

					//return new CodeBinaryOperatorExpression(var,
					//                CodeBinaryOperatorType.Assign,
					//               new CodeBinaryOperatorExpression(var,
					//                                                CodeBinaryOperatorType.Subtract,
					//                                                new CodePrimitiveExpression(1)));
					
				case UnaryOperatorType.Increment:
					// emulate ++i, with i = i + 1
					var = (CodeExpression)unaryOperatorExpression.Expression.AcceptVisitor(this, data);

					assign = new CodeAssignStatement(var,
					                                 new CodeBinaryOperatorExpression(var,
					                                                                  CodeBinaryOperatorType.Add,
					                                                                  new CodePrimitiveExpression(1)));

					AddStmt(assign);

					return assign;

					//return new CodeAssignStatement(var,
					//                               new CodeBinaryOperatorExpression(var,
					//                                                                CodeBinaryOperatorType.Add,
					//                                                                new CodePrimitiveExpression(1)));

					//return new CodeBinaryOperatorExpression(var,
					//                CodeBinaryOperatorType.Assign,
					//                new CodeBinaryOperatorExpression(var,
					//                                                CodeBinaryOperatorType.Add,
					//                                                new CodePrimitiveExpression(1)));

					// RG:
				case UnaryOperatorType.Not:
					// emulate !a with a == false
					var = (CodeExpression)unaryOperatorExpression.Expression.AcceptVisitor(this, data);
					
					CodeBinaryOperatorExpression cboe = var as CodeBinaryOperatorExpression;
					if (cboe != null && cboe.Operator == CodeBinaryOperatorType.IdentityEquality) {
						return new CodeBinaryOperatorExpression(cboe.Left, CodeBinaryOperatorType.IdentityInequality, cboe.Right);
					} else {
						return new CodeBinaryOperatorExpression(var,CodeBinaryOperatorType.ValueEquality, new CodePrimitiveExpression(false));
					}

				default:
					throw new NotSupportedException("CodeDom does not support Unary Operators");
			}
		}
        protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
        {
            UnaryOperatorExpression o = other as UnaryOperatorExpression;

            return(o != null && this.Operator == o.Operator && this.Expression.DoMatch(o.Expression, match));
        }