Inheritance: ICSharpCode.NRefactory.Ast.Expression
 public override object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     if (conditionalExpression.TrueExpression is PrimitiveExpression && ((PrimitiveExpression) conditionalExpression.TrueExpression).Value == null)
     {
         TypeReference typeReference = GetExpressionType(conditionalExpression.FalseExpression);
         if (typeReference != null && (typeReference.RankSpecifier == null || typeReference.RankSpecifier.Length == 0))
         {
             string fullName = GetFullName(typeReference);
             if (types.Contains(fullName))
             {
                 Expression minValue = (Expression) values[fullName];
                 conditionalExpression.TrueExpression = minValue;
             }
         }
     }
     else if (conditionalExpression.FalseExpression is PrimitiveExpression && ((PrimitiveExpression) conditionalExpression.FalseExpression).Value == null)
     {
         TypeReference typeReference = GetExpressionType(conditionalExpression.TrueExpression);
         if (typeReference != null && (typeReference.RankSpecifier == null || typeReference.RankSpecifier.Length == 0))
         {
             string fullName = GetFullName(typeReference);
             if (types.Contains(fullName))
             {
                 Expression minValue = (Expression) values[fullName];
                 conditionalExpression.TrueExpression = minValue;
             }
         }
     }
     return base.TrackedVisitConditionalExpression(conditionalExpression, data);
 }
		/// <summary>
		/// We have to replace code such as:
		///		doc.FirstName ?? ""
		/// Into 
		///		doc.FirstName != null ? doc.FirstName : ""
		/// Because we use DynamicNullObject instead of null, and that preserve the null coallasing semantics.
		/// </summary>
		public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
		{
			if(binaryOperatorExpression.Op==BinaryOperatorType.NullCoalescing)
			{
				var node = new ConditionalExpression(
					new BinaryOperatorExpression(binaryOperatorExpression.Left, BinaryOperatorType.ReferenceInequality,
					                             new PrimitiveExpression(null, null)),
					binaryOperatorExpression.Left,
					binaryOperatorExpression.Right
					);
				ReplaceCurrentNode(node);
				return null;
			}

			return base.VisitBinaryOperatorExpression(binaryOperatorExpression, data);
		}
Ejemplo n.º 3
0
		public override object VisitConditionalExpression (ConditionalExpression conditionalExpression, object data) 
		{
			return CreateResult (GetCommonType (GetTypeSafe (conditionalExpression.TrueExpression), 
			                                    GetTypeSafe (conditionalExpression.FalseExpression)).FullName);
		}
 public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
 {
     IdentifierExpression ident = invocationExpression.TargetObject as IdentifierExpression;
     if (ident != null) {
         if ("IIF".Equals(ident.Identifier, StringComparison.InvariantCultureIgnoreCase)
             && invocationExpression.Arguments.Count == 3)
         {
             ConditionalExpression ce = new ConditionalExpression(invocationExpression.Arguments[0],
                                                                  invocationExpression.Arguments[1],
                                                                  invocationExpression.Arguments[2]);
             ReplaceCurrentNode(new ParenthesizedExpression(ce));
             return base.VisitConditionalExpression(ce, data);
         }
         if ("IsNothing".Equals(ident.Identifier, StringComparison.InvariantCultureIgnoreCase)
             && invocationExpression.Arguments.Count == 1)
         {
             BinaryOperatorExpression boe = new BinaryOperatorExpression(invocationExpression.Arguments[0],
                                                                         BinaryOperatorType.ReferenceEquality,
                                                                         new PrimitiveExpression(null, "null"));
             ReplaceCurrentNode(new ParenthesizedExpression(boe));
             return base.VisitBinaryOperatorExpression(boe, data);
         }
         if (methodTable == null) {
             methodTable = CreateDictionary("Conversion", "FileSystem", "Financial", "Information",
                                            "Interaction", "Strings", "VBMath");
         }
         Expression expr;
         if (methodTable.TryGetValue(ident.Identifier, out expr)) {
             MemberReferenceExpression fre = new MemberReferenceExpression(expr, ident.Identifier);
             invocationExpression.TargetObject = fre;
         }
     }
     return base.VisitInvocationExpression(invocationExpression, data);
 }
 public override object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     conditionalExpression.TrueExpression.AcceptVisitor(this, data);
     this.Append(" if ");
     conditionalExpression.Condition.AcceptVisitor(this, data);
     this.Append(" else ");
     conditionalExpression.FalseExpression.AcceptVisitor(this, data);
     return null;
 }
			public override object VisitConditionalExpression (ConditionalExpression expression, object data)
			{
				Console.WriteLine ("ConditionalExpression");
				IntegrateTemporaryVariableVisitorOptions options = (IntegrateTemporaryVariableVisitorOptions)data;
				if (IsExpressionToReplace (expression.Condition, (IntegrateTemporaryVariableVisitorOptions)data))
					if (IsUnary (options.Initializer))
						options.Changes.Add (ReplaceExpression (expression.Condition, options.Initializer, options)); else
						options.Changes.Add (ReplaceExpression (expression.Condition, new ParenthesizedExpression (options.Initializer), options)); else
					expression.Condition.AcceptVisitor (this, data);
				if (IsExpressionToReplace (expression.TrueExpression, (IntegrateTemporaryVariableVisitorOptions)data))
					if (!(options.Initializer is AssignmentExpression || options.Initializer is ConditionalExpression))
						options.Changes.Add (ReplaceExpression (expression.TrueExpression, options.Initializer, options)); else
						options.Changes.Add (ReplaceExpression (expression.TrueExpression, new ParenthesizedExpression (options.Initializer), options)); else
					expression.TrueExpression.AcceptVisitor (this, data);
				if (IsExpressionToReplace (expression.FalseExpression, (IntegrateTemporaryVariableVisitorOptions)data)) {
					if (!(options.Initializer is AssignmentExpression || options.Initializer is ConditionalExpression))
						options.Changes.Add (ReplaceExpression (expression.FalseExpression, options.Initializer, options)); else
						options.Changes.Add (ReplaceExpression (expression.FalseExpression, new ParenthesizedExpression (options.Initializer), options));
					return null;
				} else
					return expression.FalseExpression.AcceptVisitor(this, data);
			}
		public sealed override object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) {
			this.BeginVisit(conditionalExpression);
			object result = this.TrackedVisitConditionalExpression(conditionalExpression, data);
			this.EndVisit(conditionalExpression);
			return result;
		}
 public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     throw new NotImplementedException ();
 }
Ejemplo n.º 9
0
 public virtual object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     Debug.Assert((conditionalExpression != null));
     Debug.Assert((conditionalExpression.Condition != null));
     Debug.Assert((conditionalExpression.TrueExpression != null));
     Debug.Assert((conditionalExpression.FalseExpression != null));
     conditionalExpression.Condition.AcceptVisitor(this, data);
     conditionalExpression.TrueExpression.AcceptVisitor(this, data);
     return conditionalExpression.FalseExpression.AcceptVisitor(this, data);
 }
 public virtual bool VisitConditionalExpression(ConditionalExpression conditionalExpression, object d)
 {
     if ((conditionalExpression == null)) {
         return SetFailure();
     }
     if ((d == null)) {
         return SetFailure();
     }
     if ((conditionalExpression.Condition == null)) {
         return SetFailure();
     }
     if ((conditionalExpression.TrueExpression == null)) {
         return SetFailure();
     }
     if ((conditionalExpression.FalseExpression == null)) {
         return SetFailure();
     }
     if(conditionalExpression.GetType() != d.GetType()) {return SetFailure();}
     var data = (ConditionalExpression)d;
     if (!IsMatch(conditionalExpression, data)) {
         return SetFailure();
     }
     conditionalExpression.Condition.AcceptVisitor(this, data.Condition);
     conditionalExpression.TrueExpression.AcceptVisitor(this, data.TrueExpression);
     return conditionalExpression.FalseExpression.AcceptVisitor(this, data.FalseExpression);
 }
			public void VisitExpression (ConditionalExpression expression, MethodProperties meth)
			{
				VisitExpression(((ConditionalExpression)expression).Condition, meth);
				VisitExpression(((ConditionalExpression)expression).TrueExpression, meth);
			}
		/// <summary>
		/// A ternary operator expression. The right hand side of the following:
		/// 
		/// string a = test ? "Ape" : "Monkey";
		/// 
		/// In Ruby this gets converted to:
		/// 
		/// a = test : "Ape" : "Monkey"
		/// </summary>
		public override object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
		{	
			// Add condition.
			conditionalExpression.Condition.AcceptVisitor(this, data);
			Append(" ? ");
			
			// Add true part.
			conditionalExpression.TrueExpression.AcceptVisitor(this, data);
			
			Append(" : ");

			// Add false part.
			conditionalExpression.FalseExpression.AcceptVisitor(this, data);
			return null;
		}
 private bool IsMatch(ConditionalExpression left, ConditionalExpression right)
 {
     return true;
 }
Ejemplo n.º 14
0
 public override object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     conditionalExpression.Condition.Parent = conditionalExpression;
     conditionalExpression.TrueExpression.Parent = conditionalExpression;
     conditionalExpression.FalseExpression.Parent = conditionalExpression;
     return base.VisitConditionalExpression(conditionalExpression, data);
 }
Ejemplo n.º 15
0
 public override object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     UnlockWith(conditionalExpression);
     return base.VisitConditionalExpression(conditionalExpression, data);
 }
		public virtual object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) {
			Debug.Assert((conditionalExpression != null));
			Debug.Assert((conditionalExpression.Condition != null));
			Debug.Assert((conditionalExpression.TrueExpression != null));
			Debug.Assert((conditionalExpression.FalseExpression != null));
			nodeStack.Push(conditionalExpression.Condition);
			conditionalExpression.Condition.AcceptVisitor(this, data);
			conditionalExpression.Condition = ((Expression)(nodeStack.Pop()));
			nodeStack.Push(conditionalExpression.TrueExpression);
			conditionalExpression.TrueExpression.AcceptVisitor(this, data);
			conditionalExpression.TrueExpression = ((Expression)(nodeStack.Pop()));
			nodeStack.Push(conditionalExpression.FalseExpression);
			conditionalExpression.FalseExpression.AcceptVisitor(this, data);
			conditionalExpression.FalseExpression = ((Expression)(nodeStack.Pop()));
			return null;
		}
Ejemplo n.º 17
0
	void Expr(
#line  1808 "cs.ATG" 
out Expression expr) {

#line  1809 "cs.ATG" 
		expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; 

#line  1811 "cs.ATG" 
		Location startLocation = la.Location; 
		UnaryExpr(
#line  1812 "cs.ATG" 
out expr);
		if (StartOf(7)) {
			AssignmentOperator(
#line  1815 "cs.ATG" 
out op);
			Expr(
#line  1815 "cs.ATG" 
out expr1);

#line  1815 "cs.ATG" 
			expr = new AssignmentExpression(expr, op, expr1); 
		} else if (
#line  1816 "cs.ATG" 
la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) {
			AssignmentOperator(
#line  1817 "cs.ATG" 
out op);
			Expr(
#line  1817 "cs.ATG" 
out expr1);

#line  1817 "cs.ATG" 
			expr = new AssignmentExpression(expr, op, expr1); 
		} else if (StartOf(8)) {
			ConditionalOrExpr(
#line  1819 "cs.ATG" 
ref expr);
			if (la.kind == 13) {
				lexer.NextToken();
				Expr(
#line  1820 "cs.ATG" 
out expr1);

#line  1820 "cs.ATG" 
				expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); 
			}
			if (la.kind == 12) {
				lexer.NextToken();
				Expr(
#line  1821 "cs.ATG" 
out expr1);
				Expect(9);
				Expr(
#line  1821 "cs.ATG" 
out expr2);

#line  1821 "cs.ATG" 
				expr = new ConditionalExpression(expr, expr1, expr2);  
			}
		} else SynErr(152);

#line  1824 "cs.ATG" 
		if (expr != null) {
		if (expr.StartLocation.IsEmpty)
			expr.StartLocation = startLocation;
		if (expr.EndLocation.IsEmpty)
			expr.EndLocation = t.EndLocation;
		}
		
	}
Ejemplo n.º 18
0
 public virtual object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) {
     throw CreateException(conditionalExpression);
 }
Ejemplo n.º 19
0
		public virtual object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data) {
			throw new global::System.NotImplementedException("ConditionalExpression");
		}
Ejemplo n.º 20
0
	void Expr(
#line  1802 "Frames/cs.ATG" 
out Expression expr) {

#line  1803 "Frames/cs.ATG" 
		expr = null; Expression expr1 = null, expr2 = null; AssignmentOperatorType op; 

#line  1805 "Frames/cs.ATG" 
		Location startLocation = la.Location; 
		UnaryExpr(
#line  1806 "Frames/cs.ATG" 
out expr);
		if (StartOf(7)) {
			AssignmentOperator(
#line  1809 "Frames/cs.ATG" 
out op);
			Expr(
#line  1809 "Frames/cs.ATG" 
out expr1);

#line  1809 "Frames/cs.ATG" 
			expr = new AssignmentExpression(expr, op, expr1); 
		} else if (
#line  1810 "Frames/cs.ATG" 
la.kind == Tokens.GreaterThan && Peek(1).kind == Tokens.GreaterEqual) {
			AssignmentOperator(
#line  1811 "Frames/cs.ATG" 
out op);
			Expr(
#line  1811 "Frames/cs.ATG" 
out expr1);

#line  1811 "Frames/cs.ATG" 
			expr = new AssignmentExpression(expr, op, expr1); 
		} else if (StartOf(8)) {
			ConditionalOrExpr(
#line  1813 "Frames/cs.ATG" 
ref expr);
			if (la.kind == 13) {
				lexer.NextToken();
				Expr(
#line  1814 "Frames/cs.ATG" 
out expr1);

#line  1814 "Frames/cs.ATG" 
				expr = new BinaryOperatorExpression(expr, BinaryOperatorType.NullCoalescing, expr1); 
			}
			if (la.kind == 12) {
				lexer.NextToken();
				Expr(
#line  1815 "Frames/cs.ATG" 
out expr1);
				Expect(9);
				Expr(
#line  1815 "Frames/cs.ATG" 
out expr2);

#line  1815 "Frames/cs.ATG" 
				expr = new ConditionalExpression(expr, expr1, expr2);  
			}
		} else SynErr(150);

#line  1818 "Frames/cs.ATG" 
		if (expr != null) {
		expr.StartLocation = startLocation;
		expr.EndLocation = t.EndLocation;
		}
		
	}
		public virtual object TrackedVisitConditionalExpression(ConditionalExpression conditionalExpression, object data) {
			return base.VisitConditionalExpression(conditionalExpression, data);
		}
Ejemplo n.º 22
0
		public override object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
		{
			return CreateResolveResult(MemberLookupHelper.GetCommonType(
				resolver.ProjectContent,
				ResolveType(conditionalExpression.TrueExpression),
				ResolveType(conditionalExpression.FalseExpression)));
		}
Ejemplo n.º 23
0
	void ConditionalExpression(
//#line  1890 "VBNET.ATG" 
out Expression expr) {

//#line  1892 "VBNET.ATG" 
		ConditionalExpression conditionalExpression = new ConditionalExpression();
		BinaryOperatorExpression binaryOperatorExpression = new BinaryOperatorExpression();
		conditionalExpression.StartLocation = binaryOperatorExpression.StartLocation = la.Location;
		
		Expression condition = null;
		Expression trueExpr = null;
		Expression falseExpr = null;
		
		Expect(135);
		Expect(37);
		Expr(
//#line  1901 "VBNET.ATG" 
out condition);
		Expect(22);
		Expr(
//#line  1901 "VBNET.ATG" 
out trueExpr);
		if (la.kind == 22) {
			lexer.NextToken();
			Expr(
//#line  1901 "VBNET.ATG" 
out falseExpr);
		}
		Expect(38);

//#line  1903 "VBNET.ATG" 
		if(falseExpr != null)
		{
			conditionalExpression.Condition = condition;
			conditionalExpression.TrueExpression = trueExpr;
			conditionalExpression.FalseExpression = falseExpr;
			conditionalExpression.EndLocation = t.EndLocation;
			
			expr = conditionalExpression;
		}
		else
		{
			binaryOperatorExpression.Left = condition;
			binaryOperatorExpression.Right = trueExpr;
			binaryOperatorExpression.Op = BinaryOperatorType.NullCoalescing;
			binaryOperatorExpression.EndLocation = t.EndLocation;
			
			expr = binaryOperatorExpression;
		}
		
	}
Ejemplo n.º 24
0
 public override object VisitConditionalExpression (ConditionalExpression node, object data)
 {
     node.Condition.AcceptVisitor (this, null);
     Write (" ? ");
     node.TrueExpression.AcceptVisitor (this, null);
     Write (" : ");
     var type = node.FalseExpression.AcceptVisitor (this, null);
     
     //Console.WriteLine ("Condi Type: {0}", type);
     
     return type;
 }