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" |
Chris Lattner | 500d329 | 2009-01-29 05:15:15 +0000 | [diff] [blame] | 16 | #include "clang/Lex/LexDiagnostic.h" |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 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 | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 20 | /// LexIncludeFilename - After the preprocessor has parsed a #include, lex and |
| 21 | /// (potentially) macro expand the filename. |
| 22 | void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { |
| 23 | assert(ParsingPreprocessorDirective && |
| 24 | ParsingFilename == false && |
| 25 | "Must be in a preprocessing directive!"); |
| 26 | |
| 27 | // We are now parsing a filename! |
| 28 | ParsingFilename = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 29 | |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 30 | // Lex the filename. |
| 31 | IndirectLex(FilenameTok); |
| 32 | |
| 33 | // We should have obtained the filename now. |
| 34 | ParsingFilename = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 35 | |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 36 | // No filename? |
| 37 | if (FilenameTok.is(tok::eom)) |
Chris Lattner | 306fda7 | 2008-11-22 06:20:42 +0000 | [diff] [blame] | 38 | PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 39 | } |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 40 | |
| 41 | /// getFileEntry - Return the FileEntry corresponding to this FileID. Like |
| 42 | /// getFileID(), this only works for lexers with attached preprocessors. |
| 43 | const FileEntry *PreprocessorLexer::getFileEntry() const { |
| 44 | return PP->getSourceManager().getFileEntryForID(getFileID()); |
| 45 | } |