expr.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  1. /* $Id$ */
  2. /* This file contains the expression evaluator. It exports the following
  3. routines:
  4. - int eval_cond(p_tree p)
  5. This routine evaluates the conditional expression indicated by p
  6. and returns 1 if it evaluates to TRUE, or 0 if it could not be
  7. evaluated for some reason or if it evalutes to FALSE.
  8. If the expression cannot be evaluated, an error message is given.
  9. - int eval_desig(p_tree p, t_addr *paddr, long **psize, p_type *ptp)
  10. This routine evaluates the expression indicated by p, which should
  11. result in a designator. The result of the expression is an address
  12. which is to be found in *paddr. *psize will contain the size of the
  13. designated object, and *ptp its type.
  14. If the expression cannot be evaluated or does not result in a
  15. designator, 0 is returned and an error message is given.
  16. Otherwise, 1 is returned.
  17. - int eval_expr(p_tree p, char **pbuf, long **psize, p_type *ptp)
  18. This routine evaluates the expression indicated by p.
  19. The result of the expression is left in *pbuf.
  20. *psize will contain the size of the value, and *ptp its type.
  21. If the expression cannot be evaluated, 0 is returned and an error
  22. message is given. Otherwise, 1 is returned.
  23. - int convert(char **pbuf, long *psize, p_type *ptp, p_type tp, long size)
  24. This routine tries to convert the value in pbuf of size psize
  25. and type ptp to type tp with size size. It returns 0 if this fails,
  26. while producing an error message. Otherwise, it returns 1 and
  27. the resulting value, type and size are left in pbuf, ptp, and
  28. psize, respectively.
  29. - long get_int(char *buf, long size, int class)
  30. Returns the value of size 'size', residing in 'buf', of 'class'
  31. T_INTEGER, T_UNSIGNED, or T_ENUM.
  32. - int put_int(char *buf, long size, long value)
  33. Stores the value 'value' of size 'size' in 'buf'.
  34. - double get_real(char *buf, long size)
  35. Returns the real value of size 'size', residing in 'buf'.
  36. T_INTEGER, T_UNSIGNED, or T_ENUM.
  37. - int put_real(char *buf, long size, double value)
  38. Stores the value 'value' of size 'size' in 'buf'.
  39. */
  40. #include <stdio.h>
  41. #include <alloc.h>
  42. #include <assert.h>
  43. #include "position.h"
  44. #include "operator.h"
  45. #include "tree.h"
  46. #include "expr.h"
  47. #include "symbol.h"
  48. #include "type.h"
  49. #include "langdep.h"
  50. #include "scope.h"
  51. #include "idf.h"
  52. #include "misc.h"
  53. extern FILE *db_out;
  54. extern int stack_offset;
  55. extern char *strcpy();
  56. extern t_addr *get_EM_regs();
  57. extern char *memcpy();
  58. extern char *malloc(), *realloc();
  59. #define malloc_succeeded(p) if (! (p)) {\
  60. error("could not allocate enough memory");\
  61. return 0;\
  62. }
  63. /* static t_addr get_addr(p_symbol sym; long *psize);
  64. Get the address of the object indicated by sym. Returns 0 on failure,
  65. address on success. *psize will contain size of object.
  66. For local variables or parameters, the 'stack_offset' variable is
  67. used to determine from which stack frame the search must start.
  68. */
  69. static t_addr
  70. get_addr(sym, psize)
  71. register p_symbol sym;
  72. long *psize;
  73. {
  74. p_type tp = sym->sy_type;
  75. long size = tp->ty_size;
  76. t_addr *EM_regs;
  77. int i;
  78. p_scope sc, symsc;
  79. *psize = size;
  80. switch(sym->sy_class) {
  81. case VAR:
  82. /* exists if child exists; nm_value contains addres */
  83. return (t_addr) sym->sy_name.nm_value;
  84. case VARPAR:
  85. case LOCVAR:
  86. /* first find the stack frame in which it resides */
  87. symsc = base_scope(sym->sy_scope);
  88. /* now symsc contains the scope where the storage for sym is
  89. allocated. Now find it on the stack of child.
  90. */
  91. i = stack_offset;
  92. for (;;) {
  93. sc = 0;
  94. if (! (EM_regs = get_EM_regs(i++))) {
  95. return 0;
  96. }
  97. if (! EM_regs[1]) {
  98. error("%s not available", sym->sy_idf->id_text);
  99. return 0;
  100. }
  101. sc = base_scope(get_scope_from_addr(EM_regs[2]));
  102. if (! sc || sc->sc_start > EM_regs[2]) {
  103. error("%s not available", sym->sy_idf->id_text);
  104. sc = 0;
  105. return 0;
  106. }
  107. if (sc == symsc) break; /* found it */
  108. }
  109. if (sym->sy_class == LOCVAR) {
  110. /* Either local variable or value parameter */
  111. return EM_regs[sym->sy_name.nm_value < 0 ? 0 : 1] +
  112. (t_addr) sym->sy_name.nm_value;
  113. }
  114. /* If we get here, we have a var parameter. Get the parameters
  115. of the current procedure invocation.
  116. */
  117. {
  118. p_type proctype = sc->sc_definedby->sy_type;
  119. t_addr a;
  120. char *AB;
  121. size = proctype->ty_nbparams;
  122. if (has_static_link(sc)) size += pointer_size;
  123. AB = malloc((unsigned) size);
  124. if (! AB) {
  125. error("could not allocate enough memory");
  126. break;
  127. }
  128. if (! get_bytes(size, EM_regs[1], AB)) {
  129. break;
  130. }
  131. if ((size = tp->ty_size) == 0) {
  132. size = compute_size(tp, AB);
  133. *psize = size;
  134. }
  135. a = (t_addr) get_int(AB+sym->sy_name.nm_value, pointer_size, T_UNSIGNED);
  136. free(AB);
  137. return a;
  138. }
  139. default:
  140. error("%s is not a variable", sym->sy_idf->id_text);
  141. break;
  142. }
  143. return 0;
  144. }
  145. static int
  146. get_v(a, pbuf, size)
  147. t_addr a;
  148. char **pbuf;
  149. long size;
  150. {
  151. if (a) {
  152. *pbuf = malloc((unsigned) size);
  153. if (! *pbuf) {
  154. error("could not allocate enough memory");
  155. return 0;
  156. }
  157. if (! get_bytes(size, a, *pbuf)) return 0;
  158. return 1;
  159. }
  160. return 0;
  161. }
  162. /* static int get_value(p_symbol sym; char **pbuf; long *psize);
  163. Get the value of the symbol indicated by sym. Return 0 on failure,
  164. 1 on success. On success, 'pbuf' contains the value, and 'psize' contains
  165. the size. For 'pbuf', storage is allocated by malloc; this storage must
  166. be freed by caller (I don't like this any more than you do, but caller
  167. does not know sizes).
  168. For local variables or parameters, the 'stack_offset' variable is
  169. used to determine from which stack frame the search must start.
  170. */
  171. static int
  172. get_value(sym, pbuf, psize)
  173. register p_symbol sym;
  174. char **pbuf;
  175. long *psize;
  176. {
  177. p_type tp = sym->sy_type;
  178. int retval = 0;
  179. t_addr a;
  180. long size = tp->ty_size;
  181. *pbuf = 0;
  182. switch(sym->sy_class) {
  183. case CONST:
  184. *pbuf = malloc((unsigned) size);
  185. if (! *pbuf) {
  186. error("could not allocate enough memory");
  187. break;
  188. }
  189. switch(tp->ty_class) {
  190. case T_REAL:
  191. put_real(*pbuf, size, sym->sy_const.co_rval);
  192. break;
  193. case T_INTEGER:
  194. case T_SUBRANGE:
  195. case T_UNSIGNED:
  196. case T_ENUM:
  197. put_int(*pbuf, size, sym->sy_const.co_ival);
  198. break;
  199. case T_SET:
  200. memcpy(*pbuf, sym->sy_const.co_setval, (int) size);
  201. break;
  202. case T_STRING:
  203. memcpy(*pbuf, sym->sy_const.co_sval, (int) size);
  204. break;
  205. default:
  206. fatal("strange constant");
  207. }
  208. retval = 1;
  209. break;
  210. case VAR:
  211. case VARPAR:
  212. case LOCVAR:
  213. a = get_addr(sym, psize);
  214. retval = get_v(a, pbuf, *psize);
  215. size = *psize;
  216. break;
  217. case UBOUND:
  218. a = get_addr(sym->sy_descr, psize);
  219. retval = get_v(a, pbuf, *psize);
  220. if (! retval) break;
  221. size = get_int(*pbuf, *psize, T_INTEGER);
  222. retval = get_v(a+*psize, pbuf, *psize);
  223. if (! retval) break;
  224. size += get_int(*pbuf, *psize, T_INTEGER);
  225. put_int(*pbuf, *psize, size);
  226. size = *psize;
  227. break;
  228. case LBOUND:
  229. a = get_addr(sym->sy_descr, psize);
  230. retval = get_v(a, pbuf, *psize);
  231. break;
  232. }
  233. if (retval == 0) {
  234. if (*pbuf) free(*pbuf);
  235. *pbuf = 0;
  236. *psize = 0;
  237. }
  238. else *psize = size;
  239. return retval;
  240. }
  241. /* buffer to integer and vice versa routines */
  242. long
  243. get_int(buf, size, class)
  244. char *buf;
  245. long size;
  246. int class;
  247. {
  248. register long l;
  249. switch((int)size) {
  250. case sizeof(char):
  251. l = *buf;
  252. if (class == T_INTEGER && l >= 0x7F) l -= 256;
  253. else if (class != T_INTEGER && l < 0) l += 256;
  254. break;
  255. case sizeof(short):
  256. l = *((short *) buf);
  257. if (class == T_INTEGER && l >= 0x7FFF) l -= 65536;
  258. else if (class != T_INTEGER && l < 0) l += 65536;
  259. break;
  260. default:
  261. l = *((long *) buf);
  262. }
  263. return l;
  264. }
  265. put_int(buf, size, value)
  266. char *buf;
  267. long size;
  268. long value;
  269. {
  270. switch((int)size) {
  271. case sizeof(char):
  272. *buf = value;
  273. break;
  274. case sizeof(short):
  275. *((short *) buf) = value;
  276. break;
  277. default:
  278. *((long *) buf) = value;
  279. break;
  280. }
  281. /*NOTREACHED*/
  282. }
  283. /* buffer to real and vice versa routines */
  284. double
  285. get_real(buf, size)
  286. char *buf;
  287. long size;
  288. {
  289. switch((int) size) {
  290. case sizeof(float):
  291. return *((float *) buf);
  292. default:
  293. return *((double *) buf);
  294. }
  295. /*NOTREACHED*/
  296. }
  297. put_real(buf, size, value)
  298. char *buf;
  299. long size;
  300. double value;
  301. {
  302. switch((int)size) {
  303. case sizeof(float):
  304. *((float *) buf) = value;
  305. break;
  306. default:
  307. *((double *) buf) = value;
  308. break;
  309. }
  310. /* NOTREACHED */
  311. }
  312. int
  313. convert(pbuf, psize, ptp, tp, size)
  314. char **pbuf;
  315. long *psize;
  316. register p_type *ptp;
  317. register p_type tp;
  318. long size;
  319. {
  320. /* Convert the value in pbuf, of size psize and type ptp, to type
  321. tp and leave the resulting value in pbuf, the resulting size
  322. in psize, and the resulting type in ptp.
  323. */
  324. long l;
  325. double d;
  326. if (*ptp == tp) return 1;
  327. if (size > *psize) {
  328. *pbuf = realloc(*pbuf, (unsigned int) size);
  329. malloc_succeeded(*pbuf);
  330. }
  331. if ((*ptp)->ty_class == T_SUBRANGE) *ptp = (*ptp)->ty_base;
  332. if (tp && *ptp) switch((*ptp)->ty_class) {
  333. case T_INTEGER:
  334. case T_UNSIGNED:
  335. case T_POINTER:
  336. case T_ENUM:
  337. l = get_int(*pbuf, *psize, (*ptp)->ty_class);
  338. if (tp == bool_type) l = l != 0;
  339. switch(tp->ty_class) {
  340. case T_SUBRANGE:
  341. case T_INTEGER:
  342. case T_UNSIGNED:
  343. case T_POINTER:
  344. case T_ENUM:
  345. put_int(*pbuf, size, l);
  346. *psize = size;
  347. *ptp = tp;
  348. return 1;
  349. case T_REAL:
  350. put_real(*pbuf,
  351. size,
  352. (*ptp)->ty_class == T_INTEGER
  353. ? (double) l
  354. : (double) (unsigned long) l);
  355. *psize = size;
  356. *ptp = tp;
  357. return 1;
  358. default:
  359. break;
  360. }
  361. break;
  362. case T_REAL:
  363. d = get_real(*pbuf, *psize);
  364. switch(tp->ty_class) {
  365. case T_ENUM:
  366. case T_SUBRANGE:
  367. case T_INTEGER:
  368. case T_UNSIGNED:
  369. case T_POINTER:
  370. if (tp == bool_type) put_int(*pbuf, size, (long) (d != 0));
  371. else put_int(*pbuf, size, (long) d);
  372. *psize = size;
  373. *ptp = tp;
  374. return 1;
  375. case T_REAL:
  376. put_real(*pbuf, size, d);
  377. *psize = size;
  378. *ptp = tp;
  379. return 1;
  380. default:
  381. break;
  382. }
  383. break;
  384. default:
  385. break;
  386. }
  387. error("illegal conversion");
  388. return 0;
  389. }
  390. int
  391. eval_cond(p)
  392. p_tree p;
  393. {
  394. char *buf;
  395. long size;
  396. p_type tp;
  397. long val;
  398. p_type target_tp = currlang->has_bool_type ? bool_type : int_type;
  399. if (eval_expr(p, &buf, &size, &tp)) {
  400. if (convert(&buf, &size, &tp, target_tp, target_tp->ty_size)) {
  401. val = get_int(buf, size, T_UNSIGNED);
  402. free(buf);
  403. return (int) (val != 0);
  404. }
  405. free(buf);
  406. }
  407. return 0;
  408. }
  409. /* one routine for each unary operator */
  410. static int
  411. not_op(p, pbuf, psize, ptp)
  412. p_tree p;
  413. char **pbuf;
  414. long *psize;
  415. p_type *ptp;
  416. {
  417. p_type target_tp = currlang->has_bool_type ? bool_type : int_type;
  418. if (eval_expr(p->t_args[0], pbuf, psize, ptp) &&
  419. convert(pbuf, psize, ptp, target_tp, target_tp->ty_size)) {
  420. put_int(*pbuf, *psize, (long) !get_int(*pbuf, *psize, T_UNSIGNED));
  421. return 1;
  422. }
  423. return 0;
  424. }
  425. static int
  426. bnot_op(p, pbuf, psize, ptp)
  427. p_tree p;
  428. char **pbuf;
  429. long *psize;
  430. p_type *ptp;
  431. {
  432. if (eval_expr(p->t_args[0], pbuf, psize, ptp)) {
  433. switch((*ptp)->ty_class) {
  434. case T_INTEGER:
  435. case T_ENUM:
  436. case T_UNSIGNED:
  437. case T_SUBRANGE:
  438. put_int(*pbuf, *psize, ~get_int(*pbuf, *psize, T_UNSIGNED));
  439. return 1;
  440. default:
  441. error("illegal operand type(s)");
  442. break;
  443. }
  444. }
  445. return 0;
  446. }
  447. static int
  448. ptr_addr(p, paddr, psize, ptp)
  449. p_tree p;
  450. t_addr *paddr;
  451. long *psize;
  452. p_type *ptp;
  453. {
  454. char *buf;
  455. if (eval_expr(p->t_args[0], &buf, psize, ptp)) {
  456. switch((*ptp)->ty_class) {
  457. case T_POINTER:
  458. *ptp = (*ptp)->ty_ptrto;
  459. *psize = (*ptp)->ty_size;
  460. *paddr = get_int(buf, pointer_size, T_UNSIGNED);
  461. free(buf);
  462. return 1;
  463. default:
  464. error("illegal operand of DEREF");
  465. free(buf);
  466. break;
  467. }
  468. }
  469. return 0;
  470. }
  471. static int
  472. deref_op(p, pbuf, psize, ptp)
  473. p_tree p;
  474. char **pbuf;
  475. long *psize;
  476. p_type *ptp;
  477. {
  478. t_addr addr;
  479. if (ptr_addr(p, &addr, psize, ptp)) {
  480. *pbuf = malloc((unsigned) *psize);
  481. malloc_succeeded(*pbuf);
  482. if (! get_bytes(*psize, addr, *pbuf)) {
  483. free(*pbuf);
  484. *pbuf = 0;
  485. return 0;
  486. }
  487. return 1;
  488. }
  489. return 0;
  490. }
  491. static int
  492. addr_op(p, pbuf, psize, ptp)
  493. p_tree p;
  494. char **pbuf;
  495. long *psize;
  496. p_type *ptp;
  497. {
  498. t_addr addr;
  499. if (eval_desig(p->t_args[0], &addr, psize, ptp)) {
  500. *pbuf = malloc((unsigned) pointer_size);
  501. malloc_succeeded(*pbuf);
  502. put_int(*pbuf, pointer_size, (long) addr);
  503. address_type->ty_ptrto = *ptp;
  504. *ptp = address_type;
  505. return 1;
  506. }
  507. return 0;
  508. }
  509. static int
  510. unmin_op(p, pbuf, psize, ptp)
  511. p_tree p;
  512. char **pbuf;
  513. long *psize;
  514. p_type *ptp;
  515. {
  516. if (eval_expr(p->t_args[0], pbuf, psize, ptp)) {
  517. switch((*ptp)->ty_class) {
  518. case T_SUBRANGE:
  519. case T_INTEGER:
  520. case T_ENUM:
  521. case T_UNSIGNED:
  522. put_int(*pbuf, *psize, -get_int(*pbuf, *psize, (*ptp)->ty_class));
  523. return 1;
  524. case T_REAL:
  525. put_real(*pbuf, *psize, -get_real(*pbuf, *psize));
  526. return 1;
  527. default:
  528. error("illegal operand of unary -");
  529. break;
  530. }
  531. }
  532. return 0;
  533. }
  534. static int
  535. unplus_op(p, pbuf, psize, ptp)
  536. p_tree p;
  537. char **pbuf;
  538. long *psize;
  539. p_type *ptp;
  540. {
  541. if (eval_expr(p->t_args[0], pbuf, psize, ptp)) {
  542. switch((*ptp)->ty_class) {
  543. case T_SUBRANGE:
  544. case T_INTEGER:
  545. case T_ENUM:
  546. case T_UNSIGNED:
  547. case T_REAL:
  548. return 1;
  549. default:
  550. error("illegal operand of unary +");
  551. break;
  552. }
  553. }
  554. return 0;
  555. }
  556. static int (*un_op[])() = {
  557. 0,
  558. not_op,
  559. deref_op,
  560. 0,
  561. 0,
  562. 0,
  563. 0,
  564. 0,
  565. 0,
  566. 0,
  567. 0,
  568. unplus_op,
  569. unmin_op,
  570. 0,
  571. 0,
  572. 0,
  573. 0,
  574. 0,
  575. 0,
  576. 0,
  577. 0,
  578. 0,
  579. 0,
  580. 0,
  581. bnot_op,
  582. 0,
  583. 0,
  584. 0,
  585. addr_op
  586. };
  587. static p_type
  588. balance(tp1, tp2)
  589. p_type tp1, tp2;
  590. {
  591. if (tp1->ty_class == T_SUBRANGE) tp1 = tp1->ty_base;
  592. if (tp2->ty_class == T_SUBRANGE) tp2 = tp2->ty_base;
  593. if (tp1 == tp2) return tp2;
  594. if (tp2->ty_class == T_REAL) {
  595. p_type tmp = tp1; tp1 = tp2; tp2 = tmp;
  596. }
  597. if (tp1->ty_class == T_REAL) {
  598. switch(tp2->ty_class) {
  599. case T_INTEGER:
  600. case T_UNSIGNED:
  601. case T_ENUM:
  602. return tp1;
  603. case T_REAL:
  604. return tp1->ty_size > tp2->ty_size ? tp1 : tp2;
  605. default:
  606. error("illegal type combination");
  607. return 0;
  608. }
  609. }
  610. if (tp2->ty_class == T_POINTER) {
  611. p_type tmp = tp1; tp1 = tp2; tp2 = tmp;
  612. }
  613. if (tp1->ty_class == T_POINTER) {
  614. switch(tp2->ty_class) {
  615. case T_INTEGER:
  616. case T_UNSIGNED:
  617. case T_POINTER:
  618. case T_ENUM:
  619. return tp1;
  620. default:
  621. error("illegal type combination");
  622. return 0;
  623. }
  624. }
  625. if (tp2->ty_class == T_UNSIGNED) {
  626. p_type tmp = tp1; tp1 = tp2; tp2 = tmp;
  627. }
  628. if (tp1->ty_class == T_UNSIGNED) {
  629. switch(tp2->ty_class) {
  630. case T_INTEGER:
  631. case T_UNSIGNED:
  632. if (tp1->ty_size >= tp2->ty_size) return tp1;
  633. return tp2;
  634. case T_ENUM:
  635. return tp1;
  636. default:
  637. error("illegal type combination");
  638. return 0;
  639. }
  640. }
  641. if (tp2->ty_class == T_INTEGER) {
  642. p_type tmp = tp1; tp1 = tp2; tp2 = tmp;
  643. }
  644. if (tp1->ty_class == T_INTEGER) {
  645. switch(tp2->ty_class) {
  646. case T_INTEGER:
  647. if (tp1->ty_size >= tp2->ty_size) return tp1;
  648. return tp2;
  649. case T_ENUM:
  650. return tp1;
  651. default:
  652. error("illegal type combination");
  653. return 0;
  654. }
  655. }
  656. error("illegal type combination");
  657. return 0;
  658. }
  659. static int
  660. andor_op(p, pbuf, psize, ptp)
  661. p_tree p;
  662. char **pbuf;
  663. long *psize;
  664. p_type *ptp;
  665. {
  666. long l1, l2;
  667. char *buf = 0;
  668. long size;
  669. p_type tp;
  670. p_type target_tp = currlang->has_bool_type ? bool_type : int_type;
  671. if (eval_expr(p->t_args[0], pbuf, psize, ptp) &&
  672. convert(pbuf, psize, ptp, target_tp, target_tp->ty_size) &&
  673. eval_expr(p->t_args[1], &buf, &size, &tp) &&
  674. convert(&buf, &size, &tp, target_tp, target_tp->ty_size)) {
  675. l1 = get_int(*pbuf, *psize, T_UNSIGNED);
  676. l2 = get_int(buf, size, T_UNSIGNED);
  677. put_int(*pbuf,
  678. *psize,
  679. p->t_whichoper == E_AND
  680. ? (long)(l1 && l2)
  681. : (long)(l1 || l2));
  682. free(buf);
  683. return 1;
  684. }
  685. if (buf) free(buf);
  686. return 0;
  687. }
  688. static int
  689. arith_op(p, pbuf, psize, ptp)
  690. p_tree p;
  691. char **pbuf;
  692. long *psize;
  693. p_type *ptp;
  694. {
  695. long l1, l2;
  696. double d1, d2;
  697. char *buf = 0;
  698. long size;
  699. p_type tp, balance_tp;
  700. if (!(eval_expr(p->t_args[0], pbuf, psize, ptp) &&
  701. eval_expr(p->t_args[1], &buf, &size, &tp))) {
  702. return 0;
  703. }
  704. if ((*ptp)->ty_class == T_POINTER) {
  705. if (currlang != c_dep ||
  706. (p->t_whichoper != E_PLUS && p->t_whichoper != E_MIN)) {
  707. error("illegal operand type(s)");
  708. free(buf);
  709. return 0;
  710. }
  711. l1 = get_int(*pbuf, *psize, T_UNSIGNED);
  712. if (tp->ty_class == T_POINTER) {
  713. if (p->t_whichoper != E_MIN) {
  714. error("illegal operand type(s)");
  715. free(buf);
  716. return 0;
  717. }
  718. l2 = get_int(buf, size, T_UNSIGNED);
  719. free(buf);
  720. *pbuf = Realloc(*pbuf, (unsigned) long_size);
  721. put_int(*pbuf, long_size, (l1 - l2)/(*ptp)->ty_ptrto->ty_size);
  722. *ptp = long_type;
  723. return 1;
  724. }
  725. if (! convert(&buf, &size, &tp, long_type, long_size)) {
  726. free(buf);
  727. return 0;
  728. }
  729. l2 = get_int(buf, size, T_INTEGER) * (*ptp)->ty_ptrto->ty_size;
  730. free(buf);
  731. buf = 0;
  732. if (p->t_whichoper == E_PLUS) l1 += l2;
  733. else l1 -= l2;
  734. put_int(*pbuf, *psize, l1);
  735. return 1;
  736. }
  737. if ((balance_tp = balance(*ptp, tp)) &&
  738. convert(pbuf, psize, ptp, balance_tp, balance_tp->ty_size) &&
  739. convert(&buf, &size, &tp, balance_tp, balance_tp->ty_size)) {
  740. switch(balance_tp->ty_class) {
  741. case T_INTEGER:
  742. case T_ENUM:
  743. case T_UNSIGNED:
  744. l1 = get_int(*pbuf, *psize, balance_tp->ty_class);
  745. l2 = get_int(buf, size, balance_tp->ty_class);
  746. free(buf);
  747. buf = 0;
  748. switch(p->t_whichoper) {
  749. case E_BAND:
  750. l1 &= l2;
  751. break;
  752. case E_BOR:
  753. l1 |= l2;
  754. break;
  755. case E_BXOR:
  756. l1 ^= l2;
  757. break;
  758. case E_PLUS:
  759. l1 += l2;
  760. break;
  761. case E_MIN:
  762. l1 -= l2;
  763. break;
  764. case E_MUL:
  765. l1 *= l2;
  766. break;
  767. case E_DIV:
  768. case E_ZDIV:
  769. if (! l2) {
  770. error("division by 0");
  771. return 0;
  772. }
  773. if (balance_tp->ty_class == T_INTEGER) {
  774. if ((l1 < 0) != (l2 < 0)) {
  775. if (l1 < 0) l1 = - l1;
  776. else l2 = -l2;
  777. if (p->t_whichoper == E_DIV) {
  778. l1 = -((l1+l2-1)/l2);
  779. }
  780. else {
  781. l1 = -(l1/l2);
  782. }
  783. }
  784. else l1 /= l2;
  785. }
  786. else l1 = (unsigned long) l1 /
  787. (unsigned long) l2;
  788. break;
  789. case E_MOD:
  790. case E_ZMOD:
  791. if (! l2) {
  792. error("modulo by 0");
  793. return 0;
  794. }
  795. if (balance_tp->ty_class == T_INTEGER) {
  796. if ((l1 < 0) != (l2 < 0)) {
  797. if (l1 < 0) l1 = - l1;
  798. else l2 = -l2;
  799. if (p->t_whichoper == E_MOD) {
  800. l1 = ((l1+l2-1)/l2)*l2 - l1;
  801. }
  802. else {
  803. l1 = (l1/l2)*l2 - l1;
  804. }
  805. }
  806. else l1 %= l2;
  807. }
  808. else l1 = (unsigned long) l1 %
  809. (unsigned long) l2;
  810. break;
  811. }
  812. put_int(*pbuf, *psize, l1);
  813. break;
  814. case T_REAL:
  815. d1 = get_real(*pbuf, *psize);
  816. d2 = get_real(buf, size);
  817. free(buf);
  818. buf = 0;
  819. switch(p->t_whichoper) {
  820. case E_DIV:
  821. case E_ZDIV:
  822. if (d2 == 0.0) {
  823. error("division by 0.0");
  824. return 0;
  825. }
  826. d1 /= d2;
  827. break;
  828. case E_PLUS:
  829. d1 += d2;
  830. break;
  831. case E_MIN:
  832. d1 -= d2;
  833. break;
  834. case E_MUL:
  835. d1 *= d2;
  836. break;
  837. }
  838. put_real(*pbuf, *psize, d1);
  839. break;
  840. default:
  841. error("illegal operand type(s)");
  842. free(buf);
  843. return 0;
  844. }
  845. return 1;
  846. }
  847. if (buf) free(buf);
  848. return 0;
  849. }
  850. static int
  851. sft_op(p, pbuf, psize, ptp)
  852. p_tree p;
  853. char **pbuf;
  854. long *psize;
  855. p_type *ptp;
  856. {
  857. long l1, l2;
  858. char *buf = 0;
  859. long size;
  860. p_type tp;
  861. if (eval_expr(p->t_args[0], pbuf, psize, ptp) &&
  862. eval_expr(p->t_args[1], &buf, &size, &tp) &&
  863. convert(&buf, &size, &tp, int_type, int_size)) {
  864. tp = *ptp;
  865. if (tp->ty_class == T_SUBRANGE) {
  866. tp = tp->ty_base;
  867. }
  868. switch(tp->ty_class) {
  869. case T_INTEGER:
  870. case T_ENUM:
  871. case T_UNSIGNED:
  872. l1 = get_int(*pbuf, *psize, tp->ty_class);
  873. l2 = get_int(buf, size, T_INTEGER);
  874. free(buf);
  875. buf = 0;
  876. switch(p->t_whichoper) {
  877. case E_LSFT:
  878. l1 <<= (int) l2;
  879. break;
  880. case E_RSFT:
  881. if (tp->ty_class == T_INTEGER) l1 >>= (int) l2;
  882. else l1 = (unsigned long) l1 >> (int) l2;
  883. break;
  884. }
  885. break;
  886. default:
  887. error("illegal operand type(s)");
  888. free(buf);
  889. return 0;
  890. }
  891. return 1;
  892. }
  893. if (buf) free(buf);
  894. return 0;
  895. }
  896. static int
  897. cmp_op(p, pbuf, psize, ptp)
  898. p_tree p;
  899. char **pbuf;
  900. long *psize;
  901. p_type *ptp;
  902. {
  903. long l1, l2;
  904. double d1, d2;
  905. char *buf = 0;
  906. long size;
  907. p_type tp, balance_tp;
  908. if (eval_expr(p->t_args[0], pbuf, psize, ptp) &&
  909. eval_expr(p->t_args[1], &buf, &size, &tp) &&
  910. (balance_tp = balance(*ptp, tp)) &&
  911. convert(pbuf, psize, ptp, balance_tp, balance_tp->ty_size) &&
  912. convert(&buf, &size, &tp, balance_tp, balance_tp->ty_size)) {
  913. switch(balance_tp->ty_class) {
  914. case T_INTEGER:
  915. case T_ENUM:
  916. case T_UNSIGNED:
  917. case T_POINTER:
  918. l1 = get_int(*pbuf, *psize, balance_tp->ty_class);
  919. l2 = get_int(buf, size, balance_tp->ty_class);
  920. free(buf);
  921. buf = 0;
  922. switch(p->t_whichoper) {
  923. case E_EQUAL:
  924. l1 = l1 == l2;
  925. break;
  926. case E_NOTEQUAL:
  927. l1 = l1 != l2;
  928. break;
  929. case E_LTEQUAL:
  930. if (balance_tp->ty_class == T_INTEGER) {
  931. l1 = l1 <= l2;
  932. }
  933. else l1 = (unsigned long) l1 <=
  934. (unsigned long) l2;
  935. break;
  936. case E_LT:
  937. if (balance_tp->ty_class == T_INTEGER) {
  938. l1 = l1 < l2;
  939. }
  940. else l1 = (unsigned long) l1 <
  941. (unsigned long) l2;
  942. break;
  943. case E_GTEQUAL:
  944. if (balance_tp->ty_class == T_INTEGER) {
  945. l1 = l1 >= l2;
  946. }
  947. else l1 = (unsigned long) l1 >=
  948. (unsigned long) l2;
  949. break;
  950. case E_GT:
  951. if (balance_tp->ty_class == T_INTEGER) {
  952. l1 = l1 > l2;
  953. }
  954. else l1 = (unsigned long) l1 >
  955. (unsigned long) l2;
  956. break;
  957. default:
  958. l1 = 0;
  959. assert(0);
  960. break;
  961. }
  962. break;
  963. case T_REAL:
  964. d1 = get_real(*pbuf, *psize);
  965. d2 = get_real(buf, size);
  966. free(buf);
  967. buf = 0;
  968. switch(p->t_whichoper) {
  969. case E_EQUAL:
  970. l1 = d1 == d2;
  971. break;
  972. case E_NOTEQUAL:
  973. l1 = d1 != d2;
  974. break;
  975. case E_LTEQUAL:
  976. l1 = d1 <= d2;
  977. break;
  978. case E_LT:
  979. l1 = d1 < d2;
  980. break;
  981. case E_GTEQUAL:
  982. l1 = d1 >= d2;
  983. break;
  984. case E_GT:
  985. l1 = d1 > d2;
  986. break;
  987. default:
  988. l1 = 0;
  989. assert(0);
  990. break;
  991. }
  992. break;
  993. default:
  994. error("illegal operand type(s)");
  995. free(buf);
  996. return 0;
  997. }
  998. if (*psize < int_size) {
  999. *psize = int_size;
  1000. *pbuf = realloc(*pbuf, (unsigned int) int_size);
  1001. malloc_succeeded(*pbuf);
  1002. }
  1003. else *psize = int_size;
  1004. if (currlang->has_bool_type) {
  1005. *ptp = bool_type;
  1006. }
  1007. else *ptp = int_type;
  1008. put_int(*pbuf, *psize, l1);
  1009. return 1;
  1010. }
  1011. if (buf) free(buf);
  1012. return 0;
  1013. }
  1014. static int
  1015. in_op(p, pbuf, psize, ptp)
  1016. p_tree p;
  1017. char **pbuf;
  1018. long *psize;
  1019. p_type *ptp;
  1020. {
  1021. long l;
  1022. char *buf = 0;
  1023. long size;
  1024. p_type tp;
  1025. int sft = int_size == 2 ? 4 : 5;
  1026. if (eval_expr(p->t_args[0], pbuf, psize, ptp) &&
  1027. eval_expr(p->t_args[1], &buf, &size, &tp)) {
  1028. if (tp->ty_class != T_SET) {
  1029. error("right-hand side of IN not a set");
  1030. free(buf);
  1031. return 0;
  1032. }
  1033. if (! convert(pbuf, psize, ptp, tp->ty_setbase, int_size)) {
  1034. free(buf);
  1035. return 0;
  1036. }
  1037. l = get_int(*pbuf, *psize, (*ptp)->ty_class) - tp->ty_setlow;
  1038. l = l >= 0
  1039. && l <= (size << 3)
  1040. && (((int *) buf)[(int)(l>>sft)] & (1 << (l & ((1 << sft)-1))));
  1041. free(buf);
  1042. *pbuf = realloc(*pbuf, (unsigned) int_size);
  1043. malloc_succeeded(*pbuf);
  1044. *psize = int_size;
  1045. *ptp = currlang->has_bool_type ? bool_type : int_type;
  1046. put_int(*pbuf, *psize, l);
  1047. return 1;
  1048. }
  1049. return 0;
  1050. }
  1051. static int
  1052. array_addr(p, paddr, psize, ptp)
  1053. p_tree p;
  1054. t_addr *paddr;
  1055. long *psize;
  1056. p_type *ptp;
  1057. {
  1058. long l;
  1059. char *buf = 0;
  1060. long size;
  1061. p_type tp;
  1062. if (eval_desig(p->t_args[0], paddr, psize, ptp) &&
  1063. eval_expr(p->t_args[1], &buf, &size, &tp)) {
  1064. if ((*ptp)->ty_class != T_ARRAY && (*ptp)->ty_class != T_POINTER) {
  1065. error("illegal left-hand side of [");
  1066. free(buf);
  1067. return 0;
  1068. }
  1069. if ((*ptp)->ty_class == T_POINTER) {
  1070. if (! get_bytes(pointer_size, *paddr, (char *) paddr)) {
  1071. free(buf);
  1072. return 0;
  1073. }
  1074. *paddr = get_int((char *) paddr, pointer_size, T_UNSIGNED);
  1075. }
  1076. if (! convert(&buf, &size, &tp, int_type, int_size)) {
  1077. free(buf);
  1078. return 0;
  1079. }
  1080. l = get_int(buf, size, T_INTEGER);
  1081. free(buf);
  1082. buf = 0;
  1083. if ((*ptp)->ty_class == T_ARRAY) {
  1084. if (l < (*ptp)->ty_lb || l > (*ptp)->ty_hb) {
  1085. error("array bound error");
  1086. return 0;
  1087. }
  1088. l -= (*ptp)->ty_lb;
  1089. *ptp = (*ptp)->ty_elements;
  1090. l *= (*currlang->arrayelsize)((*ptp)->ty_size);
  1091. }
  1092. else {
  1093. *ptp = (*ptp)->ty_ptrto;
  1094. l *= (*ptp)->ty_size;
  1095. }
  1096. *psize = (*ptp)->ty_size;
  1097. *paddr += l;
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. static int
  1103. array_op(p, pbuf, psize, ptp)
  1104. p_tree p;
  1105. char **pbuf;
  1106. long *psize;
  1107. p_type *ptp;
  1108. {
  1109. t_addr a;
  1110. if (array_addr(p, &a, psize, ptp)) {
  1111. *pbuf = malloc((unsigned int) *psize);
  1112. malloc_succeeded(*pbuf);
  1113. if (! get_bytes(*psize, a, *pbuf)) {
  1114. return 0;
  1115. }
  1116. return 1;
  1117. }
  1118. return 0;
  1119. }
  1120. static int
  1121. select_addr(p, paddr, psize, ptp)
  1122. p_tree p;
  1123. t_addr *paddr;
  1124. long *psize;
  1125. p_type *ptp;
  1126. {
  1127. register p_type tp;
  1128. register struct fields *f;
  1129. register int nf;
  1130. if (eval_desig(p->t_args[0], paddr, psize, ptp)) {
  1131. tp = *ptp;
  1132. if (tp->ty_class != T_STRUCT && tp->ty_class != T_UNION) {
  1133. error("SELECT on non-struct");
  1134. return 0;
  1135. }
  1136. if (p->t_args[1]->t_oper != OP_NAME) {
  1137. error("right-hand side of SELECT not a name");
  1138. return 0;
  1139. }
  1140. for (nf = tp->ty_nfields, f = tp->ty_fields; nf; nf--, f++) {
  1141. if (! strcmp(f->fld_name, p->t_args[1]->t_str)) break;
  1142. }
  1143. if (! nf) {
  1144. error("'%s' not found", p->t_args[1]->t_str);
  1145. return 0;
  1146. }
  1147. /* ??? this needs some work for bitfields ??? */
  1148. *paddr += f->fld_pos>>3;
  1149. *psize = f->fld_bitsize >> 3;
  1150. *ptp = f->fld_type;
  1151. return 1;
  1152. }
  1153. return 0;
  1154. }
  1155. static int
  1156. select_op(p, pbuf, psize, ptp)
  1157. p_tree p;
  1158. char **pbuf;
  1159. long *psize;
  1160. p_type *ptp;
  1161. {
  1162. t_addr a;
  1163. if (select_addr(p, &a, psize, ptp)) {
  1164. *pbuf = malloc((unsigned int) *psize);
  1165. malloc_succeeded(*pbuf);
  1166. if (! get_bytes(*psize, a, *pbuf)) {
  1167. free(*pbuf);
  1168. *pbuf = 0;
  1169. return 0;
  1170. }
  1171. return 1;
  1172. }
  1173. return 0;
  1174. }
  1175. static int
  1176. derselect_op(p, pbuf, psize, ptp)
  1177. p_tree p;
  1178. char **pbuf;
  1179. long *psize;
  1180. p_type *ptp;
  1181. {
  1182. int retval;
  1183. t_tree t;
  1184. t.t_oper = OP_UNOP;
  1185. t.t_whichoper = E_DEREF;
  1186. t.t_args[0] = p->t_args[0];
  1187. p->t_args[0] = &t;
  1188. p->t_whichoper = E_SELECT;
  1189. retval = eval_expr(p, pbuf, psize, ptp);
  1190. p->t_args[0] = t.t_args[0];
  1191. p->t_whichoper = E_DERSELECT;
  1192. return retval;
  1193. }
  1194. static int (*bin_op[])() = {
  1195. 0,
  1196. 0,
  1197. 0,
  1198. andor_op,
  1199. andor_op,
  1200. arith_op,
  1201. arith_op,
  1202. arith_op,
  1203. arith_op,
  1204. in_op,
  1205. array_op,
  1206. arith_op,
  1207. arith_op,
  1208. arith_op,
  1209. cmp_op,
  1210. cmp_op,
  1211. cmp_op,
  1212. cmp_op,
  1213. cmp_op,
  1214. cmp_op,
  1215. select_op,
  1216. arith_op,
  1217. arith_op,
  1218. arith_op,
  1219. 0,
  1220. derselect_op,
  1221. sft_op,
  1222. sft_op,
  1223. 0
  1224. };
  1225. int
  1226. eval_expr(p, pbuf, psize, ptp)
  1227. p_tree p;
  1228. char **pbuf;
  1229. long *psize;
  1230. p_type *ptp;
  1231. {
  1232. register p_symbol sym;
  1233. int retval = 0;
  1234. *pbuf = 0;
  1235. switch(p->t_oper) {
  1236. case OP_FORMAT:
  1237. if (eval_expr(p->t_args[0], pbuf, psize, ptp)) retval = 1;
  1238. break;
  1239. case OP_NAME:
  1240. case OP_SELECT:
  1241. sym = identify(p, VAR|REGVAR|LOCVAR|VARPAR|CONST|LBOUND|UBOUND);
  1242. if (! sym) return 0;
  1243. if (! get_value(sym, pbuf, psize)) {
  1244. break;
  1245. }
  1246. *ptp = sym->sy_type;
  1247. retval = 1;
  1248. break;
  1249. case OP_INTEGER:
  1250. *pbuf = malloc((unsigned int) long_size);
  1251. malloc_succeeded(*pbuf);
  1252. *psize = long_size;
  1253. *ptp = long_type;
  1254. put_int(*pbuf, long_size, p->t_ival);
  1255. retval = 1;
  1256. break;
  1257. case OP_REAL:
  1258. *pbuf = malloc((unsigned int) double_size);
  1259. malloc_succeeded(*pbuf);
  1260. *psize = double_size;
  1261. *ptp = double_type;
  1262. put_real(*pbuf, double_size, p->t_fval);
  1263. retval = 1;
  1264. break;
  1265. case OP_STRING:
  1266. *psize = strlen(p->t_sval)+1;
  1267. *pbuf = malloc((unsigned int)*psize);
  1268. malloc_succeeded(*pbuf);
  1269. *ptp = string_type;
  1270. strcpy(*pbuf, p->t_sval);
  1271. retval = 1;
  1272. break;
  1273. case OP_UNOP:
  1274. retval = (*un_op[p->t_whichoper])(p, pbuf, psize, ptp);
  1275. break;
  1276. case OP_BINOP:
  1277. retval = (*bin_op[p->t_whichoper])(p, pbuf, psize, ptp);
  1278. break;
  1279. default:
  1280. assert(0);
  1281. break;
  1282. }
  1283. if (! retval) {
  1284. if (*pbuf) {
  1285. free(*pbuf);
  1286. *pbuf = 0;
  1287. }
  1288. *psize = 0;
  1289. }
  1290. else {
  1291. if ((*ptp)->ty_class == T_CROSS) {
  1292. *ptp = (*ptp)->ty_cross;
  1293. if (! *ptp) *ptp = void_type;
  1294. }
  1295. }
  1296. return retval;
  1297. }
  1298. int
  1299. eval_desig(p, paddr, psize, ptp)
  1300. p_tree p;
  1301. t_addr *paddr;
  1302. long *psize;
  1303. p_type *ptp;
  1304. {
  1305. register p_symbol sym;
  1306. int retval = 0;
  1307. t_addr a;
  1308. switch(p->t_oper) {
  1309. case OP_NAME:
  1310. case OP_SELECT:
  1311. sym = identify(p, VAR|REGVAR|LOCVAR|VARPAR);
  1312. if (! sym) return 0;
  1313. if (! (a = get_addr(sym, psize))) {
  1314. break;
  1315. }
  1316. *paddr = a;
  1317. *ptp = sym->sy_type;
  1318. retval = 1;
  1319. break;
  1320. case OP_UNOP:
  1321. switch(p->t_whichoper) {
  1322. case E_DEREF:
  1323. if (ptr_addr(p, paddr, psize, ptp)) {
  1324. retval = 1;
  1325. }
  1326. break;
  1327. default:
  1328. print_node(db_out, p, 0);
  1329. fputs(" not a designator\n", db_out);
  1330. break;
  1331. }
  1332. break;
  1333. case OP_BINOP:
  1334. switch(p->t_whichoper) {
  1335. case E_ARRAY:
  1336. if (array_addr(p, paddr, psize, ptp)) {
  1337. retval = 1;
  1338. }
  1339. break;
  1340. case E_SELECT:
  1341. if (select_addr(p, paddr, psize, ptp)) {
  1342. retval = 1;
  1343. }
  1344. break;
  1345. default:
  1346. print_node(db_out, p, 0);
  1347. fputs(" not a designator\n", db_out);
  1348. break;
  1349. }
  1350. break;
  1351. default:
  1352. error("illegal designator");
  1353. break;
  1354. }
  1355. if (! retval) {
  1356. *psize = 0;
  1357. }
  1358. else {
  1359. if ((*ptp)->ty_class == T_CROSS) {
  1360. *ptp = (*ptp)->ty_cross;
  1361. if (! *ptp) {
  1362. *ptp = void_type;
  1363. print_node(db_out, p, 0);
  1364. fputs(" designator has unknown type\n", db_out);
  1365. retval = 0;
  1366. *psize = 0;
  1367. }
  1368. }
  1369. }
  1370. return retval;
  1371. }