clang
17.0.0git
|
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 | |
Preprocessor (std::shared_ptr< PreprocessorOptions > PPOpts, DiagnosticsEngine &diags, LangOptions &opts, 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. More... | |
void | InitializeForModelFile () |
Initialize the preprocessor to parse a model file. More... | |
void | FinalizeForModelFile () |
Cleanup after model file parsing. More... | |
PreprocessorOptions & | getPreprocessorOpts () const |
Retrieve the preprocessor options used to initialize this preprocessor. More... | |
DiagnosticsEngine & | getDiagnostics () const |
void | setDiagnostics (DiagnosticsEngine &D) |
const LangOptions & | getLangOpts () const |
const TargetInfo & | getTargetInfo () const |
const TargetInfo * | getAuxTargetInfo () const |
FileManager & | getFileManager () const |
SourceManager & | getSourceManager () const |
HeaderSearch & | getHeaderSearchInfo () const |
IdentifierTable & | getIdentifierTable () |
const IdentifierTable & | getIdentifierTable () const |
SelectorTable & | getSelectorTable () |
Builtin::Context & | getBuiltinInfo () |
llvm::BumpPtrAllocator & | getPreprocessorAllocator () |
void | setExternalSource (ExternalPreprocessorSource *Source) |
ExternalPreprocessorSource * | getExternalSource () const |
ModuleLoader & | getModuleLoader () const |
Retrieve the module loader associated with this preprocessor. More... | |
bool | hadModuleLoaderFatalFailure () const |
unsigned | getNumDirectives () const |
Retrieve the number of Directives that have been processed by the Preprocessor. More... | |
bool | isParsingIfOrElifDirective () const |
True if we are currently preprocessing a if or #elif directive. More... | |
void | SetCommentRetentionState (bool KeepComments, bool KeepMacroComments) |
Control whether the preprocessor retains comments in output. More... | |
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. More... | |
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. More... | |
bool | isCurrentLexer (const PreprocessorLexer *L) const |
Return true if we are lexing directly from the specified lexer. More... | |
PreprocessorLexer * | getCurrentLexer () const |
Return the current lexer being lexed from. More... | |
PreprocessorLexer * | getCurrentFileLexer () const |
Return the current file lexer being lexed from. More... | |
Module * | getCurrentLexerSubmodule () const |
Return the submodule owning the file being lexed. More... | |
FileID | getPredefinesFileID () const |
Returns the FileID for the preprocessor predefines. More... | |
unsigned | getTokenCount () const |
Get the number of tokens processed so far. More... | |
unsigned | getMaxTokens () const |
Get the max number of tokens before issuing a -Wmax-tokens warning. More... | |
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. More... | |
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. More... | |
MacroDefinition | getMacroDefinition (const IdentifierInfo *II) |
MacroDefinition | getMacroDefinitionAtLoc (const IdentifierInfo *II, SourceLocation Loc) |
MacroDirective * | getLocalMacroDirective (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. More... | |
const MacroInfo * | getMacroInfo (const IdentifierInfo *II) const |
MacroInfo * | getMacroInfo (const IdentifierInfo *II) |
MacroDirective * | getLocalMacroDirectiveHistory (const IdentifierInfo *II) const |
Given an identifier, return the latest non-imported macro directive for that identifier. More... | |
void | appendMacroDirective (IdentifierInfo *II, MacroDirective *MD) |
Add a directive to the macro directive history for this identifier. More... | |
DefMacroDirective * | appendDefMacroDirective (IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc) |
DefMacroDirective * | appendDefMacroDirective (IdentifierInfo *II, MacroInfo *MI) |
void | setLoadedMacroDirective (IdentifierInfo *II, MacroDirective *ED, MacroDirective *MD) |
Set a MacroDirective that was loaded from a PCH file. More... | |
ModuleMacro * | addModuleMacro (Module *Mod, IdentifierInfo *II, MacroInfo *Macro, ArrayRef< ModuleMacro * > Overrides, bool &IsNew) |
Register an exported macro for a module and identifier. More... | |
ModuleMacro * | getModuleMacro (Module *Mod, const IdentifierInfo *II) |
ArrayRef< ModuleMacro * > | getLeafModuleMacros (const IdentifierInfo *II) const |
Get the list of leaf (non-overridden) module macros for a name. More... | |
ArrayRef< BuildingSubmoduleInfo > | getBuildingSubmodules () const |
Get the list of submodules that we're currently building. More... | |
void | markClangModuleAsAffecting (Module *M) |
Mark the given clang module as affecting the current clang module or translation unit. More... | |
const llvm::SmallSetVector< Module *, 2 > & | getAffectingClangModules () const |
Get the set of top-level clang modules that affected preprocessing, but were not imported. More... | |
bool | markIncluded (const FileEntry *File) |
Mark the file as included. More... | |
bool | alreadyIncluded (const FileEntry *File) const |
Return true if this header has already been included. More... | |
IncludedFilesSet & | getIncludedFiles () |
Get the set of included files. More... | |
const IncludedFilesSet & | getIncludedFiles () const |
StringRef | getLastMacroWithSpelling (SourceLocation Loc, ArrayRef< TokenValue > Tokens) const |
Return the name of the macro defined before Loc that has spelling Tokens . More... | |
const std::string & | getPredefines () const |
Get the predefines for this processor. More... | |
void | setPredefines (std::string P) |
Set the predefines for this Preprocessor. More... | |
IdentifierInfo * | getIdentifierInfo (StringRef Name) const |
Return information about the specified preprocessor identifier token. More... | |
void | AddPragmaHandler (StringRef Namespace, PragmaHandler *Handler) |
Add the specified pragma handler to this preprocessor. More... | |
void | AddPragmaHandler (PragmaHandler *Handler) |
void | RemovePragmaHandler (StringRef Namespace, PragmaHandler *Handler) |
Remove the specific pragma handler from this preprocessor. More... | |
void | RemovePragmaHandler (PragmaHandler *Handler) |
void | IgnorePragmas () |
Install empty handlers for all pragmas (making them ignored). More... | |
void | setEmptylineHandler (EmptylineHandler *Handler) |
Set empty line handler. More... | |
EmptylineHandler * | getEmptylineHandler () const |
void | addCommentHandler (CommentHandler *Handler) |
Add the specified comment handler to the preprocessor. More... | |
void | removeCommentHandler (CommentHandler *Handler) |
Remove the specified comment handler. More... | |
void | setCodeCompletionHandler (CodeCompletionHandler &Handler) |
Set the code completion handler to the given object. More... | |
CodeCompletionHandler * | getCodeCompletionHandler () const |
Retrieve the current code-completion handler. More... | |
void | clearCodeCompletionHandler () |
Clear out the code completion handler. More... | |
void | CodeCompleteIncludedFile (llvm::StringRef Dir, bool IsAngled) |
Hook used by the lexer to invoke the "included file" code completion point. More... | |
void | CodeCompleteNaturalLanguage () |
Hook used by the lexer to invoke the "natural language" code completion point. More... | |
void | setCodeCompletionIdentifierInfo (IdentifierInfo *Filter) |
Set the code completion token for filtering purposes. More... | |
void | setCodeCompletionTokenRange (const SourceLocation Start, const SourceLocation End) |
Set the code completion token range for detecting replacement range later on. More... | |
SourceRange | getCodeCompletionTokenRange () const |
StringRef | getCodeCompletionFilter () |
Get the code completion token for filtering purposes. More... | |
PreprocessingRecord * | getPreprocessingRecord () const |
Retrieve the preprocessing record, or NULL if there is no preprocessing record. More... | |
void | createPreprocessingRecord () |
Create a new preprocessing record, which will keep track of all macro expansions, macro definitions, etc. More... | |
bool | isPCHThroughHeader (const FileEntry *FE) |
Returns true if the FileEntry is the PCH through header. More... | |
bool | creatingPCHWithThroughHeader () |
True if creating a PCH with a through header. More... | |
bool | usingPCHWithThroughHeader () |
True if using a PCH with a through header. More... | |
bool | creatingPCHWithPragmaHdrStop () |
True if creating a PCH with a #pragma hdrstop. More... | |
bool | usingPCHWithPragmaHdrStop () |
True if using a PCH with a #pragma hdrstop. More... | |
void | SkipTokensWhileUsingPCH () |
Skip tokens until after the include of the through header or until after a #pragma hdrstop. More... | |
void | HandleSkippedDirectiveWhileUsingPCH (Token &Result, SourceLocation HashLoc) |
Process directives while skipping until the through header or #pragma hdrstop is found. More... | |
void | EnterMainSourceFile () |
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc. More... | |
void | EndSourceFile () |
Inform the preprocessor callbacks that processing is complete. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
void | CommitBacktrackedTokens () |
Disable the last EnableBacktrackAtThisPos call. More... | |
void | Backtrack () |
Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously called. More... | |
bool | isBacktrackEnabled () const |
True if EnableBacktrackAtThisPos() was called and caching of tokens is on. More... | |
void | Lex (Token &Result) |
Lex the next token for this preprocessor. More... | |
bool | LexHeaderName (Token &Result, bool AllowMacroExpansion=true) |
Lex a token, forming a header-name token if possible. More... | |
bool | LexAfterModuleImport (Token &Result) |
Lex a token following the 'import' contextual keyword. More... | |
void | CollectPpImportSuffix (SmallVectorImpl< Token > &Toks) |
Collect the tokens of a C++20 pp-import-suffix. More... | |
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. More... | |
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). More... | |
void | LexNonComment (Token &Result) |
Lex a token. More... | |
void | LexUnexpandedToken (Token &Result) |
Just like Lex, but disables macro expansion of identifier tokens. More... | |
void | LexUnexpandedNonComment (Token &Result) |
Like LexNonComment, but this disables macro expansion of identifier tokens. More... | |
bool | parseSimpleIntegerLiteral (Token &Tok, uint64_t &Value) |
Parses a simple integer literal to get its numeric value. More... | |
void | SetMacroExpansionOnlyInDirectives () |
Disables macro expansion everywhere except for preprocessor directives. More... | |
const Token & | LookAhead (unsigned N) |
Peeks ahead N tokens and returns that token without consuming any tokens. More... | |
void | RevertCachedTokens (unsigned N) |
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens. More... | |
void | EnterToken (const Token &Tok, bool IsReinject) |
Enters a token in the token stream to be lexed next. More... | |
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. More... | |
SourceLocation | getLastCachedTokenLocation () const |
Get the location of the last cached token, suitable for setting the end location of an annotation token. More... | |
bool | IsPreviousCachedToken (const Token &Tok) const |
Whether Tok is the most recent token (CachedLexPos - 1 ) in CachedTokens. More... | |
void | ReplacePreviousCachedToken (ArrayRef< Token > NewToks) |
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks . More... | |
void | ReplaceLastTokenWithAnnotation (const Token &Tok) |
Replace the last token with an annotation token. More... | |
void | EnterAnnotationToken (SourceRange Range, tok::TokenKind Kind, void *AnnotationVal) |
Enter an annotation token into the token stream. More... | |
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. More... | |
void | TypoCorrectToken (const Token &Tok) |
Update the current token to represent the provided identifier, in order to cache an action performed by typo correction. More... | |
void | recomputeCurLexerKind () |
Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers. More... | |
bool | isIncrementalProcessingEnabled () const |
Returns true if incremental processing is enabled. More... | |
void | enableIncrementalProcessing (bool value=true) |
Enables the incremental processing. More... | |
bool | SetCodeCompletionPoint (const FileEntry *File, unsigned Line, unsigned Column) |
Specify the point at which code-completion will be performed. More... | |
bool | isCodeCompletionEnabled () const |
Determine if we are performing code completion. More... | |
SourceLocation | getCodeCompletionLoc () const |
Returns the location of the code-completion point. More... | |
SourceLocation | getCodeCompletionFileLoc () const |
Returns the start location of the file of code-completion point. More... | |
bool | isCodeCompletionReached () const |
Returns true if code-completion is enabled and we have hit the code-completion point. More... | |
void | setCodeCompletionReached () |
Note that we hit the code-completion point. More... | |
std::pair< IdentifierInfo *, SourceLocation > | getPragmaARCCFCodeAuditedInfo () const |
The location of the currently-active #pragma clang arc_cf_code_audited begin. More... | |
void | setPragmaARCCFCodeAuditedInfo (IdentifierInfo *Ident, SourceLocation Loc) |
Set the location of the currently-active #pragma clang arc_cf_code_audited begin. More... | |
SourceLocation | getPragmaAssumeNonNullLoc () const |
The location of the currently-active #pragma clang assume_nonnull begin. More... | |
void | setPragmaAssumeNonNullLoc (SourceLocation Loc) |
Set the location of the currently-active #pragma clang assume_nonnull begin. More... | |
SourceLocation | getPreambleRecordedPragmaAssumeNonNullLoc () const |
Get the location of the recorded unterminated #pragma clang assume_nonnull begin in the preamble, if one exists. More... | |
void | setPreambleRecordedPragmaAssumeNonNullLoc (SourceLocation Loc) |
Record the location of the unterminated #pragma clang assume_nonnull begin in the preamble. More... | |
void | setMainFileDir (const DirectoryEntry *Dir) |
Set the directory in which the main file should be considered to have been found, if it is not a real file. More... | |
void | setSkipMainFilePreamble (unsigned Bytes, bool StartOfLine) |
Instruct the preprocessor to skip part of the main source file. More... | |
DiagnosticBuilder | Diag (SourceLocation Loc, unsigned DiagID) const |
Forwarding function for diagnostics. More... | |
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. More... | |
std::string | getSpelling (const Token &Tok, bool *Invalid=nullptr) const |
Return the 'spelling' of the Tok token. More... | |
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. More... | |
StringRef | getSpelling (const Token &Tok, SmallVectorImpl< char > &Buffer, bool *Invalid=nullptr) const |
Get the spelling of a token into a SmallVector. More... | |
bool | getRawToken (SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false) |
Relex the token at the specified location. More... | |
char | getSpellingOfSingleCharacterNumericConstant (const Token &Tok, bool *Invalid=nullptr) const |
Given a Token Tok that is a numeric constant with length 1, return the character. More... | |
StringRef | getImmediateMacroName (SourceLocation Loc) |
Retrieve the name of the immediate macro expansion. More... | |
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. More... | |
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. More... | |
SourceLocation | getLocForEndOfToken (SourceLocation Loc, unsigned Offset=0) |
Computes the source location just past the end of the token at this source location. More... | |
bool | isAtStartOfMacroExpansion (SourceLocation loc, SourceLocation *MacroBegin=nullptr) const |
Returns true if the given MacroID location points at the first token of the macro expansion. More... | |
bool | isAtEndOfMacroExpansion (SourceLocation loc, SourceLocation *MacroEnd=nullptr) const |
Returns true if the given MacroID location points at the last token of the macro expansion. More... | |
void | DumpToken (const Token &Tok, bool DumpFlags=false) const |
Print the token to stderr, used for debugging. More... | |
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. More... | |
void | IncrementPasteCounter (bool isFast) |
Increment the counters for the number of token paste operations performed. More... | |
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. More... | |
IdentifierInfo * | 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. More... | |
void | SetPoisonReason (IdentifierInfo *II, unsigned DiagID) |
Specifies the reason for poisoning an identifier. More... | |
void | HandlePoisonedIdentifier (Token &Identifier) |
Display reason for poisoned identifier. More... | |
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. More... | |
bool | HandleEndOfFile (Token &Result, bool isEndOfMacro=false) |
Callback invoked when the lexer hits the end of the current file. More... | |
bool | HandleEndOfTokenLexer (Token &Result) |
Callback invoked when the current TokenLexer hits the end of its token stream. More... | |
void | HandleDirective (Token &Result) |
Callback invoked when the lexer sees a # token at the start of a line. More... | |
SourceLocation | CheckEndOfDirective (const char *DirType, bool EnableMacros=false) |
Ensure that the next token is a tok::eod token. More... | |
SourceRange | DiscardUntilEndOfDirective () |
Read and discard all tokens remaining on the current line until the tok::eod token is found. More... | |
bool | SawDateOrTime () const |
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far. More... | |
unsigned | getCounterValue () const |
void | setCounterValue (unsigned V) |
LangOptions::FPEvalMethodKind | getCurrentFPEvalMethod () const |
LangOptions::FPEvalMethodKind | getTUFPEvalMethod () const |
SourceLocation | getLastFPEvalPragmaLocation () const |
LangOptions::FPEvalMethodKind | getLastFPEvalMethod () const |
void | setLastFPEvalMethod (LangOptions::FPEvalMethodKind Val) |
void | setCurrentFPEvalMethod (SourceLocation PragmaLoc, LangOptions::FPEvalMethodKind Val) |
void | setTUFPEvalMethod (LangOptions::FPEvalMethodKind Val) |
Module * | getCurrentModule () |
Retrieves the module that we're currently building, if any. More... | |
Module * | getCurrentModuleImplementation () |
Retrieves the module whose implementation we're current compiling, if any. More... | |
MacroInfo * | AllocateMacroInfo (SourceLocation L) |
Allocate a new MacroInfo object with the provided SourceLocation. More... | |
bool | GetIncludeFilenameSpelling (SourceLocation Loc, StringRef &Buffer) |
Turn the specified lexer token into a fully checked and spelled filename, e.g. More... | |
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. More... | |
bool | isInPrimaryFile () const |
Return true if we're in the top-level file, not in a #include. More... | |
bool | LexOnOffSwitch (tok::OnOffSwitch &Result) |
Lex an on-off-switch (C99 6.10.6p2) and verify that it is followed by EOD. More... | |
bool | CheckMacroName (Token &MacroNameTok, MacroUse isDefineUndef, bool *ShadowFlag=nullptr) |
void | EnterSubmodule (Module *M, SourceLocation ImportLoc, bool ForPragma) |
Module * | LeaveSubmodule (bool ForPragma) |
Module * | getModuleForLocation (SourceLocation Loc, bool AllowTextual) |
Find the module that owns the source or header file that Loc points to. More... | |
const FileEntry * | 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). More... | |
bool | isRecordingPreamble () const |
bool | hasRecordedPreamble () const |
ArrayRef< PPConditionalInfo > | getPreambleConditionalStack () const |
void | setRecordedPreambleConditionalStack (ArrayRef< PPConditionalInfo > s) |
void | setReplayablePreambleConditionalStack (ArrayRef< PPConditionalInfo > s, std::optional< PreambleSkipInfo > SkipInfo) |
std::optional< PreambleSkipInfo > | getPreambleSkipInfo () const |
void | HandlePragmaOnce (Token &OnceTok) |
HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'. More... | |
void | HandlePragmaMark (Token &MarkTok) |
void | HandlePragmaPoison () |
HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'. More... | |
void | HandlePragmaSystemHeader (Token &SysHeaderTok) |
HandlePragmaSystemHeader - Implement #pragma GCC system_header. More... | |
void | HandlePragmaDependency (Token &DependencyTok) |
HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah. More... | |
void | HandlePragmaPushMacro (Token &Tok) |
Handle #pragma push_macro. More... | |
void | HandlePragmaPopMacro (Token &Tok) |
Handle #pragma pop_macro. More... | |
void | HandlePragmaIncludeAlias (Token &Tok) |
void | HandlePragmaModuleBuild (Token &Tok) |
void | HandlePragmaHdrstop (Token &Tok) |
IdentifierInfo * | ParsePragmaPushOrPopMacro (Token &Tok) |
ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro. More... | |
bool | HandleComment (Token &result, SourceRange Comment) |
void | markMacroAsUsed (MacroInfo *MI) |
A macro is used, update information about macros that need unused warnings. More... | |
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) const |
PPCallbacks * | getPPCallbacks () const |
void | addPPCallbacks (std::unique_ptr< PPCallbacks > C) |
Static Public Member Functions | |
static bool | checkModuleIsAvailable (const LangOptions &LangOpts, const TargetInfo &TargetInfo, DiagnosticsEngine &Diags, Module *M) |
Check that the given module is available, producing a diagnostic if not. More... | |
static void | processPathForFileMacro (SmallVectorImpl< char > &Path, const LangOptions &LangOpts, const TargetInfo &TI) |
Public Attributes | |
const TranslationUnitKind | TUKind |
The kind of translation unit we are processing. More... | |
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_iterator > | macros (bool IncludeExternalMacros=true) const |
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.
using clang::Preprocessor::IncludedFilesSet = llvm::DenseSet<const FileEntry *> |
Definition at line 540 of file Preprocessor.h.
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 1313 of file Preprocessor.h.
Preprocessor::Preprocessor | ( | std::shared_ptr< PreprocessorOptions > | PPOpts, |
DiagnosticsEngine & | diags, | ||
LangOptions & | opts, | ||
SourceManager & | SM, | ||
HeaderSearch & | Headers, | ||
ModuleLoader & | TheModuleLoader, | ||
IdentifierInfoLookup * | IILookup = nullptr , |
||
bool | OwnsHeaderSearch = false , |
||
TranslationUnitKind | TUKind = TU_Complete |
||
) |
Definition at line 79 of file Preprocessor.cpp.
Preprocessor::~Preprocessor | ( | ) |
Definition at line 164 of file Preprocessor.cpp.
void Preprocessor::addCommentHandler | ( | CommentHandler * | Handler | ) |
Add the specified comment handler to the preprocessor.
Definition at line 1395 of file Preprocessor.cpp.
Referenced by clang::Parser::Parser(), and clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks().
|
inline |
Definition at line 2661 of file Preprocessor.h.
|
inline |
Definition at line 2637 of file Preprocessor.h.
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().
|
inline |
Definition at line 1158 of file Preprocessor.h.
Referenced by clang::AttachDependencyGraphGen(), clang::AttachHeaderIncludeGen(), clang::DependencyCollector::attachToPreprocessor(), clang::ModuleDependencyCollector::attachToPreprocessor(), clang::tooling::dependencies::ModuleDepCollector::attachToPreprocessor(), clang::ExtractAPIAction::CreateASTConsumer(), clang::arcmt::MigrateSourceAction::CreateASTConsumer(), clang::CodeGenAction::CreateASTConsumer(), clang::arcmt::ObjCMigrateAction::CreateASTConsumer(), createPreprocessingRecord(), clang::DoPrintPreprocessedInput(), clang::MacroExpansionContext::registerForPreprocessor(), clang::RewriteIncludesInInput(), clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks(), and clang::syntax::TokenCollector::TokenCollector().
|
inline |
Definition at line 1387 of file Preprocessor.h.
References AddPragmaHandler().
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 904 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().
|
inline |
Definition at line 2649 of file Preprocessor.h.
|
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 2054 of file Preprocessor.h.
References clang::Lexer::AdvanceToTokenCharacter().
Referenced by GetLineValue().
MacroInfo * Preprocessor::AllocateMacroInfo | ( | SourceLocation | L | ) |
Allocate a new MacroInfo object with the provided SourceLocation.
Definition at line 60 of file PPDirectives.cpp.
Return true if this header has already been included.
Definition at line 1352 of file Preprocessor.h.
References clang::File.
Referenced by clang::HeaderSearch::ShouldEnterIncludeFile().
|
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 1715 of file Preprocessor.h.
References clang::Token::isAnnotation(), and isBacktrackEnabled().
Referenced by clang::Parser::TryAnnotateTypeOrScopeToken(), and clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec().
|
inline |
Definition at line 1280 of file Preprocessor.h.
References appendDefMacroDirective(), and clang::MacroInfo::getDefinitionLoc().
|
inline |
Definition at line 1274 of file Preprocessor.h.
References appendMacroDirective().
Referenced by appendDefMacroDirective(), and HandlePragmaPopMacro().
void Preprocessor::appendMacroDirective | ( | IdentifierInfo * | II, |
MacroDirective * | MD | ||
) |
Add a directive to the macro directive history for this identifier.
Definition at line 71 of file PPMacroExpansion.cpp.
References clang::MacroDirective::getPrevious(), clang::MacroDirective::isDefined(), clang::IdentifierInfo::isFromAST(), clang::IdentifierInfo::setChangedSinceDeserialization(), clang::IdentifierInfo::setHasMacroDefinition(), and clang::MacroDirective::setPrevious().
Referenced by appendDefMacroDirective(), and HandlePragmaPopMacro().
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().
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.
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 397 of file PPDirectives.cpp.
References clang::FixItHint::CreateInsertion(), Diag(), DiscardUntilEndOfDirective(), clang::SourceRange::getEnd(), clang::Token::getLocation(), clang::Token::is(), Lex(), and LexUnexpandedToken().
bool Preprocessor::CheckMacroName | ( | Token & | MacroNameTok, |
MacroUse | isDefineUndef, | ||
bool * | ShadowFlag = nullptr |
||
) |
Definition at line 296 of file PPDirectives.cpp.
References Diag(), clang::SourceManager::getBufferName(), clang::Token::getIdentifierInfo(), clang::Token::getKind(), getLangOpts(), clang::Token::getLocation(), getMacroInfo(), clang::IdentifierInfo::getPPKeywordID(), clang::Token::is(), clang::MacroInfo::isBuiltinMacro(), clang::IdentifierInfo::isCPlusPlusOperatorKeyword(), clang::SourceManager::isInSystemHeader(), MD_KeywordDef, MD_NoWarn, MD_ReservedMacro, clang::MU_Define, clang::MU_Other, clang::MU_Undef, shouldWarnOnMacroDef(), and shouldWarnOnMacroUndef().
Referenced by EvaluateDefined().
|
static |
Check that the given module is available, producing a diagnostic if not.
true
if the check failed (because the module is not available). false
if the module appears to be usable. Definition at line 1872 of file PPDirectives.cpp.
Referenced by prepareToBuildModule().
|
inline |
Clear out the code completion handler.
Definition at line 1428 of file Preprocessor.h.
Referenced by clang::Parser::~Parser().
void Preprocessor::CodeCompleteIncludedFile | ( | llvm::StringRef | Dir, |
bool | IsAngled | ||
) |
Hook used by the lexer to invoke the "included file" code completion point.
Definition at line 451 of file Preprocessor.cpp.
References clang::CodeCompletionHandler::CodeCompleteIncludedFile(), and setCodeCompletionReached().
void Preprocessor::CodeCompleteNaturalLanguage | ( | ) |
Hook used by the lexer to invoke the "natural language" code completion point.
Definition at line 458 of file Preprocessor.cpp.
References clang::CodeCompletionHandler::CodeCompleteNaturalLanguage(), and setCodeCompletionReached().
Referenced by clang::Lexer::ReadToEndOfLine().
void Preprocessor::CollectPpImportSuffix | ( | SmallVectorImpl< Token > & | Toks | ) |
Collect the tokens of a C++20 pp-import-suffix.
Definition at line 1087 of file Preprocessor.cpp.
References clang::comments::tok::eof, and Lex().
Referenced by LexAfterModuleImport().
void Preprocessor::CommitBacktrackedTokens | ( | ) |
Disable the last EnableBacktrackAtThisPos call.
Definition at line 32 of file PPCaching.cpp.
void Preprocessor::createPreprocessingRecord | ( | ) |
Create a new preprocessing record, which will keep track of all macro expansions, macro definitions, etc.
Definition at line 1473 of file Preprocessor.cpp.
References addPPCallbacks(), and getSourceManager().
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 489 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(), LexHeaderName(), and ParsePragmaPushOrPopMacro().
bool Preprocessor::creatingPCHWithPragmaHdrStop | ( | ) |
True if creating a PCH with a #pragma hdrstop.
Definition at line 627 of file Preprocessor.cpp.
References clang::TU_Prefix, and TUKind.
Referenced by HandlePragmaHdrstop().
bool Preprocessor::creatingPCHWithThroughHeader | ( | ) |
True if creating a PCH with a through header.
Definition at line 617 of file Preprocessor.cpp.
References clang::FileID::isValid(), clang::TU_Prefix, and TUKind.
Referenced by HandleEndOfFile().
|
inline |
Definition at line 1901 of file Preprocessor.h.
References clang::Token::getLocation(), and clang::DiagnosticsEngine::Report().
|
inline |
Forwarding function for diagnostics.
This emits a diagnostic at the specified Token's location, translating the token's start position in the current buffer into a SourcePosition object for rendering.
Definition at line 1897 of file Preprocessor.h.
References clang::DiagnosticsEngine::Report().
Referenced by clang::Sema::ActOnNumericConstant(), buildMSAsmString(), clang::CharLiteralParser::CharLiteralParser(), checkConfigMacro(), CheckEndOfDirective(), CheckMacroName(), clang::Lexer::Diag(), diagnoseAutoModuleImport(), diagnoseUnexpectedOperator(), EnterMainSourceFile(), EnterSourceFile(), EvaluateDefined(), EvaluateDirectiveSubExpr(), EvaluateFeatureLikeBuiltinMacro(), EvaluateHasIncludeCommon(), EvaluateValue(), ExpectFeatureIdentifierInfo(), FinishLexStringLiteral(), GetIncludeFilenameSpelling(), GetLineValue(), HandleDirective(), HandleEndOfFile(), HandleIdentifier(), HandlePoisonedIdentifier(), clang::PragmaNamespace::HandlePragma(), HandlePragmaDependency(), HandlePragmaHdrstop(), HandlePragmaIncludeAlias(), HandlePragmaModuleBuild(), HandlePragmaOnce(), HandlePragmaPoison(), HandlePragmaPopMacro(), HandlePragmaSystemHeader(), LexAfterModuleImport(), LexHeaderName(), LexModuleNameComponent(), LexOnOffSwitch(), makeModuleVisible(), ParseAlignPragma(), ParseLoopHintValue(), ParsePragmaPushOrPopMacro(), clang::Parser::ParseTopLevelDecl(), ReadLineMarkerFlags(), and SkipTokensWhileUsingPCH().
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 83 of file PPDirectives.cpp.
References clang::comments::tok::eof, clang::Token::getLocation(), clang::Token::isNot(), LexUnexpandedToken(), clang::SourceRange::setBegin(), and clang::SourceRange::setEnd().
Referenced by CheckEndOfDirective(), GetLineValue(), HandleDirective(), HandlePragmaModuleBuild(), HandleSkippedDirectiveWhileUsingPCH(), and ReadLineMarkerFlags().
void Preprocessor::DumpLocation | ( | SourceLocation | Loc | ) | const |
Definition at line 261 of file Preprocessor.cpp.
References clang::SourceLocation::print().
Referenced by DumpToken().
void Preprocessor::DumpMacro | ( | const MacroInfo & | MI | ) | const |
Definition at line 265 of file Preprocessor.cpp.
References DumpToken(), clang::MacroInfo::getNumTokens(), and clang::MacroInfo::getReplacementToken().
void Preprocessor::dumpMacroInfo | ( | const IdentifierInfo * | II | ) |
Definition at line 258 of file PPMacroExpansion.cpp.
References clang::MacroInfo::dump(), clang::IdentifierInfo::getNameStart(), and State.
Print the token to stderr, used for debugging.
Definition at line 235 of file Preprocessor.cpp.
References DumpLocation(), clang::SourceManager::getCharacterData(), clang::Token::getKind(), clang::Token::getLength(), clang::Token::getLocation(), getSpelling(), clang::tok::getTokenName(), clang::Token::hasLeadingSpace(), clang::Token::isAnnotation(), clang::Token::isAtStartOfLine(), clang::Token::isExpandDisabled(), and clang::Token::needsCleaning().
Referenced by DumpMacro(), clang::DumpRawTokensAction::ExecuteAction(), and clang::DumpTokensAction::ExecuteAction().
|
inline |
Definition at line 2674 of file Preprocessor.h.
References Identifier.
Referenced by EvaluateDefined().
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.
Enables the incremental processing.
Definition at line 1781 of file Preprocessor.h.
References getLangOpts().
void Preprocessor::EndSourceFile | ( | ) |
Inform the preprocessor callbacks that processing is complete.
Definition at line 700 of file Preprocessor.cpp.
Referenced by clang::FrontendAction::EndSourceFile().
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 1785 of file PPDirectives.cpp.
References clang::Token::setAnnotationEndLoc(), clang::Token::setAnnotationValue(), clang::Token::setKind(), clang::Token::setLocation(), and clang::Token::startToken().
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.
Args | specifies the tokens input to a function-like macro. |
ILEnd | specifies 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.
void Preprocessor::EnterMainSourceFile | ( | ) |
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
EnterMainSourceFile - Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
Definition at line 545 of file Preprocessor.cpp.
References clang::SrcMgr::C_User, clang::SourceManager::createFileID(), Diag(), EnterSourceFile(), clang::File, clang::SourceManager::getFileEntryForID(), clang::SourceManager::getMainFileID(), clang::SourceManager::isLoadedFileID(), clang::FileID::isValid(), LookupFile(), markIncluded(), SkipTokensWhileUsingPCH(), usingPCHWithPragmaHdrStop(), and usingPCHWithThroughHeader().
Referenced by DoPrintMacros(), clang::DoPrintPreprocessedInput(), clang::IncrementalAction::ExecuteAction(), clang::DumpTokensAction::ExecuteAction(), clang::PreprocessOnlyAction::ExecuteAction(), clang::RewriteIncludesInInput(), and clang::RewriteMacrosInInput().
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(), isCodeCompletionEnabled(), and string().
Referenced by EnterMainSourceFile().
void Preprocessor::EnterSubmodule | ( | Module * | M, |
SourceLocation | ImportLoc, | ||
bool | ForPragma | ||
) |
Definition at line 685 of file PPLexerChange.cpp.
References getHeaderSearchInfo(), getLangOpts(), clang::HeaderSearch::getModuleMap(), makeModuleVisible(), clang::ModuleMap::resolveConflicts(), clang::ModuleMap::resolveExports(), clang::ModuleMap::resolveUses(), and State.
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 1693 of file Preprocessor.h.
Referenced by FixDigraph(), and clang::Parser::TryAnnotateTypeOrScopeToken().
|
inline |
Definition at line 1543 of file Preprocessor.h.
|
inline |
Definition at line 1537 of file Preprocessor.h.
void Preprocessor::FinalizeForModelFile | ( | ) |
Cleanup after model file parsing.
Definition at line 229 of file Preprocessor.cpp.
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 1334 of file Preprocessor.cpp.
References Diag(), Lex(), LexUnexpandedToken(), and string().
Referenced by LexStringLiteral().
|
inline |
Get the set of top-level clang modules that affected preprocessing, but were not imported.
Definition at line 1340 of file Preprocessor.h.
Referenced by clang::tooling::dependencies::ModuleDepCollectorPP::EndOfMainFile().
|
inline |
Definition at line 1062 of file Preprocessor.h.
|
inline |
Get the list of submodules that we're currently building.
Definition at line 1305 of file Preprocessor.h.
|
inline |
Definition at line 1070 of file Preprocessor.h.
Referenced by clang::FrontendAction::BeginSourceFile(), clang::CompilerInstance::createASTContext(), and clang::createChainedIncludesSource().
|
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 1816 of file Preprocessor.h.
|
inline |
Get the code completion token for filtering purposes.
Definition at line 1456 of file Preprocessor.h.
|
inline |
Retrieve the current code-completion handler.
Definition at line 1423 of file Preprocessor.h.
Referenced by EvaluateDefined(), and EvaluateValue().
|
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 1810 of file Preprocessor.h.
|
inline |
Definition at line 1451 of file Preprocessor.h.
|
inline |
Definition at line 1105 of file Preprocessor.h.
Referenced by HandleComment(), PrintPreprocessedTokens(), and clang::Lexer::resetExtendedTokenMode().
|
inline |
Definition at line 2179 of file Preprocessor.h.
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().
|
inline |
Definition at line 2182 of file Preprocessor.h.
References clang::LangOptions::FEM_UnsetOnCommandLine.
Referenced by clang::Sema::ActOnPragmaFloatControl().
|
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 1137 of file Preprocessor.h.
|
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 1147 of file Preprocessor.h.
Module * Preprocessor::getCurrentModule | ( | ) |
Retrieves the module that we're currently building, if any.
Definition at line 525 of file Preprocessor.cpp.
References getHeaderSearchInfo(), getLangOpts(), and clang::HeaderSearch::lookupModule().
Referenced by clang::Sema::ActOnEndOfTranslationUnit(), HandleEndOfFile(), LookupFile(), and markIdentifierFromAST().
Module * Preprocessor::getCurrentModuleImplementation | ( | ) |
Retrieves the module whose implementation we're current compiling, if any.
Definition at line 532 of file Preprocessor.cpp.
References getHeaderSearchInfo(), getLangOpts(), and clang::HeaderSearch::lookupModule().
Referenced by clang::tooling::dependencies::ModuleDepCollector::applyDiscoveredDependencies().
|
inline |
Definition at line 1057 of file Preprocessor.h.
Referenced by clang::Sema::ActOnNumericConstant(), clang::AttachHeaderIncludeGen(), clang::CharLiteralParser::CharLiteralParser(), clang::ento::CreateAnalysisConsumer(), EnableCodeCompletion(), EvaluateValue(), clang::PCHGenerator::HandleTranslationUnit(), HasExtension(), parseSimpleIntegerLiteral(), and setCodeCompletionReached().
|
inline |
Definition at line 1407 of file Preprocessor.h.
|
inline |
Definition at line 1077 of file Preprocessor.h.
Referenced by isTrivialSingleTokenExpansion().
|
inline |
Definition at line 1063 of file Preprocessor.h.
Referenced by EnableCodeCompletion().
|
inline |
Definition at line 1065 of file Preprocessor.h.
Referenced by clang::Sema::ActOnEndOfTranslationUnit(), clang::tooling::dependencies::ModuleDepCollector::applyDiscoveredDependencies(), clang::DependencyCollector::attachToPreprocessor(), clang::ModuleDependencyCollector::attachToPreprocessor(), compileModule(), clang::CompilerInstance::createPCHExternalASTSource(), clang::FrontendAction::EndSourceFile(), EnterSubmodule(), EvaluateHasIncludeCommon(), clang::FrontendAction::Execute(), clang::FrontendAction::getCurrentModule(), getCurrentModule(), getCurrentModuleImplementation(), getHeaderNameForHeader(), getHeaderToIncludeForDiagnostics(), getInputBufferForModule(), getTopImportImplicitModule(), clang::VerifyDiagnosticConsumer::HandleDiagnostic(), HandlePragmaIncludeAlias(), clang::PCHGenerator::HandleTranslationUnit(), clang::CompilerInstance::loadGlobalModuleIndex(), clang::CompilerInstance::loadModule(), loadModuleMapForModuleBuild(), and prepareToBuildModule().
const FileEntry * 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.
IncLoc | The location at which the missing effect was detected. |
MLoc | A location within an unimported module at which the desired effect occurred. |
Definition at line 861 of file PPDirectives.cpp.
References clang::ModuleMap::ExcludedHeader, clang::HeaderSearch::findAllModulesForHeader(), getHeaderSearchInfo(), getLangOpts(), getModuleForLocation(), getSourceManager(), clang::HeaderSearch::hasModuleMap(), clang::SourceManager::isInSystemHeader(), clang::SourceLocation::isInvalid(), SM, and clang::ModuleMap::TextualHeader.
Referenced by clang::Sema::diagnoseMissingImport().
|
inline |
Return information about the specified preprocessor identifier token.
Definition at line 1378 of file Preprocessor.h.
Referenced by checkConfigMacro(), DiagnoseCallingConvCast(), clang::Sema::DiagnoseOwningPropertyGetterSynthesis(), fixSeparateAttrArgAndNumber(), getFallthroughAttrSpelling(), clang::Sema::getNSErrorIdent(), clang::Sema::getNullabilityKeyword(), clang::Parser::Initialize(), clang::Sema::Initialize(), Lex(), LexAfterModuleImport(), LexModuleNameComponent(), LookUpIdentifierInfo(), and clang::ento::tryExpandAsInteger().
|
inline |
Definition at line 1067 of file Preprocessor.h.
Referenced by clang::Sema::ActOnClassPropertyRefExpr(), clang::Sema::ActOnOpenMPTileDirective(), clang::Sema::ActOnOpenMPUnrollDirective(), clang::FrontendAction::BeginSourceFile(), BuildNonArrayForRange(), clang::CompilerInstance::createASTContext(), clang::createChainedIncludesSource(), clang::Sema::DeclareGlobalNewDelete(), clang::FrontendAction::EndSourceFile(), clang::ASTReader::getIdentifierTable(), clang::Sema::getOrCreateStdNamespace(), clang::Sema::HandleExprPropertyRefExpr(), HandleIdentifier(), clang::Parser::Initialize(), clang::Sema::isStdInitializerList(), clang::Sema::lookupCoroutineTraits(), and clang::Sema::lookupStdExperimentalNamespace().
|
inline |
Definition at line 1068 of file Preprocessor.h.
|
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 1988 of file Preprocessor.h.
References clang::Lexer::getImmediateMacroName(), and getLangOpts().
Referenced by lookThroughRangesV3Condition().
|
inline |
Get the set of included files.
Definition at line 1357 of file Preprocessor.h.
|
inline |
Definition at line 1358 of file Preprocessor.h.
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.
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 1737 of file PPDirectives.cpp.
References Diag().
Referenced by EvaluateHasIncludeCommon(), HandlePragmaDependency(), and HandlePragmaIncludeAlias().
|
inline |
Definition at line 1060 of file Preprocessor.h.
Referenced by clang::Sema::ActOnNumericConstant(), AddFunctionParameterChunks(), clang::TokenConcatenation::AvoidConcat(), clang::FrontendAction::BeginSourceFile(), clang::CharLiteralParser::CharLiteralParser(), CheckMacroName(), clang::createChainedIncludesSource(), clang::DoPrintPreprocessedInput(), EmitAlphaCounter(), emitPremigrationErrors(), enableIncrementalProcessing(), EnterSubmodule(), EvaluateDirectiveSubExpr(), EvaluateValue(), clang::DumpRawTokensAction::ExecuteAction(), FindLocsWithCommonFileID(), getCurrentModule(), getCurrentModuleImplementation(), getFallthroughAttrSpelling(), getHeaderToIncludeForDiagnostics(), getImmediateMacroName(), getIssueHash(), clang::Parser::getLangOpts(), getModuleForLocation(), HandleDirective(), HandleIdentifier(), HandlePragmaOnce(), clang::PCHGenerator::HandleTranslationUnit(), Initialize(), clang::ASTReader::isGlobalIndexUnavailable(), isIncrementalProcessingEnabled(), isInterestingIdentifier(), isMacroDefined(), LeaveSubmodule(), clang::TokenLexer::Lex(), Lex(), LexAfterModuleImport(), LexRawTokensFromMainFile(), clang::ASTReader::loadGlobalIndex(), MaybeAddSentinel(), ParseAlignPragma(), parseSimpleIntegerLiteral(), PrintPreprocessedTokens(), clang::RewriteMacrosInInput(), shouldWarnOnMacroDef(), shouldWarnOnMacroUndef(), and clang::TokenConcatenation::TokenConcatenation().
|
inline |
Get the location of the last cached token, suitable for setting the end location of an annotation token.
Definition at line 1723 of file Preprocessor.h.
Referenced by IsPreviousCachedToken().
|
inline |
Definition at line 2197 of file Preprocessor.h.
Referenced by clang::Sema::ActOnPragmaFloatControl().
|
inline |
Definition at line 2193 of file Preprocessor.h.
Referenced by clang::Sema::ActOnPragmaFloatControl(), and clang::Sema::ActOnPragmaFPReassociate().
StringRef Preprocessor::getLastMacroWithSpelling | ( | SourceLocation | Loc, |
ArrayRef< TokenValue > | Tokens | ||
) | const |
Return the name of the macro defined before Loc
that has spelling Tokens
.
If there are multiple macros with same spelling, return the last one defined.
Definition at line 357 of file Preprocessor.cpp.
Referenced by DiagnoseCallingConvCast(), clang::Sema::DiagnoseOwningPropertyGetterSynthesis(), and getFallthroughAttrSpelling().
|
inline |
Get the list of leaf (non-overridden) module macros for a name.
Definition at line 1295 of file Preprocessor.h.
References clang::IdentifierInfo::isOutOfDate().
Referenced by indexPreprocessorModuleMacros().
|
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 1242 of file Preprocessor.h.
References getLocalMacroDirectiveHistory(), and clang::IdentifierInfo::hasMacroDefinition().
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().
|
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.
Offset | an 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 2021 of file Preprocessor.h.
References clang::Lexer::getLocForEndOfToken(), and Offset.
Referenced by clang::Sema::DiagnoseCommaOperator(), EvaluateHasIncludeCommon(), GenerateNewArgTokens(), clang::Parser::getEndOfPreviousToken(), and clang::Parser::ParseConstraintLogicalAndExpression().
|
inline |
Definition at line 2670 of file Preprocessor.h.
|
inline |
Definition at line 1212 of file Preprocessor.h.
References clang::IdentifierInfo::hasMacroDefinition().
Referenced by EvaluateDefined(), getMacroInfo(), HandleIdentifier(), and isMacroDefined().
|
inline |
Definition at line 1225 of file Preprocessor.h.
References clang::IdentifierInfo::hadMacroDefinition().
|
inline |
Definition at line 1257 of file Preprocessor.h.
References getMacroDefinition(), and clang::IdentifierInfo::hasMacroDefinition().
|
inline |
Definition at line 1253 of file Preprocessor.h.
Referenced by checkConfigMacro(), CheckMacroName(), clang::Sema::getPrintingPolicy(), HandleEndOfFile(), HandlePragmaPopMacro(), HandlePragmaPushMacro(), isTrivialSingleTokenExpansion(), and clang::ento::tryExpandAsInteger().
|
inline |
Get the max number of tokens before issuing a -Wmax-tokens warning.
Definition at line 1170 of file Preprocessor.h.
Referenced by clang::Parser::ParseTopLevelDecl().
|
inline |
Definition at line 1177 of file Preprocessor.h.
Referenced by clang::Parser::ParseTopLevelDecl().
Module * Preprocessor::getModuleForLocation | ( | SourceLocation | Loc, |
bool | AllowTextual | ||
) |
Find the module that owns the source or header file that Loc
points to.
If the location is in a file that was included into a module, or is outside any module, returns nullptr.
Definition at line 839 of file PPDirectives.cpp.
References clang::LangOptions::CurrentModule, clang::ModuleMap::findModuleForHeader(), clang::SourceManager::getExpansionLoc(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getFileID(), getLangOpts(), clang::ModuleMap::KnownHeader::getModule(), clang::HeaderSearch::getModuleMap(), clang::SourceManager::isInMainFile(), and clang::HeaderSearch::lookupModule().
Referenced by getHeaderToIncludeForDiagnostics(), and LookupFile().
|
inline |
Definition at line 1592 of file Preprocessor.h.
|
inline |
Retrieve the module loader associated with this preprocessor.
Definition at line 1082 of file Preprocessor.h.
Referenced by clang::PCHGenerator::HandleTranslationUnit().
ModuleMacro * Preprocessor::getModuleMacro | ( | Module * | Mod, |
const IdentifierInfo * | II | ||
) |
Definition at line 171 of file PPMacroExpansion.cpp.
References clang::ModuleMacro::Profile().
|
inline |
Retrieve the number of Directives that have been processed by the Preprocessor.
Definition at line 1090 of file Preprocessor.h.
|
inline |
Accessors for preprocessor callbacks.
Note that this class takes ownership of any PPCallbacks object given to it.
Definition at line 1157 of file Preprocessor.h.
Referenced by EvaluateDefined(), and EvaluateHasIncludeCommon().
|
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 1837 of file Preprocessor.h.
Referenced by clang::Sema::AddCFAuditedAttribute().
|
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 1852 of file Preprocessor.h.
|
inline |
Definition at line 1108 of file Preprocessor.h.
|
inline |
Definition at line 2575 of file Preprocessor.h.
|
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 1867 of file Preprocessor.h.
|
inline |
Definition at line 2590 of file Preprocessor.h.
|
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 1369 of file Preprocessor.h.
|
inline |
Returns the FileID for the preprocessor predefines.
Definition at line 1150 of file Preprocessor.h.
Referenced by checkConfigMacro(), HandleEndOfFile(), clang::RewriteIncludesInInput(), shouldIgnoreMacro(), and SkipTokensWhileUsingPCH().
|
inline |
Retrieve the preprocessing record, or NULL if there is no preprocessing record.
Definition at line 1464 of file Preprocessor.h.
Referenced by clang::ASTUnit::getLocalPreprocessingEntities().
|
inline |
Definition at line 1071 of file Preprocessor.h.
Referenced by clang::ModuleMacro::create(), ParseAlignPragma(), and ParseLoopHintValue().
|
inline |
Retrieve the preprocessor options used to initialize this preprocessor.
Definition at line 1055 of file Preprocessor.h.
Referenced by ComputeDATE_TIME(), and EnterSourceFile().
|
inline |
Relex the token at the specified location.
Definition at line 1957 of file Preprocessor.h.
References clang::Lexer::getRawToken().
Referenced by UseNSOptionsMacro().
|
inline |
Definition at line 1069 of file Preprocessor.h.
Referenced by clang::Sema::ActOnClassPropertyRefExpr(), clang::CompilerInstance::createASTContext(), and clang::Sema::HandleExprPropertyRefExpr().
|
inline |
Definition at line 1064 of file Preprocessor.h.
Referenced by clang::Sema::ActOnNumericConstant(), AddFunctionParameterChunks(), clang::ModuleDependencyCollector::attachToPreprocessor(), clang::TokenConcatenation::AvoidConcat(), clang::CharLiteralParser::CharLiteralParser(), checkConfigMacro(), 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(), GetMappedTokenLoc(), clang::VerifyDiagnosticConsumer::HandleComment(), clang::TokenLexer::Init(), 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().
|
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.
Invalid | If non-null, will be set true if an error occurs. |
Definition at line 1926 of file Preprocessor.h.
References clang::Lexer::getSpelling().
|
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 1942 of file Preprocessor.h.
References clang::Lexer::getSpelling().
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 467 of file Preprocessor.cpp.
References clang::Token::getIdentifierInfo(), clang::Token::getLength(), getSpelling(), clang::Token::hasUCN(), clang::Token::isNot(), and clang::Token::needsCleaning().
|
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.
buffer | A buffer which will be used only if the token requires "cleaning", e.g. if it contains trigraphs or escaped newlines |
invalid | If non-null, will be set true if an error occurs. |
Definition at line 1912 of file Preprocessor.h.
References clang::Lexer::getSpelling().
Referenced by clang::Sema::ActOnCharacterConstant(), clang::Sema::ActOnNumericConstant(), buildMSAsmString(), DumpToken(), dumpTokenInto(), EvaluateHasIncludeCommon(), EvaluateValue(), GetFirstChar(), GetLineValue(), getSpelling(), HandlePragmaDependency(), HandlePragmaIncludeAlias(), clang::MacroInfo::isIdenticalTo(), isMapModifier(), isMapType(), LexHeaderName(), LookUpIdentifierInfo(), ParsePragmaPushOrPopMacro(), parseSimpleIntegerLiteral(), PrintMacroDefinition(), and clang::RewriteMacrosInInput().
|
inline |
Given a Token Tok
that is a numeric constant with length 1, return the character.
Definition at line 1965 of file Preprocessor.h.
References clang::Token::getLength(), clang::Token::getLiteralData(), clang::Token::getLocation(), clang::Token::is(), and clang::Token::needsCleaning().
Referenced by clang::Sema::ActOnNumericConstant().
|
inline |
Definition at line 1114 of file Preprocessor.h.
|
inline |
Definition at line 1061 of file Preprocessor.h.
References clang::Target.
Referenced by clang::Sema::ActOnNumericConstant(), clang::CharLiteralParser::CharLiteralParser(), EvaluateValue(), clang::Parser::getTargetInfo(), Initialize(), and parseSimpleIntegerLiteral().
|
inline |
Get the number of tokens processed so far.
Definition at line 1167 of file Preprocessor.h.
Referenced by clang::Parser::ParseTopLevelDecl().
size_t Preprocessor::getTotalMemory | ( | ) | const |
Definition at line 327 of file Preprocessor.cpp.
Referenced by PrintStats().
|
inline |
Definition at line 2189 of file Preprocessor.h.
|
inline |
Definition at line 1084 of file Preprocessor.h.
References clang::ModuleLoader::HadFatalFailure.
bool Preprocessor::HandleComment | ( | Token & | result, |
SourceRange | Comment | ||
) |
Definition at line 1409 of file Preprocessor.cpp.
References getCommentRetentionState(), and Lex().
void Preprocessor::HandleDirective | ( | Token & | Result | ) |
Callback invoked when the lexer sees a # token at the start of a line.
HandleDirective - This callback is invoked when the lexer sees a # token at the start of a line.
This consumes the directive, modifies the lexer/preprocessor state, and advances the lexer(s) so that the next token read is the correct one.
Definition at line 1117 of file PPDirectives.cpp.
References clang::CodeCompletionHandler::CodeCompleteDirective(), Diag(), DiscardUntilEndOfDirective(), clang::PreprocessorLexer::getConditionalStackDepth(), clang::MultipleIncludeOpt::getHasReadAnyTokensVal(), clang::Token::getIdentifierInfo(), clang::MultipleIncludeOpt::getImmediatelyAfterTopLevelIfndef(), clang::Decl::getKind(), getLangOpts(), clang::Token::getLocation(), clang::IdentifierInfo::getPPKeywordID(), HandleSkippedDirectiveWhileUsingPCH(), LexUnexpandedToken(), clang::PreprocessorLexer::MIOpt, clang::PreprocessorLexer::ParsingPreprocessorDirective, clang::PIK_HashPragma, clang::dependency_directives_scan::pp___include_macros, clang::dependency_directives_scan::pp_define, clang::dependency_directives_scan::pp_elif, clang::dependency_directives_scan::pp_elifdef, clang::dependency_directives_scan::pp_elifndef, clang::dependency_directives_scan::pp_else, clang::dependency_directives_scan::pp_endif, clang::dependency_directives_scan::pp_if, clang::dependency_directives_scan::pp_ifdef, clang::dependency_directives_scan::pp_ifndef, clang::dependency_directives_scan::pp_import, clang::dependency_directives_scan::pp_include, clang::dependency_directives_scan::pp_include_next, clang::dependency_directives_scan::pp_undef, clang::MultipleIncludeOpt::resetImmediatelyAfterTopLevelIfndef(), and setCodeCompletionReached().
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::comments::tok::eof, 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(), clang::Decl::getLocation(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), getMacroInfo(), clang::MultipleIncludeOpt::GetMacroLocation(), getPredefinesFileID(), clang::PreprocessorLexer::getSourceLocation(), isCodeCompletionEnabled(), isIncrementalProcessingEnabled(), isInPrimaryFile(), isMacroDefined(), isPCHThroughHeader(), isRecordingPreamble(), clang::FileID::isValid(), clang::SourceLocation::isValid(), LeaveSubmodule(), clang::SourceManager::local_sloc_entry_size(), max(), clang::PreprocessorLexer::MIOpt, recomputeCurLexerKind(), RemoveTopOfLexerStack(), clang::HeaderSearch::SetFileControllingMacro(), clang::Decl::setLocation(), clang::SourceManager::setNumCreatedFIDsForFileID(), clang::TU_Complete, and TUKind.
Referenced by HandleEndOfTokenLexer().
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 587 of file PPLexerChange.cpp.
References HandleEndOfFile().
Referenced by HandleMicrosoftCommentPaste(), and clang::TokenLexer::Lex().
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').
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 790 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().
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 625 of file PPLexerChange.cpp.
References clang::comments::tok::eof, HandleEndOfTokenLexer(), clang::Token::is(), clang::Token::isNot(), Lex(), clang::PreprocessorLexer::LexingRawMode, and clang::PreprocessorLexer::ParsingPreprocessorDirective.
void Preprocessor::HandlePoisonedIdentifier | ( | Token & | Identifier | ) |
Display reason for poisoned identifier.
Definition at line 766 of file Preprocessor.cpp.
References Diag(), and Identifier.
Referenced by HandleIdentifier(), clang::TokenLexer::Lex(), and MaybeHandlePoisonedIdentifier().
void Preprocessor::HandlePragmaDependency | ( | Token & | DependencyTok | ) |
HandlePragmaDependency - Handle #pragma GCC dependency "foo" blah.
Definition at line 505 of file Pragma.cpp.
References Diag(), clang::File, Filename, getCurrentFileLexer(), clang::PreprocessorLexer::getFileEntry(), GetIncludeFilenameSpelling(), clang::Token::getLocation(), clang::FileEntry::getModificationTime(), getSpelling(), clang::Token::isNot(), Lex(), LexHeaderName(), LookupFile(), and string().
void Preprocessor::HandlePragmaHdrstop | ( | Token & | Tok | ) |
Definition at line 870 of file Pragma.cpp.
References creatingPCHWithPragmaHdrStop(), Diag(), clang::comments::tok::eof, clang::Token::getLocation(), clang::Token::is(), clang::SourceManager::isInMainFile(), clang::Token::isNot(), Lex(), LexStringLiteral(), string(), and usingPCHWithPragmaHdrStop().
Referenced by HandleSkippedDirectiveWhileUsingPCH().
void Preprocessor::HandlePragmaIncludeAlias | ( | Token & | Tok | ) |
Definition at line 674 of file Pragma.cpp.
References clang::HeaderSearch::AddIncludeAlias(), Diag(), getHeaderSearchInfo(), GetIncludeFilenameSpelling(), clang::Token::getLocation(), getSpelling(), clang::Token::is(), clang::Token::isNot(), Lex(), and LexHeaderName().
void Preprocessor::HandlePragmaMark | ( | Token & | MarkTok | ) |
Definition at line 421 of file Pragma.cpp.
References clang::Token::getLocation().
void Preprocessor::HandlePragmaModuleBuild | ( | Token & | Tok | ) |
Definition at line 796 of file Pragma.cpp.
References clang::ModuleLoader::createModuleFromSource(), Diag(), DiscardUntilEndOfDirective(), End, clang::comments::tok::eof, clang::Token::getKind(), clang::Token::getLocation(), clang::IdentifierInfo::getName(), clang::Token::getRawIdentifier(), clang::Token::is(), clang::Token::isAtStartOfLine(), clang::Token::isNot(), LexModuleNameComponent(), and LexUnexpandedToken().
void Preprocessor::HandlePragmaOnce | ( | Token & | OnceTok | ) |
HandlePragmaOnce - Handle #pragma once. OnceTok is the 'once'.
Definition at line 406 of file Pragma.cpp.
References Diag(), getCurrentFileLexer(), getLangOpts(), IsHeaderFile(), isInPrimaryFile(), clang::HeaderSearch::MarkFileIncludeOnce(), clang::TU_Prefix, and TUKind.
void Preprocessor::HandlePragmaPoison | ( | ) |
HandlePragmaPoison - Handle #pragma GCC poison. PoisonTok is the 'poison'.
Definition at line 431 of file Pragma.cpp.
References Diag(), clang::Token::is(), clang::IdentifierInfo::isFromAST(), isMacroDefined(), clang::Token::isNot(), clang::IdentifierInfo::isPoisoned(), clang::PreprocessorLexer::LexingRawMode, LexUnexpandedToken(), LookUpIdentifierInfo(), clang::IdentifierInfo::setChangedSinceDeserialization(), and clang::IdentifierInfo::setIsPoisoned().
void Preprocessor::HandlePragmaPopMacro | ( | Token & | PopMacroTok | ) |
Handle #pragma pop_macro.
The syntax is:
Definition at line 639 of file Pragma.cpp.
References appendDefMacroDirective(), appendMacroDirective(), Diag(), clang::Token::getLocation(), getMacroInfo(), clang::IdentifierInfo::getName(), and ParsePragmaPushOrPopMacro().
void Preprocessor::HandlePragmaPushMacro | ( | Token & | PushMacroTok | ) |
Handle #pragma push_macro.
The syntax is:
Definition at line 616 of file Pragma.cpp.
References getMacroInfo(), ParsePragmaPushOrPopMacro(), and clang::MacroInfo::setIsAllowRedefinitionsWithoutWarning().
void Preprocessor::HandlePragmaSystemHeader | ( | Token & | SysHeaderTok | ) |
HandlePragmaSystemHeader - Implement #pragma GCC system_header.
We know that the whole directive has been parsed.
Definition at line 473 of file Pragma.cpp.
References clang::SourceManager::AddLineNote(), clang::SrcMgr::C_System, Diag(), getCurrentFileLexer(), clang::PreprocessorLexer::getFileEntry(), clang::PresumedLoc::getFilename(), clang::PresumedLoc::getLine(), clang::SourceManager::getLineTableFilenameID(), clang::Token::getLocation(), clang::SourceManager::getPresumedLoc(), isInPrimaryFile(), clang::PresumedLoc::isInvalid(), clang::HeaderSearch::MarkFileSystemHeader(), and clang::PPCallbacks::SystemHeaderPragma.
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 1092 of file PPDirectives.cpp.
References DiscardUntilEndOfDirective(), HandlePragmaHdrstop(), Lex(), clang::dependency_directives_scan::pp_define, and clang::dependency_directives_scan::pp_include.
Referenced by HandleDirective().
|
inline |
Definition at line 2571 of file Preprocessor.h.
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 2155 of file Pragma.cpp.
References AddPragmaHandler().
Referenced by DoPrintMacros(), clang::PreprocessOnlyAction::ExecuteAction(), and clang::RewriteIncludesInInput().
|
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 2063 of file Preprocessor.h.
void Preprocessor::Initialize | ( | const TargetInfo & | Target, |
const TargetInfo * | AuxTarget = nullptr |
||
) |
Initialize the preprocessor using information about the target.
Target | is owned by the caller and must remain valid for the lifetime of the preprocessor. |
AuxTarget | is owned by the caller and must remain valid for the lifetime of the preprocessor. |
Definition at line 184 of file Preprocessor.cpp.
References clang::IdentifierTable::AddKeywords(), clang::LangOptions::FEM_Indeterminable, clang::LangOptions::FEM_UnsetOnCommandLine, getLangOpts(), getTargetInfo(), setCurrentFPEvalMethod(), clang::HeaderSearch::setTarget(), setTUFPEvalMethod(), and clang::Target.
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 217 of file Preprocessor.cpp.
|
inline |
Returns true if the given MacroID location points at the last token of the macro expansion.
MacroEnd | If non-null and function returns true, it is set to end location of the macro. |
Definition at line 2041 of file Preprocessor.h.
References clang::Lexer::isAtEndOfMacroExpansion().
|
inline |
Returns true if the given MacroID location points at the first token of the macro expansion.
MacroBegin | If non-null and function returns true, it is set to begin location of the macro. |
Definition at line 2030 of file Preprocessor.h.
References clang::Lexer::isAtStartOfMacroExpansion().
|
inline |
True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
Definition at line 1579 of file Preprocessor.h.
Referenced by AnnotateCachedTokens(), ReplaceLastTokenWithAnnotation(), RevertCachedTokens(), and TypoCorrectToken().
|
inline |
Determine if we are performing code completion.
Definition at line 1804 of file Preprocessor.h.
Referenced by clang::Sema::ActOnBlockStmtExpr(), clang::Sema::ActOnEndOfTranslationUnit(), EnterSourceFile(), HandleEndOfFile(), clang::Parser::Parser(), and setCodeCompletionReached().
|
inline |
Returns true if code-completion is enabled and we have hit the code-completion point.
Definition at line 1822 of file Preprocessor.h.
Referenced by ProduceSignatureHelp().
|
inline |
Return true if we are lexing directly from the specified lexer.
Definition at line 1129 of file Preprocessor.h.
|
inline |
Returns true if incremental processing is enabled.
Definition at line 1776 of file Preprocessor.h.
References getLangOpts().
Referenced by clang::Sema::ActOnEndOfTranslationUnit(), HandleEndOfFile(), clang::IncrementalParser::Parse(), and clang::Parser::ParseTopLevelDecl().
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().
|
inline |
Definition at line 1191 of file Preprocessor.h.
References bool, getLangOpts(), getMacroDefinition(), and clang::IdentifierInfo::hasMacroDefinition().
|
inline |
Definition at line 1188 of file Preprocessor.h.
References clang::IdentifierTable::get(), and Id.
Referenced by clang::Sema::CheckPtrComparisonWithNullChar(), clang::arcmt::trans::getNilString(), HandleEndOfFile(), HandlePragmaPoison(), MaybeAddSentinel(), and clang::HeaderSearch::ShouldEnterIncludeFile().
|
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 1199 of file Preprocessor.h.
References clang::IdentifierInfo::hasMacroDefinition().
Referenced by clang::HeaderSearch::ShouldEnterIncludeFile().
|
inline |
True if we are currently preprocessing a if or #elif directive.
Definition at line 1095 of file Preprocessor.h.
Referenced by EvaluateHasIncludeCommon().
Returns true if the FileEntry is the PCH through header.
Definition at line 611 of file Preprocessor.cpp.
References clang::SourceManager::getFileEntryForID(), and clang::FileID::isValid().
Referenced by HandleEndOfFile().
|
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 1126 of file Preprocessor.h.
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().
|
inline |
Definition at line 2567 of file Preprocessor.h.
Referenced by HandleEndOfFile().
Definition at line 762 of file PPLexerChange.cpp.
References addModuleMacro(), getLangOpts(), clang::MacroDirective::getPrevious(), clang::Module::getTopLevelModuleName(), and makeModuleVisible().
Referenced by HandleEndOfFile().
void Preprocessor::Lex | ( | Token & | Result | ) |
Lex the next token for this preprocessor.
Definition at line 882 of file Preprocessor.cpp.
References clang::Decl::getEndLoc(), getIdentifierInfo(), clang::Decl::getKind(), getLangOpts(), clang::Decl::getLocation(), clang::ModuleLoader::HadFatalFailure, clang::Token::IsReinjected, LexAfterModuleImport(), setCodeCompletionIdentifierInfo(), and setCodeCompletionTokenRange().
Referenced by CheckEndOfDirective(), CollectPpImportSuffix(), clang::Parser::ConsumeToken(), DoPrintMacros(), clang::DoPrintPreprocessedInput(), EvaluateFeatureLikeBuiltinMacro(), clang::DumpTokensAction::ExecuteAction(), clang::PreprocessOnlyAction::ExecuteAction(), FinishLexStringLiteral(), FixDigraph(), HandleComment(), HandleMicrosoftCommentPaste(), HandlePragmaDependency(), HandlePragmaHdrstop(), HandlePragmaIncludeAlias(), HandleSkippedDirectiveWhileUsingPCH(), LexAfterModuleImport(), LexHeaderName(), clang::PreprocessorLexer::LexIncludeFilename(), LexNonComment(), LexStringLiteral(), LexUnexpandedToken(), ParseAlignPragma(), ParseLoopHintValue(), ParsePragmaPushOrPopMacro(), parseSimpleIntegerLiteral(), PrintPreprocessedTokens(), ReadLineMarkerFlags(), clang::RewriteIncludesInInput(), clang::RewriteMacrosInInput(), clang::Parser::TryAnnotateTypeOrScopeToken(), and clang::Parser::TryConsumeToken().
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 1141 of file Preprocessor.cpp.
References CollectPpImportSuffix(), Diag(), clang::comments::tok::eof, getIdentifierInfo(), clang::Decl::getKind(), getLangOpts(), clang::Decl::getLocation(), clang::ModuleLoader::HadFatalFailure, clang::Module::Hidden, clang::SourceLocation::isMacroID(), Lex(), LexHeaderName(), clang::ModuleLoader::loadModule(), makeModuleVisible(), clang::XRayInstrKind::None, recomputeCurLexerKind(), clang::Token::setIdentifierInfo(), clang::Token::setKind(), clang::Token::setLength(), clang::Token::setLocation(), clang::Token::startToken(), and string().
Referenced by Lex(), and SkipTokensWhileUsingPCH().
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
).
FilenameTok | Filled 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. |
AllowMacroExpansion | If true , allow the header name to be formed by macro expansion (concatenating tokens as necessary if the first token is a '<'). |
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 998 of file Preprocessor.cpp.
References CreateString(), Diag(), End, clang::comments::tok::eof, 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().
|
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 1620 of file Preprocessor.h.
References Lex().
Referenced by EvaluateDefined(), EvaluateDirectiveSubExpr(), EvaluateHasIncludeCommon(), and EvaluateValue().
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 957 of file Pragma.cpp.
References Diag(), clang::Token::getIdentifierInfo(), clang::Token::isNot(), clang::IdentifierInfo::isStr(), LexUnexpandedToken(), clang::tok::OOS_DEFAULT, clang::tok::OOS_OFF, and clang::tok::OOS_ON.
|
inline |
Lex a string literal, which may be the concatenation of multiple string literals and may even come from macro expansion.
Definition at line 1599 of file Preprocessor.h.
References FinishLexStringLiteral(), Lex(), and LexUnexpandedToken().
Referenced by HandlePragmaHdrstop().
|
inline |
Like LexNonComment, but this disables macro expansion of identifier tokens.
Definition at line 1640 of file Preprocessor.h.
References LexUnexpandedToken().
Referenced by EvaluateDefined().
|
inline |
Just like Lex, but disables macro expansion of identifier tokens.
Definition at line 1627 of file Preprocessor.h.
References Lex().
Referenced by CheckEndOfDirective(), DiscardUntilEndOfDirective(), EvaluateFeatureLikeBuiltinMacro(), FinishLexStringLiteral(), HandleDirective(), clang::PragmaNamespace::HandlePragma(), HandlePragmaModuleBuild(), HandlePragmaPoison(), LexModuleName(), LexModuleNameComponent(), LexOnOffSwitch(), LexStringLiteral(), and LexUnexpandedNonComment().
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 1664 of file Preprocessor.h.
Referenced by clang::Parser::NextToken(), and clang::Parser::ParseMSAsmIdentifier().
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 |
||
) |
Given a "foo" or <foo> reference, look up the indicated file.
Returns std::nullopt on failure. isAngled
indicates whether the file reference is for system #include's or not (i.e. using <> instead of "").
Definition at line 932 of file PPDirectives.cpp.
References clang::ModuleMap::diagnoseHeaderInclusion(), Filename, getCurrentFileLexer(), getCurrentModule(), clang::FileEntry::getDir(), clang::FileManager::getDirectory(), clang::PreprocessorLexer::getFileEntry(), clang::SourceManager::getFileEntryForID(), clang::PreprocessorLexer::getFileID(), clang::SourceManager::getMainFileID(), getModuleForLocation(), clang::HeaderSearch::getModuleMap(), clang::SourceManager::isInMainFile(), clang::Module::IsSystem, clang::HeaderSearch::LookupFile(), and clang::HeaderSearch::LookupSubframeworkHeader().
Referenced by EnterMainSourceFile(), EvaluateHasIncludeCommon(), and HandlePragmaDependency().
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 713 of file Preprocessor.cpp.
References clang::expandUCNs(), getIdentifierInfo(), getSpelling(), clang::IdentifierInfo::getTokenID(), and Identifier.
Referenced by HandlePragmaPoison(), LexRawTokensFromMainFile(), and ParsePragmaPushOrPopMacro().
Preprocessor::macro_iterator Preprocessor::macro_begin | ( | bool | IncludeExternalMacros = true | ) | const |
Definition at line 313 of file Preprocessor.cpp.
References clang::ExternalPreprocessorSource::ReadDefinedMacros().
Referenced by DoPrintMacros(), and macros().
Preprocessor::macro_iterator Preprocessor::macro_end | ( | bool | IncludeExternalMacros = true | ) | const |
Definition at line 340 of file Preprocessor.cpp.
References clang::ExternalPreprocessorSource::ReadDefinedMacros().
Referenced by DoPrintMacros(), and macros().
|
inline |
Definition at line 1319 of file Preprocessor.h.
References macro_begin(), and macro_end().
Referenced by indexPreprocessorMacros(), and indexPreprocessorModuleMacros().
void Preprocessor::makeModuleVisible | ( | Module * | M, |
SourceLocation | Loc | ||
) |
Definition at line 1317 of file Preprocessor.cpp.
References Diag().
Referenced by EnterSubmodule(), clang::ASTReader::InitializeContext(), LeaveSubmodule(), and LexAfterModuleImport().
|
inline |
Mark the given clang module as affecting the current clang module or translation unit.
Definition at line 1328 of file Preprocessor.h.
References clang::Module::isModuleMapModule().
Mark the file as included.
Returns true if this is the first time the file was included.
Definition at line 1346 of file Preprocessor.h.
References clang::File, and clang::HeaderSearch::getFileInfo().
Referenced by EnterMainSourceFile(), and clang::HeaderSearch::ShouldEnterIncludeFile().
void Preprocessor::markMacroAsUsed | ( | MacroInfo * | MI | ) |
A macro is used, update information about macros that need unused warnings.
Definition at line 1978 of file PPMacroExpansion.cpp.
References clang::MacroInfo::getDefinitionLoc(), clang::MacroInfo::isUsed(), clang::MacroInfo::isWarnIfUnused(), and clang::MacroInfo::setIsUsed().
Referenced by EvaluateDefined().
|
inline |
Definition at line 2101 of file Preprocessor.h.
References HandlePoisonedIdentifier(), and Identifier.
|
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 1759 of file Preprocessor.h.
|
inline |
Definition at line 1172 of file Preprocessor.h.
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 561 of file Pragma.cpp.
References CreateString(), Diag(), clang::Token::getLocation(), getSpelling(), clang::Token::hasUDSuffix(), clang::Token::isNot(), Lex(), LookUpIdentifierInfo(), clang::Token::setKind(), clang::Token::startToken(), and string().
Referenced by HandlePragmaPopMacro(), and HandlePragmaPushMacro().
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 1375 of file Preprocessor.cpp.
References getDiagnostics(), getLangOpts(), clang::Token::getLocation(), getSourceManager(), getSpelling(), getTargetInfo(), clang::Token::is(), and Lex().
Definition at line 752 of file Preprocessor.cpp.
References clang::IdentifierInfo::setIsPoisoned().
void Preprocessor::PrintStats | ( | ) |
Definition at line 274 of file Preprocessor.cpp.
References getTotalMemory().
Referenced by clang::FrontendAction::EndSourceFile().
|
static |
Definition at line 1986 of file PPMacroExpansion.cpp.
Referenced by clang::SourceLocExpr::EvaluateInContext().
void Preprocessor::recomputeCurLexerKind | ( | ) |
Recompute the current lexer kind based on the CurLexer/ CurTokenLexer pointers.
Definition at line 384 of file Preprocessor.cpp.
Referenced by Backtrack(), HandleEndOfFile(), and LexAfterModuleImport().
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 1402 of file Preprocessor.cpp.
Referenced by clang::Parser::~Parser().
|
inline |
Definition at line 1397 of file Preprocessor.h.
References RemovePragmaHandler().
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
Definition at line 935 of file Pragma.cpp.
References clang::PragmaHandler::getIfNamespace(), clang::PragmaNamespace::IsEmpty(), and clang::PragmaNamespace::RemovePragmaHandler().
Referenced by clang::DoPrintPreprocessedInput(), and RemovePragmaHandler().
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 608 of file PPLexerChange.cpp.
Referenced by HandleEndOfFile().
|
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 1747 of file Preprocessor.h.
References clang::Token::isAnnotation(), and isBacktrackEnabled().
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.
|
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 1677 of file Preprocessor.h.
References isBacktrackEnabled().
|
inline |
Returns true if the preprocessor has seen a use of DATE or TIME in the file so far.
Definition at line 2176 of file Preprocessor.h.
|
inline |
Set the code completion handler to the given object.
Definition at line 1418 of file Preprocessor.h.
Referenced by clang::Parser::Parser().
|
inline |
Set the code completion token for filtering purposes.
Definition at line 1441 of file Preprocessor.h.
References clang::tooling::Filter.
Referenced by Lex().
bool Preprocessor::SetCodeCompletionPoint | ( | const FileEntry * | File, |
unsigned | Line, | ||
unsigned | Column | ||
) |
Specify the point at which code-completion will be performed.
File | the 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. |
Line | the line at which code completion should occur (1-based). |
Column | the column at which code completion should occur (1-based). |
Definition at line 395 of file Preprocessor.cpp.
References clang::File, and clang::SourceManager::getMemoryBufferForFileOrNone().
Referenced by EnableCodeCompletion().
|
inline |
Note that we hit the code-completion point.
Definition at line 1825 of file Preprocessor.h.
References getDiagnostics(), isCodeCompletionEnabled(), and clang::DiagnosticsEngine::setSuppressAllDiagnostics().
Referenced by CodeCompleteIncludedFile(), CodeCompleteNaturalLanguage(), EvaluateDefined(), EvaluateValue(), HandleDirective(), and LexHeaderName().
|
inline |
Set the code completion token range for detecting replacement range later on.
Definition at line 1447 of file Preprocessor.h.
References End.
Referenced by Lex().
|
inline |
Control whether the preprocessor retains comments in output.
Definition at line 1100 of file Preprocessor.h.
Referenced by clang::DoPrintPreprocessedInput().
|
inline |
Definition at line 2180 of file Preprocessor.h.
References V.
|
inline |
Definition at line 2205 of file Preprocessor.h.
References clang::LangOptions::FEM_UnsetOnCommandLine.
Referenced by clang::Sema::ActOnPragmaFloatControl(), clang::Sema::ActOnPragmaFPEvalMethod(), and Initialize().
|
inline |
Definition at line 1058 of file Preprocessor.h.
|
inline |
Set empty line handler.
Definition at line 1405 of file Preprocessor.h.
Referenced by clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks().
|
inline |
Definition at line 1073 of file Preprocessor.h.
|
inline |
Definition at line 2201 of file Preprocessor.h.
Referenced by clang::Sema::ActOnPragmaFloatControl().
void Preprocessor::setLoadedMacroDirective | ( | IdentifierInfo * | II, |
MacroDirective * | ED, | ||
MacroDirective * | MD | ||
) |
Set a MacroDirective that was loaded from a PCH file.
Definition at line 96 of file PPMacroExpansion.cpp.
References clang::MacroDirective::isDefined(), clang::IdentifierInfo::setHasMacroDefinition(), and clang::MacroDirective::setPrevious().
|
inline |
Disables macro expansion everywhere except for preprocessor directives.
Definition at line 1652 of file Preprocessor.h.
Referenced by clang::DoPrintPreprocessedInput(), and clang::RewriteIncludesInInput().
|
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 1879 of file Preprocessor.h.
Referenced by prepareToBuildModule().
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 748 of file Preprocessor.cpp.
Referenced by clang::Parser::Initialize().
|
inline |
Set the location of the currently-active #pragma clang arc_cf_code_audited begin.
An invalid location ends the pragma.
Definition at line 1843 of file Preprocessor.h.
|
inline |
Set the location of the currently-active #pragma clang assume_nonnull begin.
An invalid location ends the pragma.
Definition at line 1858 of file Preprocessor.h.
|
inline |
Definition at line 1107 of file Preprocessor.h.
|
inline |
Record the location of the unterminated #pragma clang assume_nonnull begin in the preamble.
Definition at line 1873 of file Preprocessor.h.
|
inline |
Set the predefines for this Preprocessor.
These predefines are automatically injected when parsing the main file.
Definition at line 1374 of file Preprocessor.h.
References P.
Referenced by createASTReader(), and clang::CompilerInstance::createPCHExternalASTSource().
|
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 1120 of file Preprocessor.h.
|
inline |
Definition at line 1186 of file Preprocessor.h.
References clang::driver::phases::Preprocess.
Referenced by clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks().
|
inline |
Definition at line 2579 of file Preprocessor.h.
References s.
|
inline |
Definition at line 2583 of file Preprocessor.h.
References s.
Instruct the preprocessor to skip part of the main source file.
Bytes | The number of bytes in the preamble to skip. |
StartOfLine | Whether skipping these bytes puts the lexer at the start of a line. |
Definition at line 1889 of file Preprocessor.h.
|
inline |
Definition at line 1110 of file Preprocessor.h.
Referenced by clang::DependencyFileGenerator::attachToPreprocessor().
|
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 1182 of file Preprocessor.h.
Referenced by clang::MacroExpansionContext::registerForPreprocessor(), clang::CodeGen::CoverageMappingModuleGen::setUpCoverageCallbacks(), and clang::syntax::TokenCollector::TokenCollector().
|
inline |
Definition at line 2216 of file Preprocessor.h.
References clang::LangOptions::FEM_UnsetOnCommandLine.
Referenced by Initialize().
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 640 of file Preprocessor.cpp.
References Diag(), clang::comments::tok::eof, getPredefinesFileID(), clang::Token::is(), and LexAfterModuleImport().
Referenced by EnterMainSourceFile().
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 509 of file Preprocessor.cpp.
References clang::SourceLocation::getLocWithOffset(), getSourceManager(), and SM.
|
inline |
Update the current token to represent the provided identifier, in order to cache an action performed by typo correction.
Definition at line 1765 of file Preprocessor.h.
References clang::Token::getIdentifierInfo(), and isBacktrackEnabled().
bool Preprocessor::usingPCHWithPragmaHdrStop | ( | ) |
True if using a PCH with a #pragma hdrstop.
Definition at line 631 of file Preprocessor.cpp.
References clang::TU_Prefix, and TUKind.
Referenced by EnterMainSourceFile(), and HandlePragmaHdrstop().
bool Preprocessor::usingPCHWithThroughHeader | ( | ) |
True if using a PCH with a through header.
Definition at line 622 of file Preprocessor.cpp.
References clang::FileID::isValid(), clang::TU_Prefix, and TUKind.
Referenced by EnterMainSourceFile().
|
friend |
Definition at line 543 of file Preprocessor.h.
|
friend |
Definition at line 544 of file Preprocessor.h.
|
friend |
|
friend |
Definition at line 129 of file Preprocessor.h.
|
friend |
Definition at line 130 of file Preprocessor.h.
const TranslationUnitKind clang::Preprocessor::TUKind |
The kind of translation unit we are processing.
Definition at line 287 of file Preprocessor.h.
Referenced by clang::CompilerInstance::createASTContext(), creatingPCHWithPragmaHdrStop(), creatingPCHWithThroughHeader(), HandleEndOfFile(), HandlePragmaOnce(), usingPCHWithPragmaHdrStop(), and usingPCHWithThroughHeader().