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" |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 15 | #include "clang/Basic/SourceManager.h" |
Chandler Carruth | 55fc873 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/Lex/LexDiagnostic.h" |
| 17 | #include "clang/Lex/Preprocessor.h" |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 18 | using namespace clang; |
| 19 | |
David Blaikie | 99ba9e3 | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 20 | void PreprocessorLexer::anchor() { } |
| 21 | |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 22 | PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid) |
| 23 | : PP(pp), FID(fid), InitialNumSLocEntries(0), |
| 24 | ParsingPreprocessorDirective(false), |
Daniel Dunbar | 6e64973 | 2012-11-13 19:12:37 +0000 | [diff] [blame] | 25 | ParsingFilename(false), LexingRawMode(false) { |
Argyrios Kyrtzidis | d9d2b67 | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 26 | if (pp) |
| 27 | InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size(); |
| 28 | } |
| 29 | |
James Dennett | d986853 | 2012-06-17 03:41:54 +0000 | [diff] [blame] | 30 | /// \brief After the preprocessor has parsed a \#include, lex and |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 31 | /// (potentially) macro expand the filename. |
| 32 | void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { |
| 33 | assert(ParsingPreprocessorDirective && |
| 34 | ParsingFilename == false && |
| 35 | "Must be in a preprocessing directive!"); |
| 36 | |
| 37 | // We are now parsing a filename! |
| 38 | ParsingFilename = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 40 | // Lex the filename. |
| 41 | IndirectLex(FilenameTok); |
| 42 | |
| 43 | // We should have obtained the filename now. |
| 44 | ParsingFilename = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 45 | |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 46 | // No filename? |
Peter Collingbourne | 8402155 | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 47 | if (FilenameTok.is(tok::eod)) |
Chris Lattner | 306fda7 | 2008-11-22 06:20:42 +0000 | [diff] [blame] | 48 | PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); |
Ted Kremenek | ab91b70 | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 49 | } |
Chris Lattner | 2b2453a | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 50 | |
| 51 | /// getFileEntry - Return the FileEntry corresponding to this FileID. Like |
| 52 | /// getFileID(), this only works for lexers with attached preprocessors. |
| 53 | const FileEntry *PreprocessorLexer::getFileEntry() const { |
| 54 | return PP->getSourceManager().getFileEntryForID(getFileID()); |
| 55 | } |