Exemplo n.º 1
0
        /// <summary>
        /// Reads the next default-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 SwitchDefaultStatement ParseSwitchDefaultStatement(Reference<ICodePart> parentReference, bool unsafeCode)
        {
            Param.AssertNotNull(parentReference, "parentReference");
            Param.Ignore(unsafeCode);

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

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

            // Get the colon.
            this.tokens.Add(this.GetToken(CsTokenType.LabelColon, SymbolType.Colon, statementReference));

            // Create the statement.
            SwitchDefaultStatement defaultStatement = new SwitchDefaultStatement();

            // Get each of the sub-statements beneath this statement.
            while (true)
            {
                // Check the type of the next symbol.
                Symbol symbol = this.GetNextSymbol(statementReference);

                // Check if we've reached the end of the default statement.
                if (symbol.SymbolType == SymbolType.CloseCurlyBracket || symbol.SymbolType == SymbolType.Case || symbol.SymbolType == SymbolType.Default)
                {
                    break;
                }

                // Read the next child statement.
                Statement statement = this.GetNextStatement(statementReference, unsafeCode, defaultStatement.Variables);
                if (statement == null)
                {
                    throw this.CreateSyntaxException();
                }

                // Add it to the default statement.
                defaultStatement.AddStatement(statement);
            }

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

            statementReference.Target = defaultStatement;
            return defaultStatement;
        }