tcinl.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Type checking and register allocation for inline nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit tcinl;
  19. interface
  20. uses
  21. tree;
  22. procedure firstinline(var p : ptree);
  23. implementation
  24. uses
  25. cobjects,verbose,globals,systems,
  26. symtable,aasm,types,
  27. hcodegen,htypechk,pass_1,
  28. tccal,tcld
  29. {$ifdef i386}
  30. ,i386,tgeni386
  31. {$endif}
  32. {$ifdef m68k}
  33. ,m68k,tgen68k
  34. {$endif}
  35. ;
  36. {*****************************************************************************
  37. FirstInLine
  38. *****************************************************************************}
  39. procedure firstinline(var p : ptree);
  40. var
  41. vl : longint;
  42. vr : bestreal;
  43. hp,hpp : ptree;
  44. store_count_ref,
  45. isreal,
  46. dowrite,
  47. store_valid,
  48. file_is_typed : boolean;
  49. procedure do_lowhigh(adef : pdef);
  50. var
  51. v : longint;
  52. enum : penumsym;
  53. begin
  54. case Adef^.deftype of
  55. orddef:
  56. begin
  57. if p^.inlinenumber=in_low_x then
  58. v:=porddef(Adef)^.low
  59. else
  60. v:=porddef(Adef)^.high;
  61. hp:=genordinalconstnode(v,adef);
  62. firstpass(hp);
  63. disposetree(p);
  64. p:=hp;
  65. end;
  66. enumdef:
  67. begin
  68. enum:=Penumdef(Adef)^.first;
  69. if p^.inlinenumber=in_high_x then
  70. while enum^.next<>nil do
  71. enum:=enum^.next;
  72. hp:=genenumnode(enum);
  73. disposetree(p);
  74. p:=hp;
  75. end
  76. end;
  77. end;
  78. begin
  79. store_valid:=must_be_valid;
  80. store_count_ref:=count_ref;
  81. count_ref:=false;
  82. if not (p^.inlinenumber in [in_read_x,in_readln_x,in_sizeof_x,
  83. in_typeof_x,in_ord_x,in_str_x_string,
  84. in_reset_typedfile,in_rewrite_typedfile]) then
  85. must_be_valid:=true
  86. else
  87. must_be_valid:=false;
  88. { if we handle writeln; p^.left contains no valid address }
  89. if assigned(p^.left) then
  90. begin
  91. if p^.left^.treetype=callparan then
  92. firstcallparan(p^.left,nil)
  93. else
  94. firstpass(p^.left);
  95. left_right_max(p);
  96. set_location(p^.location,p^.left^.location);
  97. end;
  98. { handle intern constant functions in separate case }
  99. if p^.inlineconst then
  100. begin
  101. { no parameters? }
  102. if not assigned(p^.left) then
  103. begin
  104. case p^.inlinenumber of
  105. in_const_pi : begin
  106. hp:=genrealconstnode(pi);
  107. end;
  108. else
  109. internalerror(89);
  110. end;
  111. end
  112. else
  113. { process constant expression with parameter }
  114. begin
  115. if not(p^.left^.treetype in [realconstn,ordconstn]) then
  116. begin
  117. CGMessage(cg_e_illegal_expression);
  118. vl:=0;
  119. vr:=0;
  120. isreal:=false;
  121. end
  122. else
  123. begin
  124. isreal:=(p^.left^.treetype=realconstn);
  125. vl:=p^.left^.value;
  126. vr:=p^.left^.value_real;
  127. end;
  128. case p^.inlinenumber of
  129. in_const_trunc : begin
  130. if isreal then
  131. hp:=genordinalconstnode(trunc(vr),s32bitdef)
  132. else
  133. hp:=genordinalconstnode(trunc(vl),s32bitdef);
  134. end;
  135. in_const_round : begin
  136. if isreal then
  137. hp:=genordinalconstnode(round(vr),s32bitdef)
  138. else
  139. hp:=genordinalconstnode(round(vl),s32bitdef);
  140. end;
  141. in_const_frac : begin
  142. if isreal then
  143. hp:=genrealconstnode(frac(vr))
  144. else
  145. hp:=genrealconstnode(frac(vl));
  146. end;
  147. in_const_int : begin
  148. if isreal then
  149. hp:=genrealconstnode(int(vr))
  150. else
  151. hp:=genrealconstnode(int(vl));
  152. end;
  153. in_const_abs : begin
  154. if isreal then
  155. hp:=genrealconstnode(abs(vr))
  156. else
  157. hp:=genordinalconstnode(abs(vl),p^.left^.resulttype);
  158. end;
  159. in_const_sqr : begin
  160. if isreal then
  161. hp:=genrealconstnode(sqr(vr))
  162. else
  163. hp:=genordinalconstnode(sqr(vl),p^.left^.resulttype);
  164. end;
  165. in_const_odd : begin
  166. if isreal then
  167. CGMessage(type_e_integer_expr_expected)
  168. else
  169. hp:=genordinalconstnode(byte(odd(vl)),booldef);
  170. end;
  171. in_const_swap_word : begin
  172. if isreal then
  173. CGMessage(type_e_integer_expr_expected)
  174. else
  175. hp:=genordinalconstnode((vl and $ff) shl 8+(vl shr 8),p^.left^.resulttype);
  176. end;
  177. in_const_swap_long : begin
  178. if isreal then
  179. CGMessage(type_e_mismatch)
  180. else
  181. hp:=genordinalconstnode((vl and $ffff) shl 16+(vl shr 16),p^.left^.resulttype);
  182. end;
  183. in_const_ptr : begin
  184. if isreal then
  185. CGMessage(type_e_mismatch)
  186. else
  187. hp:=genordinalconstnode(vl,voidpointerdef);
  188. end;
  189. in_const_sqrt : begin
  190. if isreal then
  191. hp:=genrealconstnode(sqrt(vr))
  192. else
  193. hp:=genrealconstnode(sqrt(vl));
  194. end;
  195. in_const_arctan : begin
  196. if isreal then
  197. hp:=genrealconstnode(arctan(vr))
  198. else
  199. hp:=genrealconstnode(arctan(vl));
  200. end;
  201. in_const_cos : begin
  202. if isreal then
  203. hp:=genrealconstnode(cos(vr))
  204. else
  205. hp:=genrealconstnode(cos(vl));
  206. end;
  207. in_const_sin : begin
  208. if isreal then
  209. hp:=genrealconstnode(sin(vr))
  210. else
  211. hp:=genrealconstnode(sin(vl));
  212. end;
  213. in_const_exp : begin
  214. if isreal then
  215. hp:=genrealconstnode(exp(vr))
  216. else
  217. hp:=genrealconstnode(exp(vl));
  218. end;
  219. in_const_ln : begin
  220. if isreal then
  221. hp:=genrealconstnode(ln(vr))
  222. else
  223. hp:=genrealconstnode(ln(vl));
  224. end;
  225. else
  226. internalerror(88);
  227. end;
  228. end;
  229. disposetree(p);
  230. firstpass(hp);
  231. p:=hp;
  232. end
  233. else
  234. begin
  235. case p^.inlinenumber of
  236. in_lo_long,in_hi_long,
  237. in_lo_word,in_hi_word:
  238. begin
  239. if p^.registers32<1 then
  240. p^.registers32:=1;
  241. if p^.inlinenumber in [in_lo_word,in_hi_word] then
  242. p^.resulttype:=u8bitdef
  243. else
  244. p^.resulttype:=u16bitdef;
  245. p^.location.loc:=LOC_REGISTER;
  246. if not is_integer(p^.left^.resulttype) then
  247. CGMessage(type_e_mismatch)
  248. else
  249. begin
  250. if p^.left^.treetype=ordconstn then
  251. begin
  252. case p^.inlinenumber of
  253. in_lo_word : hp:=genordinalconstnode(p^.left^.value and $ff,p^.left^.resulttype);
  254. in_hi_word : hp:=genordinalconstnode(p^.left^.value shr 8,p^.left^.resulttype);
  255. in_lo_long : hp:=genordinalconstnode(p^.left^.value and $ffff,p^.left^.resulttype);
  256. in_hi_long : hp:=genordinalconstnode(p^.left^.value shr 16,p^.left^.resulttype);
  257. end;
  258. disposetree(p);
  259. firstpass(hp);
  260. p:=hp;
  261. end;
  262. end;
  263. end;
  264. in_sizeof_x:
  265. begin
  266. if p^.registers32<1 then
  267. p^.registers32:=1;
  268. p^.resulttype:=s32bitdef;
  269. p^.location.loc:=LOC_REGISTER;
  270. end;
  271. in_typeof_x:
  272. begin
  273. if p^.registers32<1 then
  274. p^.registers32:=1;
  275. p^.location.loc:=LOC_REGISTER;
  276. p^.resulttype:=voidpointerdef;
  277. end;
  278. in_ord_x:
  279. begin
  280. if (p^.left^.treetype=ordconstn) then
  281. begin
  282. hp:=genordinalconstnode(p^.left^.value,s32bitdef);
  283. disposetree(p);
  284. p:=hp;
  285. firstpass(p);
  286. end
  287. else
  288. begin
  289. if (p^.left^.resulttype^.deftype=orddef) then
  290. if (porddef(p^.left^.resulttype)^.typ in [uchar,bool8bit]) then
  291. begin
  292. if porddef(p^.left^.resulttype)^.typ=bool8bit then
  293. begin
  294. hp:=gentypeconvnode(p^.left,u8bitdef);
  295. putnode(p);
  296. p:=hp;
  297. p^.convtyp:=tc_bool_2_int;
  298. p^.explizit:=true;
  299. firstpass(p);
  300. end
  301. else
  302. begin
  303. hp:=gentypeconvnode(p^.left,u8bitdef);
  304. putnode(p);
  305. p:=hp;
  306. p^.explizit:=true;
  307. firstpass(p);
  308. end;
  309. end
  310. { can this happen ? }
  311. else if (porddef(p^.left^.resulttype)^.typ=uvoid) then
  312. CGMessage(type_e_mismatch)
  313. else
  314. { all other orddef need no transformation }
  315. begin
  316. hp:=p^.left;
  317. putnode(p);
  318. p:=hp;
  319. end
  320. else if (p^.left^.resulttype^.deftype=enumdef) then
  321. begin
  322. hp:=gentypeconvnode(p^.left,s32bitdef);
  323. putnode(p);
  324. p:=hp;
  325. p^.explizit:=true;
  326. firstpass(p);
  327. end
  328. else
  329. begin
  330. { can anything else be ord() ?}
  331. CGMessage(type_e_mismatch);
  332. end;
  333. end;
  334. end;
  335. in_chr_byte:
  336. begin
  337. hp:=gentypeconvnode(p^.left,cchardef);
  338. putnode(p);
  339. p:=hp;
  340. p^.explizit:=true;
  341. firstpass(p);
  342. end;
  343. in_length_string:
  344. begin
  345. if is_ansistring(p^.left^.resulttype) then
  346. p^.resulttype:=s32bitdef
  347. else
  348. p^.resulttype:=u8bitdef;
  349. { wer don't need string conversations here }
  350. if (p^.left^.treetype=typeconvn) and
  351. (p^.left^.left^.resulttype^.deftype=stringdef) then
  352. begin
  353. hp:=p^.left^.left;
  354. putnode(p^.left);
  355. p^.left:=hp;
  356. end;
  357. { evaluates length of constant strings direct }
  358. if (p^.left^.treetype=stringconstn) then
  359. begin
  360. hp:=genordinalconstnode(p^.left^.length,s32bitdef);
  361. disposetree(p);
  362. firstpass(hp);
  363. p:=hp;
  364. end
  365. { length of char is one allways }
  366. else if (p^.left^.treetype=ordconstn) then
  367. if (porddef(p^.left^.resulttype)^.typ=uchar) then
  368. begin
  369. hp:=genordinalconstnode(1,s32bitdef);
  370. disposetree(p);
  371. firstpass(hp);
  372. p:=hp;
  373. end
  374. else
  375. CGMessage(type_e_mismatch);
  376. ;
  377. end;
  378. in_assigned_x:
  379. begin
  380. p^.resulttype:=booldef;
  381. p^.location.loc:=LOC_FLAGS;
  382. end;
  383. in_pred_x,
  384. in_succ_x:
  385. begin
  386. inc(p^.registers32);
  387. p^.resulttype:=p^.left^.resulttype;
  388. p^.location.loc:=LOC_REGISTER;
  389. if not is_ordinal(p^.resulttype) then
  390. CGMessage(type_e_ordinal_expr_expected)
  391. else
  392. begin
  393. if (p^.resulttype^.deftype=enumdef) and
  394. (penumdef(p^.resulttype)^.has_jumps) then
  395. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible)
  396. else
  397. if p^.left^.treetype=ordconstn then
  398. begin
  399. if p^.inlinenumber=in_succ_x then
  400. hp:=genordinalconstnode(p^.left^.value+1,p^.left^.resulttype)
  401. else
  402. hp:=genordinalconstnode(p^.left^.value-1,p^.left^.resulttype);
  403. disposetree(p);
  404. firstpass(hp);
  405. p:=hp;
  406. end;
  407. end;
  408. end;
  409. in_inc_x,
  410. in_dec_x:
  411. begin
  412. p^.resulttype:=voiddef;
  413. if assigned(p^.left) then
  414. begin
  415. firstcallparan(p^.left,nil);
  416. if codegenerror then
  417. exit;
  418. { first param must be var }
  419. if is_constnode(p^.left^.left) then
  420. CGMessage(type_e_variable_id_expected);
  421. { check type }
  422. if (p^.left^.resulttype^.deftype in [enumdef,pointerdef]) or
  423. is_ordinal(p^.left^.resulttype) then
  424. begin
  425. { two paras ? }
  426. if assigned(p^.left^.right) then
  427. begin
  428. { insert a type conversion }
  429. { the second param is always longint }
  430. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,s32bitdef);
  431. { check the type conversion }
  432. firstpass(p^.left^.right^.left);
  433. { need we an additional register ? }
  434. if not(is_constintnode(p^.left^.right^.left)) and
  435. (p^.left^.right^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  436. (p^.left^.right^.left^.registers32<1) then
  437. inc(p^.registers32);
  438. if assigned(p^.left^.right^.right) then
  439. CGMessage(cg_e_illegal_expression);
  440. end;
  441. end
  442. else
  443. CGMessage(type_e_ordinal_expr_expected);
  444. end
  445. else
  446. CGMessage(type_e_mismatch);
  447. end;
  448. in_read_x,
  449. in_readln_x,
  450. in_write_x,
  451. in_writeln_x :
  452. begin
  453. { needs a call }
  454. procinfo.flags:=procinfo.flags or pi_do_call;
  455. p^.resulttype:=voiddef;
  456. { we must know if it is a typed file or not }
  457. { but we must first do the firstpass for it }
  458. file_is_typed:=false;
  459. if assigned(p^.left) then
  460. begin
  461. firstcallparan(p^.left,nil);
  462. { now we can check }
  463. hp:=p^.left;
  464. while assigned(hp^.right) do
  465. hp:=hp^.right;
  466. { if resulttype is not assigned, then automatically }
  467. { file is not typed. }
  468. if assigned(hp) and assigned(hp^.resulttype) then
  469. Begin
  470. if (hp^.resulttype^.deftype=filedef) and
  471. (pfiledef(hp^.resulttype)^.filetype=ft_typed) then
  472. begin
  473. file_is_typed:=true;
  474. { test the type }
  475. hpp:=p^.left;
  476. while (hpp<>hp) do
  477. begin
  478. if (hpp^.left^.treetype=typen) then
  479. CGMessage(type_e_cant_read_write_type);
  480. if not is_equal(hpp^.resulttype,pfiledef(hp^.resulttype)^.typed_as) then
  481. CGMessage(type_e_mismatch);
  482. hpp:=hpp^.right;
  483. end;
  484. end;
  485. end; { endif assigned(hp) }
  486. { insert type conversions for write(ln) }
  487. if (not file_is_typed) then
  488. begin
  489. dowrite:=(p^.inlinenumber in [in_write_x,in_writeln_x]);
  490. hp:=p^.left;
  491. while assigned(hp) do
  492. begin
  493. if (hp^.left^.treetype=typen) then
  494. CGMessage(type_e_cant_read_write_type);
  495. if assigned(hp^.left^.resulttype) then
  496. begin
  497. isreal:=false;
  498. case hp^.left^.resulttype^.deftype of
  499. filedef : begin
  500. { only allowed as first parameter }
  501. if assigned(hp^.right) then
  502. CGMessage(type_e_cant_read_write_type);
  503. end;
  504. stringdef : ;
  505. pointerdef : begin
  506. if not is_equal(ppointerdef(hp^.left^.resulttype)^.definition,cchardef) then
  507. CGMessage(type_e_cant_read_write_type);
  508. end;
  509. floatdef : begin
  510. isreal:=true;
  511. end;
  512. orddef : begin
  513. case porddef(hp^.left^.resulttype)^.typ of
  514. uchar,
  515. u32bit,s32bit : ;
  516. u8bit,s8bit,
  517. u16bit,s16bit : if dowrite then
  518. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  519. bool8bit,
  520. bool16bit,bool32bit : if dowrite then
  521. hp^.left:=gentypeconvnode(hp^.left,booldef)
  522. else
  523. CGMessage(type_e_cant_read_write_type);
  524. else
  525. CGMessage(type_e_cant_read_write_type);
  526. end;
  527. end;
  528. arraydef : begin
  529. if not((parraydef(hp^.left^.resulttype)^.lowrange=0) and
  530. is_equal(parraydef(hp^.left^.resulttype)^.definition,cchardef)) then
  531. begin
  532. { but we convert only if the first index<>0,
  533. because in this case we have a ASCIIZ string }
  534. if dowrite and
  535. (parraydef(hp^.left^.resulttype)^.lowrange<>0) and
  536. (parraydef(hp^.left^.resulttype)^.definition^.deftype=orddef) and
  537. (porddef(parraydef(hp^.left^.resulttype)^.definition)^.typ=uchar) then
  538. hp^.left:=gentypeconvnode(hp^.left,cshortstringdef)
  539. else
  540. CGMessage(type_e_cant_read_write_type);
  541. end;
  542. end;
  543. else
  544. CGMessage(type_e_cant_read_write_type);
  545. end;
  546. { some format options ? }
  547. (* commented
  548. because supposes reverse order of parameters
  549. PM
  550. hpp:=hp^.right;
  551. if assigned(hpp) and hpp^.is_colon_para then
  552. begin
  553. if (not is_integer(hpp^.resulttype)) then
  554. CGMessage(type_e_integer_expr_expected)
  555. else
  556. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  557. hpp:=hpp^.right;
  558. if assigned(hpp) and hpp^.is_colon_para then
  559. begin
  560. if isreal then
  561. begin
  562. if (not is_integer(hpp^.resulttype)) then
  563. CGMessage(type_e_integer_expr_expected)
  564. else
  565. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  566. end
  567. else
  568. CGMessage(parser_e_illegal_colon_qualifier);
  569. end;
  570. end; *)
  571. end;
  572. hp:=hp^.right;
  573. end;
  574. end;
  575. { pass all parameters again for the typeconversions }
  576. if codegenerror then
  577. exit;
  578. must_be_valid:=true;
  579. firstcallparan(p^.left,nil);
  580. { calc registers }
  581. left_right_max(p);
  582. end;
  583. end;
  584. in_settextbuf_file_x :
  585. begin
  586. { warning here p^.left is the callparannode
  587. not the argument directly }
  588. { p^.left^.left is text var }
  589. { p^.left^.right^.left is the buffer var }
  590. { firstcallparan(p^.left,nil);
  591. already done in firstcalln }
  592. { now we know the type of buffer }
  593. getsymonlyin(systemunit,'SETTEXTBUF');
  594. hp:=gencallnode(pprocsym(srsym),systemunit);
  595. hp^.left:=gencallparanode(
  596. genordinalconstnode(p^.left^.left^.resulttype^.size,s32bitdef),p^.left);
  597. putnode(p);
  598. p:=hp;
  599. firstpass(p);
  600. end;
  601. { the firstpass of the arg has been done in firstcalln ? }
  602. in_reset_typedfile,in_rewrite_typedfile :
  603. begin
  604. procinfo.flags:=procinfo.flags or pi_do_call;
  605. { to be sure the right definition is loaded }
  606. p^.left^.resulttype:=nil;
  607. firstload(p^.left);
  608. p^.resulttype:=voiddef;
  609. end;
  610. in_str_x_string :
  611. begin
  612. procinfo.flags:=procinfo.flags or pi_do_call;
  613. p^.resulttype:=voiddef;
  614. if assigned(p^.left) then
  615. begin
  616. hp:=p^.left^.right;
  617. { first pass just the string for first local use }
  618. must_be_valid:=false;
  619. count_ref:=true;
  620. p^.left^.right:=nil;
  621. firstcallparan(p^.left,nil);
  622. must_be_valid:=true;
  623. p^.left^.right:=hp;
  624. firstcallparan(p^.left^.right,nil);
  625. hp:=p^.left;
  626. { valid string ? }
  627. if not assigned(hp) or
  628. (hp^.left^.resulttype^.deftype<>stringdef) or
  629. (hp^.right=nil) or
  630. (hp^.left^.location.loc<>LOC_REFERENCE) then
  631. CGMessage(cg_e_illegal_expression);
  632. { !!!! check length of string }
  633. while assigned(hp^.right) do
  634. hp:=hp^.right;
  635. { check and convert the first param }
  636. if hp^.is_colon_para then
  637. CGMessage(cg_e_illegal_expression);
  638. isreal:=false;
  639. case hp^.resulttype^.deftype of
  640. orddef : begin
  641. case porddef(hp^.left^.resulttype)^.typ of
  642. u32bit,s32bit : ;
  643. u8bit,s8bit,
  644. u16bit,s16bit : hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  645. else
  646. CGMessage(type_e_integer_or_real_expr_expected);
  647. end;
  648. end;
  649. floatdef : begin
  650. isreal:=true;
  651. end;
  652. else
  653. CGMessage(type_e_integer_or_real_expr_expected);
  654. end;
  655. { some format options ? }
  656. hpp:=p^.left^.right;
  657. if assigned(hpp) and hpp^.is_colon_para then
  658. begin
  659. if (not is_integer(hpp^.resulttype)) then
  660. CGMessage(type_e_integer_expr_expected)
  661. else
  662. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  663. hpp:=hpp^.right;
  664. if assigned(hpp) and hpp^.is_colon_para then
  665. begin
  666. if isreal then
  667. begin
  668. if (not is_integer(hpp^.resulttype)) then
  669. CGMessage(type_e_integer_expr_expected)
  670. else
  671. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  672. end
  673. else
  674. CGMessage(parser_e_illegal_colon_qualifier);
  675. end;
  676. end;
  677. { for first local use }
  678. must_be_valid:=false;
  679. count_ref:=true;
  680. end
  681. else
  682. CGMessage(parser_e_illegal_parameter_list);
  683. { pass all parameters again for the typeconversions }
  684. if codegenerror then
  685. exit;
  686. must_be_valid:=true;
  687. firstcallparan(p^.left,nil);
  688. { calc registers }
  689. left_right_max(p);
  690. end;
  691. in_include_x_y,
  692. in_exclude_x_y:
  693. begin
  694. p^.resulttype:=voiddef;
  695. if assigned(p^.left) then
  696. begin
  697. firstcallparan(p^.left,nil);
  698. p^.registers32:=p^.left^.registers32;
  699. p^.registersfpu:=p^.left^.registersfpu;
  700. {$ifdef SUPPORT_MMX}
  701. p^.registersmmx:=p^.left^.registersmmx;
  702. {$endif SUPPORT_MMX}
  703. { first param must be var }
  704. if (p^.left^.left^.location.loc<>LOC_REFERENCE) and
  705. (p^.left^.left^.location.loc<>LOC_CREGISTER) then
  706. CGMessage(cg_e_illegal_expression);
  707. { check type }
  708. if (p^.left^.resulttype^.deftype=setdef) then
  709. begin
  710. { two paras ? }
  711. if assigned(p^.left^.right) then
  712. begin
  713. { insert a type conversion }
  714. { to the type of the set elements }
  715. p^.left^.right^.left:=gentypeconvnode(
  716. p^.left^.right^.left,
  717. psetdef(p^.left^.resulttype)^.setof);
  718. { check the type conversion }
  719. firstpass(p^.left^.right^.left);
  720. { only three parameters are allowed }
  721. if assigned(p^.left^.right^.right) then
  722. CGMessage(cg_e_illegal_expression);
  723. end;
  724. end
  725. else
  726. CGMessage(type_e_mismatch);
  727. end
  728. else
  729. CGMessage(type_e_mismatch);
  730. end;
  731. in_low_x,in_high_x:
  732. begin
  733. if p^.left^.treetype in [typen,loadn] then
  734. begin
  735. case p^.left^.resulttype^.deftype of
  736. orddef,enumdef:
  737. begin
  738. do_lowhigh(p^.left^.resulttype);
  739. firstpass(p);
  740. end;
  741. setdef:
  742. begin
  743. do_lowhigh(Psetdef(p^.left^.resulttype)^.setof);
  744. firstpass(p);
  745. end;
  746. arraydef:
  747. begin
  748. if is_open_array(p^.left^.resulttype) then
  749. begin
  750. if p^.inlinenumber=in_low_x then
  751. begin
  752. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef);
  753. disposetree(p);
  754. p:=hp;
  755. firstpass(p);
  756. end
  757. else
  758. begin
  759. p^.resulttype:=s32bitdef;
  760. p^.registers32:=max(1,
  761. p^.registers32);
  762. p^.location.loc:=LOC_REGISTER;
  763. end;
  764. end
  765. else
  766. begin
  767. if p^.inlinenumber=in_low_x then
  768. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef)
  769. else
  770. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.highrange,s32bitdef);
  771. disposetree(p);
  772. p:=hp;
  773. firstpass(p);
  774. end;
  775. end;
  776. stringdef:
  777. begin
  778. if p^.inlinenumber=in_low_x then
  779. hp:=genordinalconstnode(0,u8bitdef)
  780. else
  781. hp:=genordinalconstnode(Pstringdef(p^.left^.resulttype)^.len,u8bitdef);
  782. disposetree(p);
  783. p:=hp;
  784. firstpass(p);
  785. end;
  786. else
  787. CGMessage(type_e_mismatch);
  788. end;
  789. end
  790. else
  791. CGMessage(type_e_varid_or_typeid_expected);
  792. end;
  793. in_assert_x_y :
  794. begin
  795. p^.resulttype:=voiddef;
  796. if assigned(p^.left) then
  797. begin
  798. firstcallparan(p^.left,nil);
  799. p^.registers32:=p^.left^.registers32;
  800. p^.registersfpu:=p^.left^.registersfpu;
  801. {$ifdef SUPPORT_MMX}
  802. p^.registersmmx:=p^.left^.registersmmx;
  803. {$endif SUPPORT_MMX}
  804. { check type }
  805. if is_boolean(p^.left^.resulttype) then
  806. begin
  807. { must always be a string }
  808. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,cshortstringdef);
  809. firstpass(p^.left^.right^.left);
  810. end
  811. else
  812. CGMessage(type_e_mismatch);
  813. end
  814. else
  815. CGMessage(type_e_mismatch);
  816. end;
  817. else
  818. internalerror(8);
  819. end;
  820. end;
  821. must_be_valid:=store_valid;
  822. count_ref:=store_count_ref;
  823. end;
  824. end.
  825. {
  826. $Log$
  827. Revision 1.6 1998-11-05 12:03:05 peter
  828. * released useansistring
  829. * removed -Sv, its now available in fpc modes
  830. Revision 1.5 1998/10/20 11:16:47 pierre
  831. + length(c) where C is a char is allways 1
  832. Revision 1.4 1998/10/06 20:49:11 peter
  833. * m68k compiler compiles again
  834. Revision 1.3 1998/10/05 12:32:49 peter
  835. + assert() support
  836. Revision 1.2 1998/10/02 09:24:23 peter
  837. * more constant expression evaluators
  838. Revision 1.1 1998/09/23 20:42:24 peter
  839. * splitted pass_1
  840. }