blob: 5f6f4a13419be1788e2f7d28008e55af2c15e13b [file] [log] [blame]
Eugene Zelenko5dc60fe2017-12-04 23:16:21 +00001//===- PreprocessorLexer.cpp - C Language Family Lexer --------------------===//
Ted Kremenek6c90efb2008-11-12 22:43:05 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Ted Kremenek6c90efb2008-11-12 22:43:05 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the PreprocessorLexer and Token interfaces.
10//
11//===----------------------------------------------------------------------===//
12
13#include "clang/Lex/PreprocessorLexer.h"
Ted Kremenek6c90efb2008-11-12 22:43:05 +000014#include "clang/Basic/SourceManager.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000015#include "clang/Lex/LexDiagnostic.h"
16#include "clang/Lex/Preprocessor.h"
Eugene Zelenko5dc60fe2017-12-04 23:16:21 +000017#include "clang/Lex/Token.h"
18#include <cassert>
19
Ted Kremenek6c90efb2008-11-12 22:43:05 +000020using namespace clang;
21
Eugene Zelenko5dc60fe2017-12-04 23:16:21 +000022void PreprocessorLexer::anchor() {}
David Blaikie68e081d2011-12-20 02:48:34 +000023
Argyrios Kyrtzidis61ef3db2011-08-21 23:33:04 +000024PreprocessorLexer::PreprocessorLexer(Preprocessor *pp, FileID fid)
Eugene Zelenko5dc60fe2017-12-04 23:16:21 +000025 : PP(pp), FID(fid) {
Argyrios Kyrtzidis61ef3db2011-08-21 23:33:04 +000026 if (pp)
27 InitialNumSLocEntries = pp->getSourceManager().local_sloc_entry_size();
28}
29
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000030/// After the preprocessor has parsed a \#include, lex and
Ted Kremenek6c90efb2008-11-12 22:43:05 +000031/// (potentially) macro expand the filename.
32void PreprocessorLexer::LexIncludeFilename(Token &FilenameTok) {
Richard Smithb9b05102019-03-19 01:51:19 +000033 assert(ParsingFilename == false && "reentered LexIncludeFilename");
Ted Kremenek6c90efb2008-11-12 22:43:05 +000034
35 // We are now parsing a filename!
36 ParsingFilename = true;
Mike Stump11289f42009-09-09 15:08:12 +000037
Ted Kremenek6c90efb2008-11-12 22:43:05 +000038 // Lex the filename.
Eli Friedman0834a4b2013-09-19 00:41:32 +000039 if (LexingRawMode)
40 IndirectLex(FilenameTok);
41 else
42 PP->Lex(FilenameTok);
Ted Kremenek6c90efb2008-11-12 22:43:05 +000043
44 // We should have obtained the filename now.
45 ParsingFilename = false;
Ted Kremenek6c90efb2008-11-12 22:43:05 +000046}
Chris Lattnerd32480d2009-01-17 06:22:33 +000047
48/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
49/// getFileID(), this only works for lexers with attached preprocessors.
50const FileEntry *PreprocessorLexer::getFileEntry() const {
51 return PP->getSourceManager().getFileEntryForID(getFileID());
52}