Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 1 | //===--- PreprocessorLexer.cpp - C Language Family Lexer ------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the PreprocessorLexer and Token interfaces. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "clang/Lex/PreprocessorLexer.h" |
| 15 | #include "clang/Lex/Preprocessor.h" |
| 16 | #include "clang/Basic/Diagnostic.h" |
| 17 | #include "clang/Basic/SourceManager.h" |
| 18 | |
| 19 | using namespace clang; |
| 20 | |
Ted Kremenek | 41938c8 | 2008-11-19 21:57:25 +0000 | [diff] [blame] | 21 | PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L) |
Ted Kremenek | 452e378 | 2008-11-20 01:29:45 +0000 | [diff] [blame^] | 22 | : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()), |
| 23 | ParsingPreprocessorDirective(false), |
| 24 | ParsingFilename(false), |
| 25 | LexingRawMode(false) {} |
Ted Kremenek | 41938c8 | 2008-11-19 21:57:25 +0000 | [diff] [blame] | 26 | |
Ted Kremenek | 2c71d0f | 2008-11-12 22:48:57 +0000 | [diff] [blame] | 27 | PreprocessorLexer::~PreprocessorLexer() {} |
| 28 | |
Ted Kremenek | d6a2e7d | 2008-11-12 23:13:54 +0000 | [diff] [blame] | 29 | void PreprocessorLexer::Diag(SourceLocation Loc, unsigned DiagID, |
| 30 | const std::string &Msg) const { |
| 31 | if (LexingRawMode && Diagnostic::isBuiltinNoteWarningOrExtension(DiagID)) |
| 32 | return; |
Chris Lattner | 204b2fe | 2008-11-18 21:48:13 +0000 | [diff] [blame] | 33 | PP->Diag(Loc, DiagID) << Msg; |
Ted Kremenek | d6a2e7d | 2008-11-12 23:13:54 +0000 | [diff] [blame] | 34 | } |
| 35 | |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 36 | /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and |
| 37 | /// (potentially) macro expand the filename. |
| 38 | void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { |
| 39 | assert(ParsingPreprocessorDirective && |
| 40 | ParsingFilename == false && |
| 41 | "Must be in a preprocessing directive!"); |
| 42 | |
| 43 | // We are now parsing a filename! |
| 44 | ParsingFilename = true; |
| 45 | |
| 46 | // Lex the filename. |
| 47 | IndirectLex(FilenameTok); |
| 48 | |
| 49 | // We should have obtained the filename now. |
| 50 | ParsingFilename = false; |
| 51 | |
| 52 | // No filename? |
| 53 | if (FilenameTok.is(tok::eom)) |
| 54 | Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); |
| 55 | } |