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" |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
Ted Kremenek | 41938c8 | 2008-11-19 21:57:25 +0000 | [diff] [blame] | 20 | PreprocessorLexer::PreprocessorLexer(Preprocessor* pp, SourceLocation L) |
Ted Kremenek | 452e378 | 2008-11-20 01:29:45 +0000 | [diff] [blame] | 21 | : PP(pp), FileID(pp->getSourceManager().getPhysicalLoc(L).getFileID()), |
| 22 | ParsingPreprocessorDirective(false), |
| 23 | ParsingFilename(false), |
| 24 | LexingRawMode(false) {} |
Ted Kremenek | 41938c8 | 2008-11-19 21:57:25 +0000 | [diff] [blame] | 25 | |
Ted Kremenek | 2c71d0f | 2008-11-12 22:48:57 +0000 | [diff] [blame] | 26 | PreprocessorLexer::~PreprocessorLexer() {} |
| 27 | |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 28 | /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and |
| 29 | /// (potentially) macro expand the filename. |
| 30 | void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { |
| 31 | assert(ParsingPreprocessorDirective && |
| 32 | ParsingFilename == false && |
| 33 | "Must be in a preprocessing directive!"); |
| 34 | |
| 35 | // We are now parsing a filename! |
| 36 | ParsingFilename = true; |
| 37 | |
| 38 | // Lex the filename. |
| 39 | IndirectLex(FilenameTok); |
| 40 | |
| 41 | // We should have obtained the filename now. |
| 42 | ParsingFilename = false; |
| 43 | |
| 44 | // No filename? |
| 45 | if (FilenameTok.is(tok::eom)) |
Chris Lattner | 306fda7 | 2008-11-22 06:20:42 +0000 | [diff] [blame] | 46 | PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 47 | } |