xref: /freebsd/contrib/llvm-project/clang/lib/Lex/PreprocessorLexer.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
10b57cec5SDimitry Andric //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric //  This file implements the PreprocessorLexer and Token interfaces.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #include "clang/Lex/PreprocessorLexer.h"
140b57cec5SDimitry Andric #include "clang/Basic/SourceManager.h"
150b57cec5SDimitry Andric #include "clang/Lex/LexDiagnostic.h"
160b57cec5SDimitry Andric #include "clang/Lex/Preprocessor.h"
170b57cec5SDimitry Andric #include "clang/Lex/Token.h"
180b57cec5SDimitry Andric #include <cassert>
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric using namespace clang;
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric void PreprocessorLexer::anchor() {}
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
250b57cec5SDimitry Andric     : PP(pp), FID(fid) {
260b57cec5SDimitry Andric   if (pp)
270b57cec5SDimitry Andric     InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
280b57cec5SDimitry Andric }
290b57cec5SDimitry Andric 
300b57cec5SDimitry Andric /// After the preprocessor has parsed a \#include, lex and
310b57cec5SDimitry Andric /// (potentially) macro expand the filename.
320b57cec5SDimitry Andric void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
330b57cec5SDimitry Andric   assert(ParsingFilename == false && "reentered LexIncludeFilename");
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   // We are now parsing a filename!
360b57cec5SDimitry Andric   ParsingFilename = true;
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   // Lex the filename.
390b57cec5SDimitry Andric   if (LexingRawMode)
400b57cec5SDimitry Andric     IndirectLex(FilenameTok);
410b57cec5SDimitry Andric   else
420b57cec5SDimitry Andric     PP->Lex(FilenameTok);
430b57cec5SDimitry Andric 
440b57cec5SDimitry Andric   // We should have obtained the filename now.
450b57cec5SDimitry Andric   ParsingFilename = false;
460b57cec5SDimitry Andric }
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
490b57cec5SDimitry Andric /// getFileID(), this only works for lexers with attached preprocessors.
50*5f757f3fSDimitry Andric OptionalFileEntryRef PreprocessorLexer::getFileEntry() const {
5181ad6265SDimitry Andric   return PP->getSourceManager().getFileEntryRefForID(getFileID());
520b57cec5SDimitry Andric }
53