PageRenderTime 59ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/php-pear-CodeGen-PECL-1.1.3/CodeGen_PECL-1.1.3/PECL/ExtensionParser.php

#
PHP | 1504 lines | 1163 code | 295 blank | 46 comment | 232 complexity | 718910ffd1148fefd5e226dc8cacb4b6 MD5 | raw file
  1. <?php
  2. /**
  3. * Extension to the generic parser that adds PECL specific tags
  4. *
  5. * PHP versions 5
  6. *
  7. * LICENSE: This source file is subject to version 3.0 of the PHP license
  8. * that is available through the world-wide-web at the following URI:
  9. * http://www.php.net/license/3_0.txt. If you did not receive a copy of
  10. * the PHP License and are unable to obtain it through the web, please
  11. * send a note to license@php.net so we can mail you a copy immediately.
  12. *
  13. * @category Tools and Utilities
  14. * @package CodeGen
  15. * @author Hartmut Holzgraefe <hartmut@php.net>
  16. * @copyright 2005-2008 Hartmut Holzgraefe
  17. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  18. * @version CVS: $Id: ExtensionParser.php,v 1.64 2007/04/26 11:23:08 hholzgra Exp $
  19. * @link http://pear.php.net/package/CodeGen
  20. */
  21. /**
  22. * includes
  23. */
  24. require_once "CodeGen/ExtensionParser.php";
  25. require_once "CodeGen/PECL/Maintainer.php";
  26. /**
  27. * Extension to the generic parser that adds PECL specific tags
  28. *
  29. * @category Tools and Utilities
  30. * @package CodeGen
  31. * @author Hartmut Holzgraefe <hartmut@php.net>
  32. * @copyright 2005-2008 Hartmut Holzgraefe
  33. * @license http://www.php.net/license/3_0.txt PHP License 3.0
  34. * @version Release: @package_version@
  35. * @link http://pear.php.net/package/CodeGen
  36. */
  37. class CodeGen_PECL_ExtensionParser
  38. extends CodeGen_ExtensionParser
  39. {
  40. function setInputFile($filename)
  41. {
  42. $this->extension->addPackageFile("copy", $filename);
  43. return parent::setInputFile($filename);
  44. }
  45. function tagstart_extension_maintainer($attr)
  46. {
  47. $this->pushHelper(new CodeGen_PECL_Maintainer);
  48. return $this->noAttributes($attr);
  49. }
  50. function tagstart_extension_release($attr)
  51. {
  52. $this->pushHelper(new CodeGen_PECL_Release);
  53. return $this->noAttributes($attr);
  54. }
  55. function tagstart_extension_changelog($attr)
  56. {
  57. $this->verbatim();
  58. return $this->noAttributes($attr);
  59. }
  60. function tagstart_extension_function($attr)
  61. {
  62. $err = $this->checkAttributes($attr, array("name", "role", "if"));
  63. if (PEAR::isError($err)) {
  64. return $err;
  65. }
  66. $this->pushHelper(new CodeGen_PECL_Element_Function);
  67. $role = isset($attr["role"]) ? $attr["role"] : "public";
  68. if (isset($attr["name"])) {
  69. if ($role == "public" && $this->extension->getPrefix()) {
  70. $err = $this->helper->setName($this->extension->getPrefix()."_".$attr["name"]);
  71. } else {
  72. $err = $this->helper->setName($attr["name"]);
  73. }
  74. if (PEAR::isError($err)) {
  75. return $err;
  76. }
  77. } else {
  78. return PEAR::raiseError("'name' attribut for <function> missing");
  79. }
  80. $err = $this->helper->setRole($role);
  81. if (PEAR::isError($err)) {
  82. return $err;
  83. }
  84. if (isset($attr["if"])) {
  85. $this->helper->setIfCondition($attr["if"]);
  86. }
  87. $groupIfs = $this->getGroupAttributeStack("if");
  88. if (is_array($groupIfs)) {
  89. foreach($groupIfs as $if) {
  90. $this->helper->addIfCondition($if);
  91. }
  92. }
  93. return true;
  94. }
  95. function tagstart_extension_functions_function($attr) {
  96. return $this->tagstart_extension_function($attr);
  97. }
  98. function tagstart_group_function($attr) {
  99. return $this->tagstart_extension_function($attr);
  100. }
  101. function tagstart_function_summary($attr)
  102. {
  103. return $this->noAttributes($attr);
  104. }
  105. function tagend_function_summary($attr, $data)
  106. {
  107. return $this->helper->setSummary(trim($data));
  108. }
  109. function tagstart_function_description($attr)
  110. {
  111. $this->verbatim();
  112. return $this->noAttributes($attr);
  113. }
  114. function tagend_function_description($attr, $data)
  115. {
  116. return $this->helper->setDescription(CodeGen_Tools_IndentC::linetrim($data));
  117. }
  118. function tagstart_function_proto($attr)
  119. {
  120. return $this->noAttributes($attr);
  121. }
  122. function tagend_function_proto($attr, $data)
  123. {
  124. return $this->helper->setProto(trim($data), $this->extension);
  125. }
  126. function tagstart_function_code($attr)
  127. {
  128. $err = $this->checkAttributes($attr, array("src"));
  129. if (PEAR::isError($err)) {
  130. return $err;
  131. }
  132. if (isset($attr["src"])) {
  133. if (!file_exists($attr["src"])) {
  134. return PEAR::raiseError("'src' file '$attr[src]' not found in <code>");
  135. }
  136. if (!is_readable($attr["src"])) {
  137. return PEAR::raiseError("Cannot read 'src' file '$attr[src]' in <code>");
  138. }
  139. }
  140. }
  141. function tagend_function_code($attr, $data, $line=0, $file="")
  142. {
  143. if (isset($attr["src"])) {
  144. return $this->helper->setCode(CodeGen_Tools_IndentC::linetrim(file_get_contents($attr["src"])));
  145. } else {
  146. return $this->helper->setCode($data, $line, $file);
  147. }
  148. }
  149. function tagstart_function_notest($attr)
  150. {
  151. return $this->noAttributes($attr);
  152. }
  153. function tagend_function_notest($attr, $data)
  154. {
  155. return $this->helper->setTestCode("");
  156. }
  157. function tagstart_function_test($attr)
  158. {
  159. return $this->noAttributes($attr);
  160. }
  161. function tagstart_function_test_description($attr)
  162. {
  163. return $this->noAttributes($attr);
  164. }
  165. function tagend_function_test_description($attr, $data)
  166. {
  167. return $this->helper->setTestDescription(CodeGen_Tools_IndentC::linetrim($data));
  168. }
  169. function tagstart_function_test_code($attr)
  170. {
  171. return $this->noAttributes($attr);
  172. }
  173. function tagend_function_test_code($attr, $data)
  174. {
  175. return $this->helper->setTestCode(CodeGen_Tools_IndentC::linetrim($data));
  176. }
  177. function tagstart_function_test_result($attr)
  178. {
  179. return $this->checkAttributes($attr, array("mode"));
  180. }
  181. function tagend_function_test_result($attr, $data)
  182. {
  183. return $this->helper->setTestResult(CodeGen_Tools_IndentC::linetrim($data), @$attr['mode']);
  184. }
  185. function tagstart_function_test_ini($attr)
  186. {
  187. return $this->noAttributes($attr);
  188. }
  189. function tagend_function_test_ini($attr, $data)
  190. {
  191. return $this->helper->setTestIni(CodeGen_Tools_IndentC::linetrim($data));
  192. }
  193. function tagstart_function_test_skipif($attr)
  194. {
  195. return $this->noAttributes($attr);
  196. }
  197. function tagend_function_test_skipif($attr, $data)
  198. {
  199. return $this->helper->setTestSkipIf(CodeGen_Tools_IndentC::linetrim($data));
  200. }
  201. function tagend_extension_function($attr, $data)
  202. {
  203. $err = $this->extension->addFunction($this->helper);
  204. $this->popHelper();
  205. return $err;
  206. }
  207. function tagend_extension_functions_function($attr, $data)
  208. {
  209. return $this->tagend_extension_function($attr, $data);
  210. }
  211. function tagend_group_function($attr, $data)
  212. {
  213. return $this->tagend_extension_function($attr, $data);
  214. }
  215. function tagstart_functions($attr) {
  216. return $this->noAttributes($attr);
  217. }
  218. function tagstart_extension_resource($attr)
  219. {
  220. $err = $this->checkAttributes($attr, array("name", "payload", "alloc", "if"));
  221. if (PEAR::isError($err)) {
  222. return $err;
  223. }
  224. $this->pushHelper(new CodeGen_PECL_Element_Resource);
  225. if (isset($attr["name"])) {
  226. $err = $this->helper->setName($attr["name"]);
  227. if (PEAR::isError($err)) {
  228. return $err;
  229. }
  230. } else {
  231. return PEAR::raiseError("name attribut for resource missing");
  232. }
  233. if (isset($attr["payload"])) {
  234. $err = $this->helper->setPayload($attr["payload"]);
  235. if (PEAR::isError($err)) {
  236. return $err;
  237. }
  238. } else {
  239. return PEAR::raiseError("payload attribut for resource missing");
  240. }
  241. if (isset($attr["alloc"])) {
  242. $value = $this->toBool($attr["alloc"], "alloc");
  243. if (PEAR::isError($value)) {
  244. return $value;
  245. }
  246. $err = $this->helper->setAlloc($value);
  247. if (PEAR::isError($err)) {
  248. return $err;
  249. }
  250. }
  251. if (isset($attr["if"])) {
  252. $this->helper->setIfCondition($attr["if"]);
  253. }
  254. $groupIfs = $this->getGroupAttributeStack("if");
  255. if (is_array($groupIfs)) {
  256. foreach($groupIfs as $if) {
  257. $this->helper->addIfCondition($if);
  258. }
  259. }
  260. return true;
  261. }
  262. function tagstart_resources_resource($attr)
  263. {
  264. return $this->tagstart_extension_resource($attr);
  265. }
  266. function tagstart_group_resource($attr)
  267. {
  268. return $this->tagstart_extension_resource($attr);
  269. }
  270. function tagend_resource_destruct($attr, $data)
  271. {
  272. return $this->helper->setDestruct(CodeGen_Tools_IndentC::linetrim($data));
  273. }
  274. function tagend_resource_description($attr, $data)
  275. {
  276. return $this->helper->setDescription(CodeGen_Tools_IndentC::linetrim($data));
  277. }
  278. function tagend_extension_resource($attr, $data)
  279. {
  280. $err = $this->extension->addResource($this->helper);
  281. $this->popHelper();
  282. return $err;
  283. }
  284. function tagend_resources_resource($attr, $data) {
  285. return $this->tagend_extension_resource($attr, $data);
  286. }
  287. function tagend_group_resource($attr, $data) {
  288. return $this->tagend_extension_resource($attr, $data);
  289. }
  290. function tagend_resources($attr, $data) {
  291. return true;
  292. }
  293. function tagend_extension_logo($attr, $data)
  294. {
  295. // TODO checks
  296. if (!isset($attr["name"])) {
  297. $attr["name"] = $this->extension->getName();
  298. }
  299. $logo = new CodeGen_PECL_Element_Logo($attr["name"]);
  300. if (!isset($attr["mimetype"])) {
  301. $attr["mimetype"] = false;
  302. }
  303. if (isset($attr["src"])) {
  304. $err = $logo->loadFile($attr["src"], $attr["mimetype"]);
  305. if (PEAR::isError($err)) {
  306. return $err;
  307. }
  308. } else {
  309. // we support base64 encoded embedded data only
  310. $decoded = base64_decode($data);
  311. if (!is_string($decoded)) {
  312. return PEAR::raiseError("only base64 encoded image data is supported for embedded data");
  313. }
  314. $err = $logo->setData($decoded, $attr["mimetype"]);
  315. if (PEAR::isError($err)) {
  316. return $err;
  317. }
  318. }
  319. return $this->extension->addLogo($logo);
  320. }
  321. function tagend_group_logo($attr, $data)
  322. {
  323. $this->tagend_extension_logo($attr, $data);
  324. }
  325. function tagstart_extension_constants($attr) {
  326. $this->pushHelper($attr);
  327. }
  328. function tagend_extension_constant($attr, $data)
  329. {
  330. $const = new CodeGen_PECL_Element_Constant;
  331. if (isset($attr["name"])) {
  332. $err = $const->setName($attr["name"]);
  333. if (PEAR::isError($err)) {
  334. return $err;
  335. }
  336. } else {
  337. return PEAR::raiseError("name attribut for constant missing");
  338. }
  339. if (isset($attr["type"])) {
  340. $err = $const->setType($attr["type"]);
  341. } else {
  342. $err = $const->setType("int"); // default
  343. }
  344. if (PEAR::isError($err)) {
  345. return $err;
  346. }
  347. if (isset($attr["value"])) {
  348. $err = $const->setValue($attr["value"]);
  349. } else {
  350. $const->setDefine(false);
  351. $err = $const->setValue($attr["name"]); // default -> mimic a C #define or enum value
  352. }
  353. if (PEAR::isError($err)) {
  354. return $err;
  355. }
  356. if (isset($attr["define"])) {
  357. $err = $const->setDefine($attr["define"]);
  358. }
  359. if (PEAR::isError($err)) {
  360. return $err;
  361. }
  362. if (isset($attr["group"])) {
  363. $err = $const->setGroup($attr["group"]);
  364. } else if (is_array($this->helper) && isset($this->helper["group"])) {
  365. $err = $const->setGroup($this->helper["group"]);
  366. }
  367. if (PEAR::isError($err)) {
  368. return $err;
  369. }
  370. if (isset($attr["if"])) {
  371. $condition = ($attr["if"] == "yes") ? $attr["name"] : $attr["if"];
  372. $const->setIfCondition($condition);
  373. } else if (is_array($this->helper) && isset($this->helper["if"])) {
  374. $const->setIfCondition($this->helper["if"]);
  375. }
  376. $groupIfs = $this->getGroupAttributeStack("if");
  377. if (is_array($groupIfs)) {
  378. foreach($groupIfs as $if) {
  379. $const->addIfCondition($if);
  380. }
  381. }
  382. $const->setDesc(CodeGen_Tools_IndentC::linetrim($data));
  383. return $this->extension->addConstant($const);
  384. }
  385. function tagend_constants_constant($attr, $data)
  386. {
  387. return $this->tagend_extension_constant($attr, $data);
  388. }
  389. function tagend_group_constant($attr, $data)
  390. {
  391. return $this->tagend_extension_constant($attr, $data);
  392. }
  393. function tagend_constants($attr, $data) {
  394. $this->popHelper();
  395. return true;
  396. }
  397. function tagend_extension_global($attr, $data)
  398. {
  399. $global = new CodeGen_PECL_Element_Global;
  400. if (isset($attr["name"])) {
  401. $err = $global->setName($attr["name"]);
  402. if (PEAR::isError($err)) {
  403. return $err;
  404. }
  405. } else {
  406. return PEAR::raiseError("name attribut for global missing");
  407. }
  408. if (isset($attr["type"])) {
  409. $err = $global->setType($attr["type"]);
  410. if (PEAR::isError($err)) {
  411. return $err;
  412. }
  413. } else {
  414. return PEAR::raiseError("type attribut for global missing");
  415. }
  416. if (isset($attr["value"])) {
  417. $err = $global->setValue($attr["value"]);
  418. if (PEAR::isError($err)) {
  419. return $err;
  420. }
  421. }
  422. if (isset($attr["if"])) {
  423. $global->setIfCondition($attr["if"]);
  424. }
  425. $groupIfs = $this->getGroupAttributeStack("if");
  426. if (is_array($groupIfs)) {
  427. foreach($groupIfs as $if) {
  428. $global->addIfCondition($if);
  429. }
  430. }
  431. return $this->extension->addGlobal($global);
  432. }
  433. function tagend_globals_global($attr, $data)
  434. {
  435. return $this->tagend_extension_global($attr, $data);
  436. }
  437. function tagend_group_global($attr, $data)
  438. {
  439. return $this->tagend_extension_global($attr, $data);
  440. }
  441. function tagend_extension_phpini($attr, $data)
  442. {
  443. $ini = new CodeGen_PECL_Element_Ini;
  444. if (isset($attr["name"])) {
  445. $err = $ini->setName($attr["name"]);
  446. if (PEAR::isError($err)) {
  447. return $err;
  448. }
  449. } else {
  450. return PEAR::raiseError("name attribut for php.ini directive missing");
  451. }
  452. if (isset($attr["type"])) {
  453. $err = $ini->setType($attr["type"]);
  454. if (PEAR::isError($err)) {
  455. return $err;
  456. }
  457. }
  458. if (isset($attr["value"])) {
  459. $err = $ini->setValue($attr["value"]);
  460. if (PEAR::isError($err)) {
  461. return $err;
  462. }
  463. }
  464. if (isset($attr["access"])) {
  465. $err = $ini->setAccess($attr["access"]);
  466. if (PEAR::isError($err)) {
  467. return $err;
  468. }
  469. }
  470. if (isset($attr["onupdate"])) {
  471. $err = $ini->setOnUpdate($attr["onupdate"]);
  472. if (PEAR::isError($err)) {
  473. return $err;
  474. }
  475. }
  476. if (isset($attr["if"])) {
  477. $ini->setIfCondition($attr["if"]);
  478. }
  479. $groupIfs = $this->getGroupAttributeStack("if");
  480. if (is_array($groupIfs)) {
  481. foreach($groupIfs as $if) {
  482. $ini->addIfCondition($if);
  483. }
  484. }
  485. $ini->setDesc(CodeGen_Tools_IndentC::linetrim($data));
  486. $err = $this->extension->addPhpini($ini);
  487. if (PEAR::isError($err)) {
  488. return $err;
  489. }
  490. // php.ini settings are stored in modul-global variables
  491. $global = new CodeGen_PECL_Element_Global;
  492. $err = $global->setName($ini->getName());
  493. if (PEAR::isError($err)) {
  494. return $err;
  495. }
  496. $err = $global->setType($ini->getType());
  497. if (PEAR::isError($err)) {
  498. return $err;
  499. }
  500. $global->setIfCondition($ini->getIfCondition());
  501. $err = $this->extension->addGlobal($global);
  502. return $err;
  503. }
  504. function tagend_globals_phpini($attr, $data)
  505. {
  506. return $this->tagend_extension_phpini($attr, $data);
  507. }
  508. function tagend_group_phpini($attr, $data)
  509. {
  510. return $this->tagend_extension_phpini($attr, $data);
  511. }
  512. function tagend_globals($attr, $data) {
  513. return true;
  514. }
  515. function tagstart_deps_lib($attr)
  516. {
  517. $err = $this->checkAttributes($attr, array("name", "platform", "path", "function"));
  518. if (PEAR::isError($err)) {
  519. return $err;
  520. }
  521. if (!isset($attr["name"])) {
  522. return PEAR::raiseError("");
  523. }
  524. if (!isset($attr["platform"])) {
  525. $attr["platform"] = "all";
  526. }
  527. error_log("Warning: Use of <lib> tags out of <with> sections is deprecated");
  528. $lib = new CodeGen_PECL_Dependency_Lib($attr["name"], $attr["platform"]);
  529. if (isset($attr['path'])) {
  530. $lib->setPath($attr['path']);
  531. }
  532. if (isset($attr['function'])) {
  533. $lib->setFunction($attr['function']);
  534. }
  535. $this->extension->addLib($lib);
  536. return true;
  537. }
  538. function tagstart_deps_header($attr)
  539. {
  540. $err = $this->checkAttributes($attr, array("name", "prepend", "path"));
  541. if (PEAR::isError($err)) {
  542. return $err;
  543. }
  544. error_log("Warning: Use of <header> tags out of <with> sections is deprecated");
  545. // TODO check name
  546. $header = new CodeGen_PECL_Dependency_Header($attr["name"]);
  547. if (isset($attr['path'])) {
  548. $header->setPath($attr["path"]);
  549. }
  550. if (isset($attr['prepend'])) {
  551. $header->setPrepend($attr["prepend"]);
  552. }
  553. $this->extension->addHeader($header);
  554. }
  555. function tagstart_deps_extension($attr)
  556. {
  557. $ext = new CodeGen_PECL_Dependency_Extension;
  558. $err = $ext->setName($attr['name']);
  559. if (PEAR::isError($err)) {
  560. return $err;
  561. }
  562. if (isset($attr["type"])) {
  563. $err = $ext->setType($attr['type']);
  564. if (PEAR::isError($err)) {
  565. return $err;
  566. }
  567. }
  568. if (isset($attr["version"]) || isset($attr["rel"])) {
  569. if (!isset($attr["version"])) {
  570. return PEAR::raiseError("'rel' attribut requires 'version' ");
  571. }
  572. if (!isset($attr["rel"])) {
  573. $attr["rel"] = "ge";
  574. }
  575. $err = $ext->setVersion($attr['version'], $attr['rel']);
  576. if (PEAR::isError($err)) {
  577. return $err;
  578. }
  579. }
  580. $this->extension->addOtherExtension($ext);
  581. }
  582. function tagstart_deps_with($attr)
  583. {
  584. $with = new CodeGen_PECL_Dependency_With;
  585. if (!isset($attr['name'])) {
  586. $attr["name"] = $this->extension->getName();
  587. }
  588. $err = $with->setName($attr["name"]);
  589. if (PEAR::isError($err)) {
  590. return $err;
  591. }
  592. if (isset($attr["testfile"])) {
  593. $with->setTestfile($attr["testfile"]);
  594. }
  595. if (isset($attr["defaults"])) {
  596. $with->setDefaults($attr["defaults"]);
  597. }
  598. if (isset($attr["mode"])) {
  599. $err = $with->setMode($attr["mode"]);
  600. if (PEAR::isError($err)) {
  601. return $err;
  602. }
  603. }
  604. if (isset($attr["version"])) {
  605. $with->setVersion($attr["version"]);
  606. }
  607. $this->pushHelper($with);
  608. return true;
  609. }
  610. function tagstart_deps_with_header($attr)
  611. {
  612. $err = $this->checkAttributes($attr, array("name", "prepend", "path"));
  613. if (PEAR::isError($err)) {
  614. return $err;
  615. }
  616. // TODO check name
  617. $header = new CodeGen_PECL_Dependency_Header($attr["name"]);
  618. if (isset($attr['path'])) {
  619. $header->setPath($attr["path"]);
  620. }
  621. if (isset($attr['prepend'])) {
  622. $header->setPrepend($attr["prepend"]);
  623. }
  624. $this->helper->addHeader($header);
  625. }
  626. function tagstart_deps_with_lib($attr)
  627. {
  628. $err = $this->checkAttributes($attr, array("name", "platform", "path", "function"));
  629. if (PEAR::isError($err)) {
  630. return $err;
  631. }
  632. if (!isset($attr["name"])) {
  633. return PEAR::raiseError("");
  634. }
  635. if (!isset($attr["platform"])) {
  636. $attr["platform"] = "all";
  637. }
  638. $lib = new CodeGen_PECL_Dependency_Lib($attr["name"], $attr["platform"]);
  639. if (isset($attr['path'])) {
  640. $lib->setPath($attr['path']);
  641. }
  642. if (isset($attr['function'])) {
  643. $lib->setFunction($attr['function']);
  644. }
  645. $this->helper->addLib($lib);
  646. }
  647. function tagend_deps_with($attr, $data) {
  648. $this->helper->setSummary($data);
  649. $this->extension->addWith($this->helper);
  650. $this->popHelper();
  651. }
  652. function tagstart_extension_code($attr)
  653. {
  654. if (isset($attr["src"])) {
  655. if (!file_exists($attr["src"])) {
  656. return PEAR::raiseError("Soruce file '$attr[src]' not found");
  657. }
  658. if (!is_readable($attr["src"])) {
  659. return PEAR::raiseError("Cannot read source file '$attr[src]'");
  660. }
  661. }
  662. }
  663. function tagstart_extension_test($attr) {
  664. static $testCount = 0;
  665. $test = new CodeGen_PECL_Element_Test();
  666. if (isset($attr["name"])) {
  667. $err = $test->setName($attr["name"]);
  668. if (PEAR::isError($err)) {
  669. return $err;
  670. }
  671. } else {
  672. if (!$test->getName()) {
  673. $test->setName(sprintf("%03d", ++$testCount));
  674. }
  675. }
  676. $test->setSkipIf("!extension_loaded('".$this->extension->getName()."')");
  677. $this->pushHelper($test);
  678. }
  679. function tagstart_extension_tests_test($attr)
  680. {
  681. return $this->tagstart_extension_test($attr);
  682. }
  683. function tagstart_extension_group_test($attr)
  684. {
  685. return $this->tagstart_extension_test($attr);
  686. }
  687. function tagend_test_title($attr, $data) {
  688. $this->helper->setTitle(CodeGen_Tools_IndentC::linetrim($data));
  689. }
  690. function tagend_test_description($attr, $data) {
  691. $this->helper->setDescription(CodeGen_Tools_IndentC::linetrim($data));
  692. }
  693. function tagend_test_skipif($attr, $data) {
  694. $this->helper->setSkipIf(CodeGen_Tools_IndentC::linetrim($data));
  695. }
  696. function tagend_test_get($attr, $data) {
  697. $this->helper->setGet(CodeGen_Tools_IndentC::linetrim($data));
  698. }
  699. function tagend_test_post($attr, $data) {
  700. $this->helper->setPost(CodeGen_Tools_IndentC::linetrim($data));
  701. }
  702. function tagstart_test_code($attr)
  703. {
  704. if (isset($attr["src"])) {
  705. if (!file_exists($attr["src"])) {
  706. return PEAR::raiseError("Soruce file '$attr[src]' not found");
  707. }
  708. if (!is_readable($attr["src"])) {
  709. return PEAR::raiseError("Cannot read source file '$attr[src]'");
  710. }
  711. }
  712. }
  713. function tagend_test_code($attr, $data) {
  714. if (isset($attr["src"])) {
  715. $this->helper->setCode(CodeGen_Tools_IndentC::linetrim(file_get_contents($attr["src"])));
  716. } else {
  717. $this->helper->setCode(CodeGen_Tools_IndentC::linetrim($data));
  718. }
  719. }
  720. function tagend_test_result($attr, $data) {
  721. $err = $this->helper->setOutput(CodeGen_Tools_IndentC::linetrim($data));
  722. if (isset($attr['mode']) && !PEAR::isError($err)) {
  723. $err = $this->helper->setMode($attr['mode']);
  724. }
  725. return $err;
  726. }
  727. function tagend_extension_test($attr, $data) {
  728. $test = $this->popHelper();
  729. $err = $this->extension->addTest($test);
  730. return $err;
  731. }
  732. function tagend_extension_tests_test($attr, $data) {
  733. return $this->tagend_extension_test($attr, $data);
  734. }
  735. function tagend_extension_group_test($attr, $data) {
  736. return $this->tagend_extension_test($attr, $data);
  737. }
  738. function tagend_extension_tests($attr, $data) {
  739. return true;
  740. }
  741. function tagstart_extension_class($attr)
  742. {
  743. $err = $this->checkAttributes($attr, array("name", "extends", "final", "abstract", "if"));
  744. if (PEAR::isError($err)) {
  745. return $err;
  746. }
  747. $class = new CodeGen_PECL_Element_Class;
  748. $this->pushHelper($class);
  749. if (isset($attr["name"])) {
  750. $err = $class->setName($attr["name"]);
  751. if (PEAR::isError($err)) {
  752. return $err;
  753. }
  754. } else {
  755. return PEAR::raiseError("name attribut for class missing");
  756. }
  757. if (isset($attr["extends"])) {
  758. $err = $class->setExtends($attr["extends"]);
  759. if (PEAR::isError($err)) {
  760. return $err;
  761. }
  762. }
  763. // TODO: make sure a class is not abstract and final at the same time
  764. if (isset($attr["final"])) {
  765. $value = $this->toBool($attr["final"], "final");
  766. if (PEAR::isError($value)) {
  767. return $value;
  768. }
  769. if ($value) {
  770. $class->isFinal();
  771. }
  772. }
  773. if (isset($attr["abstract"])) {
  774. $value = $this->toBool($attr["abstract"], "abstract");
  775. if (PEAR::isError($value)) {
  776. return $value;
  777. }
  778. if ($value) {
  779. $class->isAbstract();
  780. }
  781. }
  782. if (isset($attr["if"])) {
  783. $class->setIfCondition($attr["if"]);
  784. }
  785. $groupIfs = $this->getGroupAttributeStack("if");
  786. if (is_array($groupIfs)) {
  787. foreach($groupIfs as $if) {
  788. $this->helper->addIfCondition($if);
  789. }
  790. }
  791. return true;
  792. }
  793. function tagstart_group_class($attr)
  794. {
  795. return $this->tagstart_extension_class($attr);
  796. }
  797. function tagend_class_summary($attr, $data)
  798. {
  799. return $this->helper->setSummary(trim($data));
  800. }
  801. function tagend_class_description($attr, $data)
  802. {
  803. return $this->helper->setDescription(CodeGen_Tools_IndentC::linetrim($data));
  804. }
  805. function tagend_class_implements($attr, $data)
  806. {
  807. $err = $this->checkAttributes($attr, array("interface"));
  808. if (PEAR::isError($err)) {
  809. return $err;
  810. }
  811. if (!isset($attr["interface"])) {
  812. return PEAR::raiseError("intarface attribute missing for <implements>");
  813. }
  814. return $this->helper->addInterface($attr["interface"]);
  815. }
  816. function tagstart_class_property($attr)
  817. {
  818. $err = $this->checkAttributes($attr, array("name", "type", "value", "access", "static", "if"));
  819. if (PEAR::isError($err)) {
  820. return $err;
  821. }
  822. $prop = new CodeGen_PECL_Element_Property;
  823. if (!isset($attr["name"])) {
  824. return PEAR::raiseError("name attribute missing for property");
  825. }
  826. $err = $prop->setName($attr["name"]);
  827. if (PEAR::isError($err)) {
  828. return $err;
  829. }
  830. if (isset($attr["type"])) {
  831. $err = $prop->setType($attr["type"]);
  832. if (PEAR::isError($err)) {
  833. return $err;
  834. }
  835. }
  836. if (isset($attr["value"])) {
  837. if (!isset($attr["type"])) {
  838. return PEAR::raiseError("property value can only be set together with type");
  839. }
  840. $err = $prop->setValue($attr["value"]);
  841. if (PEAR::isError($err)) {
  842. return $err;
  843. }
  844. }
  845. if (isset($attr["access"])) {
  846. $err = $prop->setAccess($attr["access"]);
  847. if (PEAR::isError($err)) {
  848. return $err;
  849. }
  850. }
  851. if (isset($attr["static"])) {
  852. $value = $this->toBool($attr["static"], "static");
  853. if (PEAR::isError($value)) {
  854. return $value;
  855. }
  856. if ($value) {
  857. $prop->isStatic();
  858. }
  859. }
  860. if (isset($attr["if"])) {
  861. $prop->setIfCondition($attr["if"]);
  862. }
  863. return $this->helper->addProperty($prop);
  864. }
  865. function tagstart_class_constant($attr)
  866. {
  867. $err = $this->checkAttributes($attr, array("name", "type", "value", "if"));
  868. if (PEAR::isError($err)) {
  869. return $err;
  870. }
  871. $const = new CodeGen_PECL_Element_ClassConstant;
  872. if (!isset($attr["name"])) {
  873. return PEAR::raiseError("name attribute missing for class constant");
  874. }
  875. $err = $const->setName($attr["name"]);
  876. if (PEAR::isError($err)) {
  877. return $err;
  878. }
  879. if (!isset($attr["type"])) {
  880. return PEAR::raiseError("type attribute missing for class constant");
  881. }
  882. $err = $const->setType($attr["type"]);
  883. if (PEAR::isError($err)) {
  884. return $err;
  885. }
  886. if (!isset($attr["value"])) {
  887. return PEAR::raiseError("value attribute missing for class constant");
  888. }
  889. $err = $const->setValue($attr["value"]);
  890. if (PEAR::isError($err)) {
  891. return $err;
  892. }
  893. if (isset($attr["if"])) {
  894. $prop->setIfCondition($attr["if"]);
  895. }
  896. return $this->helper->addConstant($const);
  897. }
  898. function tagstart_class_payload($attr)
  899. {
  900. $err = $this->checkAttributes($attr, array("type", "alloc"));
  901. if (PEAR::isError($err)) {
  902. return $err;
  903. }
  904. }
  905. function tagend_class_payload($attr, $data)
  906. {
  907. if (!isset($attr["type"])) {
  908. return PEAR::raiseError("type attribute missing for class payload");
  909. }
  910. $this->helper->setPayloadType($attr["type"]);
  911. if (isset($attr["alloc"])) {
  912. $alloc = $this->toBool($attr["alloc"], "alloc");
  913. if (PEAR::isError($alloc)) {
  914. return $value;
  915. }
  916. } else {
  917. $alloc = true;
  918. }
  919. $this->helper->setPayloadAlloc($alloc);
  920. }
  921. function tagend_class_init($attr, $data)
  922. {
  923. $this->helper->setPayloadCtor($data);
  924. }
  925. function tagend_class_destruct($attr, $data)
  926. {
  927. $this->helper->setPayloadDtor($data);
  928. }
  929. function tagstart_class_function($attr)
  930. {
  931. $err = $this->checkAttributes($attr, array("name", "access", "static", "abstract", "final", "procedural", "if"));
  932. if (PEAR::isError($err)) {
  933. return $err;
  934. }
  935. $method = new CodeGen_PECL_Element_Method($this->helper);
  936. $this->pushHelper($method);
  937. if (isset($attr["name"])) {
  938. $err = $method->setName($attr["name"]);
  939. if (PEAR::isError($err)) {
  940. return $err;
  941. }
  942. } else {
  943. return PEAR::raiseError("'name' attribut for <function> missing");
  944. }
  945. if (isset($attr["access"])) {
  946. $err = $method->setAccess($attr["access"]);
  947. if (PEAR::isError($err)) {
  948. return $err;
  949. }
  950. }
  951. if (isset($attr["static"])) {
  952. $value = $this->toBool($attr["static"], "static");
  953. if (PEAR::isError($value)) {
  954. return $value;
  955. }
  956. if ($value) {
  957. $err = $method->isStatic();
  958. if (PEAR::isError($err)) {
  959. return $err;
  960. }
  961. }
  962. }
  963. if (isset($attr["abstract"])) {
  964. $value = $this->toBool($attr["abstract"], "abstract");
  965. if (PEAR::isError($value)) {
  966. return $value;
  967. }
  968. if ($value) {
  969. $err = $method->isAbstract();
  970. if (PEAR::isError($err)) {
  971. return $err;
  972. }
  973. }
  974. }
  975. if (isset($attr["final"])) {
  976. $value = $this->toBool($attr["final"], "final");
  977. if (PEAR::isError($value)) {
  978. return $value;
  979. }
  980. if ($value) {
  981. $err = $method->isFinal();
  982. if (PEAR::isError($err)) {
  983. return $err;
  984. }
  985. }
  986. }
  987. if (isset($attr["procedural"])) {
  988. if ($attr["procedural"] == "" || $attr["procedural"] == "yes") {
  989. $attr["procedural"] = "default";
  990. }
  991. $err = $method->setProceduralName($attr["procedural"]);
  992. if (PEAR::isError($err)) {
  993. return $err;
  994. }
  995. }
  996. if (isset($attr["if"])) {
  997. $method->setIfCondition($attr["if"]);
  998. }
  999. return true;
  1000. }
  1001. function tagend_class_function($attr, $data)
  1002. {
  1003. $method = $this->helper;
  1004. $this->popHelper();
  1005. $err = $this->helper->addMethod($method);
  1006. return $err;
  1007. }
  1008. function tagend_extension_class($attr, $data)
  1009. {
  1010. $err = $this->extension->addClass($this->helper);
  1011. $this->popHelper();
  1012. return true;
  1013. }
  1014. function tagend_group_class($attr, $data)
  1015. {
  1016. return $this->tagend_extension_class($attr, $data);
  1017. }
  1018. function tagstart_extension_interface($attr)
  1019. {
  1020. $err = $this->checkAttributes($attr, array("name", "extends", "if"));
  1021. if (PEAR::isError($err)) {
  1022. return $err;
  1023. }
  1024. $interface = new CodeGen_PECL_Element_Interface;
  1025. $this->pushHelper($interface);
  1026. if (isset($attr["name"])) {
  1027. $err = $interface->setName($attr["name"]);
  1028. if (PEAR::isError($err)) {
  1029. return $err;
  1030. }
  1031. } else {
  1032. return PEAR::raiseError("name attribut for class missing");
  1033. }
  1034. if (isset($attr["extends"])) {
  1035. $err = $interface->setExtends($attr["extends"]);
  1036. if (PEAR::isError($err)) {
  1037. return $err;
  1038. }
  1039. }
  1040. if (isset($attr["if"])) {
  1041. $interface->setIfCondition($attr["if"]);
  1042. }
  1043. $groupIfs = $this->getGroupAttributeStack("if");
  1044. if (is_array($groupIfs)) {
  1045. foreach($groupIfs as $if) {
  1046. $interface->addIfCondition($if);
  1047. }
  1048. }
  1049. return true;
  1050. }
  1051. function tagstart_group_interface($attr)
  1052. {
  1053. return $this->tagstart_extension_interface($attr);
  1054. }
  1055. function tagstart_interface_function($attr)
  1056. {
  1057. $err = $this->checkAttributes($attr, array("name"));
  1058. if (PEAR::isError($err)) {
  1059. return $err;
  1060. }
  1061. $method = new CodeGen_PECL_Element_Method($this->helper);
  1062. $method->isAbstract();
  1063. $method->isInterface();
  1064. $this->pushHelper($method);
  1065. if (isset($attr["name"])) {
  1066. $err = $method->setName($attr["name"]);
  1067. if (PEAR::isError($err)) {
  1068. return $err;
  1069. }
  1070. } else {
  1071. return PEAR::raiseError("'name' attribut for <function> missing");
  1072. }
  1073. return true;
  1074. }
  1075. function tagend_interface_function($attr, $data)
  1076. {
  1077. $method = $this->helper;
  1078. $this->popHelper();
  1079. $err = $this->helper->addMethod($method);
  1080. return $err;
  1081. }
  1082. function tagend_extension_interface($attr, $data)
  1083. {
  1084. $err = $this->extension->addInterface($this->helper);
  1085. $this->popHelper();
  1086. return true;
  1087. }
  1088. function tagend_group_interface($attr, $data)
  1089. {
  1090. return $this->tagend_extension_interface($attr, $data);
  1091. }
  1092. function tagstart_extension_stream($attr)
  1093. {
  1094. $err = $this->checkAttributes($attr, array("name"));
  1095. if (PEAR::isError($err)) {
  1096. return $err;
  1097. }
  1098. $this->pushHelper(new CodeGen_PECL_Element_Stream);
  1099. if (isset($attr["name"])) {
  1100. $err = $this->helper->setName($attr["name"]);
  1101. if (PEAR::isError($err)) {
  1102. return $err;
  1103. }
  1104. } else {
  1105. return PEAR::raiseError("'name' attribut for <stream> missing");
  1106. }
  1107. }
  1108. function tagstart_group_stream($attr)
  1109. {
  1110. return $this->extension_group_stream($attr);
  1111. }
  1112. function tagend_stream_open($attr, $data)
  1113. {
  1114. $this->helper->addCode("open", $data);
  1115. }
  1116. function tagend_stream_close($attr, $data)
  1117. {
  1118. $this->helper->addCode("close", $data);
  1119. }
  1120. function tagend_stream_stat($attr, $data)
  1121. {
  1122. $this->helper->addCode("stat", $data);
  1123. }
  1124. function tagend_stream_urlstat($attr, $data)
  1125. {
  1126. $this->helper->addCode("urlstat", $data);
  1127. }
  1128. function tagend_stream_diropen($attr, $data)
  1129. {
  1130. $this->helper->addCode("diropen", $data);
  1131. }
  1132. function tagend_stream_unlink($attr, $data)
  1133. {
  1134. $this->helper->addCode("unlink", $data);
  1135. }
  1136. function tagend_stream_rename($attr, $data)
  1137. {
  1138. $this->helper->addCode("rename", $data);
  1139. }
  1140. function tagend_stream_mkdir($attr, $data)
  1141. {
  1142. $this->helper->addCode("mkdir", $data);
  1143. }
  1144. function tagend_stream_rmdir($attr, $data)
  1145. {
  1146. $this->helper->addCode("rmdir", $data);
  1147. }
  1148. function tagend_stream_summary($attr, $data)
  1149. {
  1150. $this->helper->addCode("summary", $data);
  1151. }
  1152. function tagend_stream_write($attr, $data)
  1153. {
  1154. $this->helper->addCode("write", $data);
  1155. }
  1156. function tagend_stream_read($attr, $data)
  1157. {
  1158. $this->helper->addCode("read", $data);
  1159. }
  1160. function tagend_stream_flush($attr, $data)
  1161. {
  1162. $this->helper->addCode("flush", $data);
  1163. }
  1164. function tagend_stream_seek($attr, $data)
  1165. {
  1166. $this->helper->addCode("seek", $data);
  1167. }
  1168. function tagend_stream_cast($attr, $data)
  1169. {
  1170. $this->helper->addCode("cast", $data);
  1171. }
  1172. function tagend_stream_set($attr, $data)
  1173. {
  1174. $this->helper->addCode("set", $data);
  1175. }
  1176. function tagend_extension_stream($attr, $data)
  1177. {
  1178. $this->extension->addStream($this->helper);
  1179. $this->popHelper();
  1180. }
  1181. function tagend_group_stream($attr, $data)
  1182. {
  1183. return $this->tagend_extension_stream($attr, $data);
  1184. }
  1185. function tagstart_channel($attr)
  1186. {
  1187. return $this->noAttributes($attr);
  1188. }
  1189. function tagstartgroup_channel($attr)
  1190. {
  1191. return $this->tagstart_extension_channel($attr);
  1192. }
  1193. function tagend_channel($attr, $data)
  1194. {
  1195. return $this->extension->setChannel($data);
  1196. }
  1197. function tagend_group_channel($attr, $data)
  1198. {
  1199. return $this->tagend_extension_channel($attr, $data);
  1200. }
  1201. }
  1202. /*
  1203. * Local variables:
  1204. * tab-width: 4
  1205. * c-basic-offset: 4
  1206. * indent-tabs-mode:nil
  1207. * End:
  1208. */
  1209. ?>