| Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 1 | //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===// | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 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 | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 15 | #include "clang/Basic/SourceManager.h" | 
| Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/Lex/LexDiagnostic.h" | 
|  | 17 | #include "clang/Lex/Preprocessor.h" | 
| Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 18 | #include "clang/Lex/Token.h" | 
|  | 19 | #include <cassert> | 
|  | 20 |  | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 21 | using namespace clang; | 
|  | 22 |  | 
| Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 23 | void PreprocessorLexer::anchor() {} | 
| David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 24 |  | 
| Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 25 | PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid) | 
| Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 26 | : PP(pp), FID(fid) { | 
| Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 27 | if (pp) | 
|  | 28 | InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size(); | 
|  | 29 | } | 
|  | 30 |  | 
| Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 31 | /// After the preprocessor has parsed a \#include, lex and | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 32 | /// (potentially) macro expand the filename. | 
|  | 33 | void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { | 
|  | 34 | assert(ParsingPreprocessorDirective && | 
|  | 35 | ParsingFilename == false && | 
|  | 36 | "Must be in a preprocessing directive!"); | 
|  | 37 |  | 
|  | 38 | // We are now parsing a filename! | 
|  | 39 | ParsingFilename = true; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 |  | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 41 | // Lex the filename. | 
| Eli Friedman | 0834a4b | 2013-09-19 00:41:32 +0000 | [diff] [blame] | 42 | if (LexingRawMode) | 
|  | 43 | IndirectLex(FilenameTok); | 
|  | 44 | else | 
|  | 45 | PP->Lex(FilenameTok); | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 46 |  | 
|  | 47 | // We should have obtained the filename now. | 
|  | 48 | ParsingFilename = false; | 
| Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 |  | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 50 | // No filename? | 
| Peter Collingbourne | 2f1e36b | 2011-02-28 02:37:51 +0000 | [diff] [blame] | 51 | if (FilenameTok.is(tok::eod)) | 
| Chris Lattner | 57dab26 | 2008-11-22 06:20:42 +0000 | [diff] [blame] | 52 | PP->Diag(FilenameTok.getLocation(), diag::err_pp_expects_filename); | 
| Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 53 | } | 
| Chris Lattner | d32480d | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 54 |  | 
|  | 55 | /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like | 
|  | 56 | /// getFileID(), this only works for lexers with attached preprocessors. | 
|  | 57 | const FileEntry *PreprocessorLexer::getFileEntry() const { | 
|  | 58 | return PP->getSourceManager().getFileEntryForID(getFileID()); | 
|  | 59 | } |