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