blob: a6a9c6a1ec4def4431bf9c5cf8c248b64df064a4 [file]
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file LICENSE.rst or https://cmake.org/licensing for details. */
#pragma once
#include "cmConfigure.h" // IWYU pragma: keep
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include <cm/string_view>
#include "cmCommandTypes.h"
#include "cmDiagnostics.h"
#include "cmListFileCache.h"
#include "cmPolicies.h"
class cmExecutionStatus;
class cmMakefile;
namespace cmStateEnums {
enum class CommandType;
}
class cmFunctionBlocker
{
public:
/**
* should a function be blocked
*/
bool IsFunctionBlocked(cmListFileFunction const& lff,
cmExecutionStatus& status);
virtual ~cmFunctionBlocker() = default;
/** Set/Get the context in which this blocker is created. */
void SetStartingContext(cmListFileContext const& lfc)
{
this->StartingContext = lfc;
}
cmListFileContext const& GetStartingContext() const
{
return this->StartingContext;
}
protected:
template <typename Helper>
std::shared_ptr<Helper> CreateHelper(
std::vector<std::string> const& args,
std::vector<cmListFileFunction> functions, cmMakefile& mf) const
{
auto helper = std::make_shared<Helper>();
helper->Args = args;
helper->Functions = std::move(functions);
helper->FilePath = this->StartingContext.FilePath;
helper->Line = this->StartingContext.Line;
RecordPoliciesAndDiagnostics(mf, helper->Policies, helper->Diagnostics);
return helper;
}
// Share the helper so that each call does not copy it.
template <typename Helper>
bool AddCommand(std::shared_ptr<Helper> helper,
cmStateEnums::CommandType type, cmMakefile& mf) const
{
return this->AddScriptedCommand(
helper->Args.front(), type,
[helper](std::vector<cmListFileArgument> const& args,
cmExecutionStatus& status) { return (*helper)(args, status); },
mf);
}
private:
static void RecordPoliciesAndDiagnostics(
cmMakefile& mf, cmPolicies::PolicyMap& policies,
cmDiagnostics::DiagnosticMap& diagnostics);
bool AddScriptedCommand(std::string const& name,
cmStateEnums::CommandType type, cm::Command command,
cmMakefile& mf) const;
virtual cm::string_view StartCommandName() const = 0;
virtual cm::string_view EndCommandName() const = 0;
virtual bool EndCommandSupportsArguments() const { return true; }
virtual bool ArgumentsMatch(cmListFileFunction const& lff,
cmMakefile& mf) const = 0;
virtual bool Replay(std::vector<cmListFileFunction> functions,
cmExecutionStatus& status) = 0;
cmListFileContext StartingContext;
std::vector<cmListFileFunction> Functions;
unsigned int ScopeDepth = 1;
};