[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Haojian Wu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3ddfea07f8d0: [clangd] Handle the C++2b elifdef and elindef 
PP structure in… (authored by hokein).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp

Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -56,6 +56,11 @@
   // )cpp",
   R"cpp(
 #ifdef $Unknown(condit)[[UNDEFINED]]
+#elifdef $Unknown(condit)[[UNDEFINED]]
+#endif
+
+#ifdef $Unknown(condit)[[UNDEFINED]]
+#elifndef $Unknown(condit)[[UNDEFINED]]
 #endif
 
 #ifndef $Unknown(condit)[[UNDEFINED]]
@@ -101,11 +106,12 @@
 
   for (const char *Test : Tests) {
 Annotations T(Test);
-auto AST = TestTU::withCode(T.code()).build();
+auto Inputs = TestTU::withCode(T.code());
+Inputs.ExtraArgs.push_back("-std=c++2b");
+auto AST = Inputs.build();
 auto ActualMacroRefs = AST.getMacros();
 auto  = AST.getSourceManager();
 auto  = AST.getPreprocessor();
-
 for (const auto &[Name, Ranges] : T.all_ranges()) {
   if (Name == "Unknown") {
 EXPECT_THAT(ActualMacroRefs.UnknownMacros,
Index: clang-tools-extra/clangd/CollectMacros.h
===
--- clang-tools-extra/clangd/CollectMacros.h
+++ clang-tools-extra/clangd/CollectMacros.h
@@ -12,6 +12,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/SymbolID.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,11 +62,16 @@
   const clang::MacroDefinition ,
   const clang::MacroDirective *Undef) override;
 
-  // FIXME: handle C++23 #elifdef, #elifndef
   void Ifdef(SourceLocation Loc, const Token ,
  const MacroDefinition ) override;
   void Ifndef(SourceLocation Loc, const Token ,
   const MacroDefinition ) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;
+  void Elifdef(SourceLocation Loc, const Token ,
+   const MacroDefinition ) override;
+  void Elifndef(SourceLocation Loc, const Token ,
+const MacroDefinition ) override;
 
   void Defined(const Token , const MacroDefinition ,
SourceRange Range) override;
Index: clang-tools-extra/clangd/CollectMacros.cpp
===
--- clang-tools-extra/clangd/CollectMacros.cpp
+++ clang-tools-extra/clangd/CollectMacros.cpp
@@ -36,33 +36,51 @@
 SrcMgr::CharacteristicKind, FileID) {
   InMainFile = isInsideMainFile(Loc, SM);
 }
+
 void CollectMainFileMacros::MacroExpands(const Token ,
  const MacroDefinition ,
  SourceRange Range,
  const MacroArgs *Args) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::MacroUndefined(const clang::Token ,
const clang::MacroDefinition ,
const clang::MacroDirective *Undef) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::Ifdef(SourceLocation Loc, const Token ,
   const MacroDefinition ) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
 void CollectMainFileMacros::Ifndef(SourceLocation Loc, const Token ,
const MacroDefinition ) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
+void CollectMainFileMacros::Elifdef(SourceLocation Loc, const Token ,
+const MacroDefinition ) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
+void CollectMainFileMacros::Elifndef(SourceLocation Loc, const Token ,
+ const MacroDefinition ) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
 void CollectMainFileMacros::Defined(const Token ,
 const MacroDefinition ,
 SourceRange Range) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 

[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet accepted this revision.
kadircet added a comment.
This revision is now accepted and ready to land.

thanks, LG


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

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


[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-29 Thread Haojian Wu via Phabricator via cfe-commits
hokein added inline comments.



Comment at: clang-tools-extra/clangd/CollectMacros.h:69
   const MacroDefinition ) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;

kadircet wrote:
> why do we have these using decls?
This is to suppress the -Woverloaded-virtual diagnostic from gcc 
(https://godbolt.org/z/9b76fYbjx) -- PPCallback has two overloads of 
`Elifdefs`, here we only override one.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

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


[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-23 Thread Kadir Cetinkaya via Phabricator via cfe-commits
kadircet added a comment.

thanks, LG apart from the using decls




Comment at: clang-tools-extra/clangd/CollectMacros.h:69
   const MacroDefinition ) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;

why do we have these using decls?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D146717

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


[PATCH] D146717: [clangd] Handle the C++2b elifdef and elindef PP structure in CollectMainFileMacros.

2023-03-23 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added a reviewer: kadircet.
Herald added a subscriber: arphaman.
Herald added a project: All.
hokein requested review of this revision.
Herald added subscribers: MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146717

Files:
  clang-tools-extra/clangd/CollectMacros.cpp
  clang-tools-extra/clangd/CollectMacros.h
  clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp

Index: clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
===
--- clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
+++ clang-tools-extra/clangd/unittests/CollectMacrosTests.cpp
@@ -56,6 +56,11 @@
   // )cpp",
   R"cpp(
 #ifdef $Unknown(condit)[[UNDEFINED]]
+#elifdef $Unknown(condit)[[UNDEFINED]]
+#endif
+
+#ifdef $Unknown(condit)[[UNDEFINED]]
+#elifndef $Unknown(condit)[[UNDEFINED]]
 #endif
 
 #ifndef $Unknown(condit)[[UNDEFINED]]
@@ -101,11 +106,12 @@
 
   for (const char *Test : Tests) {
 Annotations T(Test);
-auto AST = TestTU::withCode(T.code()).build();
+auto Inputs = TestTU::withCode(T.code());
+Inputs.ExtraArgs.push_back("-std=c++2b");
+auto AST = Inputs.build();
 auto ActualMacroRefs = AST.getMacros();
 auto  = AST.getSourceManager();
 auto  = AST.getPreprocessor();
-
 for (const auto &[Name, Ranges] : T.all_ranges()) {
   if (Name == "Unknown") {
 EXPECT_THAT(ActualMacroRefs.UnknownMacros,
Index: clang-tools-extra/clangd/CollectMacros.h
===
--- clang-tools-extra/clangd/CollectMacros.h
+++ clang-tools-extra/clangd/CollectMacros.h
@@ -12,6 +12,7 @@
 #include "Protocol.h"
 #include "SourceCode.h"
 #include "index/SymbolID.h"
+#include "clang/Basic/SourceLocation.h"
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "llvm/ADT/DenseMap.h"
@@ -61,11 +62,16 @@
   const clang::MacroDefinition ,
   const clang::MacroDirective *Undef) override;
 
-  // FIXME: handle C++23 #elifdef, #elifndef
   void Ifdef(SourceLocation Loc, const Token ,
  const MacroDefinition ) override;
   void Ifndef(SourceLocation Loc, const Token ,
   const MacroDefinition ) override;
+  using PPCallbacks::Elifdef;
+  using PPCallbacks::Elifndef;
+  void Elifdef(SourceLocation Loc, const Token ,
+   const MacroDefinition ) override;
+  void Elifndef(SourceLocation Loc, const Token ,
+const MacroDefinition ) override;
 
   void Defined(const Token , const MacroDefinition ,
SourceRange Range) override;
Index: clang-tools-extra/clangd/CollectMacros.cpp
===
--- clang-tools-extra/clangd/CollectMacros.cpp
+++ clang-tools-extra/clangd/CollectMacros.cpp
@@ -36,33 +36,51 @@
 SrcMgr::CharacteristicKind, FileID) {
   InMainFile = isInsideMainFile(Loc, SM);
 }
+
 void CollectMainFileMacros::MacroExpands(const Token ,
  const MacroDefinition ,
  SourceRange Range,
  const MacroArgs *Args) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::MacroUndefined(const clang::Token ,
const clang::MacroDefinition ,
const clang::MacroDirective *Undef) {
   add(MacroName, MD.getMacroInfo());
 }
+
 void CollectMainFileMacros::Ifdef(SourceLocation Loc, const Token ,
   const MacroDefinition ) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
 void CollectMainFileMacros::Ifndef(SourceLocation Loc, const Token ,
const MacroDefinition ) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
+void CollectMainFileMacros::Elifdef(SourceLocation Loc, const Token ,
+const MacroDefinition ) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
+void CollectMainFileMacros::Elifndef(SourceLocation Loc, const Token ,
+ const MacroDefinition ) {
+  add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
+  /*InConditionalDirective=*/true);
+}
+
 void CollectMainFileMacros::Defined(const Token ,
 const MacroDefinition ,
 SourceRange Range) {
   add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false,
   /*InConditionalDirective=*/true);
 }
+
 void