/// <summary>
        /// Reads the next fixed-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 FixedStatement ParseFixedStatement(Reference<ICodePart> parentReference, bool unsafeCode)
        {
            Param.AssertNotNull(parentReference, "parentReference");
            Param.Ignore(unsafeCode);

            var statementReference = new Reference<ICodePart>();

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

            // Make sure we're sitting on the opening parenthesis now.
            Bracket openParenthesis = this.GetBracketToken(CsTokenType.OpenParenthesis, SymbolType.OpenParenthesis, statementReference);
            Node<CsToken> openParenthesisNode = this.tokens.InsertLast(openParenthesis);

            // Get the expression within the parenthesis. It must be a variable declaration.
            VariableDeclarationExpression expression = this.GetNextExpression(
                ExpressionPrecedence.None, statementReference, unsafeCode, true, false) as VariableDeclarationExpression;
            if (expression == null)
            {
                throw this.CreateSyntaxException();
            }

            // Get the closing parenthesis.
            Bracket closeParenthesis = this.GetBracketToken(CsTokenType.CloseParenthesis, SymbolType.CloseParenthesis, statementReference);
            Node<CsToken> closeParenthesisNode = this.tokens.InsertLast(closeParenthesis);

            openParenthesis.MatchingBracketNode = closeParenthesisNode;
            closeParenthesis.MatchingBracketNode = openParenthesisNode;

            // Get the embedded statement.
            Statement childStatement = this.GetNextStatement(statementReference, unsafeCode);
            if (childStatement == null)
            {
                throw this.CreateSyntaxException();
            }

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

            // Create the fixed-statement.
            FixedStatement statement = new FixedStatement(partialTokens, expression);
            statement.EmbeddedStatement = childStatement;
            statementReference.Target = statement;

            // Add the variable if there is one.
            foreach (VariableDeclaratorExpression declarator in expression.Declarators)
            {
                Variable variable = new Variable(
                    expression.Type,
                    declarator.Identifier.Token.Text,
                    VariableModifiers.None,
                    CodeLocation.Join(expression.Type.Location, declarator.Identifier.Token.Location),
                    statementReference,
                    expression.Type.Generated || declarator.Identifier.Token.Generated);

                // If there is already a variable in this scope with the same name, ignore this one.
                if (!statement.Variables.Contains(declarator.Identifier.Token.Text))
                {
                    statement.Variables.Add(variable);
                }
            }

            return statement;
        }
Example #2
0
 private FixedStatement ParseFixedStatement(bool unsafeCode)
 {
     CsToken item = this.GetToken(CsTokenType.Fixed, SymbolType.Fixed);
     Microsoft.StyleCop.Node<CsToken> firstItemNode = this.tokens.InsertLast(item);
     Bracket bracketToken = this.GetBracketToken(CsTokenType.OpenParenthesis, SymbolType.OpenParenthesis);
     Microsoft.StyleCop.Node<CsToken> node2 = this.tokens.InsertLast(bracketToken);
     VariableDeclarationExpression fixedVariable = this.GetNextExpression(ExpressionPrecedence.None, unsafeCode, true, false) as VariableDeclarationExpression;
     if (fixedVariable == null)
     {
         throw this.CreateSyntaxException();
     }
     Bracket bracket2 = this.GetBracketToken(CsTokenType.CloseParenthesis, SymbolType.CloseParenthesis);
     Microsoft.StyleCop.Node<CsToken> node3 = this.tokens.InsertLast(bracket2);
     bracketToken.MatchingBracketNode = node3;
     bracket2.MatchingBracketNode = node2;
     Statement nextStatement = this.GetNextStatement(unsafeCode);
     if (nextStatement == null)
     {
         throw this.CreateSyntaxException();
     }
     CsTokenList tokens = new CsTokenList(this.tokens, firstItemNode, this.tokens.Last);
     FixedStatement statement2 = new FixedStatement(tokens, fixedVariable);
     statement2.EmbeddedStatement = nextStatement;
     foreach (VariableDeclaratorExpression expression2 in fixedVariable.Declarators)
     {
         Variable variable = new Variable(fixedVariable.Type, expression2.Identifier.Token.Text, VariableModifiers.None, expression2.Tokens.First.Value.Location.StartPoint, fixedVariable.Type.Generated || expression2.Identifier.Token.Generated);
         if (!statement2.Variables.Contains(expression2.Identifier.Token.Text))
         {
             statement2.Variables.Add(variable);
         }
     }
     return statement2;
 }