clang API Documentation

Classes | Public Member Functions | Friends
clang::Preprocessor Class Reference

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

#include <Preprocessor.h>

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

List of all members.

Classes

struct  DeserializedMacroInfoChain
struct  IncludeStackInfo
 Keeps track of the stack of files currently #included, and macros currently being expanded from, not counting CurLexer/CurTokenLexer.
struct  MacroExpandsInfo
struct  MacroInfoChain
class  ResetMacroExpansionHelper

Public Member Functions

 Preprocessor (IntrusiveRefCntPtr< 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)
 Initialize the preprocessor using information about the target.
void InitializeForModelFile ()
 Initialize the preprocessor to parse a model file.
void FinalizeForModelFile ()
 Cleanup after model file parsing.
PreprocessorOptionsgetPreprocessorOpts () const
 Retrieve the preprocessor options used to initialize this preprocessor.
DiagnosticsEnginegetDiagnostics () const
void setDiagnostics (DiagnosticsEngine &D)
const LangOptionsgetLangOpts () const
const TargetInfogetTargetInfo () const
FileManagergetFileManager () const
SourceManagergetSourceManager () const
HeaderSearchgetHeaderSearchInfo () const
IdentifierTablegetIdentifierTable ()
SelectorTablegetSelectorTable ()
Builtin::ContextgetBuiltinInfo ()
llvm::BumpPtrAllocator & getPreprocessorAllocator ()
void setPTHManager (PTHManager *pm)
PTHManagergetPTHManager ()
void setExternalSource (ExternalPreprocessorSource *Source)
ExternalPreprocessorSourcegetExternalSource () const
ModuleLoadergetModuleLoader () const
 Retrieve the module loader associated with this preprocessor.
bool hadModuleLoaderFatalFailure () const
bool isParsingIfOrElifDirective () const
 True if we are currently preprocessing a #if or #elif directive.
void SetCommentRetentionState (bool KeepComments, bool KeepMacroComments)
 Control whether the preprocessor retains comments in output.
bool getCommentRetentionState () const
void setPragmasEnabled (bool Enabled)
bool getPragmasEnabled () const
void SetSuppressIncludeNotFoundError (bool Suppress)
bool GetSuppressIncludeNotFoundError ()
void setPreprocessedOutput (bool IsPreprocessedOutput)
bool isPreprocessedOutput () const
bool isCurrentLexer (const PreprocessorLexer *L) const
 Return true if we are lexing directly from the specified lexer.
PreprocessorLexergetCurrentLexer () const
 Return the current lexer being lexed from.
PreprocessorLexergetCurrentFileLexer () const
 Return the current file lexer being lexed from.
ModulegetCurrentSubmodule () const
 Return the submodule owning the file being lexed.
FileID getPredefinesFileID () const
 Returns the FileID for the preprocessor predefines.
MacroDirectivegetMacroDirective (IdentifierInfo *II) const
 Given an identifier, return its latest MacroDirective if it is #defined or null if it isn't #define'd.
const MacroInfogetMacroInfo (IdentifierInfo *II) const
MacroInfogetMacroInfo (IdentifierInfo *II)
MacroDirectivegetMacroDirectiveHistory (const IdentifierInfo *II) const
 Given an identifier, return the (probably #undef'd) MacroInfo representing the most recent macro definition.
void appendMacroDirective (IdentifierInfo *II, MacroDirective *MD)
 Add a directive to the macro directive history for this identifier.
DefMacroDirectiveappendDefMacroDirective (IdentifierInfo *II, MacroInfo *MI, SourceLocation Loc, unsigned ImportedFromModuleID, ArrayRef< unsigned > Overrides)
DefMacroDirectiveappendDefMacroDirective (IdentifierInfo *II, MacroInfo *MI)
void setLoadedMacroDirective (IdentifierInfo *II, MacroDirective *MD)
 Set a MacroDirective that was loaded from a PCH file.
StringRef 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.
const std::string & getPredefines () const
void setPredefines (const char *P)
 Set the predefines for this Preprocessor.
void setPredefines (const std::string &P)
IdentifierInfogetIdentifierInfo (StringRef Name) const
void AddPragmaHandler (StringRef Namespace, PragmaHandler *Handler)
 Add the specified pragma handler to this preprocessor.
void AddPragmaHandler (PragmaHandler *Handler)
void RemovePragmaHandler (StringRef Namespace, PragmaHandler *Handler)
 Remove the specific pragma handler from this preprocessor.
void RemovePragmaHandler (PragmaHandler *Handler)
void IgnorePragmas ()
 Install empty handlers for all pragmas (making them ignored).
void addCommentHandler (CommentHandler *Handler)
 Add the specified comment handler to the preprocessor.
void removeCommentHandler (CommentHandler *Handler)
 Remove the specified comment handler.
void setCodeCompletionHandler (CodeCompletionHandler &Handler)
 Set the code completion handler to the given object.
CodeCompletionHandlergetCodeCompletionHandler () const
 Retrieve the current code-completion handler.
void clearCodeCompletionHandler ()
 Clear out the code completion handler.
void CodeCompleteNaturalLanguage ()
 Hook used by the lexer to invoke the "natural language" code completion point.
PreprocessingRecordgetPreprocessingRecord () const
 Retrieve the preprocessing record, or NULL if there is no preprocessing record.
void createPreprocessingRecord ()
 Create a new preprocessing record, which will keep track of all macro expansions, macro definitions, etc.
void EnterMainSourceFile ()
 Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc.
void EndSourceFile ()
 Inform the preprocessor callbacks that processing is complete.
bool EnterSourceFile (FileID CurFileID, const DirectoryLookup *Dir, SourceLocation Loc)
 Add a source file to the top of the include stack and start lexing tokens from it instead of the current buffer.
void EnterMacro (Token &Identifier, SourceLocation ILEnd, MacroInfo *Macro, MacroArgs *Args)
 Add a Macro to the top of the include stack and start lexing tokens from it instead of the current buffer.
void EnterTokenStream (const Token *Toks, unsigned NumToks, bool DisableMacroExpansion, bool OwnsTokens)
 Add a "macro" context to the top of the include stack, which will cause the lexer to start returning the specified tokens.
void RemoveTopOfLexerStack ()
 Pop the current lexer/macro exp off the top of the lexer stack.
void EnableBacktrackAtThisPos ()
void CommitBacktrackedTokens ()
 Disable the last EnableBacktrackAtThisPos call.
void Backtrack ()
 Make Preprocessor re-lex the tokens that were lexed since EnableBacktrackAtThisPos() was previously called.
bool isBacktrackEnabled () const
 True if EnableBacktrackAtThisPos() was called and caching of tokens is on.
void Lex (Token &Result)
 Lex the next token for this preprocessor.
void LexAfterModuleImport (Token &Result)
 Lex a token following the 'import' contextual keyword.
bool LexStringLiteral (Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
 Lex a string literal, which may be the concatenation of multiple string literals and may even come from macro expansion.
bool FinishLexStringLiteral (Token &Result, std::string &String, const char *DiagnosticTag, bool AllowMacroExpansion)
 Complete the lexing of a string literal where the first token has already been lexed (see LexStringLiteral).
void LexNonComment (Token &Result)
 Lex a token. If it's a comment, keep lexing until we get something not a comment.
void LexUnexpandedToken (Token &Result)
 Just like Lex, but disables macro expansion of identifier tokens.
void LexUnexpandedNonComment (Token &Result)
 Like LexNonComment, but this disables macro expansion of identifier tokens.
bool parseSimpleIntegerLiteral (Token &Tok, uint64_t &Value)
 Parses a simple integer literal to get its numeric value. Floating point literals and user defined literals are rejected. Used primarily to handle pragmas that accept integer arguments.
void SetMacroExpansionOnlyInDirectives ()
 Disables macro expansion everywhere except for preprocessor directives.
const TokenLookAhead (unsigned N)
 Peeks ahead N tokens and returns that token without consuming any tokens.
void RevertCachedTokens (unsigned N)
 When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens.
void EnterToken (const Token &Tok)
 Enters a token in the token stream to be lexed next.
void AnnotateCachedTokens (const Token &Tok)
SourceLocation getLastCachedTokenLocation () const
void ReplaceLastTokenWithAnnotation (const Token &Tok)
 Replace the last token with an annotation token.
void TypoCorrectToken (const Token &Tok)
void recomputeCurLexerKind ()
 Recompute the current lexer kind based on the CurLexer/CurPTHLexer/ CurTokenLexer pointers.
bool isIncrementalProcessingEnabled () const
 Returns true if incremental processing is enabled.
void enableIncrementalProcessing (bool value=true)
 Enables the incremental processing.
bool SetCodeCompletionPoint (const FileEntry *File, unsigned Line, unsigned Column)
 Specify the point at which code-completion will be performed.
bool isCodeCompletionEnabled () const
 Determine if we are performing code completion.
SourceLocation getCodeCompletionLoc () const
 Returns the location of the code-completion point.
SourceLocation getCodeCompletionFileLoc () const
 Returns the start location of the file of code-completion point.
bool isCodeCompletionReached () const
 Returns true if code-completion is enabled and we have hit the code-completion point.
void setCodeCompletionReached ()
 Note that we hit the code-completion point.
SourceLocation getPragmaARCCFCodeAuditedLoc () const
 The location of the currently-active #pragma clang arc_cf_code_audited begin.
void setPragmaARCCFCodeAuditedLoc (SourceLocation Loc)
 Set the location of the currently-active #pragma clang arc_cf_code_audited begin. An invalid location ends the pragma.
void setSkipMainFilePreamble (unsigned Bytes, bool StartOfLine)
 Instruct the preprocessor to skip part of the main source file.
DiagnosticBuilder Diag (SourceLocation Loc, unsigned DiagID) const
DiagnosticBuilder Diag (const Token &Tok, unsigned DiagID) const
StringRef getSpelling (SourceLocation loc, SmallVectorImpl< char > &buffer, bool *invalid=nullptr) const
std::string getSpelling (const Token &Tok, bool *Invalid=nullptr) const
 Return the 'spelling' of the Tok token.
unsigned getSpelling (const Token &Tok, const char *&Buffer, bool *Invalid=nullptr) const
 Get the spelling of a token into a preallocated buffer, instead of as an std::string.
StringRef getSpelling (const Token &Tok, SmallVectorImpl< char > &Buffer, bool *Invalid=nullptr) const
 Get the spelling of a token into a SmallVector.
bool getRawToken (SourceLocation Loc, Token &Result, bool IgnoreWhiteSpace=false)
 Relex the token at the specified location.
char getSpellingOfSingleCharacterNumericConstant (const Token &Tok, bool *Invalid=nullptr) const
 Given a Token Tok that is a numeric constant with length 1, return the character.
StringRef getImmediateMacroName (SourceLocation Loc)
 Retrieve the name of the immediate macro expansion.
void CreateString (StringRef Str, Token &Tok, SourceLocation ExpansionLocStart=SourceLocation(), SourceLocation ExpansionLocEnd=SourceLocation())
 Plop the specified string into a scratch buffer and set the specified token's location and length to it.
SourceLocation getLocForEndOfToken (SourceLocation Loc, unsigned Offset=0)
 Computes the source location just past the end of the token at this source location.
bool isAtStartOfMacroExpansion (SourceLocation loc, SourceLocation *MacroBegin=nullptr) const
 Returns true if the given MacroID location points at the first token of the macro expansion.
bool isAtEndOfMacroExpansion (SourceLocation loc, SourceLocation *MacroEnd=nullptr) const
 Returns true if the given MacroID location points at the last token of the macro expansion.
void DumpToken (const Token &Tok, bool DumpFlags=false) const
 Print the token to stderr, used for debugging.
void DumpLocation (SourceLocation Loc) const
void DumpMacro (const MacroInfo &MI) const
SourceLocation AdvanceToTokenCharacter (SourceLocation TokStart, unsigned Char) const
 Given a location that specifies the start of a token, return a new location that specifies a character within the token.
void IncrementPasteCounter (bool isFast)
 Increment the counters for the number of token paste operations performed.
void PrintStats ()
size_t getTotalMemory () const
void HandleMicrosoftCommentPaste (Token &Tok)
IdentifierInfoLookUpIdentifierInfo (Token &Identifier) const
void SetPoisonReason (IdentifierInfo *II, unsigned DiagID)
 Specifies the reason for poisoning an identifier.
void HandlePoisonedIdentifier (Token &Tok)
 Display reason for poisoned identifier.
void MaybeHandlePoisonedIdentifier (Token &Identifier)
void PoisonSEHIdentifiers (bool Poison=true)
bool HandleIdentifier (Token &Identifier)
 Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo member.
bool HandleEndOfFile (Token &Result, bool isEndOfMacro=false)
 Callback invoked when the lexer hits the end of the current file.
bool HandleEndOfTokenLexer (Token &Result)
 Callback invoked when the current TokenLexer hits the end of its token stream.
void HandleDirective (Token &Result)
 Callback invoked when the lexer sees a # token at the start of a line.
void CheckEndOfDirective (const char *Directive, bool EnableMacros=false)
 Ensure that the next token is a tok::eod token.
void DiscardUntilEndOfDirective ()
 Read and discard all tokens remaining on the current line until the tok::eod token is found.
bool SawDateOrTime () const
 Returns true if the preprocessor has seen a use of __DATE__ or __TIME__ in the file so far.
unsigned getCounterValue () const
void setCounterValue (unsigned V)
ModulegetCurrentModule ()
 Retrieves the module that we're currently building, if any.
MacroInfoAllocateMacroInfo (SourceLocation L)
 Allocate a new MacroInfo object with the provided SourceLocation.
MacroInfoAllocateDeserializedMacroInfo (SourceLocation L, unsigned SubModuleID)
 Allocate a new MacroInfo object loaded from an AST file.
bool GetIncludeFilenameSpelling (SourceLocation Loc, StringRef &Filename)
 Turn the specified lexer token into a fully checked and spelled filename, e.g. as an operand of #include.
const FileEntryLookupFile (SourceLocation FilenameLoc, StringRef Filename, bool isAngled, const DirectoryLookup *FromDir, const FileEntry *FromFile, const DirectoryLookup *&CurDir, SmallVectorImpl< char > *SearchPath, SmallVectorImpl< char > *RelativePath, ModuleMap::KnownHeader *SuggestedModule, bool SkipCache=false)
 Given a "foo" or <foo> reference, look up the indicated file.
const DirectoryLookupGetCurDirLookup ()
 Get the DirectoryLookup structure used to find the current FileEntry, if CurLexer is non-null and if applicable.
bool isInPrimaryFile () const
 Return true if we're in the top-level file, not in a #include.
bool ConcatenateIncludeName (SmallString< 128 > &FilenameBuffer, SourceLocation &End)
 Handle cases where the #include name is expanded from a macro as multiple tokens, which need to be glued together.
bool LexOnOffSwitch (tok::OnOffSwitch &OOS)
 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.
bool CheckMacroName (Token &MacroNameTok, MacroUse isDefineUndef)
void HandlePragmaOnce (Token &OnceTok)
void HandlePragmaMark ()
void HandlePragmaPoison (Token &PoisonTok)
void HandlePragmaSystemHeader (Token &SysHeaderTok)
void HandlePragmaDependency (Token &DependencyTok)
void HandlePragmaPushMacro (Token &Tok)
 Handle #pragma push_macro.
void HandlePragmaPopMacro (Token &Tok)
 Handle #pragma pop_macro.
void HandlePragmaIncludeAlias (Token &Tok)
IdentifierInfoParsePragmaPushOrPopMacro (Token &Tok)
bool HandleComment (Token &Token, SourceRange Comment)
void markMacroAsUsed (MacroInfo *MI)
 A macro is used, update information about macros that need unused warnings.
PPCallbacksgetPPCallbacks () const
 Accessors for preprocessor callbacks.
void addPPCallbacks (std::unique_ptr< PPCallbacks > C)

Friends

class ASTReader
class MacroArgs
void TokenLexer::ExpandFunctionArguments ()
typedef llvm::DenseMap< const
IdentifierInfo
*, MacroDirective * >
::const_iterator 
macro_iterator
macro_iterator macro_begin (bool IncludeExternalMacros=true) const
macro_iterator macro_end (bool IncludeExternalMacros=true) const

Detailed Description

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

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

Definition at line 95 of file Preprocessor.h.


Member Typedef Documentation

typedef llvm::DenseMap<const IdentifierInfo *, MacroDirective*>::const_iterator clang::Preprocessor::macro_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 648 of file Preprocessor.h.


Constructor & Destructor Documentation

Preprocessor::Preprocessor ( IntrusiveRefCntPtr< 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 58 of file Preprocessor.cpp.

References getIdentifierInfo(), and SetPoisonReason().

Definition at line 141 of file Preprocessor.cpp.


Member Function Documentation

Add the specified comment handler to the preprocessor.

Definition at line 817 of file Preprocessor.cpp.

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

void clang::Preprocessor::addPPCallbacks ( std::unique_ptr< PPCallbacks C) [inline]
void Preprocessor::AddPragmaHandler ( StringRef  Namespace,
PragmaHandler Handler 
)

Add the specified pragma handler to this 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".

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".

Definition at line 729 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().

Definition at line 677 of file Preprocessor.h.

References AddPragmaHandler().

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

Definition at line 1182 of file Preprocessor.h.

Referenced by GetLineValue(), and clang::NumericLiteralParser::NumericLiteralParser().

Allocate a new MacroInfo object loaded from an AST file.

Definition at line 49 of file PPDirectives.cpp.

References clang::SrcMgr::static_assert().

Allocate a new MacroInfo object with the provided SourceLocation.

Definition at line 43 of file PPDirectives.cpp.

References AllocateMacroInfo().

Referenced by AllocateMacroInfo(), and RegisterBuiltinMacro().

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

We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should replace the most recent cached tokens with the given annotation token. This function has no effect if backtracking is not enabled.

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

Definition at line 910 of file Preprocessor.h.

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

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

DefMacroDirective* clang::Preprocessor::appendDefMacroDirective ( IdentifierInfo II,
MacroInfo MI,
SourceLocation  Loc,
unsigned  ImportedFromModuleID,
ArrayRef< unsigned Overrides 
) [inline]

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

Definition at line 40 of file PPCaching.cpp.

References recomputeCurLexerKind().

void 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.

Definition at line 181 of file PPDirectives.cpp.

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

bool Preprocessor::CheckMacroName ( Token MacroNameTok,
MacroUse  isDefineUndef 
)

Clear out the code completion handler.

Definition at line 713 of file Preprocessor.h.

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

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

Definition at line 414 of file Preprocessor.cpp.

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

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

Disable the last EnableBacktrackAtThisPos call.

Definition at line 32 of file PPCaching.cpp.

bool Preprocessor::ConcatenateIncludeName ( SmallString< 128 > &  FilenameBuffer,
SourceLocation End 
)

Handle cases where the #include name is expanded from a macro as multiple tokens, which need to be glued together.

This occurs for code like:

    \#define FOO <x/y.h>
    \#include FOO

because in this case, "<x/y.h>" is returned as 7 tokens, not one.

This code concatenates and consumes tokens up to the '>' token. It returns false if the > was found, otherwise it returns true if it finds and consumes the EOD marker.

Definition at line 1311 of file PPDirectives.cpp.

References Diag(), clang::Token::getLength(), clang::Token::getLocation(), getSpelling(), clang::Token::hasLeadingSpace(), clang::Token::is(), clang::Token::isNot(), Lex(), and setCodeCompletionReached().

Referenced by EvaluateHasIncludeCommon(), and HandlePragmaIncludeAlias().

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

Definition at line 851 of file Preprocessor.cpp.

References addPPCallbacks(), getSourceManager(), and Record.

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.

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

CreateString - Plop the specified string into a scratch buffer and return a location for it. If specified, the source location provides a source location for the token.

Definition at line 445 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(), clang::Token::setRawIdentifierData(), and SourceMgr.

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

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

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

Definition at line 95 of file PPDirectives.cpp.

References clang::comments::tok::eof, clang::Token::isNot(), and LexUnexpandedToken().

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

Definition at line 229 of file Preprocessor.cpp.

References clang::SourceLocation::dump(), and SourceMgr.

Referenced by DumpToken().

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

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 26 of file PPCaching.cpp.

Enables the incremental processing.

Definition at line 953 of file Preprocessor.h.

Inform the preprocessor callbacks that processing is complete.

Definition at line 516 of file Preprocessor.cpp.

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

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.

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

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

Definition at line 161 of file PPLexerChange.cpp.

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.

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

Definition at line 71 of file PPLexerChange.cpp.

References Diag(), clang::SourceManager::getBuffer(), clang::SourceManager::getBufferName(), clang::SourceManager::getFileEntryForID(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), getSourceManager(), and isCodeCompletionEnabled().

Referenced by EnterMainSourceFile().

void clang::Preprocessor::EnterToken ( const Token Tok) [inline]

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

If BackTrack() is called afterwards, the token will remain at the insertion point.

Definition at line 897 of file Preprocessor.h.

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

void Preprocessor::EnterTokenStream ( const Token Toks,
unsigned  NumToks,
bool  DisableMacroExpansion,
bool  OwnsTokens 
)

Add a "macro" context to the top of the include stack, which will cause the lexer to start returning the specified tokens.

If DisableMacroExpansion is true, tokens lexed from the token stream will not be subject to further macro expansion. Otherwise, these tokens will be re-macro-expanded when/if expansion is enabled.

If OwnsTokens is false, this method assumes that the specified stream of tokens has a permanent owner somewhere, so they do not need to be copied. If it is true, it assumes the array of tokens is allocated with new[] and must be freed.

EnterTokenStream - Add a "macro" context to the top of the include stack, which will cause the lexer to start returning the specified tokens.

If DisableMacroExpansion is true, tokens lexed from the token stream will not be subject to further macro expansion. Otherwise, these tokens will be re-macro-expanded when/if expansion is enabled.

If OwnsTokens is false, this method assumes that the specified stream of tokens has a permanent owner somewhere, so they do not need to be copied. If it is true, it assumes the array of tokens is allocated with new[] and must be freed.

Definition at line 190 of file PPLexerChange.cpp.

Referenced by EnterAnnotationToken(), clang::MacroArgs::getPreExpArgument(), HandleDirective(), ParseAlignPragma(), and clang::Parser::ParseMSAsmIdentifier().

Cleanup after model file parsing.

Definition at line 194 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 758 of file Preprocessor.cpp.

References Diag(), clang::StringLiteralParser::GetString(), clang::StringLiteralParser::hadError, clang::Token::hasUDSuffix(), clang::Token::is(), clang::StringLiteralParser::isAscii(), clang::Token::isNot(), Lex(), LexUnexpandedToken(), and clang::StringLiteralParser::Pascal.

Referenced by LexStringLiteral().

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 987 of file Preprocessor.h.

Retrieve the current code-completion handler.

Definition at line 708 of file Preprocessor.h.

Referenced by EvaluateDefined(), and EvaluateValue().

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 981 of file Preprocessor.h.

Definition at line 1304 of file Preprocessor.h.

Get the DirectoryLookup structure used to find the current FileEntry, if CurLexer is non-null and if applicable.

This allows us to implement #include_next and find directory-specific properties.

Definition at line 1346 of file Preprocessor.h.

Referenced by EvaluateHasIncludeNext().

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.

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 51 of file PPLexerChange.cpp.

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

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 570 of file Preprocessor.h.

Referenced by EvaluateHasIncludeCommon(), and EvaluateHasIncludeNext().

Retrieves the module that we're currently building, if any.

Definition at line 465 of file Preprocessor.cpp.

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

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), and HandleEndOfFile().

Return the submodule owning the file being lexed.

Definition at line 579 of file Preprocessor.h.

Referenced by EvaluateHasIncludeNext().

Definition at line 516 of file Preprocessor.h.

Referenced by isTrivialSingleTokenExpansion().

IdentifierInfo* clang::Preprocessor::getIdentifierInfo ( StringRef  Name) const [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 1122 of file Preprocessor.h.

References getLangOpts().

Referenced by isExpandedFromConfigurationMacro().

Turn the specified lexer token into a fully checked and spelled filename, e.g. as an operand of #include.

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

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

GetIncludeFilenameSpelling - Turn the specified lexer token into a fully checked and spelled filename, e.g. 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 1259 of file PPDirectives.cpp.

References Diag().

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

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

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

Definition at line 918 of file Preprocessor.h.

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

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

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

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

Definition at line 1150 of file Preprocessor.h.

Referenced by clang::Sema::ActOnCXXDelete(), addFixitForObjCARCConversion(), clang::Sema::CheckFriendTypeDecl(), clang::Sema::CheckObjCBridgeRelatedConversions(), clang::Sema::CheckUsingDeclQualifier(), clang::Sema::DiagnoseAssignmentAsCondition(), DiagnoseDirectIsaAccess(), clang::Sema::DiagnoseDtorReference(), diagnoseLogicalNotOnLHSofComparison(), diagnoseObjCARCConversion(), diagnoseObjCLiteralComparison(), diagnoseStringPlusChar(), diagnoseStringPlusInt(), EvaluateHasIncludeCommon(), clang::DeclSpec::Finish(), GenerateNewArgTokens(), clang::Sema::ParseObjCEncodeExpression(), SuggestParentheses(), clang::ConversionFixItGenerator::tryToFixConversion(), and clang::Sema::tryToRecoverWithCall().

Given an identifier, return its latest MacroDirective if it is #defined or null if it isn't #define'd.

Definition at line 600 of file Preprocessor.h.

References getMacroDirectiveHistory(), clang::IdentifierInfo::hasMacroDefinition(), and clang::MacroDirective::isDefined().

Referenced by EvaluateDefined(), getMacroInfo(), HandleIdentifier(), and HandlePragmaPopMacro().

Given an identifier, return the (probably #undef'd) MacroInfo representing the most recent macro definition.

One can iterate over all previous macro definitions from the most recent one. This should only be called for identifiers that hadMacroDefinition().

Definition at line 37 of file PPMacroExpansion.cpp.

References clang::IdentifierInfo::hadMacroDefinition().

Referenced by checkConfigMacro(), clang::CodeCompletionResult::CreateCodeCompletionString(), getMacroDirective(), and isMacroDefined().

Definition at line 613 of file Preprocessor.h.

References getMacroDirective().

Retrieve the module loader associated with this preprocessor.

Definition at line 521 of file Preprocessor.h.

Referenced by clang::PCHGenerator::HandleTranslationUnit().

Accessors for preprocessor callbacks.

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

Definition at line 589 of file Preprocessor.h.

Referenced by EvaluateDefined().

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 1007 of file Preprocessor.h.

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

Definition at line 541 of file Preprocessor.h.

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

Definition at line 659 of file Preprocessor.h.

Returns the FileID for the preprocessor predefines.

Definition at line 582 of file Preprocessor.h.

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

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

Definition at line 723 of file Preprocessor.h.

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

Definition at line 506 of file Preprocessor.h.

Referenced by ParseAlignPragma(), and ParseLoopHintValue().

Retrieve the preprocessor options used to initialize this preprocessor.

Definition at line 492 of file Preprocessor.h.

Definition at line 510 of file Preprocessor.h.

Referenced by AddImplicitIncludePTH().

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

Relex the token at the specified location.

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

Definition at line 1091 of file Preprocessor.h.

Referenced by UseNSOptionsMacro().

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

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

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

Definition at line 1046 of file Preprocessor.h.

Referenced by buildMSAsmString(), CheckMacroName(), ConcatenateIncludeName(), clang::DoRewriteTest(), DumpToken(), EvaluateHasIncludeCommon(), EvaluateValue(), GetFirstChar(), GetLineValue(), getSpelling(), HandlePragmaDependency(), HandlePragmaIncludeAlias(), clang::MacroInfo::isIdenticalTo(), LookUpIdentifierInfo(), ParseOpenMPDirectiveKind(), ParsePragmaPushOrPopMacro(), parseSimpleIntegerLiteral(), PrintMacroDefinition(), PrintPreprocessedTokens(), clang::RewriteMacrosInInput(), and clang::MacroArgs::StringifyArgument().

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

Return the 'spelling' of the Tok token.

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

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

Definition at line 1060 of file Preprocessor.h.

References getSpelling().

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

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

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

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

Definition at line 1076 of file Preprocessor.h.

References getSpelling().

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

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.

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 423 of file Preprocessor.cpp.

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

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

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

Definition at line 1099 of file Preprocessor.h.

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

Definition at line 547 of file Preprocessor.h.

Definition at line 289 of file Preprocessor.cpp.

Referenced by PrintStats().

Definition at line 523 of file Preprocessor.h.

References clang::ModuleLoader::HadFatalFailure.

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

Definition at line 831 of file Preprocessor.cpp.

References getCommentRetentionState(), and Lex().

Callback 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.

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 676 of file PPDirectives.cpp.

References clang::CodeCompletionHandler::CodeCompleteDirective(), Diag(), DiscardUntilEndOfDirective(), EnterTokenStream(), clang::PreprocessorLexer::getConditionalStackDepth(), clang::MultipleIncludeOpt::getHasReadAnyTokensVal(), clang::Token::getIdentifierInfo(), clang::MultipleIncludeOpt::getImmediatelyAfterTopLevelIfndef(), clang::Token::getKind(), getLangOpts(), clang::Token::getLocation(), clang::IdentifierInfo::getPPKeywordID(), clang::Token::is(), LexUnexpandedToken(), clang::PreprocessorLexer::MIOpt, clang::PreprocessorLexer::ParsingPreprocessorDirective, clang::PIK_HashPragma, clang::MultipleIncludeOpt::resetImmediatelyAfterTopLevelIfndef(), and setCodeCompletionReached().

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

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

Callback 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.

HandleEndOfFile - This callback is invoked when the lexer hits the end of the current file. This either returns the EOF token or pops a level off the include stack and keeps going.

Definition at line 294 of file PPLexerChange.cpp.

References computeRelativePath(), clang::FixItHint::CreateReplacement(), Diag(), clang::comments::tok::eof, clang::PPCallbacks::ExitFile, clang::HeaderSearch::FirstTimeLexingFile(), clang::MultipleIncludeOpt::GetControllingMacroAtEndOfFile(), getCurrentModule(), clang::MultipleIncludeOpt::GetDefinedLocation(), clang::MultipleIncludeOpt::GetDefinedMacro(), getDiagnostics(), clang::FileManager::getFile(), clang::SourceManager::getFileCharacteristic(), clang::SourceManager::getFileEntryForID(), clang::PreprocessorLexer::getFileID(), getFileManager(), getHeaderSearchInfo(), clang::SourceManager::getIncludeLoc(), clang::PreprocessorLexer::getInitialNumSLocEntries(), clang::Token::getLocation(), clang::SourceManager::getLocForStartOfFile(), clang::SourceLocation::getLocWithOffset(), getMacroInfo(), clang::MultipleIncludeOpt::GetMacroLocation(), clang::SourceManager::getMainFileID(), clang::HeaderSearch::getModuleMap(), clang::DirectoryEntry::getName(), clang::PreprocessorLexer::getSourceLocation(), getSourceManager(), clang::FileManager::getVirtualFileSystem(), clang::SourceManager::hasFileInfo(), clang::vfs::recursive_directory_iterator::increment(), isCodeCompletionEnabled(), clang::ModuleMap::isHeaderInUnavailableModule(), clang::DiagnosticsEngine::isIgnored(), isIncrementalProcessingEnabled(), clang::SourceLocation::isValid(), clang::SourceManager::local_sloc_entry_size(), clang::PreprocessorLexer::MIOpt, RemoveTopOfLexerStack(), clang::Token::setAnnotationEndLoc(), clang::Token::setAnnotationValue(), clang::HeaderSearch::SetFileControllingMacro(), clang::Token::setLocation(), clang::SourceManager::setNumCreatedFIDsForFileID(), clang::Token::startToken(), and clang::TU_Complete.

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 509 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.

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

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

HandleIdentifier - This callback is invoked when the lexer reads an identifier. 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 595 of file Preprocessor.cpp.

References Diag(), clang::Token::DisableExpand, clang::Token::getIdentifierInfo(), getLangOpts(), clang::Token::getLocation(), getMacroDirective(), HandlePoisonedIdentifier(), clang::MacroInfo::isEnabled(), clang::Token::isExpandDisabled(), clang::MacroInfo::isFunctionLike(), clang::MacroInfo::isObjectLike(), clang::IdentifierInfo::isPoisoned(), clang::Token::setFlag(), clang::Token::setIdentifierInfo(), clang::Token::setKind(), and clang::ExternalPreprocessorSource::updateOutOfDateIdentifier().

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

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 547 of file PPLexerChange.cpp.

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

Display reason for poisoned identifier.

Definition at line 576 of file Preprocessor.cpp.

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

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

void Preprocessor::HandlePragmaDependency ( Token DependencyTok)

Definition at line 364 of file Pragma.cpp.

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

Definition at line 353 of file Pragma.cpp.

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

void Preprocessor::HandlePragmaPoison ( Token PoisonTok)
void Preprocessor::HandlePragmaPopMacro ( Token PopMacroTok)
void Preprocessor::HandlePragmaPushMacro ( Token PushMacroTok)

Handle #pragma push_macro.

The syntax is:

   #pragma push_macro("macro")

Definition at line 560 of file Pragma.cpp.

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

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 1393 of file Pragma.cpp.

References AddPragmaHandler(), clang::PragmaNamespace::FindHandler(), clang::PragmaNamespace::getIfNamespace(), and RemovePragmaHandler().

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

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 1191 of file Preprocessor.h.

void Preprocessor::Initialize ( const TargetInfo Target)

Initialize the preprocessor using information about the target.

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

Definition at line 172 of file Preprocessor.cpp.

References BuiltinInfo, and clang::HeaderSearch::setTarget().

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 182 of file Preprocessor.cpp.

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

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

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

Definition at line 1170 of file Preprocessor.h.

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

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

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

Definition at line 1159 of file Preprocessor.h.

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

Definition at line 796 of file Preprocessor.h.

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

Determine if we are performing code completion.

Definition at line 975 of file Preprocessor.h.

Referenced by clang::Sema::ActOnEndOfTranslationUnit(), EnterSourceFile(), HandleEndOfFile(), clang::Parser::Parser(), and setCodeCompletionReached().

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

Definition at line 993 of file Preprocessor.h.

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

Definition at line 562 of file Preprocessor.h.

Returns true if incremental processing is enabled.

Definition at line 950 of file Preprocessor.h.

Referenced by HandleEndOfFile(), and clang::Parser::ParseTopLevelDecl().

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 EvaluateHasIncludeNext(), HandlePragmaOnce(), and HandlePragmaSystemHeader().

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

Definition at line 528 of file Preprocessor.h.

Referenced by EvaluateHasIncludeCommon().

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 559 of file Preprocessor.h.

void Preprocessor::Lex ( Token Result)
void clang::Preprocessor::LexNonComment ( Token Result) [inline]

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

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

Definition at line 827 of file Preprocessor.h.

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

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

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 782 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.

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

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

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

Definition at line 806 of file Preprocessor.h.

References FinishLexStringLiteral(), Lex(), and LexUnexpandedToken().

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

Definition at line 847 of file Preprocessor.h.

References clang::Token::getKind(), and LexUnexpandedToken().

Referenced by EvaluateDefined().

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

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

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

Definition at line 871 of file Preprocessor.h.

Referenced by clang::Parser::NextToken(), and ParseOpenMPDirectiveKind().

const FileEntry * Preprocessor::LookupFile ( SourceLocation  FilenameLoc,
StringRef  Filename,
bool  isAngled,
const DirectoryLookup FromDir,
const FileEntry FromFile,
const DirectoryLookup *&  CurDir,
SmallVectorImpl< char > *  SearchPath,
SmallVectorImpl< char > *  RelativePath,
ModuleMap::KnownHeader SuggestedModule,
bool  SkipCache = false 
)

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 529 of file Preprocessor.cpp.

References clang::expandUCNs(), getIdentifierInfo(), clang::Token::getRawIdentifier(), getSpelling(), clang::Token::hasUCN(), clang::Token::needsCleaning(), clang::Token::setIdentifierInfo(), and clang::Token::setKind().

Referenced by HandlePragmaPoison(), clang::html::HighlightMacros(), LexRawTokensFromMainFile(), ParsePragmaPushOrPopMacro(), and clang::html::SyntaxHighlight().

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

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

Definition at line 1560 of file PPMacroExpansion.cpp.

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

Referenced by EvaluateDefined().

ParsePragmaPushOrPopMacro - Handle parsing of pragma push_macro/pop_macro. Return the IdentifierInfo* associated with the macro to push or pop.

Definition at line 505 of file Pragma.cpp.

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

Referenced by HandlePragmaPopMacro(), and HandlePragmaPushMacro().

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

Parses a simple integer literal to get its numeric value. Floating point literals and user defined literals are rejected. Used primarily to handle pragmas that accept integer arguments.

Definition at line 799 of file Preprocessor.cpp.

References clang::Token::getLocation(), getSpelling(), clang::Token::is(), and Lex().

Definition at line 562 of file Preprocessor.cpp.

References clang::IdentifierInfo::setIsPoisoned().

Definition at line 242 of file Preprocessor.cpp.

References getTotalMemory().

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

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

Definition at line 344 of file Preprocessor.cpp.

Referenced by Backtrack(), and LexAfterModuleImport().

Remove the specified comment handler.

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

Definition at line 824 of file Preprocessor.cpp.

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

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

Remove the specific pragma handler from this 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.

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.

Definition at line 760 of file Pragma.cpp.

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

Referenced by IgnorePragmas(), and RemovePragmaHandler().

Definition at line 687 of file Preprocessor.h.

References RemovePragmaHandler().

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.

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 unknown.

Definition at line 530 of file PPLexerChange.cpp.

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

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 931 of file Preprocessor.h.

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

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 883 of file Preprocessor.h.

References isBacktrackEnabled().

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

Definition at line 1301 of file Preprocessor.h.

Set the code completion handler to the given object.

Definition at line 703 of file Preprocessor.h.

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

bool Preprocessor::SetCodeCompletionPoint ( const FileEntry File,
unsigned  Line,
unsigned  Column 
)

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

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

Definition at line 355 of file Preprocessor.cpp.

References clang::SourceManager::getFileEntryForID(), clang::SourceManager::getMainFileID(), clang::SourceManager::getMemoryBufferForFile(), Line, clang::SourceManager::overrideFileContents(), Position, and SourceMgr.

Referenced by EnableCodeCompletion().

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

Control whether the preprocessor retains comments in output.

Definition at line 533 of file Preprocessor.h.

Referenced by clang::DoPrintPreprocessedInput().

Definition at line 1305 of file Preprocessor.h.

Definition at line 495 of file Preprocessor.h.

Definition at line 512 of file Preprocessor.h.

Set a MacroDirective that was loaded from a PCH file.

Definition at line 62 of file PPMacroExpansion.cpp.

References clang::MacroDirective::isDefined(), and clang::IdentifierInfo::setHasMacroDefinition().

Disables macro expansion everywhere except for preprocessor directives.

Definition at line 859 of file Preprocessor.h.

Referenced by clang::RewriteIncludesInInput().

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 558 of file Preprocessor.cpp.

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

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

Definition at line 1013 of file Preprocessor.h.

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

Definition at line 540 of file Preprocessor.h.

void clang::Preprocessor::setPredefines ( const char *  P) [inline]

Set the predefines for this Preprocessor.

These predefines are automatically injected when parsing the main file.

Definition at line 663 of file Preprocessor.h.

References P.

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

void clang::Preprocessor::setPredefines ( const std::string &  P) [inline]

Definition at line 664 of file Preprocessor.h.

References P.

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

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

Definition at line 553 of file Preprocessor.h.

Definition at line 200 of file Preprocessor.cpp.

References clang::FileManager::addStatCache().

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

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

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

Definition at line 1023 of file Preprocessor.h.

Referenced by clang::InitializePreprocessor().

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

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

Definition at line 939 of file Preprocessor.h.

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


Friends And Related Function Documentation

friend class ASTReader [friend]

Definition at line 364 of file Preprocessor.h.

friend class MacroArgs [friend]

Definition at line 381 of file Preprocessor.h.

void TokenLexer::ExpandFunctionArguments ( ) [friend]

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