diff options
| author | Lubos Lunak <l.lunak@suse.cz> | 2013-07-20 14:23:27 +0000 |
|---|---|---|
| committer | Lubos Lunak <l.lunak@suse.cz> | 2013-07-20 14:23:27 +0000 |
| commit | 4c22f6a695f2ffcb37a3bb6dd56972209bbbd200 (patch) | |
| tree | 2a2672bf4ba5f87a5bdd4ccc0ee8c54b74f53fb4 /clang/lib/Rewrite/Frontend | |
| parent | a3d5304ec06364e0abe8c95749f99de6c5ed42a9 (diff) | |
| download | bcm5719-llvm-4c22f6a695f2ffcb37a3bb6dd56972209bbbd200.tar.gz bcm5719-llvm-4c22f6a695f2ffcb37a3bb6dd56972209bbbd200.zip | |
fix sometimes incorrect line numbers in -frewrite-includes mode (pr#14795)
Every #include is surrounded by #if 0 in order to comment it out, which adds
lines. That is fixed up right after, but that all can be inside #if part
that is not processed, so fix up also after every end of a conditional part.
llvm-svn: 186763
Diffstat (limited to 'clang/lib/Rewrite/Frontend')
| -rw-r--r-- | clang/lib/Rewrite/Frontend/InclusionRewriter.cpp | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp index 9e4bb3c89bc..0c3269a0472 100644 --- a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -365,7 +365,7 @@ bool InclusionRewriter::Process(FileID FileId, RawLex.LexFromRawLexer(RawToken); if (RawToken.is(tok::raw_identifier)) PP.LookUpIdentifierInfo(RawToken); - if (RawToken.is(tok::identifier) || RawToken.is(tok::kw_if)) { + if (RawToken.getIdentifierInfo() != NULL) { switch (RawToken.getIdentifierInfo()->getPPKeywordID()) { case tok::pp_include: case tok::pp_include_next: @@ -412,7 +412,9 @@ bool InclusionRewriter::Process(FileID FileId, break; } case tok::pp_if: - case tok::pp_elif: + case tok::pp_elif: { + bool elif = (RawToken.getIdentifierInfo()->getPPKeywordID() == + tok::pp_elif); // Rewrite special builtin macros to avoid pulling in host details. do { // Walk over the directive. @@ -453,8 +455,33 @@ bool InclusionRewriter::Process(FileID FileId, OS << "*/"; } } while (RawToken.isNot(tok::eod)); - + if (elif) { + OutputContentUpTo(FromFile, NextToWrite, + SM.getFileOffset(RawToken.getLocation()) + + RawToken.getLength(), + EOL, Line, /*EnsureNewLine*/ true); + WriteLineInfo(FileName, Line, FileType, EOL); + } break; + } + case tok::pp_endif: + case tok::pp_else: { + // We surround every #include by #if 0 to comment it out, but that + // changes line numbers. These are fixed up right after that, but + // the whole #include could be inside a preprocessor conditional + // that is not processed. So it is necessary to fix the line + // numbers one the next line after each #else/#endif as well. + RawLex.SetKeepWhitespaceMode(true); + do { + RawLex.LexFromRawLexer(RawToken); + } while (RawToken.isNot(tok::eod) && RawToken.isNot(tok::eof)); + OutputContentUpTo( + FromFile, NextToWrite, + SM.getFileOffset(RawToken.getLocation()) + RawToken.getLength(), + EOL, Line, /*EnsureNewLine*/ true); + WriteLineInfo(FileName, Line, FileType, EOL); + RawLex.SetKeepWhitespaceMode(false); + } default: break; } |

