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 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the PreprocessorLexer and Token interfaces. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "clang/Lex/PreprocessorLexer.h" |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 14 | #include "clang/Basic/SourceManager.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 15 | #include "clang/Lex/LexDiagnostic.h" |
| 16 | #include "clang/Lex/Preprocessor.h" |
Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 17 | #include "clang/Lex/Token.h" |
| 18 | #include <cassert> |
| 19 | |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | |
Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 22 | void PreprocessorLexer::anchor() {} |
David Blaikie | 68e081d | 2011-12-20 02:48:34 +0000 | [diff] [blame] | 23 | |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 24 | PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid) |
Eugene Zelenko | 5dc60fe | 2017-12-04 23:16:21 +0000 | [diff] [blame] | 25 | : PP(pp), FID(fid) { |
Argyrios Kyrtzidis | 61ef3db | 2011-08-21 23:33:04 +0000 | [diff] [blame] | 26 | if (pp) |
| 27 | InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size(); |
| 28 | } |
| 29 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 30 | /// After the preprocessor has parsed a \#include, lex and |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 31 | /// (potentially) macro expand the filename. |
| 32 | void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) { |
Richard Smith | b9b0510 | 2019-03-19 01:51:19 +0000 | [diff] [blame] | 33 | assert(ParsingFilename == false && "reentered LexIncludeFilename"); |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 34 | |
| 35 | // We are now parsing a filename! |
| 36 | ParsingFilename = true; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 37 | |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 38 | // Lex the filename. |
Eli Friedman | 0834a4b | 2013-09-19 00:41:32 +0000 | [diff] [blame] | 39 | if (LexingRawMode) |
| 40 | IndirectLex(FilenameTok); |
| 41 | else |
| 42 | PP->Lex(FilenameTok); |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 43 | |
| 44 | // We should have obtained the filename now. |
| 45 | ParsingFilename = false; |
Ted Kremenek | 6c90efb | 2008-11-12 22:43:05 +0000 | [diff] [blame] | 46 | } |
Chris Lattner | d32480d | 2009-01-17 06:22:33 +0000 | [diff] [blame] | 47 | |
| 48 | /// getFileEntry - Return the FileEntry corresponding to this FileID. Like |
| 49 | /// getFileID(), this only works for lexers with attached preprocessors. |
| 50 | const FileEntry *PreprocessorLexer::getFileEntry() const { |
| 51 | return PP->getSourceManager().getFileEntryForID(getFileID()); |
| 52 | } |