Author: Jan Svoboda Date: 2022-02-15T09:48:25+01:00 New Revision: edd09bb5a49c6a5dac29714af661d1ddffe50a72
URL: https://github.com/llvm/llvm-project/commit/edd09bb5a49c6a5dac29714af661d1ddffe50a72 DIFF: https://github.com/llvm/llvm-project/commit/edd09bb5a49c6a5dac29714af661d1ddffe50a72.diff LOG: [clang][lex] Remove `Preprocessor::GetCurDirLookup()` `Preprocessor` exposes the search directory iterator via `GetCurDirLookup()` getter, which is only used in two static functions. To simplify reasoning about search directory iterators/references and to simplify the `Preprocessor` API, this patch makes the two static functions private member functions and removes the getter entirely. Depends D119708. Reviewed By: ahoppen, dexonsmith Differential Revision: https://reviews.llvm.org/D119714 Added: Modified: clang/include/clang/Lex/Preprocessor.h clang/lib/Lex/PPMacroExpansion.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h index e567f6391531..dbe6aa949a75 100644 --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2077,13 +2077,6 @@ class Preprocessor { ModuleMap::KnownHeader *SuggestedModule, bool *IsMapped, bool *IsFrameworkFound, bool SkipCache = false); - /// 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. - const DirectoryLookup *GetCurDirLookup() { return CurDirLookup; } - /// Return true if we're in the top-level file, not in a \#include. bool isInPrimaryFile() const; @@ -2197,6 +2190,16 @@ class Preprocessor { /// If the expression is equivalent to "!defined(X)" return X in IfNDefMacro. DirectiveEvalResult EvaluateDirectiveExpression(IdentifierInfo *&IfNDefMacro); + /// Process a '__has_include("path")' expression. + /// + /// Returns true if successful. + bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II); + + /// Process '__has_include_next("path")' expression. + /// + /// Returns true if successful. + bool EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II); + /// Install the standard preprocessor pragmas: /// \#pragma GCC poison/system_header/dependency and \#pragma once. void RegisterBuiltinPragmas(); diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp index f6c95a8b67c6..a1fde8a149cc 100644 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1244,45 +1244,39 @@ static bool EvaluateHasIncludeCommon(Token &Tok, return File.hasValue(); } -/// EvaluateHasInclude - Process a '__has_include("path")' expression. -/// Returns true if successful. -static bool EvaluateHasInclude(Token &Tok, IdentifierInfo *II, - Preprocessor &PP) { - return EvaluateHasIncludeCommon(Tok, II, PP, nullptr, nullptr); +bool Preprocessor::EvaluateHasInclude(Token &Tok, IdentifierInfo *II) { + return EvaluateHasIncludeCommon(Tok, II, *this, nullptr, nullptr); } -/// EvaluateHasIncludeNext - Process '__has_include_next("path")' expression. -/// Returns true if successful. -static bool EvaluateHasIncludeNext(Token &Tok, - IdentifierInfo *II, Preprocessor &PP) { +bool Preprocessor::EvaluateHasIncludeNext(Token &Tok, IdentifierInfo *II) { // __has_include_next is like __has_include, except that we start // searching after the current found directory. If we can't do this, // issue a diagnostic. // FIXME: Factor out duplication with // Preprocessor::HandleIncludeNextDirective. - const DirectoryLookup *Lookup = PP.GetCurDirLookup(); + const DirectoryLookup *Lookup = CurDirLookup; const FileEntry *LookupFromFile = nullptr; - if (PP.isInPrimaryFile() && PP.getLangOpts().IsHeaderFile) { + if (isInPrimaryFile() && getLangOpts().IsHeaderFile) { // If the main file is a header, then it's either for PCH/AST generation, // or libclang opened it. Either way, handle it as a normal include below // and do not complain about __has_include_next. - } else if (PP.isInPrimaryFile()) { + } else if (isInPrimaryFile()) { Lookup = nullptr; - PP.Diag(Tok, diag::pp_include_next_in_primary); - } else if (PP.getCurrentLexerSubmodule()) { + Diag(Tok, diag::pp_include_next_in_primary); + } else if (getCurrentLexerSubmodule()) { // Start looking up in the directory *after* the one in which the current // file would be found, if any. - assert(PP.getCurrentLexer() && "#include_next directive in macro?"); - LookupFromFile = PP.getCurrentLexer()->getFileEntry(); + assert(getCurrentLexer() && "#include_next directive in macro?"); + LookupFromFile = getCurrentLexer()->getFileEntry(); Lookup = nullptr; } else if (!Lookup) { - PP.Diag(Tok, diag::pp_include_next_absolute_path); + Diag(Tok, diag::pp_include_next_absolute_path); } else { // Start looking up in the next directory. ++Lookup; } - return EvaluateHasIncludeCommon(Tok, II, PP, Lookup, LookupFromFile); + return EvaluateHasIncludeCommon(Tok, II, *this, Lookup, LookupFromFile); } /// Process single-argument builtin feature-like macros that return @@ -1736,9 +1730,9 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) { // double-quotes (""). bool Value; if (II == Ident__has_include) - Value = EvaluateHasInclude(Tok, II, *this); + Value = EvaluateHasInclude(Tok, II); else - Value = EvaluateHasIncludeNext(Tok, II, *this); + Value = EvaluateHasIncludeNext(Tok, II); if (Tok.isNot(tok::r_paren)) return; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits