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 &SM = AST.getSourceManager(); auto &PP = 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 &MD, const clang::MacroDirective *Undef) override; - // FIXME: handle C++23 #elifdef, #elifndef void Ifdef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override; void Ifndef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) override; + using PPCallbacks::Elifdef; + using PPCallbacks::Elifndef; + void Elifdef(SourceLocation Loc, const Token &MacroNameTok, + const MacroDefinition &MD) override; + void Elifndef(SourceLocation Loc, const Token &MacroNameTok, + const MacroDefinition &MD) override; void Defined(const Token &MacroName, const MacroDefinition &MD, 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 &MacroName, const MacroDefinition &MD, SourceRange Range, const MacroArgs *Args) { add(MacroName, MD.getMacroInfo()); } + void CollectMainFileMacros::MacroUndefined(const clang::Token &MacroName, const clang::MacroDefinition &MD, const clang::MacroDirective *Undef) { add(MacroName, MD.getMacroInfo()); } + void CollectMainFileMacros::Ifdef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) { add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false, /*InConditionalDirective=*/true); } + void CollectMainFileMacros::Ifndef(SourceLocation Loc, const Token &MacroName, const MacroDefinition &MD) { add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false, /*InConditionalDirective=*/true); } + +void CollectMainFileMacros::Elifdef(SourceLocation Loc, const Token &MacroName, + const MacroDefinition &MD) { + add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false, + /*InConditionalDirective=*/true); +} + +void CollectMainFileMacros::Elifndef(SourceLocation Loc, const Token &MacroName, + const MacroDefinition &MD) { + add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false, + /*InConditionalDirective=*/true); +} + void CollectMainFileMacros::Defined(const Token &MacroName, const MacroDefinition &MD, SourceRange Range) { add(MacroName, MD.getMacroInfo(), /*IsDefinition=*/false, /*InConditionalDirective=*/true); } + void CollectMainFileMacros::SourceRangeSkipped(SourceRange R, SourceLocation EndifLoc) { if (!InMainFile)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits