cmCableClassSet.cxx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2001 Insight Consortium
  8. All rights reserved.
  9. Redistribution and use in source and binary forms, with or without
  10. modification, are permitted provided that the following conditions are met:
  11. * Redistributions of source code must retain the above copyright notice,
  12. this list of conditions and the following disclaimer.
  13. * Redistributions in binary form must reproduce the above copyright notice,
  14. this list of conditions and the following disclaimer in the documentation
  15. and/or other materials provided with the distribution.
  16. * The name of the Insight Consortium, nor the names of any consortium members,
  17. nor of any contributors, may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. * Modified source versions must be plainly marked as such, and must not be
  20. misrepresented as being the original software.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
  22. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
  25. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. =========================================================================*/
  32. #include "cmCableClassSet.h"
  33. /**
  34. * Add to the set of required sources to define the class.
  35. */
  36. void cmCableClass::AddSources(const Sources& sources)
  37. {
  38. for(Sources::const_iterator s = sources.begin(); s != sources.end(); ++s)
  39. {
  40. m_Sources.insert(*s);
  41. }
  42. }
  43. /**
  44. * Add to the set of required sources to define the class.
  45. */
  46. void cmCableClass::AddSource(const char* source)
  47. {
  48. m_Sources.insert(source);
  49. }
  50. /**
  51. * The destructor frees all the cmCableClass instances in the set.
  52. */
  53. cmCableClassSet::~cmCableClassSet()
  54. {
  55. for(CableClassMap::const_iterator i = m_CableClassMap.begin();
  56. i != m_CableClassMap.end(); ++i)
  57. {
  58. delete i->second;
  59. }
  60. }
  61. /**
  62. * Add a class to the set.
  63. * Automatically replace ">>" with "> >" to prevent template class name
  64. * problems after replacements.
  65. */
  66. void cmCableClassSet::AddClass(const char* in_name,
  67. cmCableClass* cableClass)
  68. {
  69. cmStdString name = in_name;
  70. for(cmStdString::size_type pos = name.find(">>");
  71. pos != cmStdString::npos; pos = name.find(">>", pos+2))
  72. {
  73. name.replace(pos, 2, "> >");
  74. }
  75. m_CableClassMap.insert(CableClassMap::value_type(name, cableClass));
  76. }
  77. /**
  78. * Add a source to every class in the set. This should only be done after
  79. * all classes have been inserted.
  80. */
  81. void cmCableClassSet::AddSource(const char* name)
  82. {
  83. for(CableClassMap::iterator c = m_CableClassMap.begin();
  84. c != m_CableClassMap.end(); ++c)
  85. {
  86. c->second->AddSource(name);
  87. }
  88. }
  89. /**
  90. * Get the size of the internal CableClassMap used to store the set.
  91. */
  92. unsigned int cmCableClassSet::Size() const
  93. {
  94. return m_CableClassMap.size();
  95. }
  96. /**
  97. * Get a begin iterator to the internal CableClassMap used to store the
  98. * set.
  99. */
  100. cmCableClassSet::CableClassMap::const_iterator cmCableClassSet::Begin() const
  101. {
  102. return m_CableClassMap.begin();
  103. }
  104. /**
  105. * Get an end iterator to the internal CableClassMap used to store the
  106. * set.
  107. */
  108. cmCableClassSet::CableClassMap::const_iterator cmCableClassSet::End() const
  109. {
  110. return m_CableClassMap.end();
  111. }
  112. /**
  113. * A utility class to generate element combinations from all possible
  114. * substitutions of set members into a $ token.
  115. */
  116. class ElementCombinationGenerator
  117. {
  118. public:
  119. ElementCombinationGenerator(const char* in_element, cmMakefile* in_makefile,
  120. cmCableClassSet* out_set):
  121. m_Makefile(in_makefile), m_OutputSet(out_set)
  122. {
  123. this->ParseInputElement(in_element);
  124. }
  125. ~ElementCombinationGenerator();
  126. void Generate();
  127. public:
  128. /**
  129. * Represent a substitution.
  130. */
  131. class Substitution
  132. {
  133. public:
  134. Substitution() {}
  135. void Bind(const cmStdString& in_code, const cmCableClass* in_class)
  136. {
  137. m_Code = in_code;
  138. m_Class = in_class;
  139. }
  140. const cmCableClass* GetClass() const
  141. { return m_Class; }
  142. const cmStdString& GetCode() const
  143. { return m_Code; }
  144. private:
  145. /**
  146. * The cmCableClass associated with this substitution.
  147. */
  148. const cmCableClass* m_Class;
  149. /**
  150. * The code to be used for the substitution.
  151. */
  152. cmStdString m_Code;
  153. };
  154. /**
  155. * Interface to the parts of an input string of code, possibly with
  156. * $SomeSetName tokens in it. An indivitual Portion will be either
  157. * a StringPortion, which has no substitutions, or a ReplacePortion,
  158. * which has only a substitution, and no hard-coded text.
  159. *
  160. * This is used by cmCableClassSet::GenerateElementCombinations() to
  161. * hold the pieces of a string after the set substitution tokens
  162. * have been extracted.
  163. */
  164. class Portion
  165. {
  166. public:
  167. /**
  168. * Get the C++ code corresponding to this Portion of a string.
  169. */
  170. virtual cmStdString GetCode() const =0;
  171. /**
  172. * Get the class corresponding to this Portion of a string. This is NULL
  173. * for StringPortion, and points to a cmCableClass for ReplacePortion.
  174. */
  175. virtual const cmCableClass* GetClass() const
  176. { return NULL; }
  177. virtual ~Portion() {}
  178. };
  179. /**
  180. * Represent a hard-coded part of an input string, that has no substitutions
  181. * in it. The tag for this part of a string is always empty.
  182. */
  183. class StringPortion: public Portion
  184. {
  185. public:
  186. StringPortion(const cmStdString& in_code): m_Code(in_code) {}
  187. virtual cmStdString GetCode() const
  188. { return m_Code; }
  189. virtual const cmCableClass* GetClass() const
  190. { return NULL; }
  191. virtual ~StringPortion() {}
  192. private:
  193. /**
  194. * Hold this Portion's contribution to the output string.
  195. */
  196. cmStdString m_Code;
  197. };
  198. /**
  199. * Represent the "$SomeSetName" portion of an input string. This has a
  200. * reference to the Substitution holding the real output to generate.
  201. */
  202. class ReplacePortion;
  203. friend class ReplacePortion;
  204. class ReplacePortion: public Portion
  205. {
  206. public:
  207. ReplacePortion(const Substitution& in_substitution):
  208. m_Substitution(in_substitution) {}
  209. virtual cmStdString GetCode() const
  210. { return m_Substitution.GetCode(); }
  211. virtual const cmCableClass* GetClass() const
  212. { return m_Substitution.GetClass(); }
  213. virtual ~ReplacePortion() {}
  214. private:
  215. /**
  216. * Refer to the real Substitution for this Portion's contribution.
  217. */
  218. const Substitution& m_Substitution;
  219. };
  220. typedef std::list<Portion*> Portions;
  221. typedef std::map<const cmCableClassSet*, Substitution*> Substitutions;
  222. /**
  223. * The makefile in which to lookup set names.
  224. */
  225. cmMakefile* m_Makefile;
  226. /**
  227. * The cmCableClassSet instance to be filled with combinations.
  228. */
  229. cmCableClassSet* m_OutputSet;
  230. /**
  231. * The class name parsed out for this element, before set expansion.
  232. */
  233. cmStdString m_ClassName;
  234. /**
  235. * The tag name parsed out or generated for this element.
  236. */
  237. cmStdString m_Tag;
  238. /**
  239. * The set of sources parsed out for this element.
  240. */
  241. cmCableClass::Sources m_Sources;
  242. /**
  243. * The parts of the input string after parsing of the tokens.
  244. */
  245. Portions m_Portions;
  246. /**
  247. * Map from substitution's Set to actual Substitution.
  248. */
  249. Substitutions m_Substitutions;
  250. private:
  251. void Generate(Substitutions::const_iterator);
  252. void ParseInputElement(const char*);
  253. void SplitClassName();
  254. cmStdString ParseSetName(cmStdString::const_iterator&,
  255. cmStdString::const_iterator) const;
  256. void FindTagSource();
  257. bool GenerateTag(const cmStdString&);
  258. };
  259. /**
  260. * Destructor frees portions and substitutions that were allocated by
  261. * constructor.
  262. */
  263. ElementCombinationGenerator
  264. ::~ElementCombinationGenerator()
  265. {
  266. // Free the string portions that were allocated.
  267. for(Portions::iterator portion = m_Portions.begin();
  268. portion != m_Portions.end(); ++portion)
  269. {
  270. delete *portion;
  271. }
  272. // Free the substitutions that were allocated.
  273. for(Substitutions::iterator sub = m_Substitutions.begin();
  274. sub != m_Substitutions.end(); ++sub)
  275. {
  276. delete sub->second;
  277. }
  278. }
  279. /**
  280. * Generate all element combinations possible with the set of
  281. * substitutions available. The given output set is filled with
  282. * all the combinations.
  283. */
  284. void
  285. ElementCombinationGenerator
  286. ::Generate()
  287. {
  288. // If there are no substitutions to be made, just generate this
  289. // single combination.
  290. if(m_Substitutions.empty())
  291. {
  292. cmCableClass* cableClass = new cmCableClass(m_Tag);
  293. cableClass->AddSources(m_Sources);
  294. m_OutputSet->AddClass(m_ClassName.c_str(), cableClass);
  295. return;
  296. }
  297. // We must generate all combinations of substitutions.
  298. // Begin the recursion with the first substitution.
  299. this->Generate(m_Substitutions.begin());
  300. }
  301. /**
  302. * Internal helper to Generate() which generates all
  303. * combinations in a recursive, depth-first order.
  304. */
  305. void
  306. ElementCombinationGenerator
  307. ::Generate(Substitutions::const_iterator substitution)
  308. {
  309. // Test our position in the list of substitutions to be bound.
  310. if(substitution == m_Substitutions.end())
  311. {
  312. // All substitutions have been prepared. Generate this combination.
  313. cmStdString tag = m_Tag;
  314. cmStdString code = "";
  315. // The set of sources for the generated combination. It will
  316. // always include the sources parsed from the original element
  317. // string.
  318. cmCableClass::Sources sources = m_Sources;
  319. // Put together all the pieces, with substitutions.
  320. for(Portions::const_iterator i = m_Portions.begin();
  321. i != Portions::const_iterator(m_Portions.end()); ++i)
  322. {
  323. // See if there is a class associated with this portion.
  324. const cmCableClass* curClassPortion = (*i)->GetClass();
  325. if(curClassPortion)
  326. {
  327. // Append the tag from the class portion.
  328. tag.append(curClassPortion->GetTag());
  329. // Include any sources needed by the class in this combination's set.
  330. for(cmCableClass::Sources::const_iterator
  331. s = curClassPortion->SourcesBegin();
  332. s != curClassPortion->SourcesEnd(); ++s)
  333. {
  334. sources.insert(*s);
  335. }
  336. }
  337. // Append the portion's code to this combination's code.
  338. code.append((*i)->GetCode());
  339. }
  340. // Add this combination to the output set.
  341. cmCableClass* cableClass = new cmCableClass(tag);
  342. cableClass->AddSources(sources);
  343. m_OutputSet->AddClass(code.c_str(), cableClass);
  344. }
  345. else
  346. {
  347. // Get the set for this substitution.
  348. const cmCableClassSet* set = substitution->first;
  349. if(set == m_OutputSet)
  350. {
  351. // We cannot iterate over the set currently being defined.
  352. cmSystemTools::Error("CABLE class set self-reference!");
  353. return;
  354. }
  355. // Prepare an iterator to the next substitution.
  356. Substitutions::const_iterator nextSubstitution = substitution;
  357. ++nextSubstitution;
  358. // We must iterate over all possible values for this substitution.
  359. for(cmCableClassSet::CableClassMap::const_iterator element = set->Begin();
  360. element != set->End(); ++element)
  361. {
  362. // Bind the substitution to this element.
  363. substitution->second->Bind(element->first, element->second);
  364. // Move on to the next substitution.
  365. this->Generate(nextSubstitution);
  366. }
  367. }
  368. }
  369. /**
  370. * Called from constructor. Parses the given string to extract the
  371. * class information specified.
  372. *
  373. * The format of the string is
  374. * [tag:]class_name[;source1;source2;...]
  375. */
  376. void
  377. ElementCombinationGenerator
  378. ::ParseInputElement(const char* in_element)
  379. {
  380. // A regular expression to match the tagged element specification.
  381. cmRegularExpression taggedElement =
  382. "^([A-Za-z_0-9]*)[ \t]*:[ \t]*([^:].*|::.*)$";
  383. // A regular expression to match the element when more source files are given.
  384. cmRegularExpression sourcesRemain("^([^;]*);(.*)$");
  385. cmStdString elementWithoutTag;
  386. cmStdString sourceString;
  387. bool tagGiven = false;
  388. // See if the element was tagged, and if so, pull off the tag.
  389. if(taggedElement.find(in_element))
  390. {
  391. // A tag was given. Use it.
  392. tagGiven = true;
  393. m_Tag = taggedElement.match(1);
  394. elementWithoutTag = taggedElement.match(2);
  395. }
  396. else
  397. {
  398. // No tag was given. We will try to generate it later.
  399. elementWithoutTag = in_element;
  400. }
  401. // Separate the class name.
  402. if(sourcesRemain.find(elementWithoutTag.c_str()))
  403. {
  404. m_ClassName = sourcesRemain.match(1);
  405. sourceString = sourcesRemain.match(2);
  406. }
  407. else
  408. {
  409. m_ClassName = elementWithoutTag;
  410. }
  411. // Find any source files specified with the ";source" syntax.
  412. while(sourcesRemain.find(sourceString.c_str()))
  413. {
  414. m_Sources.insert(sourcesRemain.match(1));
  415. sourceString = sourcesRemain.match(2);
  416. }
  417. if(sourceString != "")
  418. {
  419. m_Sources.insert(sourceString);
  420. }
  421. // If no tag was given, try to generate one.
  422. if(!tagGiven)
  423. {
  424. if(!this->GenerateTag(m_ClassName))
  425. {
  426. cmSystemTools::Error("Cannot generate tag for class name: ",
  427. m_ClassName.c_str(),
  428. "\nPlease supply one with the \"tag:..\" syntax.");
  429. }
  430. }
  431. // If there is a .h with the name of the tag, add it as a source.
  432. this->FindTagSource();
  433. // Split the class name up into portions for the combination
  434. // generation method.
  435. this->SplitClassName();
  436. }
  437. /**
  438. * Parses the class name into portions. Plain text in the string is
  439. * held by a StringPortion, and a $ token for replacement is
  440. * represented by a ReplacePortion.
  441. */
  442. void
  443. ElementCombinationGenerator
  444. ::SplitClassName()
  445. {
  446. // Break the input code into blocks alternating between literal code and
  447. // set-substitution tokens (like $SomeSetName).
  448. cmStdString currentPortion = "";
  449. for(cmStdString::const_iterator c=m_ClassName.begin();
  450. c != m_ClassName.end(); ++c)
  451. {
  452. // Look for the '$' to mark the beginning of a token.
  453. if(*c != '$')
  454. {
  455. currentPortion.insert(currentPortion.end(), *c);
  456. }
  457. else
  458. {
  459. // If there is a portion of the string, record it.
  460. if(currentPortion.length() > 0)
  461. {
  462. m_Portions.push_back(new StringPortion(currentPortion));
  463. currentPortion = "";
  464. }
  465. // Skip over the '$' character.
  466. ++c;
  467. // Get element set name token.
  468. cmStdString setName = this->ParseSetName(c, m_ClassName.end());
  469. // We have a complete set name. Look it up in makefile's data
  470. // collection.
  471. cmData* d = m_Makefile->LookupData(setName.c_str());
  472. // This should be a dynamic_cast, but we don't want to require RTTI.
  473. cmCableClassSet* set = static_cast<cmCableClassSet*>(d);
  474. if(set)
  475. {
  476. // We have a valid set name. Prepare the substitution entry
  477. // for it.
  478. Substitution* sub;
  479. if(m_Substitutions.count(set) == 0)
  480. {
  481. sub = new Substitution();
  482. m_Substitutions[set] = sub;
  483. }
  484. else
  485. {
  486. sub = m_Substitutions[set];
  487. }
  488. m_Portions.push_back(new ReplacePortion(*sub));
  489. setName = "";
  490. }
  491. else
  492. {
  493. // Invalid set name. Complain.
  494. cmSystemTools::Error("Unknown name of CABLE class set: ",
  495. setName.c_str());
  496. }
  497. // Let the loop look at this character again.
  498. --c;
  499. }
  500. }
  501. // If there is a final portion of the string, record it.
  502. if(currentPortion.length() > 0)
  503. {
  504. m_Portions.push_back(new StringPortion(currentPortion));
  505. }
  506. }
  507. /**
  508. * Parse out the name of a Set specified after a $ in the element's string.
  509. * This is called with "c" pointing to the first character after the $,
  510. * and "end" equal to the string's end iterator.
  511. *
  512. * Returns the set name after parsing. "c" will point to the first
  513. * character after the end of the set name.
  514. */
  515. cmStdString
  516. ElementCombinationGenerator
  517. ::ParseSetName(cmStdString::const_iterator& c, cmStdString::const_iterator end) const
  518. {
  519. cmStdString setName = "";
  520. // Check for the $(setName) syntax.
  521. // If the first character after the '$' is a left paren, we scan for the
  522. // matching paren, and take everything in-between as the set name.
  523. if((c != end) && (*c == '('))
  524. {
  525. unsigned int depth = 1;
  526. ++c;
  527. while(c != end)
  528. {
  529. char ch = *c++;
  530. if(ch == '(') { ++depth; }
  531. else if(ch == ')') { --depth; }
  532. if(depth == 0) { break; }
  533. setName.insert(setName.end(), ch);
  534. }
  535. return setName;
  536. }
  537. // The $(setName) syntax was not used.
  538. // Look for all characters that can be part of a qualified C++
  539. // identifier.
  540. while(c != end)
  541. {
  542. char ch = *c;
  543. if(((ch >= 'a') && (ch <= 'z'))
  544. || ((ch >= 'A') && (ch <= 'Z'))
  545. || ((ch >= '0') && (ch <= '9'))
  546. || (ch == '_') || (ch == ':'))
  547. {
  548. setName.insert(setName.end(), ch);
  549. ++c;
  550. }
  551. else
  552. {
  553. break;
  554. }
  555. }
  556. return setName;
  557. }
  558. /**
  559. * After the tag for an element has been determined, but before
  560. * combination expansion is done, this is called to search for a
  561. * header file in the makefile's include path with the name of the
  562. * tag. This makes specifying lists of classes that are declared in
  563. * header files with their own name very convenient.
  564. */
  565. void ElementCombinationGenerator::FindTagSource()
  566. {
  567. // If there is no tag, don't bother with this step.
  568. if(m_Tag == "")
  569. {
  570. return;
  571. }
  572. // Get the makefile's include path.
  573. const std::vector<std::string>& includePath =
  574. m_Makefile->GetIncludeDirectories();
  575. // Search the path for a file called "(m_Tag).h".
  576. for(std::vector<std::string>::const_iterator dir = includePath.begin();
  577. dir != includePath.end(); ++dir)
  578. {
  579. cmStdString filePath = *dir;
  580. m_Makefile->ExpandVariablesInString(filePath);
  581. filePath += "/"+m_Tag+".h";
  582. if(cmSystemTools::FileExists(filePath.c_str()))
  583. {
  584. m_Sources.insert(m_Tag+".h");
  585. return;
  586. }
  587. }
  588. }
  589. /**
  590. * Given the string representing a set element, automatically generate
  591. * the element tag for it. This function determines how the output
  592. * language of all CABLE-generated wrappers will look.
  593. */
  594. bool ElementCombinationGenerator::GenerateTag(const cmStdString& element)
  595. {
  596. // Hold the regular expressions for matching against the element.
  597. cmRegularExpression regex;
  598. // If the element's code begins in a $, it is referring to a set name.
  599. // The set's elements have their own tags, so we don't need one.
  600. regex.compile("^[ \t]*\\$");
  601. if(regex.find(element))
  602. { m_Tag = ""; return true; }
  603. // Test for simple integer
  604. regex.compile("^[ \t]*([0-9]*)[ \t]*$");
  605. if(regex.find(element))
  606. {
  607. m_Tag = "_";
  608. m_Tag.append(regex.match(1));
  609. return true;
  610. }
  611. // Test for basic integer type
  612. regex.compile("^[ \t]*(unsigned[ ]|signed[ ])?[ \t]*(char|short|int|long|long[ ]long)[ \t]*$");
  613. if(regex.find(element))
  614. {
  615. m_Tag = "_";
  616. if(regex.match(1) == "unsigned ")
  617. { m_Tag.append("u"); }
  618. if(regex.match(2) == "long long")
  619. { m_Tag.append("llong"); }
  620. else
  621. { m_Tag.append(regex.match(2)); }
  622. return true;
  623. }
  624. // Test for basic floating-point type
  625. regex.compile("^[ \t]*(long[ ])?[ \t]*(float|double)[ \t]*$");
  626. if(regex.find(element))
  627. {
  628. m_Tag = "_";
  629. if(regex.match(1) == "long ")
  630. m_Tag.append("l");
  631. m_Tag.append(regex.match(2));
  632. return true;
  633. }
  634. // Test for basic wide-character type
  635. regex.compile("^[ \t]*(wchar_t)[ \t]*$");
  636. if(regex.find(element))
  637. {
  638. m_Tag = "_wchar";
  639. return true;
  640. }
  641. // Test for type name (possibly with template arguments).
  642. regex.compile("^[ \t]*([A-Za-z_][A-Za-z0-9_]*)(<.*)?[ \t]*$");
  643. if(regex.find(element))
  644. {
  645. // The tag is the same as the type. If there were template arguments,
  646. // they are ignored since they may have their own tags.
  647. m_Tag = regex.match(1);
  648. return true;
  649. }
  650. // Test for a name with a single namespace qualifier.
  651. regex.compile("^[ \t]*([A-Za-z_][A-Za-z0-9_]*)::([A-Za-z_][A-Za-z0-9_]*)(<.*)?[ \t]*$");
  652. if(regex.find(element))
  653. {
  654. // The tag is the same as the namespace and type concatenated together.
  655. m_Tag = regex.match(1);
  656. m_Tag.append(regex.match(2));
  657. return true;
  658. }
  659. // We can't generate a tag.
  660. m_Tag = "";
  661. return false;
  662. }
  663. /**
  664. * Given an element in string form, parse out the information from it,
  665. * generate the combinations of set substitutions, and add all the
  666. * elements that result.
  667. */
  668. void cmCableClassSet::ParseAndAddElement(const char* in_element,
  669. cmMakefile* makefile)
  670. {
  671. // Create an object to handle the generation.
  672. ElementCombinationGenerator combinationGenerator(in_element, makefile, this);
  673. // Generate the combinations.
  674. combinationGenerator.Generate();
  675. }