Пример #1
0
        /// <summary>
        /// Reads the next unsafe-statement from the file and returns it.
        /// </summary>
        /// <param name="parentReference">
        /// The parent code unit.
        /// </param>
        /// <returns>
        /// Returns the statement.
        /// </returns>
        private UnsafeStatement ParseUnsafeStatement(Reference<ICodePart> parentReference)
        {
            Param.AssertNotNull(parentReference, "parentReference");
            Reference<ICodePart> statementReference = new Reference<ICodePart>();

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

            // Get the embedded statement. It must be a block statement.
            BlockStatement childStatement = this.GetNextStatement(statementReference, true) as BlockStatement;
            if (childStatement == null)
            {
                throw this.CreateSyntaxException();
            }

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

            // Create and return the unsafe-statement.
            UnsafeStatement statement = new UnsafeStatement(partialTokens, childStatement);
            statementReference.Target = statement;

            return statement;
        }
 /// <summary>
 /// The save.
 /// </summary>
 /// <param name="unsafeStatement">
 /// The unsafe statement.
 /// </param>
 private void Save(UnsafeStatement unsafeStatement)
 {
     this.cppWriter.Write("/* unsafe */");
     this.Save((Statement)unsafeStatement.EmbeddedStatement);
 }