1 //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements the PreprocessorLexer and Token interfaces.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Lex/PreprocessorLexer.h"
14 #include "clang/Basic/SourceManager.h"
15 #include "clang/Lex/LexDiagnostic.h"
16 #include "clang/Lex/Preprocessor.h"
17 #include "clang/Lex/Token.h"
20 using namespace clang
;
22 void PreprocessorLexer::anchor() {}
24 PreprocessorLexer::PreprocessorLexer(Preprocessor
*pp
, FileID fid
)
27 InitialNumSLocEntries
= pp
->getSourceManager().local_sloc_entry_size();
30 /// After the preprocessor has parsed a \#include, lex and
31 /// (potentially) macro expand the filename.
32 void PreprocessorLexer::LexIncludeFilename(Token
&FilenameTok
) {
33 assert(ParsingFilename
== false && "reentered LexIncludeFilename");
35 // We are now parsing a filename!
36 ParsingFilename
= true;
40 IndirectLex(FilenameTok
);
44 // We should have obtained the filename now.
45 ParsingFilename
= false;
48 /// getFileEntry - Return the FileEntry corresponding to this FileID. Like
49 /// getFileID(), this only works for lexers with attached preprocessors.
50 OptionalFileEntryRefDegradesToFileEntryPtr
51 PreprocessorLexer::getFileEntry() const {
52 return PP
->getSourceManager().getFileEntryRefForID(getFileID());