Use cmsys::auto_ptr to manage cmCompiledGeneratorExpressions

The compiled generator expressions need to outlive the creating
type. For the same reason, store the input string in a std::string.
This commit is contained in:
Stephen Kelly 2012-11-19 19:30:56 +01:00
parent 5ac16ea6e4
commit 76ea420fb9
6 changed files with 44 additions and 45 deletions

View File

@ -47,7 +47,7 @@ std::string cmCustomCommandGenerator::GetCommand(unsigned int c) const
{
return target->GetLocation(this->Config);
}
return this->GE->Parse(argv0).Evaluate(this->Makefile, this->Config);
return this->GE->Parse(argv0)->Evaluate(this->Makefile, this->Config);
}
//----------------------------------------------------------------------------
@ -58,7 +58,7 @@ cmCustomCommandGenerator
cmCustomCommandLine const& commandLine = this->CC.GetCommandLines()[c];
for(unsigned int j=1;j < commandLine.size(); ++j)
{
std::string arg = this->GE->Parse(commandLine[j]).Evaluate(this->Makefile,
std::string arg = this->GE->Parse(commandLine[j])->Evaluate(this->Makefile,
this->Config);
cmd += " ";
if(this->OldStyle)

View File

@ -25,44 +25,29 @@
//----------------------------------------------------------------------------
cmGeneratorExpression::cmGeneratorExpression(
cmListFileBacktrace const& backtrace):
Backtrace(backtrace), CompiledExpression(0)
Backtrace(backtrace)
{
}
//----------------------------------------------------------------------------
const cmCompiledGeneratorExpression &
cmsys::auto_ptr<cmCompiledGeneratorExpression>
cmGeneratorExpression::Parse(std::string const& input)
{
return this->Parse(input.c_str());
}
//----------------------------------------------------------------------------
const cmCompiledGeneratorExpression &
cmsys::auto_ptr<cmCompiledGeneratorExpression>
cmGeneratorExpression::Parse(const char* input)
{
cmGeneratorExpressionLexer l;
std::vector<cmGeneratorExpressionToken> tokens = l.Tokenize(input);
bool needsParsing = l.GetSawGeneratorExpression();
std::vector<cmGeneratorExpressionEvaluator*> evaluators;
if (needsParsing)
{
cmGeneratorExpressionParser p(tokens);
p.Parse(evaluators);
}
delete this->CompiledExpression;
this->CompiledExpression = new cmCompiledGeneratorExpression(
this->Backtrace,
evaluators,
input,
needsParsing);
return *this->CompiledExpression;
return cmsys::auto_ptr<cmCompiledGeneratorExpression>(
new cmCompiledGeneratorExpression(
this->Backtrace,
input));
}
cmGeneratorExpression::~cmGeneratorExpression()
{
delete this->CompiledExpression;
}
//----------------------------------------------------------------------------
@ -73,7 +58,7 @@ const char *cmCompiledGeneratorExpression::Evaluate(
{
if (!this->NeedsParsing)
{
return this->Input;
return this->Input.c_str();
}
this->Output = "";
@ -108,12 +93,19 @@ const char *cmCompiledGeneratorExpression::Evaluate(
cmCompiledGeneratorExpression::cmCompiledGeneratorExpression(
cmListFileBacktrace const& backtrace,
const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
const char *input, bool needsParsing)
: Backtrace(backtrace), Evaluators(evaluators), Input(input),
NeedsParsing(needsParsing)
const char *input)
: Backtrace(backtrace), Input(input ? input : "")
{
cmGeneratorExpressionLexer l;
std::vector<cmGeneratorExpressionToken> tokens =
l.Tokenize(this->Input.c_str());
this->NeedsParsing = l.GetSawGeneratorExpression();
if (this->NeedsParsing)
{
cmGeneratorExpressionParser p(tokens);
p.Parse(this->Evaluators);
}
}

View File

@ -14,10 +14,12 @@
#define cmGeneratorExpression_h
#include "cmStandardIncludes.h"
#include "cmListFileCache.h"
#include <stack>
#include <cmsys/RegularExpression.hxx>
#include <cmsys/auto_ptr.hxx>
class cmTarget;
class cmMakefile;
@ -44,8 +46,9 @@ public:
cmGeneratorExpression(cmListFileBacktrace const& backtrace);
~cmGeneratorExpression();
const cmCompiledGeneratorExpression& Parse(std::string const& input);
const cmCompiledGeneratorExpression& Parse(const char* input);
cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(
std::string const& input);
cmsys::auto_ptr<cmCompiledGeneratorExpression> Parse(const char* input);
enum PreprocessContext {
StripAllGeneratorExpressions
@ -59,7 +62,6 @@ private:
void operator=(const cmGeneratorExpression &);
cmListFileBacktrace const& Backtrace;
cmCompiledGeneratorExpression *CompiledExpression;
};
class cmCompiledGeneratorExpression
@ -76,20 +78,24 @@ public:
~cmCompiledGeneratorExpression();
std::string GetInput() const
{
return this->Input;
}
private:
cmCompiledGeneratorExpression(cmListFileBacktrace const& backtrace,
const std::vector<cmGeneratorExpressionEvaluator*> &evaluators,
const char *input, bool needsParsing);
const char *input);
friend class cmGeneratorExpression;
cmCompiledGeneratorExpression(const cmCompiledGeneratorExpression &);
void operator=(const cmCompiledGeneratorExpression &);
cmListFileBacktrace const& Backtrace;
const std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
const char* const Input;
const bool NeedsParsing;
cmListFileBacktrace Backtrace;
std::vector<cmGeneratorExpressionEvaluator*> Evaluators;
const std::string Input;
bool NeedsParsing;
mutable std::set<cmTarget*> Targets;
mutable std::string Output;

View File

@ -267,7 +267,7 @@ std::vector<std::string> cmGeneratorTarget::GetIncludeDirectories(
"INCLUDE_DIRECTORIES", 0, 0);
cmSystemTools::ExpandListArgument(ge.Parse(prop)
.Evaluate(this->Makefile,
->Evaluate(this->Makefile,
config,
false,
this->Target,
@ -315,7 +315,7 @@ std::string cmGeneratorTarget::GetCompileDefinitions(const char *config)
cmGeneratorExpressionDAGChecker dagChecker(lfbt,
this->GetName(),
defPropName, 0, 0);
return ge.Parse(prop).Evaluate(this->Makefile,
return ge.Parse(prop)->Evaluate(this->Makefile,
config,
false,
this->Target,

View File

@ -1728,9 +1728,10 @@ cmTargetTraceDependencies
for(cmCustomCommandLine::const_iterator cli = cit->begin();
cli != cit->end(); ++cli)
{
const cmCompiledGeneratorExpression &cge = ge.Parse(*cli);
cge.Evaluate(this->Makefile, 0, true);
std::set<cmTarget*> geTargets = cge.GetTargets();
const cmsys::auto_ptr<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)
{

View File

@ -112,7 +112,7 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
else
{
// Use the command name given.
exe = ge.Parse(exe.c_str()).Evaluate(mf, config);
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.Parse(*ci).Evaluate(mf, config));
os << " " << lg->EscapeForCMake(ge.Parse(*ci)->Evaluate(mf, config));
}
// Finish the test command.