46 #include "llvm/ADT/APInt.h"
47 #include "llvm/ADT/DenseMap.h"
48 #include "llvm/ADT/SmallString.h"
49 #include "llvm/ADT/SmallVector.h"
50 #include "llvm/ADT/STLExtras.h"
51 #include "llvm/ADT/StringRef.h"
52 #include "llvm/ADT/StringSwitch.h"
53 #include "llvm/Support/Capacity.h"
54 #include "llvm/Support/ErrorHandling.h"
55 #include "llvm/Support/MemoryBuffer.h"
56 #include "llvm/Support/raw_ostream.h"
64 using namespace clang;
77 : PPOpts(std::move(PPOpts)), Diags(&diags), LangOpts(opts), Target(nullptr),
78 AuxTarget(nullptr), FileMgr(Headers.getFileMgr()),
SourceMgr(SM),
80 HeaderInfo(Headers), TheModuleLoader(TheModuleLoader),
81 ExternalSource(nullptr), Identifiers(opts, IILookup),
83 IncrementalProcessing(
false), TUKind(TUKind), CodeComplete(nullptr),
84 CodeCompletionFile(nullptr), CodeCompletionOffset(0),
85 LastTokenWasAt(
false), ModuleImportExpectsIdentifier(
false),
86 CodeCompletionReached(
false), CodeCompletionII(nullptr),
87 MainFileDir(nullptr), SkipMainFilePreamble(0,
true), CurPPLexer(nullptr),
88 CurDirLookup(nullptr), CurLexerKind(CLK_Lexer),
89 CurLexerSubmodule(nullptr), Callbacks(nullptr),
90 CurSubmoduleState(&NullSubmoduleState), MacroArgCache(nullptr),
91 Record(nullptr), MIChainHead(nullptr) {
92 OwnsHeaderSearch = OwnsHeaders;
97 NumDirectives = NumDefined = NumUndefined = NumPragma = 0;
98 NumIf = NumElse = NumEndif = 0;
99 NumEnteredSourceFiles = 0;
100 NumMacroExpanded = NumFnMacroExpanded = NumBuiltinMacroExpanded = 0;
101 NumFastMacroExpanded = NumTokenPaste = NumFastTokenPaste = 0;
102 MaxIncludeStackDepth = 0;
106 KeepComments =
false;
107 KeepMacroComments =
false;
108 SuppressIncludeNotFoundError =
false;
111 DisableMacroExpansion =
false;
112 MacroExpansionInDirectivesOverride =
false;
114 InMacroArgPreExpansion =
false;
115 NumCachedTokenLexers = 0;
116 PragmasEnabled =
true;
117 ParsingIfOrElifDirective =
false;
118 PreprocessedOutput =
false;
123 ReadMacrosFromExternalSource =
false;
131 RegisterBuiltinPragmas();
134 RegisterBuiltinMacros();
136 if(LangOpts.Borland) {
147 Ident__exception_info = Ident__exception_code =
nullptr;
148 Ident__abnormal_termination = Ident___exception_info =
nullptr;
149 Ident___exception_code = Ident___abnormal_termination =
nullptr;
150 Ident_GetExceptionInfo = Ident_GetExceptionCode =
nullptr;
151 Ident_AbnormalTermination =
nullptr;
154 if (this->PPOpts->GeneratePreamble)
155 PreambleConditionalStack.startRecording();
159 assert(BacktrackPositions.empty() &&
"EnableBacktrack/Backtrack imbalance!");
161 IncludeMacroStack.clear();
164 while (MacroInfoChain *
I = MIChainHead) {
165 MIChainHead =
I->Next;
166 I->~MacroInfoChain();
172 std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers,
nullptr);
173 CurTokenLexer.reset();
176 for (
MacroArgs *ArgList = MacroArgCache; ArgList;)
177 ArgList = ArgList->deallocate();
180 if (OwnsHeaderSearch)
186 assert((!this->Target || this->Target == &Target) &&
187 "Invalid override of target information");
188 this->Target = &Target;
190 assert((!this->AuxTarget || this->AuxTarget == AuxTarget) &&
191 "Invalid override of aux target information.");
192 this->AuxTarget = AuxTarget;
200 NumEnteredSourceFiles = 0;
203 PragmaHandlersBackup = std::move(PragmaHandlers);
204 PragmaHandlers = llvm::make_unique<PragmaNamespace>(StringRef());
205 RegisterBuiltinPragmas();
208 PredefinesFileID =
FileID();
212 NumEnteredSourceFiles = 1;
214 PragmaHandlers = std::move(PragmaHandlersBackup);
226 if (!DumpFlags)
return;
228 llvm::errs() <<
"\t";
230 llvm::errs() <<
" [StartOfLine]";
232 llvm::errs() <<
" [LeadingSpace]";
234 llvm::errs() <<
" [ExpandDisabled]";
237 llvm::errs() <<
" [UnClean='" << StringRef(Start, Tok.
getLength())
241 llvm::errs() <<
"\tLoc=<";
251 llvm::errs() <<
"MACRO: ";
252 for (
unsigned i = 0, e = MI.
getNumTokens(); i != e; ++i) {
256 llvm::errs() <<
"\n";
260 llvm::errs() <<
"\n*** Preprocessor Stats:\n";
261 llvm::errs() << NumDirectives <<
" directives found:\n";
262 llvm::errs() <<
" " << NumDefined <<
" #define.\n";
263 llvm::errs() <<
" " << NumUndefined <<
" #undef.\n";
264 llvm::errs() <<
" #include/#include_next/#import:\n";
265 llvm::errs() <<
" " << NumEnteredSourceFiles <<
" source files entered.\n";
266 llvm::errs() <<
" " << MaxIncludeStackDepth <<
" max include stack depth\n";
267 llvm::errs() <<
" " << NumIf <<
" #if/#ifndef/#ifdef.\n";
268 llvm::errs() <<
" " << NumElse <<
" #else/#elif.\n";
269 llvm::errs() <<
" " << NumEndif <<
" #endif.\n";
270 llvm::errs() <<
" " << NumPragma <<
" #pragma.\n";
271 llvm::errs() << NumSkipped <<
" #if/#ifndef#ifdef regions skipped\n";
273 llvm::errs() << NumMacroExpanded <<
"/" << NumFnMacroExpanded <<
"/"
274 << NumBuiltinMacroExpanded <<
" obj/fn/builtin macros expanded, "
275 << NumFastMacroExpanded <<
" on the fast path.\n";
276 llvm::errs() << (NumFastTokenPaste+NumTokenPaste)
277 <<
" token paste (##) operations performed, "
278 << NumFastTokenPaste <<
" on the fast path.\n";
280 llvm::errs() <<
"\nPreprocessor Memory: " <<
getTotalMemory() <<
"B total";
282 llvm::errs() <<
"\n BumpPtr: " << BP.getTotalMemory();
283 llvm::errs() <<
"\n Macro Expanded Tokens: "
284 << llvm::capacity_in_bytes(MacroExpandedTokens);
285 llvm::errs() <<
"\n Predefines Buffer: " << Predefines.capacity();
287 llvm::errs() <<
"\n Macros: "
288 << llvm::capacity_in_bytes(CurSubmoduleState->Macros);
289 llvm::errs() <<
"\n #pragma push_macro Info: "
290 << llvm::capacity_in_bytes(PragmaPushMacroInfo);
291 llvm::errs() <<
"\n Poison Reasons: "
292 << llvm::capacity_in_bytes(PoisonReasons);
293 llvm::errs() <<
"\n Comment Handlers: "
294 << llvm::capacity_in_bytes(CommentHandlers) <<
"\n";
299 if (IncludeExternalMacros && ExternalSource &&
300 !ReadMacrosFromExternalSource) {
301 ReadMacrosFromExternalSource =
true;
307 CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
309 return CurSubmoduleState->Macros.begin();
313 return BP.getTotalMemory()
314 + llvm::capacity_in_bytes(MacroExpandedTokens)
315 + Predefines.capacity()
318 + llvm::capacity_in_bytes(CurSubmoduleState->Macros)
319 + llvm::capacity_in_bytes(PragmaPushMacroInfo)
320 + llvm::capacity_in_bytes(PoisonReasons)
321 + llvm::capacity_in_bytes(CommentHandlers);
326 if (IncludeExternalMacros && ExternalSource &&
327 !ReadMacrosFromExternalSource) {
328 ReadMacrosFromExternalSource =
true;
332 return CurSubmoduleState->Macros.end();
339 std::equal(Tokens.begin(), Tokens.end(), MI->
tokens_begin());
346 StringRef BestSpelling;
350 Def =
I->second.findDirectiveAtLoc(Loc, SourceMgr);
362 BestLocation = Location;
363 BestSpelling =
I->first->getName();
371 CurLexerKind = CLK_Lexer;
372 else if (CurPTHLexer)
373 CurLexerKind = CLK_PTHLexer;
374 else if (CurTokenLexer)
375 CurLexerKind = CLK_TokenLexer;
377 CurLexerKind = CLK_CachingLexer;
381 unsigned CompleteLine,
382 unsigned CompleteColumn) {
384 assert(CompleteLine && CompleteColumn &&
"Starts from 1:1");
385 assert(!CodeCompletionFile &&
"Already set");
387 using llvm::MemoryBuffer;
390 bool Invalid =
false;
396 const char *
Position = Buffer->getBufferStart();
399 if (*Position !=
'\r' && *Position !=
'\n')
403 if ((Position[1] ==
'\r' || Position[1] ==
'\n') &&
404 Position[0] != Position[1])
411 Position += CompleteColumn - 1;
415 if (SkipMainFilePreamble.first &&
417 if (Position - Buffer->getBufferStart() < SkipMainFilePreamble.first)
418 Position = Buffer->getBufferStart() + SkipMainFilePreamble.first;
421 if (Position > Buffer->getBufferEnd())
422 Position = Buffer->getBufferEnd();
424 CodeCompletionFile = File;
425 CodeCompletionOffset = Position - Buffer->getBufferStart();
427 std::unique_ptr<MemoryBuffer> NewBuffer =
428 MemoryBuffer::getNewUninitMemBuffer(Buffer->getBufferSize() + 1,
429 Buffer->getBufferIdentifier());
430 char *NewBuf =
const_cast<char*
>(NewBuffer->getBufferStart());
431 char *NewPos = std::copy(Buffer->getBufferStart(),
Position, NewBuf);
433 std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
450 bool *Invalid)
const {
452 if (Tok.
isNot(tok::raw_identifier) && !Tok.
hasUCN()) {
455 return II->getName();
462 const char *Ptr = Buffer.data();
464 return StringRef(Ptr, Len);
476 SourceLocation Loc = ScratchBuf->getToken(Str.data(), Str.size(), DestPtr);
478 if (ExpansionLocStart.
isValid())
480 ExpansionLocEnd, Str.size());
484 if (Tok.
is(tok::raw_identifier))
507 assert(NumEnteredSourceFiles == 0 &&
"Cannot reenter the main file!");
518 if (SkipMainFilePreamble.first > 0)
519 CurLexer->SkipBytes(SkipMainFilePreamble.first,
520 SkipMainFilePreamble.second);
529 std::unique_ptr<llvm::MemoryBuffer> SB =
530 llvm::MemoryBuffer::getMemBufferCopy(Predefines,
"<built-in>");
531 assert(SB &&
"Cannot create predefined source buffer");
533 assert(FID.
isValid() &&
"Could not create FileID for predefines?");
534 setPredefinesFileID(FID);
540 void Preprocessor::replayPreambleConditionalStack() {
542 if (PreambleConditionalStack.isReplaying()) {
544 "CurPPLexer is null when calling replayPreambleConditionalStack.");
546 PreambleConditionalStack.doneReplaying();
553 Callbacks->EndOfMainFile();
564 assert(!Identifier.
getRawIdentifier().empty() &&
"No raw identifier data!");
574 StringRef CleanedStr =
getSpelling(Identifier, IdentifierBuffer);
576 if (Identifier.
hasUCN()) {
587 if (
getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() &&
589 Identifier.
setKind(clang::tok::identifier);
591 Identifier.
setKind(II->getTokenID());
597 PoisonReasons[II] = DiagID;
601 assert(Ident__exception_code && Ident__exception_info);
602 assert(Ident___exception_code && Ident___exception_info);
616 "Can't handle identifiers without identifier info!");
617 llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it =
619 if(it == PoisonReasons.end())
620 Diag(Identifier, diag::err_pp_used_poisoned_id);
631 if (LangOpts.CPlusPlus)
632 return llvm::StringSwitch<diag::kind>(II.
getName())
634 .Case(#NAME, diag::warn_cxx11_keyword)
635 #include "clang/Basic/TokenKinds.def"
639 "Keyword not known to come from a newer Standard or proposed Standard");
642 void Preprocessor::updateOutOfDateIdentifier(
IdentifierInfo &II)
const {
657 "Can't handle identifiers without identifier info!");
666 if (II.isOutOfDate()) {
667 bool CurrentIsPoisoned =
false;
668 if (&II == Ident__VA_ARGS__)
669 CurrentIsPoisoned = Ident__VA_ARGS__->
isPoisoned();
671 updateOutOfDateIdentifier(II);
672 Identifier.
setKind(II.getTokenID());
674 if (&II == Ident__VA_ARGS__)
675 II.setIsPoisoned(CurrentIsPoisoned);
680 if (II.isPoisoned() && CurPPLexer) {
686 auto *MI = MD.getMacroInfo();
687 assert(MI &&
"macro definition with no macro info?");
688 if (!DisableMacroExpansion) {
692 if (!MI->isFunctionLike() || isNextPPTokenLParen())
693 return HandleMacroExpandedIdentifier(Identifier, MD);
699 if (MI->isObjectLike() || isNextPPTokenLParen())
700 Diag(Identifier, diag::pp_disabled_macro_expansion);
710 if (II.isFutureCompatKeyword() && !DisableMacroExpansion) {
714 II.setIsFutureCompatKeyword(
false);
721 if (II.isExtensionToken() && !DisableMacroExpansion)
722 Diag(Identifier, diag::ext_token_used);
732 if (((LastTokenWasAt && II.isModulesImport()) ||
733 Identifier.
is(tok::kw_import)) &&
734 !InMacroArgs && !DisableMacroExpansion &&
736 CurLexerKind != CLK_CachingLexer) {
738 ModuleImportPath.clear();
739 ModuleImportExpectsIdentifier =
true;
740 CurLexerKind = CLK_LexAfterModuleImport;
749 switch (CurLexerKind) {
751 ReturnedToken = CurLexer->Lex(Result);
754 ReturnedToken = CurPTHLexer->Lex(Result);
757 ReturnedToken = CurTokenLexer->Lex(Result);
759 case CLK_CachingLexer:
761 ReturnedToken =
true;
763 case CLK_LexAfterModuleImport:
765 ReturnedToken =
true;
768 }
while (!ReturnedToken);
770 if (Result.
is(tok::code_completion))
773 LastTokenWasAt = Result.
is(tok::at);
791 if (ModuleImportExpectsIdentifier && Result.
getKind() == tok::identifier) {
796 ModuleImportExpectsIdentifier =
false;
797 CurLexerKind = CLK_LexAfterModuleImport;
804 if (!ModuleImportExpectsIdentifier && Result.
getKind() == tok::period) {
805 ModuleImportExpectsIdentifier =
true;
806 CurLexerKind = CLK_LexAfterModuleImport;
811 if (!ModuleImportPath.empty()) {
816 std::string FlatModuleName;
818 for (
auto &Piece : ModuleImportPath) {
819 if (!FlatModuleName.empty())
820 FlatModuleName +=
".";
821 FlatModuleName += Piece.first->getName();
824 ModuleImportPath.clear();
825 ModuleImportPath.push_back(
829 Module *Imported =
nullptr;
831 Imported = TheModuleLoader.
loadModule(ModuleImportLoc,
839 Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
844 CurSubmoduleState->VisibleModules.setVisible(
849 Diag(ModuleImportLoc, diag::warn_module_conflict)
850 << Path[0]->getFullModuleName()
851 << Conflict->getFullModuleName()
856 if (!BuildingSubmoduleStack.empty() && M != BuildingSubmoduleStack.back().M)
857 BuildingSubmoduleStack.back().M->Imports.insert(M);
861 const char *DiagnosticTag,
862 bool AllowMacroExpansion) {
864 if (Result.
isNot(tok::string_literal)) {
865 Diag(Result, diag::err_expected_string_literal)
866 << 0 << DiagnosticTag;
873 StrToks.push_back(Result);
876 Diag(Result, diag::err_invalid_string_udl);
878 if (AllowMacroExpansion)
882 }
while (Result.
is(tok::string_literal));
886 assert(Literal.
isAscii() &&
"Didn't allow wide strings in");
892 Diag(StrToks[0].getLocation(), diag::err_expected_string_literal)
893 << 0 << DiagnosticTag;
902 assert(Tok.
is(tok::numeric_constant));
904 bool NumberInvalid =
false;
905 StringRef Spelling =
getSpelling(Tok, IntegerBuffer, &NumberInvalid);
909 if (Literal.hadError || !Literal.isIntegerLiteral() || Literal.hasUDSuffix())
911 llvm::APInt APVal(64, 0);
912 if (Literal.GetIntegerValue(APVal))
915 Value = APVal.getLimitedValue();
920 assert(Handler &&
"NULL comment handler");
921 assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) ==
922 CommentHandlers.end() &&
"Comment handler already registered");
923 CommentHandlers.push_back(Handler);
927 std::vector<CommentHandler *>::iterator Pos
928 = std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler);
929 assert(Pos != CommentHandlers.end() &&
"Comment handler not registered");
930 CommentHandlers.erase(Pos);
934 bool AnyPendingTokens =
false;
935 for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(),
936 HEnd = CommentHandlers.end();
938 if ((*H)->HandleComment(*
this, Comment))
939 AnyPendingTokens =
true;
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
SourceManager & getSourceManager() const
bool isPoisoned() const
Return true if this token has been poisoned.
ExternalPreprocessorSource * getExternalSource() const
void FinalizeForModelFile()
Cleanup after model file parsing.
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
Defines the clang::FileManager interface and associated types.
Defines the SourceManager interface.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
Defines the FileSystemStatCache interface.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
bool isObjectLike() const
virtual void CodeCompleteNaturalLanguage()
Callback invoked when performing code completion in a part of the file where we expect natural langua...
Defines the clang::MacroInfo and clang::MacroDirective classes.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
A description of the current definition of a macro.
void LexAfterModuleImport(Token &Result)
Lex a token following the 'import' contextual keyword.
std::unique_ptr< llvm::MemoryBuffer > Buffer
bool hasUCN() const
Returns true if this token contains a universal character name.
void setFlag(TokenFlags Flag)
Set the specified flag.
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
MacroMap::const_iterator macro_iterator
void setCodeCompletionIdentifierInfo(IdentifierInfo *Filter)
Set the code completion token for filtering purposes.
void setCodeCompletionReached()
Note that we hit the code-completion point.
void createPreprocessingRecord()
Create a new preprocessing record, which will keep track of all macro expansions, macro definitions...
bool parseSimpleIntegerLiteral(Token &Tok, uint64_t &Value)
Parses a simple integer literal to get its numeric value.
void setPTHManager(PTHManager *pm)
Manage memory buffers across multiple users.
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 ...
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
void SetPoisonReason(IdentifierInfo *II, unsigned DiagID)
Specifies the reason for poisoning an identifier.
One of these records is kept for each identifier that is lexed.
Represents a macro directive exported by a module.
void setRawIdentifierData(const char *Ptr)
SourceLocation getLocation() const
Preprocessor(std::shared_ptr< PreprocessorOptions > PPOpts, DiagnosticsEngine &diags, LangOptions &opts, SourceManager &SM, MemoryBufferCache &PCMCache, HeaderSearch &Headers, ModuleLoader &TheModuleLoader, IdentifierInfoLookup *IILookup=nullptr, bool OwnsHeaderSearch=false, TranslationUnitKind TUKind=TU_Complete)
const LangOptions & getLangOpts() const
Token - This structure provides full information about a lexed token.
void setKind(tok::TokenKind K)
void removeCommentHandler(CommentHandler *Handler)
Remove the specified comment handler.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes a module or submodule.
bool SetCodeCompletionPoint(const FileEntry *File, unsigned Line, unsigned Column)
Specify the point at which code-completion will be performed.
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
bool getCommentRetentionState() const
void Initialize(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize the preprocessor using information about the target.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
Concrete class used by the front-end to report problems and issues.
HeaderSearch & getHeaderSearchInfo() const
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
tokens_iterator tokens_begin() const
void dump(const SourceManager &SM) const
tok::TokenKind getKind() const
detail::InMemoryDirectory::const_iterator I
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
void LexUnexpandedToken(Token &Result)
Just like Lex, but disables macro expansion of identifier tokens.
void recomputeCurLexerKind()
Recompute the current lexer kind based on the CurLexer/CurPTHLexer/ CurTokenLexer pointers...
StringRef getRawIdentifier() const
getRawIdentifier - For a raw identifier token (i.e., an identifier lexed in raw mode), returns a reference to the text substring in the buffer if known.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
Provides lookups to, and iteration over, IdentiferInfo objects.
Exposes information about the current target.
Abstract interface for external sources of preprocessor information.
StringRef getName() const
Return the actual identifier string.
void makeModuleVisible(Module *M, SourceLocation Loc)
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID=0, unsigned LoadedOffset=0)
Create a new FileID that represents the specified file being #included from the specified IncludePosi...
virtual void ReadDefinedMacros()=0
Read the set of macros defined by this external macro source.
MacroArgs - An instance of this class captures information about the formal arguments specified to a ...
void EnterMainSourceFile()
Enter the specified FileID as the main source file, which implicitly adds the builtin defines etc...
llvm::Registry< PragmaHandler > PragmaHandlerRegistry
Registry of pragma handlers added by plugins.
Defines the clang::Preprocessor interface.
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix. ...
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
static bool MacroDefinitionEquals(const MacroInfo *MI, ArrayRef< TokenValue > Tokens)
Compares macro tokens with a specified token value sequence.
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
bool isNot(tok::TokenKind K) const
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
void overrideFileContents(const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree)
Override the contents of the given source file by providing an already-allocated buffer.
size_t getTotalMemory() const
void addStatCache(std::unique_ptr< FileSystemStatCache > statCache, bool AtBeginning=false)
Installs the provided FileSystemStatCache object within the FileManager.
Encodes a location in the source.
void setLength(unsigned Len)
StringRef GetString() const
bool isValid() const
Return true if this is a valid SourceLocation object.
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
macro_iterator macro_end(bool IncludeExternalMacros=true) const
All of the names in this module are hidden.
Cached information about one file (either on disk or in the virtual file system). ...
void setIdentifierInfo(IdentifierInfo *II)
void Lex(Token &Result)
Lex the next token for this preprocessor.
llvm::MemoryBuffer * getMemoryBufferForFile(const FileEntry *File, bool *Invalid=nullptr)
Retrieve the memory buffer associated with the given file.
ArrayRef< FormatToken * > Tokens
const Token & getReplacementToken(unsigned Tok) const
FileID getMainFileID() const
Returns the FileID of the main source file.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
static diag::kind getFutureCompatDiagKind(const IdentifierInfo &II, const LangOptions &LangOpts)
Returns a diagnostic message kind for reporting a future keyword as appropriate for the identifier an...
void addCommentHandler(CommentHandler *Handler)
Add the specified comment handler to the preprocessor.
MacroInfo * getMacroInfo()
virtual ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path, Module::NameVisibilityKind Visibility, bool IsInclusionDirective)=0
Attempt to load the given module.
void CodeCompleteNaturalLanguage()
Hook used by the lexer to invoke the "natural language" code completion point.
detail::InMemoryDirectory::const_iterator E
Abstract interface for a module loader.
void PoisonSEHIdentifiers(bool Poison=true)
void setLiteralData(const char *Ptr)
bool isLiteral() const
Return true if this is a "literal", like a numeric constant, string, etc.
Encapsulates the data about a macro definition (e.g.
PragmaNamespace - This PragmaHandler subdivides the namespace of pragmas, allowing hierarchical pragm...
bool HandleIdentifier(Token &Identifier)
Callback invoked when the lexer reads an identifier and has filled in the tokens IdentifierInfo membe...
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 LexStringLi...
void setConditionalLevels(ArrayRef< PPConditionalInfo > CL)
virtual void updateOutOfDateIdentifier(IdentifierInfo &II)=0
Update an out-of-date identifier.
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 ...
void InitializeForModelFile()
Initialize the preprocessor to parse a model file.
void HandlePoisonedIdentifier(Token &Tok)
Display reason for poisoned identifier.
#define CXX11_KEYWORD(NAME, FLAGS)
bool HandleComment(Token &Token, SourceRange Comment)
void DumpMacro(const MacroInfo &MI) const
TranslationUnitKind
Describes the kind of translation unit being processed.
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
unsigned kind
All of the diagnostics that can be emitted by the frontend.
const char * getTokenName(TokenKind Kind) LLVM_READNONE
Determines the name of a token as used within the front end.
Defines the clang::TargetInfo interface.
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber...
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
unsigned getLength() const
void DumpLocation(SourceLocation Loc) const
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
ScratchBuffer - This class exposes a simple interface for the dynamic construction of tokens...
bool isExpandDisabled() const
Return true if this identifier token should never be expanded in the future, due to C99 6...
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
void addPPCallbacks(std::unique_ptr< PPCallbacks > C)
This class handles loading and caching of source files into memory.
virtual ~CodeCompletionHandler()
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 curr...
IdentifierInfo * getIdentifierInfo() const