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); }
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; } }
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)); }