Example #1
0
 public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     B.ConditionalExpression te = new B.ConditionalExpression(GetLexicalInfo(conditionalExpression));
     te.Condition  = ConvertExpression(conditionalExpression.Condition);
     te.TrueValue  = ConvertExpression(conditionalExpression.TrueExpression);
     te.FalseValue = ConvertExpression(conditionalExpression.FalseExpression);
     return(te);
 }
Example #2
0
        void BindNullableInitializer(Node node, Expression rhs, IType type)
        {
            var instantiation = CreateNullableInstantiation(rhs, type);
            node.Replace(rhs, instantiation);
            Visit(instantiation);

            var coalescing = BuildNullableCoalescingConditional(rhs);
            if (null != coalescing) //rhs contains at least one nullable
            {
                var cond = new ConditionalExpression
                           	{
                           		Condition = coalescing,
                           		TrueValue = instantiation,
                           		FalseValue = CreateNullableInstantiation(type)
                           	};
                node.Replace(instantiation, cond);
                Visit(cond);
            }
        }
Example #3
0
 public override void LeaveConditionalExpression(ConditionalExpression node)
 {
     IType trueType = GetExpressionType(node.TrueValue);
     IType falseType = GetExpressionType(node.FalseValue);
     BindExpressionType(node, GetMostGenericType(trueType, falseType));
 }
Example #4
0
	protected Expression  paren_expression() //throws RecognitionException, TokenStreamException
{
		Expression e;
		
		IToken  lparen = null;
		
			e = null;
			Expression condition = null;
			Expression falseValue = null;
		
		
		try {      // for error handling
			bool synPredMatched565 = false;
			if (((LA(1)==LPAREN) && (LA(2)==OF)))
			{
				int _m565 = mark();
				synPredMatched565 = true;
				inputState.guessing++;
				try {
					{
						match(LPAREN);
						match(OF);
					}
				}
				catch (RecognitionException)
				{
					synPredMatched565 = false;
				}
				rewind(_m565);
				inputState.guessing--;
			}
			if ( synPredMatched565 )
			{
				e=typed_array();
			}
			else if ((LA(1)==LPAREN) && (tokenSet_70_.member(LA(2)))) {
				{
					lparen = LT(1);
					match(LPAREN);
					e=array_or_expression();
					{
						switch ( LA(1) )
						{
						case IF:
						{
							match(IF);
							condition=boolean_expression();
							match(ELSE);
							falseValue=array_or_expression();
							if (0==inputState.guessing)
							{
								
												ConditionalExpression ce = new ConditionalExpression(ToLexicalInfo(lparen));
												ce.Condition = condition;
												ce.TrueValue = e;
												ce.FalseValue = falseValue;
												
												e = ce;
											
							}
							break;
						}
						case RPAREN:
						{
							break;
						}
						default:
						{
							throw new NoViableAltException(LT(1), getFilename());
						}
						 }
					}
					match(RPAREN);
				}
			}
			else
			{
				throw new NoViableAltException(LT(1), getFilename());
			}
			
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "paren_expression");
				recover(ex,tokenSet_44_);
			}
			else
			{
				throw ex;
			}
		}
		return e;
	}
Example #5
0
        public override void OnConditionalExpression(ConditionalExpression node)
        {
            IType type = GetExpressionType(node);

            Label endLabel = _il.DefineLabel();

            EmitBranchFalse(node.Condition, endLabel);
            node.TrueValue.Accept(this);
            EmitCastIfNeeded(type, PopType());

            Label elseEndLabel = _il.DefineLabel();
            _il.Emit(OpCodes.Br, elseEndLabel);
            _il.MarkLabel(endLabel);

            endLabel = elseEndLabel;
            node.FalseValue.Accept(this);
            EmitCastIfNeeded(type, PopType());

            _il.MarkLabel(endLabel);

            PushType(type);
        }
Example #6
0
		protected Expression ProcessTargets(Expression node)
		{
			// Look for safe access operators in the targets chain
			UnaryExpression ue = null;
			Expression target = node;
			Expression nextTarget = null;
			while (IsTargetable(target))
			{
				if (target is MemberReferenceExpression)
				{
					nextTarget = ((MemberReferenceExpression)target).Target;
				} 
				else if (target is SlicingExpression)
				{
					nextTarget = ((SlicingExpression)target).Target;
				}
				else
				{
					nextTarget = ((MethodInvocationExpression)target).Target;
				}

				if (IsSafeAccess(nextTarget))
				{
					ue = (UnaryExpression)nextTarget;
					break;
				}

				target = nextTarget;
			}

			// No safe access operator was found
			if (ue == null)
			{
				return null;
			}

			// Target the safe access to a temporary variable
			var tmp = new ReferenceExpression(node.LexicalInfo, Context.GetUniqueName("safe"));
			tmp.IsSynthetic = true;

			// Make sure preceding operators are processed
			MemberReferenceExpression mre = null;
			SlicingExpression se = null;
			MethodInvocationExpression mie = null;
			if (null != (mre = target as MemberReferenceExpression))
			{
				Visit(mre.Target);
				mre.Target = tmp.CloneNode();
			} 
			else if (null != (se = target as SlicingExpression))
			{
				Visit(se.Target);
				se.Target = tmp.CloneNode();
			}
			else if (null != (mie = target as MethodInvocationExpression))
			{
				Visit(mie.Target);
				mie.Target = tmp.CloneNode();
			}

			// Convert the target into a ternary operation 
			var tern = new ConditionalExpression(node.LexicalInfo);
			tern.Condition = new BinaryExpression(
				BinaryOperatorType.ReferenceInequality,
				CodeBuilder.CreateAssignment(tmp, ue.Operand),
				CodeBuilder.CreateNullLiteral()
				);
			tern.TrueValue = node;
			tern.FalseValue = CodeBuilder.CreateNullLiteral();

			return tern;
		}
 public override void LeaveConditionalExpression(ConditionalExpression node)
 {
     node.Condition = ExplicitBooleanContext(node.Condition);
 }
 public override void LeaveConditionalExpression(ConditionalExpression node)
 {
     var trueType = GetExpressionType(node.TrueValue);
     var falseType = GetExpressionType(node.FalseValue);
     if (TypeSystemServices.IsNullable(trueType) && !TypeSystemServices.IsNullable(falseType))
     {
         node.FalseValue = CreateNullableInstantiation(node.FalseValue, trueType);
         Visit(node.FalseValue);
     }
     if (!TypeSystemServices.IsNullable(trueType) && TypeSystemServices.IsNullable(falseType))
     {
         node.TrueValue = CreateNullableInstantiation(node.TrueValue, falseType);
         Visit(node.TrueValue);
     }
     BindExpressionType(node, GetMostGenericType(trueType, falseType));
 }
Example #9
0
		override public void OnConditionalExpression(ConditionalExpression node)
		{
			var type = GetExpressionType(node);

			var endLabel = _il.DefineLabel();

			EmitBranchFalse(node.Condition, endLabel);
			LoadExpressionWithType(type, node.TrueValue);

			var elseEndLabel = _il.DefineLabel();
			_il.Emit(OpCodes.Br, elseEndLabel);
			_il.MarkLabel(endLabel);

			endLabel = elseEndLabel;
			LoadExpressionWithType(type, node.FalseValue);

			_il.MarkLabel(endLabel);

			PushType(type);
		}
Example #10
0
		public override void LeaveConditionalExpression(ConditionalExpression node)
		{
			var newTrueValue = Convert(node.ExpressionType, node.TrueValue);
			if (newTrueValue != null)
				node.TrueValue = newTrueValue;
			var newFalseValue = Convert(node.ExpressionType, node.FalseValue);
			if (newFalseValue != null)
				node.FalseValue = newFalseValue;
		}
Example #11
0
		override public object Clone()
		{
		
			ConditionalExpression clone = new ConditionalExpression();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			clone._expressionType = _expressionType;
			if (null != _condition)
			{
				clone._condition = _condition.Clone() as Expression;
				clone._condition.InitializeParent(clone);
			}
			if (null != _trueValue)
			{
				clone._trueValue = _trueValue.Clone() as Expression;
				clone._trueValue.InitializeParent(clone);
			}
			if (null != _falseValue)
			{
				clone._falseValue = _falseValue.Clone() as Expression;
				clone._falseValue.InitializeParent(clone);
			}
			return clone;


		}
		override public void LeaveConditionalExpression(ConditionalExpression node)
		{
			node.Condition = AssertBoolContext(node.Condition);
		}
Example #13
0
 public override void LeaveConditionalExpression(ConditionalExpression node)
 {
     CheckExpressionType(node.TrueValue);
     CheckExpressionType(node.FalseValue);
 }
Example #14
0
 public override void OnConditionalExpression(ConditionalExpression e)
 {
     Write("(");
     Visit(e.TrueValue);
     WriteKeyword(" if ");
     Visit(e.Condition);
     WriteKeyword(" else ");
     Visit(e.FalseValue);
     Write(")");
 }
 public Expression conditional_expression()
 {
     Expression expression = null;
     IToken token = null;
     try
     {
         expression = this.logical_or();
         if ((this.LA(1) == 0x57) && tokenSet_16_.member(this.LA(2)))
         {
             token = this.LT(1);
             this.match(0x57);
             Expression expression2 = this.logical_or();
             this.match(0x42);
             Expression expression3 = this.conditional_expression();
             if (base.inputState.guessing == 0)
             {
                 ConditionalExpression expression4;
                 ConditionalExpression expression1 = expression4 = new ConditionalExpression(ToLexicalInfo(token));
                 expression4.set_Condition(expression);
                 expression4.set_TrueValue(expression2);
                 expression4.set_FalseValue(expression3);
                 expression = expression4;
             }
             return expression;
         }
         if (!tokenSet_20_.member(this.LA(1)) || !tokenSet_28_.member(this.LA(2)))
         {
             throw new NoViableAltException(this.LT(1), this.getFilename());
         }
         return expression;
     }
     catch (RecognitionException exception)
     {
         if (base.inputState.guessing != 0)
         {
             throw;
         }
         this.reportError(exception);
         this.recover(exception, tokenSet_20_);
         return expression;
     }
     return expression;
 }
		public object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
		{
			B.ConditionalExpression te = new B.ConditionalExpression(GetLexicalInfo(conditionalExpression));
			te.Condition = ConvertExpression(conditionalExpression.Condition);
			te.TrueValue = ConvertExpression(conditionalExpression.TrueExpression);
			te.FalseValue = ConvertExpression(conditionalExpression.FalseExpression);
			return te;
		}