cmGeneratorExpression: Port users to two-stage processing
Removing the Process() API and removing the parameters from the constructor will allow cmGeneratorExpressions to be cached and evaluated with multiple configs for example, such as when evaluating target properties. This requires the creation of a new compiled representation of cmGeneratorExpression. The cmListFileBacktrace remains in the constructor so that we can record where a particular generator expression appeared in the CMakeLists file.
This commit is contained in:
parent
f1eacf0e07
commit
91011bd217
|
@ -21,7 +21,7 @@ cmCustomCommandGenerator::cmCustomCommandGenerator(
|
|||
cmCustomCommand const& cc, const char* config, cmMakefile* mf):
|
||||
CC(cc), Config(config), Makefile(mf), LG(mf->GetLocalGenerator()),
|
||||
OldStyle(cc.GetEscapeOldStyle()), MakeVars(cc.GetEscapeAllowMakeVars()),
|
||||
GE(new cmGeneratorExpression(mf, config, cc.GetBacktrace()))
|
||||
GE(new cmGeneratorExpression(cc.GetBacktrace()))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
|
|||
{
|
||||
return target->GetLocation(this->Config);
|
||||
}
|
||||
return this->GE->Process(argv0);
|
||||
return this->GE->Parse(argv0).Evaluate(this->Makefile, this->Config);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
@ -58,7 +58,8 @@ cmCustomCommandGenerator
|
|||
cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
|
||||
for(unsigned int j=1;j < commandLine.size(); ++j)
|
||||
{
|
||||
std::string arg = this->GE->Process(commandLine[j]);
|
||||
std::string arg = this->GE->Parse(commandLine[j]).Evaluate(this->Makefile,
|
||||
this->Config);
|
||||
cmd += " ";
|
||||
if(this->OldStyle)
|
||||
{
|
||||
|
|
|
@ -22,48 +22,50 @@
|
|||
|
||||
//----------------------------------------------------------------------------
|
||||
cmGeneratorExpression::cmGeneratorExpression(
|
||||
cmMakefile* mf, const char* config,
|
||||
cmListFileBacktrace const& backtrace, bool quiet):
|
||||
Makefile(mf), Config(config), Backtrace(backtrace), Quiet(quiet),
|
||||
NeedsParsing(true)
|
||||
cmListFileBacktrace const& backtrace):
|
||||
Backtrace(backtrace), CompiledExpression(0)
|
||||
{
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const char* cmGeneratorExpression::Process(std::string const& input)
|
||||
const cmCompiledGeneratorExpression &
|
||||
cmGeneratorExpression::Parse(std::string const& input)
|
||||
{
|
||||
return this->Process(input.c_str());
|
||||
return this->Parse(input.c_str());
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const char* cmGeneratorExpression::Process(const char* input)
|
||||
const cmCompiledGeneratorExpression &
|
||||
cmGeneratorExpression::Parse(const char* input)
|
||||
{
|
||||
this->Parse(input);
|
||||
return this->Evaluate(this->Makefile, this->Config, this->Quiet);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
void cmGeneratorExpression::Parse(const char* input)
|
||||
{
|
||||
this->Evaluators.clear();
|
||||
|
||||
this->Input = input;
|
||||
cmGeneratorExpressionLexer l;
|
||||
std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(this->Input);
|
||||
this->NeedsParsing = l.GetSawGeneratorExpression();
|
||||
std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(input);
|
||||
bool needsParsing = l.GetSawGeneratorExpression();
|
||||
std::vector<cmGeneratorExpressionEvaluator*> evaluators;
|
||||
|
||||
if (!this->NeedsParsing)
|
||||
if (needsParsing)
|
||||
{
|
||||
return;
|
||||
cmGeneratorExpressionParser p(tokens);
|
||||
p.Parse(evaluators);
|
||||
}
|
||||
|
||||
cmGeneratorExpressionParser p(tokens);
|
||||
p.Parse(this->Evaluators);
|
||||
delete this->CompiledExpression;
|
||||
this->CompiledExpression = new cmCompiledGeneratorExpression(
|
||||
this->Backtrace,
|
||||
evaluators,
|
||||
input,
|
||||
needsParsing);
|
||||
return *this->CompiledExpression;
|
||||
}
|
||||
|
||||
cmGeneratorExpression::~cmGeneratorExpression()
|
||||
{
|
||||
delete this->CompiledExpression;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const char *cmGeneratorExpression::Evaluate(
|
||||
cmMakefile* mf, const char* config, bool quiet)
|
||||
const char *cmCompiledGeneratorExpression::Evaluate(
|
||||
cmMakefile* mf, const char* config, bool quiet) const
|
||||
{
|
||||
if (!this->NeedsParsing)
|
||||
{
|
||||
|
@ -99,8 +101,19 @@ const char *cmGeneratorExpression::Evaluate(
|
|||
return this->Output.c_str();
|
||||
}
|
||||
|
||||
cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
|
||||
cmListFileBacktrace const& backtrace,
|
||||
const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
|
||||
const char *input, bool needsParsing)
|
||||
: Backtrace(backtrace), Evaluators(evaluators), Input(input),
|
||||
NeedsParsing(needsParsing)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
cmGeneratorExpression::~cmGeneratorExpression()
|
||||
cmCompiledGeneratorExpression::~cmCompiledGeneratorExpression()
|
||||
{
|
||||
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
|
||||
= this->Evaluators.begin();
|
||||
|
|
|
@ -21,6 +21,8 @@ class cmListFileBacktrace;
|
|||
|
||||
struct cmGeneratorExpressionEvaluator;
|
||||
|
||||
class cmCompiledGeneratorExpression;
|
||||
|
||||
/** \class cmGeneratorExpression
|
||||
* \brief Evaluate generate-time query expression syntax.
|
||||
*
|
||||
|
@ -33,34 +35,48 @@ struct cmGeneratorExpressionEvaluator;
|
|||
class cmGeneratorExpression
|
||||
{
|
||||
public:
|
||||
/** Construct with an evaluation context and configuration. */
|
||||
cmGeneratorExpression(cmMakefile* mf, const char* config,
|
||||
cmListFileBacktrace const& backtrace,
|
||||
bool quiet = false);
|
||||
|
||||
/** Construct. */
|
||||
cmGeneratorExpression(cmListFileBacktrace const& backtrace);
|
||||
~cmGeneratorExpression();
|
||||
|
||||
/** Evaluate generator expressions in a string. */
|
||||
const char* Process(std::string const& input);
|
||||
const char* Process(const char* input);
|
||||
const cmCompiledGeneratorExpression& Parse(std::string const& input);
|
||||
const cmCompiledGeneratorExpression& Parse(const char* input);
|
||||
|
||||
void Parse(const char* input);
|
||||
private:
|
||||
cmGeneratorExpression(const cmGeneratorExpression &);
|
||||
void operator=(const cmGeneratorExpression &);
|
||||
|
||||
cmListFileBacktrace const& Backtrace;
|
||||
cmCompiledGeneratorExpression *CompiledExpression;
|
||||
};
|
||||
|
||||
class cmCompiledGeneratorExpression
|
||||
{
|
||||
public:
|
||||
const char* Evaluate(cmMakefile* mf, const char* config,
|
||||
bool quiet = false);
|
||||
bool quiet = false) const;
|
||||
|
||||
/** Get set of targets found during evaluations. */
|
||||
std::set<cmTarget*> const& GetTargets() const
|
||||
{ return this->Targets; }
|
||||
|
||||
~cmCompiledGeneratorExpression();
|
||||
|
||||
private:
|
||||
std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
|
||||
cmMakefile* Makefile;
|
||||
const char* Config;
|
||||
cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
|
||||
const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
|
||||
const char *input, bool needsParsing);
|
||||
|
||||
friend class cmGeneratorExpression;
|
||||
|
||||
cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
|
||||
void operator=(const cmCompiledGeneratorExpression &);
|
||||
|
||||
cmListFileBacktrace const& Backtrace;
|
||||
bool Quiet;
|
||||
const std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
|
||||
const char* const Input;
|
||||
const bool NeedsParsing;
|
||||
|
||||
std::set<cmTarget*> Targets;
|
||||
const char* Input;
|
||||
bool NeedsParsing;
|
||||
|
||||
std::string Output;
|
||||
mutable std::set<cmTarget*> Targets;
|
||||
mutable std::string Output;
|
||||
};
|
||||
|
|
|
@ -1623,7 +1623,11 @@ cmTargetTraceDependencies
|
|||
{
|
||||
// Transform command names that reference targets built in this
|
||||
// project to corresponding target-level dependencies.
|
||||
cmGeneratorExpression ge(this->Makefile, 0, cc.GetBacktrace(), true);
|
||||
cmGeneratorExpression ge(cc.GetBacktrace());
|
||||
|
||||
// Add target-level dependencies referenced by generator expressions.
|
||||
std::set<cmTarget*> targets;
|
||||
|
||||
for(cmCustomCommandLines::const_iterator cit = cc.GetCommandLines().begin();
|
||||
cit != cc.GetCommandLines().end(); ++cit)
|
||||
{
|
||||
|
@ -1645,12 +1649,17 @@ cmTargetTraceDependencies
|
|||
for(cmCustomCommandLine::const_iterator cli = cit->begin();
|
||||
cli != cit->end(); ++cli)
|
||||
{
|
||||
ge.Process(*cli);
|
||||
const cmCompiledGeneratorExpression &cge = ge.Parse(*cli);
|
||||
cge.Evaluate(this->Makefile, 0, true);
|
||||
std::set<cmTarget*> geTargets = cge.GetTargets();
|
||||
for(std::set<cmTarget*>::const_iterator it = geTargets.begin();
|
||||
it != geTargets.end(); ++it)
|
||||
{
|
||||
targets.insert(*it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add target-level dependencies referenced by generator expressions.
|
||||
std::set<cmTarget*> targets = ge.GetTargets();
|
||||
for(std::set<cmTarget*>::iterator ti = targets.begin();
|
||||
ti != targets.end(); ++ti)
|
||||
{
|
||||
|
|
|
@ -91,8 +91,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||
this->TestGenerated = true;
|
||||
|
||||
// Set up generator expression evaluation context.
|
||||
cmMakefile* mf = this->Test->GetMakefile();
|
||||
cmGeneratorExpression ge(mf, config, this->Test->GetBacktrace());
|
||||
cmGeneratorExpression ge(this->Test->GetBacktrace());
|
||||
|
||||
// Start the test command.
|
||||
os << indent << "ADD_TEST(" << this->Test->GetName() << " ";
|
||||
|
@ -103,6 +102,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||
// Check whether the command executable is a target whose name is to
|
||||
// be translated.
|
||||
std::string exe = command[0];
|
||||
cmMakefile* mf = this->Test->GetMakefile();
|
||||
cmTarget* target = mf->FindTargetToUse(exe.c_str());
|
||||
if(target && target->GetType() == cmTarget::EXECUTABLE)
|
||||
{
|
||||
|
@ -112,7 +112,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||
else
|
||||
{
|
||||
// Use the command name given.
|
||||
exe = ge.Process(exe.c_str());
|
||||
exe = ge.Parse(exe.c_str()).Evaluate(mf, config);
|
||||
cmSystemTools::ConvertToUnixSlashes(exe);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
|
|||
for(std::vector<std::string>::const_iterator ci = command.begin()+1;
|
||||
ci != command.end(); ++ci)
|
||||
{
|
||||
os << " " << lg->EscapeForCMake(ge.Process(*ci));
|
||||
os << " " << lg->EscapeForCMake(ge.Parse(*ci).Evaluate(mf, config));
|
||||
}
|
||||
|
||||
// Finish the test command.
|
||||
|
|
Loading…
Reference in New Issue