Exemple #1
0
        // TODO - Still need to move parameter variables to their child scope. They are currently defined at the parent method scope, which is technically incorrect
        public Statement ProcessStatement(GLSLBracketTagger bracketTagger, GLSLFunctionTagger functionTagger, GLSLVariableTagger variableTagger)
        {
            var statement = new Statement(Span);
            statement.TagSpans.AddRange(_tagSpans);

            // Process the constructed statement
            bool isFunctionDefinition = false;

            for (var i = 0; i < TokenCount; i++)
            {
                var token = GetTokenAt(i);

                if (token.Tag.TokenType == GLSLTokenTypes.None)
                {
                    if (i > 0)
                    {
                        var previousToken = GetTokenAt(i - 1);
                        if (previousToken.Tag.TokenType == GLSLTokenTypes.Type)
                        {
                            // We need to determine the scope of this variable
                            var scope = bracketTagger.GetScope(previousToken.Span);

                            // This could be a variable OR a function definition.
                            // For it to be a function, the scope must be zero AND the token must be followed by parentheses
                            if (i > 1)
                            {
                                // This is a variable. Check for preceding keyword
                                if (isFunctionDefinition)
                                {
                                    // In this case, we KNOW that this should be a parameter variable. Look ahead until we get the bracket and find the child scope
                                    //scope = bracketTagger.GetScope(_tokens.Last().Span);
                                }

                                var tokenType = GetVariableType(i, isFunctionDefinition);
                                statement.TagSpans.AddRange(variableTagger.AddToken(token.Span, scope, previousToken.Span.GetText(), tokenType).TagSpans);
                            }
                            else if (scope.Level == 0 && i < TokenCount - 1 && GetTokenAt(i + 1).Span.GetText() == "(")
                            {
                                // We can now confirm that this is a function definition. Any variables defined within the definition are now parameters
                                isFunctionDefinition = true;
                                statement.TagSpans.AddRange(functionTagger.AddToken(token.Span, previousToken.Span.GetText()).TagSpans);
                            }
                            else
                            {
                                statement.TagSpans.AddRange(variableTagger.AddToken(token.Span, scope, previousToken.Span.GetText(), GLSLTokenTypes.LocalVariable).TagSpans);
                            }
                        }
                    }
                }
            }

            Clear();
            return statement;
        }