PageRenderTime 50ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/sandbox/marija.kuleshova/bin/lib/Type.class.php

http://na-agent.googlecode.com/
PHP | 504 lines | 501 code | 3 blank | 0 comment | 82 complexity | 6909016c0763e5036dd4a1e6263f8549 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. class Type {
  3. public function __construct(){}
  4. static function getClass($o) {
  5. $GLOBALS['%s']->push("Type::getClass");
  6. $?spos = $GLOBALS['%s']->length;
  7. if($o === null) {
  8. $GLOBALS['%s']->pop();
  9. return null;
  10. }
  11. if(is_array($o)) {
  12. if(count($o) === 2 && is_callable($o)) {
  13. $GLOBALS['%s']->pop();
  14. return null;
  15. }
  16. {
  17. $?tmp = _hx_ttype("Array");
  18. $GLOBALS['%s']->pop();
  19. return $?tmp;
  20. }
  21. }
  22. if(is_string($o)) {
  23. if(_hx_is_lambda($o)) {
  24. $GLOBALS['%s']->pop();
  25. return null;
  26. }
  27. {
  28. $?tmp2 = _hx_ttype("String");
  29. $GLOBALS['%s']->pop();
  30. return $?tmp2;
  31. }
  32. }
  33. if(!is_object($o)) {
  34. {
  35. $GLOBALS['%s']->pop();
  36. return null;
  37. }
  38. }
  39. $c = get_class($o);
  40. if($c === false || $c === "_hx_anonymous" || is_subclass_of($c, "enum")) {
  41. $GLOBALS['%s']->pop();
  42. return null;
  43. }
  44. else {
  45. $?tmp3 = _hx_ttype($c);
  46. $GLOBALS['%s']->pop();
  47. return $?tmp3;
  48. }
  49. $GLOBALS['%s']->pop();
  50. }
  51. static function getEnum($o) {
  52. $GLOBALS['%s']->push("Type::getEnum");
  53. $?spos = $GLOBALS['%s']->length;
  54. if(!$o instanceof Enum) {
  55. $GLOBALS['%s']->pop();
  56. return null;
  57. }
  58. else {
  59. $?tmp = _hx_ttype(get_class($o));
  60. $GLOBALS['%s']->pop();
  61. return $?tmp;
  62. }
  63. $GLOBALS['%s']->pop();
  64. }
  65. static function getSuperClass($c) {
  66. $GLOBALS['%s']->push("Type::getSuperClass");
  67. $?spos = $GLOBALS['%s']->length;
  68. $s = get_parent_class($c->__tname__);
  69. if($s === false) {
  70. $GLOBALS['%s']->pop();
  71. return null;
  72. }
  73. else {
  74. $?tmp = _hx_ttype($s);
  75. $GLOBALS['%s']->pop();
  76. return $?tmp;
  77. }
  78. $GLOBALS['%s']->pop();
  79. }
  80. static function getClassName($c) {
  81. $GLOBALS['%s']->push("Type::getClassName");
  82. $?spos = $GLOBALS['%s']->length;
  83. if($c === null) {
  84. $GLOBALS['%s']->pop();
  85. return null;
  86. }
  87. {
  88. $?tmp = $c->__qname__;
  89. $GLOBALS['%s']->pop();
  90. return $?tmp;
  91. }
  92. $GLOBALS['%s']->pop();
  93. }
  94. static function getEnumName($e) {
  95. $GLOBALS['%s']->push("Type::getEnumName");
  96. $?spos = $GLOBALS['%s']->length;
  97. {
  98. $?tmp = $e->__qname__;
  99. $GLOBALS['%s']->pop();
  100. return $?tmp;
  101. }
  102. $GLOBALS['%s']->pop();
  103. }
  104. static function resolveClass($name) {
  105. $GLOBALS['%s']->push("Type::resolveClass");
  106. $?spos = $GLOBALS['%s']->length;
  107. $c = _hx_qtype($name);
  108. if($c instanceof _hx_class) {
  109. $GLOBALS['%s']->pop();
  110. return $c;
  111. }
  112. else {
  113. $GLOBALS['%s']->pop();
  114. return null;
  115. }
  116. $GLOBALS['%s']->pop();
  117. }
  118. static function resolveEnum($name) {
  119. $GLOBALS['%s']->push("Type::resolveEnum");
  120. $?spos = $GLOBALS['%s']->length;
  121. $e = _hx_qtype($name);
  122. if($e instanceof _hx_enum) {
  123. $GLOBALS['%s']->pop();
  124. return $e;
  125. }
  126. else {
  127. $GLOBALS['%s']->pop();
  128. return null;
  129. }
  130. $GLOBALS['%s']->pop();
  131. }
  132. static function createInstance($cl, $args) {
  133. $GLOBALS['%s']->push("Type::createInstance");
  134. $?spos = $GLOBALS['%s']->length;
  135. if($cl->__qname__ == "Array") {
  136. $?tmp = new _hx_array(array());
  137. $GLOBALS['%s']->pop();
  138. return $?tmp;
  139. }
  140. if($cl->__qname__ == "String") {
  141. $?tmp2 = $args[0];
  142. $GLOBALS['%s']->pop();
  143. return $?tmp2;
  144. }
  145. $c = $cl->__rfl__();
  146. if($c === null) {
  147. $GLOBALS['%s']->pop();
  148. return null;
  149. }
  150. {
  151. $?tmp3 = $inst = $c->getConstructor() ? $c->newInstanceArgs($args->?a) : $c->newInstanceArgs();
  152. $GLOBALS['%s']->pop();
  153. return $?tmp3;
  154. }
  155. $GLOBALS['%s']->pop();
  156. }
  157. static function createEmptyInstance($cl) {
  158. $GLOBALS['%s']->push("Type::createEmptyInstance");
  159. $?spos = $GLOBALS['%s']->length;
  160. if($cl->__qname__ == "Array") {
  161. $?tmp = new _hx_array(array());
  162. $GLOBALS['%s']->pop();
  163. return $?tmp;
  164. }
  165. if($cl->__qname__ == "String") {
  166. $GLOBALS['%s']->pop();
  167. return "";
  168. }
  169. try {
  170. php_Boot::$skip_constructor = true;
  171. $rfl = $cl->__rfl__();
  172. if($rfl === null) {
  173. $GLOBALS['%s']->pop();
  174. return null;
  175. }
  176. $m = $rfl->getConstructor();
  177. $nargs = $m->getNumberOfRequiredParameters();
  178. $i = null;
  179. if($nargs > 0) {
  180. $args = array_fill(0, $m->getNumberOfRequiredParameters(), null);
  181. $i = $rfl->newInstanceArgs($args);
  182. }
  183. else {
  184. $i = $rfl->newInstanceArgs(array());
  185. }
  186. php_Boot::$skip_constructor = false;
  187. {
  188. $GLOBALS['%s']->pop();
  189. return $i;
  190. }
  191. }catch(Exception $?e) {
  192. $_ex_ = ($?e instanceof HException) ? $?e->e : $?e;
  193. ;
  194. { $e = $_ex_;
  195. {
  196. $GLOBALS['%e'] = new _hx_array(array());
  197. while($GLOBALS['%s']->length >= $?spos) $GLOBALS['%e']->unshift($GLOBALS['%s']->pop());
  198. $GLOBALS['%s']->push($GLOBALS['%e'][0]);
  199. php_Boot::$skip_constructor = false;
  200. throw new HException("Unable to instantiate " . Std::string($cl));
  201. }}}
  202. {
  203. $GLOBALS['%s']->pop();
  204. return null;
  205. }
  206. $GLOBALS['%s']->pop();
  207. }
  208. static function createEnum($e, $constr, $params) {
  209. $GLOBALS['%s']->push("Type::createEnum");
  210. $?spos = $GLOBALS['%s']->length;
  211. $f = Reflect::field($e, $constr);
  212. if($f === null) {
  213. throw new HException("No such constructor " . $constr);
  214. }
  215. if(Reflect::isFunction($f)) {
  216. if($params === null) {
  217. throw new HException(("Constructor " . $constr) . " need parameters");
  218. }
  219. {
  220. $?tmp = Reflect::callMethod($e, $f, $params);
  221. $GLOBALS['%s']->pop();
  222. return $?tmp;
  223. }
  224. }
  225. if($params !== null && $params->length !== 0) {
  226. throw new HException(("Constructor " . $constr) . " does not need parameters");
  227. }
  228. {
  229. $GLOBALS['%s']->pop();
  230. return $f;
  231. }
  232. $GLOBALS['%s']->pop();
  233. }
  234. static function createEnumIndex($e, $index, $params) {
  235. $GLOBALS['%s']->push("Type::createEnumIndex");
  236. $?spos = $GLOBALS['%s']->length;
  237. $c = _hx_array_get(Type::getEnumConstructs($e), $index);
  238. if($c === null) {
  239. throw new HException($index . " is not a valid enum constructor index");
  240. }
  241. {
  242. $?tmp = Type::createEnum($e, $c, $params);
  243. $GLOBALS['%s']->pop();
  244. return $?tmp;
  245. }
  246. $GLOBALS['%s']->pop();
  247. }
  248. static function getInstanceFields($c) {
  249. $GLOBALS['%s']->push("Type::getInstanceFields");
  250. $?spos = $GLOBALS['%s']->length;
  251. if($c->__qname__ == "String") {
  252. $?tmp = new _hx_array(array("substr", "charAt", "charCodeAt", "indexOf", "lastIndexOf", "split", "toLowerCase", "toUpperCase", "toString", "length"));
  253. $GLOBALS['%s']->pop();
  254. return $?tmp;
  255. }
  256. if($c->__qname__ == "Array") {
  257. $?tmp2 = new _hx_array(array("push", "concat", "join", "pop", "reverse", "shift", "slice", "sort", "splice", "toString", "copy", "unshift", "insert", "remove", "iterator", "length"));
  258. $GLOBALS['%s']->pop();
  259. return $?tmp2;
  260. }
  261. $rfl = $c->__rfl__();
  262. if($rfl === null) return new _hx_array(array());
  263. $r = array();
  264. $internals = array('__construct', '__call', '__get', '__set', '__isset', '__unset', '__toString');
  265. $ms = $rfl->getMethods();
  266. while(list(, $m) = each($ms)) {
  267. $n = $m->getName();
  268. if(!$m->isStatic() && ! in_array($n, $internals)) $r[] = $n;
  269. }
  270. $ps = $rfl->getProperties();
  271. while(list(, $p) = each($ps))
  272. if(!$p->isStatic()) $r[] = $p->getName();
  273. {
  274. $?tmp3 = new _hx_array(array_values(array_unique($r)));
  275. $GLOBALS['%s']->pop();
  276. return $?tmp3;
  277. }
  278. $GLOBALS['%s']->pop();
  279. }
  280. static function getClassFields($c) {
  281. $GLOBALS['%s']->push("Type::getClassFields");
  282. $?spos = $GLOBALS['%s']->length;
  283. if($c->__qname__ == "String") {
  284. $?tmp = new _hx_array(array("fromCharCode"));
  285. $GLOBALS['%s']->pop();
  286. return $?tmp;
  287. }
  288. if($c->__qname__ == "Array") {
  289. $?tmp2 = new _hx_array(array());
  290. $GLOBALS['%s']->pop();
  291. return $?tmp2;
  292. }
  293. $rfl = $c->__rfl__();
  294. if($rfl === null) return new _hx_array(array());
  295. $ms = $rfl->getMethods();
  296. $r = array();
  297. while(list(, $m) = each($ms))
  298. if($m->isStatic()) $r[] = $m->getName();
  299. $ps = $rfl->getProperties();
  300. while(list(, $p) = each($ps))
  301. if($p->isStatic()) $r[] = $p->getName();
  302. ;
  303. {
  304. $?tmp3 = new _hx_array(array_unique($r));
  305. $GLOBALS['%s']->pop();
  306. return $?tmp3;
  307. }
  308. $GLOBALS['%s']->pop();
  309. }
  310. static function getEnumConstructs($e) {
  311. $GLOBALS['%s']->push("Type::getEnumConstructs");
  312. $?spos = $GLOBALS['%s']->length;
  313. if($e->__tname__ == 'Bool') {
  314. $?tmp = new _hx_array(array("true", "false"));
  315. $GLOBALS['%s']->pop();
  316. return $?tmp;
  317. }
  318. if($e->__tname__ == 'Void') {
  319. $?tmp2 = new _hx_array(array());
  320. $GLOBALS['%s']->pop();
  321. return $?tmp2;
  322. }
  323. $rfl = new ReflectionClass($e->__tname__);
  324. $sps = $rfl->getStaticProperties();
  325. $r = array(); while(list($k) = each($sps)) $r[] = $k;
  326. $sps = $rfl->getMethods();
  327. while(list(, $m) = each($sps)) { $n = $m->getName(); if($n != '__construct' && $n != '__toString') $r[] = $n; }
  328. {
  329. $?tmp3 = new _hx_array($r);
  330. $GLOBALS['%s']->pop();
  331. return $?tmp3;
  332. }
  333. $GLOBALS['%s']->pop();
  334. }
  335. static function typeof($v) {
  336. $GLOBALS['%s']->push("Type::typeof");
  337. $?spos = $GLOBALS['%s']->length;
  338. if($v === null) {
  339. $?tmp = ValueType::$TNull;
  340. $GLOBALS['%s']->pop();
  341. return $?tmp;
  342. }
  343. if(is_array($v)) {
  344. if(is_callable($v)) {
  345. $?tmp2 = ValueType::$TFunction;
  346. $GLOBALS['%s']->pop();
  347. return $?tmp2;
  348. }
  349. {
  350. $?tmp3 = ValueType::TClass(_hx_qtype("Array"));
  351. $GLOBALS['%s']->pop();
  352. return $?tmp3;
  353. }
  354. }
  355. if(is_string($v)) {
  356. if(_hx_is_lambda($v)) {
  357. $?tmp4 = ValueType::$TFunction;
  358. $GLOBALS['%s']->pop();
  359. return $?tmp4;
  360. }
  361. {
  362. $?tmp5 = ValueType::TClass(_hx_qtype("String"));
  363. $GLOBALS['%s']->pop();
  364. return $?tmp5;
  365. }
  366. }
  367. if(is_bool($v)) {
  368. $?tmp6 = ValueType::$TBool;
  369. $GLOBALS['%s']->pop();
  370. return $?tmp6;
  371. }
  372. if(is_int($v)) {
  373. $?tmp7 = ValueType::$TInt;
  374. $GLOBALS['%s']->pop();
  375. return $?tmp7;
  376. }
  377. if(is_float($v)) {
  378. $?tmp8 = ValueType::$TFloat;
  379. $GLOBALS['%s']->pop();
  380. return $?tmp8;
  381. }
  382. if($v instanceof _hx_anonymous) {
  383. $?tmp9 = ValueType::$TObject;
  384. $GLOBALS['%s']->pop();
  385. return $?tmp9;
  386. }
  387. if($v instanceof _hx_enum) {
  388. $?tmp10 = ValueType::$TObject;
  389. $GLOBALS['%s']->pop();
  390. return $?tmp10;
  391. }
  392. if($v instanceof _hx_class) {
  393. $?tmp11 = ValueType::$TObject;
  394. $GLOBALS['%s']->pop();
  395. return $?tmp11;
  396. }
  397. $c = _hx_ttype(get_class($v));
  398. if($c instanceof _hx_enum) {
  399. $?tmp12 = ValueType::TEnum($c);
  400. $GLOBALS['%s']->pop();
  401. return $?tmp12;
  402. }
  403. if($c instanceof _hx_class) {
  404. $?tmp13 = ValueType::TClass($c);
  405. $GLOBALS['%s']->pop();
  406. return $?tmp13;
  407. }
  408. {
  409. $?tmp14 = ValueType::$TUnknown;
  410. $GLOBALS['%s']->pop();
  411. return $?tmp14;
  412. }
  413. $GLOBALS['%s']->pop();
  414. }
  415. static function enumEq($a, $b) {
  416. $GLOBALS['%s']->push("Type::enumEq");
  417. $?spos = $GLOBALS['%s']->length;
  418. if($a === $b) {
  419. $GLOBALS['%s']->pop();
  420. return true;
  421. }
  422. try {
  423. if(!_hx_equal($a->index, $b->index)) {
  424. $GLOBALS['%s']->pop();
  425. return false;
  426. }
  427. {
  428. $_g1 = 0; $_g = count($a->params);
  429. while($_g1 < $_g) {
  430. $i = $_g1++;
  431. if(Type::getEnum($a->params[$i]) !== null) {
  432. if(!Type::enumEq($a->params[$i], $b->params[$i])) {
  433. $GLOBALS['%s']->pop();
  434. return false;
  435. }
  436. }
  437. else {
  438. if(!_hx_equal($a->params[$i], $b->params[$i])) {
  439. $GLOBALS['%s']->pop();
  440. return false;
  441. }
  442. }
  443. unset($i);
  444. }
  445. }
  446. }catch(Exception $?e) {
  447. $_ex_ = ($?e instanceof HException) ? $?e->e : $?e;
  448. ;
  449. { $e = $_ex_;
  450. {
  451. $GLOBALS['%e'] = new _hx_array(array());
  452. while($GLOBALS['%s']->length >= $?spos) $GLOBALS['%e']->unshift($GLOBALS['%s']->pop());
  453. $GLOBALS['%s']->push($GLOBALS['%e'][0]);
  454. {
  455. $GLOBALS['%s']->pop();
  456. return false;
  457. }
  458. }}}
  459. {
  460. $GLOBALS['%s']->pop();
  461. return true;
  462. }
  463. $GLOBALS['%s']->pop();
  464. }
  465. static function enumConstructor($e) {
  466. $GLOBALS['%s']->push("Type::enumConstructor");
  467. $?spos = $GLOBALS['%s']->length;
  468. {
  469. $?tmp = $e->tag;
  470. $GLOBALS['%s']->pop();
  471. return $?tmp;
  472. }
  473. $GLOBALS['%s']->pop();
  474. }
  475. static function enumParameters($e) {
  476. $GLOBALS['%s']->push("Type::enumParameters");
  477. $?spos = $GLOBALS['%s']->length;
  478. if(_hx_field($e, "params") === null) {
  479. $?tmp = new _hx_array(array());
  480. $GLOBALS['%s']->pop();
  481. return $?tmp;
  482. }
  483. else {
  484. $?tmp2 = new _hx_array($e->params);
  485. $GLOBALS['%s']->pop();
  486. return $?tmp2;
  487. }
  488. $GLOBALS['%s']->pop();
  489. }
  490. static function enumIndex($e) {
  491. $GLOBALS['%s']->push("Type::enumIndex");
  492. $?spos = $GLOBALS['%s']->length;
  493. {
  494. $?tmp = $e->index;
  495. $GLOBALS['%s']->pop();
  496. return $?tmp;
  497. }
  498. $GLOBALS['%s']->pop();
  499. }
  500. function __toString() { return 'Type'; }
  501. }