xref: /llvm-project/clang/lib/Lex/PreprocessorLexer.cpp (revision 764275949897533a4be0728250e69a94d228fbc5)
1 //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 //  This file implements the PreprocessorLexer and Token interfaces.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "clang/Lex/PreprocessorLexer.h"
14 #include "clang/Basic/SourceManager.h"
15 #include "clang/Lex/Preprocessor.h"
16 #include "clang/Lex/Token.h"
17 #include <cassert>
18 
19 using namespace clang;
20 
21 void PreprocessorLexer::anchor() {}
22 
23 PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
24     : PP(pp), FID(fid) {
25   if (pp)
26     InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
27 }
28 
29 /// After the preprocessor has parsed a \#include, lex and
30 /// (potentially) macro expand the filename.
31 void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
32   assert(ParsingFilename == false && "reentered LexIncludeFilename");
33 
34   // We are now parsing a filename!
35   ParsingFilename = true;
36 
37   // Lex the filename.
38   if (LexingRawMode)
39     IndirectLex(FilenameTok);
40   else
41     PP->Lex(FilenameTok);
42 
43   // We should have obtained the filename now.
44   ParsingFilename = false;
45 }
46 
47 /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
48 /// getFileID(), this only works for lexers with attached preprocessors.
49 OptionalFileEntryRef PreprocessorLexer::getFileEntry() const {
50   return PP->getSourceManager().getFileEntryRefForID(getFileID());
51 }
52