diff options
Diffstat (limited to 'clang/include/clang/Lex/Preprocessor.h')
-rw-r--r-- | clang/include/clang/Lex/Preprocessor.h | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index 9716196b95c2..5cd017fa925f 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -416,6 +416,14 @@ class Preprocessor { /// of phase 4 of translation or for some other situation. unsigned LexLevel = 0; + /// The number of (LexLevel 0) preprocessor tokens. + unsigned TokenCount = 0; + + /// The maximum number of (LexLevel 0) tokens before issuing a -Wmax-tokens + /// warning, or zero for unlimited. + unsigned MaxTokens = 0; + SourceLocation MaxTokensOverrideLoc; + public: struct PreambleSkipInfo { SourceLocation HashTokenLoc; @@ -1010,6 +1018,19 @@ public: } /// \} + /// Get the number of tokens processed so far. + unsigned getTokenCount() const { return TokenCount; } + + /// Get the max number of tokens before issuing a -Wmax-tokens warning. + unsigned getMaxTokens() const { return MaxTokens; } + + void overrideMaxTokens(unsigned Value, SourceLocation Loc) { + MaxTokens = Value; + MaxTokensOverrideLoc = Loc; + }; + + SourceLocation getMaxTokensOverrideLoc() const { return MaxTokensOverrideLoc; } + /// Register a function that would be called on each token in the final /// expanded token stream. /// This also reports annotation tokens produced by the parser. @@ -1163,7 +1184,7 @@ public: /// /// These predefines are automatically injected when parsing the main file. void setPredefines(const char *P) { Predefines = P; } - void setPredefines(StringRef P) { Predefines = P; } + void setPredefines(StringRef P) { Predefines = std::string(P); } /// Return information about the specified preprocessor /// identifier token. @@ -1541,6 +1562,12 @@ public: void EnterAnnotationToken(SourceRange Range, tok::TokenKind Kind, void *AnnotationVal); + /// Determine whether it's possible for a future call to Lex to produce an + /// annotation token created by a previous call to EnterAnnotationToken. + bool mightHavePendingAnnotationTokens() { + return CurLexerKind != CLK_Lexer; + } + /// Update the current token to represent the provided /// identifier, in order to cache an action performed by typo correction. void TypoCorrectToken(const Token &Tok) { @@ -2203,21 +2230,23 @@ private: ModuleBegin, ModuleImport, SkippedModuleImport, + Failure, } Kind; Module *ModuleForHeader = nullptr; ImportAction(ActionKind AK, Module *Mod = nullptr) : Kind(AK), ModuleForHeader(Mod) { - assert((AK == None || Mod) && "no module for module action"); + assert((AK == None || Mod || AK == Failure) && + "no module for module action"); } }; Optional<FileEntryRef> LookupHeaderIncludeOrImport( - const DirectoryLookup *&CurDir, StringRef Filename, + const DirectoryLookup *&CurDir, StringRef &Filename, SourceLocation FilenameLoc, CharSourceRange FilenameRange, const Token &FilenameTok, bool &IsFrameworkFound, bool IsImportDecl, bool &IsMapped, const DirectoryLookup *LookupFrom, - const FileEntry *LookupFromFile, StringRef LookupFilename, + const FileEntry *LookupFromFile, StringRef &LookupFilename, SmallVectorImpl<char> &RelativePath, SmallVectorImpl<char> &SearchPath, ModuleMap::KnownHeader &SuggestedModule, bool isAngled); @@ -2249,20 +2278,22 @@ public: /// into a module, or is outside any module, returns nullptr. Module *getModuleForLocation(SourceLocation Loc); - /// We want to produce a diagnostic at location IncLoc concerning a - /// missing module import. - /// - /// \param IncLoc The location at which the missing import was detected. - /// \param M The desired module. - /// \param MLoc A location within the desired module at which some desired - /// effect occurred (eg, where a desired entity was declared). - /// - /// \return A file that can be #included to import a module containing MLoc. - /// Null if no such file could be determined or if a #include is not - /// appropriate. - const FileEntry *getModuleHeaderToIncludeForDiagnostics(SourceLocation IncLoc, - Module *M, - SourceLocation MLoc); + /// We want to produce a diagnostic at location IncLoc concerning an + /// unreachable effect at location MLoc (eg, where a desired entity was + /// declared or defined). Determine whether the right way to make MLoc + /// reachable is by #include, and if so, what header should be included. + /// + /// This is not necessarily fast, and might load unexpected module maps, so + /// should only be called by code that intends to produce an error. + /// + /// \param IncLoc The location at which the missing effect was detected. + /// \param MLoc A location within an unimported module at which the desired + /// effect occurred. + /// \return A file that can be #included to provide the desired effect. Null + /// if no such file could be determined or if a #include is not + /// appropriate (eg, if a module should be imported instead). + const FileEntry *getHeaderToIncludeForDiagnostics(SourceLocation IncLoc, + SourceLocation MLoc); bool isRecordingPreamble() const { return PreambleConditionalStack.isRecording(); |