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), PCMCache(PCMCache),
89 ScratchBuf(new
ScratchBuffer(SourceMgr)), HeaderInfo(Headers),
90 TheModuleLoader(TheModuleLoader), ExternalSource(nullptr),
94 Identifiers(IILookup), PragmaHandlers(new
PragmaNamespace(StringRef())),
95 TUKind(TUKind), SkipMainFilePreamble(0,
true),
96 CurSubmoduleState(&NullSubmoduleState) {
97 OwnsHeaderSearch = OwnsHeaders;
100 KeepComments =
false;
101 KeepMacroComments =
false;
102 SuppressIncludeNotFoundError =
false;
105 DisableMacroExpansion =
false;
106 MacroExpansionInDirectivesOverride =
false;
108 InMacroArgPreExpansion =
false;
109 NumCachedTokenLexers = 0;
110 PragmasEnabled =
true;
111 ParsingIfOrElifDirective =
false;
112 PreprocessedOutput =
false;
115 ReadMacrosFromExternalSource =
false;
125 Ident__VA_OPT__ =
nullptr;
129 RegisterBuiltinPragmas();
132 RegisterBuiltinMacros();
134 if(LangOpts.Borland) {
145 Ident__exception_info = Ident__exception_code =
nullptr;
146 Ident__abnormal_termination = Ident___exception_info =
nullptr;
147 Ident___exception_code = Ident___abnormal_termination =
nullptr;
148 Ident_GetExceptionInfo = Ident_GetExceptionCode =
nullptr;
149 Ident_AbnormalTermination =
nullptr;
153 if (!this->PPOpts->PCHThroughHeader.empty() &&
154 !this->PPOpts->ImplicitPCHInclude.empty())
155 SkippingUntilPCHThroughHeader =
true;
157 if (this->PPOpts->GeneratePreamble)
158 PreambleConditionalStack.startRecording();
162 assert(BacktrackPositions.empty() &&
"EnableBacktrack/Backtrack imbalance!");
164 IncludeMacroStack.clear();
167 while (MacroInfoChain *I = MIChainHead) {
168 MIChainHead = I->Next;
169 I->~MacroInfoChain();
175 std::fill(TokenLexerCache, TokenLexerCache + NumCachedTokenLexers,
nullptr);
176 CurTokenLexer.reset();
179 for (
MacroArgs *ArgList = MacroArgCache; ArgList;)
180 ArgList = ArgList->deallocate();
183 if (OwnsHeaderSearch)
189 assert((!this->Target || this->Target == &Target) &&
190 "Invalid override of target information");
191 this->Target = &Target;
193 assert((!this->AuxTarget || this->AuxTarget == AuxTarget) &&
194 "Invalid override of aux target information.");
195 this->AuxTarget = AuxTarget;
206 NumEnteredSourceFiles = 0;
209 PragmaHandlersBackup = std::move(PragmaHandlers);
210 PragmaHandlers = llvm::make_unique<PragmaNamespace>(StringRef());
211 RegisterBuiltinPragmas();
214 PredefinesFileID =
FileID();
218 NumEnteredSourceFiles = 1;
220 PragmaHandlers = std::move(PragmaHandlersBackup);
232 if (!DumpFlags)
return;
234 llvm::errs() <<
"\t";
236 llvm::errs() <<
" [StartOfLine]";
238 llvm::errs() <<
" [LeadingSpace]";
240 llvm::errs() <<
" [ExpandDisabled]";
243 llvm::errs() <<
" [UnClean='" << StringRef(Start, Tok.
getLength())
247 llvm::errs() <<
"\tLoc=<";
257 llvm::errs() <<
"MACRO: ";
258 for (
unsigned i = 0, e = MI.
getNumTokens(); i != e; ++i) {
262 llvm::errs() <<
"\n";
266 llvm::errs() <<
"\n*** Preprocessor Stats:\n";
267 llvm::errs() << NumDirectives <<
" directives found:\n";
268 llvm::errs() <<
" " << NumDefined <<
" #define.\n";
269 llvm::errs() <<
" " << NumUndefined <<
" #undef.\n";
270 llvm::errs() <<
" #include/#include_next/#import:\n";
271 llvm::errs() <<
" " << NumEnteredSourceFiles <<
" source files entered.\n";
272 llvm::errs() <<
" " << MaxIncludeStackDepth <<
" max include stack depth\n";
273 llvm::errs() <<
" " << NumIf <<
" #if/#ifndef/#ifdef.\n";
274 llvm::errs() <<
" " << NumElse <<
" #else/#elif.\n";
275 llvm::errs() <<
" " << NumEndif <<
" #endif.\n";
276 llvm::errs() <<
" " << NumPragma <<
" #pragma.\n";
277 llvm::errs() << NumSkipped <<
" #if/#ifndef#ifdef regions skipped\n";
279 llvm::errs() << NumMacroExpanded <<
"/" << NumFnMacroExpanded <<
"/" 280 << NumBuiltinMacroExpanded <<
" obj/fn/builtin macros expanded, " 281 << NumFastMacroExpanded <<
" on the fast path.\n";
282 llvm::errs() << (NumFastTokenPaste+NumTokenPaste)
283 <<
" token paste (##) operations performed, " 284 << NumFastTokenPaste <<
" on the fast path.\n";
286 llvm::errs() <<
"\nPreprocessor Memory: " <<
getTotalMemory() <<
"B total";
288 llvm::errs() <<
"\n BumpPtr: " << BP.getTotalMemory();
289 llvm::errs() <<
"\n Macro Expanded Tokens: " 290 << llvm::capacity_in_bytes(MacroExpandedTokens);
291 llvm::errs() <<
"\n Predefines Buffer: " << Predefines.capacity();
293 llvm::errs() <<
"\n Macros: " 294 << llvm::capacity_in_bytes(CurSubmoduleState->Macros);
295 llvm::errs() <<
"\n #pragma push_macro Info: " 296 << llvm::capacity_in_bytes(PragmaPushMacroInfo);
297 llvm::errs() <<
"\n Poison Reasons: " 298 << llvm::capacity_in_bytes(PoisonReasons);
299 llvm::errs() <<
"\n Comment Handlers: " 300 << llvm::capacity_in_bytes(CommentHandlers) <<
"\n";
305 if (IncludeExternalMacros && ExternalSource &&
306 !ReadMacrosFromExternalSource) {
307 ReadMacrosFromExternalSource =
true;
313 CurSubmoduleState->Macros.insert(std::make_pair(Macro.II, MacroState()));
315 return CurSubmoduleState->Macros.begin();
319 return BP.getTotalMemory()
320 + llvm::capacity_in_bytes(MacroExpandedTokens)
321 + Predefines.capacity()
324 + llvm::capacity_in_bytes(CurSubmoduleState->Macros)
325 + llvm::capacity_in_bytes(PragmaPushMacroInfo)
326 + llvm::capacity_in_bytes(PoisonReasons)
327 + llvm::capacity_in_bytes(CommentHandlers);
332 if (IncludeExternalMacros && ExternalSource &&
333 !ReadMacrosFromExternalSource) {
334 ReadMacrosFromExternalSource =
true;
338 return CurSubmoduleState->Macros.end();
345 std::equal(Tokens.begin(), Tokens.end(), MI->
tokens_begin());
352 StringRef BestSpelling;
356 Def = I->second.findDirectiveAtLoc(Loc, SourceMgr);
368 BestLocation = Location;
369 BestSpelling = I->first->getName();
377 CurLexerKind = CLK_Lexer;
378 else if (CurPTHLexer)
379 CurLexerKind = CLK_PTHLexer;
380 else if (CurTokenLexer)
381 CurLexerKind = CLK_TokenLexer;
383 CurLexerKind = CLK_CachingLexer;
387 unsigned CompleteLine,
388 unsigned CompleteColumn) {
390 assert(CompleteLine && CompleteColumn &&
"Starts from 1:1");
391 assert(!CodeCompletionFile &&
"Already set");
393 using llvm::MemoryBuffer;
396 bool Invalid =
false;
402 const char *Position = Buffer->getBufferStart();
404 for (; *Position; ++Position) {
405 if (*Position !=
'\r' && *Position !=
'\n')
409 if ((Position[1] ==
'\r' || Position[1] ==
'\n') &&
410 Position[0] != Position[1])
417 Position += CompleteColumn - 1;
421 if (SkipMainFilePreamble.first &&
423 if (Position - Buffer->getBufferStart() < SkipMainFilePreamble.first)
424 Position = Buffer->getBufferStart() + SkipMainFilePreamble.first;
427 if (Position > Buffer->getBufferEnd())
428 Position = Buffer->getBufferEnd();
430 CodeCompletionFile = File;
431 CodeCompletionOffset = Position - Buffer->getBufferStart();
433 auto NewBuffer = llvm::WritableMemoryBuffer::getNewUninitMemBuffer(
434 Buffer->getBufferSize() + 1, Buffer->getBufferIdentifier());
435 char *NewBuf = NewBuffer->getBufferStart();
436 char *NewPos = std::copy(Buffer->getBufferStart(), Position, NewBuf);
438 std::copy(Position, Buffer->getBufferEnd(), NewPos+1);
455 bool *Invalid)
const {
457 if (Tok.
isNot(tok::raw_identifier) && !Tok.
hasUCN()) {
460 return II->getName();
467 const char *Ptr = Buffer.data();
469 return StringRef(Ptr, Len);
481 SourceLocation Loc = ScratchBuf->getToken(Str.data(), Str.size(), DestPtr);
483 if (ExpansionLocStart.
isValid())
485 ExpansionLocEnd, Str.size());
489 if (Tok.
is(tok::raw_identifier))
499 bool Invalid =
false;
507 ScratchBuf->getToken(Buffer.data() + LocInfo.second, Length, DestPtr);
528 assert(NumEnteredSourceFiles == 0 &&
"Cannot reenter the main file!");
539 if (SkipMainFilePreamble.first > 0)
540 CurLexer->SetByteOffset(SkipMainFilePreamble.first,
541 SkipMainFilePreamble.second);
550 std::unique_ptr<llvm::MemoryBuffer> SB =
551 llvm::MemoryBuffer::getMemBufferCopy(Predefines,
"<built-in>");
552 assert(SB &&
"Cannot create predefined source buffer");
554 assert(FID.
isValid() &&
"Could not create FileID for predefines?");
555 setPredefinesFileID(FID);
560 if (!PPOpts->PCHThroughHeader.empty()) {
566 false,
nullptr,
nullptr, CurDir,
571 << PPOpts->PCHThroughHeader;
574 setPCHThroughHeaderFileID(
583 void Preprocessor::setPCHThroughHeaderFileID(
FileID FID) {
584 assert(PCHThroughHeaderFileID.
isInvalid() &&
585 "PCHThroughHeaderFileID already set!");
586 PCHThroughHeaderFileID = FID;
590 assert(PCHThroughHeaderFileID.
isValid() &&
591 "Invalid PCH through header FileID");
596 return TUKind ==
TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
597 PCHThroughHeaderFileID.
isValid();
601 return TUKind !=
TU_Prefix && !PPOpts->PCHThroughHeader.empty() &&
602 PCHThroughHeaderFileID.
isValid();
610 bool ReachedMainFileEOF =
false;
616 ReachedMainFileEOF =
true;
619 if (!SkippingUntilPCHThroughHeader)
622 if (ReachedMainFileEOF)
624 << PPOpts->PCHThroughHeader << 1;
627 void Preprocessor::replayPreambleConditionalStack() {
629 if (PreambleConditionalStack.isReplaying()) {
631 "CurPPLexer is null when calling replayPreambleConditionalStack.");
633 PreambleConditionalStack.doneReplaying();
634 if (PreambleConditionalStack.reachedEOFWhileSkipping())
635 SkipExcludedConditionalBlock(
636 PreambleConditionalStack.SkipInfo->HashTokenLoc,
637 PreambleConditionalStack.SkipInfo->IfTokenLoc,
638 PreambleConditionalStack.SkipInfo->FoundNonSkipPortion,
639 PreambleConditionalStack.SkipInfo->FoundElse,
640 PreambleConditionalStack.SkipInfo->ElseLoc);
647 Callbacks->EndOfMainFile();
658 assert(!Identifier.
getRawIdentifier().empty() &&
"No raw identifier data!");
668 StringRef CleanedStr =
getSpelling(Identifier, IdentifierBuffer);
670 if (Identifier.
hasUCN()) {
681 if (
getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() &&
683 Identifier.
setKind(tok::identifier);
685 Identifier.
setKind(II->getTokenID());
691 PoisonReasons[II] = DiagID;
695 assert(Ident__exception_code && Ident__exception_info);
696 assert(Ident___exception_code && Ident___exception_info);
710 "Can't handle identifiers without identifier info!");
711 llvm::DenseMap<IdentifierInfo*,unsigned>::const_iterator it =
713 if(it == PoisonReasons.end())
714 Diag(Identifier, diag::err_pp_used_poisoned_id);
725 if (LangOpts.CPlusPlus)
726 return llvm::StringSwitch<diag::kind>(II.
getName())
728 .Case(#NAME, diag::warn_cxx11_keyword)
729 #define CXX2A_KEYWORD(NAME, FLAGS) \ 730 .Case(#NAME, diag::warn_cxx2a_keyword) 731 #include "clang/Basic/TokenKinds.def" 735 "Keyword not known to come from a newer Standard or proposed Standard");
738 void Preprocessor::updateOutOfDateIdentifier(
IdentifierInfo &II)
const {
753 "Can't handle identifiers without identifier info!");
762 if (II.isOutOfDate()) {
763 bool CurrentIsPoisoned =
false;
764 const bool IsSpecialVariadicMacro =
765 &II == Ident__VA_ARGS__ || &II == Ident__VA_OPT__;
766 if (IsSpecialVariadicMacro)
769 updateOutOfDateIdentifier(II);
770 Identifier.
setKind(II.getTokenID());
772 if (IsSpecialVariadicMacro)
773 II.setIsPoisoned(CurrentIsPoisoned);
778 if (II.isPoisoned() && CurPPLexer) {
784 auto *MI = MD.getMacroInfo();
785 assert(MI &&
"macro definition with no macro info?");
786 if (!DisableMacroExpansion) {
790 if (!MI->isFunctionLike() || isNextPPTokenLParen())
791 return HandleMacroExpandedIdentifier(Identifier, MD);
797 if (MI->isObjectLike() || isNextPPTokenLParen())
798 Diag(Identifier, diag::pp_disabled_macro_expansion);
808 if (II.isFutureCompatKeyword() && !DisableMacroExpansion) {
812 II.setIsFutureCompatKeyword(
false);
819 if (II.isExtensionToken() && !DisableMacroExpansion)
820 Diag(Identifier, diag::ext_token_used);
830 if (((LastTokenWasAt && II.isModulesImport()) ||
831 Identifier.
is(tok::kw_import)) &&
832 !InMacroArgs && !DisableMacroExpansion &&
834 CurLexerKind != CLK_CachingLexer) {
836 ModuleImportPath.clear();
837 ModuleImportExpectsIdentifier =
true;
838 CurLexerKind = CLK_LexAfterModuleImport;
847 switch (CurLexerKind) {
849 ReturnedToken = CurLexer->Lex(Result);
852 ReturnedToken = CurPTHLexer->Lex(Result);
855 ReturnedToken = CurTokenLexer->Lex(Result);
857 case CLK_CachingLexer:
859 ReturnedToken =
true;
861 case CLK_LexAfterModuleImport:
863 ReturnedToken =
true;
866 }
while (!ReturnedToken);
876 LastTokenWasAt = Result.
is(tok::at);
894 if (ModuleImportExpectsIdentifier && Result.
getKind() == tok::identifier) {
899 ModuleImportExpectsIdentifier =
false;
900 CurLexerKind = CLK_LexAfterModuleImport;
907 if (!ModuleImportExpectsIdentifier && Result.
getKind() == tok::period) {
908 ModuleImportExpectsIdentifier =
true;
909 CurLexerKind = CLK_LexAfterModuleImport;
914 if (!ModuleImportPath.empty()) {
919 std::string FlatModuleName;
921 for (
auto &Piece : ModuleImportPath) {
922 if (!FlatModuleName.empty())
923 FlatModuleName +=
".";
924 FlatModuleName += Piece.first->getName();
927 ModuleImportPath.clear();
928 ModuleImportPath.push_back(
932 Module *Imported =
nullptr;
934 Imported = TheModuleLoader.
loadModule(ModuleImportLoc,
942 Callbacks->moduleImport(ModuleImportLoc, ModuleImportPath, Imported);
947 CurSubmoduleState->VisibleModules.setVisible(
952 Diag(ModuleImportLoc, diag::warn_module_conflict)
953 << Path[0]->getFullModuleName()
954 << Conflict->getFullModuleName()
959 if (!BuildingSubmoduleStack.empty() && M != BuildingSubmoduleStack.back().M)
960 BuildingSubmoduleStack.back().M->Imports.insert(M);
964 const char *DiagnosticTag,
965 bool AllowMacroExpansion) {
967 if (Result.
isNot(tok::string_literal)) {
968 Diag(Result, diag::err_expected_string_literal)
969 << 0 << DiagnosticTag;
976 StrToks.push_back(Result);
979 Diag(Result, diag::err_invalid_string_udl);
981 if (AllowMacroExpansion)
985 }
while (Result.
is(tok::string_literal));
989 assert(Literal.
isAscii() &&
"Didn't allow wide strings in");
995 Diag(StrToks[0].getLocation(), diag::err_expected_string_literal)
996 << 0 << DiagnosticTag;
1005 assert(Tok.
is(tok::numeric_constant));
1007 bool NumberInvalid =
false;
1008 StringRef Spelling =
getSpelling(Tok, IntegerBuffer, &NumberInvalid);
1012 if (Literal.hadError || !Literal.isIntegerLiteral() || Literal.hasUDSuffix())
1014 llvm::APInt APVal(64, 0);
1015 if (Literal.GetIntegerValue(APVal))
1018 Value = APVal.getLimitedValue();
1023 assert(Handler &&
"NULL comment handler");
1024 assert(std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler) ==
1025 CommentHandlers.end() &&
"Comment handler already registered");
1026 CommentHandlers.push_back(Handler);
1030 std::vector<CommentHandler *>::iterator Pos =
1031 std::find(CommentHandlers.begin(), CommentHandlers.end(), Handler);
1032 assert(Pos != CommentHandlers.end() &&
"Comment handler not registered");
1033 CommentHandlers.erase(Pos);
1037 bool AnyPendingTokens =
false;
1038 for (std::vector<CommentHandler *>::iterator H = CommentHandlers.begin(),
1039 HEnd = CommentHandlers.end();
1041 if ((*H)->HandleComment(*
this, Comment))
1042 AnyPendingTokens =
true;
void AddKeywords(const LangOptions &LangOpts)
Populate the identifier table with info about the language keywords for the language specified by Lan...
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
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.
The translation unit is a prefix to a translation unit, and is not 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...
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
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.
const FileEntry * 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 *IsMapped, bool SkipCache=false)
Given a "foo" or <foo> reference, look up the indicated file.
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.
SourceLocation getSpellingLoc(SourceLocation Loc) const
Given a SourceLocation object, return the spelling location referenced by the ID. ...
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...
bool usingPCHWithThroughHeader()
True if using a PCH with a through header.
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.
bool isPCHThroughHeader(const FileEntry *File)
Returns true if the FileEntry is the PCH through header.
size_t getTotalMemory() const
bool getCommentRetentionState() const
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
bool isObjectLike() const
The result type of a method or function.
StringRef GetString() const
DirectoryLookup - This class represents one entry in the search list that specifies the search order ...
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)
SourceLocation createExpansionLoc(SourceLocation Loc, SourceLocation ExpansionLocStart, SourceLocation ExpansionLocEnd, unsigned TokLength, bool ExpansionIsTokenRange=true, int LoadedID=0, unsigned LoadedOffset=0)
Return a new SourceLocation that encodes the fact that a token from SpellingLoc should actually be re...
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
SourceLocation SplitToken(SourceLocation TokLoc, unsigned Length)
Split the first Length characters out of the token starting at TokLoc and return a location pointing ...
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.
FileID getPredefinesFileID() const
Returns the FileID for the preprocessor predefines.
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.
SourceLocation createTokenSplitLoc(SourceLocation SpellingLoc, SourceLocation TokenStart, SourceLocation TokenEnd)
Return a new SourceLocation that encodes that the token starting at TokenStart ends prematurely at To...
void SkipTokensUntilPCHThroughHeader()
Skip tokens until after the #include of the through header.
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.
bool creatingPCHWithThroughHeader()
True if creating a PCH with a through header.
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()
std::pair< FileID, unsigned > getDecomposedLoc(SourceLocation Loc) const
Decompose the specified location into a raw FileID + Offset pair.
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...