cmGeneratorExpressionEvaluator.cxx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2012 Stephen Kelly <[email protected]>
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmMakefile.h"
  11. #include "cmGeneratorExpressionEvaluator.h"
  12. #include "cmGeneratorExpressionParser.h"
  13. #include "cmGeneratorExpressionDAGChecker.h"
  14. #include "cmGeneratorExpression.h"
  15. //----------------------------------------------------------------------------
  16. #if !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x510
  17. static
  18. #endif
  19. void reportError(cmGeneratorExpressionContext *context,
  20. const std::string &expr, const std::string &result)
  21. {
  22. context->HadError = true;
  23. if (context->Quiet)
  24. {
  25. return;
  26. }
  27. cmOStringStream e;
  28. e << "Error evaluating generator expression:\n"
  29. << " " << expr << "\n"
  30. << result;
  31. context->Makefile->GetCMakeInstance()
  32. ->IssueMessage(cmake::FATAL_ERROR, e.str().c_str(),
  33. context->Backtrace);
  34. }
  35. //----------------------------------------------------------------------------
  36. struct cmGeneratorExpressionNode
  37. {
  38. virtual ~cmGeneratorExpressionNode() {}
  39. virtual bool GeneratesContent() const { return true; }
  40. virtual bool AcceptsSingleArbitraryContentParameter() const
  41. { return false; }
  42. virtual int NumExpectedParameters() const { return 1; }
  43. virtual std::string Evaluate(const std::vector<std::string> &parameters,
  44. cmGeneratorExpressionContext *context,
  45. const GeneratorExpressionContent *content,
  46. cmGeneratorExpressionDAGChecker *dagChecker
  47. ) const = 0;
  48. };
  49. //----------------------------------------------------------------------------
  50. static const struct ZeroNode : public cmGeneratorExpressionNode
  51. {
  52. ZeroNode() {}
  53. virtual bool GeneratesContent() const { return false; }
  54. std::string Evaluate(const std::vector<std::string> &,
  55. cmGeneratorExpressionContext *,
  56. const GeneratorExpressionContent *,
  57. cmGeneratorExpressionDAGChecker *) const
  58. {
  59. // Unreachable
  60. return std::string();
  61. }
  62. } zeroNode;
  63. //----------------------------------------------------------------------------
  64. static const struct OneNode : public cmGeneratorExpressionNode
  65. {
  66. OneNode() {}
  67. virtual bool AcceptsSingleArbitraryContentParameter() const { return true; }
  68. std::string Evaluate(const std::vector<std::string> &,
  69. cmGeneratorExpressionContext *,
  70. const GeneratorExpressionContent *,
  71. cmGeneratorExpressionDAGChecker *) const
  72. {
  73. // Unreachable
  74. return std::string();
  75. }
  76. } oneNode;
  77. //----------------------------------------------------------------------------
  78. #define BOOLEAN_OP_NODE(OPNAME, OP, SUCCESS_VALUE, FAILURE_VALUE) \
  79. static const struct OP ## Node : public cmGeneratorExpressionNode \
  80. { \
  81. OP ## Node () {} \
  82. /* We let -1 carry the meaning 'at least one' */ \
  83. virtual int NumExpectedParameters() const { return -1; } \
  84. \
  85. std::string Evaluate(const std::vector<std::string> &parameters, \
  86. cmGeneratorExpressionContext *context, \
  87. const GeneratorExpressionContent *content, \
  88. cmGeneratorExpressionDAGChecker *) const \
  89. { \
  90. std::vector<std::string>::const_iterator it = parameters.begin(); \
  91. const std::vector<std::string>::const_iterator end = parameters.end(); \
  92. for ( ; it != end; ++it) \
  93. { \
  94. if (*it == #FAILURE_VALUE) \
  95. { \
  96. return #FAILURE_VALUE; \
  97. } \
  98. else if (*it != #SUCCESS_VALUE) \
  99. { \
  100. reportError(context, content->GetOriginalExpression(), \
  101. "Parameters to $<" #OP "> must resolve to either '0' or '1'."); \
  102. return std::string(); \
  103. } \
  104. } \
  105. return #SUCCESS_VALUE; \
  106. } \
  107. } OPNAME;
  108. BOOLEAN_OP_NODE(andNode, AND, 1, 0)
  109. BOOLEAN_OP_NODE(orNode, OR, 0, 1)
  110. #undef BOOLEAN_OP_NODE
  111. //----------------------------------------------------------------------------
  112. static const struct NotNode : public cmGeneratorExpressionNode
  113. {
  114. NotNode() {}
  115. std::string Evaluate(const std::vector<std::string> &parameters,
  116. cmGeneratorExpressionContext *context,
  117. const GeneratorExpressionContent *content,
  118. cmGeneratorExpressionDAGChecker *) const
  119. {
  120. if (*parameters.begin() != "0" && *parameters.begin() != "1")
  121. {
  122. reportError(context, content->GetOriginalExpression(),
  123. "$<NOT> parameter must resolve to exactly one '0' or '1' value.");
  124. return std::string();
  125. }
  126. return *parameters.begin() == "0" ? "1" : "0";
  127. }
  128. } notNode;
  129. //----------------------------------------------------------------------------
  130. static const struct BoolNode : public cmGeneratorExpressionNode
  131. {
  132. BoolNode() {}
  133. virtual int NumExpectedParameters() const { return 1; }
  134. std::string Evaluate(const std::vector<std::string> &parameters,
  135. cmGeneratorExpressionContext *,
  136. const GeneratorExpressionContent *,
  137. cmGeneratorExpressionDAGChecker *) const
  138. {
  139. return !cmSystemTools::IsOff(parameters.begin()->c_str()) ? "1" : "0";
  140. }
  141. } boolNode;
  142. //----------------------------------------------------------------------------
  143. static const struct StrEqualNode : public cmGeneratorExpressionNode
  144. {
  145. StrEqualNode() {}
  146. virtual int NumExpectedParameters() const { return 2; }
  147. std::string Evaluate(const std::vector<std::string> &parameters,
  148. cmGeneratorExpressionContext *,
  149. const GeneratorExpressionContent *,
  150. cmGeneratorExpressionDAGChecker *) const
  151. {
  152. return *parameters.begin() == parameters[1] ? "1" : "0";
  153. }
  154. } strEqualNode;
  155. //----------------------------------------------------------------------------
  156. static const struct Angle_RNode : public cmGeneratorExpressionNode
  157. {
  158. Angle_RNode() {}
  159. virtual int NumExpectedParameters() const { return 0; }
  160. std::string Evaluate(const std::vector<std::string> &,
  161. cmGeneratorExpressionContext *,
  162. const GeneratorExpressionContent *,
  163. cmGeneratorExpressionDAGChecker *) const
  164. {
  165. return ">";
  166. }
  167. } angle_rNode;
  168. //----------------------------------------------------------------------------
  169. static const struct CommaNode : public cmGeneratorExpressionNode
  170. {
  171. CommaNode() {}
  172. virtual int NumExpectedParameters() const { return 0; }
  173. std::string Evaluate(const std::vector<std::string> &,
  174. cmGeneratorExpressionContext *,
  175. const GeneratorExpressionContent *,
  176. cmGeneratorExpressionDAGChecker *) const
  177. {
  178. return ",";
  179. }
  180. } commaNode;
  181. //----------------------------------------------------------------------------
  182. static const struct ConfigurationNode : public cmGeneratorExpressionNode
  183. {
  184. ConfigurationNode() {}
  185. virtual int NumExpectedParameters() const { return 0; }
  186. std::string Evaluate(const std::vector<std::string> &,
  187. cmGeneratorExpressionContext *context,
  188. const GeneratorExpressionContent *,
  189. cmGeneratorExpressionDAGChecker *) const
  190. {
  191. return context->Config ? context->Config : "";
  192. }
  193. } configurationNode;
  194. //----------------------------------------------------------------------------
  195. static const struct ConfigurationTestNode : public cmGeneratorExpressionNode
  196. {
  197. ConfigurationTestNode() {}
  198. virtual int NumExpectedParameters() const { return 1; }
  199. std::string Evaluate(const std::vector<std::string> &parameters,
  200. cmGeneratorExpressionContext *context,
  201. const GeneratorExpressionContent *content,
  202. cmGeneratorExpressionDAGChecker *) const
  203. {
  204. cmsys::RegularExpression configValidator;
  205. configValidator.compile("^[A-Za-z0-9_]*$");
  206. if (!configValidator.find(parameters.begin()->c_str()))
  207. {
  208. reportError(context, content->GetOriginalExpression(),
  209. "Expression syntax not recognized.");
  210. return std::string();
  211. }
  212. if (!context->Config)
  213. {
  214. return parameters.front().empty() ? "1" : "0";
  215. }
  216. return *parameters.begin() == context->Config ? "1" : "0";
  217. }
  218. } configurationTestNode;
  219. //----------------------------------------------------------------------------
  220. static const struct TargetPropertyNode : public cmGeneratorExpressionNode
  221. {
  222. TargetPropertyNode() {}
  223. // This node handles errors on parameter count itself.
  224. virtual int NumExpectedParameters() const { return -1; }
  225. std::string Evaluate(const std::vector<std::string> &parameters,
  226. cmGeneratorExpressionContext *context,
  227. const GeneratorExpressionContent *content,
  228. cmGeneratorExpressionDAGChecker *dagCheckerParent
  229. ) const
  230. {
  231. if (parameters.size() != 1 && parameters.size() != 2)
  232. {
  233. reportError(context, content->GetOriginalExpression(),
  234. "$<TARGET_PROPERTY:...> expression requires one or two parameters");
  235. return std::string();
  236. }
  237. cmsys::RegularExpression targetNameValidator;
  238. // The ':' is supported to allow use with IMPORTED targets. At least
  239. // Qt 4 and 5 IMPORTED targets use ':' as the namespace delimiter.
  240. targetNameValidator.compile("^[A-Za-z0-9_.:-]+$");
  241. cmsys::RegularExpression propertyNameValidator;
  242. propertyNameValidator.compile("^[A-Za-z0-9_]+$");
  243. cmGeneratorTarget* target = context->Target;
  244. std::string propertyName = *parameters.begin();
  245. if (parameters.size() == 2)
  246. {
  247. if (parameters.begin()->empty() && parameters[1].empty())
  248. {
  249. reportError(context, content->GetOriginalExpression(),
  250. "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  251. "target name and property name.");
  252. return std::string();
  253. }
  254. if (parameters.begin()->empty())
  255. {
  256. reportError(context, content->GetOriginalExpression(),
  257. "$<TARGET_PROPERTY:tgt,prop> expression requires a non-empty "
  258. "target name.");
  259. return std::string();
  260. }
  261. std::string targetName = parameters.front();
  262. propertyName = parameters[1];
  263. if (!targetNameValidator.find(targetName.c_str()))
  264. {
  265. if (!propertyNameValidator.find(propertyName.c_str()))
  266. {
  267. ::reportError(context, content->GetOriginalExpression(),
  268. "Target name and property name not supported.");
  269. return std::string();
  270. }
  271. ::reportError(context, content->GetOriginalExpression(),
  272. "Target name not supported.");
  273. return std::string();
  274. }
  275. target = context->Makefile->FindGeneratorTargetToUse(
  276. targetName.c_str());
  277. if (!target)
  278. {
  279. cmOStringStream e;
  280. e << "Target \""
  281. << targetName
  282. << "\" not found.";
  283. reportError(context, content->GetOriginalExpression(), e.str());
  284. return std::string();
  285. }
  286. }
  287. if (propertyName.empty())
  288. {
  289. reportError(context, content->GetOriginalExpression(),
  290. "$<TARGET_PROPERTY:...> expression requires a non-empty property "
  291. "name.");
  292. return std::string();
  293. }
  294. if (!propertyNameValidator.find(propertyName.c_str()))
  295. {
  296. ::reportError(context, content->GetOriginalExpression(),
  297. "Property name not supported.");
  298. return std::string();
  299. }
  300. cmGeneratorExpressionDAGChecker dagChecker(context->Backtrace,
  301. target->GetName(),
  302. propertyName,
  303. content,
  304. dagCheckerParent);
  305. if (!dagChecker.check())
  306. {
  307. dagChecker.reportError(context, content->GetOriginalExpression());
  308. return std::string();
  309. }
  310. const char *prop = target->GetProperty(propertyName.c_str());
  311. return prop ? prop : "";
  312. }
  313. } targetPropertyNode;
  314. //----------------------------------------------------------------------------
  315. template<bool linker, bool soname>
  316. struct TargetFilesystemArtifactResultCreator
  317. {
  318. static std::string Create(cmTarget* target,
  319. cmGeneratorExpressionContext *context,
  320. const GeneratorExpressionContent *content);
  321. };
  322. //----------------------------------------------------------------------------
  323. template<>
  324. struct TargetFilesystemArtifactResultCreator<false, true>
  325. {
  326. static std::string Create(cmTarget* target,
  327. cmGeneratorExpressionContext *context,
  328. const GeneratorExpressionContent *content)
  329. {
  330. // The target soname file (.so.1).
  331. if(target->IsDLLPlatform())
  332. {
  333. ::reportError(context, content->GetOriginalExpression(),
  334. "TARGET_SONAME_FILE is not allowed "
  335. "for DLL target platforms.");
  336. return std::string();
  337. }
  338. if(target->GetType() != cmTarget::SHARED_LIBRARY)
  339. {
  340. ::reportError(context, content->GetOriginalExpression(),
  341. "TARGET_SONAME_FILE is allowed only for "
  342. "SHARED libraries.");
  343. return std::string();
  344. }
  345. std::string result = target->GetDirectory(context->Config);
  346. result += "/";
  347. result += target->GetSOName(context->Config);
  348. return result;
  349. }
  350. };
  351. //----------------------------------------------------------------------------
  352. template<>
  353. struct TargetFilesystemArtifactResultCreator<true, false>
  354. {
  355. static std::string Create(cmTarget* target,
  356. cmGeneratorExpressionContext *context,
  357. const GeneratorExpressionContent *content)
  358. {
  359. // The file used to link to the target (.so, .lib, .a).
  360. if(!target->IsLinkable())
  361. {
  362. ::reportError(context, content->GetOriginalExpression(),
  363. "TARGET_LINKER_FILE is allowed only for libraries and "
  364. "executables with ENABLE_EXPORTS.");
  365. return std::string();
  366. }
  367. return target->GetFullPath(context->Config,
  368. target->HasImportLibrary());
  369. }
  370. };
  371. //----------------------------------------------------------------------------
  372. template<>
  373. struct TargetFilesystemArtifactResultCreator<false, false>
  374. {
  375. static std::string Create(cmTarget* target,
  376. cmGeneratorExpressionContext *context,
  377. const GeneratorExpressionContent *)
  378. {
  379. return target->GetFullPath(context->Config, false, true);
  380. }
  381. };
  382. //----------------------------------------------------------------------------
  383. template<bool dirQual, bool nameQual>
  384. struct TargetFilesystemArtifactResultGetter
  385. {
  386. static std::string Get(const std::string &result);
  387. };
  388. //----------------------------------------------------------------------------
  389. template<>
  390. struct TargetFilesystemArtifactResultGetter<false, true>
  391. {
  392. static std::string Get(const std::string &result)
  393. { return cmSystemTools::GetFilenameName(result); }
  394. };
  395. //----------------------------------------------------------------------------
  396. template<>
  397. struct TargetFilesystemArtifactResultGetter<true, false>
  398. {
  399. static std::string Get(const std::string &result)
  400. { return cmSystemTools::GetFilenamePath(result); }
  401. };
  402. //----------------------------------------------------------------------------
  403. template<>
  404. struct TargetFilesystemArtifactResultGetter<false, false>
  405. {
  406. static std::string Get(const std::string &result)
  407. { return result; }
  408. };
  409. //----------------------------------------------------------------------------
  410. template<bool linker, bool soname, bool dirQual, bool nameQual>
  411. struct TargetFilesystemArtifact : public cmGeneratorExpressionNode
  412. {
  413. TargetFilesystemArtifact() {}
  414. virtual int NumExpectedParameters() const { return 1; }
  415. std::string Evaluate(const std::vector<std::string> &parameters,
  416. cmGeneratorExpressionContext *context,
  417. const GeneratorExpressionContent *content,
  418. cmGeneratorExpressionDAGChecker *) const
  419. {
  420. // Lookup the referenced target.
  421. std::string name = *parameters.begin();
  422. cmsys::RegularExpression targetValidator;
  423. // The ':' is supported to allow use with IMPORTED targets.
  424. targetValidator.compile("^[A-Za-z0-9_.:-]+$");
  425. if (!targetValidator.find(name.c_str()))
  426. {
  427. ::reportError(context, content->GetOriginalExpression(),
  428. "Expression syntax not recognized.");
  429. return std::string();
  430. }
  431. cmTarget* target = context->Makefile->FindTargetToUse(name.c_str());
  432. if(!target)
  433. {
  434. ::reportError(context, content->GetOriginalExpression(),
  435. "No target \"" + name + "\"");
  436. return std::string();
  437. }
  438. if(target->GetType() >= cmTarget::UTILITY &&
  439. target->GetType() != cmTarget::UNKNOWN_LIBRARY)
  440. {
  441. ::reportError(context, content->GetOriginalExpression(),
  442. "Target \"" + name + "\" is not an executable or library.");
  443. return std::string();
  444. }
  445. context->Targets.insert(target);
  446. std::string result =
  447. TargetFilesystemArtifactResultCreator<linker, soname>::Create(
  448. target,
  449. context,
  450. content);
  451. if (context->HadError)
  452. {
  453. return std::string();
  454. }
  455. return
  456. TargetFilesystemArtifactResultGetter<dirQual, nameQual>::Get(result);
  457. }
  458. };
  459. //----------------------------------------------------------------------------
  460. static const
  461. TargetFilesystemArtifact<false, false, false, false> targetFileNode;
  462. static const
  463. TargetFilesystemArtifact<true, false, false, false> targetLinkerFileNode;
  464. static const
  465. TargetFilesystemArtifact<false, true, false, false> targetSoNameFileNode;
  466. static const
  467. TargetFilesystemArtifact<false, false, false, true> targetFileNameNode;
  468. static const
  469. TargetFilesystemArtifact<true, false, false, true> targetLinkerFileNameNode;
  470. static const
  471. TargetFilesystemArtifact<false, true, false, true> targetSoNameFileNameNode;
  472. static const
  473. TargetFilesystemArtifact<false, false, true, false> targetFileDirNode;
  474. static const
  475. TargetFilesystemArtifact<true, false, true, false> targetLinkerFileDirNode;
  476. static const
  477. TargetFilesystemArtifact<false, true, true, false> targetSoNameFileDirNode;
  478. //----------------------------------------------------------------------------
  479. static const
  480. cmGeneratorExpressionNode* GetNode(const std::string &identifier)
  481. {
  482. if (identifier == "0")
  483. return &zeroNode;
  484. if (identifier == "1")
  485. return &oneNode;
  486. if (identifier == "AND")
  487. return &andNode;
  488. if (identifier == "OR")
  489. return &orNode;
  490. if (identifier == "NOT")
  491. return &notNode;
  492. else if (identifier == "CONFIGURATION")
  493. return &configurationNode;
  494. else if (identifier == "CONFIG")
  495. return &configurationTestNode;
  496. else if (identifier == "TARGET_FILE")
  497. return &targetFileNode;
  498. else if (identifier == "TARGET_LINKER_FILE")
  499. return &targetLinkerFileNode;
  500. else if (identifier == "TARGET_SONAME_FILE")
  501. return &targetSoNameFileNode;
  502. else if (identifier == "TARGET_FILE_NAME")
  503. return &targetFileNameNode;
  504. else if (identifier == "TARGET_LINKER_FILE_NAME")
  505. return &targetLinkerFileNameNode;
  506. else if (identifier == "TARGET_SONAME_FILE_NAME")
  507. return &targetSoNameFileNameNode;
  508. else if (identifier == "TARGET_FILE_DIR")
  509. return &targetFileDirNode;
  510. else if (identifier == "TARGET_LINKER_FILE_DIR")
  511. return &targetLinkerFileDirNode;
  512. else if (identifier == "TARGET_SONAME_FILE_DIR")
  513. return &targetSoNameFileDirNode;
  514. else if (identifier == "STREQUAL")
  515. return &strEqualNode;
  516. else if (identifier == "BOOL")
  517. return &boolNode;
  518. else if (identifier == "ANGLE-R")
  519. return &angle_rNode;
  520. else if (identifier == "COMMA")
  521. return &commaNode;
  522. else if (identifier == "TARGET_PROPERTY")
  523. return &targetPropertyNode;
  524. return 0;
  525. }
  526. //----------------------------------------------------------------------------
  527. GeneratorExpressionContent::GeneratorExpressionContent(
  528. const char *startContent,
  529. unsigned int length)
  530. : StartContent(startContent), ContentLength(length)
  531. {
  532. }
  533. //----------------------------------------------------------------------------
  534. std::string GeneratorExpressionContent::GetOriginalExpression() const
  535. {
  536. return std::string(this->StartContent, this->ContentLength);
  537. }
  538. //----------------------------------------------------------------------------
  539. std::string GeneratorExpressionContent::Evaluate(
  540. cmGeneratorExpressionContext *context,
  541. cmGeneratorExpressionDAGChecker *dagChecker) const
  542. {
  543. std::string identifier;
  544. {
  545. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  546. = this->IdentifierChildren.begin();
  547. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  548. = this->IdentifierChildren.end();
  549. for ( ; it != end; ++it)
  550. {
  551. identifier += (*it)->Evaluate(context, dagChecker);
  552. if (context->HadError)
  553. {
  554. return std::string();
  555. }
  556. }
  557. }
  558. const cmGeneratorExpressionNode *node = GetNode(identifier);
  559. if (!node)
  560. {
  561. reportError(context, this->GetOriginalExpression(),
  562. "Expression did not evaluate to a known generator expression");
  563. return std::string();
  564. }
  565. if (!node->GeneratesContent())
  566. {
  567. return std::string();
  568. }
  569. if (node->AcceptsSingleArbitraryContentParameter())
  570. {
  571. std::string result;
  572. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  573. pit = this->ParamChildren.begin();
  574. const
  575. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  576. pend = this->ParamChildren.end();
  577. for ( ; pit != pend; ++pit)
  578. {
  579. if (!result.empty())
  580. {
  581. result += ",";
  582. }
  583. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  584. = pit->begin();
  585. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  586. = pit->end();
  587. for ( ; it != end; ++it)
  588. {
  589. result += (*it)->Evaluate(context, dagChecker);
  590. if (context->HadError)
  591. {
  592. return std::string();
  593. }
  594. }
  595. }
  596. return result;
  597. }
  598. std::vector<std::string> parameters;
  599. {
  600. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  601. pit = this->ParamChildren.begin();
  602. const
  603. std::vector<std::vector<cmGeneratorExpressionEvaluator*> >::const_iterator
  604. pend = this->ParamChildren.end();
  605. for ( ; pit != pend; ++pit)
  606. {
  607. std::string parameter;
  608. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it =
  609. pit->begin();
  610. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end =
  611. pit->end();
  612. for ( ; it != end; ++it)
  613. {
  614. parameter += (*it)->Evaluate(context, dagChecker);
  615. if (context->HadError)
  616. {
  617. return std::string();
  618. }
  619. }
  620. parameters.push_back(parameter);
  621. }
  622. }
  623. int numExpected = node->NumExpectedParameters();
  624. if ((numExpected != -1 && (unsigned int)numExpected != parameters.size()))
  625. {
  626. if (numExpected == 0)
  627. {
  628. reportError(context, this->GetOriginalExpression(),
  629. "$<" + identifier + "> expression requires no parameters.");
  630. }
  631. else if (numExpected == 1)
  632. {
  633. reportError(context, this->GetOriginalExpression(),
  634. "$<" + identifier + "> expression requires "
  635. "exactly one parameter.");
  636. }
  637. else
  638. {
  639. cmOStringStream e;
  640. e << "$<" + identifier + "> expression requires "
  641. << numExpected
  642. << " comma separated parameters, but got "
  643. << parameters.size() << " instead.";
  644. reportError(context, this->GetOriginalExpression(), e.str());
  645. }
  646. return std::string();
  647. }
  648. if (numExpected == -1 && parameters.empty())
  649. {
  650. reportError(context, this->GetOriginalExpression(), "$<" + identifier
  651. + "> expression requires at least one parameter.");
  652. return std::string();
  653. }
  654. return node->Evaluate(parameters, context, this, dagChecker);
  655. }
  656. //----------------------------------------------------------------------------
  657. static void deleteAll(const std::vector<cmGeneratorExpressionEvaluator*> &c)
  658. {
  659. std::vector<cmGeneratorExpressionEvaluator*>::const_iterator it
  660. = c.begin();
  661. const std::vector<cmGeneratorExpressionEvaluator*>::const_iterator end
  662. = c.end();
  663. for ( ; it != end; ++it)
  664. {
  665. delete *it;
  666. }
  667. }
  668. //----------------------------------------------------------------------------
  669. GeneratorExpressionContent::~GeneratorExpressionContent()
  670. {
  671. deleteAll(this->IdentifierChildren);
  672. typedef std::vector<cmGeneratorExpressionEvaluator*> EvaluatorVector;
  673. typedef std::vector<cmGeneratorExpressionToken> TokenVector;
  674. std::vector<EvaluatorVector>::const_iterator pit =
  675. this->ParamChildren.begin();
  676. const std::vector<EvaluatorVector>::const_iterator pend =
  677. this->ParamChildren.end();
  678. for ( ; pit != pend; ++pit)
  679. {
  680. deleteAll(*pit);
  681. }
  682. }