clang
18.0.0git
lib
Lex
PreprocessorLexer.cpp
Go to the documentation of this file.
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/LexDiagnostic.h
"
16
#include "
clang/Lex/Preprocessor.h
"
17
#include "
clang/Lex/Token.h
"
18
#include <cassert>
19
20
using namespace
clang
;
21
22
void
PreprocessorLexer::anchor() {}
23
24
PreprocessorLexer::PreprocessorLexer
(
Preprocessor
*pp,
FileID
fid)
25
: PP(pp), FID(fid) {
26
if
(pp)
27
InitialNumSLocEntries
= pp->
getSourceManager
().
local_sloc_entry_size
();
28
}
29
30
/// After the preprocessor has parsed a \#include, lex and
31
/// (potentially) macro expand the filename.
32
void
PreprocessorLexer::LexIncludeFilename
(
Token
&FilenameTok) {
33
assert(
ParsingFilename
==
false
&&
"reentered LexIncludeFilename"
);
34
35
// We are now parsing a filename!
36
ParsingFilename
=
true
;
37
38
// Lex the filename.
39
if
(
LexingRawMode
)
40
IndirectLex
(FilenameTok);
41
else
42
PP
->
Lex
(FilenameTok);
43
44
// We should have obtained the filename now.
45
ParsingFilename
=
false
;
46
}
47
48
/// getFileEntry - Return the FileEntry corresponding to this FileID. Like
49
/// getFileID(), this only works for lexers with attached preprocessors.
50
OptionalFileEntryRefDegradesToFileEntryPtr
51
PreprocessorLexer::getFileEntry
()
const
{
52
return
PP
->
getSourceManager
().
getFileEntryRefForID
(
getFileID
());
53
}
LexDiagnostic.h
PreprocessorLexer.h
Defines the PreprocessorLexer interface.
Preprocessor.h
Defines the clang::Preprocessor interface.
SourceManager.h
Defines the SourceManager interface.
Token.h
clang::FileID
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Definition:
SourceLocation.h:39
clang::OptionalFileEntryRefDegradesToFileEntryPtr
Wrapper around OptionalFileEntryRef that degrades to 'const FileEntry*', facilitating incremental pat...
Definition:
FileEntry.h:322
clang::PreprocessorLexer::getFileEntry
OptionalFileEntryRefDegradesToFileEntryPtr getFileEntry() const
getFileEntry - Return the FileEntry corresponding to this FileID.
Definition:
PreprocessorLexer.cpp:51
clang::PreprocessorLexer::IndirectLex
virtual void IndirectLex(Token &Result)=0
clang::PreprocessorLexer::LexingRawMode
bool LexingRawMode
True if in raw mode.
Definition:
PreprocessorLexer.h:68
clang::PreprocessorLexer::PP
Preprocessor * PP
Definition:
PreprocessorLexer.h:37
clang::PreprocessorLexer::getFileID
FileID getFileID() const
Definition:
PreprocessorLexer.h:147
clang::PreprocessorLexer::ParsingFilename
bool ParsingFilename
True after #include; turns <xx> or "xxx" into a tok::header_name token.
Definition:
PreprocessorLexer.h:53
clang::PreprocessorLexer::PreprocessorLexer
PreprocessorLexer()
Definition:
PreprocessorLexer.h:78
clang::PreprocessorLexer::LexIncludeFilename
void LexIncludeFilename(Token &FilenameTok)
Lex a token, producing a header-name token if possible.
Definition:
PreprocessorLexer.cpp:32
clang::PreprocessorLexer::InitialNumSLocEntries
unsigned InitialNumSLocEntries
Number of SLocEntries before lexing the file.
Definition:
PreprocessorLexer.h:43
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition:
Preprocessor.h:128
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition:
Preprocessor.cpp:882
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition:
Preprocessor.h:1203
clang::SourceManager::getFileEntryRefForID
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
Definition:
SourceManager.h:1052
clang::SourceManager::local_sloc_entry_size
unsigned local_sloc_entry_size() const
Get the number of local SLocEntries we have.
Definition:
SourceManager.h:1701
clang::Token
Token - This structure provides full information about a lexed token.
Definition:
Token.h:35
clang
Definition:
CalledOnceCheck.h:17
Generated on Sat Sep 23 2023 18:24:57 for clang by
1.9.6