clang  14.0.0git
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
clang::PreprocessorLexer Class Referenceabstract

#include "clang/Lex/PreprocessorLexer.h"

Inheritance diagram for clang::PreprocessorLexer:
Inheritance graph
[legend]
Collaboration diagram for clang::PreprocessorLexer:
Collaboration graph
[legend]

Classes

struct  IncludeInfo
 

Public Types

using conditional_iterator = SmallVectorImpl< PPConditionalInfo >::const_iterator
 Iterator that traverses the current stack of preprocessor conditional directives (#if/#ifdef/#ifndef). More...
 

Public Member Functions

 PreprocessorLexer (const PreprocessorLexer &)=delete
 
PreprocessorLexeroperator= (const PreprocessorLexer &)=delete
 
void LexIncludeFilename (Token &FilenameTok)
 Lex a token, producing a header-name token if possible. More...
 
void setParsingPreprocessorDirective (bool f)
 Inform the lexer whether or not we are currently lexing a preprocessor directive. More...
 
bool isLexingRawMode () const
 Return true if this lexer is in raw mode or not. More...
 
PreprocessorgetPP () const
 Return the preprocessor object for this lexer. More...
 
FileID getFileID () const
 
unsigned getInitialNumSLocEntries () const
 Number of SLocEntries before lexing the file. More...
 
const FileEntrygetFileEntry () const
 getFileEntry - Return the FileEntry corresponding to this FileID. More...
 
conditional_iterator conditional_begin () const
 
conditional_iterator conditional_end () const
 
void setConditionalLevels (ArrayRef< PPConditionalInfo > CL)
 
void addInclude (StringRef Filename, const FileEntry &File, SourceLocation Location)
 
const llvm::StringMap< IncludeInfo > & getIncludeHistory () const
 

Protected Member Functions

 PreprocessorLexer ()
 
 PreprocessorLexer (Preprocessor *pp, FileID fid)
 
virtual ~PreprocessorLexer ()=default
 
virtual void IndirectLex (Token &Result)=0
 
virtual SourceLocation getSourceLocation ()=0
 Return the source location for the next observable location. More...
 
void pushConditionalLevel (SourceLocation DirectiveStart, bool WasSkipping, bool FoundNonSkip, bool FoundElse)
 pushConditionalLevel - When we enter a #if directive, this keeps track of what we are currently in for diagnostic emission (e.g. More...
 
void pushConditionalLevel (const PPConditionalInfo &CI)
 
bool popConditionalLevel (PPConditionalInfo &CI)
 popConditionalLevel - Remove an entry off the top of the conditional stack, returning information about it. More...
 
PPConditionalInfopeekConditionalLevel ()
 Return the top of the conditional stack. More...
 
unsigned getConditionalStackDepth () const
 

Protected Attributes

PreprocessorPP = nullptr
 
const FileID FID
 The SourceManager FileID corresponding to the file being lexed. More...
 
unsigned InitialNumSLocEntries = 0
 Number of SLocEntries before lexing the file. More...
 
bool ParsingPreprocessorDirective = false
 True when parsing #XXX; turns '\n' into a tok::eod token. More...
 
bool ParsingFilename = false
 True after #include; turns <xx> or "xxx" into a tok::header_name token. More...
 
bool LexingRawMode = false
 True if in raw mode. More...
 
MultipleIncludeOpt MIOpt
 A state machine that detects the #ifndef-wrapping a file idiom for the multiple-include optimization. More...
 
SmallVector< PPConditionalInfo, 4 > ConditionalStack
 Information about the set of #if/#ifdef/#ifndef blocks we are currently in. More...
 
llvm::StringMap< IncludeInfoIncludeHistory
 

Friends

class Preprocessor
 

Detailed Description

Definition at line 31 of file PreprocessorLexer.h.

Member Typedef Documentation

◆ conditional_iterator

Iterator that traverses the current stack of preprocessor conditional directives (#if/#ifdef/#ifndef).

Definition at line 173 of file PreprocessorLexer.h.

Constructor & Destructor Documentation

◆ PreprocessorLexer() [1/3]

clang::PreprocessorLexer::PreprocessorLexer ( )
inlineprotected

Definition at line 86 of file PreprocessorLexer.h.

◆ PreprocessorLexer() [2/3]

PreprocessorLexer::PreprocessorLexer ( Preprocessor pp,
FileID  fid 
)
protected

◆ ~PreprocessorLexer()

virtual clang::PreprocessorLexer::~PreprocessorLexer ( )
protectedvirtualdefault

◆ PreprocessorLexer() [3/3]

clang::PreprocessorLexer::PreprocessorLexer ( const PreprocessorLexer )
delete

Member Function Documentation

◆ addInclude()

void clang::PreprocessorLexer::addInclude ( StringRef  Filename,
const FileEntry File,
SourceLocation  Location 
)
inline

Definition at line 188 of file PreprocessorLexer.h.

References clang::File, Filename, and IncludeHistory.

◆ conditional_begin()

conditional_iterator clang::PreprocessorLexer::conditional_begin ( ) const
inline

Definition at line 175 of file PreprocessorLexer.h.

References ConditionalStack.

◆ conditional_end()

conditional_iterator clang::PreprocessorLexer::conditional_end ( ) const
inline

Definition at line 179 of file PreprocessorLexer.h.

References ConditionalStack.

◆ getConditionalStackDepth()

unsigned clang::PreprocessorLexer::getConditionalStackDepth ( ) const
inlineprotected

Definition at line 131 of file PreprocessorLexer.h.

References ConditionalStack.

Referenced by clang::Preprocessor::HandleDirective().

◆ getFileEntry()

const FileEntry * PreprocessorLexer::getFileEntry ( ) const

◆ getFileID()

FileID clang::PreprocessorLexer::getFileID ( ) const
inline

◆ getIncludeHistory()

const llvm::StringMap<IncludeInfo>& clang::PreprocessorLexer::getIncludeHistory ( ) const
inline

Definition at line 193 of file PreprocessorLexer.h.

References IncludeHistory.

◆ getInitialNumSLocEntries()

unsigned clang::PreprocessorLexer::getInitialNumSLocEntries ( ) const
inline

Number of SLocEntries before lexing the file.

Definition at line 162 of file PreprocessorLexer.h.

References InitialNumSLocEntries.

Referenced by clang::Preprocessor::HandleEndOfFile().

◆ getPP()

Preprocessor* clang::PreprocessorLexer::getPP ( ) const
inline

Return the preprocessor object for this lexer.

Definition at line 153 of file PreprocessorLexer.h.

References PP.

◆ getSourceLocation()

virtual SourceLocation clang::PreprocessorLexer::getSourceLocation ( )
protectedpure virtual

Return the source location for the next observable location.

Implemented in clang::Lexer.

Referenced by clang::Preprocessor::HandleEndOfFile().

◆ IndirectLex()

virtual void clang::PreprocessorLexer::IndirectLex ( Token Result)
protectedpure virtual

Referenced by LexIncludeFilename().

◆ isLexingRawMode()

bool clang::PreprocessorLexer::isLexingRawMode ( ) const
inline

Return true if this lexer is in raw mode or not.

Definition at line 150 of file PreprocessorLexer.h.

References LexingRawMode.

Referenced by DecodeTrigraphChar(), and isEndOfBlockCommentWithEscapedNewLine().

◆ LexIncludeFilename()

void PreprocessorLexer::LexIncludeFilename ( Token FilenameTok)

Lex a token, producing a header-name token if possible.

After the preprocessor has parsed a #include, lex and (potentially) macro expand the filename.

Definition at line 32 of file PreprocessorLexer.cpp.

References IndirectLex(), clang::Preprocessor::Lex(), LexingRawMode, ParsingFilename, and PP.

Referenced by clang::Preprocessor::LexHeaderName().

◆ operator=()

PreprocessorLexer& clang::PreprocessorLexer::operator= ( const PreprocessorLexer )
delete

◆ peekConditionalLevel()

PPConditionalInfo& clang::PreprocessorLexer::peekConditionalLevel ( )
inlineprotected

Return the top of the conditional stack.

Precondition
This requires that there be a conditional active.

Definition at line 126 of file PreprocessorLexer.h.

References ConditionalStack.

◆ popConditionalLevel()

bool clang::PreprocessorLexer::popConditionalLevel ( PPConditionalInfo CI)
inlineprotected

popConditionalLevel - Remove an entry off the top of the conditional stack, returning information about it.

If the conditional stack is empty, this returns true and does not fill in the arguments.

Definition at line 117 of file PreprocessorLexer.h.

References ConditionalStack.

◆ pushConditionalLevel() [1/2]

void clang::PreprocessorLexer::pushConditionalLevel ( const PPConditionalInfo CI)
inlineprotected

Definition at line 110 of file PreprocessorLexer.h.

References ConditionalStack.

◆ pushConditionalLevel() [2/2]

void clang::PreprocessorLexer::pushConditionalLevel ( SourceLocation  DirectiveStart,
bool  WasSkipping,
bool  FoundNonSkip,
bool  FoundElse 
)
inlineprotected

pushConditionalLevel - When we enter a #if directive, this keeps track of what we are currently in for diagnostic emission (e.g.

#if with missing #endif).

Definition at line 101 of file PreprocessorLexer.h.

References ConditionalStack, clang::PPConditionalInfo::FoundElse, clang::PPConditionalInfo::FoundNonSkip, clang::PPConditionalInfo::IfLoc, and clang::PPConditionalInfo::WasSkipping.

◆ setConditionalLevels()

void clang::PreprocessorLexer::setConditionalLevels ( ArrayRef< PPConditionalInfo CL)
inline

Definition at line 183 of file PreprocessorLexer.h.

References ConditionalStack.

◆ setParsingPreprocessorDirective()

void clang::PreprocessorLexer::setParsingPreprocessorDirective ( bool  f)
inline

Inform the lexer whether or not we are currently lexing a preprocessor directive.

Definition at line 145 of file PreprocessorLexer.h.

References ParsingPreprocessorDirective.

Friends And Related Function Documentation

◆ Preprocessor

friend class Preprocessor
friend

Definition at line 35 of file PreprocessorLexer.h.

Member Data Documentation

◆ ConditionalStack

SmallVector<PPConditionalInfo, 4> clang::PreprocessorLexer::ConditionalStack
protected

Information about the set of #if/#ifdef/#ifndef blocks we are currently in.

Definition at line 77 of file PreprocessorLexer.h.

Referenced by conditional_begin(), conditional_end(), getConditionalStackDepth(), peekConditionalLevel(), popConditionalLevel(), pushConditionalLevel(), and setConditionalLevels().

◆ FID

const FileID clang::PreprocessorLexer::FID
protected

The SourceManager FileID corresponding to the file being lexed.

Definition at line 41 of file PreprocessorLexer.h.

Referenced by getFileID(), and clang::Lexer::getImmediateMacroName().

◆ IncludeHistory

llvm::StringMap<IncludeInfo> clang::PreprocessorLexer::IncludeHistory
protected

Definition at line 84 of file PreprocessorLexer.h.

Referenced by addInclude(), and getIncludeHistory().

◆ InitialNumSLocEntries

unsigned clang::PreprocessorLexer::InitialNumSLocEntries = 0
protected

Number of SLocEntries before lexing the file.

Definition at line 44 of file PreprocessorLexer.h.

Referenced by getInitialNumSLocEntries(), and PreprocessorLexer().

◆ LexingRawMode

bool clang::PreprocessorLexer::LexingRawMode = false
protected

True if in raw mode.

Raw mode disables interpretation of tokens and is a far faster mode to lex in than non-raw-mode. This flag:

  1. If EOF of the current lexer is found, the include stack isn't popped.
  2. Identifier information is not looked up for identifier tokens. As an effect of this, implicit macro expansion is naturally disabled.
  3. "#" tokens at the start of a line are treated as normal tokens, not implicitly transformed by the lexer.
  4. All diagnostic messages are disabled.
  5. No callbacks are made into the preprocessor.

Note that in raw mode that the PP pointer may be null.

Definition at line 69 of file PreprocessorLexer.h.

Referenced by clang::Preprocessor::HandleMicrosoftCommentPaste(), clang::Preprocessor::HandlePragmaPoison(), isLexingRawMode(), clang::Lexer::Lexer(), LexIncludeFilename(), and clang::Lexer::SetKeepWhitespaceMode().

◆ MIOpt

MultipleIncludeOpt clang::PreprocessorLexer::MIOpt
protected

A state machine that detects the #ifndef-wrapping a file idiom for the multiple-include optimization.

Definition at line 73 of file PreprocessorLexer.h.

Referenced by clang::Preprocessor::HandleDirective(), and clang::Preprocessor::HandleEndOfFile().

◆ ParsingFilename

bool clang::PreprocessorLexer::ParsingFilename = false
protected

True after #include; turns <xx> or "xxx" into a tok::header_name token.

Definition at line 54 of file PreprocessorLexer.h.

Referenced by LexIncludeFilename(), and clang::Lexer::ReadToEndOfLine().

◆ ParsingPreprocessorDirective

bool clang::PreprocessorLexer::ParsingPreprocessorDirective = false
protected

◆ PP

Preprocessor* clang::PreprocessorLexer::PP = nullptr
protected

The documentation for this class was generated from the following files: