2012-09-11 21:53:38 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2012 Stephen Kelly <steveire@gmail.com>
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmGeneratorExpressionEvaluator.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmAlgorithms.h"
|
2012-09-18 15:53:39 +04:00
|
|
|
#include "cmGeneratorExpression.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmGeneratorExpressionDAGChecker.h"
|
|
|
|
#include "cmGeneratorExpressionParser.h"
|
2015-02-22 19:43:13 +03:00
|
|
|
#include "cmGlobalGenerator.h"
|
2016-04-29 17:53:13 +03:00
|
|
|
#include "cmLocalGenerator.h"
|
|
|
|
#include "cmMakefile.h"
|
2014-02-26 18:59:18 +04:00
|
|
|
#include "cmSourceFile.h"
|
2012-09-11 21:53:38 +04:00
|
|
|
|
2012-11-01 17:21:25 +04:00
|
|
|
#include <cmsys/String.h>
|
|
|
|
|
2013-01-03 23:56:32 +04:00
|
|
|
#include <assert.h>
|
2013-12-27 15:42:37 +04:00
|
|
|
#include <errno.h>
|
2013-01-03 23:56:32 +04:00
|
|
|
|
2015-02-23 01:32:11 +03:00
|
|
|
#include "cmGeneratorExpressionNode.h"
|
2012-09-11 21:53:38 +04:00
|
|
|
|
|
|
|
GeneratorExpressionContent::GeneratorExpressionContent(
|
|
|
|
const char *startContent,
|
2013-10-21 21:18:16 +04:00
|
|
|
size_t length)
|
2012-09-11 21:53:38 +04:00
|
|
|
: StartContent(startContent), ContentLength(length)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GeneratorExpressionContent::GetOriginalExpression() const
|
|
|
|
{
|
|
|
|
return std::string(this->StartContent, this->ContentLength);
|
|
|
|
}
|
|
|
|
|
2013-04-25 15:54:18 +04:00
|
|
|
std::string GeneratorExpressionContent::ProcessArbitraryContent(
|
|
|
|
const cmGeneratorExpressionNode *node,
|
|
|
|
const std::string &identifier,
|
|
|
|
cmGeneratorExpressionContext *context,
|
|
|
|
cmGeneratorExpressionDAGChecker *dagChecker,
|
|
|
|
std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
|
|
|
|
pit) const
|
|
|
|
{
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
const
|
|
|
|
std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
|
|
|
|
pend = this->ParamChildren.end();
|
|
|
|
for ( ; pit != pend; ++pit)
|
|
|
|
{
|
|
|
|
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
|
|
|
|
= pit->begin();
|
|
|
|
const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
|
|
|
|
= pit->end();
|
|
|
|
for ( ; it != end; ++it)
|
|
|
|
{
|
|
|
|
if (node->RequiresLiteralInput())
|
|
|
|
{
|
|
|
|
if ((*it)->GetType() != cmGeneratorExpressionEvaluator::Text)
|
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(),
|
|
|
|
"$<" + identifier + "> expression requires literal input.");
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result += (*it)->Evaluate(context, dagChecker);
|
|
|
|
if (context->HadError)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((pit + 1) != pend)
|
|
|
|
{
|
|
|
|
result += ",";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node->RequiresLiteralInput())
|
|
|
|
{
|
|
|
|
std::vector<std::string> parameters;
|
|
|
|
parameters.push_back(result);
|
|
|
|
return node->Evaluate(parameters, context, this, dagChecker);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-09-11 21:53:38 +04:00
|
|
|
std::string GeneratorExpressionContent::Evaluate(
|
2012-09-18 15:42:23 +04:00
|
|
|
cmGeneratorExpressionContext *context,
|
|
|
|
cmGeneratorExpressionDAGChecker *dagChecker) const
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
|
|
|
std::string identifier;
|
|
|
|
{
|
|
|
|
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
|
|
|
|
= this->IdentifierChildren.begin();
|
|
|
|
const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
|
|
|
|
= this->IdentifierChildren.end();
|
|
|
|
for ( ; it != end; ++it)
|
|
|
|
{
|
2012-09-18 15:42:23 +04:00
|
|
|
identifier += (*it)->Evaluate(context, dagChecker);
|
2012-09-11 21:53:38 +04:00
|
|
|
if (context->HadError)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-23 01:32:11 +03:00
|
|
|
const cmGeneratorExpressionNode *node =
|
|
|
|
cmGeneratorExpressionNode::GetNode(identifier);
|
2012-09-11 21:53:38 +04:00
|
|
|
|
|
|
|
if (!node)
|
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(),
|
|
|
|
"Expression did not evaluate to a known generator expression");
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!node->GeneratesContent())
|
|
|
|
{
|
2013-04-25 15:28:57 +04:00
|
|
|
if (node->NumExpectedParameters() == 1
|
|
|
|
&& node->AcceptsArbitraryContentParameter())
|
2012-11-27 01:43:13 +04:00
|
|
|
{
|
|
|
|
if (this->ParamChildren.empty())
|
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(),
|
|
|
|
"$<" + identifier + "> expression requires a parameter.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::vector<std::string> parameters;
|
|
|
|
this->EvaluateParameters(node, identifier, context, dagChecker,
|
|
|
|
parameters);
|
|
|
|
}
|
2012-09-11 21:53:38 +04:00
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> parameters;
|
2012-11-27 01:42:00 +04:00
|
|
|
this->EvaluateParameters(node, identifier, context, dagChecker, parameters);
|
|
|
|
if (context->HadError)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
|
|
|
return node->Evaluate(parameters, context, this, dagChecker);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GeneratorExpressionContent::EvaluateParameters(
|
|
|
|
const cmGeneratorExpressionNode *node,
|
|
|
|
const std::string &identifier,
|
|
|
|
cmGeneratorExpressionContext *context,
|
|
|
|
cmGeneratorExpressionDAGChecker *dagChecker,
|
|
|
|
std::vector<std::string> ¶meters) const
|
|
|
|
{
|
2013-04-25 15:54:57 +04:00
|
|
|
const int numExpected = node->NumExpectedParameters();
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
|
|
|
std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
|
|
|
|
pit = this->ParamChildren.begin();
|
|
|
|
const
|
|
|
|
std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
|
|
|
|
pend = this->ParamChildren.end();
|
2013-04-25 15:54:57 +04:00
|
|
|
const bool acceptsArbitraryContent
|
|
|
|
= node->AcceptsArbitraryContentParameter();
|
2013-12-18 03:32:35 +04:00
|
|
|
int counter = 1;
|
|
|
|
for ( ; pit != pend; ++pit, ++counter)
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
2013-12-18 03:32:35 +04:00
|
|
|
if (acceptsArbitraryContent && counter == numExpected)
|
2013-04-25 15:54:57 +04:00
|
|
|
{
|
|
|
|
std::string lastParam = this->ProcessArbitraryContent(node, identifier,
|
|
|
|
context,
|
|
|
|
dagChecker,
|
2013-12-18 03:32:35 +04:00
|
|
|
pit);
|
2013-04-25 15:54:57 +04:00
|
|
|
parameters.push_back(lastParam);
|
|
|
|
return std::string();
|
|
|
|
}
|
2013-12-18 03:32:35 +04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string parameter;
|
|
|
|
std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
|
|
|
|
pit->begin();
|
|
|
|
const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
|
|
|
|
pit->end();
|
|
|
|
for ( ; it != end; ++it)
|
|
|
|
{
|
|
|
|
parameter += (*it)->Evaluate(context, dagChecker);
|
|
|
|
if (context->HadError)
|
|
|
|
{
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parameters.push_back(parameter);
|
|
|
|
}
|
2012-09-11 21:53:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-16 17:52:25 +04:00
|
|
|
if ((numExpected > cmGeneratorExpressionNode::DynamicParameters
|
|
|
|
&& (unsigned int)numExpected != parameters.size()))
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
|
|
|
if (numExpected == 0)
|
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(),
|
|
|
|
"$<" + identifier + "> expression requires no parameters.");
|
|
|
|
}
|
|
|
|
else if (numExpected == 1)
|
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(),
|
|
|
|
"$<" + identifier + "> expression requires "
|
|
|
|
"exactly one parameter.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-05 22:31:31 +03:00
|
|
|
std::ostringstream e;
|
2012-09-11 21:53:38 +04:00
|
|
|
e << "$<" + identifier + "> expression requires "
|
|
|
|
<< numExpected
|
|
|
|
<< " comma separated parameters, but got "
|
|
|
|
<< parameters.size() << " instead.";
|
|
|
|
reportError(context, this->GetOriginalExpression(), e.str());
|
|
|
|
}
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2013-05-16 17:52:25 +04:00
|
|
|
if (numExpected == cmGeneratorExpressionNode::OneOrMoreParameters
|
|
|
|
&& parameters.empty())
|
2012-09-11 21:53:38 +04:00
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(), "$<" + identifier
|
|
|
|
+ "> expression requires at least one parameter.");
|
|
|
|
}
|
2013-12-31 17:28:52 +04:00
|
|
|
if (numExpected == cmGeneratorExpressionNode::OneOrZeroParameters
|
2013-12-31 18:57:25 +04:00
|
|
|
&& parameters.size() > 1)
|
2013-12-31 17:28:52 +04:00
|
|
|
{
|
|
|
|
reportError(context, this->GetOriginalExpression(), "$<" + identifier
|
|
|
|
+ "> expression requires one or zero parameters.");
|
|
|
|
}
|
2012-11-27 01:42:00 +04:00
|
|
|
return std::string();
|
2012-09-11 21:53:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GeneratorExpressionContent::~GeneratorExpressionContent()
|
|
|
|
{
|
2015-01-04 18:35:26 +03:00
|
|
|
cmDeleteAll(this->IdentifierChildren);
|
|
|
|
std::for_each(this->ParamChildren.begin(), this->ParamChildren.end(),
|
|
|
|
cmDeleteAll<std::vector<cmGeneratorExpressionEvaluator*> >);
|
2012-09-11 21:53:38 +04:00
|
|
|
}
|