public override void OnExpressionStatement(ExpressionStatement node)
 {
     var e = node as ExpressionStatement;
     if(null!=e && e.Expression is BinaryExpression){
         Visit(e.Expression as BinaryExpression);
     }
 }
		override public void LeaveExpressionStatement(ExpressionStatement node)
		{
			// allow interactive evaluation of closures (see booish)
			var converted = ConvertExpression(node.Expression);
			if (converted != null)
				node.Expression = converted;
		}
Beispiel #3
0
        public override void LeaveExpressionStatement(ExpressionStatement node)
        {
            IntegerLiteralExpression literal = node.Expression as IntegerLiteralExpression;
            if (null == literal)
                return;

            AssertLiteralInRange(literal, GetExpressionType(literal));
        }
Beispiel #4
0
		public static TypeMember Lift(ExpressionStatement stmt)
		{
			var e = stmt.Expression;
			var closure = e as BlockExpression;
			if (closure != null)
				return TypeMember.Lift(closure);

			throw new NotImplementedException(stmt.ToCodeString());
		}
 public override void OnExpressionStatement(ExpressionStatement es)
 {
     if (es.Expression is MethodInvocationExpression)
         es.Expression = ReplaceExpression(es.Expression);
     else if (es.Expression is BinaryExpression)
     {
         BinaryExpression expression = (BinaryExpression)es.Expression;
         expression.Right = ReplaceExpression(expression.Right);
     }
 }
 public override void OnExpressionStatement(ExpressionStatement node)
 {
     base.OnExpressionStatement(node);
     base.EnsureDocumentInitialized(node);
     Expression expression = node.get_Expression();
     SourceLocation self = base.doc.TokenSourceLocationFollowing(BooExtensions.AsLexicalInfo(expression.get_EndSourceLocation(), null), ";");
     if (self != null)
     {
         node.set_EndSourceLocation(BooExtensions.OffsetedBy(self, 0, -2));
     }
 }
		static void ReplaceWithInitializer(DeclarationStatement decl)
		{
			if (decl.Initializer == null) {
				decl.ReplaceBy(null);
			} else {
				ExpressionStatement statement = new ExpressionStatement(decl.LexicalInfo);
				statement.Expression = new BinaryExpression(decl.LexicalInfo, BinaryOperatorType.Assign,
				                                            new ReferenceExpression(decl.Declaration.LexicalInfo, decl.Declaration.Name),
				                                            decl.Initializer);
				decl.ReplaceBy(statement);
			}
		}
        public void Expression_statement_is_transformed()
        {
            LiteralExpression exp = new StringLiteralExpression("arg1");
            ExpressionStatement doStuffStatement = new ExpressionStatement(exp);

            MacroStatement fixture = new MacroStatement(new LexicalInfo("test", 1, 1));
            fixture.Name = "DoStuff";
            fixture.Block = new Block();
            fixture.Block.Add(doStuffStatement);

            BlockToArgumentsTransformer transformer = new BlockToArgumentsTransformer("DoStuff");
            transformer.Visit(fixture);

            Assert.AreEqual(exp, fixture.Arguments[0]);
            Assert.IsFalse(fixture.Block.HasStatements, "MacroStatement block should be empty after transformation.");
        }
 public override void OnExpressionStatement(ExpressionStatement node)
 {
     if (node.Expression is LiteralExpression)
     {
         CurrentText.AppendLine( node.Expression.expand());
     }
     else if(node.Expression is UnaryExpression){
         var u = node.Expression as UnaryExpression;
         if(u.Operator==UnaryOperatorType.UnaryNegation){
             CurrentText.Append("-");
             CurrentText.Append(u.Operand.ToCodeString());
         }
     }else if(node.Expression is ExpressionInterpolationExpression){
         CurrentText.Append(node.Expression.expand());
     }
     else{
         base.OnExpressionStatement(node);
     }
 }
        public void MacroStatement_with_block_is_transformed_to_MethodInvocationExpression()
        {
            const string methodInBlockName = "some_method";
            const string doStuff = "DoStuff";

            Expression argInBlockExpression = new StringLiteralExpression("argInBlock");
            Statement argInBlockStatement = new ExpressionStatement(argInBlockExpression);

            MacroStatement statementInBlock = GetMacroStatement(methodInBlockName, argInBlockStatement);

            MacroStatement doStuffStatement = GetMacroStatement(doStuff, statementInBlock);

            BlockToArgumentsTransformer transformer = new BlockToArgumentsTransformer(doStuff, methodInBlockName);
            transformer.Visit(doStuffStatement);

            MethodInvocationExpression mie = doStuffStatement.Arguments[0] as MethodInvocationExpression;

            Assert.IsNotNull(mie, "Could not cast argument one of MacroStatement to MethodInvocationExpression.");
            Assert.AreEqual(methodInBlockName, (mie.Target as ReferenceExpression).Name);
            Assert.IsAssignableFrom(typeof (BlockExpression), mie.Arguments[0]);
        }
            public override void OnExpressionStatement(ExpressionStatement node) {

                if(isWrite(node.Expression)) {
                    var arg = get_arg(node.Expression);
                    var first = arg;
                    if (!(arg is ExpressionInterpolationExpression))
                    {
                        
                        arg = new ExpressionInterpolationExpression();
                    }
                    var block = ((Block) node.ParentNode);
                    var index = block.Statements.IndexOf(node);
                    if(index==-1) return;
                    while (true) {
                        if (index > block.Statements.Count - 2) break;
                        var next = block.Statements[index + 1];
                        if(!(next is ExpressionStatement))break;
                        if(!isWrite(((ExpressionStatement)next).Expression)) break;
                        block.Statements.Remove(next);
                        var nextarg = get_arg(((ExpressionStatement) next).Expression);
                        if (nextarg is ExpressionInterpolationExpression)
                        {
                            foreach (var e in ((ExpressionInterpolationExpression)nextarg).Expressions) {
                                ((ExpressionInterpolationExpression)arg).Expressions.Add(e);  
                            }
                        }
                        else {
                            ((ExpressionInterpolationExpression) arg).Expressions.Add(nextarg);
                        }
                    }
                    if(((ExpressionInterpolationExpression)arg).Expressions.Count>0) {
                        if (first != arg) {
                            ((ExpressionInterpolationExpression) arg).Expressions.Insert(0, first);
                        }
                        set_arg(node.Expression, arg);
                    }
                }
            }
Beispiel #12
0
 public override void LeaveExpressionStatement(ExpressionStatement node)
 {
     // if the type of the inner expression is not
     // void we need to pop its return value to leave
     // the stack sane
     DiscardValueOnStack();
 }
Beispiel #13
0
        //throws RecognitionException, TokenStreamException
        protected ExpressionStatement expression_stmt()
        {
            ExpressionStatement s;

                s = null;
                Expression e = null;

            try {      // for error handling
            e=assignment_expression();
            if (0==inputState.guessing)
            {

                        s = new ExpressionStatement(e);

            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex, "expression_stmt");
                recover(ex,tokenSet_21_);
            }
            else
            {
                throw ex;
            }
            }
            return s;
        }
Beispiel #14
0
 public override bool EnterExpressionStatement(ExpressionStatement node)
 {
     EmitDebugInfo(node);
     return true;
 }
 public override void LeaveExpressionStatement(ExpressionStatement node)
 {
     // allow interactive evaluation of closures (see booish)
     Expression converted = ConvertExpression(node.Expression);
     if (null != converted)
     {
         node.Expression = converted;
     }
 }
Beispiel #16
0
        //throws RecognitionException, TokenStreamException
        protected Statement assignment_or_method_invocation_with_block_stmt()
        {
            Statement stmt;

            IToken  op = null;

                stmt = null;
                Expression lhs = null;
                Expression rhs = null;
                StatementModifier modifier = null;
                BinaryOperatorType binaryOperator = BinaryOperatorType.None;
                IToken token = null;

            try {      // for error handling
            lhs=slicing_expression();
            {
                switch ( LA(1) )
                {
                case DEF:
                case DO:
                case COLON:
                {
                    {
                        lhs=method_invocation_block(lhs);
                        if (0==inputState.guessing)
                        {
                            stmt = new ExpressionStatement(lhs);
                        }
                    }
                    break;
                }
                case ASSIGN:
                {
                    {
                        {
                            op = LT(1);
                            match(ASSIGN);
                            if (0==inputState.guessing)
                            {
                                token = op; binaryOperator = OperatorParser.ParseAssignment(op.getText());
                            }
                            {
                                switch ( LA(1) )
                                {
                                case DEF:
                                case DO:
                                case COLON:
                                {
                                    rhs=callable_expression();
                                    break;
                                }
                                case ESEPARATOR:
                                case CAST:
                                case CHAR:
                                case FALSE:
                                case NOT:
                                case NULL:
                                case SELF:
                                case SUPER:
                                case TRUE:
                                case TYPEOF:
                                case ID:
                                case TRIPLE_QUOTED_STRING:
                                case LPAREN:
                                case DOUBLE_QUOTED_STRING:
                                case SINGLE_QUOTED_STRING:
                                case LBRACK:
                                case SUBTRACT:
                                case COMMA:
                                case SPLICE_BEGIN:
                                case DOT:
                                case MULTIPLY:
                                case LBRACE:
                                case QQ_BEGIN:
                                case LONG:
                                case INCREMENT:
                                case DECREMENT:
                                case ONES_COMPLEMENT:
                                case INT:
                                case RE_LITERAL:
                                case DOUBLE:
                                case FLOAT:
                                case TIMESPAN:
                                {
                                    {
                                        rhs=array_or_expression();
                                        {
                                            switch ( LA(1) )
                                            {
                                            case DEF:
                                            case DO:
                                            case COLON:
                                            {
                                                rhs=method_invocation_block(rhs);
                                                break;
                                            }
                                            case IF:
                                            case UNLESS:
                                            case WHILE:
                                            {
                                                {
                                                    modifier=stmt_modifier();
                                                    eos();
                                                }
                                                break;
                                            }
                                            case EOF:
                                            case EOS:
                                            case NEWLINE:
                                            {
                                                eos();
                                                break;
                                            }
                                            default:
                                            {
                                                throw new NoViableAltException(LT(1), getFilename());
                                            }
                                             }
                                        }
                                    }
                                    break;
                                }
                                default:
                                {
                                    throw new NoViableAltException(LT(1), getFilename());
                                }
                                 }
                            }
                        }
                        if (0==inputState.guessing)
                        {

                                            stmt = new ExpressionStatement(
                                                    new BinaryExpression(SourceLocationFactory.ToLexicalInfo(token),
                                                        binaryOperator,
                                                        lhs, rhs));
                                            stmt.Modifier = modifier;

                        }
                    }
                    break;
                }
                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                 }
            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_79_);
            }
            else
            {
                throw ex;
            }
            }
            return stmt;
        }
Beispiel #17
0
	protected Statement  closure_expression_stmt() //throws RecognitionException, TokenStreamException
{
		Statement s;
		
		
			s = null;
			Expression e = null;
		
		
		try {      // for error handling
			e=array_or_expression();
			if (0==inputState.guessing)
			{
				s = new ExpressionStatement(e);
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "closure_expression_stmt");
				recover(ex,tokenSet_90_);
			}
			else
			{
				throw ex;
			}
		}
		return s;
	}
Beispiel #18
0
 public override void LeaveExpressionStatement(ExpressionStatement node)
 {
     // if the type of the inner expression is not
     // void we need to pop its return value to leave
     // the stack sane
     DiscardValueOnStack();
     AssertStackIsEmpty("stack must be empty after a statement! Offending statement: '" + node.ToCodeString() + "'");
 }
			public override void OnExpressionStatement(ExpressionStatement node)
			{
				base.OnExpressionStatement(node);
				lastExpressionStatement = node;
			}
Beispiel #20
0
 public override void OnExpressionStatement(ExpressionStatement node)
 {
     WriteIndented();
     Visit(node.Expression);
     Visit(node.Modifier);
     WriteLine();
 }
Beispiel #21
0
 public object VisitExpressionStatement(ExpressionStatement statementExpression, object data)
 {
     B.ExpressionStatement st = new B.ExpressionStatement(GetLexicalInfo(statementExpression));
     st.Expression = ConvertExpression(statementExpression.Expression);
     return(st);
 }
		public override void OnExpressionStatement(ExpressionStatement node)
		{
			_expression = null;
			node.Expression.Accept(this);
			if (_expression != null)
				_statements.Add(new CodeExpressionStatement(_expression));
		}
Beispiel #23
0
		public override void OnExpressionStatement(ExpressionStatement node)
		{
			if (!_checked)
				return;

			base.OnExpressionStatement(node);

			IntegerLiteralExpression literal = node.Expression as IntegerLiteralExpression;
			if (null == literal)
				return;

			AssertLiteralInRange(literal, GetExpressionType(literal));
		}
 public override void OnExpressionStatement(ExpressionStatement node)
 {
     base.OnExpressionStatement(node);
     this.Expression = node.Expression;
 }
 public override void LeaveExpressionStatement(ExpressionStatement node)
 {
     LeaveStatement(node);
 }
Beispiel #26
0
	protected Statement  assignment_or_method_invocation_with_block_stmt() //throws RecognitionException, TokenStreamException
{
		Statement stmt;
		
		IToken  op = null;
		
				stmt = null;
				Expression lhs = null;
				Expression rhs = null;
				StatementModifier modifier = null;
				BinaryOperatorType binaryOperator = BinaryOperatorType.None;
				IToken token = null;
			
		
		try {      // for error handling
			lhs=slicing_expression();
			{
				switch ( LA(1) )
				{
				case DEF:
				case DO:
				case COLON:
				{
					{
						lhs=method_invocation_block(lhs);
						if (0==inputState.guessing)
						{
							stmt = new ExpressionStatement(lhs);
						}
					}
					break;
				}
				case ASSIGN:
				{
					{
						{
							op = LT(1);
							match(ASSIGN);
							if (0==inputState.guessing)
							{
								token = op; binaryOperator = OperatorParser.ParseAssignment(op.getText());
							}
							{
								if (((tokenSet_70_.member(LA(1))) && (tokenSet_92_.member(LA(2))))&&(_compact))
								{
									rhs=array_or_expression();
								}
								else {
									bool synPredMatched492 = false;
									if (((LA(1)==DEF||LA(1)==DO||LA(1)==COLON)))
									{
										int _m492 = mark();
										synPredMatched492 = true;
										inputState.guessing++;
										try {
											{
												switch ( LA(1) )
												{
												case COLON:
												{
													match(COLON);
													break;
												}
												case DEF:
												{
													match(DEF);
													break;
												}
												case DO:
												{
													match(DO);
													break;
												}
												default:
												{
													throw new NoViableAltException(LT(1), getFilename());
												}
												 }
											}
										}
										catch (RecognitionException)
										{
											synPredMatched492 = false;
										}
										rewind(_m492);
										inputState.guessing--;
									}
									if ( synPredMatched492 )
									{
										rhs=callable_expression();
									}
									else if ((tokenSet_70_.member(LA(1))) && (tokenSet_93_.member(LA(2)))) {
										{
											rhs=array_or_expression();
											{
												switch ( LA(1) )
												{
												case DEF:
												case DO:
												case COLON:
												{
													rhs=method_invocation_block(rhs);
													break;
												}
												case IF:
												case UNLESS:
												case WHILE:
												{
													{
														modifier=stmt_modifier();
														eos();
													}
													break;
												}
												case EOL:
												case EOS:
												{
													eos();
													break;
												}
												default:
												{
													throw new NoViableAltException(LT(1), getFilename());
												}
												 }
											}
										}
									}
									else
									{
										throw new NoViableAltException(LT(1), getFilename());
									}
									}
								}
							}
							if (0==inputState.guessing)
							{
								
												stmt = new ExpressionStatement(
														new BinaryExpression(ToLexicalInfo(token),
															binaryOperator,
															lhs, rhs));
												stmt.Modifier = modifier;
											
							}
						}
						break;
					}
					default:
					{
						throw new NoViableAltException(LT(1), getFilename());
					}
					 }
				}
			}
			catch (RecognitionException ex)
			{
				if (0 == inputState.guessing)
				{
					reportError(ex, "assignment_or_method_invocation_with_block_stmt");
					recover(ex,tokenSet_84_);
				}
				else
				{
					throw ex;
				}
			}
			return stmt;
		}
		public object VisitExpressionStatement(ExpressionStatement statementExpression, object data)
		{
			B.ExpressionStatement st = new B.ExpressionStatement(GetLexicalInfo(statementExpression));
			st.Expression = ConvertExpression(statementExpression.Expression);
			return st;
		}
Beispiel #28
0
	protected Statement  assignment_or_method_invocation() //throws RecognitionException, TokenStreamException
{
		Statement stmt;
		
		IToken  op = null;
		
				stmt = null;
				Expression lhs = null;
				Expression rhs = null;
				StatementModifier modifier = null;
				BinaryOperatorType binaryOperator = BinaryOperatorType.None;
				IToken token = null;
			
		
		try {      // for error handling
			lhs=slicing_expression();
			{
				op = LT(1);
				match(ASSIGN);
				if (0==inputState.guessing)
				{
					token = op; binaryOperator = OperatorParser.ParseAssignment(op.getText());
				}
				rhs=array_or_expression();
			}
			if (0==inputState.guessing)
			{
				
						stmt = new ExpressionStatement(
								new BinaryExpression(ToLexicalInfo(token),
									binaryOperator,
									lhs, rhs));
						stmt.Modifier = modifier;
					
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "assignment_or_method_invocation");
				recover(ex,tokenSet_19_);
			}
			else
			{
				throw ex;
			}
		}
		return stmt;
	}
Beispiel #29
0
        public override void OnExpressionStatement(ExpressionStatement node)
        {
            EmitDebugInfo(node);

            base.OnExpressionStatement(node);

            // if the type of the inner expression is not
            // void we need to pop its return value to leave
            // the stack sane
            DiscardValueOnStack();
        }
Beispiel #30
0
 public override void LeaveExpressionStatement(ExpressionStatement node)
 {
     AssertHasSideEffect(node.Expression);
 }
Beispiel #31
0
		override public object Clone()
		{
		
			ExpressionStatement clone = new ExpressionStatement();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			if (null != _modifier)
			{
				clone._modifier = _modifier.Clone() as StatementModifier;
				clone._modifier.InitializeParent(clone);
			}
			if (null != _expression)
			{
				clone._expression = _expression.Clone() as Expression;
				clone._expression.InitializeParent(clone);
			}
			return clone;


		}