xref: /freebsd/contrib/llvm-project/clang/lib/Lex/PreprocessorLexer.cpp (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric //  This file implements the PreprocessorLexer and Token interfaces.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric #include "clang/Lex/PreprocessorLexer.h"
14*0b57cec5SDimitry Andric #include "clang/Basic/SourceManager.h"
15*0b57cec5SDimitry Andric #include "clang/Lex/LexDiagnostic.h"
16*0b57cec5SDimitry Andric #include "clang/Lex/Preprocessor.h"
17*0b57cec5SDimitry Andric #include "clang/Lex/Token.h"
18*0b57cec5SDimitry Andric #include <cassert>
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric using namespace clang;
21*0b57cec5SDimitry Andric 
22*0b57cec5SDimitry Andric void PreprocessorLexer::anchor() {}
23*0b57cec5SDimitry Andric 
24*0b57cec5SDimitry Andric PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
25*0b57cec5SDimitry Andric     : PP(pp), FID(fid) {
26*0b57cec5SDimitry Andric   if (pp)
27*0b57cec5SDimitry Andric     InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
28*0b57cec5SDimitry Andric }
29*0b57cec5SDimitry Andric 
30*0b57cec5SDimitry Andric /// After the preprocessor has parsed a \#include, lex and
31*0b57cec5SDimitry Andric /// (potentially) macro expand the filename.
32*0b57cec5SDimitry Andric void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
33*0b57cec5SDimitry Andric   assert(ParsingFilename == false && "reentered LexIncludeFilename");
34*0b57cec5SDimitry Andric 
35*0b57cec5SDimitry Andric   // We are now parsing a filename!
36*0b57cec5SDimitry Andric   ParsingFilename = true;
37*0b57cec5SDimitry Andric 
38*0b57cec5SDimitry Andric   // Lex the filename.
39*0b57cec5SDimitry Andric   if (LexingRawMode)
40*0b57cec5SDimitry Andric     IndirectLex(FilenameTok);
41*0b57cec5SDimitry Andric   else
42*0b57cec5SDimitry Andric     PP->Lex(FilenameTok);
43*0b57cec5SDimitry Andric 
44*0b57cec5SDimitry Andric   // We should have obtained the filename now.
45*0b57cec5SDimitry Andric   ParsingFilename = false;
46*0b57cec5SDimitry Andric }
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric /// getFileEntry - Return the FileEntry corresponding to this FileID.  Like
49*0b57cec5SDimitry Andric /// getFileID(), this only works for lexers with attached preprocessors.
50*0b57cec5SDimitry Andric const FileEntry *PreprocessorLexer::getFileEntry() const {
51*0b57cec5SDimitry Andric   return PP->getSourceManager().getFileEntryForID(getFileID());
52*0b57cec5SDimitry Andric }
53