Esempio n. 1
0
        private PreprocessorLine LexBlock()
        {
            while (_lexer.LexBlock(_text, _tokens, _includeComments))
            {
                PreprocessorLine line = _parser.Parse(_text, _defines);

                if (line != null)
                {
DoLine:
                    switch (line.Type)
                    {
                    case PreprocessorTokenType.Define:
                    case PreprocessorTokenType.Undef:
                    case PreprocessorTokenType.Warning:
                    case PreprocessorTokenType.Error:
                    case PreprocessorTokenType.Line:
                    case PreprocessorTokenType.Default:
                    case PreprocessorTokenType.Hidden:
                    case PreprocessorTokenType.Pragma:
                        DoSimpleLine(line);
                        break;

                    case PreprocessorTokenType.Region:
                        line = LexBlock();
                        if (line.Type == PreprocessorTokenType.EndRegion)
                        {
                            break;
                        }
                        else
                        {
                            ReportError(PreprocessorError.EndRegionExpected);
                            goto DoLine;
                        }

                    case PreprocessorTokenType.If:
                        line = DoIf((PreprocessorIfLine)line);
                        if (line != null)
                        {
                            goto DoLine;
                        }
                        break;

                    case PreprocessorTokenType.EndRegion:
                    case PreprocessorTokenType.Elif:
                    case PreprocessorTokenType.Else:
                    case PreprocessorTokenType.Endif:
                    case PreprocessorTokenType.EndOfLine:
                        return(line);
                    }
                }
            }

            return(new PreprocessorLine(PreprocessorTokenType.EndOfLine));
        }
Esempio n. 2
0
        private PreprocessorLine SkipElseBlock()
        {
            PreprocessorLine line = SkipBlock();

            if (line.Type == PreprocessorTokenType.Endif)
            {
                line = null;
            }
            else
            {
                ReportError(PreprocessorError.PPEndifExpected);
            }

            return(line);
        }
        public PreprocessorLine ParseNextLine(TextBuffer text, IDictionary defines) {
            PreprocessorLine line = null;

            do {
                lexer.SkipWhiteSpace();
                if (lexer.EOF) {
                    line = new PreprocessorLine(PreprocessorTokenType.EndOfLine);
                }
                else if (text.PeekChar() != '#') {
                    lexer.IgnoreRestOfLine();
                }
                else {
                    line = Parse(text, defines);
                }
            } while (line == null);

            return line;
        }
Esempio n. 4
0
        public PreprocessorLine ParseNextLine(TextBuffer text, IDictionary defines)
        {
            PreprocessorLine line = null;

            do
            {
                lexer.SkipWhiteSpace();
                if (lexer.EOF)
                {
                    line = new PreprocessorLine(PreprocessorTokenType.EndOfLine);
                }
                else if (text.PeekChar() != '#')
                {
                    lexer.IgnoreRestOfLine();
                }
                else
                {
                    line = Parse(text, defines);
                }
            } while (line == null);

            return(line);
        }
Esempio n. 5
0
        private void DoSimpleLine(PreprocessorLine line)
        {
            switch (line.Type)
            {
            case PreprocessorTokenType.Define:
            case PreprocessorTokenType.Undef:
                if (FoundNonComment())
                {
                    // have more than BOF
                    ReportError(PreprocessorError.DefineAfterToken);
                }
                else
                {
                    PreprocessorDeclarationLine decl = (PreprocessorDeclarationLine)line;
                    if (decl.Type == PreprocessorTokenType.Define)
                    {
                        _defines.Add(decl.Identifier.Text, null);
                    }
                    else
                    {
                        _defines.Remove(decl.Identifier.Text);
                    }
                }
                break;

            case PreprocessorTokenType.Warning:
                ReportFormattedError(PreprocessorError.PPWarning, ((PreprocessorControlLine)line).Message);
                break;

            case PreprocessorTokenType.Error:
                ReportFormattedError(PreprocessorError.PPError, ((PreprocessorControlLine)line).Message);
                break;

            case PreprocessorTokenType.Line: {
                PreprocessorLineNumberLine lineNumber = ((PreprocessorLineNumberLine)line);
                if (lineNumber.File != null)
                {
                    _lineMap.AddEntry(_text.Line, lineNumber.Line, lineNumber.File);
                }
                else
                {
                    _lineMap.AddEntry(_text.Line, lineNumber.Line);
                }
            }
            break;

            case PreprocessorTokenType.Default:
                _lineMap.AddEntry(_text.Line, _text.Line, _lineMap.FileName);
                break;

            case PreprocessorTokenType.Hidden:
                // #line hidden is for the weak
                break;

            case PreprocessorTokenType.Pragma:
                // no pragma's suported yet
                break;

            default:
                Debug.Fail("Bad preprocessor line");
                break;
            }
        }
Esempio n. 6
0
        private void DoSimpleLine(PreprocessorLine line) {
            switch (line.Type) {
                case PreprocessorTokenType.Define:
                case PreprocessorTokenType.Undef:
                    if (FoundNonComment()) {
                        // have more than BOF
                        ReportError(PreprocessorError.DefineAfterToken);
                    }
                    else {
                        PreprocessorDeclarationLine decl = (PreprocessorDeclarationLine)line;
                        if (decl.Type == PreprocessorTokenType.Define) {
                            _defines.Add(decl.Identifier.Text, null);
                        }
                        else {
                            _defines.Remove(decl.Identifier.Text);
                        }
                    }
                    break;

                case PreprocessorTokenType.Warning:
                    ReportFormattedError(PreprocessorError.PPWarning, ((PreprocessorControlLine)line).Message);
                    break;

                case PreprocessorTokenType.Error:
                    ReportFormattedError(PreprocessorError.PPError, ((PreprocessorControlLine)line).Message);
                    break;

                case PreprocessorTokenType.Line: {
                        PreprocessorLineNumberLine lineNumber = ((PreprocessorLineNumberLine)line);
                        if (lineNumber.File != null) {
                            _lineMap.AddEntry(_text.Line, lineNumber.Line, lineNumber.File);
                        }
                        else {
                            _lineMap.AddEntry(_text.Line, lineNumber.Line);
                        }
                    }
                    break;
                case PreprocessorTokenType.Default:
                    _lineMap.AddEntry(_text.Line, _text.Line, _lineMap.FileName);
                    break;

                case PreprocessorTokenType.Hidden:
                    // #line hidden is for the weak
                    break;
                case PreprocessorTokenType.Pragma:
                    // no pragma's suported yet
                    break;
                default:
                    Debug.Fail("Bad preprocessor line");
                    break;
            }
        }