[PATCH] D29923: PPCallbacks::MacroUndefined, change signature and add test.
This revision was automatically updated to reflect the committed changes. Closed by commit rL301449: PPCallbacks::MacroUndefined, change signature and add test. (authored by marsupial). Changed prior to commit: https://reviews.llvm.org/D29923?vs=91627=96808#toc Repository: rL LLVM https://reviews.llvm.org/D29923 Files: cfe/trunk/include/clang/Lex/PPCallbacks.h cfe/trunk/include/clang/Lex/PreprocessingRecord.h cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp cfe/trunk/lib/Lex/PPDirectives.cpp cfe/trunk/lib/Lex/PreprocessingRecord.cpp cfe/trunk/tools/libclang/Indexing.cpp cfe/trunk/unittests/Basic/SourceManagerTest.cpp Index: cfe/trunk/include/clang/Lex/PreprocessingRecord.h === --- cfe/trunk/include/clang/Lex/PreprocessingRecord.h +++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h @@ -488,7 +488,8 @@ void MacroExpands(const Token , const MacroDefinition , SourceRange Range, const MacroArgs *Args) override; void MacroDefined(const Token , const MacroDirective *MD) override; -void MacroUndefined(const Token , const MacroDefinition ) override; +void MacroUndefined(const Token , const MacroDefinition , +const MacroDirective *Undef) override; void InclusionDirective(SourceLocation HashLoc, const Token , StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, Index: cfe/trunk/include/clang/Lex/PPCallbacks.h === --- cfe/trunk/include/clang/Lex/PPCallbacks.h +++ cfe/trunk/include/clang/Lex/PPCallbacks.h @@ -247,10 +247,14 @@ } /// \brief Hook called whenever a macro \#undef is seen. + /// \param Token The active Token + /// \param MD A MacroDefinition for the named macro. + /// \param Undef New MacroDirective if the macro was defined, null otherwise. /// /// MD is released immediately following this callback. virtual void MacroUndefined(const Token , - const MacroDefinition ) { + const MacroDefinition , + const MacroDirective *Undef) { } /// \brief Hook called whenever the 'defined' operator is seen. @@ -439,15 +443,17 @@ Second->MacroExpands(MacroNameTok, MD, Range, Args); } - void MacroDefined(const Token , const MacroDirective *MD) override { + void MacroDefined(const Token , +const MacroDirective *MD) override { First->MacroDefined(MacroNameTok, MD); Second->MacroDefined(MacroNameTok, MD); } void MacroUndefined(const Token , - const MacroDefinition ) override { -First->MacroUndefined(MacroNameTok, MD); -Second->MacroUndefined(MacroNameTok, MD); + const MacroDefinition , + const MacroDirective *Undef) override { +First->MacroUndefined(MacroNameTok, MD, Undef); +Second->MacroUndefined(MacroNameTok, MD, Undef); } void Defined(const Token , const MacroDefinition , Index: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp === --- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp +++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp @@ -172,7 +172,8 @@ /// MacroUndefined - This hook is called whenever a macro #undef is seen. void MacroUndefined(const Token , - const MacroDefinition ) override; + const MacroDefinition , + const MacroDirective *Undef) override; }; } // end anonymous namespace @@ -389,7 +390,8 @@ } void PrintPPOutputPPCallbacks::MacroUndefined(const Token , - const MacroDefinition ) { + const MacroDefinition , + const MacroDirective *Undef) { // Only print out macro definitions in -dD mode. if (!DumpDefines) return; Index: cfe/trunk/lib/Lex/PreprocessingRecord.cpp === --- cfe/trunk/lib/Lex/PreprocessingRecord.cpp +++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp @@ -422,7 +422,8 @@ } void PreprocessingRecord::MacroUndefined(const Token , - const MacroDefinition ) { + const MacroDefinition , + const MacroDirective *Undef) { MD.forAllDefinitions([&](MacroInfo *MI) { MacroDefinitions.erase(MI); }); } Index: cfe/trunk/lib/Lex/PPDirectives.cpp === --- cfe/trunk/lib/Lex/PPDirectives.cpp +++ cfe/trunk/lib/Lex/PPDirectives.cpp @@ -2592,25 +2592,26 @@ // Okay, we have a valid identifier to undef. auto *II =
[PATCH] D29923: PPCallbacks::MacroUndefined, change signature and add test.
bruno accepted this revision. bruno added a comment. This revision is now accepted and ready to land. LGTM! https://reviews.llvm.org/D29923 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29923: PPCallbacks::MacroUndefined, change signature and add test.
marsupial added a comment. ping https://reviews.llvm.org/D29923 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D29923: PPCallbacks::MacroUndefined, change signature and add test.
marsupial updated this revision to Diff 91627. marsupial retitled this revision from "Add test for PPCallbacks::MacroUndefined" to "PPCallbacks::MacroUndefined, change signature and add test.". marsupial edited the summary of this revision. Herald added a subscriber: nemanjai. https://reviews.llvm.org/D29923 Files: include/clang/Lex/PPCallbacks.h include/clang/Lex/PreprocessingRecord.h lib/Frontend/PrintPreprocessedOutput.cpp lib/Lex/PPDirectives.cpp lib/Lex/PreprocessingRecord.cpp tools/libclang/Indexing.cpp unittests/Basic/SourceManagerTest.cpp Index: unittests/Basic/SourceManagerTest.cpp === --- unittests/Basic/SourceManagerTest.cpp +++ unittests/Basic/SourceManagerTest.cpp @@ -246,12 +246,18 @@ namespace { struct MacroAction { + enum Kind { kExpansion, kDefinition, kUnDefinition}; + SourceLocation Loc; std::string Name; - bool isDefinition; // if false, it is expansion. - - MacroAction(SourceLocation Loc, StringRef Name, bool isDefinition) -: Loc(Loc), Name(Name), isDefinition(isDefinition) { } + unsigned MAKind : 3; + + MacroAction(SourceLocation Loc, StringRef Name, unsigned K) +: Loc(Loc), Name(Name), MAKind(K) { } + + bool isExpansion() const { return MAKind == kExpansion; } + bool isDefinition() const { return MAKind & kDefinition; } + bool isUnDefinition() const { return MAKind & kUnDefinition; } }; class MacroTracker : public PPCallbacks { @@ -264,21 +270,33 @@ const MacroDirective *MD) override { Macros.push_back(MacroAction(MD->getLocation(), MacroNameTok.getIdentifierInfo()->getName(), - true)); + MacroAction::kDefinition)); + } + void MacroUndefined(const Token , + const MacroDefinition , + const MacroDirective *UD) override { +Macros.push_back( +MacroAction(UD ? UD->getLocation() : SourceLocation(), +MacroNameTok.getIdentifierInfo()->getName(), +UD ? MacroAction::kDefinition | MacroAction::kUnDefinition + : MacroAction::kUnDefinition)); } void MacroExpands(const Token , const MacroDefinition , SourceRange Range, const MacroArgs *Args) override { Macros.push_back(MacroAction(MacroNameTok.getLocation(), MacroNameTok.getIdentifierInfo()->getName(), - false)); + MacroAction::kExpansion)); } }; } TEST_F(SourceManagerTest, isBeforeInTranslationUnitWithMacroInInclude) { const char *header = -"#define MACRO_IN_INCLUDE 0\n"; +"#define MACRO_IN_INCLUDE 0\n" +"#define MACRO_DEFINED\n" +"#undef MACRO_DEFINED\n" +"#undef MACRO_UNDEFINED\n"; const char *main = "#define M(x) x\n" @@ -323,42 +341,54 @@ // Make sure we got the tokens that we expected. ASSERT_EQ(0U, toks.size()); - ASSERT_EQ(9U, Macros.size()); + ASSERT_EQ(15U, Macros.size()); // #define M(x) x - ASSERT_TRUE(Macros[0].isDefinition); + ASSERT_TRUE(Macros[0].isDefinition()); ASSERT_EQ("M", Macros[0].Name); // #define INC "/test-header.h" - ASSERT_TRUE(Macros[1].isDefinition); + ASSERT_TRUE(Macros[1].isDefinition()); ASSERT_EQ("INC", Macros[1].Name); // M expansion in #include M(INC) - ASSERT_FALSE(Macros[2].isDefinition); + ASSERT_FALSE(Macros[2].isDefinition()); ASSERT_EQ("M", Macros[2].Name); // INC expansion in #include M(INC) - ASSERT_FALSE(Macros[3].isDefinition); + ASSERT_TRUE(Macros[3].isExpansion()); ASSERT_EQ("INC", Macros[3].Name); // #define MACRO_IN_INCLUDE 0 - ASSERT_TRUE(Macros[4].isDefinition); + ASSERT_TRUE(Macros[4].isDefinition()); ASSERT_EQ("MACRO_IN_INCLUDE", Macros[4].Name); + // #define MACRO_DEFINED + ASSERT_TRUE(Macros[5].isDefinition()); + ASSERT_FALSE(Macros[5].isUnDefinition()); + ASSERT_EQ("MACRO_DEFINED", Macros[5].Name); + // #undef MACRO_DEFINED + ASSERT_TRUE(Macros[6].isDefinition()); + ASSERT_TRUE(Macros[6].isUnDefinition()); + ASSERT_EQ("MACRO_DEFINED", Macros[6].Name); + // #undef MACRO_UNDEFINED + ASSERT_FALSE(Macros[7].isDefinition()); + ASSERT_TRUE(Macros[7].isUnDefinition()); + ASSERT_EQ("MACRO_UNDEFINED", Macros[7].Name); // #define INC2 - ASSERT_TRUE(Macros[5].isDefinition); - ASSERT_EQ("INC2", Macros[5].Name); + ASSERT_TRUE(Macros[8].isDefinition()); + ASSERT_EQ("INC2", Macros[8].Name); // M expansion in #include M(INC2) - ASSERT_FALSE(Macros[6].isDefinition); - ASSERT_EQ("M", Macros[6].Name); + ASSERT_FALSE(Macros[9].isDefinition()); + ASSERT_EQ("M", Macros[9].Name); // INC2 expansion in #include M(INC2) - ASSERT_FALSE(Macros[7].isDefinition); - ASSERT_EQ("INC2", Macros[7].Name); + ASSERT_TRUE(Macros[10].isExpansion()); + ASSERT_EQ("INC2", Macros[10].Name); // #define MACRO_IN_INCLUDE 0 -