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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of clang/lib/Lex/PreprocessorLexer.cpp