[PATCH] D119714: [clang][lex] Remove `Preprocessor::GetCurDirLookup()`

2022-02-15 Thread Jan Svoboda via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGedd09bb5a49c: [clang][lex] Remove 
`Preprocessor::GetCurDirLookup()` (authored by jansvoboda11).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119714/new/

https://reviews.llvm.org/D119714

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPMacroExpansion.cpp

Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ 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 , IdentifierInfo *II,
-   Preprocessor ) {
-  return EvaluateHasIncludeCommon(Tok, II, PP, nullptr, nullptr);
+bool Preprocessor::EvaluateHasInclude(Token , IdentifierInfo *II) {
+  return EvaluateHasIncludeCommon(Tok, II, *this, nullptr, nullptr);
 }
 
-/// EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
-/// Returns true if successful.
-static bool EvaluateHasIncludeNext(Token ,
-   IdentifierInfo *II, Preprocessor ) {
+bool Preprocessor::EvaluateHasIncludeNext(Token , 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;
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ 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 *);
 
+  /// Process a '__has_include("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasInclude(Token , IdentifierInfo *II);
+
+  /// Process '__has_include_next("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasIncludeNext(Token , IdentifierInfo *II);
+
   /// Install the standard preprocessor pragmas:
   /// \#pragma GCC poison/system_header/dependency and \#pragma once.

[PATCH] D119714: [clang][lex] Remove `Preprocessor::GetCurDirLookup()`

2022-02-14 Thread Duncan P. N. Exon Smith via Phabricator via cfe-commits
dexonsmith accepted this revision.
dexonsmith added a comment.

LGTM too.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119714/new/

https://reviews.llvm.org/D119714

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D119714: [clang][lex] Remove `Preprocessor::GetCurDirLookup()`

2022-02-14 Thread Jan Svoboda via Phabricator via cfe-commits
jansvoboda11 created this revision.
jansvoboda11 added reviewers: ahoppen, Bigcheese, dexonsmith.
jansvoboda11 requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

`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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119714

Files:
  clang/include/clang/Lex/Preprocessor.h
  clang/lib/Lex/PPMacroExpansion.cpp

Index: clang/lib/Lex/PPMacroExpansion.cpp
===
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ 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 , IdentifierInfo *II,
-   Preprocessor ) {
-  return EvaluateHasIncludeCommon(Tok, II, PP, nullptr, nullptr);
+bool Preprocessor::EvaluateHasInclude(Token , IdentifierInfo *II) {
+  return EvaluateHasIncludeCommon(Tok, II, *this, nullptr, nullptr);
 }
 
-/// EvaluateHasIncludeNext - Process '__has_include_next("path")' expression.
-/// Returns true if successful.
-static bool EvaluateHasIncludeNext(Token ,
-   IdentifierInfo *II, Preprocessor ) {
+bool Preprocessor::EvaluateHasIncludeNext(Token , 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;
Index: clang/include/clang/Lex/Preprocessor.h
===
--- clang/include/clang/Lex/Preprocessor.h
+++ 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 *);
 
+  /// Process a '__has_include("path")' expression.
+  ///
+  /// Returns true if successful.
+  bool EvaluateHasInclude(Token ,