From 604993248fdee0bec8ab8c74c1173c67496a7dfd Mon Sep 17 00:00:00 2001 From: Marc Chevrier Date: Mon, 15 Aug 2022 17:05:12 +0200 Subject: cmMakefile::VariablePushPop: helper class to manage variable scopes --- Source/cmMakefile.cxx | 13 +++++++++++++ Source/cmMakefile.h | 14 ++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 208d907..b228e2b 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4543,6 +4543,19 @@ bool cmMakefile::SetPolicyVersion(std::string const& version_min, cmPolicies::WarnCompat::On); } +cmMakefile::VariablePushPop::VariablePushPop(cmMakefile* m) + : Makefile(m) +{ + this->Makefile->StateSnapshot = + this->Makefile->GetState()->CreateVariableScopeSnapshot( + this->Makefile->StateSnapshot); +} + +cmMakefile::VariablePushPop::~VariablePushPop() +{ + this->Makefile->PopSnapshot(); +} + bool cmMakefile::HasCMP0054AlreadyBeenReported( cmListFileContext const& context) const { diff --git a/Source/cmMakefile.h b/Source/cmMakefile.h index 0198ec1..10432a8 100644 --- a/Source/cmMakefile.h +++ b/Source/cmMakefile.h @@ -376,6 +376,20 @@ public: }; friend class PolicyPushPop; + /** Helper class to push and pop variables scopes automatically. */ + class VariablePushPop + { + public: + VariablePushPop(cmMakefile* m); + ~VariablePushPop(); + + VariablePushPop(VariablePushPop const&) = delete; + VariablePushPop& operator=(VariablePushPop const&) = delete; + + private: + cmMakefile* Makefile; + }; + /** * Determine if the given context, name pair has already been reported * in context of CMP0054. -- cgit v0.12