PageRenderTime 33ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/buildtools/managers/cmake/parser/cmakeast.cpp

https://github.com/robertknight/kdevelop
C++ | 3631 lines | 3062 code | 523 blank | 46 comment | 781 complexity | b849596bee148b54274cf59292c15246 MD5 | raw file
Possible License(s): GPL-2.0, CC-BY-SA-3.0, LGPL-2.1
  1. /* KDevelop CMake Support
  2. *
  3. * Copyright 2006 Matt Rogers <mattr@kde.org>
  4. * Copyright 2007 Aleix Pol <aleixpol@gmail.com>
  5. *
  6. * Some parts of this code are based on CMake
  7. * Copyright 2002 Kitware, Inc. Insight Consortium <kitware@kitware.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301, USA.
  23. */
  24. #include "cmakeast.h"
  25. #include <QRegExp>
  26. #include <QString>
  27. #include <KDebug>
  28. #include "astfactory.h"
  29. #include "cmakelistsparser.h"
  30. CMAKE_REGISTER_AST( AddDefinitionsAst, add_definitions )
  31. CMAKE_REGISTER_AST( AddDependenciesAst, add_dependencies )
  32. CMAKE_REGISTER_AST( AddExecutableAst, add_executable )
  33. CMAKE_REGISTER_AST( AddLibraryAst, add_library )
  34. CMAKE_REGISTER_AST( AddSubdirectoryAst, add_subdirectory )
  35. CMAKE_REGISTER_AST( AddTestAst, add_test )
  36. CMAKE_REGISTER_AST( AuxSourceDirectoryAst, aux_source_directory )
  37. CMAKE_REGISTER_AST( BreakAst, break)
  38. CMAKE_REGISTER_AST( BuildCommandAst, build_command )
  39. CMAKE_REGISTER_AST( BuildNameAst, build_name )
  40. CMAKE_REGISTER_AST( CMakeMinimumRequiredAst, cmake_minimum_required )
  41. CMAKE_REGISTER_AST( CMakePolicyAst, cmake_policy)
  42. CMAKE_REGISTER_AST( ConfigureFileAst, configure_file )
  43. CMAKE_REGISTER_AST( CreateTestSourcelistAst, create_test_sourcelist )
  44. CMAKE_REGISTER_AST( CustomCommandAst, add_custom_command )
  45. CMAKE_REGISTER_AST( CustomTargetAst, add_custom_target )
  46. CMAKE_REGISTER_AST( EnableLanguageAst, enable_language )
  47. CMAKE_REGISTER_AST( EnableTestingAst, enable_testing )
  48. CMAKE_REGISTER_AST( ExecProgramAst, exec_program )
  49. CMAKE_REGISTER_AST( ExecuteProcessAst, execute_process )
  50. CMAKE_REGISTER_AST( ExportAst, export)
  51. CMAKE_REGISTER_AST( ExportLibraryDepsAst, export_library_dependencies)
  52. CMAKE_REGISTER_AST( FileAst, file )
  53. CMAKE_REGISTER_AST( FindFileAst, find_file )
  54. CMAKE_REGISTER_AST( FindLibraryAst, find_library )
  55. CMAKE_REGISTER_AST( FindPackageAst, find_package )
  56. CMAKE_REGISTER_AST( FindPathAst, find_path )
  57. CMAKE_REGISTER_AST( FindProgramAst, find_program )
  58. CMAKE_REGISTER_AST( ForeachAst, foreach )
  59. CMAKE_REGISTER_AST( GetCMakePropertyAst, get_cmake_property )
  60. CMAKE_REGISTER_AST( GetDirPropertyAst, get_directory_property )
  61. CMAKE_REGISTER_AST( GetSourceFilePropAst, get_source_file_property )
  62. CMAKE_REGISTER_AST( GetTargetPropAst, get_target_property )
  63. CMAKE_REGISTER_AST( GetTestPropAst, get_test_property )
  64. CMAKE_REGISTER_AST( GetFilenameComponentAst, get_filename_component )
  65. CMAKE_REGISTER_AST( IfAst, if )
  66. CMAKE_REGISTER_AST( IncludeAst, include )
  67. CMAKE_REGISTER_AST( IncludeDirectoriesAst, include_directories )
  68. CMAKE_REGISTER_AST( IncludeRegularExpressionAst, include_regular_expression )
  69. CMAKE_REGISTER_AST( InstallFilesAst, install_files )
  70. CMAKE_REGISTER_AST( InstallProgramsAst, install_programs )
  71. CMAKE_REGISTER_AST( InstallTargetsAst, install_targets )
  72. CMAKE_REGISTER_AST( LinkDirectoriesAst, link_directories )
  73. CMAKE_REGISTER_AST( LinkLibrariesAst, link_libraries )
  74. CMAKE_REGISTER_AST( ListAst, list )
  75. CMAKE_REGISTER_AST( LoadCacheAst, load_cache )
  76. CMAKE_REGISTER_AST( LoadCommandAst, load_command )
  77. CMAKE_REGISTER_AST( MacroAst, macro )
  78. CMAKE_REGISTER_AST( MarkAsAdvancedAst, mark_as_advanced )
  79. CMAKE_REGISTER_AST( MakeDirectoryAst, make_directory )
  80. CMAKE_REGISTER_AST( MathAst, math )
  81. CMAKE_REGISTER_AST( MessageAst, message )
  82. CMAKE_REGISTER_AST( OptionAst, option )
  83. CMAKE_REGISTER_AST( OutputRequiredFilesAst, output_required_files )
  84. CMAKE_REGISTER_AST( ProjectAst, project )
  85. CMAKE_REGISTER_AST( RemoveAst, remove )
  86. CMAKE_REGISTER_AST( ReturnAst, return )
  87. CMAKE_REGISTER_AST( RemoveDefinitionsAst, remove_definitions )
  88. CMAKE_REGISTER_AST( SetAst, set )
  89. CMAKE_REGISTER_AST( SetDirectoryPropsAst, set_directory_properties )
  90. CMAKE_REGISTER_AST( SetSourceFilesPropsAst, set_source_files_properties )
  91. CMAKE_REGISTER_AST( SetTargetPropsAst, set_target_properties )
  92. CMAKE_REGISTER_AST( SetTestsPropsAst, set_tests_properties )
  93. CMAKE_REGISTER_AST( SourceGroupAst, source_group )
  94. CMAKE_REGISTER_AST( SeparateArgumentsAst, separate_arguments )
  95. CMAKE_REGISTER_AST( SiteNameAst, site_name )
  96. CMAKE_REGISTER_AST( StringAst, string )
  97. CMAKE_REGISTER_AST( SubdirsAst, subdirs )
  98. CMAKE_REGISTER_AST( SubdirDependsAst, subdir_depends )
  99. CMAKE_REGISTER_AST( TargetLinkLibrariesAst, target_link_libraries)
  100. CMAKE_REGISTER_AST( TryCompileAst, try_compile )
  101. CMAKE_REGISTER_AST( TryRunAst, try_run )
  102. CMAKE_REGISTER_AST( UseMangledMesaAst, use_mangled_mesa )
  103. CMAKE_REGISTER_AST( UtilitySourceAst, utility_source )
  104. CMAKE_REGISTER_AST( VariableRequiresAst, variable_requires )
  105. CMAKE_REGISTER_AST( WhileAst, while)
  106. CMAKE_REGISTER_AST( WriteFileAst, write_file)
  107. void CMakeAst::writeBack(QString& ) const
  108. {
  109. }
  110. enum Stage {NAMES, PATHS, PATH_SUFFIXES};
  111. CustomCommandAst::CustomCommandAst()
  112. {
  113. m_forTarget = false;
  114. m_buildStage = PostBuild;
  115. m_isVerbatim = false;
  116. m_append = false;
  117. }
  118. CustomCommandAst::~CustomCommandAst()
  119. {
  120. }
  121. void CustomCommandAst::writeBack( QString& /*buffer */ ) const
  122. {
  123. }
  124. bool CustomCommandAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  125. {
  126. if ( func.name.toLower() != QLatin1String( "add_custom_command" ) )
  127. return false;
  128. if (func.arguments.size() < 4)
  129. return false;
  130. enum tdoing {
  131. doing_source,
  132. doing_command,
  133. doing_target,
  134. doing_depends,
  135. doing_main_dependency,
  136. doing_output,
  137. doing_outputs,
  138. doing_comment,
  139. doing_working_directory,
  140. doing_nothing
  141. };
  142. tdoing doing = doing_nothing;
  143. QString currentLine;
  144. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  145. for ( it = func.arguments.begin(); it != itEnd; ++it)
  146. {
  147. QString copy = it->value;
  148. if(copy == "SOURCE")
  149. doing = doing_source;
  150. else if(copy == "COMMAND")
  151. {
  152. doing = doing_command;
  153. // Save the current command before starting the next command.
  154. if ( !currentLine.isEmpty() )
  155. {
  156. m_commands.append( currentLine );
  157. currentLine.clear();
  158. }
  159. }
  160. else if(copy == "PRE_BUILD")
  161. m_buildStage = PreBuild;
  162. else if(copy == "PRE_LINK")
  163. m_buildStage = PreLink;
  164. else if(copy == "POST_BUILD")
  165. m_buildStage = PostBuild;
  166. else if(copy == "VERBATIM")
  167. m_isVerbatim = true;
  168. else if(copy == "APPEND")
  169. m_append = true;
  170. else if(copy == "TARGET")
  171. doing = doing_target;
  172. else if(copy == "ARGS")
  173. // Ignore this old keyword.
  174. ;
  175. else if (copy == "DEPENDS")
  176. doing = doing_depends;
  177. else if (copy == "OUTPUTS")
  178. doing = doing_outputs;
  179. else if (copy == "OUTPUT")
  180. doing = doing_output;
  181. else if (copy == "WORKING_DIRECTORY")
  182. doing = doing_working_directory;
  183. else if (copy == "MAIN_DEPENDENCY")
  184. doing = doing_main_dependency;
  185. else if (copy == "COMMENT")
  186. doing = doing_comment;
  187. else
  188. {
  189. switch (doing)
  190. {
  191. case doing_working_directory:
  192. m_workingDir = copy;
  193. break;
  194. case doing_source:
  195. m_source = copy;
  196. break;
  197. case doing_main_dependency:
  198. m_mainDep = copy;
  199. break;
  200. case doing_command:
  201. m_commands.append( copy );
  202. break;
  203. case doing_target:
  204. m_target = copy;
  205. break;
  206. case doing_depends:
  207. m_otherDeps.append( copy );
  208. break;
  209. case doing_outputs:
  210. case doing_output:
  211. m_outputs.append(copy);
  212. break;
  213. case doing_comment:
  214. m_comment = copy;
  215. break;
  216. default:
  217. return false;
  218. }
  219. }
  220. }
  221. // Store the last command line finished.
  222. if ( !currentLine.isEmpty() )
  223. {
  224. m_commands.append( currentLine );
  225. currentLine.clear();
  226. }
  227. // At this point we could complain about the lack of arguments. For
  228. // the moment, let's say that COMMAND, TARGET are always required.
  229. if ( m_outputs.isEmpty() && m_target.isEmpty() )
  230. return false;
  231. if ( m_source.isEmpty() && !m_target.isEmpty() && !m_outputs.isEmpty())
  232. return false;
  233. if ( m_append && m_outputs.isEmpty() )
  234. return false;
  235. return true;
  236. }
  237. CustomTargetAst::CustomTargetAst()
  238. {
  239. m_buildAlways = false;
  240. m_isVerbatim = false;
  241. }
  242. CustomTargetAst::~CustomTargetAst()
  243. {
  244. }
  245. void CustomTargetAst::writeBack( QString& ) const
  246. {
  247. }
  248. bool CustomTargetAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  249. {
  250. if ( func.name.toLower() != QLatin1String( "add_custom_target" ) )
  251. return false;
  252. //make sure we have at least one argument
  253. if ( func.arguments.size() < 1 )
  254. return false;
  255. //check and make sure the target name isn't something silly
  256. CMakeFunctionArgument arg = func.arguments.front();
  257. if ( arg.value.toLower() == QLatin1String( "all" ) )
  258. return false;
  259. else
  260. m_target = arg.value;
  261. //check if we're part of the special "all" target
  262. if(func.arguments.count()>1)
  263. {
  264. CMakeFunctionArgument arg2 = func.arguments[1];
  265. if ( arg2.value.toUpper() == QLatin1String( "ALL" ) )
  266. m_buildAlways = true;
  267. else
  268. m_buildAlways = false;
  269. }
  270. //what are we doing?
  271. enum Action {
  272. ParsingCommand,
  273. ParsingDep,
  274. ParsingWorkingDir,
  275. ParsingComment,
  276. ParsingVerbatim
  277. };
  278. //command should be first
  279. QString currentLine;
  280. Action act = ParsingCommand;
  281. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  282. it = func.arguments.begin();
  283. if(m_buildAlways)
  284. it+=2;
  285. else
  286. ++it;
  287. QString currCmd;
  288. for ( ; it != itEnd; ++it )
  289. {
  290. QString arg = it->value;
  291. if ( arg == "DEPENDS" )
  292. act = ParsingDep;
  293. else if ( arg == "WORKING_DIRECTORY" )
  294. act = ParsingWorkingDir;
  295. else if ( arg == "VERBATIM" )
  296. {
  297. m_isVerbatim = true;
  298. act = ParsingVerbatim;
  299. }
  300. else if ( arg == "COMMENT" )
  301. act = ParsingComment;
  302. else if ( arg == "COMMAND" )
  303. {
  304. currCmd.clear();
  305. act = ParsingCommand;
  306. }
  307. else
  308. {
  309. switch( act )
  310. {
  311. case ParsingCommand:
  312. if(m_commandArgs.contains(currCmd))
  313. m_commandArgs[currCmd].append(arg);
  314. else
  315. {
  316. currCmd=arg;
  317. m_commandArgs.insert(arg, QStringList());
  318. }
  319. break;
  320. case ParsingDep:
  321. m_dependencies.append( arg );
  322. break;
  323. case ParsingWorkingDir:
  324. m_workingDir = arg;
  325. break;
  326. case ParsingComment:
  327. m_comment += arg;
  328. break;
  329. default:
  330. return false;
  331. }
  332. }
  333. }
  334. //check for bogus characters in the target name
  335. if ( m_target.indexOf( QRegExp( "(#|<|>)" ) ) != -1 )
  336. return false;
  337. return true;
  338. }
  339. /* Add Definitions AST */
  340. AddDefinitionsAst::AddDefinitionsAst()
  341. {
  342. }
  343. AddDefinitionsAst::~AddDefinitionsAst()
  344. {
  345. }
  346. void AddDefinitionsAst::writeBack( QString& ) const
  347. {
  348. }
  349. bool AddDefinitionsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  350. {
  351. if ( func.name.toLower() != "add_definitions" )
  352. return false;
  353. if ( func.arguments.isEmpty() )
  354. return false;
  355. foreach( CMakeFunctionArgument arg, func.arguments )
  356. {
  357. m_definitions << arg.value;
  358. }
  359. return true;
  360. }
  361. /* Add Dependencies AST */
  362. AddDependenciesAst::AddDependenciesAst()
  363. {
  364. }
  365. AddDependenciesAst::~AddDependenciesAst()
  366. {
  367. }
  368. void AddDependenciesAst::writeBack( QString& ) const
  369. {
  370. }
  371. bool AddDependenciesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  372. {
  373. if ( func.name.toLower() != "add_dependencies" )
  374. return false;
  375. if ( func.arguments.size() < 2 )
  376. return false;
  377. QList<CMakeFunctionArgument> args = func.arguments;
  378. m_target = args.front().value;
  379. QList<CMakeFunctionArgument>::const_iterator it, itEnd = args.end();
  380. it = args.begin() + 1; //skip the first argument since it's the target
  381. for ( ; it != itEnd; ++it )
  382. {
  383. m_dependencies << it->value;
  384. }
  385. return true;
  386. }
  387. AddExecutableAst::AddExecutableAst()
  388. {
  389. m_isWin32 = false;
  390. m_isOsXBundle = false;
  391. m_excludeFromAll = false;
  392. }
  393. AddExecutableAst::~AddExecutableAst()
  394. {
  395. }
  396. void AddExecutableAst::writeBack( QString& ) const
  397. {
  398. }
  399. bool AddExecutableAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  400. {
  401. if ( func.name.toLower() != "add_executable" )
  402. return false;
  403. if ( func.arguments.size() < 2 )
  404. return false;
  405. QList<CMakeFunctionArgument> args = func.arguments;
  406. QList<CMakeFunctionArgument>::const_iterator it, itEnd = args.end();
  407. it = args.begin();
  408. m_executable = it->value;
  409. ++it;
  410. for ( ; it != itEnd; ++it )
  411. {
  412. if ( it->value == "WIN32" )
  413. m_isWin32 = true;
  414. else if ( it->value == "MACOSX_BUNDLE" )
  415. m_isOsXBundle = true;
  416. else if ( it->value == "EXCLUDE_FROM_ALL" )
  417. m_excludeFromAll = true;
  418. else
  419. m_sourceLists.append( it->value );
  420. }
  421. if ( m_sourceLists.isEmpty() )
  422. return false;
  423. return true;
  424. }
  425. AddLibraryAst::AddLibraryAst()
  426. {
  427. m_isShared = false;
  428. m_isStatic = true;
  429. m_isModule = false;
  430. m_excludeFromAll = false;
  431. }
  432. AddLibraryAst::~AddLibraryAst()
  433. {
  434. }
  435. void AddLibraryAst::writeBack( QString& ) const
  436. {
  437. }
  438. bool AddLibraryAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  439. {
  440. if ( func.name.toLower() != "add_library" )
  441. return false;
  442. if ( func.arguments.size() < 1 )
  443. return false;
  444. bool libTypeSet = false;
  445. QList<CMakeFunctionArgument> args = func.arguments;
  446. QList<CMakeFunctionArgument>::const_iterator it, itEnd = args.end();
  447. it = args.begin();
  448. m_libraryName = it->value;
  449. ++it;
  450. while ( it != itEnd )
  451. {
  452. if ( it->value == "STATIC" && !libTypeSet )
  453. {
  454. m_isStatic = true;
  455. libTypeSet = true;
  456. ++it;
  457. }
  458. else if ( it->value == "SHARED" && !libTypeSet )
  459. {
  460. m_isShared = true;
  461. libTypeSet = true;
  462. ++it;
  463. }
  464. else if ( it->value == "MODULE" && !libTypeSet )
  465. {
  466. m_isModule = true;
  467. libTypeSet = true;
  468. ++it;
  469. }
  470. else if ( it->value == "EXCLUDE_FROM_ALL" )
  471. {
  472. m_excludeFromAll = true;
  473. ++it;
  474. }
  475. else
  476. break;
  477. }
  478. if ( it == itEnd )
  479. return false; //there are no sources
  480. while ( it != itEnd )
  481. {
  482. m_sourceLists.append( it->value );
  483. ++it;
  484. }
  485. if ( m_sourceLists.isEmpty() )
  486. return false;
  487. return true;
  488. }
  489. AddSubdirectoryAst::AddSubdirectoryAst()
  490. {
  491. }
  492. AddSubdirectoryAst::~AddSubdirectoryAst()
  493. {
  494. }
  495. void AddSubdirectoryAst::writeBack( QString& ) const
  496. {
  497. }
  498. bool AddSubdirectoryAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  499. {
  500. if ( func.name.toLower() != "add_subdirectory" )
  501. return false;
  502. if ( func.arguments.size() < 1 )
  503. return false;
  504. m_sourceDir = func.arguments[0].value;
  505. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  506. it = ++func.arguments.begin();
  507. for ( ; it != itEnd; ++it )
  508. {
  509. if ( it->value == "EXCLUDE_FROM_ALL" )
  510. m_excludeFromAll = true;
  511. else if ( m_binaryDir.isEmpty() )
  512. m_binaryDir = it->value;
  513. else
  514. return false; //invalid num of args
  515. }
  516. return true;
  517. }
  518. AddTestAst::AddTestAst()
  519. {
  520. }
  521. AddTestAst::~AddTestAst()
  522. {
  523. }
  524. void AddTestAst::writeBack( QString& ) const
  525. {
  526. }
  527. bool AddTestAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  528. {
  529. if ( func.name.toLower() != "add_test" )
  530. return false;
  531. if ( func.arguments.size() < 2 )
  532. return false;
  533. m_testName = func.arguments[0].value;
  534. m_exeName = func.arguments[1].value;
  535. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  536. it = func.arguments.begin() + 2;
  537. for ( ; it != itEnd; ++it )
  538. m_testArgs << it->value;
  539. return true;
  540. }
  541. AuxSourceDirectoryAst::AuxSourceDirectoryAst()
  542. {
  543. }
  544. AuxSourceDirectoryAst::~AuxSourceDirectoryAst()
  545. {
  546. }
  547. void AuxSourceDirectoryAst::writeBack( QString& ) const
  548. {
  549. }
  550. bool AuxSourceDirectoryAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  551. {
  552. if ( func.name.toLower() != "aux_source_directory" )
  553. return false;
  554. if ( func.arguments.size() != 2 )
  555. return false;
  556. m_dirName = func.arguments[0].value;
  557. m_variableName = func.arguments[1].value;
  558. return true;
  559. }
  560. BuildCommandAst::BuildCommandAst()
  561. {
  562. }
  563. BuildCommandAst::~BuildCommandAst()
  564. {
  565. }
  566. void BuildCommandAst::writeBack( QString& ) const
  567. {
  568. }
  569. bool BuildCommandAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  570. {
  571. if ( func.name.toLower() != "build_command" )
  572. return false;
  573. if ( func.arguments.size() < 2 )
  574. return false;
  575. m_variableName = func.arguments[0].value;
  576. m_makeCommand = func.arguments[1].value;
  577. return true;
  578. }
  579. BuildNameAst::BuildNameAst()
  580. {
  581. }
  582. BuildNameAst::~BuildNameAst()
  583. {
  584. }
  585. void BuildNameAst::writeBack( QString& ) const
  586. {
  587. }
  588. bool BuildNameAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  589. {
  590. if ( func.name.toLower() != "build_name" )
  591. return false;
  592. if ( func.arguments.size() != 1 )
  593. return false;
  594. m_buildName = func.arguments[0].value;
  595. return true;
  596. }
  597. CMakeMinimumRequiredAst::CMakeMinimumRequiredAst()
  598. {
  599. }
  600. CMakeMinimumRequiredAst::~CMakeMinimumRequiredAst()
  601. {
  602. }
  603. void CMakeMinimumRequiredAst::writeBack( QString& ) const
  604. {
  605. }
  606. bool CMakeMinimumRequiredAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  607. {
  608. if ( func.name.toLower() != "cmake_minimum_required" )
  609. return false;
  610. if ( (func.arguments.size() < 2 && func.arguments.count()>3) || func.arguments.first().value.toUpper()!="VERSION")
  611. return false;
  612. QRegExp rx("([0-9]*).([0-9]*).?([0-9]*)");
  613. rx.indexIn(func.arguments[1].value);
  614. QStringList caps=rx.capturedTexts();
  615. caps.erase(caps.begin());
  616. foreach(QString s, caps)
  617. {
  618. bool correct;
  619. m_version.append(s.toInt(&correct));
  620. if(!correct)
  621. return false;
  622. }
  623. if(func.arguments.count()==3)
  624. {
  625. if(func.arguments[2].value.toUpper()=="FATAL_ERROR")
  626. m_wrongVersionIsFatal = true;
  627. else
  628. return false;
  629. }
  630. return true;
  631. }
  632. ConfigureFileAst::ConfigureFileAst()
  633. {
  634. }
  635. ConfigureFileAst::~ConfigureFileAst()
  636. {
  637. }
  638. void ConfigureFileAst::writeBack( QString& ) const
  639. {
  640. }
  641. bool ConfigureFileAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  642. {
  643. if ( func.name.toLower() != "configure_file" )
  644. return false;
  645. if ( func.arguments.size() < 2 )
  646. return false;
  647. m_inputFile = func.arguments[0].value;
  648. m_outputFile = func.arguments[1].value;
  649. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  650. it = func.arguments.begin() + 2;
  651. for ( ; it != itEnd; ++it )
  652. {
  653. CMakeFunctionArgument arg = ( *it );
  654. if ( arg.value == "COPYONLY" )
  655. m_copyOnly = true;
  656. else if ( arg.value == "ESCAPE_QUOTES" )
  657. m_escapeQuotes = true;
  658. else if ( arg.value == "@ONLY" )
  659. m_atsOnly = true;
  660. else if ( arg.value == "IMMEDIATE" )
  661. m_immediate = true;
  662. }
  663. return true;
  664. }
  665. CreateTestSourcelistAst::CreateTestSourcelistAst()
  666. {
  667. }
  668. CreateTestSourcelistAst::~CreateTestSourcelistAst()
  669. {
  670. }
  671. void CreateTestSourcelistAst::writeBack( QString& ) const
  672. {
  673. }
  674. bool CreateTestSourcelistAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  675. {
  676. if ( func.name.toLower() != "create_test_sourcelist" )
  677. return false;
  678. if ( func.arguments.count() < 3 )
  679. return false;
  680. m_name=func.arguments[0].value;
  681. m_driverName=func.arguments[1].value;
  682. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.constEnd();
  683. it = func.arguments.begin() + 2;
  684. enum State { Tests, ExtraInclude, Function};
  685. State s=Tests;
  686. for(; it!=itEnd; ++it)
  687. {
  688. if(it->value=="EXTRA_INCLUDE") s=ExtraInclude;
  689. else if(it->value=="FUNCTION") s=Function;
  690. else switch(s) {
  691. case Tests:
  692. m_tests.append(it->value);
  693. break;
  694. case ExtraInclude:
  695. m_extraIncludes.append(it->value);
  696. s=Tests;
  697. break;
  698. case Function:
  699. m_function.append(it->value);
  700. s=Tests;
  701. break;
  702. }
  703. }
  704. return !m_tests.isEmpty();
  705. }
  706. EnableLanguageAst::EnableLanguageAst()
  707. {
  708. }
  709. EnableLanguageAst::~EnableLanguageAst()
  710. {
  711. }
  712. void EnableLanguageAst::writeBack( QString& ) const
  713. {
  714. }
  715. bool EnableLanguageAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  716. {
  717. if ( func.name.toLower() != "enable_language" )
  718. return false;
  719. if ( func.arguments.count() != 1 )
  720. return false;
  721. m_language = func.arguments[0].value;
  722. return true;
  723. }
  724. EnableTestingAst::EnableTestingAst()
  725. {
  726. }
  727. EnableTestingAst::~EnableTestingAst()
  728. {
  729. }
  730. void EnableTestingAst::writeBack( QString& ) const
  731. {
  732. }
  733. bool EnableTestingAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  734. {
  735. return func.name.toLower() == "enable_testing" && func.arguments.isEmpty();
  736. }
  737. ExecProgramAst::ExecProgramAst()
  738. {
  739. }
  740. ExecProgramAst::~ExecProgramAst()
  741. {
  742. }
  743. void ExecProgramAst::writeBack( QString& ) const
  744. {
  745. }
  746. bool ExecProgramAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  747. {
  748. if(func.name.toLower() != "exec_program" || func.arguments.count()<2)
  749. return false;
  750. m_executableName = func.arguments[0].value;
  751. bool args=false;
  752. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin(), itEnd=func.arguments.end();
  753. // don't re-read the first element
  754. it++;
  755. for(; it!=itEnd; ++it) {
  756. if(it->value.toUpper()=="OUTPUT_VARIABLE") {
  757. ++it;
  758. if(it!=itEnd)
  759. m_outputVariable = it->value;
  760. else
  761. return false;
  762. } else if(it->value.toUpper()=="RETURN_VALUE") {
  763. ++it;
  764. if(it!=itEnd)
  765. m_returnValue = it->value;
  766. else
  767. return false;
  768. } else if(it->value.toUpper()=="ARGS") {
  769. args=true;
  770. } else if(args) {
  771. m_arguments += it->value;
  772. } else
  773. m_workingDirectory = it->value;
  774. }
  775. return true;
  776. }
  777. ExecuteProcessAst::ExecuteProcessAst()
  778. : m_timeout(0.f), m_isOutputQuiet(false), m_isErrorQuiet(false),
  779. m_isOutputStrip(false), m_isErrorStrip(false)
  780. {
  781. }
  782. ExecuteProcessAst::~ExecuteProcessAst()
  783. {
  784. }
  785. void ExecuteProcessAst::writeBack( QString& ) const
  786. {
  787. }
  788. bool ExecuteProcessAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  789. {
  790. if(func.name.toLower() != "execute_process" || func.arguments.count()<2)
  791. return false;
  792. enum Action {
  793. None,
  794. Cmd,
  795. WorkDir,
  796. Timeout,
  797. ResultVar,
  798. OutputVar,
  799. ErrorVar,
  800. InputFile,
  801. OutputFile,
  802. ErrorFile
  803. };
  804. Action act=None;
  805. foreach(CMakeFunctionArgument a, func.arguments) {
  806. QString val=a.value.toLower();
  807. Action actAnt=act;
  808. if(val=="command") {
  809. m_commands.append(QStringList());
  810. act=Cmd;
  811. } else if(val=="working_directory")
  812. act=WorkDir;
  813. else if(val=="timeout")
  814. act=Timeout;
  815. else if(val=="result_variable")
  816. act=ResultVar;
  817. else if(val=="output_variable")
  818. act=OutputVar;
  819. else if(val=="error_variable")
  820. act=ErrorVar;
  821. else if(val=="input_file")
  822. act=InputFile;
  823. else if(val=="output_file")
  824. act=OutputFile;
  825. else if(val=="error_file")
  826. act=ErrorFile;
  827. else if(val=="output_quiet")
  828. {
  829. m_isOutputQuiet=true;
  830. act=None;
  831. }
  832. else if(val=="error_quiet")
  833. {
  834. m_isErrorQuiet=true;
  835. act=None;
  836. }
  837. else if(val=="output_strip_trailing_whitespace")
  838. {
  839. m_isOutputStrip=true;
  840. act=None;
  841. }
  842. else if(val=="error_strip_trailing_whitespace")
  843. {
  844. m_isErrorStrip=true;
  845. act=None;
  846. }
  847. if(act!=actAnt)
  848. val.clear();
  849. switch(act) {
  850. case None:
  851. break;
  852. case Cmd:
  853. if(!val.isEmpty())
  854. m_commands.last().append(a.value);
  855. break;
  856. case WorkDir:
  857. m_workingDirectory=a.value;
  858. break;
  859. case Timeout:
  860. m_timeout=val.toFloat();
  861. break;
  862. case ResultVar:
  863. m_resultVariable=a.value;
  864. break;
  865. case OutputVar:
  866. m_outputVariable=a.value;
  867. break;
  868. case ErrorVar:
  869. m_errorVariable=a.value;
  870. break;
  871. case InputFile:
  872. m_inputFile=a.value;
  873. break;
  874. case OutputFile:
  875. m_outputFile=a.value;
  876. break;
  877. case ErrorFile:
  878. m_errorFile=a.value;
  879. break;
  880. }
  881. }
  882. return true;
  883. }
  884. ExportLibraryDepsAst::ExportLibraryDepsAst()
  885. : m_append(false)
  886. {
  887. }
  888. ExportLibraryDepsAst::~ExportLibraryDepsAst()
  889. {
  890. }
  891. void ExportLibraryDepsAst::writeBack( QString& ) const
  892. {
  893. }
  894. bool ExportLibraryDepsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  895. {
  896. if(func.name.toLower() != "export_library_dependencies" || func.arguments.isEmpty())
  897. return false;
  898. m_file=func.arguments[0].value;
  899. if(func.arguments.count()>=2)
  900. {
  901. if(func.arguments[1].value=="APPEND")
  902. {
  903. m_append=true;
  904. }
  905. if(func.arguments.count()>(2+m_append))
  906. return false;
  907. }
  908. return true;
  909. }
  910. FileAst::FileAst()
  911. {
  912. }
  913. FileAst::~FileAst()
  914. {
  915. }
  916. void FileAst::writeBack( QString& ) const
  917. {
  918. }
  919. bool FileAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  920. {
  921. if ( func.name.toLower() != "file" )
  922. return false;
  923. if ( func.arguments.count()<2 )
  924. return false;
  925. QString type = func.arguments[0].value.toUpper();
  926. int min_args=-1;
  927. if(type=="WRITE") {
  928. m_type = WRITE;
  929. min_args=3;
  930. } else if(type=="APPEND") {
  931. m_type = APPEND;
  932. min_args=3;
  933. } else if(type=="READ") {
  934. m_type = READ;
  935. min_args=3;
  936. } else if(type=="GLOB") {
  937. m_type = GLOB;
  938. min_args=3;
  939. } else if(type=="GLOB_RECURSE") {
  940. m_type = GLOB_RECURSE;
  941. min_args = 3;
  942. } else if(type=="REMOVE") {
  943. m_type = REMOVE;
  944. min_args=2;
  945. } else if(type=="REMOVE_RECURSE") {
  946. m_type = REMOVE_RECURSE;
  947. min_args=2;
  948. } else if(type=="MAKE_DIRECTORY") {
  949. m_type = MAKE_DIRECTORY;
  950. min_args=2;
  951. } else if(type=="RELATIVE_PATH") {
  952. m_type = RELATIVE_PATH;
  953. min_args=4;
  954. } else if(type=="TO_CMAKE_PATH") {
  955. m_type = TO_CMAKE_PATH;
  956. min_args=3;
  957. } else if(type=="TO_NATIVE_PATH") {
  958. m_type = TO_NATIVE_PATH;
  959. min_args=3;
  960. }
  961. if(func.arguments.count()<min_args)
  962. return false;
  963. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  964. switch(m_type) {
  965. case WRITE:
  966. case APPEND:
  967. m_path = func.arguments[1].value;
  968. m_message = func.arguments[2].value;
  969. break;
  970. case READ:
  971. m_path=func.arguments[1].value;
  972. m_variable = func.arguments[2].value;
  973. break;
  974. case GLOB:
  975. case GLOB_RECURSE:
  976. m_variable = func.arguments[1].value;
  977. it=func.arguments.constBegin()+2;
  978. itEnd=func.arguments.constEnd();
  979. for(; it!=itEnd; ++it) {
  980. if(it->value=="RELATIVE") {
  981. it++;
  982. if(it==itEnd)
  983. return false;
  984. else
  985. m_path = it->value;
  986. } else
  987. m_globbingExpressions << it->value;
  988. }
  989. break;
  990. case REMOVE:
  991. case REMOVE_RECURSE:
  992. case MAKE_DIRECTORY:
  993. it=func.arguments.constBegin()+1;
  994. itEnd=func.arguments.constEnd();
  995. for(; it!=itEnd; ++it)
  996. m_directories << it->value;
  997. break;
  998. case RELATIVE_PATH:
  999. m_variable = func.arguments[1].value;
  1000. m_directory = func.arguments[2].value;
  1001. m_path = func.arguments[3].value;
  1002. break;
  1003. case TO_CMAKE_PATH:
  1004. case TO_NATIVE_PATH:
  1005. m_path = func.arguments[1].value;
  1006. m_variable = func.arguments[2].value;
  1007. break;
  1008. }
  1009. return true;
  1010. }
  1011. FindFileAst::FindFileAst()
  1012. : m_noDefaultPath(false)
  1013. {
  1014. }
  1015. FindFileAst::~FindFileAst()
  1016. {
  1017. }
  1018. void FindFileAst::writeBack( QString& ) const
  1019. {
  1020. }
  1021. bool FindFileAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1022. {
  1023. if(func.name.toLower()!="find_file" || func.arguments.count()<3)
  1024. return false;
  1025. bool definedNames=false;
  1026. m_variableName = func.arguments[0].value;
  1027. Stage s = NAMES;
  1028. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+1, itEnd=func.arguments.end();
  1029. if(it->value=="NAMES") {
  1030. ++it;
  1031. definedNames = true;
  1032. } else {
  1033. m_filenames=QStringList(it->value);
  1034. it++;
  1035. s=PATHS;
  1036. definedNames = false;
  1037. }
  1038. for(; it!=itEnd; ++it) {
  1039. if(it->value=="NO_DEFAULT_PATH")
  1040. m_noDefaultPath = true;
  1041. else if(it->value=="NO_CMAKE_ENVIRONMENT_PATH")
  1042. m_noCmakeEnvironmentPath = true;
  1043. else if(it->value=="NO_CMAKE_PATH")
  1044. m_noSystemEnvironmentPath = true;
  1045. else if(it->value=="DOC") {
  1046. ++it;
  1047. if(it==itEnd)
  1048. return false;
  1049. m_documentation = it->value;
  1050. } else if(it->value=="PATHS")
  1051. s=PATHS;
  1052. else if(it->value=="PATH_SUFFIXES")
  1053. s=PATH_SUFFIXES;
  1054. else switch(s) {
  1055. case NAMES:
  1056. m_filenames << it->value;
  1057. if(!definedNames)
  1058. s=PATHS;
  1059. break;
  1060. case PATHS:
  1061. m_path << it->value;
  1062. break;
  1063. case PATH_SUFFIXES:
  1064. m_pathSuffixes << it->value;
  1065. break;
  1066. }
  1067. }
  1068. return !m_filenames.isEmpty() && !m_path.isEmpty();
  1069. }
  1070. MacroCallAst::MacroCallAst()
  1071. {
  1072. }
  1073. MacroCallAst::~MacroCallAst()
  1074. {
  1075. }
  1076. void MacroCallAst::writeBack( QString& ) const
  1077. {
  1078. }
  1079. bool MacroCallAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1080. {
  1081. if(func.name.isEmpty())
  1082. return false;
  1083. m_name = func.name.toLower();
  1084. foreach(CMakeFunctionArgument fa, func.arguments)
  1085. {
  1086. m_arguments += fa.value;
  1087. }
  1088. return true;
  1089. }
  1090. FindLibraryAst::FindLibraryAst()
  1091. : m_noDefaultPath(false)
  1092. {
  1093. }
  1094. FindLibraryAst::~FindLibraryAst()
  1095. {
  1096. }
  1097. void FindLibraryAst::writeBack( QString& ) const
  1098. {
  1099. }
  1100. bool FindLibraryAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1101. {
  1102. if(func.name.toLower()!="find_library" || func.arguments.count()<2)
  1103. return false;
  1104. bool definedNames=false;
  1105. m_variableName = func.arguments[0].value;
  1106. Stage s = NAMES;
  1107. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.constBegin()+1, itEnd=func.arguments.constEnd();
  1108. if(it->value=="NAMES") {
  1109. ++it;
  1110. definedNames = true;
  1111. } else {
  1112. m_filenames=QStringList(it->value);
  1113. ++it;
  1114. s=PATHS;
  1115. definedNames = false;
  1116. }
  1117. for(; it!=itEnd; ++it) {
  1118. if(it->value=="NO_DEFAULT_PATH")
  1119. m_noDefaultPath = true;
  1120. else if(it->value=="NO_CMAKE_ENVIRONMENT_PATH")
  1121. m_noCmakeEnvironmentPath = true;
  1122. else if(it->value=="NO_CMAKE_PATH")
  1123. m_noSystemEnvironmentPath = true;
  1124. else if(it->value=="DOC") {
  1125. ++it;
  1126. if(it==itEnd)
  1127. return false;
  1128. m_documentation = it->value;
  1129. } else if(it->value=="PATHS")
  1130. s=PATHS;
  1131. else if(it->value=="PATH_SUFFIXES")
  1132. s=PATH_SUFFIXES;
  1133. else switch(s) {
  1134. case NAMES:
  1135. m_filenames << it->value;
  1136. if(!definedNames)
  1137. s=PATHS;
  1138. break;
  1139. case PATHS:
  1140. m_path << it->value;
  1141. break;
  1142. case PATH_SUFFIXES:
  1143. m_pathSuffixes << it->value;
  1144. break;
  1145. }
  1146. }
  1147. return !m_filenames.isEmpty();
  1148. }
  1149. FindPackageAst::FindPackageAst()
  1150. {
  1151. }
  1152. FindPackageAst::~FindPackageAst()
  1153. {
  1154. }
  1155. void FindPackageAst::writeBack( QString& ) const
  1156. {
  1157. }
  1158. bool FindPackageAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1159. {
  1160. m_isQuiet=false;
  1161. m_noModule=false;
  1162. m_isRequired=false;
  1163. if ( func.name.toLower() != "find_package" )
  1164. return false;
  1165. if ( func.arguments.isEmpty() )
  1166. return false;
  1167. m_name = func.arguments[0].value;
  1168. foreach( CMakeFunctionArgument arg, func.arguments ) {
  1169. if(arg.value[0].isNumber()) {
  1170. bool correctmin, correctmaj;
  1171. QStringList version = func.arguments[1].value.split('.');
  1172. m_minorVersion = version[0].toInt(&correctmin);
  1173. m_majorVersion = version[1].toInt(&correctmaj);
  1174. if(!correctmin || !correctmaj)
  1175. return false;
  1176. } else if(arg.value=="QUIET")
  1177. m_isQuiet=true;
  1178. else if(arg.value=="NO_MODULE")
  1179. m_noModule=true;
  1180. else if(arg.value=="REQUIRED")
  1181. m_isRequired=true;
  1182. }
  1183. return true;
  1184. }
  1185. FindPathAst::FindPathAst()
  1186. : m_noDefaultPath(false)
  1187. , m_noCmakeEnvironmentPath(false)
  1188. , m_noCmakePath(false)
  1189. , m_noSystemEnvironmentPath(false)
  1190. , m_noCmakeSystemPath(false)
  1191. {
  1192. }
  1193. FindPathAst::~FindPathAst()
  1194. {
  1195. }
  1196. void FindPathAst::writeBack( QString& ) const
  1197. {
  1198. }
  1199. bool FindPathAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1200. {
  1201. if(func.name.toLower()!="find_path" || func.arguments.count()<2)
  1202. return false;
  1203. //FIXME: FIND_PATH(KDE4_DATA_DIR cmake/modules/FindKDE4Internal.cmake ${_data_DIR})
  1204. bool definedNames=false;
  1205. m_variableName = func.arguments[0].value;
  1206. Stage s = NAMES;
  1207. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+1, itEnd=func.arguments.end();
  1208. if(it->value=="NAMES") {
  1209. ++it;
  1210. definedNames = true;
  1211. } else {
  1212. m_filenames=QStringList(it->value);
  1213. it++;
  1214. s=PATHS;
  1215. definedNames = false;
  1216. }
  1217. for(; it!=itEnd; ++it) {
  1218. if(it->value=="NO_DEFAULT_PATH")
  1219. m_noDefaultPath = true;
  1220. else if(it->value=="NO_CMAKE_ENVIRONMENT_PATH")
  1221. m_noCmakeEnvironmentPath = true;
  1222. else if(it->value=="NO_CMAKE_PATH")
  1223. m_noSystemEnvironmentPath = true;
  1224. else if(it->value=="DOC") {
  1225. ++it;
  1226. if(it==itEnd)
  1227. return false;
  1228. m_documentation = it->value;
  1229. } else if(it->value=="PATHS")
  1230. s=PATHS;
  1231. else if(it->value=="PATH_SUFFIXES")
  1232. s=PATH_SUFFIXES;
  1233. else switch(s) {
  1234. case NAMES:
  1235. m_filenames << it->value;
  1236. if(!definedNames)
  1237. s=PATHS;
  1238. break;
  1239. case PATHS:
  1240. m_path << it->value;
  1241. break;
  1242. case PATH_SUFFIXES:
  1243. m_pathSuffixes << it->value;
  1244. break;
  1245. }
  1246. }
  1247. return !m_filenames.isEmpty();
  1248. }
  1249. FindProgramAst::FindProgramAst()
  1250. {
  1251. m_noDefaultPath = m_noCmakeEnvironmentPath = m_noCmakePath =
  1252. m_noSystemEnvironmentPath = m_noSystemEnvironmentPath = false;
  1253. }
  1254. FindProgramAst::~FindProgramAst()
  1255. {
  1256. }
  1257. void FindProgramAst::writeBack( QString& ) const
  1258. {
  1259. }
  1260. bool FindProgramAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1261. {
  1262. if(func.name.toLower()!="find_program" || func.arguments.count()<2)
  1263. return false;
  1264. m_variableName = func.arguments[0].value;
  1265. Stage s = NAMES;
  1266. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+1, itEnd=func.arguments.end();
  1267. if(it->value=="NAMES")
  1268. ++it;
  1269. else {
  1270. m_filenames=QStringList(it->value);
  1271. s=PATHS;
  1272. }
  1273. for(; it!=itEnd; ++it) {
  1274. if(it->value=="NO_DEFAULT_PATH")
  1275. m_noDefaultPath = true;
  1276. else if(it->value=="NO_CMAKE_ENVIRONMENT_PATH")
  1277. m_noCmakeEnvironmentPath = true;
  1278. else if(it->value=="NO_CMAKE_PATH")
  1279. m_noCmakePath=true;
  1280. else if(it->value=="NO_SYSTEM_ENVIRONMENT_PATH")
  1281. m_noSystemEnvironmentPath = true;
  1282. else if(it->value=="NO_SYSTEM_ENVIRONMENT_PATH")
  1283. m_noSystemEnvironmentPath = true;
  1284. else if(it->value=="DOC") {
  1285. ++it;
  1286. if(it==itEnd)
  1287. return false;
  1288. m_documentation = it->value;
  1289. } else if(it->value=="PATHS")
  1290. s=PATHS;
  1291. else if(it->value=="PATH_SUFFIXES")
  1292. s=PATH_SUFFIXES;
  1293. else switch(s) {
  1294. case NAMES:
  1295. m_filenames << it->value;
  1296. break;
  1297. case PATHS:
  1298. m_path << it->value;
  1299. break;
  1300. case PATH_SUFFIXES:
  1301. m_pathSuffixes << it->value;
  1302. break;
  1303. }
  1304. }
  1305. return !m_filenames.isEmpty();
  1306. }
  1307. FltkWrapUiAst::FltkWrapUiAst()
  1308. {
  1309. }
  1310. FltkWrapUiAst::~FltkWrapUiAst()
  1311. {
  1312. }
  1313. void FltkWrapUiAst::writeBack( QString& ) const
  1314. {
  1315. }
  1316. bool FltkWrapUiAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1317. {
  1318. return false;
  1319. }
  1320. ForeachAst::ForeachAst()
  1321. {
  1322. }
  1323. ForeachAst::~ForeachAst()
  1324. {
  1325. }
  1326. void ForeachAst::writeBack( QString& ) const
  1327. {
  1328. }
  1329. bool ForeachAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1330. {
  1331. if(func.name.toLower()!="foreach" || func.arguments.count()<2)
  1332. return false;
  1333. m_loopVar=func.arguments.first().value;
  1334. if(func.arguments[1].value=="RANGE") {
  1335. bool correctStart = true, correctStop = true, correctRange = true;
  1336. m_range=true;
  1337. if(func.arguments.count()<3)
  1338. return false;
  1339. m_ranges.step = 1;
  1340. m_ranges.start = 0;
  1341. if( func.arguments.count() == 3 )
  1342. {
  1343. m_ranges.stop = func.arguments[2].value.toInt(&correctStop);
  1344. }else
  1345. {
  1346. m_ranges.start = func.arguments[2].value.toInt(&correctStart);
  1347. m_ranges.stop = func.arguments[3].value.toInt(&correctStop);
  1348. }
  1349. if(func.arguments.count()==5)
  1350. m_ranges.step = func.arguments[4].value.toInt(&correctRange);
  1351. if(!correctStart || !correctStop || !correctRange)
  1352. return false;
  1353. } else {
  1354. m_range=false;
  1355. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.constBegin()+1, itEnd=func.arguments.constEnd();
  1356. for(; it!=itEnd; ++it)
  1357. {
  1358. m_arguments += it->value;
  1359. }
  1360. }
  1361. return true;
  1362. }
  1363. GetCMakePropertyAst::GetCMakePropertyAst()
  1364. {
  1365. }
  1366. GetCMakePropertyAst::~GetCMakePropertyAst()
  1367. {
  1368. }
  1369. void GetCMakePropertyAst::writeBack( QString& ) const
  1370. {
  1371. }
  1372. bool GetCMakePropertyAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1373. {
  1374. if(func.name.toLower()!="get_cmake_property" || func.arguments.count()!=2)
  1375. return false;
  1376. m_variableName = func.arguments[0].value;
  1377. QString type=func.arguments[1].value.toUpper();
  1378. if(type=="VARIABLES")
  1379. m_type=VARIABLES;
  1380. else if(type=="CACHE_VARIABLES")
  1381. m_type=CACHE_VARIABLES;
  1382. else if(type=="COMMANDS")
  1383. m_type=COMMANDS;
  1384. else if(type=="MACROS")
  1385. m_type=MACROS;
  1386. else
  1387. return false;
  1388. return true;
  1389. }
  1390. GetDirPropertyAst::GetDirPropertyAst()
  1391. {
  1392. }
  1393. GetDirPropertyAst::~GetDirPropertyAst()
  1394. {
  1395. }
  1396. void GetDirPropertyAst::writeBack( QString& ) const
  1397. {
  1398. }
  1399. bool GetDirPropertyAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1400. {
  1401. return false;
  1402. }
  1403. GetFilenameComponentAst::GetFilenameComponentAst()
  1404. {
  1405. }
  1406. GetFilenameComponentAst::~GetFilenameComponentAst()
  1407. {
  1408. }
  1409. void GetFilenameComponentAst::writeBack( QString& ) const
  1410. {
  1411. }
  1412. bool GetFilenameComponentAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1413. {
  1414. if(func.name.toLower()!="get_filename_component" || func.arguments.count()<3)
  1415. return false;
  1416. m_variableName = func.arguments[0].value;
  1417. m_fileName = func.arguments[1].value;
  1418. QString t = func.arguments[2].value;
  1419. if(t=="PATH") m_type=PATH;
  1420. else if(t=="ABSOLUTE") m_type=ABSOLUTE;
  1421. else if(t=="NAME") m_type=NAME;
  1422. else if(t=="EXT") m_type=EXT;
  1423. else if(t=="NAME_WE") m_type=NAME_WE;
  1424. else if(t=="PROGRAM") m_type=PROGRAM;
  1425. else
  1426. return false;
  1427. if(m_type==PROGRAM) {
  1428. //TODO: Did not understand this option
  1429. }
  1430. m_cache = func.arguments.last().value=="CACHE";
  1431. return true;
  1432. }
  1433. GetSourceFilePropAst::GetSourceFilePropAst()
  1434. {
  1435. }
  1436. GetSourceFilePropAst::~GetSourceFilePropAst()
  1437. {
  1438. }
  1439. void GetSourceFilePropAst::writeBack( QString& ) const
  1440. {
  1441. }
  1442. bool GetSourceFilePropAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1443. {
  1444. if(func.name.toLower()!="get_source_file_property" || func.arguments.count()!=3)
  1445. return false;
  1446. m_variableName=func.arguments[0].value;
  1447. m_filename=func.arguments[1].value;
  1448. m_property=func.arguments[2].value;
  1449. return true;
  1450. }
  1451. GetTargetPropAst::GetTargetPropAst()
  1452. {
  1453. }
  1454. GetTargetPropAst::~GetTargetPropAst()
  1455. {
  1456. }
  1457. void GetTargetPropAst::writeBack( QString& ) const
  1458. {
  1459. }
  1460. bool GetTargetPropAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1461. {
  1462. if(func.name.toLower()!="get_target_property" || func.arguments.count()!=3)
  1463. return false;
  1464. m_variableName=func.arguments[0].value;
  1465. m_target=func.arguments[1].value;
  1466. m_property=func.arguments[2].value;
  1467. return true;
  1468. }
  1469. GetTestPropAst::GetTestPropAst()
  1470. {
  1471. }
  1472. GetTestPropAst::~GetTestPropAst()
  1473. {
  1474. }
  1475. void GetTestPropAst::writeBack( QString& ) const
  1476. {
  1477. }
  1478. bool GetTestPropAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1479. {
  1480. if(func.name.toLower()!="get_target_property" || func.arguments.count()!=3)
  1481. return false;
  1482. m_test=func.arguments[0].value;
  1483. m_variableName=func.arguments[1].value;
  1484. m_property=func.arguments[2].value;
  1485. return true;
  1486. }
  1487. IfAst::IfAst()
  1488. {
  1489. }
  1490. IfAst::~IfAst()
  1491. {
  1492. }
  1493. void IfAst::writeBack( QString& s) const
  1494. {
  1495. kDebug(9032)<< "if:" << s;
  1496. }
  1497. bool IfAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1498. {
  1499. if(func.name.toLower()!="if" && func.name.toLower()!="elseif" && func.name.toLower()!="else")
  1500. return false;
  1501. if(func.name.toLower()=="else" && !func.arguments.isEmpty())
  1502. return false;
  1503. m_kind = func.name;
  1504. m_condition = QStringList();
  1505. foreach(CMakeFunctionArgument fa, func.arguments)
  1506. {
  1507. m_condition += fa.value;
  1508. }
  1509. return true;
  1510. }
  1511. IncludeAst::IncludeAst()
  1512. : m_optional(false)
  1513. {
  1514. }
  1515. IncludeAst::~IncludeAst()
  1516. {
  1517. }
  1518. void IncludeAst::writeBack( QString& ) const
  1519. {
  1520. }
  1521. bool IncludeAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1522. {
  1523. if ( func.name.toLower() != "include" )
  1524. return false;
  1525. if ( func.arguments.size() < 1 || func.arguments.size() > 4 )
  1526. return false;
  1527. m_includeFile = func.arguments[0].value;
  1528. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  1529. it=func.arguments.begin() + 1;
  1530. itEnd = func.arguments.end();
  1531. bool nextIsResult=false;
  1532. for ( ; it != itEnd; ++it ) {
  1533. if(nextIsResult)
  1534. {
  1535. m_resultVariable=it->value;
  1536. nextIsResult=false;
  1537. }
  1538. else if ( it->value == "OPTIONAL" )
  1539. m_optional = true;
  1540. else if( it->value == "RESULT_VARIABLE" )
  1541. nextIsResult=true;
  1542. }
  1543. return true;
  1544. }
  1545. IncludeDirectoriesAst::IncludeDirectoriesAst()
  1546. {
  1547. }
  1548. IncludeDirectoriesAst::~IncludeDirectoriesAst()
  1549. {
  1550. }
  1551. void IncludeDirectoriesAst::writeBack( QString& ) const
  1552. {
  1553. }
  1554. bool IncludeDirectoriesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1555. {
  1556. if ( func.name.toLower() != "include_directories" || func.arguments.isEmpty() )
  1557. return false;
  1558. int i=0;
  1559. m_includeType = DEFAULT;
  1560. m_isSystem = false;
  1561. if(func.arguments[i].value=="AFTER") {
  1562. if(m_includeType!=DEFAULT)
  1563. return false;
  1564. m_includeType = AFTER;
  1565. i++;
  1566. }
  1567. if(func.arguments[i].value=="BEFORE") {
  1568. if(m_includeType!=DEFAULT)
  1569. return false;
  1570. m_includeType = BEFORE;
  1571. i++;
  1572. }
  1573. if(func.arguments[i].value=="SYSTEM") {
  1574. m_isSystem = true;
  1575. i++;
  1576. }
  1577. if ( func.arguments.size() <= i )
  1578. return false;
  1579. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  1580. it=func.arguments.begin() + i;
  1581. itEnd = func.arguments.end();
  1582. for ( ; it != itEnd; ++it )
  1583. m_includedDirectories.append(it->value);
  1584. return true;
  1585. }
  1586. IncludeExternalMsProjectAst::IncludeExternalMsProjectAst()
  1587. {
  1588. }
  1589. IncludeExternalMsProjectAst::~IncludeExternalMsProjectAst()
  1590. {
  1591. }
  1592. void IncludeExternalMsProjectAst::writeBack( QString& ) const
  1593. {
  1594. }
  1595. bool IncludeExternalMsProjectAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1596. {
  1597. return false;
  1598. }
  1599. IncludeRegularExpressionAst::IncludeRegularExpressionAst()
  1600. {
  1601. }
  1602. IncludeRegularExpressionAst::~IncludeRegularExpressionAst()
  1603. {
  1604. }
  1605. void IncludeRegularExpressionAst::writeBack( QString& ) const
  1606. {
  1607. }
  1608. bool IncludeRegularExpressionAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1609. {
  1610. if ( func.name.toLower() != "include_regular_expression" || func.arguments.isEmpty() || func.arguments.count()>2 )
  1611. return false;
  1612. m_match=func.arguments[0].value;
  1613. if(func.arguments.count()==2)
  1614. m_complain=func.arguments[1].value;
  1615. return true;
  1616. }
  1617. InstallAst::InstallAst()
  1618. {
  1619. }
  1620. InstallAst::~InstallAst()
  1621. {
  1622. }
  1623. void InstallAst::writeBack( QString& ) const
  1624. {
  1625. }
  1626. bool InstallAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1627. {
  1628. return false;
  1629. }
  1630. InstallFilesAst::InstallFilesAst()
  1631. {
  1632. }
  1633. InstallFilesAst::~InstallFilesAst()
  1634. {
  1635. }
  1636. void InstallFilesAst::writeBack( QString& ) const
  1637. {
  1638. }
  1639. bool InstallFilesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1640. {
  1641. if(func.name.toLower()=="install_files" || func.arguments.count()<2)
  1642. return false;
  1643. m_directory=func.arguments[0].value;
  1644. if(func.arguments.count()==2)
  1645. {
  1646. m_regex=func.arguments[1].value;
  1647. }
  1648. else
  1649. {
  1650. QList<CMakeFunctionArgument>::const_iterator it, itEnd=func.arguments.constEnd();
  1651. if(func.arguments[1].value!="FILES")
  1652. m_extension=func.arguments[1].value;
  1653. for(it=func.arguments.constBegin()+2; it!=itEnd; ++it)
  1654. {
  1655. m_files.append(it->value);
  1656. }
  1657. }
  1658. return !m_files.isEmpty() || !m_regex.isEmpty();
  1659. }
  1660. InstallProgramsAst::InstallProgramsAst()
  1661. {
  1662. }
  1663. InstallProgramsAst::~InstallProgramsAst()
  1664. {
  1665. }
  1666. void InstallProgramsAst::writeBack( QString& ) const
  1667. {
  1668. }
  1669. bool InstallProgramsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1670. {
  1671. if(func.name.toLower()=="install_programs" || func.arguments.count()<2)
  1672. return false;
  1673. m_directory=func.arguments[0].value;
  1674. if(func.arguments.count()==2)
  1675. {
  1676. m_regex=func.arguments[1].value;
  1677. }
  1678. else
  1679. {
  1680. QList<CMakeFunctionArgument>::const_iterator it, itEnd=func.arguments.constEnd();
  1681. int firstpos=1;
  1682. if(func.arguments[1].value!="FILES")
  1683. firstpos++;
  1684. for(it=func.arguments.constBegin()+firstpos; it!=itEnd; ++it)
  1685. {
  1686. m_files.append(it->value);
  1687. }
  1688. }
  1689. return !m_files.isEmpty() || !m_regex.isEmpty();
  1690. }
  1691. InstallTargetsAst::InstallTargetsAst()
  1692. {
  1693. }
  1694. InstallTargetsAst::~InstallTargetsAst()
  1695. {
  1696. }
  1697. void InstallTargetsAst::writeBack( QString& ) const
  1698. {
  1699. }
  1700. bool InstallTargetsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1701. {
  1702. if(func.name.toLower()=="install_targets" || func.arguments.count()<2)
  1703. return false;
  1704. m_directory=func.arguments[0].value;
  1705. QList<CMakeFunctionArgument>::const_iterator it, itEnd=func.arguments.constEnd();
  1706. int firstpos=1;
  1707. if(func.arguments[1].value=="RUNTIME_DIRECTORY")
  1708. {
  1709. firstpos+=2;
  1710. if(func.arguments.count()<3)
  1711. return false;
  1712. m_runtimeDir=func.arguments[2].value;
  1713. }
  1714. for(it=func.arguments.constBegin()+firstpos; it!=itEnd; ++it)
  1715. {
  1716. m_targets.append(it->value);
  1717. }
  1718. return !m_targets.isEmpty();
  1719. }
  1720. LinkDirectoriesAst::LinkDirectoriesAst()
  1721. {
  1722. }
  1723. LinkDirectoriesAst::~LinkDirectoriesAst()
  1724. {
  1725. }
  1726. void LinkDirectoriesAst::writeBack( QString& ) const
  1727. {
  1728. }
  1729. bool LinkDirectoriesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1730. {
  1731. if ( func.name.toLower() != "include_regular_expression" || func.arguments.isEmpty() )
  1732. return false;
  1733. foreach(const CMakeFunctionArgument &arg, func.arguments)
  1734. m_directories.append(arg.value);
  1735. return true;
  1736. }
  1737. LinkLibrariesAst::LinkLibrariesAst()
  1738. {
  1739. }
  1740. LinkLibrariesAst::~LinkLibrariesAst()
  1741. {
  1742. }
  1743. void LinkLibrariesAst::writeBack( QString& ) const
  1744. {
  1745. }
  1746. bool LinkLibrariesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1747. {
  1748. if ( func.name.toLower() != "link_libraries" || func.arguments.isEmpty() )
  1749. return false;
  1750. QString lastLib;
  1751. foreach(const CMakeFunctionArgument &arg, func.arguments)
  1752. {
  1753. BuildType current=None;
  1754. if(arg.value=="debug")
  1755. current=Debug;
  1756. else if(arg.value=="optimized")
  1757. current=Optimized;
  1758. else
  1759. {
  1760. if(!lastLib.isEmpty())
  1761. m_libraries.append(LibraryType(lastLib, None));
  1762. lastLib=arg.value;
  1763. }
  1764. if(current!=None)
  1765. m_libraries.append(LibraryType(lastLib, current));
  1766. }
  1767. return true;
  1768. }
  1769. ListAst::ListAst()
  1770. {
  1771. }
  1772. ListAst::~ListAst()
  1773. {
  1774. }
  1775. void ListAst::writeBack( QString& ) const
  1776. {
  1777. }
  1778. bool ListAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1779. {
  1780. if ( func.name.toLower() != "list" )
  1781. return false;
  1782. if ( func.arguments.size() < 2)
  1783. return false;
  1784. QString argName = func.arguments[0].value;
  1785. if(argName=="LENGTH")
  1786. m_type = LENGTH;
  1787. else if(argName=="GET")
  1788. m_type=GET;
  1789. else if(argName=="APPEND")
  1790. m_type = APPEND;
  1791. else if(argName=="INSERT")
  1792. m_type = INSERT;
  1793. else if(argName=="REMOVE_ITEM")
  1794. m_type = REMOVE_ITEM;
  1795. else if(argName=="REMOVE_AT")
  1796. m_type = REMOVE_AT;
  1797. else if(argName=="SORT")
  1798. m_type = SORT;
  1799. else if(argName=="REVERSE")
  1800. m_type = REVERSE;
  1801. else
  1802. return false;
  1803. m_list = func.arguments[1].value;
  1804. switch(m_type)
  1805. {
  1806. case LENGTH:
  1807. if(func.arguments.count()!=3)
  1808. return false;
  1809. m_output = func.arguments[2].value;
  1810. break;
  1811. case GET: {
  1812. if(func.arguments.count()<3)
  1813. return false;
  1814. bool correct;
  1815. m_output = func.arguments.last().value;
  1816. m_index.append(func.arguments[2].value.toInt(&correct));
  1817. if(!correct)
  1818. return false;
  1819. int i=0;
  1820. foreach(CMakeFunctionArgument arg, func.arguments)
  1821. {
  1822. if(i>2 && i<func.arguments.count())
  1823. m_elements.append(arg.value);
  1824. i++;
  1825. }
  1826. } break;
  1827. case APPEND: {
  1828. if(func.arguments.count()<3)
  1829. return false;
  1830. int i=0;
  1831. foreach(CMakeFunctionArgument arg, func.arguments)
  1832. {
  1833. if(i>1)
  1834. m_elements.append(arg.value);
  1835. i++;
  1836. }
  1837. } break;
  1838. case INSERT: {
  1839. bool correct;
  1840. if(func.arguments.count()<4)
  1841. return false;
  1842. int i=0;
  1843. m_index.append(func.arguments[1].value.toInt(&correct));
  1844. if(!correct)
  1845. return false;
  1846. foreach(CMakeFunctionArgument arg, func.arguments)
  1847. {
  1848. if(i>2)
  1849. m_elements.append(arg.value);
  1850. i++;
  1851. }
  1852. } break;
  1853. case REMOVE_ITEM: {
  1854. if(func.arguments.count()<4)
  1855. return false;
  1856. int i=0;
  1857. foreach(CMakeFunctionArgument arg, func.arguments)
  1858. {
  1859. if(i>2)
  1860. m_elements.append(arg.value);
  1861. i++;
  1862. }
  1863. } break;
  1864. case REMOVE_AT: {
  1865. if(func.arguments.count()<3)
  1866. return false;
  1867. int i=0;
  1868. foreach(CMakeFunctionArgument arg, func.arguments)
  1869. {
  1870. if(i>1)
  1871. {
  1872. bool correct;
  1873. m_index.append(arg.value.toInt(&correct));
  1874. kDebug(9042) << "???" << arg.value;
  1875. Q_ASSERT(correct);
  1876. }
  1877. i++;
  1878. }
  1879. } break;
  1880. case SORT:
  1881. case REVERSE:
  1882. if(func.arguments.count()>2)
  1883. return false;
  1884. break;
  1885. }
  1886. return true;
  1887. }
  1888. LoadCacheAst::LoadCacheAst()
  1889. {
  1890. }
  1891. LoadCacheAst::~LoadCacheAst()
  1892. {
  1893. }
  1894. void LoadCacheAst::writeBack( QString& ) const
  1895. {
  1896. }
  1897. bool LoadCacheAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1898. {
  1899. if ( func.name.toLower() != "load_cache" || func.arguments.count()<4)
  1900. return false;
  1901. m_cachePath=func.arguments[0].value;
  1902. if(func.arguments[1].value=="READ_WITH_PREFIX")
  1903. {
  1904. QString prefix;
  1905. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.constEnd();
  1906. for ( it = func.arguments.constBegin() + 2; it != itEnd; ++it )
  1907. {
  1908. if(prefix.isEmpty())
  1909. {
  1910. prefix=it->value;
  1911. }
  1912. else
  1913. {
  1914. m_prefixes=PrefixEntry(prefix, it->value);
  1915. prefix.clear();
  1916. }
  1917. }
  1918. return prefix.isEmpty();
  1919. }
  1920. else
  1921. {
  1922. bool exclude=false;
  1923. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.constEnd();
  1924. for ( it = func.arguments.constBegin() + 2; it != itEnd; ++it )
  1925. {
  1926. if(it->value=="EXCLUDE")
  1927. exclude=true;
  1928. else if(it->value=="INCLUDE_INTERNALS")
  1929. exclude=false;
  1930. else
  1931. {
  1932. if(exclude)
  1933. m_exclude.append(it->value);
  1934. else
  1935. m_includeInternals.append(it->value);
  1936. }
  1937. }
  1938. return true;
  1939. }
  1940. return false;
  1941. }
  1942. LoadCommandAst::LoadCommandAst()
  1943. {
  1944. }
  1945. LoadCommandAst::~LoadCommandAst()
  1946. {
  1947. }
  1948. void LoadCommandAst::writeBack( QString& ) const
  1949. {
  1950. }
  1951. bool LoadCommandAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1952. {
  1953. if ( func.name.toLower() != "load_cache" || func.arguments.count()<4)
  1954. return false;
  1955. m_cmdName=func.arguments[0].value;
  1956. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.constEnd();
  1957. for ( it = func.arguments.constBegin() + 1; it != itEnd; ++it )
  1958. m_location.append( it->value );
  1959. return !m_location.isEmpty();
  1960. }
  1961. MacroAst::MacroAst()
  1962. {
  1963. }
  1964. MacroAst::~MacroAst()
  1965. {
  1966. }
  1967. void MacroAst::writeBack( QString& ) const
  1968. {
  1969. }
  1970. bool MacroAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1971. {
  1972. if ( func.name.toLower() != "macro" || func.arguments.isEmpty())
  1973. return false;
  1974. m_macroName = func.arguments[0].value.toLower();
  1975. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  1976. for ( it = func.arguments.begin() + 1; it != itEnd; ++it )
  1977. m_knownArgs.append( it->value );
  1978. return true;
  1979. }
  1980. MakeDirectoryAst::MakeDirectoryAst()
  1981. {
  1982. }
  1983. MakeDirectoryAst::~MakeDirectoryAst()
  1984. {
  1985. }
  1986. void MakeDirectoryAst::writeBack( QString& ) const
  1987. {
  1988. }
  1989. bool MakeDirectoryAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  1990. {
  1991. if ( func.name.toLower() != "make_directory" || func.arguments.isEmpty() || func.arguments.size()>1)
  1992. return false;
  1993. m_directory=func.arguments.first().value;
  1994. return true;
  1995. }
  1996. MarkAsAdvancedAst::MarkAsAdvancedAst()
  1997. {
  1998. }
  1999. MarkAsAdvancedAst::~MarkAsAdvancedAst()
  2000. {
  2001. }
  2002. void MarkAsAdvancedAst::writeBack( QString& ) const
  2003. {
  2004. }
  2005. bool MarkAsAdvancedAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2006. {
  2007. if ( func.name.toLower() != "mark_as_advanced" || func.arguments.isEmpty() )
  2008. return false;
  2009. m_isClear = func.arguments[0].value == "CLEAR";
  2010. m_isForce = func.arguments[0].value == "FORCE";
  2011. if ( (m_isClear || m_isForce) && func.arguments.size() < 2 )
  2012. return false;
  2013. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  2014. it=func.arguments.begin();
  2015. itEnd = func.arguments.end();
  2016. if(m_isClear || m_isForce)
  2017. it++;
  2018. for ( ; it != itEnd; ++it )
  2019. {
  2020. m_advancedVars.append(it->value);
  2021. }
  2022. return true;
  2023. }
  2024. MathAst::MathAst()
  2025. {
  2026. }
  2027. MathAst::~MathAst()
  2028. {
  2029. }
  2030. void MathAst::writeBack( QString& ) const
  2031. {
  2032. }
  2033. bool MathAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2034. {
  2035. if(func.name.toLower()!="math" || func.arguments.count()!=3 || func.arguments.first().value!="EXPR")
  2036. return false;
  2037. m_outputVariable = func.arguments[1].value;
  2038. m_expression = func.arguments.last().value;
  2039. return true;
  2040. }
  2041. MessageAst::MessageAst()
  2042. {
  2043. }
  2044. MessageAst::~MessageAst()
  2045. {
  2046. }
  2047. void MessageAst::writeBack( QString& ) const
  2048. {
  2049. }
  2050. bool MessageAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2051. {
  2052. if(func.name.toLower()!="message" || func.arguments.isEmpty())
  2053. return false;
  2054. if(func.arguments.count()>1) {
  2055. QString type=func.arguments.first().value;
  2056. if(type=="SEND_ERROR")
  2057. m_type=SEND_ERROR;
  2058. else if(type=="STATUS")
  2059. m_type=STATUS;
  2060. else if(type=="FATAL_ERROR")
  2061. m_type=FATAL_ERROR;
  2062. }
  2063. m_message.append(func.arguments.last().value); //Maybe should do a foreach
  2064. return true;
  2065. }
  2066. OptionAst::OptionAst()
  2067. {
  2068. }
  2069. OptionAst::~OptionAst()
  2070. {
  2071. }
  2072. void OptionAst::writeBack( QString& ) const
  2073. {
  2074. }
  2075. bool OptionAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2076. {
  2077. if(func.name.toLower()!="option" || (func.arguments.count()<2 && func.arguments.count()>3))
  2078. return false;
  2079. m_variableName = func.arguments[0].value;
  2080. m_description = func.arguments[1].value;
  2081. m_defaultValue = "OFF";
  2082. if(func.arguments.count() ==3)
  2083. m_defaultValue = func.arguments[2].value;
  2084. return true;
  2085. }
  2086. OutputRequiredFilesAst::OutputRequiredFilesAst()
  2087. {
  2088. }
  2089. OutputRequiredFilesAst::~OutputRequiredFilesAst()
  2090. {
  2091. }
  2092. void OutputRequiredFilesAst::writeBack( QString& ) const
  2093. {
  2094. }
  2095. bool OutputRequiredFilesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2096. {
  2097. if(func.name.toLower()!="output_required_files" || func.arguments.count()!=2)
  2098. return false;
  2099. m_srcFile=func.arguments[0].value;
  2100. m_outputFile=func.arguments[1].value;
  2101. return true;
  2102. }
  2103. ProjectAst::ProjectAst()
  2104. {
  2105. }
  2106. ProjectAst::~ProjectAst()
  2107. {
  2108. }
  2109. void ProjectAst::writeBack( QString& ) const
  2110. {
  2111. }
  2112. bool ProjectAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2113. {
  2114. if ( func.name.toLower() != "project" )
  2115. return false;
  2116. if ( func.arguments.size() < 1 )
  2117. return false;
  2118. m_projectName = func.arguments[0].value;
  2119. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  2120. for ( it = func.arguments.begin()+1; it != itEnd; ++it )
  2121. {
  2122. CMakeFunctionArgument arg = ( *it );
  2123. if ( arg.value == "CXX" )
  2124. m_useCpp = true;
  2125. else if ( arg.value == "C" )
  2126. m_useC = true;
  2127. else if ( arg.value == "Java" )
  2128. m_useJava = true;
  2129. else
  2130. return false;
  2131. }
  2132. return true;
  2133. }
  2134. QtWrapCppAst::QtWrapCppAst()
  2135. {
  2136. }
  2137. QtWrapCppAst::~QtWrapCppAst()
  2138. {
  2139. }
  2140. void QtWrapCppAst::writeBack( QString& ) const
  2141. {
  2142. }
  2143. bool QtWrapCppAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2144. {
  2145. return false;
  2146. }
  2147. QtWrapUiAst::QtWrapUiAst()
  2148. {
  2149. }
  2150. QtWrapUiAst::~QtWrapUiAst()
  2151. {
  2152. }
  2153. void QtWrapUiAst::writeBack( QString& ) const
  2154. {
  2155. }
  2156. bool QtWrapUiAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2157. {
  2158. return false;
  2159. }
  2160. RemoveAst::RemoveAst()
  2161. {
  2162. }
  2163. RemoveAst::~RemoveAst()
  2164. {
  2165. }
  2166. void RemoveAst::writeBack( QString& ) const
  2167. {
  2168. }
  2169. bool RemoveAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2170. {
  2171. if ( func.name.toLower() != "remove" || func.arguments.isEmpty())
  2172. return false;
  2173. m_variableName = func.arguments[0].value;
  2174. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  2175. for ( it = func.arguments.begin()+1; it != itEnd; ++it )
  2176. {
  2177. m_values.append(it->value);
  2178. }
  2179. return !m_values.isEmpty();
  2180. }
  2181. RemoveDefinitionsAst::RemoveDefinitionsAst()
  2182. {
  2183. }
  2184. RemoveDefinitionsAst::~RemoveDefinitionsAst()
  2185. {
  2186. }
  2187. void RemoveDefinitionsAst::writeBack( QString& ) const
  2188. {
  2189. }
  2190. bool RemoveDefinitionsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2191. {
  2192. if ( func.name.toLower() != "remove_definitions")
  2193. return false;
  2194. QList<CMakeFunctionArgument>::const_iterator it, itEnd = func.arguments.end();
  2195. for ( it = func.arguments.begin(); it != itEnd; ++it )
  2196. {
  2197. m_definitions.append(it->value);
  2198. }
  2199. return !m_definitions.isEmpty();
  2200. }
  2201. SeparateArgumentsAst::SeparateArgumentsAst()
  2202. {
  2203. }
  2204. SeparateArgumentsAst::~SeparateArgumentsAst()
  2205. {
  2206. }
  2207. void SeparateArgumentsAst::writeBack( QString& ) const
  2208. {
  2209. }
  2210. bool SeparateArgumentsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2211. {
  2212. if ( func.name.toLower() != "separate_arguments" || func.arguments.count()==1)
  2213. return false;
  2214. m_variableName=func.arguments.first().value;
  2215. return true;
  2216. }
  2217. SetAst::SetAst()
  2218. {
  2219. }
  2220. SetAst::~SetAst()
  2221. {
  2222. }
  2223. void SetAst::writeBack( QString& ) const
  2224. {
  2225. }
  2226. bool SetAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2227. {
  2228. if ( func.name.toLower() != "set" )
  2229. return false;
  2230. if ( func.arguments.size() < 1 )
  2231. return false;
  2232. m_variableName = func.arguments[0].value;
  2233. int argSize = func.arguments.size();
  2234. //look for the FORCE argument. Thanks to the CMake folks for letting
  2235. //me read their code
  2236. m_forceStoring = ( argSize > 4 && func.arguments.last().value == "FORCE" );
  2237. m_storeInCache = ( argSize > 3 && func.arguments[argSize - 3 - ( m_forceStoring ? 1 : 0 )].value == "CACHE" );
  2238. int numCacheArgs = ( m_storeInCache ? 3 : 0 );
  2239. int numForceArgs = ( m_forceStoring ? 1 : 0 );
  2240. if ( argSize > 1 + numCacheArgs + numForceArgs )
  2241. {
  2242. QList<CMakeFunctionArgument> args = func.arguments;
  2243. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  2244. it = args.begin() + 1;
  2245. itEnd = args.end() - numCacheArgs - numForceArgs;
  2246. for ( ; it != itEnd; ++it )
  2247. m_values.append( it->value );
  2248. }
  2249. //catch some simple things. if CACHE is the last or next to last arg or if
  2250. //FORCE was used without CACHE, then there's a problem.
  2251. if ( func.arguments.last().value == "CACHE" ||
  2252. ( argSize > 1 && func.arguments[argSize - 2].value == "CACHE" ) ||
  2253. m_forceStoring && !m_storeInCache )
  2254. {
  2255. return false;
  2256. }
  2257. return true;
  2258. }
  2259. SetDirectoryPropsAst::SetDirectoryPropsAst()
  2260. {
  2261. }
  2262. SetDirectoryPropsAst::~SetDirectoryPropsAst()
  2263. {
  2264. }
  2265. void SetDirectoryPropsAst::writeBack( QString& ) const
  2266. {
  2267. }
  2268. bool SetDirectoryPropsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2269. {
  2270. if(func.name.toLower()!="set_directory_properties" || func.arguments.count()<3)
  2271. return false;
  2272. bool props=false;
  2273. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin();
  2274. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2275. QString prop;
  2276. for(; it!=itEnd; ++it)
  2277. {
  2278. if(it->value=="PROPERTIES")
  2279. {
  2280. props=true;
  2281. continue;
  2282. }
  2283. if(!props)
  2284. {
  2285. return false;
  2286. }
  2287. else
  2288. {
  2289. if(prop.isEmpty())
  2290. prop=it->value;
  2291. else
  2292. {
  2293. m_properties.append(PropPair(prop, it->value));
  2294. prop.clear();
  2295. }
  2296. }
  2297. }
  2298. return prop.isEmpty();
  2299. }
  2300. SetSourceFilesPropsAst::SetSourceFilesPropsAst()
  2301. {
  2302. }
  2303. SetSourceFilesPropsAst::~SetSourceFilesPropsAst()
  2304. {
  2305. }
  2306. void SetSourceFilesPropsAst::writeBack( QString& ) const
  2307. {
  2308. }
  2309. bool SetSourceFilesPropsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2310. {
  2311. if(func.name.toLower()!="set_source_files_properties" || func.arguments.count()<4)
  2312. return false;
  2313. bool props=false;
  2314. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin();
  2315. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2316. QString prop;
  2317. for(; it!=itEnd; ++it)
  2318. {
  2319. if(it->value=="PROPERTIES")
  2320. {
  2321. props=true;
  2322. continue;
  2323. }
  2324. if(!props)
  2325. {
  2326. m_files.append(it->value);
  2327. }
  2328. else
  2329. {
  2330. if(prop.isEmpty())
  2331. prop=it->value;
  2332. else
  2333. {
  2334. m_properties.append(PropPair(prop, it->value));
  2335. prop.clear();
  2336. }
  2337. }
  2338. }
  2339. return prop.isEmpty();
  2340. }
  2341. SetTargetPropsAst::SetTargetPropsAst()
  2342. {
  2343. }
  2344. SetTargetPropsAst::~SetTargetPropsAst()
  2345. {
  2346. }
  2347. void SetTargetPropsAst::writeBack( QString& ) const
  2348. {
  2349. }
  2350. bool SetTargetPropsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2351. {
  2352. if(func.name.toLower()!="set_target_properties" || func.arguments.count()<4)
  2353. return false;
  2354. bool props=false;
  2355. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin();
  2356. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2357. QString prop;
  2358. for(; it!=itEnd; ++it)
  2359. {
  2360. if(it->value=="PROPERTIES")
  2361. {
  2362. props=true;
  2363. continue;
  2364. }
  2365. if(!props)
  2366. {
  2367. m_targets.append(it->value);
  2368. }
  2369. else
  2370. {
  2371. if(prop.isEmpty())
  2372. prop=it->value;
  2373. else
  2374. {
  2375. m_properties.append(PropPair(prop, it->value));
  2376. prop.clear();
  2377. }
  2378. }
  2379. }
  2380. return prop.isEmpty();
  2381. }
  2382. SetTestsPropsAst::SetTestsPropsAst()
  2383. {
  2384. }
  2385. SetTestsPropsAst::~SetTestsPropsAst()
  2386. {
  2387. }
  2388. void SetTestsPropsAst::writeBack( QString& ) const
  2389. {
  2390. }
  2391. bool SetTestsPropsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2392. {
  2393. if(func.name.toLower()!="set_tests_properties" || func.arguments.count()<4)
  2394. return false;
  2395. bool props=false;
  2396. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin();
  2397. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2398. QString prop;
  2399. for(; it!=itEnd; ++it)
  2400. {
  2401. if(it->value=="PROPERTIES")
  2402. {
  2403. props=true;
  2404. continue;
  2405. }
  2406. if(!props)
  2407. {
  2408. m_tests.append(it->value);
  2409. }
  2410. else
  2411. {
  2412. if(prop.isEmpty())
  2413. prop=it->value;
  2414. else
  2415. {
  2416. m_properties.append(PropPair(prop, it->value));
  2417. prop.clear();
  2418. }
  2419. }
  2420. }
  2421. return prop.isEmpty();
  2422. }
  2423. SiteNameAst::SiteNameAst()
  2424. {
  2425. }
  2426. SiteNameAst::~SiteNameAst()
  2427. {
  2428. }
  2429. void SiteNameAst::writeBack( QString& ) const
  2430. {
  2431. }
  2432. bool SiteNameAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2433. {
  2434. if(func.name.toLower()!="site_name" || func.arguments.count()!=1)
  2435. return false;
  2436. m_variableName = func.arguments.first().value;
  2437. return true;
  2438. }
  2439. SourceGroupAst::SourceGroupAst()
  2440. {
  2441. }
  2442. SourceGroupAst::~SourceGroupAst()
  2443. {
  2444. }
  2445. void SourceGroupAst::writeBack( QString& ) const
  2446. {
  2447. }
  2448. bool SourceGroupAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2449. {
  2450. if(func.name.toLower()!="source_group" || func.arguments.count()>1)
  2451. return false;
  2452. m_name=func.arguments[0].value;
  2453. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+1;
  2454. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2455. enum Param { None, Regex, Files };
  2456. Param current=None;
  2457. for(; it!=itEnd; ++it)
  2458. {
  2459. if(it->value=="REGULAR_EXPRESSION")
  2460. current=Regex;
  2461. else if(it->value=="FILES")
  2462. current=Files;
  2463. else switch(current)
  2464. {
  2465. case Regex:
  2466. m_regex=it->value;
  2467. case Files:
  2468. m_files.append(it->value);
  2469. break;
  2470. case None:
  2471. return false;
  2472. }
  2473. }
  2474. return !m_regex.isEmpty() || !m_files.isEmpty();
  2475. }
  2476. StringAst::StringAst()
  2477. {
  2478. }
  2479. StringAst::~StringAst()
  2480. {
  2481. }
  2482. void StringAst::writeBack( QString& ) const
  2483. {
  2484. }
  2485. bool StringAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2486. {
  2487. if(func.name.toLower()!="string" || func.arguments.count()<3)
  2488. return false;
  2489. QString stringType=func.arguments[0].value.toUpper();
  2490. if(stringType=="REGEX")
  2491. {
  2492. if(func.arguments.count()<5)
  2493. return false;
  2494. m_type=REGEX;
  2495. QString regexType = func.arguments[1].value.toUpper();
  2496. int outpos=3;
  2497. if(regexType=="MATCH") m_cmdType=MATCH;
  2498. else if(regexType=="MATCHALL") m_cmdType=MATCHALL;
  2499. else if(regexType=="REPLACE") {
  2500. m_cmdType=REGEX_REPLACE;
  2501. m_replace=func.arguments[3].value;
  2502. outpos=4;
  2503. }
  2504. m_regex = func.arguments[2].value;
  2505. m_outputVariable = func.arguments[outpos].value;
  2506. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+outpos+1;
  2507. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2508. for(; it!=itEnd; ++it)
  2509. {
  2510. m_input += it->value;
  2511. }
  2512. }
  2513. else if(stringType=="REPLACE")
  2514. {
  2515. m_type=REPLACE;
  2516. m_regex = func.arguments[1].value;
  2517. m_replace=func.arguments[2].value;
  2518. m_outputVariable = func.arguments[3].value;
  2519. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+4;
  2520. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2521. for(; it!=itEnd; ++it)
  2522. {
  2523. m_input += it->value;
  2524. }
  2525. }
  2526. else if(stringType=="COMPARE")
  2527. {
  2528. if(func.arguments.count()!=5)
  2529. return false;
  2530. m_type=COMPARE;
  2531. QString argumentType=func.arguments[1].value.toUpper();
  2532. if(argumentType=="EQUAL") m_cmdType=EQUAL;
  2533. else if(argumentType=="NOTEQUAL") m_cmdType=NOTEQUAL;
  2534. else if(argumentType=="LESS") m_cmdType=LESS;
  2535. else if(argumentType=="GREATER") m_cmdType=GREATER;
  2536. m_input.append(func.arguments[2].value);
  2537. m_input.append(func.arguments[3].value);
  2538. m_outputVariable = func.arguments[4].value;
  2539. }
  2540. else if(stringType=="ASCII")
  2541. {
  2542. m_type=ASCII;
  2543. QList<CMakeFunctionArgument>::const_iterator it=func.arguments.begin()+1;
  2544. QList<CMakeFunctionArgument>::const_iterator itEnd=func.arguments.end();
  2545. for(; it!=itEnd; ++it)
  2546. {
  2547. m_input += it->value;
  2548. }
  2549. m_input.pop_back(); //We remove the output var
  2550. m_outputVariable = func.arguments.last().value;
  2551. }
  2552. else if(stringType=="CONFIGURE")
  2553. {
  2554. m_type=CONFIGURE;
  2555. m_input += func.arguments[1].value;
  2556. m_outputVariable=func.arguments[2].value;
  2557. int i=3;
  2558. m_only = func.arguments[i].value.toUpper()=="@ONLY";
  2559. if(m_only) i++;
  2560. m_escapeQuotes = func.arguments[i].value.toUpper()=="ESCAPE_QUOTES";
  2561. }
  2562. else if(stringType=="TOUPPER")
  2563. {
  2564. m_type=TOUPPER;
  2565. m_input.append(func.arguments[1].value);
  2566. m_outputVariable = func.arguments[2].value;
  2567. }
  2568. else if(stringType=="TOLOWER")
  2569. {
  2570. m_type=TOLOWER;
  2571. m_input.append(func.arguments[1].value);
  2572. m_outputVariable = func.arguments[2].value;
  2573. }
  2574. else if(stringType=="LENGTH")
  2575. {
  2576. m_type=LENGTH;
  2577. m_input.append(func.arguments[1].value);
  2578. m_outputVariable = func.arguments[2].value;
  2579. }
  2580. else if(stringType=="SUBSTRING")
  2581. {
  2582. if(func.arguments.count()<5)
  2583. return false;
  2584. bool correctBegin, correctLength;
  2585. m_type=SUBSTRING;
  2586. m_input.append(func.arguments[1].value);
  2587. m_begin = func.arguments[2].value.toInt(&correctBegin);
  2588. m_length = func.arguments[3].value.toInt(&correctLength);
  2589. m_outputVariable = func.arguments[4].value;
  2590. if(!correctBegin || !correctLength)
  2591. return false;
  2592. }
  2593. return true;
  2594. }
  2595. SubdirDependsAst::SubdirDependsAst()
  2596. {
  2597. }
  2598. SubdirDependsAst::~SubdirDependsAst()
  2599. {
  2600. }
  2601. void SubdirDependsAst::writeBack( QString& ) const
  2602. {
  2603. }
  2604. bool SubdirDependsAst::parseFunctionInfo( const CMakeFunctionDesc& func)
  2605. {
  2606. if ( func.name.toLower() != "subdir_depends" || func.arguments.isEmpty())
  2607. return false;
  2608. return true;
  2609. }
  2610. SubdirsAst::SubdirsAst() : m_preorder(false)
  2611. {
  2612. }
  2613. SubdirsAst::~SubdirsAst()
  2614. {
  2615. }
  2616. void SubdirsAst::writeBack( QString& ) const
  2617. {
  2618. }
  2619. bool SubdirsAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2620. {
  2621. if ( func.name.toLower() != "subdirs" )
  2622. return false;
  2623. if ( func.arguments.isEmpty() )
  2624. return false;
  2625. bool excludeFromAll=false;
  2626. foreach(CMakeFunctionArgument arg, func.arguments)
  2627. {
  2628. if(arg.value.toLower()=="exclude_from_all")
  2629. excludeFromAll=true;
  2630. else if(arg.value.toLower()=="preorder")
  2631. m_preorder=true;
  2632. else {
  2633. if(excludeFromAll)
  2634. m_exluceFromAll.append(arg.value);
  2635. else
  2636. m_directories.append(arg.value);
  2637. }
  2638. }
  2639. return true;
  2640. }
  2641. TargetLinkLibrariesAst::TargetLinkLibrariesAst()
  2642. {
  2643. }
  2644. TargetLinkLibrariesAst::~TargetLinkLibrariesAst()
  2645. {
  2646. }
  2647. void TargetLinkLibrariesAst::writeBack( QString& ) const
  2648. {
  2649. }
  2650. bool TargetLinkLibrariesAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2651. {
  2652. if ( func.name.toLower() != "target_link_libraries" )
  2653. return false;
  2654. //we don't do variable expansion when parsing like CMake does, so we
  2655. //need to have at least two arguments for target_link_libraries
  2656. if ( func.arguments.size() < 2 )
  2657. return false;
  2658. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  2659. it = func.arguments.begin() + 1;
  2660. itEnd = func.arguments.end();
  2661. for ( ; it != itEnd; ++it )
  2662. {
  2663. CMakeFunctionArgument arg = ( *it );
  2664. if ( arg.value == "debug" )
  2665. {
  2666. ++it;
  2667. if ( it == itEnd )
  2668. return false;
  2669. else
  2670. m_debugLibs.append( it->value );
  2671. }
  2672. else if ( arg.value == "optimized" )
  2673. {
  2674. ++it;
  2675. if ( it == itEnd )
  2676. return false;
  2677. else
  2678. m_optimizedLibs.append( it->value );
  2679. }
  2680. else
  2681. m_otherLibs.append( arg.value );
  2682. }
  2683. return true;
  2684. }
  2685. TryCompileAst::TryCompileAst()
  2686. {
  2687. }
  2688. TryCompileAst::~TryCompileAst()
  2689. {
  2690. }
  2691. void TryCompileAst::writeBack( QString& ) const
  2692. {
  2693. }
  2694. bool TryCompileAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2695. {
  2696. if ( func.name.toLower() != "try_compile" || func.arguments.size() < 3)
  2697. return false;
  2698. m_resultName=func.arguments[0].value;
  2699. m_binDir=func.arguments[1].value;
  2700. m_source=func.arguments[2].value;
  2701. enum Param { None, CMakeFlags, CompileDefinitions, OutputVariable, CopyFile };
  2702. Param current=None;
  2703. QList<CMakeFunctionArgument>::const_iterator it, itEnd;
  2704. it = func.arguments.begin() + 3;
  2705. itEnd = func.arguments.end();
  2706. //FIXME:Maybe could look for errors
  2707. for ( ; it != itEnd; ++it )
  2708. {
  2709. if(it->value=="CMAKE_FLAGS") current=CMakeFlags;
  2710. else if(it->value=="COMPILE_DEFINITIONS") current=CompileDefinitions;
  2711. else if(it->value=="OUTPUT_VARIABLE") current=OutputVariable;
  2712. else if(it->value=="COPY_FILE") current=OutputVariable;
  2713. else switch(current)
  2714. {
  2715. case None:
  2716. if(m_projectName.isEmpty())
  2717. m_projectName=it->value;
  2718. else
  2719. m_targetName=it->value;
  2720. current=None;
  2721. break;
  2722. case CMakeFlags:
  2723. m_cmakeFlags.append(it->value);
  2724. break;
  2725. case CompileDefinitions:
  2726. m_compileDefinitions.append(it->value);
  2727. break;
  2728. case OutputVariable:
  2729. m_outputName=it->value;
  2730. current=None;
  2731. break;
  2732. case CopyFile:
  2733. m_copyFile=it->value;
  2734. current=None;
  2735. break;
  2736. }
  2737. }
  2738. return true;
  2739. }
  2740. TryRunAst::TryRunAst()
  2741. {
  2742. }
  2743. TryRunAst::~TryRunAst()
  2744. {
  2745. }
  2746. void TryRunAst::writeBack( QString& ) const
  2747. {
  2748. }
  2749. bool TryRunAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2750. {
  2751. if(func.name.toLower()!="try_run" || func.arguments.count()<4)
  2752. return false;
  2753. enum Actions { None, CMakeFlags, CompileDefs, OutputVariable, Args };
  2754. Actions act;
  2755. unsigned int i=0;
  2756. foreach(CMakeFunctionArgument arg, func.arguments) {
  2757. QString val=arg.value.toLower();
  2758. if(i<4)
  2759. act=None;
  2760. if(i==0)
  2761. m_runResultVar=arg.value;
  2762. else if(i==1)
  2763. m_compileResultVar=arg.value;
  2764. else if(i==2)
  2765. m_binDir=arg.value;
  2766. else if(i==3)
  2767. m_srcFile=arg.value;
  2768. else if(val=="cmake_flags")
  2769. act=CMakeFlags;
  2770. else if(val=="compile_definitions")
  2771. act=CompileDefs;
  2772. else if(val=="output_variable")
  2773. act=OutputVariable;
  2774. else if(val=="args")
  2775. act=Args;
  2776. else switch(act) {
  2777. case None:
  2778. return false;
  2779. case CMakeFlags:
  2780. m_cmakeFlags.append(arg.value);
  2781. break;
  2782. case CompileDefs:
  2783. m_compileDefs.append(arg.value);
  2784. case OutputVariable:
  2785. m_outputVar=arg.value;
  2786. break;
  2787. case Args:
  2788. m_args.append(arg.value);
  2789. break;
  2790. }
  2791. i++;
  2792. }
  2793. return true;
  2794. }
  2795. UseMangledMesaAst::UseMangledMesaAst()
  2796. {
  2797. }
  2798. UseMangledMesaAst::~UseMangledMesaAst()
  2799. {
  2800. }
  2801. void UseMangledMesaAst::writeBack( QString& ) const
  2802. {
  2803. }
  2804. bool UseMangledMesaAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2805. {
  2806. if(func.name.toLower()!="path_to_mesa" || func.arguments.count()!=2)
  2807. return false;
  2808. m_pathToMesa=func.arguments[0].value;
  2809. m_outputDir=func.arguments[1].value;
  2810. return true;
  2811. }
  2812. UtilitySourceAst::UtilitySourceAst()
  2813. {
  2814. }
  2815. UtilitySourceAst::~UtilitySourceAst()
  2816. {
  2817. }
  2818. void UtilitySourceAst::writeBack( QString& ) const
  2819. {
  2820. }
  2821. bool UtilitySourceAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2822. {
  2823. if(func.name.toLower()!="utility_source" || func.arguments.count()<3)
  2824. return false;
  2825. unsigned int i=0;
  2826. foreach(CMakeFunctionArgument arg, func.arguments) {
  2827. if(i==0)
  2828. m_cacheEntry=arg.value;
  2829. else if(i==1)
  2830. m_executableName=arg.value;
  2831. else if(i==2)
  2832. m_pathToSource=arg.value;
  2833. else
  2834. m_fileList.append(arg.value);
  2835. }
  2836. return true;
  2837. }
  2838. VariableRequiresAst::VariableRequiresAst()
  2839. {
  2840. }
  2841. VariableRequiresAst::~VariableRequiresAst()
  2842. {
  2843. }
  2844. void VariableRequiresAst::writeBack( QString& ) const
  2845. {
  2846. }
  2847. bool VariableRequiresAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2848. {
  2849. if(func.name.toLower()!="variable_requires" || func.arguments.count()<2)
  2850. return false;
  2851. unsigned int i=0;
  2852. foreach(CMakeFunctionArgument arg, func.arguments) {
  2853. if(i==0)
  2854. m_testVariable=arg.value;
  2855. else if(i==1)
  2856. m_resultVariable=arg.value;
  2857. else
  2858. m_requiredVariables.append(arg.value);
  2859. i++;
  2860. }
  2861. return true;
  2862. }
  2863. VtkMakeInstantiatorAst::VtkMakeInstantiatorAst()
  2864. {
  2865. }
  2866. VtkMakeInstantiatorAst::~VtkMakeInstantiatorAst()
  2867. {
  2868. }
  2869. void VtkMakeInstantiatorAst::writeBack( QString& ) const
  2870. {
  2871. }
  2872. bool VtkMakeInstantiatorAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2873. {
  2874. return false;
  2875. }
  2876. VtkWrapJavaAst::VtkWrapJavaAst()
  2877. {
  2878. }
  2879. VtkWrapJavaAst::~VtkWrapJavaAst()
  2880. {
  2881. }
  2882. void VtkWrapJavaAst::writeBack( QString& ) const
  2883. {
  2884. }
  2885. bool VtkWrapJavaAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2886. {
  2887. return false;
  2888. }
  2889. VtkWrapPythonAst::VtkWrapPythonAst()
  2890. {
  2891. }
  2892. VtkWrapPythonAst::~VtkWrapPythonAst()
  2893. {
  2894. }
  2895. void VtkWrapPythonAst::writeBack( QString& ) const
  2896. {
  2897. }
  2898. bool VtkWrapPythonAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2899. {
  2900. return false;
  2901. }
  2902. VtkWrapTclAst::VtkWrapTclAst()
  2903. {
  2904. }
  2905. VtkWrapTclAst::~VtkWrapTclAst()
  2906. {
  2907. }
  2908. void VtkWrapTclAst::writeBack( QString& ) const
  2909. {
  2910. }
  2911. bool VtkWrapTclAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2912. {
  2913. return false;
  2914. }
  2915. WhileAst::WhileAst()
  2916. {
  2917. }
  2918. WhileAst::~WhileAst()
  2919. {
  2920. }
  2921. void WhileAst::writeBack( QString& ) const
  2922. {
  2923. }
  2924. bool WhileAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2925. {
  2926. if(func.name.toLower()!="while" || func.arguments.isEmpty())
  2927. return false;
  2928. foreach(CMakeFunctionArgument arg, func.arguments)
  2929. {
  2930. m_condition.append(arg.value);
  2931. }
  2932. return true;
  2933. }
  2934. WriteFileAst::WriteFileAst()
  2935. {
  2936. }
  2937. WriteFileAst::~WriteFileAst()
  2938. {
  2939. }
  2940. void WriteFileAst::writeBack( QString& ) const
  2941. {
  2942. }
  2943. bool WriteFileAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2944. {
  2945. if(func.name.toLower()!="write_file" || func.arguments.count()<2)
  2946. return false;
  2947. m_filename=func.arguments[0].value;
  2948. m_message=func.arguments[1].value;
  2949. if(func.arguments.count()>=3)
  2950. {
  2951. if(func.arguments[2].value=="APPEND")
  2952. {
  2953. m_append=true;
  2954. }
  2955. if(func.arguments.count()>(3+m_append))
  2956. return false;
  2957. }
  2958. return true;
  2959. }
  2960. CustomInvokationAst::CustomInvokationAst()
  2961. {
  2962. }
  2963. CustomInvokationAst::~CustomInvokationAst()
  2964. {
  2965. }
  2966. void CustomInvokationAst::writeBack( QString& ) const
  2967. {
  2968. }
  2969. bool CustomInvokationAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2970. {
  2971. m_function = func;
  2972. m_arguments = func.arguments;
  2973. return true;
  2974. }
  2975. BreakAst::BreakAst()
  2976. {
  2977. }
  2978. BreakAst::~BreakAst()
  2979. {
  2980. }
  2981. void BreakAst::writeBack( QString& ) const
  2982. {
  2983. }
  2984. bool BreakAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2985. {
  2986. return func.arguments.isEmpty() && func.name.toLower()=="break";
  2987. }
  2988. CMakePolicyAst::CMakePolicyAst()
  2989. {
  2990. }
  2991. CMakePolicyAst::~CMakePolicyAst()
  2992. {
  2993. }
  2994. void CMakePolicyAst::writeBack( QString& ) const
  2995. {
  2996. }
  2997. bool CMakePolicyAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  2998. {
  2999. if(func.name.toLower()!="cmake_policy" || func.arguments.isEmpty())
  3000. return false;
  3001. const QString &first=func.arguments[0].value;
  3002. if(first=="VERSION")
  3003. {
  3004. QRegExp rx("([0-9]*).([0-9]*).?([0-9]*)");
  3005. rx.indexIn(func.arguments[1].value);
  3006. QStringList caps=rx.capturedTexts();
  3007. caps.erase(caps.begin());
  3008. foreach(QString s, caps)
  3009. {
  3010. bool correct;
  3011. m_version.append(s.toInt(&correct));
  3012. if(!correct)
  3013. return false;
  3014. }
  3015. }
  3016. else if(first=="SET" && func.arguments.count()==3)
  3017. {
  3018. QRegExp rx("CMP<([1-9]*)>");
  3019. rx.indexIn(func.arguments[1].value);
  3020. QStringList cmpValue=rx.capturedTexts();
  3021. if(cmpValue.count()==1)
  3022. {
  3023. m_policyNum=cmpValue[1].toInt();
  3024. }
  3025. else
  3026. return false;
  3027. if(func.arguments[2].value=="OLD")
  3028. m_isNew=false;
  3029. else if(func.arguments[2].value=="NEW")
  3030. m_isNew=true;
  3031. else
  3032. return false;
  3033. return true;
  3034. } else if(first=="PUSH") {
  3035. m_action=PUSH;
  3036. return func.arguments.isEmpty();
  3037. } else if(first=="POP") {
  3038. m_action=POP;
  3039. return func.arguments.isEmpty();
  3040. }
  3041. return false;
  3042. }
  3043. ExportAst::ExportAst()
  3044. {
  3045. }
  3046. ExportAst::~ExportAst()
  3047. {
  3048. }
  3049. void ExportAst::writeBack( QString& ) const
  3050. {
  3051. }
  3052. bool ExportAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  3053. {
  3054. if(func.name.toLower()!="export" || func.arguments.count() < 2 || func.arguments[0].value!="TARGETS")
  3055. return false;
  3056. enum Option { TARGETS, NAMESPACE, FILE };
  3057. Option opt=TARGETS;
  3058. foreach(const CMakeFunctionArgument& arg, func.arguments)
  3059. {
  3060. if(arg.value=="TARGETS")
  3061. {
  3062. if(opt!=TARGETS)
  3063. return false;
  3064. }
  3065. else if(arg.value=="NAMESPACE")
  3066. {
  3067. opt=NAMESPACE;
  3068. }
  3069. else if(arg.value=="FILE")
  3070. {
  3071. opt=FILE;
  3072. }
  3073. else if(arg.value=="APPEND")
  3074. {
  3075. m_append=true;
  3076. }
  3077. else
  3078. {
  3079. switch(opt)
  3080. {
  3081. case TARGETS:
  3082. m_targets.append(arg.value);
  3083. break;
  3084. case NAMESPACE:
  3085. m_targetNamespace=arg.value;
  3086. break;
  3087. case FILE:
  3088. m_filename=arg.value;
  3089. break;
  3090. }
  3091. opt=TARGETS;
  3092. }
  3093. }
  3094. return !m_targets.isEmpty();
  3095. }
  3096. ReturnAst::ReturnAst()
  3097. {
  3098. }
  3099. ReturnAst::~ReturnAst()
  3100. {
  3101. }
  3102. void ReturnAst::writeBack( QString& ) const
  3103. {
  3104. }
  3105. bool ReturnAst::parseFunctionInfo( const CMakeFunctionDesc& func )
  3106. {
  3107. return func.arguments.isEmpty() && func.name.toLower()=="return";
  3108. }