Beispiel #1
0
		Method CreateGetter(Field f)
		{
			Method m = new Method();
			m.Name = "get";

			// value = ViewState["<f.Name>"]
			m.Body.Statements.Add(
				new ExpressionStatement(
					new BinaryExpression(
						BinaryOperatorType.Assign,
						new ReferenceExpression("value"),
						CreateViewStateSlice(f)
						)
					)
				);

			if (null != _default)
			{
				// return <_default> unless value
				ReturnStatement rs = new ReturnStatement(_default);
				rs.Modifier = new StatementModifier(StatementModifierType.Unless, new ReferenceExpression("value"));
				m.Body.Statements.Add(rs);
			}

			// return value
			m.Body.Statements.Add(
				new ReturnStatement(
					new ReferenceExpression("value")
					)
				);

			return m;
		}
Beispiel #2
0
		public override void LeaveReturnStatement(ReturnStatement node)
		{
			if (node.Expression == null)
				return;

			TryToReify(node.Expression, _currentMethod.ReturnType);
		}
			public override void OnReturnStatement(ReturnStatement node)
			{
				noReturnStatement = false;
				if (node.Expression == null) {
					result = ParserService.CurrentProjectContent.SystemTypes.Void;
				} else {
					result = new BooResolver().GetTypeOfExpression(node.Expression, context);
				}
			}
        public void ForCoverage()
        {
            var block = new Block();
            var statement = new ReturnStatement(new StringLiteralExpression("literal"));
            block.Statements.Add(statement);

            var visitor = new ReturnValueVisitor();
            bool found = visitor.Found;
            visitor.OnReturnStatement(statement);
        }
 public void CheckForEmptyCoroutine(Method node)
 {
     if (this.IsEmptyCoroutine(node))
     {
         ReturnStatement statement;
         ReturnStatement statement1 = statement = new ReturnStatement(LexicalInfo.Empty);
         statement.set_Expression(Expression.Lift(this.EmptyEnumeratorReference));
         node.get_Body().Add(statement);
     }
 }
		override public void LeaveReturnStatement(ReturnStatement node)
		{
			Expression expression = node.Expression;
			if (null == expression)
				return;

			if (!HasReturnType(_current))
				return;

			Expression newExpression = Convert(_current.ReturnType, expression);
			if (null == newExpression)
				return;

			node.Expression = newExpression;
		}
Beispiel #7
0
		public override void OnReturnStatement(ReturnStatement stmt)
		{
			// First normalize the statement
			normalizer.Visit(stmt);
			//empty return, so error
			if (stmt.Expression == null)
				throw new MonoRailException("An empty return statement on a method with output attribute");
			found = true;
			Block block = (Block) stmt.ParentNode;
			int index = 0;
			while(block.Statements[index] != stmt)
			{
				index ++;
			}

			MethodInvocationExpression invocation = mie.CloneNode();
			invocation.Arguments.Add(stmt.Expression);

			stmt.Expression = invocation;
		}
Beispiel #8
0
	protected ReturnStatement  return_expression_stmt() //throws RecognitionException, TokenStreamException
{
		ReturnStatement s;
		
		IToken  r = null;
		
				s = null;
				Expression e = null;
				StatementModifier modifier = null;
			
		
		try {      // for error handling
			r = LT(1);
			match(RETURN);
			{
				switch ( LA(1) )
				{
				case ESEPARATOR:
				case CAST:
				case CHAR:
				case FALSE:
				case NOT:
				case NULL:
				case SELF:
				case SUPER:
				case THEN:
				case TRUE:
				case TYPEOF:
				case TRIPLE_QUOTED_STRING:
				case LPAREN:
				case DOUBLE_QUOTED_STRING:
				case SINGLE_QUOTED_STRING:
				case ID:
				case MULTIPLY:
				case LBRACK:
				case COMMA:
				case SPLICE_BEGIN:
				case DOT:
				case LBRACE:
				case QQ_BEGIN:
				case SUBTRACT:
				case LONG:
				case INCREMENT:
				case DECREMENT:
				case ONES_COMPLEMENT:
				case INT:
				case BACKTICK_QUOTED_STRING:
				case RE_LITERAL:
				case DOUBLE:
				case FLOAT:
				case TIMESPAN:
				{
					e=array_or_expression();
					break;
				}
				case EOL:
				case IF:
				case UNLESS:
				case WHILE:
				case EOS:
				case RBRACE:
				case QQ_END:
				{
					break;
				}
				default:
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				 }
			}
			{
				if (((LA(1)==IF||LA(1)==UNLESS||LA(1)==WHILE))&&(!_compact))
				{
					modifier=stmt_modifier();
				}
				else if ((tokenSet_98_.member(LA(1)))) {
				}
				else
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				
			}
			if (0==inputState.guessing)
			{
				
						s = new ReturnStatement(ToLexicalInfo(r));
						s.Modifier = modifier;
						s.Expression = e;
					
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "return_expression_stmt");
				recover(ex,tokenSet_98_);
			}
			else
			{
				throw ex;
			}
		}
		return s;
	}
Beispiel #9
0
        private static void AddOptionalReturnStatement(Block body)
        {
            if (body.Statements.Count != 1) return;
            var stmt = body.FirstStatement as ExpressionStatement;
            if (null == stmt) return;

            var rs = new ReturnStatement(stmt.LexicalInfo, stmt.Expression, null);
            rs.Annotate(OptionalReturnStatementAnnotation);
            body.Replace(stmt, rs);
        }
Beispiel #10
0
        //throws RecognitionException, TokenStreamException
        protected ReturnStatement return_stmt()
        {
            ReturnStatement s;

            IToken  r = null;

                s = null;
                Expression e = null;
                StatementModifier modifier = null;

            try {      // for error handling
            r = LT(1);
            match(RETURN);
            {
                switch ( LA(1) )
                {
                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:
                {
                    {
                        e=array_or_expression();
                        {
                            switch ( LA(1) )
                            {
                            case DEF:
                            case DO:
                            case COLON:
                            {
                                e=method_invocation_block(e);
                                break;
                            }
                            case EOF:
                            case IF:
                            case UNLESS:
                            case WHILE:
                            case EOS:
                            case NEWLINE:
                            {
                                {
                                    {
                                        switch ( LA(1) )
                                        {
                                        case IF:
                                        case UNLESS:
                                        case WHILE:
                                        {
                                            modifier=stmt_modifier();
                                            break;
                                        }
                                        case EOF:
                                        case EOS:
                                        case NEWLINE:
                                        {
                                            break;
                                        }
                                        default:
                                        {
                                            throw new NoViableAltException(LT(1), getFilename());
                                        }
                                         }
                                    }
                                    eos();
                                }
                                break;
                            }
                            default:
                            {
                                throw new NoViableAltException(LT(1), getFilename());
                            }
                             }
                        }
                    }
                    break;
                }
                case DEF:
                case DO:
                case COLON:
                {
                    {
                        e=callable_expression();
                    }
                    break;
                }
                case EOF:
                case IF:
                case UNLESS:
                case WHILE:
                case EOS:
                case NEWLINE:
                {
                    {
                        {
                            switch ( LA(1) )
                            {
                            case IF:
                            case UNLESS:
                            case WHILE:
                            {
                                modifier=stmt_modifier();
                                break;
                            }
                            case EOF:
                            case EOS:
                            case NEWLINE:
                            {
                                break;
                            }
                            default:
                            {
                                throw new NoViableAltException(LT(1), getFilename());
                            }
                             }
                        }
                        eos();
                    }
                    break;
                }
                default:
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }
                 }
            }
            if (0==inputState.guessing)
            {

                        s = new ReturnStatement(SourceLocationFactory.ToLexicalInfo(r));
                        s.Modifier = modifier;
                        s.Expression = e;

            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_79_);
            }
            else
            {
                throw ex;
            }
            }
            return s;
        }
Beispiel #11
0
        public override void OnReturnStatement(ReturnStatement node)
        {
            EmitDebugInfo(node);
            OpCode retOpCode = _tryBlock > 0 ? OpCodes.Leave : OpCodes.Br;
            Label label = _returnLabel;

            if (null != node.Expression)
            {
                ++_returnStatements;

                Visit(node.Expression);
                EmitCastIfNeeded(_returnType, PopType());

                if (retOpCode == OpCodes.Leave)
                {
                    //`leave' clears the stack, so we have to store return value temporarily
                    //we can use a default value holder for that since it won't be read afterwards
                    //of course this is necessary only if return type is not void
                    LocalBuilder temp = GetDefaultValueHolder(_returnType);
                    _il.Emit(OpCodes.Stloc, temp);
                    label = _leaveLabel;
                    _hasLeaveWithStoredValue = true;
                }
            }
            else if (_returnType != TypeSystemServices.VoidType)
            {
                _returnImplicit = true;
                label = _implicitLabel;
            }

            if (_method.Body.LastStatement != node)
                _il.Emit(retOpCode, label);
            else if (null != node.Expression)
                _returnStatements = -1; //instruct epilogue to branch last ret only if necessary
        }
Beispiel #12
0
 public override void OnReturnStatement(ReturnStatement r)
 {
     WriteIndented();
     WriteKeyword("return ");
     Visit(r.Expression);
     Visit(r.Modifier);
     WriteLine();
 }
 public override void LeaveReturnStatement(ReturnStatement node)
 {
     if (HasReturnType(_current))
     {
         Expression expression = node.Expression;
         if (null != expression)
         {
             Expression newExpression = Convert(_current.ReturnType, expression);
             if (null != newExpression)
             {
                 node.Expression = newExpression;
             }
         }
     }
 }
		public override void OnReturnStatement(ReturnStatement node)
		{
			_expression = null;
			if (node.Expression != null)
				node.Expression.Accept(this);
			_statements.Add(new CodeMethodReturnStatement(_expression));
		}
Beispiel #15
0
		override public object Clone()
		{
		
			ReturnStatement clone = new ReturnStatement();
			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;


		}
 public void return_statement(Block b)
 {
     IToken token = null;
     try
     {
         Expression expression;
         token = this.LT(1);
         this.match(30);
         if (tokenSet_16_.member(this.LA(1)) && tokenSet_49_.member(this.LA(2)))
         {
             expression = this.expression();
         }
         else if (!tokenSet_15_.member(this.LA(1)) || !tokenSet_20_.member(this.LA(2)))
         {
             throw new NoViableAltException(this.LT(1), this.getFilename());
         }
         if (base.inputState.guessing == 0)
         {
             ReturnStatement statement;
             ReturnStatement statement1 = statement = new ReturnStatement(ToLexicalInfo(token));
             statement.set_Expression(expression);
             b.Add(statement);
         }
     }
     catch (RecognitionException exception)
     {
         if (base.inputState.guessing != 0)
         {
             throw;
         }
         this.reportError(exception);
         this.recover(exception, tokenSet_15_);
     }
 }
Beispiel #17
0
		override public void OnReturnStatement(ReturnStatement node)
		{
			RemoveUnreachableCode(node);
		}
Beispiel #18
0
        public override void LeaveReturnStatement(ReturnStatement node)
        {
            if (null == node.Expression)
                return;

            // forces anonymous types to be correctly
            // instantiated
            IType expressionType = GetConcreteExpressionType(node.Expression);
            if (TypeSystemServices.VoidType == expressionType
                && node.ContainsAnnotation(OptionalReturnStatementAnnotation))
            {
                node.ParentNode.Replace(
                    node,
                    new ExpressionStatement(node.Expression));
                return;
            }

            IType returnType = _currentMethod.ReturnType;
            if (TypeSystemServices.IsUnknown(returnType))
                _currentMethod.AddReturnExpression(node.Expression);
            else
                AssertTypeCompatibility(node.Expression, returnType, expressionType);

            //bind to nullable Value if needed
            if (TypeSystemServices.IsNullable(expressionType) && !TypeSystemServices.IsNullable(returnType))
            {
                // TODO: move to later steps or introduce an implicit conversion operator
                var mre = new MemberReferenceExpression(node.Expression.LexicalInfo, node.Expression, "Value");
                Visit(mre);
                node.Replace(node.Expression, mre);
            }
        }
        public override void LeaveReturnStatement(ReturnStatement node)
        {
            if (null == node.Expression) return;

            // forces anonymous types to be correctly
            // instantiated
            IType expressionType = GetConcreteExpressionType(node.Expression);
            if (TypeSystemServices.VoidType == expressionType
                && node.ContainsAnnotation(OptionalReturnStatementAnnotation))
            {
                node.ParentNode.Replace(
                    node,
                    new ExpressionStatement(node.Expression));
                return;
            }

            IType returnType = _currentMethod.ReturnType;
            if (TypeSystemServices.IsUnknown(returnType))
            {
                _currentMethod.AddReturnExpression(node.Expression);
            }
            else
            {
                AssertTypeCompatibility(node.Expression, returnType, expressionType);
            }
        }
Beispiel #20
0
 public override void LeaveReturnStatement(ReturnStatement node)
 {
     if (InsideEnsure)
     {
         Error(CompilerErrorFactory.CantReturnFromEnsure(node));
     }
     if (null == node.Expression) return;
     CheckExpressionType(node.Expression);
 }
 public override void LeaveReturnStatement(ReturnStatement node)
 {
     LeaveStatement(node);
 }
Beispiel #22
0
        public override void OnReturnStatement(ReturnStatement node)
        {
            EmitDebugInfo(node);
            OpCode retOpCode = _tryBlock > 0 ? OpCodes.Leave : OpCodes.Br;

            if (null != node.Expression)
            {
                Visit(node.Expression);
                EmitCastIfNeeded(_returnType, PopType());
                _il.Emit(OpCodes.Stloc, _returnValueLocal);
            }
            _il.Emit(retOpCode, _returnLabel);
        }
Beispiel #23
0
 public override void OnReturnStatement(ReturnStatement node)
 {
     _hasReturnStatements |= (null != node.Expression);
 }
 public override void OnReturnStatement(ReturnStatement node)
 {
     base.OnReturnStatement(node);
     this.Expression = node.Expression;
 }