diff --git a/clang/include/clang/Lex/Preprocessor.h b/clang/include/clang/Lex/Preprocessor.h --- a/clang/include/clang/Lex/Preprocessor.h +++ b/clang/include/clang/Lex/Preprocessor.h @@ -2077,13 +2077,6 @@ 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 @@ /// 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 --- a/clang/lib/Lex/PPMacroExpansion.cpp +++ b/clang/lib/Lex/PPMacroExpansion.cpp @@ -1244,45 +1244,39 @@ 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 @@ // 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;