56 #include "llvm/ADT/APInt.h" 57 #include "llvm/ADT/ArrayRef.h" 58 #include "llvm/ADT/DenseMap.h" 59 #include "llvm/ADT/SmallString.h" 60 #include "llvm/ADT/SmallVector.h" 61 #include "llvm/ADT/STLExtras.h" 62 #include "llvm/ADT/StringRef.h" 63 #include "llvm/ADT/StringSwitch.h" 64 #include "llvm/Support/Capacity.h" 65 #include "llvm/Support/ErrorHandling.h" 66 #include "llvm/Support/MemoryBuffer.h" 67 #include "llvm/Support/raw_ostream.h" 75 using namespace clang;
87 : PPOpts(
std::move(PPOpts)), Diags(&diags), LangOpts(opts),
88 FileMgr(Headers.getFileMgr()), SourceMgr(SM),
90 HeaderInfo(Headers), TheModuleLoader(TheModuleLoader),
91 ExternalSource(nullptr), Identifiers(opts, IILookup),
93 SkipMainFilePreamble(0,
true),
94 CurSubmoduleState(&NullSubmoduleState) {
95 OwnsHeaderSearch = OwnsHeaders;
99 KeepMacroComments =
false;
100 SuppressIncludeNotFoundError =
false;
103 DisableMacroExpansion =
false;
104 MacroExpansionInDirectivesOverride =
false;
106 InMacroArgPreExpansion =
false;
107 NumCachedTokenLexers = 0;
108 PragmasEnabled =
true;
109 ParsingIfOrElifDirective =
false;
110 PreprocessedOutput =
false;
113 ReadMacrosFromExternalSource =
false;
123 Ident__VA_OPT__ =
nullptr;
127 RegisterBuiltinPragmas();
130 RegisterBuiltinMacros();
132 if(LangOpts.Borland) {
143 Ident__exception_info = Ident__exception_code =
nullptr;
144 Ident__abnormal_termination = Ident___exception_info =
nullptr;
145 Ident___exception_code = Ident___abnormal_termination =
nullptr;
146 Ident_GetExceptionInfo = Ident_GetExceptionCode =
nullptr;
147 Ident_AbnormalTermination =
nullptr;
150 if (this->PPOpts->GeneratePreamble)
151 PreambleConditionalStack.startRecording();
155 assert(BacktrackPositions.empty() &&
"EnableBacktrack/Backtrack imbalance!");
157 IncludeMacroStack.clear();
160 while (MacroInfoChain *I = MIChainHead) {
161 MIChainHead = I->Next;
162 I->~MacroInfoChain();
168 std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers,
nullptr);
169 CurTokenLexer.reset();
172 for (
MacroArgs *ArgList = MacroArgCache; ArgList;)
173 ArgList = ArgList->deallocate();
176 if (OwnsHeaderSearch)
182 assert((!this->Target || this->Target == &Target) &&
183 "Invalid override of target information");
184 this->Target = &Target;
186 assert((!this->AuxTarget || this->AuxTarget == AuxTarget) &&
187 "Invalid override of aux target information.");
188 this->AuxTarget = AuxTarget;
196 NumEnteredSourceFiles = 0;
199 PragmaHandlersBackup = std::move(PragmaHandlers);
200 PragmaHandlers = llvm::make_unique<PragmaNamespace>(StringRef());
201 RegisterBuiltinPragmas();
204 PredefinesFileID =
FileID();
208 NumEnteredSourceFiles = 1;
210 PragmaHandlers = std::move(PragmaHandlersBackup);
222 if (!DumpFlags)
return;
224 llvm::errs() <<
"\t";
226 llvm::errs() <<
" [StartOfLine]";
228 llvm::errs() <<
" [LeadingSpace]";
230 llvm::errs() <<
" [ExpandDisabled]";
233 llvm::errs() <<
" [UnClean='" << StringRef(Start, Tok.
getLength())
237 llvm::errs() <<
"\tLoc=<";
247 llvm::errs() <<
"MACRO: ";
248 for (
unsigned i = 0, e = MI.
getNumTokens(); i != e; ++i) {
252 llvm::errs() <<
"\n";
256 llvm::errs() <<
"\n*** Preprocessor Stats:\n";
257 llvm::errs() << NumDirectives <<
" directives found:\n";
258 llvm::errs() <<
" " << NumDefined <<
" #define.\n";
259 llvm::errs() <<
" " << NumUndefined <<
" #undef.\n";
260 llvm::errs() <<
" #include/#include_next/#import:\n";
261 llvm::errs() <<
" " << NumEnteredSourceFiles <<
" source files entered.\n";
262 llvm::errs() <<
" " << MaxIncludeStackDepth <<
" max include stack depth\n";
263 llvm::errs() <<
" " << NumIf <<
" #if/#ifndef/#ifdef.\n";
264 llvm::errs() <<
" " << NumElse <<
" #else/#elif.\n";
265 llvm::errs() <<
" " << NumEndif <<
" #endif.\n";
266 llvm::errs() <<
" " << NumPragma <<
" #pragma.\n";
267 llvm::errs() << NumSkipped <<
" #if/#ifndef#ifdef regions skipped\n";
269 llvm::errs() << NumMacroExpanded <<
"/" << NumFnMacroExpanded <<
"/" 270 << NumBuiltinMacroExpanded <<
" obj/fn/builtin macros expanded, " 271 << NumFastMacroExpanded <<
" on the fast path.\n";
272 llvm::errs() << (NumFastTokenPaste+NumTokenPaste)
273 <<
" token paste (##) operations performed, " 274 << NumFastTokenPaste <<
" on the fast path.\n";
276 llvm::errs() <<
"\nPreprocessor Memory: " <<
getTotalMemory() <<
"B total";
278 llvm::errs() <<
"\n BumpPtr: " << BP.getTotalMemory();
279 llvm::errs() <<
"\n Macro Expanded Tokens: " 280 << llvm::capacity_in_bytes(MacroExpandedTokens);
281 llvm::errs() <<
"\n Predefines Buffer: " << Predefines.capacity();
283 llvm::errs() <<
"\n Macros: " 284 << llvm::capacity_in_bytes(CurSubmoduleState->Macros);
285 llvm::errs() <<
"\n #pragma push_macro Info: " 286 << llvm::capacity_in_bytes(PragmaPushMacroInfo);
287 llvm::errs() <<
"\n Poison Reasons: " 288 << llvm::capacity_in_bytes(PoisonReasons);
289 llvm::errs() <<
"\n Comment Handlers: " 290 << llvm::capacity_in_bytes(CommentHandlers) <<
"\n";
295 if (IncludeExternalMacros && ExternalSource &&
296 !ReadMacrosFromExternalSource) {
297 ReadMacrosFromExternalSource =
true;
303 CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
305 return CurSubmoduleState->Macros.begin();
309 return BP.getTotalMemory()
310 + llvm::capacity_in_bytes(MacroExpandedTokens)
311 + Predefines.capacity()
314 + llvm::capacity_in_bytes(CurSubmoduleState->Macros)
315 + llvm::capacity_in_bytes(PragmaPushMacroInfo)
316 + llvm::capacity_in_bytes(PoisonReasons)
317 + llvm::capacity_in_bytes(CommentHandlers);
322 if (IncludeExternalMacros && ExternalSource &&
323 !ReadMacrosFromExternalSource) {
324 ReadMacrosFromExternalSource =
true;
328 return CurSubmoduleState->Macros.end();
335 std::equal(Tokens.begin(), Tokens.end(), MI->
tokens_begin());
342 StringRef BestSpelling;
346 Def = I->second.findDirectiveAtLoc(Loc, SourceMgr);
358 BestLocation = Location;
359 BestSpelling = I->first->getName();
367 CurLexerKind = CLK_Lexer;
368 else if (CurPTHLexer)
369 CurLexerKind = CLK_PTHLexer;
370 else if (CurTokenLexer)
371 CurLexerKind = CLK_TokenLexer;
373 CurLexerKind = CLK_CachingLexer;
377 unsigned CompleteLine,
378 unsigned CompleteColumn) {
380 assert(CompleteLine && CompleteColumn &&
"Starts from 1:1");
381 assert(!CodeCompletionFile &&
"Already set");
383 using llvm::MemoryBuffer;
386 bool Invalid =
false;
392 const char *Position = Buffer->getBufferStart();
394 for (; *Position; ++Position) {
395 if (*Position !=
'\r' && *Position !=
'\n')
399 if ((Position[1] ==
'\r' || Position[1] ==
'\n') &&
400 Position[0] != Position[1])
407 Position += CompleteColumn - 1;
411 if (SkipMainFilePreamble.first &&
413 if (Position - Buffer->getBufferStart() < SkipMainFilePreamble.first)
414 Position = Buffer->getBufferStart() + SkipMainFilePreamble.first;
417 if (Position > Buffer->getBufferEnd())
418 Position = Buffer->getBufferEnd();
420 CodeCompletionFile = File;
421 CodeCompletionOffset = Position - Buffer->getBufferStart();
423 auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
424 Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
425 char *NewBuf = NewBuffer->getBufferStart();
426 char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
428 std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
445 bool *Invalid)
const {
447 if (Tok.
isNot(tok::raw_identifier) && !Tok.
hasUCN()) {
450 return II->getName();
457 const char *Ptr = Buffer.data();
459 return StringRef(Ptr, Len);
471 SourceLocation Loc = ScratchBuf->getToken(Str.data(), Str.size(), DestPtr);
473 if (ExpansionLocStart.
isValid())
475 ExpansionLocEnd, Str.size());
479 if (Tok.
is(tok::raw_identifier))
502 assert(NumEnteredSourceFiles == 0 &&
"Cannot reenter the main file!");
513 if (SkipMainFilePreamble.first > 0)
514 CurLexer->SetByteOffset(SkipMainFilePreamble.first,
515 SkipMainFilePreamble.second);
524 std::unique_ptr<llvm::MemoryBuffer> SB =
525 llvm::MemoryBuffer::getMemBufferCopy(Predefines,
"<built-in>");
526 assert(SB &&
"Cannot create predefined source buffer");
528 assert(FID.
isValid() &&
"Could not create FileID for predefines?");
529 setPredefinesFileID(FID);
535 void Preprocessor::replayPreambleConditionalStack() {
537 if (PreambleConditionalStack.isReplaying()) {
539 "CurPPLexer is null when calling replayPreambleConditionalStack.");
541 PreambleConditionalStack.doneReplaying();
542 if (PreambleConditionalStack.reachedEOFWhileSkipping())
543 SkipExcludedConditionalBlock(
544 PreambleConditionalStack.SkipInfo->HashTokenLoc,
545 PreambleConditionalStack.SkipInfo->IfTokenLoc,
546 PreambleConditionalStack.SkipInfo->FoundNonSkipPortion,
547 PreambleConditionalStack.SkipInfo->FoundElse,
548 PreambleConditionalStack.SkipInfo->ElseLoc);
555 Callbacks->EndOfMainFile();
566 assert(!Identifier.
getRawIdentifier().empty() &&
"No raw identifier data!");
576 StringRef CleanedStr =
getSpelling(Identifier, IdentifierBuffer);
578 if (Identifier.
hasUCN()) {
589 if (
getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() &&
591 Identifier.
setKind(tok::identifier);
593 Identifier.
setKind(II->getTokenID());
599 PoisonReasons[II] = DiagID;
603 assert(Ident__exception_code && Ident__exception_info);
604 assert(Ident___exception_code && Ident___exception_info);
618 "Can't handle identifiers without identifier info!");
619 llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it =
621 if(it == PoisonReasons.end())
622 Diag(Identifier, diag::err_pp_used_poisoned_id);
633 if (LangOpts.CPlusPlus)
634 return llvm::StringSwitch<diag::kind>(II.
getName())
636 .Case(#NAME, diag::warn_cxx11_keyword)
637 #define CXX2A_KEYWORD(NAME, FLAGS) \ 638 .Case(#NAME, diag::warn_cxx2a_keyword) 639 #include "clang/Basic/TokenKinds.def" 643 "Keyword not known to come from a newer Standard or proposed Standard");
646 void Preprocessor::updateOutOfDateIdentifier(
IdentifierInfo &II)
const {
661 "Can't handle identifiers without identifier info!");
670 if (II.isOutOfDate()) {
671 bool CurrentIsPoisoned =
false;
672 const bool IsSpecialVariadicMacro =
673 &II == Ident__VA_ARGS__ || &II == Ident__VA_OPT__;
674 if (IsSpecialVariadicMacro)
677 updateOutOfDateIdentifier(II);
678 Identifier.
setKind(II.getTokenID());
680 if (IsSpecialVariadicMacro)
681 II.setIsPoisoned(CurrentIsPoisoned);
686 if (II.isPoisoned() && CurPPLexer) {
692 auto *MI = MD.getMacroInfo();
693 assert(MI &&
"macro definition with no macro info?");
694 if (!DisableMacroExpansion) {
698 if (!MI->isFunctionLike() || isNextPPTokenLParen())
699 return HandleMacroExpandedIdentifier(Identifier, MD);
705 if (MI->isObjectLike() || isNextPPTokenLParen())
706 Diag(Identifier, diag::pp_disabled_macro_expansion);
716 if (II.isFutureCompatKeyword() && !DisableMacroExpansion) {
720 II.setIsFutureCompatKeyword(
false);
727 if (II.isExtensionToken() && !DisableMacroExpansion)
728 Diag(Identifier, diag::ext_token_used);
738 if (((LastTokenWasAt && II.isModulesImport()) ||
739 Identifier.
is(tok::kw_import)) &&
740 !InMacroArgs && !DisableMacroExpansion &&
742 CurLexerKind != CLK_CachingLexer) {
744 ModuleImportPath.clear();
745 ModuleImportExpectsIdentifier =
true;
746 CurLexerKind = CLK_LexAfterModuleImport;
755 switch (CurLexerKind) {
757 ReturnedToken = CurLexer->Lex(Result);
760 ReturnedToken = CurPTHLexer->Lex(Result);
763 ReturnedToken = CurTokenLexer->Lex(Result);
765 case CLK_CachingLexer:
767 ReturnedToken =
true;
769 case CLK_LexAfterModuleImport:
771 ReturnedToken =
true;
774 }
while (!ReturnedToken);
776 if (Result.
is(tok::code_completion))
779 LastTokenWasAt = Result.
is(tok::at);
797 if (ModuleImportExpectsIdentifier && Result.
getKind() == tok::identifier) {
802 ModuleImportExpectsIdentifier =
false;
803 CurLexerKind = CLK_LexAfterModuleImport;
810 if (!ModuleImportExpectsIdentifier && Result.
getKind() == tok::period) {
811 ModuleImportExpectsIdentifier =
true;
812 CurLexerKind = CLK_LexAfterModuleImport;
817 if (!ModuleImportPath.empty()) {
822 std::string FlatModuleName;
824 for (
auto &Piece : ModuleImportPath) {
825 if (!FlatModuleName.empty())
826 FlatModuleName +=
".";
827 FlatModuleName += Piece.first->getName();
830 ModuleImportPath.clear();
831 ModuleImportPath.push_back(
835 Module *Imported =
nullptr;
837 Imported = TheModuleLoader.
loadModule(ModuleImportLoc,
845 Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
850 CurSubmoduleState->VisibleModules.setVisible(
855 Diag(ModuleImportLoc, diag::warn_module_conflict)
856 << Path[0]->getFullModuleName()
857 << Conflict->getFullModuleName()
862 if (!BuildingSubmoduleStack.empty() && M != BuildingSubmoduleStack.back().M)
863 BuildingSubmoduleStack.back().M->Imports.insert(M);
867 const char *DiagnosticTag,
868 bool AllowMacroExpansion) {
870 if (Result.
isNot(tok::string_literal)) {
871 Diag(Result, diag::err_expected_string_literal)
872 << 0 << DiagnosticTag;
879 StrToks.push_back(Result);
882 Diag(Result, diag::err_invalid_string_udl);
884 if (AllowMacroExpansion)
888 }
while (Result.
is(tok::string_literal));
892 assert(Literal.
isAscii() &&
"Didn't allow wide strings in");
898 Diag(StrToks[0].getLocation(), diag::err_expected_string_literal)
899 << 0 << DiagnosticTag;
908 assert(Tok.
is(tok::numeric_constant));
910 bool NumberInvalid =
false;
911 StringRef Spelling =
getSpelling(Tok, IntegerBuffer, &NumberInvalid);
915 if (Literal.hadError || !Literal.isIntegerLiteral() || Literal.hasUDSuffix())
917 llvm::APInt APVal(64, 0);
918 if (Literal.GetIntegerValue(APVal))
921 Value = APVal.getLimitedValue();
926 assert(Handler &&
"NULL comment handler");
927 assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) ==
928 CommentHandlers.end() &&
"Comment handler already registered");
929 CommentHandlers.push_back(Handler);
933 std::vector<CommentHandler *>::iterator Pos =
934 std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler);
935 assert(Pos != CommentHandlers.end() &&
"Comment handler not registered");
936 CommentHandlers.erase(Pos);
940 bool AnyPendingTokens =
false;
941 for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(),
942 HEnd = CommentHandlers.end();
944 if ((*H)->HandleComment(*
this, Comment))
945 AnyPendingTokens =
true;
void FinalizeForModelFile()
Cleanup after model file parsing.
IdentifierInfo * getIdentifierInfo(StringRef Name) const
Return information about the specified preprocessor identifier token.
Defines the clang::FileManager interface and associated types.
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)) {...
Defines the SourceManager interface.
Defines the clang::Module class, which describes a module in the source code.
Module * getCurrentModule()
Retrieves the module that we're currently building, if any.
Defines the FileSystemStatCache interface.
bool isLoadedFileID(FileID FID) const
Returns true if FID came from a PCH/Module.
void EndSourceFile()
Inform the preprocessor callbacks that processing is complete.
virtual void CodeCompleteNaturalLanguage()
Callback invoked when performing code completion in a part of the file where we expect natural langua...
bool isBeforeInTranslationUnit(SourceLocation LHS, SourceLocation RHS) const
Determines the order of 2 source locations in the translation unit.
const char * getCharacterData(SourceLocation SL, bool *Invalid=nullptr) const
Return a pointer to the start of the specified location in the appropriate spelling MemoryBuffer...
Defines the clang::MacroInfo and clang::MacroDirective classes.
A description of the current definition of a macro.
bool isOutOfDate() const
Determine whether the information for this identifier is out of date with respect to the external sou...
void LexAfterModuleImport(Token &Result)
Lex a token following the 'import' contextual keyword.
void setFlag(TokenFlags Flag)
Set the specified flag.
StringRef getLastMacroWithSpelling(SourceLocation Loc, ArrayRef< TokenValue > Tokens) const
Return the name of the macro defined before Loc that has spelling Tokens.
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.
tokens_iterator tokens_begin() const
tok::TokenKind getKind() const
bool isLiteral() const
Return true if this is a "literal", like a numeric constant, string, etc.
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)
virtual ~ExternalPreprocessorSource()
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)
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...
const LangOptions & getLangOpts() const
Describes a module or submodule.
bool SetCodeCompletionPoint(const FileEntry *File, unsigned Line, unsigned Column)
Specify the point at which code-completion will be performed.
llvm::Registry< PragmaHandler > PragmaHandlerRegistry
Registry of pragma handlers added by plugins.
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 ...
A record of the steps taken while preprocessing a source file, including the various preprocessing di...
HeaderSearch & getHeaderSearchInfo() const
const Token & getReplacementToken(unsigned Tok) const
bool hasUDSuffix() const
Return true if this token is a string or character literal which has a ud-suffix. ...
macro_iterator macro_begin(bool IncludeExternalMacros=true) const
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified...
void Initialize(const TargetInfo &Target, const TargetInfo *AuxTarget=nullptr)
Initialize the preprocessor using information about the target.
Concrete class used by the front-end to report problems and issues.
macro_iterator macro_end(bool IncludeExternalMacros=true) const
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...
void dump(const SourceManager &SM) const
Provides lookups to, and iteration over, IdentiferInfo objects.
Exposes information about the current target.
IdentifierInfo * LookUpIdentifierInfo(Token &Identifier) const
Given a tok::raw_identifier token, look up the identifier information for the token and install it in...
Defines the clang::LangOptions interface.
void makeModuleVisible(Module *M, SourceLocation Loc)
SourceLocation getLocation() const
bool isInSystemHeader(SourceLocation Loc) const
Returns if a SourceLocation is in a system header.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
const AnnotatedLine * Line
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...
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Defines the clang::Preprocessor interface.
void setIsPoisoned(bool Value=true)
setIsPoisoned - Mark this identifier as poisoned.
static bool MacroDefinitionEquals(const MacroInfo *MI, ArrayRef< TokenValue > Tokens)
Compares macro tokens with a specified token value sequence.
size_t getTotalMemory() const
bool getCommentRetentionState() const
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
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...
bool isObjectLike() const
The result type of a method or function.
StringRef GetString() const
SourceManager & getSourceManager() const
void DumpMacro(const MacroInfo &MI) const
void overrideFileContents(const FileEntry *SourceFile, llvm::MemoryBuffer *Buffer, bool DoNotFree)
Override the contents of the given source file by providing an already-allocated buffer.
ExternalPreprocessorSource * getExternalSource() const
bool isExpandDisabled() const
Return true if this identifier token should never be expanded in the future, due to C99 6...
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)
MacroDefinition getMacroDefinition(const IdentifierInfo *II)
All of the names in this module are hidden.
IdentifierInfo * getIdentifierInfo() const
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.
bool isPoisoned() const
Return true if this token has been poisoned.
bool isAtStartOfLine() const
isAtStartOfLine - Return true if this token is at the start of a line.
void expandUCNs(SmallVectorImpl< char > &Buf, StringRef Input)
Copy characters from Input to Buf, expanding any UCNs.
void DumpToken(const Token &Tok, bool DumpFlags=false) const
Print the token to stderr, used for debugging.
StringRef getName() const
Return the actual identifier string.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
bool isNot(tok::TokenKind K) const
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
unsigned getNumTokens() const
Return the number of tokens that this macro expands to.
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.
FileID getMainFileID() const
Returns the FileID of the main source file.
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.
Abstract interface for a module loader.
unsigned getLength() const
void PoisonSEHIdentifiers(bool Poison=true)
void setLiteralData(const char *Ptr)
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)
Defines the clang::SourceLocation class and associated facilities.
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.
TranslationUnitKind
Describes the kind of translation unit being processed.
void DumpLocation(SourceLocation Loc) const
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.
bool needsCleaning() const
Return true if this token has trigraphs or escaped newlines in it.
NumericLiteralParser - This performs strict semantic analysis of the content of a ppnumber...
MacroMap::const_iterator macro_iterator
void setLocation(SourceLocation L)
A trivial tuple used to represent a source range.
bool hasUCN() const
Returns true if this token contains a universal character name.
bool isFutureCompatKeyword() const
is/setIsFutureCompatKeyword - Initialize information about whether or not this language token is a ke...
Defines the PreprocessorLexer interface.
ScratchBuffer - This class exposes a simple interface for the dynamic construction of tokens...
void InitializeTarget(const TargetInfo &Target, const TargetInfo *AuxTarget)
Perform target-specific initialization.
bool hasLeadingSpace() const
Return true if this token has whitespace before it.
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID) const
Forwarding function for diagnostics.
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...