Пример #1
0
        /// <summary>
        /// Reads the next return-statement from the file and returns it.
        /// </summary>
        /// <param name="parentReference">
        /// The parent code unit.
        /// </param>
        /// <param name="unsafeCode">
        /// Indicates whether the code being parsed resides in an unsafe code block.
        /// </param>
        /// <returns>
        /// Returns the statement.
        /// </returns>
        private ReturnStatement ParseReturnStatement(Reference<ICodePart> parentReference, bool unsafeCode)
        {
            Param.AssertNotNull(parentReference, "parentReference");
            Param.Ignore(unsafeCode);

            Reference<ICodePart> statementReference = new Reference<ICodePart>();

            // Move past the return keyword.
            CsToken firstToken = this.GetToken(CsTokenType.Return, SymbolType.Return, parentReference, statementReference);
            Node<CsToken> firstTokenNode = this.tokens.InsertLast(firstToken);

            // Check the next symbol and see if there is an expression to return.
            Symbol symbol = this.GetNextSymbol(statementReference);

            Expression expression = null;
            if (symbol.SymbolType != SymbolType.Semicolon)
            {
                // Get the expression to return.
                expression = this.GetNextExpression(ExpressionPrecedence.None, statementReference, unsafeCode);
                if (expression == null)
                {
                    throw this.CreateSyntaxException();
                }
            }

            this.tokens.Add(this.GetToken(CsTokenType.Semicolon, SymbolType.Semicolon, statementReference));

            // Create the token list for the statement.
            CsTokenList partialTokens = new CsTokenList(this.tokens, firstTokenNode, firstTokenNode);

            // Create and return the statement.
            ReturnStatement statement = new ReturnStatement(partialTokens, expression);
            statementReference.Target = statement;

            return statement;
        }
 /// <summary>
 /// The save.
 /// </summary>
 /// <param name="returnStatement">
 /// The return statement.
 /// </param>
 private void Save(ReturnStatement returnStatement)
 {
     this.cppWriter.Write("return ");
     @switch(returnStatement.ReturnValue);
 }