clang 19.0.0git
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Friends | List of all members
clang::Preprocessor Class Reference

Engages in a tight little dance with the lexer to efficiently preprocess tokens. More...

#include "clang/Lex/Preprocessor.h"

Classes

struct  PreambleSkipInfo
 
class  ResetMacroExpansionHelper
 

Public Types

using IncludedFilesSet = llvm::DenseSet< const FileEntry * >
 

Public Member Functions

const char * getCheckPoint (FileID FID, const char *Start) const
 Returns a pointer into the given file's buffer that's guaranteed to be between tokens.
 
 Preprocessor (std::shared_ptr< PreprocessorOptions > PPOpts, DiagnosticsEngine &diags, const LangOptions &LangOpts, SourceManager &SM, HeaderSearch &Headers, ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup=nullptr, bool OwnsHeaderSearch=false, TranslationUnitKind TUKind=TU_Complete)
 
 ~Preprocessor ()
 
void Initialize (const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
 Initialize the preprocessor using information about the target.
 
void InitializeForModelFile ()
 Initialize the preprocessor to parse a model file.
 
void FinalizeForModelFile ()
 Cleanup after model file parsing.
 
PreprocessorOptionsgetPreprocessorOpts () const
 Retrieve the preprocessor options used to initialize this preprocessor.
 
DiagnosticsEnginegetDiagnostics () const
 
void setDiagnostics (DiagnosticsEngine &D)
 
const LangOptionsgetLangOpts () const
 
const TargetInfogetTargetInfo () const
 
const TargetInfogetAuxTargetInfo () const
 
FileManagergetFileManager () const
 
SourceManagergetSourceManager () const
 
HeaderSearchgetHeaderSearchInfo () const
 
IdentifierTablegetIdentifierTable ()
 
const IdentifierTablegetIdentifierTable () const
 
SelectorTablegetSelectorTable ()
 
Builtin::ContextgetBuiltinInfo ()
 
llvm::BumpPtrAllocator & getPreprocessorAllocator ()
 
void setExternalSource (ExternalPreprocessorSource *Source)
 
ExternalPreprocessorSourcegetExternalSource () const
 
ModuleLoadergetModuleLoader () const
 Retrieve the module loader associated with this preprocessor.
 
bool hadModuleLoaderFatalFailure () const
 
unsigned getNumDirectives () const
 Retrieve the number of Directives that have been processed by the Preprocessor.
 
bool isParsingIfOrElifDirective () const
 True if we are currently preprocessing a if or #elif directive.
 
void SetCommentRetentionState (bool KeepComments, bool KeepMacroComments)
 Control whether the preprocessor retains comments in output.
 
bool getCommentRetentionState () const
 
void setPragmasEnabled (bool Enabled)
 
bool getPragmasEnabled () const
 
void SetSuppressIncludeNotFoundError (bool Suppress)
 
bool GetSuppressIncludeNotFoundError ()
 
void setPreprocessedOutput (bool IsPreprocessedOutput)
 Sets whether the preprocessor is responsible for producing output or if it is producing tokens to be consumed by Parse and Sema.
 
bool isPreprocessedOutput () const
 Returns true if the preprocessor is responsible for generating output, false if it is producing tokens to be consumed by Parse and Sema.
 
bool isCurrentLexer (const PreprocessorLexer *L) const
 Return true if we are lexing directly from the specified lexer.
 
PreprocessorLexergetCurrentLexer () const
 Return the current lexer being lexed from.
 
PreprocessorLexergetCurrentFileLexer () const
 Return the current file lexer being lexed from.
 
ModulegetCurrentLexerSubmodule () const
 Return the submodule owning the file being lexed.
 
FileID getPredefinesFileID () const
 Returns the FileID for the preprocessor predefines.
 
unsigned getTokenCount () const
 Get the number of tokens processed so far.
 
unsigned getMaxTokens () const
 Get the max number of tokens before issuing a -Wmax-tokens warning.
 
void overrideMaxTokens (unsigned Value, SourceLocation Loc)
 
SourceLocation getMaxTokensOverrideLoc () const
 
void setTokenWatcher (llvm::unique_function< void(const clang::Token &)> F)
 Register a function that would be called on each token in the final expanded token stream.
 
void setPreprocessToken (bool Preprocess)
 
bool isMacroDefined (StringRef Id)
 
bool isMacroDefined (const IdentifierInfo *II)
 
bool isMacroDefinedInLocalModule (const IdentifierInfo *II, Module *M)
 Determine whether II is defined as a macro within the module M, if that is a module that we've already preprocessed.
 
MacroDefinition getMacroDefinition (const IdentifierInfo *II)
 
MacroDefinition getMacroDefinitionAtLoc (const IdentifierInfo *II, SourceLocation Loc)
 
MacroDirectivegetLocalMacroDirective (const IdentifierInfo *II) const
 Given an identifier, return its latest non-imported MacroDirective if it is #define'd and not #undef'd, or null if it isn't #define'd.
 
const MacroInfogetMacroInfo (const IdentifierInfo *II) const
 
MacroInfogetMacroInfo (const IdentifierInfo *II)
 
MacroDirectivegetLocalMacroDirectiveHistory (const IdentifierInfo *II) const
 Given an identifier, return the latest non-imported macro directive for that identifier.
 
void appendMacroDirective (IdentifierInfo *II, MacroDirective *MD)
 Add a directive to the macro directive history for this identifier.
 
DefMacroDirectiveappendDefMacroDirective (IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc)
 
DefMacroDirectiveappendDefMacroDirective (IdentifierInfo *II, MacroInfo *MI)
 
void setLoadedMacroDirective (IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD)
 Set a MacroDirective that was loaded from a PCH file.
 
ModuleMacroaddModuleMacro (Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew)
 Register an exported macro for a module and identifier.
 
ModuleMacrogetModuleMacro (Module *Mod, const IdentifierInfo *II)
 
ArrayRef< ModuleMacro * > getLeafModuleMacros (const IdentifierInfo *II) const
 Get the list of leaf (non-overridden) module macros for a name.
 
ArrayRef< BuildingSubmoduleInfo > getBuildingSubmodules () const
 Get the list of submodules that we're currently building.
 
void markClangModuleAsAffecting (Module *M)
 Mark the given clang module as affecting the current clang module or translation unit.
 
const llvm::SmallSetVector< Module *, 2 > & getAffectingClangModules () const
 Get the set of top-level clang modules that affected preprocessing, but were not imported.
 
bool markIncluded (FileEntryRef File)
 Mark the file as included.
 
bool alreadyIncluded (FileEntryRef File) const
 Return true if this header has already been included.
 
IncludedFilesSetgetIncludedFiles ()
 Get the set of included files.
 
const IncludedFilesSetgetIncludedFiles () const
 
StringRef getLastMacroWithSpelling (SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
 Return the name of the macro defined before Loc that has spelling Tokens.
 
const std::string & getPredefines () const
 Get the predefines for this processor.
 
void setPredefines (std::string P)
 Set the predefines for this Preprocessor.
 
IdentifierInfogetIdentifierInfo (StringRef Name) const
 Return information about the specified preprocessor identifier token.
 
void AddPragmaHandler (StringRef Namespace, PragmaHandler *Handler)
 Add the specified pragma handler to this preprocessor.
 
void AddPragmaHandler (PragmaHandler *Handler)
 
void RemovePragmaHandler (StringRef Namespace, PragmaHandler *Handler)
 Remove the specific pragma handler from this preprocessor.
 
void RemovePragmaHandler (PragmaHandler *Handler)
 
void IgnorePragmas ()
 Install empty handlers for all pragmas (making them ignored).
 
void setEmptylineHandler (EmptylineHandler *Handler)
 Set empty line handler.
 
EmptylineHandlergetEmptylineHandler () const
 
void addCommentHandler (CommentHandler *Handler)
 Add the specified comment handler to the preprocessor.
 
void removeCommentHandler (CommentHandler *Handler)
 Remove the specified comment handler.
 
void setCodeCompletionHandler (CodeCompletionHandler &Handler)
 Set the code completion handler to the given object.
 
CodeCompletionHandlergetCodeCompletionHandler () const
 Retrieve the current code-completion handler.
 
void clearCodeCompletionHandler ()
 Clear out the code completion handler.
 
void CodeCompleteIncludedFile (llvm::StringRef Dir, bool IsAngled)
 Hook used by the lexer to invoke the "included file" code completion point.
 
void CodeCompleteNaturalLanguage ()
 Hook used by the lexer to invoke the "natural language" code completion point.
 
void setCodeCompletionIdentifierInfo (IdentifierInfo *Filter)
 Set the code completion token for filtering purposes.
 
void setCodeCompletionTokenRange (const SourceLocation Start, const SourceLocation End)
 Set the code completion token range for detecting replacement range later on.
 
SourceRange getCodeCompletionTokenRange () const
 
StringRef getCodeCompletionFilter ()
 Get the code completion token for filtering purposes.
 
PreprocessingRecordgetPreprocessingRecord () const
 Retrieve the preprocessing record, or NULL if there is no preprocessing record.
 
void createPreprocessingRecord ()
 Create a new preprocessing record, which will keep track of all macro expansions, macro definitions, etc.
 
bool isPCHThroughHeader (const FileEntry *FE)
 Returns true if the FileEntry is the PCH through header.
 
bool creatingPCHWithThroughHeader ()
 True if creating a PCH with a through header.
 
bool usingPCHWithThroughHeader ()
 True if using a PCH with a through header.
 
bool creatingPCHWithPragmaHdrStop ()
 True if creating a PCH with a #pragma hdrstop.
 
bool usingPCHWithPragmaHdrStop ()
 True if using a PCH with a #pragma hdrstop.
 
void SkipTokensWhileUsingPCH ()
 Skip tokens until after the #include of the through header or until after a #pragma hdrstop.
 
void HandleSkippedDirectiveWhileUsingPCH (Token &Result, SourceLocation HashLoc)
 Process directives while skipping until the through header or #pragma hdrstop is found.
 
void EnterMainSourceFile ()
 Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
 
void EndSourceFile ()
 Inform the preprocessor callbacks that processing is complete.
 
bool EnterSourceFile (FileID FID, ConstSearchDirIterator Dir, SourceLocation Loc, bool IsFirstIncludeOfFile=true)
 Add a source file to the top of the include stack and start lexing tokens from it instead of the current buffer.
 
void EnterMacro (Token &Tok, SourceLocation ILEnd, MacroInfo *Macro, MacroArgs *Args)
 Add a Macro to the top of the include stack and start lexing tokens from it instead of the current buffer.
 
void EnterTokenStream (std::unique_ptr< Token[]> Toks, unsigned NumToks, bool DisableMacroExpansion, bool IsReinject)
 
void EnterTokenStream (ArrayRef< Token > Toks, bool DisableMacroExpansion, bool IsReinject)
 
void RemoveTopOfLexerStack ()
 Pop the current lexer/macro exp off the top of the lexer stack.
 
void EnableBacktrackAtThisPos ()
 From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is called, the Preprocessor keeps track of the lexed tokens so that a subsequent Backtrack() call will make the Preprocessor re-lex the same tokens.
 
void CommitBacktrackedTokens ()
 Disable the last EnableBacktrackAtThisPos call.
 
void Backtrack ()
 Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously called.
 
bool isBacktrackEnabled () const
 True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
 
void Lex (Token &Result)
 Lex the next token for this preprocessor.
 
void LexTokensUntilEOF (std::vector< Token > *Tokens=nullptr)
 Lex all tokens for this preprocessor until (and excluding) end of file.
 
bool LexHeaderName (Token &Result, bool AllowMacroExpansion=true)
 Lex a token, forming a header-name token if possible.
 
bool LexAfterModuleImport (Token &Result)
 Lex a token following the 'import' contextual keyword.
 
void CollectPpImportSuffix (SmallVectorImpl< Token > &Toks)
 Collect the tokens of a C++20 pp-import-suffix.
 
void makeModuleVisible (Module *M, SourceLocation Loc)
 
SourceLocation getModuleImportLoc (Module *M) const
 
bool LexStringLiteral (Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
 Lex a string literal, which may be the concatenation of multiple string literals and may even come from macro expansion.
 
bool FinishLexStringLiteral (Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
 Complete the lexing of a string literal where the first token has already been lexed (see LexStringLiteral).
 
void LexNonComment (Token &Result)
 Lex a token.
 
void LexUnexpandedToken (Token &Result)
 Just like Lex, but disables macro expansion of identifier tokens.
 
void LexUnexpandedNonComment (Token &Result)
 Like LexNonComment, but this disables macro expansion of identifier tokens.
 
bool parseSimpleIntegerLiteral (Token &Tok, uint64_t &Value)
 Parses a simple integer literal to get its numeric value.
 
void SetMacroExpansionOnlyInDirectives ()
 Disables macro expansion everywhere except for preprocessor directives.
 
const TokenLookAhead (unsigned N)
 Peeks ahead N tokens and returns that token without consuming any tokens.
 
void RevertCachedTokens (unsigned N)
 When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens.
 
void EnterToken (const Token &Tok, bool IsReinject)
 Enters a token in the token stream to be lexed next.
 
void AnnotateCachedTokens (const Token &Tok)
 We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should replace the most recent cached tokens with the given annotation token.
 
SourceLocation getLastCachedTokenLocation () const
 Get the location of the last cached token, suitable for setting the end location of an annotation token.
 
bool IsPreviousCachedToken (const Token &Tok) const
 Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
 
void ReplacePreviousCachedToken (ArrayRef< Token > NewToks)
 Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
 
void ReplaceLastTokenWithAnnotation (const Token &Tok)
 Replace the last token with an annotation token.
 
void EnterAnnotationToken (SourceRange Range, tok::TokenKind Kind, void *AnnotationVal)
 Enter an annotation token into the token stream.
 
bool mightHavePendingAnnotationTokens ()
 Determine whether it's possible for a future call to Lex to produce an annotation token created by a previous call to EnterAnnotationToken.
 
void TypoCorrectToken (const Token &Tok)
 Update the current token to represent the provided identifier, in order to cache an action performed by typo correction.
 
void recomputeCurLexerKind ()
 Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.
 
bool isIncrementalProcessingEnabled () const
 Returns true if incremental processing is enabled.
 
void enableIncrementalProcessing (bool value=true)
 Enables the incremental processing.
 
bool SetCodeCompletionPoint (FileEntryRef File, unsigned Line, unsigned Column)
 Specify the point at which code-completion will be performed.
 
bool isCodeCompletionEnabled () const
 Determine if we are performing code completion.
 
SourceLocation getCodeCompletionLoc () const
 Returns the location of the code-completion point.
 
SourceLocation getCodeCompletionFileLoc () const
 Returns the start location of the file of code-completion point.
 
bool isCodeCompletionReached () const
 Returns true if code-completion is enabled and we have hit the code-completion point.
 
void setCodeCompletionReached ()
 Note that we hit the code-completion point.
 
std::pair< IdentifierInfo *, SourceLocationgetPragmaARCCFCodeAuditedInfo () const
 The location of the currently-active #pragma clang arc_cf_code_audited begin.
 
void setPragmaARCCFCodeAuditedInfo (IdentifierInfo *Ident, SourceLocation Loc)
 Set the location of the currently-active #pragma clang arc_cf_code_audited begin.
 
SourceLocation getPragmaAssumeNonNullLoc () const
 The location of the currently-active #pragma clang assume_nonnull begin.
 
void setPragmaAssumeNonNullLoc (SourceLocation Loc)
 Set the location of the currently-active #pragma clang assume_nonnull begin.
 
SourceLocation getPreambleRecordedPragmaAssumeNonNullLoc () const
 Get the location of the recorded unterminated #pragma clang assume_nonnull begin in the preamble, if one exists.
 
void setPreambleRecordedPragmaAssumeNonNullLoc (SourceLocation Loc)
 Record the location of the unterminated #pragma clang assume_nonnull begin in the preamble.
 
void setMainFileDir (DirectoryEntryRef Dir)
 Set the directory in which the main file should be considered to have been found, if it is not a real file.
 
void setSkipMainFilePreamble (unsigned Bytes, bool StartOfLine)
 Instruct the preprocessor to skip part of the main source file.
 
DiagnosticBuilder Diag (SourceLocation Loc, unsigned DiagID) const
 Forwarding function for diagnostics.
 
DiagnosticBuilder Diag (const Token &Tok, unsigned DiagID) const
 
StringRef getSpelling (SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
 Return the 'spelling' of the token at the given location; does not go up to the spelling location or down to the expansion location.
 
std::string getSpelling (const Token &Tok, bool *Invalid=nullptr) const
 Return the 'spelling' of the Tok token.
 
unsigned getSpelling (const Token &Tok, const char *&Buffer, bool *Invalid=nullptr) const
 Get the spelling of a token into a preallocated buffer, instead of as an std::string.
 
StringRef getSpelling (const Token &Tok, SmallVectorImpl< char > &Buffer, bool *Invalid=nullptr) const
 Get the spelling of a token into a SmallVector.
 
bool getRawToken (SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false)
 Relex the token at the specified location.
 
char getSpellingOfSingleCharacterNumericConstant (const Token &Tok, bool *Invalid=nullptr) const
 Given a Token Tok that is a numeric constant with length 1, return the character.
 
StringRef getImmediateMacroName (SourceLocation Loc)
 Retrieve the name of the immediate macro expansion.
 
void CreateString (StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
 Plop the specified string into a scratch buffer and set the specified token's location and length to it.
 
SourceLocation SplitToken (SourceLocation TokLoc, unsigned Length)
 Split the first Length characters out of the token starting at TokLoc and return a location pointing to the split token.
 
SourceLocation getLocForEndOfToken (SourceLocation Loc, unsigned Offset=0)
 Computes the source location just past the end of the token at this source location.
 
bool isAtStartOfMacroExpansion (SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
 Returns true if the given MacroID location points at the first token of the macro expansion.
 
bool isAtEndOfMacroExpansion (SourceLocation loc, SourceLocation *MacroEnd=nullptr) const
 Returns true if the given MacroID location points at the last token of the macro expansion.
 
void DumpToken (const Token &Tok, bool DumpFlags=false) const
 Print the token to stderr, used for debugging.
 
void DumpLocation (SourceLocation Loc) const
 
void DumpMacro (const MacroInfo &MI) const
 
void dumpMacroInfo (const IdentifierInfo *II)
 
SourceLocation AdvanceToTokenCharacter (SourceLocation TokStart, unsigned Char) const
 Given a location that specifies the start of a token, return a new location that specifies a character within the token.
 
void IncrementPasteCounter (bool isFast)
 Increment the counters for the number of token paste operations performed.
 
void PrintStats ()
 
size_t getTotalMemory () const
 
void HandleMicrosoftCommentPaste (Token &Tok)
 When the macro expander pastes together a comment (/##/) in Microsoft mode, this method handles updating the current state, returning the token on the next source line.
 
IdentifierInfoLookUpIdentifierInfo (Token &Identifier) const
 Given a tok::raw_identifier token, look up the identifier information for the token and install it into the token, updating the token kind accordingly.
 
void SetPoisonReason (IdentifierInfo *II, unsigned DiagID)
 Specifies the reason for poisoning an identifier.
 
void HandlePoisonedIdentifier (Token &Identifier)
 Display reason for poisoned identifier.
 
void MaybeHandlePoisonedIdentifier (Token &Identifier)
 
void PoisonSEHIdentifiers (bool Poison=true)
 
bool HandleIdentifier (Token &Identifier)
 Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo member.
 
bool HandleEndOfFile (Token &Result, bool isEndOfMacro=false)
 Callback invoked when the lexer hits the end of the current file.
 
bool HandleEndOfTokenLexer (Token &Result)
 Callback invoked when the current TokenLexer hits the end of its token stream.
 
void HandleDirective (Token &Result)
 Callback invoked when the lexer sees a # token at the start of a line.
 
SourceLocation CheckEndOfDirective (const char *DirType, bool EnableMacros=false)
 Ensure that the next token is a tok::eod token.
 
SourceRange DiscardUntilEndOfDirective ()
 Read and discard all tokens remaining on the current line until the tok::eod token is found.
 
bool SawDateOrTime () const
 Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
 
unsigned getCounterValue () const
 
void setCounterValue (unsigned V)
 
LangOptions::FPEvalMethodKind getCurrentFPEvalMethod () const
 
LangOptions::FPEvalMethodKind getTUFPEvalMethod () const
 
SourceLocation getLastFPEvalPragmaLocation () const
 
void setCurrentFPEvalMethod (SourceLocation PragmaLoc, LangOptions::FPEvalMethodKind Val)
 
void setTUFPEvalMethod (LangOptions::FPEvalMethodKind Val)
 
ModulegetCurrentModule ()
 Retrieves the module that we're currently building, if any.
 
ModulegetCurrentModuleImplementation ()
 Retrieves the module whose implementation we're current compiling, if any.
 
bool isInNamedModule () const
 If we are preprocessing a named module.
 
bool isInNamedInterfaceUnit () const
 If we are proprocessing a named interface unit.
 
StringRef getNamedModuleName () const
 Get the named module name we're preprocessing.
 
bool isInImplementationUnit () const
 If we are implementing an implementation module unit.
 
bool isInImportingCXXNamedModules () const
 If we're importing a standard C++20 Named Modules.
 
MacroInfoAllocateMacroInfo (SourceLocation L)
 Allocate a new MacroInfo object with the provided SourceLocation.
 
bool GetIncludeFilenameSpelling (SourceLocation Loc, StringRef &Buffer)
 Turn the specified lexer token into a fully checked and spelled filename, e.g.
 
OptionalFileEntryRef LookupFile (SourceLocation FilenameLoc, StringRef Filename, bool isAngled, ConstSearchDirIterator FromDir, const FileEntry *FromFile, ConstSearchDirIterator *CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache=false, bool OpenFile=true, bool CacheFailures=true)
 Given a "foo" or <foo> reference, look up the indicated file.
 
bool isInPrimaryFile () const
 Return true if we're in the top-level file, not in a #include.
 
bool LexOnOffSwitch (tok::OnOffSwitch &Result)
 Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.
 
bool CheckMacroName (Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag=nullptr)
 
void EnterSubmodule (Module *M, SourceLocation ImportLoc, bool ForPragma)
 
ModuleLeaveSubmodule (bool ForPragma)
 
ModulegetModuleForLocation (SourceLocation Loc, bool AllowTextual)
 Find the module that owns the source or header file that Loc points to.
 
OptionalFileEntryRef getHeaderToIncludeForDiagnostics (SourceLocation IncLoc, SourceLocation MLoc)
 We want to produce a diagnostic at location IncLoc concerning an unreachable effect at location MLoc (eg, where a desired entity was declared or defined).
 
bool isRecordingPreamble () const
 
bool hasRecordedPreamble () const
 
ArrayRef< PPConditionalInfogetPreambleConditionalStack () const
 
void setRecordedPreambleConditionalStack (ArrayRef< PPConditionalInfo > s)
 
void setReplayablePreambleConditionalStack (ArrayRef< PPConditionalInfo > s, std::optional< PreambleSkipInfo > SkipInfo)
 
std::optional< PreambleSkipInfogetPreambleSkipInfo () const
 
void HandlePragmaOnce (Token &OnceTok)
 HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
 
void HandlePragmaMark (Token &MarkTok)
 
void HandlePragmaPoison ()
 HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
 
void HandlePragmaSystemHeader (Token &SysHeaderTok)
 HandlePragmaSystemHeader - Implement #pragma GCC system_header.
 
void HandlePragmaDependency (Token &DependencyTok)
 HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
 
void HandlePragmaPushMacro (Token &Tok)
 Handle #pragma push_macro.
 
void HandlePragmaPopMacro (Token &Tok)
 Handle #pragma pop_macro.
 
void HandlePragmaIncludeAlias (Token &Tok)
 
void HandlePragmaModuleBuild (Token &Tok)
 
void HandlePragmaHdrstop (Token &Tok)
 
IdentifierInfoParsePragmaPushOrPopMacro (Token &Tok)
 ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.
 
bool HandleComment (Token &result, SourceRange Comment)
 
void markMacroAsUsed (MacroInfo *MI)
 A macro is used, update information about macros that need unused warnings.
 
void addMacroDeprecationMsg (const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
 
void addRestrictExpansionMsg (const IdentifierInfo *II, std::string Msg, SourceLocation AnnotationLoc)
 
void addFinalLoc (const IdentifierInfo *II, SourceLocation AnnotationLoc)
 
const MacroAnnotations & getMacroAnnotations (const IdentifierInfo *II) const
 
void emitMacroExpansionWarnings (const Token &Identifier, bool IsIfnDef=false) const
 
bool isSafeBufferOptOut (const SourceManager &SourceMgr, const SourceLocation &Loc) const
 
bool enterOrExitSafeBufferOptOutRegion (bool isEnter, const SourceLocation &Loc)
 Alter the state of whether this PP currently is in a "-Wunsafe-buffer-usage" opt-out region.
 
bool isPPInSafeBufferOptOutRegion ()
 
bool isPPInSafeBufferOptOutRegion (SourceLocation &StartLoc)
 
PPCallbacksgetPPCallbacks () const
 
void addPPCallbacks (std::unique_ptr< PPCallbacks > C)
 

Static Public Member Functions

static bool checkModuleIsAvailable (const LangOptions &LangOpts, const TargetInfo &TargetInfo, const Module &M, DiagnosticsEngine &Diags)
 Check that the given module is available, producing a diagnostic if not.
 
static void processPathForFileMacro (SmallVectorImpl< char > &Path, const LangOptions &LangOpts, const TargetInfo &TI)
 
static void processPathToFileName (SmallVectorImpl< char > &FileName, const PresumedLoc &PLoc, const LangOptions &LangOpts, const TargetInfo &TI)
 

Public Attributes

const TranslationUnitKind TUKind
 The kind of translation unit we are processing.
 

Friends

class VAOptDefinitionContext
 
class VariadicMacroScopeGuard
 
class ASTReader
 
class MacroArgs
 
void TokenLexer::ExpandFunctionArguments ()
 
using macro_iterator = MacroMap::const_iterator
 
macro_iterator macro_begin (bool IncludeExternalMacros=true) const
 
macro_iterator macro_end (bool IncludeExternalMacros=true) const
 
llvm::iterator_range< macro_iteratormacros (bool IncludeExternalMacros=true) const
 

Detailed Description

Engages in a tight little dance with the lexer to efficiently preprocess tokens.

Lexers know only about tokens within a single source file, and don't know anything about preprocessor-level issues like the #include stack, token expansion, etc.

Definition at line 128 of file Preprocessor.h.

Member Typedef Documentation

◆ IncludedFilesSet

Definition at line 689 of file Preprocessor.h.

◆ macro_iterator

using clang::Preprocessor::macro_iterator = MacroMap::const_iterator

Iterators for the macro history table. Currently defined macros have IdentifierInfo::hasMacroDefinition() set and an empty MacroInfo::getUndefLoc() at the head of the list.

Definition at line 1458 of file Preprocessor.h.

Constructor & Destructor Documentation

◆ Preprocessor()

Preprocessor::Preprocessor ( std::shared_ptr< PreprocessorOptions PPOpts,
DiagnosticsEngine diags,
const LangOptions LangOpts,
SourceManager SM,
HeaderSearch Headers,
ModuleLoader TheModuleLoader,
IdentifierInfoLookup IILookup = nullptr,
bool  OwnsHeaderSearch = false,
TranslationUnitKind  TUKind = TU_Complete 
)

◆ ~Preprocessor()

Preprocessor::~Preprocessor ( )

Definition at line 171 of file Preprocessor.cpp.

Member Function Documentation

◆ addCommentHandler()

void Preprocessor::addCommentHandler ( CommentHandler Handler)

Add the specified comment handler to the preprocessor.

Definition at line 1410 of file Preprocessor.cpp.

Referenced by clang::Parser::Parser(), and clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks().

◆ addFinalLoc()

void clang::Preprocessor::addFinalLoc ( const IdentifierInfo II,
SourceLocation  AnnotationLoc 
)
inline

Definition at line 2828 of file Preprocessor.h.

◆ addMacroDeprecationMsg()

void clang::Preprocessor::addMacroDeprecationMsg ( const IdentifierInfo II,
std::string  Msg,
SourceLocation  AnnotationLoc 
)
inline

Definition at line 2804 of file Preprocessor.h.

◆ addModuleMacro()

ModuleMacro * Preprocessor::addModuleMacro ( Module Mod,
IdentifierInfo II,
MacroInfo Macro,
ArrayRef< ModuleMacro * >  Overrides,
bool IsNew 
)

Register an exported macro for a module and identifier.

Definition at line 132 of file PPMacroExpansion.cpp.

References clang::ModuleMacro::create(), clang::ModuleMacro::Profile(), and clang::IdentifierInfo::setHasMacroDefinition().

Referenced by LeaveSubmodule().

◆ addPPCallbacks()

void clang::Preprocessor::addPPCallbacks ( std::unique_ptr< PPCallbacks C)
inline

◆ AddPragmaHandler() [1/2]

void clang::Preprocessor::AddPragmaHandler ( PragmaHandler Handler)
inline

Definition at line 1533 of file Preprocessor.h.

References AddPragmaHandler().

◆ AddPragmaHandler() [2/2]

void Preprocessor::AddPragmaHandler ( StringRef  Namespace,
PragmaHandler Handler 
)

Add the specified pragma handler to this preprocessor.

AddPragmaHandler - Add the specified pragma handler to the preprocessor.

If Namespace is non-null, then it is a token required to exist on the pragma line before the pragma string starts, e.g. "STDC" or "GCC".

If 'Namespace' is non-null, then it is a token required to exist on the pragma line before the pragma string starts, e.g. "STDC" or "GCC".

Definition at line 915 of file Pragma.cpp.

References clang::PragmaNamespace::AddPragma(), clang::PragmaNamespace::FindHandler(), clang::PragmaNamespace::getIfNamespace(), and clang::PragmaHandler::getName().

Referenced by AddPragmaHandler(), clang::DoPrintPreprocessedInput(), and IgnorePragmas().

◆ addRestrictExpansionMsg()

void clang::Preprocessor::addRestrictExpansionMsg ( const IdentifierInfo II,
std::string  Msg,
SourceLocation  AnnotationLoc 
)
inline

Definition at line 2816 of file Preprocessor.h.

◆ AdvanceToTokenCharacter()

SourceLocation clang::Preprocessor::AdvanceToTokenCharacter ( SourceLocation  TokStart,
unsigned  Char 
) const
inline

Given a location that specifies the start of a token, return a new location that specifies a character within the token.

Definition at line 2198 of file Preprocessor.h.

References clang::Lexer::AdvanceToTokenCharacter().

Referenced by GetLineValue().

◆ AllocateMacroInfo()

MacroInfo * Preprocessor::AllocateMacroInfo ( SourceLocation  L)

Allocate a new MacroInfo object with the provided SourceLocation.

Definition at line 62 of file PPDirectives.cpp.

Referenced by RegisterBuiltinMacro().

◆ alreadyIncluded()

bool clang::Preprocessor::alreadyIncluded ( FileEntryRef  File) const
inline

Return true if this header has already been included.

Definition at line 1497 of file Preprocessor.h.

References clang::File, and clang::HeaderSearch::getFileInfo().

Referenced by clang::HeaderSearch::ShouldEnterIncludeFile().

◆ AnnotateCachedTokens()

void clang::Preprocessor::AnnotateCachedTokens ( const Token Tok)
inline

We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should replace the most recent cached tokens with the given annotation token.

This function has no effect if backtracking is not enabled.

Note that the use of this function is just for optimization, so that the cached tokens doesn't get re-parsed and re-resolved after a backtrack is invoked.

Definition at line 1864 of file Preprocessor.h.

References clang::Token::isAnnotation(), and isBacktrackEnabled().

Referenced by clang::Parser::TryAnnotateTypeOrScopeToken(), and clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec().

◆ appendDefMacroDirective() [1/2]

DefMacroDirective * clang::Preprocessor::appendDefMacroDirective ( IdentifierInfo II,
MacroInfo MI 
)
inline

◆ appendDefMacroDirective() [2/2]

DefMacroDirective * clang::Preprocessor::appendDefMacroDirective ( IdentifierInfo II,
MacroInfo MI,
SourceLocation  Loc 
)
inline

◆ appendMacroDirective()

void Preprocessor::appendMacroDirective ( IdentifierInfo II,
MacroDirective MD 
)

◆ Backtrack()

void Preprocessor::Backtrack ( )

Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously called.

Definition at line 40 of file PPCaching.cpp.

References recomputeCurLexerKind().

◆ CheckEndOfDirective()

SourceLocation Preprocessor::CheckEndOfDirective ( const char *  DirType,
bool  EnableMacros = false 
)

Ensure that the next token is a tok::eod token.

If not, emit a diagnostic and consume up until the eod. If EnableMacros is true, then we consider macros that expand to zero tokens as being ok.

Returns
The location of the end of the directive (the terminating newline).

If not, emit a diagnostic and consume up until the eod. If EnableMacros is true, then we consider macros that expand to zero tokens as being ok.

Returns the location of the end of the directive.

Definition at line 415 of file PPDirectives.cpp.

References clang::FixItHint::CreateInsertion(), Diag(), DiscardUntilEndOfDirective(), clang::SourceRange::getEnd(), clang::Token::getLocation(), clang::Token::is(), Lex(), and LexUnexpandedToken().

◆ CheckMacroName()

bool Preprocessor::CheckMacroName ( Token MacroNameTok,
MacroUse  isDefineUndef,
bool ShadowFlag = nullptr 
)

◆ checkModuleIsAvailable()

bool Preprocessor::checkModuleIsAvailable ( const LangOptions LangOpts,
const TargetInfo TargetInfo,
const Module M,
DiagnosticsEngine Diags 
)
static

◆ clearCodeCompletionHandler()

void clang::Preprocessor::clearCodeCompletionHandler ( )
inline

Clear out the code completion handler.

Definition at line 1574 of file Preprocessor.h.

Referenced by clang::Parser::~Parser().

◆ CodeCompleteIncludedFile()

void Preprocessor::CodeCompleteIncludedFile ( llvm::StringRef  Dir,
bool  IsAngled 
)

Hook used by the lexer to invoke the "included file" code completion point.

Definition at line 452 of file Preprocessor.cpp.

References clang::CodeCompletionHandler::CodeCompleteIncludedFile(), and setCodeCompletionReached().

◆ CodeCompleteNaturalLanguage()

void Preprocessor::CodeCompleteNaturalLanguage ( )

Hook used by the lexer to invoke the "natural language" code completion point.

Definition at line 459 of file Preprocessor.cpp.

References clang::CodeCompletionHandler::CodeCompleteNaturalLanguage(), and setCodeCompletionReached().

Referenced by clang::Lexer::ReadToEndOfLine(), and clang::MacroArgs::StringifyArgument().

◆ CollectPpImportSuffix()

void Preprocessor::CollectPpImportSuffix ( SmallVectorImpl< Token > &  Toks)

Collect the tokens of a C++20 pp-import-suffix.

Definition at line 1089 of file Preprocessor.cpp.

References Lex().

Referenced by LexAfterModuleImport().

◆ CommitBacktrackedTokens()

void Preprocessor::CommitBacktrackedTokens ( )

Disable the last EnableBacktrackAtThisPos call.

Definition at line 32 of file PPCaching.cpp.

◆ createPreprocessingRecord()

void Preprocessor::createPreprocessingRecord ( )

Create a new preprocessing record, which will keep track of all macro expansions, macro definitions, etc.

Definition at line 1562 of file Preprocessor.cpp.

References addPPCallbacks(), and getSourceManager().

◆ CreateString()

void Preprocessor::CreateString ( StringRef  Str,
Token Tok,
SourceLocation  ExpansionLocStart = SourceLocation(),
SourceLocation  ExpansionLocEnd = SourceLocation() 
)

Plop the specified string into a scratch buffer and set the specified token's location and length to it.

CreateString - Plop the specified string into a scratch buffer and return a location for it.

If specified, the source location provides a location of the expansion point of the token.

If specified, the source location provides a source location for the token.

Definition at line 490 of file Preprocessor.cpp.

References clang::SourceManager::createExpansionLoc(), clang::Token::is(), clang::Token::isLiteral(), clang::SourceLocation::isValid(), clang::Token::setLength(), clang::Token::setLiteralData(), clang::Token::setLocation(), and clang::Token::setRawIdentifierData().

Referenced by ComputeDATE_TIME(), clang::Sema::ExpandFunctionLocalPredefinedMacros(), LexHeaderName(), ParsePragmaPushOrPopMacro(), and clang::MacroArgs::StringifyArgument().

◆ creatingPCHWithPragmaHdrStop()

bool Preprocessor::creatingPCHWithPragmaHdrStop ( )

True if creating a PCH with a #pragma hdrstop.

Definition at line 628 of file Preprocessor.cpp.

References clang::TU_Prefix, and TUKind.

Referenced by HandlePragmaHdrstop().

◆ creatingPCHWithThroughHeader()

bool Preprocessor::creatingPCHWithThroughHeader ( )

True if creating a PCH with a through header.

Definition at line 618 of file Preprocessor.cpp.

References clang::FileID::isValid(), clang::TU_Prefix, and TUKind.

Referenced by HandleEndOfFile().

◆ Diag() [1/2]

DiagnosticBuilder clang::Preprocessor::Diag ( const Token Tok,
unsigned  DiagID 
) const
inline

◆ Diag() [2/2]

DiagnosticBuilder clang::Preprocessor::Diag ( SourceLocation  Loc,
unsigned  DiagID 
) const
inline

◆ DiscardUntilEndOfDirective()

SourceRange Preprocessor::DiscardUntilEndOfDirective ( )

Read and discard all tokens remaining on the current line until the tok::eod token is found.

Returns the range of the skipped tokens.

Definition at line 85 of file PPDirectives.cpp.

References clang::Token::getLocation(), clang::Token::isNot(), LexUnexpandedToken(), clang::SourceRange::setBegin(), and clang::SourceRange::setEnd().

Referenced by CheckEndOfDirective(), GetLineValue(), HandleDirective(), HandlePragmaModuleBuild(), HandleSkippedDirectiveWhileUsingPCH(), and ReadLineMarkerFlags().

◆ DumpLocation()

void Preprocessor::DumpLocation ( SourceLocation  Loc) const

Definition at line 263 of file Preprocessor.cpp.

References clang::SourceLocation::print().

Referenced by DumpToken().

◆ DumpMacro()

void Preprocessor::DumpMacro ( const MacroInfo MI) const

◆ dumpMacroInfo()

void Preprocessor::dumpMacroInfo ( const IdentifierInfo II)

◆ DumpToken()

void Preprocessor::DumpToken ( const Token Tok,
bool  DumpFlags = false 
) const

◆ emitMacroExpansionWarnings()

void clang::Preprocessor::emitMacroExpansionWarnings ( const Token Identifier,
bool  IsIfnDef = false 
) const
inline

◆ EnableBacktrackAtThisPos()

void Preprocessor::EnableBacktrackAtThisPos ( )

From the point that this method is called, and until CommitBacktrackedTokens() or Backtrack() is called, the Preprocessor keeps track of the lexed tokens so that a subsequent Backtrack() call will make the Preprocessor re-lex the same tokens.

Nested backtracks are allowed, meaning that EnableBacktrackAtThisPos can be called multiple times and CommitBacktrackedTokens/Backtrack calls will be combined with the EnableBacktrackAtThisPos calls in reverse order.

NOTE: DO NOT forget to call either CommitBacktrackedTokens or Backtrack at some point after EnableBacktrackAtThisPos. If you don't, caching of tokens will continue indefinitely.

Definition at line 25 of file PPCaching.cpp.

◆ enableIncrementalProcessing()

void clang::Preprocessor::enableIncrementalProcessing ( bool  value = true)
inline

Enables the incremental processing.

Definition at line 1928 of file Preprocessor.h.

◆ EndSourceFile()

void Preprocessor::EndSourceFile ( )

Inform the preprocessor callbacks that processing is complete.

Definition at line 685 of file Preprocessor.cpp.

Referenced by clang::FrontendAction::EndSourceFile().

◆ EnterAnnotationToken()

void Preprocessor::EnterAnnotationToken ( SourceRange  Range,
tok::TokenKind  Kind,
void *  AnnotationVal 
)

Enter an annotation token into the token stream.

Push a token onto the token stream containing an annotation.

Definition at line 1804 of file PPDirectives.cpp.

References clang::Token::setAnnotationEndLoc(), clang::Token::setAnnotationValue(), clang::Token::setKind(), clang::Token::setLocation(), and clang::Token::startToken().

◆ EnterMacro()

void Preprocessor::EnterMacro ( Token Tok,
SourceLocation  ILEnd,
MacroInfo Macro,
MacroArgs Args 
)

Add a Macro to the top of the include stack and start lexing tokens from it instead of the current buffer.

EnterMacro - Add a Macro to the top of the include stack and start lexing tokens from it instead of the current buffer.

Parameters
Argsspecifies the tokens input to a function-like macro.
ILEndspecifies the location of the ')' for a function-like macro or the identifier for an object-like macro.

Definition at line 151 of file PPLexerChange.cpp.

◆ EnterMainSourceFile()

void Preprocessor::EnterMainSourceFile ( )

◆ enterOrExitSafeBufferOptOutRegion()

bool Preprocessor::enterOrExitSafeBufferOptOutRegion ( bool  isEnter,
const SourceLocation Loc 
)

Alter the state of whether this PP currently is in a "-Wunsafe-buffer-usage" opt-out region.

Parameters
isEntertrue if this PP is entering a region; otherwise, this PP is exiting a region
Locthe location of the entry or exit of a region
Returns
true iff it is INVALID to enter or exit a region, i.e., attempt to enter a region before exiting a previous region, or exiting a region that PP is not currently in.

Definition at line 1509 of file Preprocessor.cpp.

References isPPInSafeBufferOptOutRegion().

◆ EnterSourceFile()

bool Preprocessor::EnterSourceFile ( FileID  FID,
ConstSearchDirIterator  Dir,
SourceLocation  Loc,
bool  IsFirstIncludeOfFile = true 
)

Add a source file to the top of the include stack and start lexing tokens from it instead of the current buffer.

EnterSourceFile - Add a source file to the top of the include stack and start lexing tokens from it instead of the current buffer.

Emits a diagnostic, doesn't enter the file, and returns true on error.

Definition at line 69 of file PPLexerChange.cpp.

References Diag(), clang::File, clang::SourceManager::getBufferName(), clang::SourceManager::getBufferOrNone(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileEntryRefForID(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), getPreprocessorOpts(), getSourceManager(), and isCodeCompletionEnabled().

Referenced by EnterMainSourceFile(), and clang::IncrementalParser::Parse().

◆ EnterSubmodule()

void Preprocessor::EnterSubmodule ( Module M,
SourceLocation  ImportLoc,
bool  ForPragma 
)

◆ EnterToken()

void clang::Preprocessor::EnterToken ( const Token Tok,
bool  IsReinject 
)
inline

Enters a token in the token stream to be lexed next.

If BackTrack() is called afterwards, the token will remain at the insertion point. If IsReinject is true, resulting token will have Token::IsReinjected flag set. See the flag documentation for details.

Definition at line 1842 of file Preprocessor.h.

Referenced by FixDigraph(), and clang::Parser::TryAnnotateTypeOrScopeToken().

◆ EnterTokenStream() [1/2]

void clang::Preprocessor::EnterTokenStream ( ArrayRef< Token Toks,
bool  DisableMacroExpansion,
bool  IsReinject 
)
inline

Definition at line 1689 of file Preprocessor.h.

◆ EnterTokenStream() [2/2]

void clang::Preprocessor::EnterTokenStream ( std::unique_ptr< Token[]>  Toks,
unsigned  NumToks,
bool  DisableMacroExpansion,
bool  IsReinject 
)
inline

Definition at line 1683 of file Preprocessor.h.

◆ FinalizeForModelFile()

void Preprocessor::FinalizeForModelFile ( )

Cleanup after model file parsing.

Definition at line 231 of file Preprocessor.cpp.

◆ FinishLexStringLiteral()

bool Preprocessor::FinishLexStringLiteral ( Token Result,
std::string &  String,
const char *  DiagnosticTag,
bool  AllowMacroExpansion 
)

Complete the lexing of a string literal where the first token has already been lexed (see LexStringLiteral).

Definition at line 1349 of file Preprocessor.cpp.

References Diag(), Lex(), LexUnexpandedToken(), and clang::Result.

Referenced by LexStringLiteral().

◆ getAffectingClangModules()

const llvm::SmallSetVector< Module *, 2 > & clang::Preprocessor::getAffectingClangModules ( ) const
inline

Get the set of top-level clang modules that affected preprocessing, but were not imported.

Definition at line 1485 of file Preprocessor.h.

Referenced by clang::tooling::dependencies::ModuleDepCollectorPP::EndOfMainFile().

◆ getAuxTargetInfo()

const TargetInfo * clang::Preprocessor::getAuxTargetInfo ( ) const
inline

Definition at line 1207 of file Preprocessor.h.

Referenced by clang::InitializePreprocessor().

◆ getBuildingSubmodules()

ArrayRef< BuildingSubmoduleInfo > clang::Preprocessor::getBuildingSubmodules ( ) const
inline

Get the list of submodules that we're currently building.

Definition at line 1450 of file Preprocessor.h.

◆ getBuiltinInfo()

Builtin::Context & clang::Preprocessor::getBuiltinInfo ( )
inline

◆ getCheckPoint()

const char * Preprocessor::getCheckPoint ( FileID  FID,
const char *  Start 
) const

Returns a pointer into the given file's buffer that's guaranteed to be between tokens.

The returned pointer is always before Start. The maximum distance betweenthe returned pointer and Start is limited by a constant value, but also an implementation detail. If no such check point exists, nullptr is returned.

Definition at line 1570 of file Preprocessor.cpp.

References clang::Last, and P.

Referenced by highlightLines().

◆ getCodeCompletionFileLoc()

SourceLocation clang::Preprocessor::getCodeCompletionFileLoc ( ) const
inline

Returns the start location of the file of code-completion point.

Returns an invalid location if code-completion is not enabled or the file containing the code-completion point has not been lexed yet.

Definition at line 1962 of file Preprocessor.h.

◆ getCodeCompletionFilter()

StringRef clang::Preprocessor::getCodeCompletionFilter ( )
inline

Get the code completion token for filtering purposes.

Definition at line 1602 of file Preprocessor.h.

Referenced by clang::PrintingCodeCompleteConsumer::ProcessCodeCompleteResults().

◆ getCodeCompletionHandler()

CodeCompletionHandler * clang::Preprocessor::getCodeCompletionHandler ( ) const
inline

Retrieve the current code-completion handler.

Definition at line 1569 of file Preprocessor.h.

Referenced by EvaluateDefined(), and EvaluateValue().

◆ getCodeCompletionLoc()

SourceLocation clang::Preprocessor::getCodeCompletionLoc ( ) const
inline

Returns the location of the code-completion point.

Returns an invalid location if code-completion is not enabled or the file containing the code-completion point has not been lexed yet.

Definition at line 1956 of file Preprocessor.h.

◆ getCodeCompletionTokenRange()

SourceRange clang::Preprocessor::getCodeCompletionTokenRange ( ) const
inline

Definition at line 1597 of file Preprocessor.h.

◆ getCommentRetentionState()

bool clang::Preprocessor::getCommentRetentionState ( ) const
inline

◆ getCounterValue()

unsigned clang::Preprocessor::getCounterValue ( ) const
inline

Definition at line 2323 of file Preprocessor.h.

◆ getCurrentFileLexer()

PreprocessorLexer * Preprocessor::getCurrentFileLexer ( ) const

Return the current file lexer being lexed from.

getCurrentLexer - Return the current file lexer being lexed from.

Note that this ignores any potentially active macro expansions and _Pragma expansions going on at the time.

Definition at line 50 of file PPLexerChange.cpp.

Referenced by HandlePragmaDependency(), HandlePragmaOnce(), HandlePragmaSystemHeader(), and LookupFile().

◆ getCurrentFPEvalMethod()

LangOptions::FPEvalMethodKind clang::Preprocessor::getCurrentFPEvalMethod ( ) const
inline

◆ getCurrentLexer()

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

Return the current lexer being lexed from.

Note that this ignores any potentially active macro expansions and _Pragma expansions going on at the time.

Definition at line 1282 of file Preprocessor.h.

Referenced by clang::ParseAST().

◆ getCurrentLexerSubmodule()

Module * clang::Preprocessor::getCurrentLexerSubmodule ( ) const
inline

Return the submodule owning the file being lexed.

This may not be the current module if we have changed modules since entering the file.

Definition at line 1292 of file Preprocessor.h.

◆ getCurrentModule()

Module * Preprocessor::getCurrentModule ( )

◆ getCurrentModuleImplementation()

Module * Preprocessor::getCurrentModuleImplementation ( )

Retrieves the module whose implementation we're current compiling, if any.

Definition at line 533 of file Preprocessor.cpp.

References getHeaderSearchInfo(), getLangOpts(), and clang::HeaderSearch::lookupModule().

Referenced by clang::tooling::dependencies::ModuleDepCollector::applyDiscoveredDependencies(), and clang::FrontendAction::BeginSourceFile().

◆ getDiagnostics()

DiagnosticsEngine & clang::Preprocessor::getDiagnostics ( ) const
inline

◆ getEmptylineHandler()

EmptylineHandler * clang::Preprocessor::getEmptylineHandler ( ) const
inline

Definition at line 1553 of file Preprocessor.h.

◆ getExternalSource()

ExternalPreprocessorSource * clang::Preprocessor::getExternalSource ( ) const
inline

Definition at line 1222 of file Preprocessor.h.

Referenced by isTrivialSingleTokenExpansion().

◆ getFileManager()

FileManager & clang::Preprocessor::getFileManager ( ) const
inline

◆ getHeaderSearchInfo()

HeaderSearch & clang::Preprocessor::getHeaderSearchInfo ( ) const
inline

◆ getHeaderToIncludeForDiagnostics()

OptionalFileEntryRef Preprocessor::getHeaderToIncludeForDiagnostics ( SourceLocation  IncLoc,
SourceLocation  MLoc 
)

We want to produce a diagnostic at location IncLoc concerning an unreachable effect at location MLoc (eg, where a desired entity was declared or defined).

Determine whether the right way to make MLoc reachable is by #include, and if so, what header should be included.

This is not necessarily fast, and might load unexpected module maps, so should only be called by code that intends to produce an error.

Parameters
IncLocThe location at which the missing effect was detected.
MLocA location within an unimported module at which the desired effect occurred.
Returns
A file that can be #included to provide the desired effect. Null if no such file could be determined or if a #include is not appropriate (eg, if a module should be imported instead).

Definition at line 881 of file PPDirectives.cpp.

References clang::ModuleMap::ExcludedHeader, clang::HeaderSearch::findAllModulesForHeader(), getHeaderSearchInfo(), getLangOpts(), getModuleForLocation(), getSourceManager(), clang::HeaderSearch::hasModuleMap(), clang::SourceManager::isInSystemHeader(), clang::SourceLocation::isInvalid(), clang::ObjC, SM, and clang::ModuleMap::TextualHeader.

Referenced by clang::Sema::diagnoseMissingImport().

◆ getIdentifierInfo()

IdentifierInfo * clang::Preprocessor::getIdentifierInfo ( StringRef  Name) const
inline

◆ getIdentifierTable() [1/2]

IdentifierTable & clang::Preprocessor::getIdentifierTable ( )
inline

◆ getIdentifierTable() [2/2]

const IdentifierTable & clang::Preprocessor::getIdentifierTable ( ) const
inline

Definition at line 1213 of file Preprocessor.h.

◆ getImmediateMacroName()

StringRef clang::Preprocessor::getImmediateMacroName ( SourceLocation  Loc)
inline

Retrieve the name of the immediate macro expansion.

This routine starts from a source location, and finds the name of the macro responsible for its immediate expansion. It looks through any intervening macro argument expansions to compute this. It returns a StringRef that refers to the SourceManager-owned buffer of the source where that macro name is spelled. Thus, the result shouldn't out-live the SourceManager.

Definition at line 2132 of file Preprocessor.h.

References clang::Lexer::getImmediateMacroName(), and getLangOpts().

Referenced by isExpandedFromConfigurationMacro(), lookThroughRangesV3Condition(), and ShouldDiagnoseAvailabilityInContext().

◆ getIncludedFiles() [1/2]

IncludedFilesSet & clang::Preprocessor::getIncludedFiles ( )
inline

Get the set of included files.

Definition at line 1503 of file Preprocessor.h.

◆ getIncludedFiles() [2/2]

const IncludedFilesSet & clang::Preprocessor::getIncludedFiles ( ) const
inline

Definition at line 1504 of file Preprocessor.h.

◆ GetIncludeFilenameSpelling()

bool Preprocessor::GetIncludeFilenameSpelling ( SourceLocation  Loc,
StringRef &  Buffer 
)

Turn the specified lexer token into a fully checked and spelled filename, e.g.

GetIncludeFilenameSpelling - Turn the specified lexer token into a fully checked and spelled filename, e.g.

as an operand of #include.

The caller is expected to provide a buffer that is large enough to hold the spelling of the filename, but is also expected to handle the case when this method decides to use a different buffer.

Returns
true if the input filename was in <>'s or false if it was in ""'s.

as an operand of #include. This returns true if the input filename was in <>'s or false if it were in ""'s. The caller is expected to provide a buffer that is large enough to hold the spelling of the filename, but is also expected to handle the case when this method decides to use a different buffer.

Definition at line 1756 of file PPDirectives.cpp.

References Diag().

Referenced by EvaluateHasIncludeCommon(), HandlePragmaDependency(), and HandlePragmaIncludeAlias().

◆ getLangOpts()

const LangOptions & clang::Preprocessor::getLangOpts ( ) const
inline

Definition at line 1205 of file Preprocessor.h.

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), clang::Sema::ActOnNumericConstant(), AddFunctionParameterChunks(), AddMacroResults(), clang::TokenConcatenation::AvoidConcat(), clang::FrontendAction::BeginSourceFile(), clang::CharLiteralParser::CharLiteralParser(), clang::Sema::checkLiteralOperatorId(), CheckMacroName(), clang::createChainedIncludesSource(), clang::DoPrintPreprocessedInput(), clang::DoRewriteTest(), EmitAlphaCounter(), emitMacroExpansionWarnings(), emitPremigrationErrors(), EnterSubmodule(), EvaluateDirectiveSubExpr(), EvaluateValue(), clang::DumpRawTokensAction::ExecuteAction(), FindLocsWithCommonFileID(), getCurrentModule(), getCurrentModuleImplementation(), clang::PCHGenerator::getEmittingModule(), getFallthroughAttrSpelling(), getHeaderToIncludeForDiagnostics(), getImmediateMacroName(), getIssueHash(), clang::Parser::getLangOpts(), getModuleForLocation(), HandleDirective(), HandleEndOfFile(), HandleIdentifier(), HandlePragmaOnce(), HasExtension(), HasFeature(), Initialize(), clang::InitializePreprocessor(), isExpandedFromConfigurationMacro(), isInImportingCXXNamedModules(), isInterestingIdentifier(), isMacroDefined(), LeaveSubmodule(), Lex(), clang::TokenLexer::Lex(), LexAfterModuleImport(), LexRawTokensFromMainFile(), clang::ASTUnit::LoadFromASTFile(), MaybeAddSentinel(), clang::IncrementalParser::Parse(), ParseAlignPragma(), parseSimpleIntegerLiteral(), PrintPreprocessedTokens(), clang::PCHValidator::ReadHeaderSearchOptions(), clang::PCHValidator::ReadLanguageOptions(), clang::PCHValidator::ReadPreprocessorOptions(), clang::SimpleASTReaderListener::ReadPreprocessorOptions(), clang::RewriteMacrosInInput(), shouldWarnOnMacroDef(), shouldWarnOnMacroUndef(), and clang::TokenConcatenation::TokenConcatenation().

◆ getLastCachedTokenLocation()

SourceLocation clang::Preprocessor::getLastCachedTokenLocation ( ) const
inline

Get the location of the last cached token, suitable for setting the end location of an annotation token.

Definition at line 1872 of file Preprocessor.h.

Referenced by IsPreviousCachedToken().

◆ getLastFPEvalPragmaLocation()

SourceLocation clang::Preprocessor::getLastFPEvalPragmaLocation ( ) const
inline

◆ getLastMacroWithSpelling()

StringRef Preprocessor::getLastMacroWithSpelling ( SourceLocation  Loc,
ArrayRef< TokenValue Tokens 
) const

◆ getLeafModuleMacros()

ArrayRef< ModuleMacro * > clang::Preprocessor::getLeafModuleMacros ( const IdentifierInfo II) const
inline

Get the list of leaf (non-overridden) module macros for a name.

Definition at line 1440 of file Preprocessor.h.

References clang::IdentifierInfo::isOutOfDate().

Referenced by indexPreprocessorModuleMacros().

◆ getLocalMacroDirective()

MacroDirective * clang::Preprocessor::getLocalMacroDirective ( const IdentifierInfo II) const
inline

Given an identifier, return its latest non-imported MacroDirective if it is #define'd and not #undef'd, or null if it isn't #define'd.

Definition at line 1387 of file Preprocessor.h.

References getLocalMacroDirectiveHistory(), and clang::IdentifierInfo::hasMacroDefinition().

◆ getLocalMacroDirectiveHistory()

MacroDirective * Preprocessor::getLocalMacroDirectiveHistory ( const IdentifierInfo II) const

Given an identifier, return the latest non-imported macro directive for that identifier.

One can iterate over all previous macro directives from the most recent one.

Definition at line 63 of file PPMacroExpansion.cpp.

References clang::IdentifierInfo::hadMacroDefinition().

Referenced by checkConfigMacro(), and getLocalMacroDirective().

◆ getLocForEndOfToken()

SourceLocation clang::Preprocessor::getLocForEndOfToken ( SourceLocation  Loc,
unsigned  Offset = 0 
)
inline

Computes the source location just past the end of the token at this source location.

This routine can be used to produce a source location that points just past the end of the token referenced by Loc, and is generally used when a diagnostic needs to point just after a token where it expected something different that it received. If the returned source location would not be meaningful (e.g., if it points into a macro), this routine returns an invalid source location.

Parameters
Offsetan offset from the end of the token, where the source location should refer to. The default offset (0) produces a source location pointing just past the end of the token; an offset of 1 produces a source location pointing to the last character in the token, etc.

Definition at line 2165 of file Preprocessor.h.

References clang::Lexer::getLocForEndOfToken().

Referenced by clang::Sema::CheckCompleteVariableDeclaration(), clang::Sema::DiagnoseCommaOperator(), EvaluateHasIncludeCommon(), GenerateNewArgTokens(), clang::Parser::getEndOfPreviousToken(), and clang::Parser::ParseConstraintLogicalAndExpression().

◆ getMacroAnnotations()

const MacroAnnotations & clang::Preprocessor::getMacroAnnotations ( const IdentifierInfo II) const
inline

Definition at line 2837 of file Preprocessor.h.

◆ getMacroDefinition()

MacroDefinition clang::Preprocessor::getMacroDefinition ( const IdentifierInfo II)
inline

◆ getMacroDefinitionAtLoc()

MacroDefinition clang::Preprocessor::getMacroDefinitionAtLoc ( const IdentifierInfo II,
SourceLocation  Loc 
)
inline

◆ getMacroInfo() [1/2]

MacroInfo * clang::Preprocessor::getMacroInfo ( const IdentifierInfo II)
inline

◆ getMacroInfo() [2/2]

const MacroInfo * clang::Preprocessor::getMacroInfo ( const IdentifierInfo II) const
inline

◆ getMaxTokens()

unsigned clang::Preprocessor::getMaxTokens ( ) const
inline

Get the max number of tokens before issuing a -Wmax-tokens warning.

Definition at line 1315 of file Preprocessor.h.

Referenced by clang::Parser::ParseTopLevelDecl().

◆ getMaxTokensOverrideLoc()

SourceLocation clang::Preprocessor::getMaxTokensOverrideLoc ( ) const
inline

Definition at line 1322 of file Preprocessor.h.

Referenced by clang::Parser::ParseTopLevelDecl().

◆ getModuleForLocation()

Module * Preprocessor::getModuleForLocation ( SourceLocation  Loc,
bool  AllowTextual 
)

◆ getModuleImportLoc()

SourceLocation clang::Preprocessor::getModuleImportLoc ( Module M) const
inline

Definition at line 1741 of file Preprocessor.h.

◆ getModuleLoader()

ModuleLoader & clang::Preprocessor::getModuleLoader ( ) const
inline

Retrieve the module loader associated with this preprocessor.

Definition at line 1227 of file Preprocessor.h.

Referenced by clang::Sema::getModuleLoader(), and clang::PCHGenerator::HandleTranslationUnit().

◆ getModuleMacro()

ModuleMacro * Preprocessor::getModuleMacro ( Module Mod,
const IdentifierInfo II 
)

Definition at line 171 of file PPMacroExpansion.cpp.

References clang::ModuleMacro::Profile().

◆ getNamedModuleName()

StringRef clang::Preprocessor::getNamedModuleName ( ) const
inline

Get the named module name we're preprocessing.

Requires we're preprocessing a named module.

Definition at line 2377 of file Preprocessor.h.

◆ getNumDirectives()

unsigned clang::Preprocessor::getNumDirectives ( ) const
inline

Retrieve the number of Directives that have been processed by the Preprocessor.

Definition at line 1235 of file Preprocessor.h.

◆ getPPCallbacks()

PPCallbacks * clang::Preprocessor::getPPCallbacks ( ) const
inline

Accessors for preprocessor callbacks.

Note that this class takes ownership of any PPCallbacks object given to it.

Definition at line 1302 of file Preprocessor.h.

Referenced by EvaluateDefined(), and EvaluateHasIncludeCommon().

◆ getPragmaARCCFCodeAuditedInfo()

std::pair< IdentifierInfo *, SourceLocation > clang::Preprocessor::getPragmaARCCFCodeAuditedInfo ( ) const
inline

The location of the currently-active #pragma clang arc_cf_code_audited begin.

Returns an invalid location if there is no such pragma active.

Definition at line 1983 of file Preprocessor.h.

Referenced by clang::Sema::AddCFAuditedAttribute().

◆ getPragmaAssumeNonNullLoc()

SourceLocation clang::Preprocessor::getPragmaAssumeNonNullLoc ( ) const
inline

The location of the currently-active #pragma clang assume_nonnull begin.

Returns an invalid location if there is no such pragma active.

Definition at line 1998 of file Preprocessor.h.

Referenced by GetFullTypeForDeclarator().

◆ getPragmasEnabled()

bool clang::Preprocessor::getPragmasEnabled ( ) const
inline

Definition at line 1253 of file Preprocessor.h.

◆ getPreambleConditionalStack()

ArrayRef< PPConditionalInfo > clang::Preprocessor::getPreambleConditionalStack ( ) const
inline

Definition at line 2742 of file Preprocessor.h.

◆ getPreambleRecordedPragmaAssumeNonNullLoc()

SourceLocation clang::Preprocessor::getPreambleRecordedPragmaAssumeNonNullLoc ( ) const
inline

Get the location of the recorded unterminated #pragma clang assume_nonnull begin in the preamble, if one exists.

Returns an invalid location if the premable did not end with such a pragma active or if there is no recorded preamble.

Definition at line 2013 of file Preprocessor.h.

◆ getPreambleSkipInfo()

std::optional< PreambleSkipInfo > clang::Preprocessor::getPreambleSkipInfo ( ) const
inline

Definition at line 2757 of file Preprocessor.h.

◆ getPredefines()

const std::string & clang::Preprocessor::getPredefines ( ) const
inline

Get the predefines for this processor.

Used by some third-party tools to inspect and add predefines (see https://github.com/llvm/llvm-project/issues/57483).

Definition at line 1515 of file Preprocessor.h.

◆ getPredefinesFileID()

FileID clang::Preprocessor::getPredefinesFileID ( ) const
inline

Returns the FileID for the preprocessor predefines.

Definition at line 1295 of file Preprocessor.h.

Referenced by checkConfigMacro(), HandleDirective(), HandleEndOfFile(), clang::RewriteIncludesInInput(), shouldIgnoreMacro(), and SkipTokensWhileUsingPCH().

◆ getPreprocessingRecord()

PreprocessingRecord * clang::Preprocessor::getPreprocessingRecord ( ) const
inline

Retrieve the preprocessing record, or NULL if there is no preprocessing record.

Definition at line 1610 of file Preprocessor.h.

Referenced by clang::ASTUnit::getLocalPreprocessingEntities().

◆ getPreprocessorAllocator()

llvm::BumpPtrAllocator & clang::Preprocessor::getPreprocessorAllocator ( )
inline

◆ getPreprocessorOpts()

PreprocessorOptions & clang::Preprocessor::getPreprocessorOpts ( ) const
inline

◆ getRawToken()

bool clang::Preprocessor::getRawToken ( SourceLocation  Loc,
Token Result,
bool  IgnoreWhiteSpace = false 
)
inline

Relex the token at the specified location.

Returns
true if there was a failure, false on success.

Definition at line 2101 of file Preprocessor.h.

References clang::Lexer::getRawToken(), and clang::Result.

Referenced by UseNSOptionsMacro().

◆ getSelectorTable()

SelectorTable & clang::Preprocessor::getSelectorTable ( )
inline

◆ getSourceManager()

SourceManager & clang::Preprocessor::getSourceManager ( ) const
inline

Definition at line 1209 of file Preprocessor.h.

Referenced by clang::Sema::ActOnNumericConstant(), AddFunctionParameterChunks(), clang::ModuleDependencyCollector::attachToPreprocessor(), clang::TokenConcatenation::AvoidConcat(), clang::VerifyDiagnosticConsumer::BeginSourceFile(), clang::CharLiteralParser::CharLiteralParser(), checkConfigMacro(), clang::Sema::checkLiteralOperatorId(), clang::Lexer::Create_PragmaLexer(), clang::CompilerInstance::createASTContext(), createPreprocessingRecord(), clang::DoPrintPreprocessedInput(), clang::DoRewriteTest(), emitPremigrationErrors(), EnterSourceFile(), EvaluateDefined(), EvaluateValue(), clang::PrintDependencyDirectivesSourceMinimizerAction::ExecuteAction(), clang::DumpRawTokensAction::ExecuteAction(), FindLocsWithCommonFileID(), clang::PreprocessorLexer::getFileEntry(), GetFirstChar(), getHeaderToIncludeForDiagnostics(), getIssueHash(), getMacroDefinitionAtLoc(), GetMappedTokenLoc(), clang::VerifyDiagnosticConsumer::HandleComment(), clang::TokenLexer::Init(), isExpandedFromConfigurationMacro(), IsPreviousCachedToken(), clang::TokenLexer::Lex(), LexRawTokensFromMainFile(), parseSimpleIntegerLiteral(), clang::PreprocessorLexer::PreprocessorLexer(), ReadLineMarkerFlags(), clang::MacroExpansionContext::registerForPreprocessor(), clang::RewriteIncludesInInput(), clang::RewriteMacrosInInput(), clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks(), shouldIgnoreMacro(), SplitToken(), and clang::syntax::TokenCollector::TokenCollector().

◆ getSpelling() [1/4]

std::string clang::Preprocessor::getSpelling ( const Token Tok,
bool Invalid = nullptr 
) const
inline

Return the 'spelling' of the Tok token.

The spelling of a token is the characters used to represent the token in the source file after trigraph expansion and escaped-newline folding. In particular, this wants to get the true, uncanonicalized, spelling of things like digraphs, UCNs, etc.

Parameters
InvalidIf non-null, will be set true if an error occurs.

Definition at line 2070 of file Preprocessor.h.

References clang::Lexer::getSpelling(), and clang::Invalid.

◆ getSpelling() [2/4]

unsigned clang::Preprocessor::getSpelling ( const Token Tok,
const char *&  Buffer,
bool Invalid = nullptr 
) const
inline

Get the spelling of a token into a preallocated buffer, instead of as an std::string.

The caller is required to allocate enough space for the token, which is guaranteed to be at least Tok.getLength() bytes long. The length of the actual result is returned.

Note that this method may do two possible things: it may either fill in the buffer specified with characters, or it may change the input pointer to point to a constant buffer with the data already in it (avoiding a copy). The caller is not allowed to modify the returned buffer pointer if an internal buffer is returned.

Definition at line 2086 of file Preprocessor.h.

References clang::Lexer::getSpelling(), and clang::Invalid.

◆ getSpelling() [3/4]

StringRef Preprocessor::getSpelling ( const Token Tok,
SmallVectorImpl< char > &  Buffer,
bool Invalid = nullptr 
) const

Get the spelling of a token into a SmallVector.

getSpelling - This method is used to get the spelling of a token into a SmallVector.

Note that the returned StringRef may not point to the supplied buffer if a copy can be avoided.

Definition at line 468 of file Preprocessor.cpp.

References clang::Token::getIdentifierInfo(), clang::Token::getLength(), getSpelling(), clang::Token::hasUCN(), clang::Invalid, clang::Token::isNot(), and clang::Token::needsCleaning().

◆ getSpelling() [4/4]

StringRef clang::Preprocessor::getSpelling ( SourceLocation  loc,
SmallVectorImpl< char > &  buffer,
bool invalid = nullptr 
) const
inline

Return the 'spelling' of the token at the given location; does not go up to the spelling location or down to the expansion location.

Parameters
bufferA buffer which will be used only if the token requires "cleaning", e.g. if it contains trigraphs or escaped newlines
invalidIf non-null, will be set true if an error occurs.

Definition at line 2056 of file Preprocessor.h.

References clang::Lexer::getSpelling().

Referenced by clang::Sema::ActOnCharacterConstant(), clang::Sema::ActOnNumericConstant(), buildMSAsmString(), clang::DoRewriteTest(), DumpToken(), dumpTokenInto(), EvaluateHasIncludeCommon(), EvaluateValue(), GetFirstChar(), GetLineValue(), getSpelling(), HandlePragmaDependency(), HandlePragmaIncludeAlias(), clang::MacroInfo::isIdenticalTo(), isMapModifier(), isMapType(), LexHeaderName(), LookUpIdentifierInfo(), clang::Parser::ParseOpenMPVarList(), ParsePragmaPushOrPopMacro(), parseSimpleIntegerLiteral(), PrintMacroDefinition(), PrintPreprocessedTokens(), clang::RewriteMacrosInInput(), and clang::MacroArgs::StringifyArgument().

◆ getSpellingOfSingleCharacterNumericConstant()

char clang::Preprocessor::getSpellingOfSingleCharacterNumericConstant ( const Token Tok,
bool Invalid = nullptr 
) const
inline

Given a Token Tok that is a numeric constant with length 1, return the character.

Definition at line 2109 of file Preprocessor.h.

References clang::Token::getLength(), clang::Token::getLiteralData(), clang::Token::getLocation(), clang::Invalid, clang::Token::is(), and clang::Token::needsCleaning().

Referenced by clang::Sema::ActOnNumericConstant().

◆ GetSuppressIncludeNotFoundError()

bool clang::Preprocessor::GetSuppressIncludeNotFoundError ( )
inline

Definition at line 1259 of file Preprocessor.h.

◆ getTargetInfo()

const TargetInfo & clang::Preprocessor::getTargetInfo ( ) const
inline

◆ getTokenCount()

unsigned clang::Preprocessor::getTokenCount ( ) const
inline

Get the number of tokens processed so far.

Definition at line 1312 of file Preprocessor.h.

Referenced by clang::Parser::ParseTopLevelDecl().

◆ getTotalMemory()

size_t Preprocessor::getTotalMemory ( ) const

Definition at line 329 of file Preprocessor.cpp.

Referenced by PrintStats().

◆ getTUFPEvalMethod()

LangOptions::FPEvalMethodKind clang::Preprocessor::getTUFPEvalMethod ( ) const
inline

Definition at line 2333 of file Preprocessor.h.

◆ hadModuleLoaderFatalFailure()

bool clang::Preprocessor::hadModuleLoaderFatalFailure ( ) const
inline

Definition at line 1229 of file Preprocessor.h.

References clang::ModuleLoader::HadFatalFailure.

◆ HandleComment()

bool Preprocessor::HandleComment ( Token result,
SourceRange  Comment 
)

Definition at line 1424 of file Preprocessor.cpp.

References getCommentRetentionState(), and Lex().

◆ HandleDirective()

void Preprocessor::HandleDirective ( Token Result)

◆ HandleEndOfFile()

bool Preprocessor::HandleEndOfFile ( Token Result,
bool  isEndOfMacro = false 
)

Callback invoked when the lexer hits the end of the current file.

HandleEndOfFile - This callback is invoked when the lexer hits the end of the current file.

This either returns the EOF token and returns true, or pops a level off the include stack and returns false, at which point the client should call lex again.

This either returns the EOF token or pops a level off the include stack and keeps going.

Definition at line 332 of file PPLexerChange.cpp.

References collectAllSubModulesWithUmbrellaHeader(), clang::FixItHint::CreateReplacement(), creatingPCHWithThroughHeader(), Diag(), clang::PPCallbacks::ExitFile, clang::MultipleIncludeOpt::GetControllingMacroAtEndOfFile(), getCurrentModule(), clang::MultipleIncludeOpt::GetDefinedLocation(), clang::MultipleIncludeOpt::GetDefinedMacro(), clang::SourceManager::getFileCharacteristic(), clang::PreprocessorLexer::getFileEntry(), clang::SourceManager::getFileEntryForID(), clang::PreprocessorLexer::getFileID(), clang::SourceManager::getIncludeLoc(), clang::PreprocessorLexer::getInitialNumSLocEntries(), getLangOpts(), clang::SourceManager::getLocForStartOfFile(), getMacroInfo(), clang::MultipleIncludeOpt::GetMacroLocation(), getPredefinesFileID(), clang::PreprocessorLexer::getSourceLocation(), isCodeCompletionEnabled(), isIncrementalProcessingEnabled(), isInPrimaryFile(), isMacroDefined(), isPCHThroughHeader(), isPPInSafeBufferOptOutRegion(), isRecordingPreamble(), clang::FileID::isValid(), clang::SourceLocation::isValid(), LeaveSubmodule(), clang::SourceManager::local_sloc_entry_size(), clang::PreprocessorLexer::MIOpt, recomputeCurLexerKind(), RemoveTopOfLexerStack(), clang::Result, clang::HeaderSearch::SetFileControllingMacro(), clang::SourceManager::setNumCreatedFIDsForFileID(), clang::TU_Complete, and TUKind.

Referenced by HandleEndOfTokenLexer().

◆ HandleEndOfTokenLexer()

bool Preprocessor::HandleEndOfTokenLexer ( Token Result)

Callback invoked when the current TokenLexer hits the end of its token stream.

HandleEndOfTokenLexer - This callback is invoked when the current TokenLexer hits the end of its token stream.

Definition at line 602 of file PPLexerChange.cpp.

References HandleEndOfFile(), and clang::Result.

Referenced by HandleMicrosoftCommentPaste(), and clang::TokenLexer::Lex().

◆ HandleIdentifier()

bool Preprocessor::HandleIdentifier ( Token Identifier)

Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo member.

HandleIdentifier - This callback is invoked when the lexer reads an identifier.

This callback potentially macro expands it or turns it into a named token (like 'for').

Returns
true if we actually computed a token, false if we need to lex again.

This callback looks up the identifier in the map and/or potentially macro expands it or turns it into a named token (like 'for').

Note that callers of this method are guarded by checking the IdentifierInfo's 'isHandleIdentifierCase' bit. If this method changes, the IdentifierInfo methods that compute these properties will need to change to match.

Definition at line 775 of file Preprocessor.cpp.

References Diag(), clang::Token::DisableExpand, getIdentifierTable(), getLangOpts(), getMacroDefinition(), clang::IdentifierInfo::getName(), clang::IdentifierInfo::getTokenID(), HandlePoisonedIdentifier(), Identifier, clang::IdentifierInfo::isExtensionToken(), clang::IdentifierInfo::isFutureCompatKeyword(), clang::IdentifierInfo::isModulesImport(), clang::IdentifierInfo::isOutOfDate(), clang::IdentifierInfo::isPoisoned(), clang::IdentifierInfo::setIsFutureCompatKeyword(), and clang::IdentifierInfo::setIsPoisoned().

Referenced by clang::TokenLexer::Lex().

◆ HandleMicrosoftCommentPaste()

void Preprocessor::HandleMicrosoftCommentPaste ( Token Tok)

When the macro expander pastes together a comment (/##/) in Microsoft mode, this method handles updating the current state, returning the token on the next source line.

HandleMicrosoftCommentPaste - When the macro expander pastes together a comment (/##/) in microsoft mode, this method handles updating the current state, returning the token on the next source line.

Definition at line 640 of file PPLexerChange.cpp.

References HandleEndOfTokenLexer(), clang::Token::is(), clang::Token::isNot(), Lex(), clang::PreprocessorLexer::LexingRawMode, and clang::PreprocessorLexer::ParsingPreprocessorDirective.

◆ HandlePoisonedIdentifier()

void Preprocessor::HandlePoisonedIdentifier ( Token Identifier)

Display reason for poisoned identifier.

Definition at line 751 of file Preprocessor.cpp.

References Diag(), and Identifier.

Referenced by HandleIdentifier(), clang::TokenLexer::Lex(), and MaybeHandlePoisonedIdentifier().

◆ HandlePragmaDependency()

void Preprocessor::HandlePragmaDependency ( Token DependencyTok)

◆ HandlePragmaHdrstop()

void Preprocessor::HandlePragmaHdrstop ( Token Tok)

◆ HandlePragmaIncludeAlias()

void Preprocessor::HandlePragmaIncludeAlias ( Token Tok)

◆ HandlePragmaMark()

void Preprocessor::HandlePragmaMark ( Token MarkTok)

Definition at line 432 of file Pragma.cpp.

References clang::Token::getLocation().

◆ HandlePragmaModuleBuild()

void Preprocessor::HandlePragmaModuleBuild ( Token Tok)

◆ HandlePragmaOnce()

void Preprocessor::HandlePragmaOnce ( Token OnceTok)

HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.

Definition at line 417 of file Pragma.cpp.

References Diag(), getCurrentFileLexer(), getLangOpts(), isInPrimaryFile(), clang::HeaderSearch::MarkFileIncludeOnce(), clang::TU_Prefix, and TUKind.

◆ HandlePragmaPoison()

void Preprocessor::HandlePragmaPoison ( )

◆ HandlePragmaPopMacro()

void Preprocessor::HandlePragmaPopMacro ( Token PopMacroTok)

Handle #pragma pop_macro.

The syntax is:

#pragma pop_macro("macro")

Definition at line 650 of file Pragma.cpp.

References appendDefMacroDirective(), appendMacroDirective(), Diag(), clang::Token::getLocation(), getMacroInfo(), clang::IdentifierInfo::getName(), and ParsePragmaPushOrPopMacro().

◆ HandlePragmaPushMacro()

void Preprocessor::HandlePragmaPushMacro ( Token PushMacroTok)

Handle #pragma push_macro.

The syntax is:

#pragma push_macro("macro")

Definition at line 627 of file Pragma.cpp.

References getMacroInfo(), ParsePragmaPushOrPopMacro(), and clang::MacroInfo::setIsAllowRedefinitionsWithoutWarning().

◆ HandlePragmaSystemHeader()

void Preprocessor::HandlePragmaSystemHeader ( Token SysHeaderTok)

◆ HandleSkippedDirectiveWhileUsingPCH()

void Preprocessor::HandleSkippedDirectiveWhileUsingPCH ( Token Result,
SourceLocation  HashLoc 
)

Process directives while skipping until the through header or #pragma hdrstop is found.

Process a directive while looking for the through header or a #pragma hdrstop.

The following directives are handled: #include (to check if it is the through header) #define (to warn about macros that don't match the PCH) #pragma (to check for pragma hdrstop). All other directives are completely discarded.

Definition at line 1103 of file PPDirectives.cpp.

References DiscardUntilEndOfDirective(), HandlePragmaHdrstop(), Lex(), and clang::Result.

Referenced by HandleDirective().

◆ hasRecordedPreamble()

bool clang::Preprocessor::hasRecordedPreamble ( ) const
inline

Definition at line 2738 of file Preprocessor.h.

◆ IgnorePragmas()

void Preprocessor::IgnorePragmas ( )

Install empty handlers for all pragmas (making them ignored).

Ignore all pragmas, useful for modes such as -Eonly which would otherwise warn about those pragmas being unknown.

Definition at line 2195 of file Pragma.cpp.

References AddPragmaHandler().

Referenced by DoPrintMacros(), clang::PreprocessOnlyAction::ExecuteAction(), and clang::RewriteIncludesInInput().

◆ IncrementPasteCounter()

void clang::Preprocessor::IncrementPasteCounter ( bool  isFast)
inline

Increment the counters for the number of token paste operations performed.

If fast was specified, this is a 'fast paste' case we handled.

Definition at line 2207 of file Preprocessor.h.

◆ Initialize()

void Preprocessor::Initialize ( const TargetInfo Target,
const TargetInfo AuxTarget = nullptr 
)

Initialize the preprocessor using information about the target.

Parameters
Targetis owned by the caller and must remain valid for the lifetime of the preprocessor.
AuxTargetis owned by the caller and must remain valid for the lifetime of the preprocessor.

Definition at line 191 of file Preprocessor.cpp.

References clang::IdentifierTable::AddKeywords(), clang::LangOptionsBase::FEM_UnsetOnCommandLine, getLangOpts(), getTargetInfo(), setCurrentFPEvalMethod(), clang::HeaderSearch::setTarget(), and setTUFPEvalMethod().

◆ InitializeForModelFile()

void Preprocessor::InitializeForModelFile ( )

Initialize the preprocessor to parse a model file.

To parse model files the preprocessor of the original source is reused to preserver the identifier table. However to avoid some duplicate information in the preprocessor some cleanup is needed before it is used to parse model files. This method does that cleanup.

Definition at line 219 of file Preprocessor.cpp.

◆ isAtEndOfMacroExpansion()

bool clang::Preprocessor::isAtEndOfMacroExpansion ( SourceLocation  loc,
SourceLocation MacroEnd = nullptr 
) const
inline

Returns true if the given MacroID location points at the last token of the macro expansion.

Parameters
MacroEndIf non-null and function returns true, it is set to end location of the macro.

Definition at line 2185 of file Preprocessor.h.

References clang::Lexer::isAtEndOfMacroExpansion().

◆ isAtStartOfMacroExpansion()

bool clang::Preprocessor::isAtStartOfMacroExpansion ( SourceLocation  loc,
SourceLocation MacroBegin = nullptr 
) const
inline

Returns true if the given MacroID location points at the first token of the macro expansion.

Parameters
MacroBeginIf non-null and function returns true, it is set to begin location of the macro.

Definition at line 2174 of file Preprocessor.h.

References clang::Lexer::isAtStartOfMacroExpansion().

◆ isBacktrackEnabled()

bool clang::Preprocessor::isBacktrackEnabled ( ) const
inline

True if EnableBacktrackAtThisPos() was called and caching of tokens is on.

Definition at line 1725 of file Preprocessor.h.

Referenced by AnnotateCachedTokens(), ReplaceLastTokenWithAnnotation(), RevertCachedTokens(), and TypoCorrectToken().

◆ isCodeCompletionEnabled()

bool clang::Preprocessor::isCodeCompletionEnabled ( ) const
inline

◆ isCodeCompletionReached()

bool clang::Preprocessor::isCodeCompletionReached ( ) const
inline

Returns true if code-completion is enabled and we have hit the code-completion point.

Definition at line 1968 of file Preprocessor.h.

Referenced by ProduceSignatureHelp().

◆ isCurrentLexer()

bool clang::Preprocessor::isCurrentLexer ( const PreprocessorLexer L) const
inline

Return true if we are lexing directly from the specified lexer.

Definition at line 1274 of file Preprocessor.h.

◆ isIncrementalProcessingEnabled()

bool clang::Preprocessor::isIncrementalProcessingEnabled ( ) const
inline

Returns true if incremental processing is enabled.

Definition at line 1925 of file Preprocessor.h.

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), HandleEndOfFile(), clang::IncrementalParser::Parse(), and clang::Parser::ParseTopLevelDecl().

◆ isInImplementationUnit()

bool clang::Preprocessor::isInImplementationUnit ( ) const
inline

If we are implementing an implementation module unit.

Note that the module implementation partition is not considered as an implementation unit.

Definition at line 2382 of file Preprocessor.h.

◆ isInImportingCXXNamedModules()

bool clang::Preprocessor::isInImportingCXXNamedModules ( ) const
inline

If we're importing a standard C++20 Named Modules.

Definition at line 2387 of file Preprocessor.h.

References getLangOpts().

Referenced by LexAfterModuleImport(), and clang::tooling::dependencies::ModuleDepCollectorPP::moduleImport().

◆ isInNamedInterfaceUnit()

bool clang::Preprocessor::isInNamedInterfaceUnit ( ) const
inline

If we are proprocessing a named interface unit.

Note that a module implementation partition is not considered as an named interface unit here although it is importable to ease the parsing.

Definition at line 2371 of file Preprocessor.h.

◆ isInNamedModule()

bool clang::Preprocessor::isInNamedModule ( ) const
inline

If we are preprocessing a named module.

Definition at line 2365 of file Preprocessor.h.

◆ isInPrimaryFile()

bool Preprocessor::isInPrimaryFile ( ) const

Return true if we're in the top-level file, not in a #include.

isInPrimaryFile - Return true if we're in the top-level file, not in a #include.

This looks through macro expansions and active _Pragma lexers.

Definition at line 35 of file PPLexerChange.cpp.

Referenced by HandleEndOfFile(), HandlePragmaOnce(), and HandlePragmaSystemHeader().

◆ isMacroDefined() [1/2]

bool clang::Preprocessor::isMacroDefined ( const IdentifierInfo II)
inline

◆ isMacroDefined() [2/2]

bool clang::Preprocessor::isMacroDefined ( StringRef  Id)
inline

◆ isMacroDefinedInLocalModule()

bool clang::Preprocessor::isMacroDefinedInLocalModule ( const IdentifierInfo II,
Module M 
)
inline

Determine whether II is defined as a macro within the module M, if that is a module that we've already preprocessed.

Does not check for macros imported into M.

Definition at line 1344 of file Preprocessor.h.

References clang::IdentifierInfo::hasMacroDefinition().

Referenced by clang::HeaderSearch::ShouldEnterIncludeFile().

◆ isParsingIfOrElifDirective()

bool clang::Preprocessor::isParsingIfOrElifDirective ( ) const
inline

True if we are currently preprocessing a if or #elif directive.

Definition at line 1240 of file Preprocessor.h.

Referenced by EvaluateHasIncludeCommon().

◆ isPCHThroughHeader()

bool Preprocessor::isPCHThroughHeader ( const FileEntry FE)

Returns true if the FileEntry is the PCH through header.

Definition at line 612 of file Preprocessor.cpp.

References clang::SourceManager::getFileEntryForID(), and clang::FileID::isValid().

Referenced by HandleEndOfFile().

◆ isPPInSafeBufferOptOutRegion() [1/2]

bool Preprocessor::isPPInSafeBufferOptOutRegion ( )
Returns
true iff this PP is currently in a "-Wunsafe-buffer-usage" opt-out region

Definition at line 1546 of file Preprocessor.cpp.

Referenced by enterOrExitSafeBufferOptOutRegion(), and HandleEndOfFile().

◆ isPPInSafeBufferOptOutRegion() [2/2]

bool Preprocessor::isPPInSafeBufferOptOutRegion ( SourceLocation StartLoc)
Parameters
StartLocoutput argument. It will be set to the start location of the current "-Wunsafe-buffer-usage" opt-out region iff this function returns true.
Returns
true iff this PP is currently in a "-Wunsafe-buffer-usage" opt-out region

Definition at line 1549 of file Preprocessor.cpp.

◆ isPreprocessedOutput()

bool clang::Preprocessor::isPreprocessedOutput ( ) const
inline

Returns true if the preprocessor is responsible for generating output, false if it is producing tokens to be consumed by Parse and Sema.

Definition at line 1271 of file Preprocessor.h.

◆ IsPreviousCachedToken()

bool Preprocessor::IsPreviousCachedToken ( const Token Tok) const

Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.

Definition at line 139 of file PPCaching.cpp.

References clang::Token::getKind(), getLastCachedTokenLocation(), clang::Token::getLocation(), and getSourceManager().

◆ isRecordingPreamble()

bool clang::Preprocessor::isRecordingPreamble ( ) const
inline

Definition at line 2734 of file Preprocessor.h.

Referenced by HandleEndOfFile().

◆ isSafeBufferOptOut()

bool Preprocessor::isSafeBufferOptOut ( const SourceManager SourceMgr,
const SourceLocation Loc 
) const
Returns
true iff the given Loc is in a "-Wunsafe-buffer-usage" opt-out region. This Loc must be a source location that has been pre-processed.

Definition at line 1485 of file Preprocessor.cpp.

References clang::SourceManager::isBeforeInTranslationUnit().

◆ LeaveSubmodule()

Module * Preprocessor::LeaveSubmodule ( bool  ForPragma)

◆ Lex()

void Preprocessor::Lex ( Token Result)

◆ LexAfterModuleImport()

bool Preprocessor::LexAfterModuleImport ( Token Result)

Lex a token following the 'import' contextual keyword.

pp-import: [C++20]
      import header-name pp-import-suffix[opt] ;
      import header-name-tokens pp-import-suffix[opt] ;

[ObjC] @ import module-name ; [Clang] import module-name ;

header-name-tokens:
      string-literal
      < [any sequence of preprocessing-tokens other than >] >

module-name:
      module-name-qualifier[opt] identifier

module-name-qualifier
      module-name-qualifier[opt] identifier .

We respond to a pp-import by importing macros from the named module.

Definition at line 1143 of file Preprocessor.cpp.

References CollectPpImportSuffix(), Diag(), getIdentifierInfo(), getLangOpts(), clang::ModuleLoader::HadFatalFailure, clang::Module::Hidden, isInImportingCXXNamedModules(), clang::SourceLocation::isMacroID(), Lex(), LexHeaderName(), clang::ModuleLoader::loadModule(), makeModuleVisible(), recomputeCurLexerKind(), clang::Result, clang::Token::setIdentifierInfo(), clang::Token::setKind(), clang::Token::setLength(), clang::Token::setLocation(), and clang::Token::startToken().

◆ LexHeaderName()

bool Preprocessor::LexHeaderName ( Token FilenameTok,
bool  AllowMacroExpansion = true 
)

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

Lex a header-name token (including one formed from header-name-tokens if AllowConcatenation is true).

Parameters
FilenameTokFilled in with the next token. On success, this will be either a header_name token. On failure, it will be whatever other token was found instead.
AllowMacroExpansionIf true, allow the header name to be formed by macro expansion (concatenating tokens as necessary if the first token is a '<').
Returns
true if we reached EOD or EOF while looking for a > token in a concatenated header name and diagnosed it. false otherwise.

Definition at line 1000 of file Preprocessor.cpp.

References CreateString(), Diag(), clang::Token::getLength(), clang::Token::getLocation(), getSpelling(), clang::Token::hasLeadingEmptyMacro(), clang::Token::hasLeadingSpace(), clang::Token::is(), clang::Token::isAtStartOfLine(), clang::Token::isNot(), clang::Token::isOneOf(), clang::Token::LeadingEmptyMacro, clang::Token::LeadingSpace, Lex(), clang::PreprocessorLexer::LexIncludeFilename(), memcpy(), setCodeCompletionReached(), clang::Token::setFlagValue(), clang::Token::setKind(), clang::Token::StartOfLine, and clang::Token::startToken().

Referenced by EvaluateHasIncludeCommon(), HandlePragmaDependency(), HandlePragmaIncludeAlias(), and LexAfterModuleImport().

◆ LexNonComment()

void clang::Preprocessor::LexNonComment ( Token Result)
inline

Lex a token.

If it's a comment, keep lexing until we get something not a comment.

This is useful in -E -C mode where comments would foul up preprocessor directive handling.

Definition at line 1769 of file Preprocessor.h.

References Lex(), and clang::Result.

Referenced by EvaluateDefined(), EvaluateDirectiveSubExpr(), EvaluateHasIncludeCommon(), and EvaluateValue().

◆ LexOnOffSwitch()

bool Preprocessor::LexOnOffSwitch ( tok::OnOffSwitch Result)

Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD.

Return true if the token is not a valid on-off-switch.

Definition at line 968 of file Pragma.cpp.

References Diag(), clang::Token::getIdentifierInfo(), clang::Token::isNot(), clang::IdentifierInfo::isStr(), LexUnexpandedToken(), clang::tok::OOS_DEFAULT, clang::tok::OOS_OFF, clang::tok::OOS_ON, and clang::Result.

◆ LexStringLiteral()

bool clang::Preprocessor::LexStringLiteral ( Token Result,
std::string &  String,
const char *  DiagnosticTag,
bool  AllowMacroExpansion 
)
inline

Lex a string literal, which may be the concatenation of multiple string literals and may even come from macro expansion.

Returns
true on success, false if a error diagnostic has been generated.

Definition at line 1748 of file Preprocessor.h.

References FinishLexStringLiteral(), Lex(), LexUnexpandedToken(), and clang::Result.

Referenced by HandlePragmaHdrstop().

◆ LexTokensUntilEOF()

void Preprocessor::LexTokensUntilEOF ( std::vector< Token > *  Tokens = nullptr)

Lex all tokens for this preprocessor until (and excluding) end of file.

Definition at line 977 of file Preprocessor.cpp.

References clang::Token::isOneOf(), and Lex().

◆ LexUnexpandedNonComment()

void clang::Preprocessor::LexUnexpandedNonComment ( Token Result)
inline

Like LexNonComment, but this disables macro expansion of identifier tokens.

Definition at line 1789 of file Preprocessor.h.

References LexUnexpandedToken(), and clang::Result.

Referenced by EvaluateDefined().

◆ LexUnexpandedToken()

void clang::Preprocessor::LexUnexpandedToken ( Token Result)
inline

◆ LookAhead()

const Token & clang::Preprocessor::LookAhead ( unsigned  N)
inline

Peeks ahead N tokens and returns that token without consuming any tokens.

LookAhead(0) returns the next token that would be returned by Lex(), LookAhead(1) returns the token after it, etc. This returns normal tokens after phase 5. As such, it is equivalent to using 'Lex', not 'LexUnexpandedToken'.

Definition at line 1813 of file Preprocessor.h.

Referenced by clang::Parser::NextToken(), clang::Parser::parseMapTypeModifiers(), clang::Parser::ParseMSAsmIdentifier(), and clang::Parser::ParseOpenMPVarList().

◆ LookupFile()

OptionalFileEntryRef Preprocessor::LookupFile ( SourceLocation  FilenameLoc,
StringRef  Filename,
bool  isAngled,
ConstSearchDirIterator  FromDir,
const FileEntry FromFile,
ConstSearchDirIterator CurDir,
SmallVectorImpl< char > *  SearchPath,
SmallVectorImpl< char > *  RelativePath,
ModuleMap::KnownHeader SuggestedModule,
bool IsMapped,
bool IsFrameworkFound,
bool  SkipCache = false,
bool  OpenFile = true,
bool  CacheFailures = true 
)

◆ LookUpIdentifierInfo()

IdentifierInfo * Preprocessor::LookUpIdentifierInfo ( Token Identifier) const

Given a tok::raw_identifier token, look up the identifier information for the token and install it into the token, updating the token kind accordingly.

LookUpIdentifierInfo - Given a tok::raw_identifier token, look up the identifier information for the token and install it into the token, updating the token kind accordingly.

Definition at line 698 of file Preprocessor.cpp.

References clang::expandUCNs(), getIdentifierInfo(), getSpelling(), clang::IdentifierInfo::getTokenID(), and Identifier.

Referenced by HandlePragmaPoison(), LexRawTokensFromMainFile(), and ParsePragmaPushOrPopMacro().

◆ macro_begin()

Preprocessor::macro_iterator Preprocessor::macro_begin ( bool  IncludeExternalMacros = true) const

Definition at line 315 of file Preprocessor.cpp.

Referenced by AddMacroResults(), DoPrintMacros(), getLastMacroWithSpelling(), and macros().

◆ macro_end()

Preprocessor::macro_iterator Preprocessor::macro_end ( bool  IncludeExternalMacros = true) const

Definition at line 342 of file Preprocessor.cpp.

Referenced by AddMacroResults(), DoPrintMacros(), getLastMacroWithSpelling(), and macros().

◆ macros()

llvm::iterator_range< macro_iterator > clang::Preprocessor::macros ( bool  IncludeExternalMacros = true) const
inline

◆ makeModuleVisible()

void Preprocessor::makeModuleVisible ( Module M,
SourceLocation  Loc 
)

Definition at line 1332 of file Preprocessor.cpp.

References Diag().

Referenced by EnterSubmodule(), LeaveSubmodule(), and LexAfterModuleImport().

◆ markClangModuleAsAffecting()

void clang::Preprocessor::markClangModuleAsAffecting ( Module M)
inline

Mark the given clang module as affecting the current clang module or translation unit.

Definition at line 1473 of file Preprocessor.h.

References clang::Module::isModuleMapModule().

Referenced by clang::CompilerInstance::loadModule().

◆ markIncluded()

bool clang::Preprocessor::markIncluded ( FileEntryRef  File)
inline

Mark the file as included.

Returns true if this is the first time the file was included.

Definition at line 1491 of file Preprocessor.h.

References clang::File, and clang::HeaderSearch::getFileInfo().

Referenced by EnterMainSourceFile(), and clang::HeaderSearch::ShouldEnterIncludeFile().

◆ markMacroAsUsed()

void Preprocessor::markMacroAsUsed ( MacroInfo MI)

A macro is used, update information about macros that need unused warnings.

Definition at line 1964 of file PPMacroExpansion.cpp.

References clang::MacroInfo::getDefinitionLoc(), clang::MacroInfo::isUsed(), clang::MacroInfo::isWarnIfUnused(), and clang::MacroInfo::setIsUsed().

Referenced by EvaluateDefined().

◆ MaybeHandlePoisonedIdentifier()

void clang::Preprocessor::MaybeHandlePoisonedIdentifier ( Token Identifier)
inline

Definition at line 2245 of file Preprocessor.h.

References HandlePoisonedIdentifier(), and Identifier.

◆ mightHavePendingAnnotationTokens()

bool clang::Preprocessor::mightHavePendingAnnotationTokens ( )
inline

Determine whether it's possible for a future call to Lex to produce an annotation token created by a previous call to EnterAnnotationToken.

Definition at line 1908 of file Preprocessor.h.

◆ overrideMaxTokens()

void clang::Preprocessor::overrideMaxTokens ( unsigned  Value,
SourceLocation  Loc 
)
inline

Definition at line 1317 of file Preprocessor.h.

◆ ParsePragmaPushOrPopMacro()

IdentifierInfo * Preprocessor::ParsePragmaPushOrPopMacro ( Token Tok)

ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro.

Return the IdentifierInfo* associated with the macro to push or pop.

Definition at line 572 of file Pragma.cpp.

References CreateString(), Diag(), clang::Token::getLocation(), getSpelling(), clang::Token::hasUDSuffix(), clang::Token::isNot(), Lex(), LookUpIdentifierInfo(), clang::Token::setKind(), and clang::Token::startToken().

Referenced by HandlePragmaPopMacro(), and HandlePragmaPushMacro().

◆ parseSimpleIntegerLiteral()

bool Preprocessor::parseSimpleIntegerLiteral ( Token Tok,
uint64_t &  Value 
)

Parses a simple integer literal to get its numeric value.

Floating point literals and user defined literals are rejected. Used primarily to handle pragmas that accept integer arguments.

Definition at line 1390 of file Preprocessor.cpp.

References getDiagnostics(), getLangOpts(), clang::Token::getLocation(), getSourceManager(), getSpelling(), getTargetInfo(), clang::Token::is(), and Lex().

Referenced by clang::Parser::ParseOpenMPVarList().

◆ PoisonSEHIdentifiers()

void Preprocessor::PoisonSEHIdentifiers ( bool  Poison = true)

Definition at line 737 of file Preprocessor.cpp.

References clang::IdentifierInfo::setIsPoisoned().

◆ PrintStats()

void Preprocessor::PrintStats ( )

Definition at line 276 of file Preprocessor.cpp.

References getTotalMemory().

Referenced by clang::FrontendAction::EndSourceFile().

◆ processPathForFileMacro()

void Preprocessor::processPathForFileMacro ( SmallVectorImpl< char > &  Path,
const LangOptions LangOpts,
const TargetInfo TI 
)
static

◆ processPathToFileName()

void Preprocessor::processPathToFileName ( SmallVectorImpl< char > &  FileName,
const PresumedLoc PLoc,
const LangOptions LangOpts,
const TargetInfo TI 
)
static

◆ recomputeCurLexerKind()

void Preprocessor::recomputeCurLexerKind ( )

Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.

Definition at line 386 of file Preprocessor.cpp.

Referenced by Backtrack(), HandleEndOfFile(), and LexAfterModuleImport().

◆ removeCommentHandler()

void Preprocessor::removeCommentHandler ( CommentHandler Handler)

Remove the specified comment handler.

It is an error to remove a handler that has not been registered.

Definition at line 1417 of file Preprocessor.cpp.

Referenced by clang::Parser::~Parser().

◆ RemovePragmaHandler() [1/2]

void clang::Preprocessor::RemovePragmaHandler ( PragmaHandler Handler)
inline

Definition at line 1543 of file Preprocessor.h.

References RemovePragmaHandler().

◆ RemovePragmaHandler() [2/2]

void Preprocessor::RemovePragmaHandler ( StringRef  Namespace,
PragmaHandler Handler 
)

Remove the specific pragma handler from this preprocessor.

RemovePragmaHandler - Remove the specific pragma handler from the preprocessor.

If Namespace is non-null, then it should be the namespace that Handler was added to. It is an error to remove a handler that has not been registered.

If

  • Namespace is non-null, then it should be the namespace that
  • Handler was added to. It is an error to remove a handler that has not been registered.

Definition at line 946 of file Pragma.cpp.

References clang::PragmaHandler::getIfNamespace(), clang::PragmaNamespace::IsEmpty(), and clang::PragmaNamespace::RemovePragmaHandler().

Referenced by clang::DoPrintPreprocessedInput(), and RemovePragmaHandler().

◆ RemoveTopOfLexerStack()

void Preprocessor::RemoveTopOfLexerStack ( )

Pop the current lexer/macro exp off the top of the lexer stack.

RemoveTopOfLexerStack - Pop the current lexer/macro exp off the top of the lexer stack.

This should only be used in situations where the current state of the top-of-stack lexer is known.

This should only be used in situations where the current state of the top-of-stack lexer is unknown.

Definition at line 623 of file PPLexerChange.cpp.

Referenced by clang::MacroArgs::getPreExpArgument(), and HandleEndOfFile().

◆ ReplaceLastTokenWithAnnotation()

void clang::Preprocessor::ReplaceLastTokenWithAnnotation ( const Token Tok)
inline

Replace the last token with an annotation token.

Like AnnotateCachedTokens(), this routine replaces an already-parsed (and resolved) token with an annotation token. However, this routine only replaces the last token with the annotation token; it does not affect any other cached tokens. This function has no effect if backtracking is not enabled.

Definition at line 1896 of file Preprocessor.h.

References clang::Token::isAnnotation(), and isBacktrackEnabled().

◆ ReplacePreviousCachedToken()

void Preprocessor::ReplacePreviousCachedToken ( ArrayRef< Token NewToks)

Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.

Useful when a token needs to be split in smaller ones and CachedTokens most recent token must to be updated to reflect that.

Definition at line 157 of file PPCaching.cpp.

◆ RevertCachedTokens()

void clang::Preprocessor::RevertCachedTokens ( unsigned  N)
inline

When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens.

Note that the number of tokens being reverted should be up to the last backtrack position, not more.

Definition at line 1826 of file Preprocessor.h.

References isBacktrackEnabled().

◆ SawDateOrTime()

bool clang::Preprocessor::SawDateOrTime ( ) const
inline

Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.

Definition at line 2320 of file Preprocessor.h.

◆ setCodeCompletionHandler()

void clang::Preprocessor::setCodeCompletionHandler ( CodeCompletionHandler Handler)
inline

Set the code completion handler to the given object.

Definition at line 1564 of file Preprocessor.h.

Referenced by clang::Parser::Parser().

◆ setCodeCompletionIdentifierInfo()

void clang::Preprocessor::setCodeCompletionIdentifierInfo ( IdentifierInfo Filter)
inline

Set the code completion token for filtering purposes.

Definition at line 1587 of file Preprocessor.h.

Referenced by Lex().

◆ SetCodeCompletionPoint()

bool Preprocessor::SetCodeCompletionPoint ( FileEntryRef  File,
unsigned  Line,
unsigned  Column 
)

Specify the point at which code-completion will be performed.

Parameters
Filethe file in which code completion should occur. If this file is included multiple times, code-completion will perform completion the first time it is included. If NULL, this function clears out the code-completion point.
Linethe line at which code completion should occur (1-based).
Columnthe column at which code completion should occur (1-based).
Returns
true if an error occurred, false otherwise.

Definition at line 397 of file Preprocessor.cpp.

References clang::File, clang::SourceManager::getFileEntryForID(), clang::SourceManager::getMainFileID(), clang::SourceManager::getMemoryBufferForFileOrNone(), clang::Line, and clang::SourceManager::overrideFileContents().

Referenced by EnableCodeCompletion().

◆ setCodeCompletionReached()

void clang::Preprocessor::setCodeCompletionReached ( )
inline

◆ setCodeCompletionTokenRange()

void clang::Preprocessor::setCodeCompletionTokenRange ( const SourceLocation  Start,
const SourceLocation  End 
)
inline

Set the code completion token range for detecting replacement range later on.

Definition at line 1593 of file Preprocessor.h.

Referenced by Lex().

◆ SetCommentRetentionState()

void clang::Preprocessor::SetCommentRetentionState ( bool  KeepComments,
bool  KeepMacroComments 
)
inline

Control whether the preprocessor retains comments in output.

Definition at line 1245 of file Preprocessor.h.

Referenced by clang::DoPrintPreprocessedInput().

◆ setCounterValue()

void clang::Preprocessor::setCounterValue ( unsigned  V)
inline

Definition at line 2324 of file Preprocessor.h.

References V.

Referenced by clang::ASTUnit::LoadFromASTFile(), and clang::PCHValidator::ReadCounter().

◆ setCurrentFPEvalMethod()

void clang::Preprocessor::setCurrentFPEvalMethod ( SourceLocation  PragmaLoc,
LangOptions::FPEvalMethodKind  Val 
)
inline

◆ setDiagnostics()

void clang::Preprocessor::setDiagnostics ( DiagnosticsEngine D)
inline

Definition at line 1203 of file Preprocessor.h.

◆ setEmptylineHandler()

void clang::Preprocessor::setEmptylineHandler ( EmptylineHandler Handler)
inline

Set empty line handler.

Definition at line 1551 of file Preprocessor.h.

Referenced by clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks().

◆ setExternalSource()

void clang::Preprocessor::setExternalSource ( ExternalPreprocessorSource Source)
inline

Definition at line 1218 of file Preprocessor.h.

◆ setLoadedMacroDirective()

void Preprocessor::setLoadedMacroDirective ( IdentifierInfo II,
MacroDirective ED,
MacroDirective MD 
)

◆ SetMacroExpansionOnlyInDirectives()

void clang::Preprocessor::SetMacroExpansionOnlyInDirectives ( )
inline

Disables macro expansion everywhere except for preprocessor directives.

Definition at line 1801 of file Preprocessor.h.

Referenced by clang::DoPrintPreprocessedInput(), and clang::RewriteIncludesInInput().

◆ setMainFileDir()

void clang::Preprocessor::setMainFileDir ( DirectoryEntryRef  Dir)
inline

Set the directory in which the main file should be considered to have been found, if it is not a real file.

Definition at line 2025 of file Preprocessor.h.

Referenced by prepareToBuildModule().

◆ SetPoisonReason()

void Preprocessor::SetPoisonReason ( IdentifierInfo II,
unsigned  DiagID 
)

Specifies the reason for poisoning an identifier.

If that identifier is accessed while poisoned, then this reason will be used instead of the default "poisoned" diagnostic.

Definition at line 733 of file Preprocessor.cpp.

Referenced by clang::Parser::Initialize(), and Preprocessor().

◆ setPragmaARCCFCodeAuditedInfo()

void clang::Preprocessor::setPragmaARCCFCodeAuditedInfo ( IdentifierInfo Ident,
SourceLocation  Loc 
)
inline

Set the location of the currently-active #pragma clang arc_cf_code_audited begin.

An invalid location ends the pragma.

Definition at line 1989 of file Preprocessor.h.

◆ setPragmaAssumeNonNullLoc()

void clang::Preprocessor::setPragmaAssumeNonNullLoc ( SourceLocation  Loc)
inline

Set the location of the currently-active #pragma clang assume_nonnull begin.

An invalid location ends the pragma.

Definition at line 2004 of file Preprocessor.h.

◆ setPragmasEnabled()

void clang::Preprocessor::setPragmasEnabled ( bool  Enabled)
inline

Definition at line 1252 of file Preprocessor.h.

◆ setPreambleRecordedPragmaAssumeNonNullLoc()

void clang::Preprocessor::setPreambleRecordedPragmaAssumeNonNullLoc ( SourceLocation  Loc)
inline

Record the location of the unterminated #pragma clang assume_nonnull begin in the preamble.

Definition at line 2019 of file Preprocessor.h.

◆ setPredefines()

void clang::Preprocessor::setPredefines ( std::string  P)
inline

Set the predefines for this Preprocessor.

These predefines are automatically injected when parsing the main file.

Definition at line 1520 of file Preprocessor.h.

References P.

Referenced by createASTReader(), clang::CompilerInstance::createPCHExternalASTSource(), and clang::InitializePreprocessor().

◆ setPreprocessedOutput()

void clang::Preprocessor::setPreprocessedOutput ( bool  IsPreprocessedOutput)
inline

Sets whether the preprocessor is responsible for producing output or if it is producing tokens to be consumed by Parse and Sema.

Definition at line 1265 of file Preprocessor.h.

◆ setPreprocessToken()

void clang::Preprocessor::setPreprocessToken ( bool  Preprocess)
inline

◆ setRecordedPreambleConditionalStack()

void clang::Preprocessor::setRecordedPreambleConditionalStack ( ArrayRef< PPConditionalInfo s)
inline

Definition at line 2746 of file Preprocessor.h.

References s.

◆ setReplayablePreambleConditionalStack()

void clang::Preprocessor::setReplayablePreambleConditionalStack ( ArrayRef< PPConditionalInfo s,
std::optional< PreambleSkipInfo SkipInfo 
)
inline

Definition at line 2750 of file Preprocessor.h.

References s.

◆ setSkipMainFilePreamble()

void clang::Preprocessor::setSkipMainFilePreamble ( unsigned  Bytes,
bool  StartOfLine 
)
inline

Instruct the preprocessor to skip part of the main source file.

Parameters
BytesThe number of bytes in the preamble to skip.
StartOfLineWhether skipping these bytes puts the lexer at the start of a line.

Definition at line 2033 of file Preprocessor.h.

Referenced by clang::FrontendAction::BeginSourceFile(), and clang::InitializePreprocessor().

◆ SetSuppressIncludeNotFoundError()

void clang::Preprocessor::SetSuppressIncludeNotFoundError ( bool  Suppress)
inline

◆ setTokenWatcher()

void clang::Preprocessor::setTokenWatcher ( llvm::unique_function< void(const clang::Token &)>  F)
inline

Register a function that would be called on each token in the final expanded token stream.

This also reports annotation tokens produced by the parser.

Definition at line 1327 of file Preprocessor.h.

Referenced by clang::MacroExpansionContext::registerForPreprocessor(), clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks(), and clang::syntax::TokenCollector::TokenCollector().

◆ setTUFPEvalMethod()

void clang::Preprocessor::setTUFPEvalMethod ( LangOptions::FPEvalMethodKind  Val)
inline

Definition at line 2352 of file Preprocessor.h.

References clang::LangOptionsBase::FEM_UnsetOnCommandLine.

Referenced by Initialize().

◆ SkipTokensWhileUsingPCH()

void Preprocessor::SkipTokensWhileUsingPCH ( )

Skip tokens until after the #include of the through header or until after a #pragma hdrstop.

Skip tokens until after the #include of the through header or until after a #pragma hdrstop is seen.

Tokens in the predefines file and the main file may be skipped. If the end of the predefines file is reached, skipping continues into the main file. If the end of the main file is reached, it's a fatal error.

Definition at line 641 of file Preprocessor.cpp.

References Diag(), getPredefinesFileID(), and clang::Token::is().

Referenced by EnterMainSourceFile().

◆ SplitToken()

SourceLocation Preprocessor::SplitToken ( SourceLocation  TokLoc,
unsigned  Length 
)

Split the first Length characters out of the token starting at TokLoc and return a location pointing to the split token.

Re-lexing from the split token will return the split token rather than the original.

Definition at line 510 of file Preprocessor.cpp.

References clang::SourceLocation::getLocWithOffset(), getSourceManager(), clang::Invalid, and SM.

◆ TypoCorrectToken()

void clang::Preprocessor::TypoCorrectToken ( const Token Tok)
inline

Update the current token to represent the provided identifier, in order to cache an action performed by typo correction.

Definition at line 1914 of file Preprocessor.h.

References clang::Token::getIdentifierInfo(), and isBacktrackEnabled().

◆ usingPCHWithPragmaHdrStop()

bool Preprocessor::usingPCHWithPragmaHdrStop ( )

True if using a PCH with a #pragma hdrstop.

Definition at line 632 of file Preprocessor.cpp.

References clang::TU_Prefix, and TUKind.

Referenced by EnterMainSourceFile(), HandlePragmaHdrstop(), and Preprocessor().

◆ usingPCHWithThroughHeader()

bool Preprocessor::usingPCHWithThroughHeader ( )

True if using a PCH with a through header.

Definition at line 623 of file Preprocessor.cpp.

References clang::FileID::isValid(), clang::TU_Prefix, and TUKind.

Referenced by EnterMainSourceFile().

Friends And Related Function Documentation

◆ ASTReader

friend class ASTReader
friend

Definition at line 692 of file Preprocessor.h.

◆ MacroArgs

friend class MacroArgs
friend

Definition at line 693 of file Preprocessor.h.

◆ TokenLexer::ExpandFunctionArguments

void TokenLexer::ExpandFunctionArguments ( )
friend

◆ VAOptDefinitionContext

friend class VAOptDefinitionContext
friend

Definition at line 129 of file Preprocessor.h.

◆ VariadicMacroScopeGuard

friend class VariadicMacroScopeGuard
friend

Definition at line 130 of file Preprocessor.h.

Member Data Documentation

◆ TUKind

const TranslationUnitKind clang::Preprocessor::TUKind

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