tcinl.pas 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864
  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. {$ifdef UseAnsiString}
  346. if is_ansistring(p^.left^.resulttype) then
  347. p^.resulttype:=s32bitdef
  348. else
  349. {$endif UseAnsiString}
  350. p^.resulttype:=u8bitdef;
  351. { wer don't need string conversations here }
  352. if (p^.left^.treetype=typeconvn) and
  353. (p^.left^.left^.resulttype^.deftype=stringdef) then
  354. begin
  355. hp:=p^.left^.left;
  356. putnode(p^.left);
  357. p^.left:=hp;
  358. end;
  359. { evalutes length of constant strings direct }
  360. if (p^.left^.treetype=stringconstn) then
  361. begin
  362. {$ifdef UseAnsiString}
  363. hp:=genordinalconstnode(p^.left^.length,s32bitdef);
  364. {$else UseAnsiString}
  365. hp:=genordinalconstnode(length(p^.left^.value_str^),s32bitdef);
  366. {$endif UseAnsiString}
  367. disposetree(p);
  368. firstpass(hp);
  369. p:=hp;
  370. end;
  371. end;
  372. in_assigned_x:
  373. begin
  374. p^.resulttype:=booldef;
  375. p^.location.loc:=LOC_FLAGS;
  376. end;
  377. in_pred_x,
  378. in_succ_x:
  379. begin
  380. inc(p^.registers32);
  381. p^.resulttype:=p^.left^.resulttype;
  382. p^.location.loc:=LOC_REGISTER;
  383. if not is_ordinal(p^.resulttype) then
  384. CGMessage(type_e_ordinal_expr_expected)
  385. else
  386. begin
  387. if (p^.resulttype^.deftype=enumdef) and
  388. (penumdef(p^.resulttype)^.has_jumps) then
  389. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible)
  390. else
  391. if p^.left^.treetype=ordconstn then
  392. begin
  393. if p^.inlinenumber=in_succ_x then
  394. hp:=genordinalconstnode(p^.left^.value+1,p^.left^.resulttype)
  395. else
  396. hp:=genordinalconstnode(p^.left^.value-1,p^.left^.resulttype);
  397. disposetree(p);
  398. firstpass(hp);
  399. p:=hp;
  400. end;
  401. end;
  402. end;
  403. in_inc_x,
  404. in_dec_x:
  405. begin
  406. p^.resulttype:=voiddef;
  407. if assigned(p^.left) then
  408. begin
  409. firstcallparan(p^.left,nil);
  410. if codegenerror then
  411. exit;
  412. { first param must be var }
  413. if is_constnode(p^.left^.left) then
  414. CGMessage(type_e_variable_id_expected);
  415. { check type }
  416. if (p^.left^.resulttype^.deftype in [enumdef,pointerdef]) or
  417. is_ordinal(p^.left^.resulttype) then
  418. begin
  419. { two paras ? }
  420. if assigned(p^.left^.right) then
  421. begin
  422. { insert a type conversion }
  423. { the second param is always longint }
  424. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,s32bitdef);
  425. { check the type conversion }
  426. firstpass(p^.left^.right^.left);
  427. { need we an additional register ? }
  428. if not(is_constintnode(p^.left^.right^.left)) and
  429. (p^.left^.right^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  430. (p^.left^.right^.left^.registers32<1) then
  431. inc(p^.registers32);
  432. if assigned(p^.left^.right^.right) then
  433. CGMessage(cg_e_illegal_expression);
  434. end;
  435. end
  436. else
  437. CGMessage(type_e_ordinal_expr_expected);
  438. end
  439. else
  440. CGMessage(type_e_mismatch);
  441. end;
  442. in_read_x,
  443. in_readln_x,
  444. in_write_x,
  445. in_writeln_x :
  446. begin
  447. { needs a call }
  448. procinfo.flags:=procinfo.flags or pi_do_call;
  449. p^.resulttype:=voiddef;
  450. { we must know if it is a typed file or not }
  451. { but we must first do the firstpass for it }
  452. file_is_typed:=false;
  453. if assigned(p^.left) then
  454. begin
  455. firstcallparan(p^.left,nil);
  456. { now we can check }
  457. hp:=p^.left;
  458. while assigned(hp^.right) do
  459. hp:=hp^.right;
  460. { if resulttype is not assigned, then automatically }
  461. { file is not typed. }
  462. if assigned(hp) and assigned(hp^.resulttype) then
  463. Begin
  464. if (hp^.resulttype^.deftype=filedef) and
  465. (pfiledef(hp^.resulttype)^.filetype=ft_typed) then
  466. begin
  467. file_is_typed:=true;
  468. { test the type }
  469. hpp:=p^.left;
  470. while (hpp<>hp) do
  471. begin
  472. if (hpp^.left^.treetype=typen) then
  473. CGMessage(type_e_cant_read_write_type);
  474. if not is_equal(hpp^.resulttype,pfiledef(hp^.resulttype)^.typed_as) then
  475. CGMessage(type_e_mismatch);
  476. hpp:=hpp^.right;
  477. end;
  478. end;
  479. end; { endif assigned(hp) }
  480. { insert type conversions for write(ln) }
  481. if (not file_is_typed) then
  482. begin
  483. dowrite:=(p^.inlinenumber in [in_write_x,in_writeln_x]);
  484. hp:=p^.left;
  485. while assigned(hp) do
  486. begin
  487. if (hp^.left^.treetype=typen) then
  488. CGMessage(type_e_cant_read_write_type);
  489. if assigned(hp^.left^.resulttype) then
  490. begin
  491. isreal:=false;
  492. case hp^.left^.resulttype^.deftype of
  493. filedef : begin
  494. { only allowed as first parameter }
  495. if assigned(hp^.right) then
  496. CGMessage(type_e_cant_read_write_type);
  497. end;
  498. stringdef : ;
  499. pointerdef : begin
  500. if not is_equal(ppointerdef(hp^.left^.resulttype)^.definition,cchardef) then
  501. CGMessage(type_e_cant_read_write_type);
  502. end;
  503. floatdef : begin
  504. isreal:=true;
  505. end;
  506. orddef : begin
  507. case porddef(hp^.left^.resulttype)^.typ of
  508. uchar,
  509. u32bit,s32bit : ;
  510. u8bit,s8bit,
  511. u16bit,s16bit : if dowrite then
  512. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  513. bool8bit,
  514. bool16bit,bool32bit : if dowrite then
  515. hp^.left:=gentypeconvnode(hp^.left,booldef)
  516. else
  517. CGMessage(type_e_cant_read_write_type);
  518. else
  519. CGMessage(type_e_cant_read_write_type);
  520. end;
  521. end;
  522. arraydef : begin
  523. if not((parraydef(hp^.left^.resulttype)^.lowrange=0) and
  524. is_equal(parraydef(hp^.left^.resulttype)^.definition,cchardef)) then
  525. begin
  526. { but we convert only if the first index<>0,
  527. because in this case we have a ASCIIZ string }
  528. if dowrite and
  529. (parraydef(hp^.left^.resulttype)^.lowrange<>0) and
  530. (parraydef(hp^.left^.resulttype)^.definition^.deftype=orddef) and
  531. (porddef(parraydef(hp^.left^.resulttype)^.definition)^.typ=uchar) then
  532. hp^.left:=gentypeconvnode(hp^.left,cstringdef)
  533. else
  534. CGMessage(type_e_cant_read_write_type);
  535. end;
  536. end;
  537. else
  538. CGMessage(type_e_cant_read_write_type);
  539. end;
  540. { some format options ? }
  541. (* commented
  542. because supposes reverse order of parameters
  543. PM
  544. hpp:=hp^.right;
  545. if assigned(hpp) and hpp^.is_colon_para then
  546. begin
  547. if (not is_integer(hpp^.resulttype)) then
  548. CGMessage(type_e_integer_expr_expected)
  549. else
  550. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  551. hpp:=hpp^.right;
  552. if assigned(hpp) and hpp^.is_colon_para then
  553. begin
  554. if isreal then
  555. begin
  556. if (not is_integer(hpp^.resulttype)) then
  557. CGMessage(type_e_integer_expr_expected)
  558. else
  559. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  560. end
  561. else
  562. CGMessage(parser_e_illegal_colon_qualifier);
  563. end;
  564. end; *)
  565. end;
  566. hp:=hp^.right;
  567. end;
  568. end;
  569. { pass all parameters again for the typeconversions }
  570. if codegenerror then
  571. exit;
  572. must_be_valid:=true;
  573. firstcallparan(p^.left,nil);
  574. { calc registers }
  575. left_right_max(p);
  576. end;
  577. end;
  578. in_settextbuf_file_x :
  579. begin
  580. { warning here p^.left is the callparannode
  581. not the argument directly }
  582. { p^.left^.left is text var }
  583. { p^.left^.right^.left is the buffer var }
  584. { firstcallparan(p^.left,nil);
  585. already done in firstcalln }
  586. { now we know the type of buffer }
  587. getsymonlyin(systemunit,'SETTEXTBUF');
  588. hp:=gencallnode(pprocsym(srsym),systemunit);
  589. hp^.left:=gencallparanode(
  590. genordinalconstnode(p^.left^.left^.resulttype^.size,s32bitdef),p^.left);
  591. putnode(p);
  592. p:=hp;
  593. firstpass(p);
  594. end;
  595. { the firstpass of the arg has been done in firstcalln ? }
  596. in_reset_typedfile,in_rewrite_typedfile :
  597. begin
  598. procinfo.flags:=procinfo.flags or pi_do_call;
  599. { to be sure the right definition is loaded }
  600. p^.left^.resulttype:=nil;
  601. firstload(p^.left);
  602. p^.resulttype:=voiddef;
  603. end;
  604. in_str_x_string :
  605. begin
  606. procinfo.flags:=procinfo.flags or pi_do_call;
  607. p^.resulttype:=voiddef;
  608. if assigned(p^.left) then
  609. begin
  610. hp:=p^.left^.right;
  611. { first pass just the string for first local use }
  612. must_be_valid:=false;
  613. count_ref:=true;
  614. p^.left^.right:=nil;
  615. firstcallparan(p^.left,nil);
  616. must_be_valid:=true;
  617. p^.left^.right:=hp;
  618. firstcallparan(p^.left^.right,nil);
  619. hp:=p^.left;
  620. { valid string ? }
  621. if not assigned(hp) or
  622. (hp^.left^.resulttype^.deftype<>stringdef) or
  623. (hp^.right=nil) or
  624. (hp^.left^.location.loc<>LOC_REFERENCE) then
  625. CGMessage(cg_e_illegal_expression);
  626. { !!!! check length of string }
  627. while assigned(hp^.right) do
  628. hp:=hp^.right;
  629. { check and convert the first param }
  630. if hp^.is_colon_para then
  631. CGMessage(cg_e_illegal_expression);
  632. isreal:=false;
  633. case hp^.resulttype^.deftype of
  634. orddef : begin
  635. case porddef(hp^.left^.resulttype)^.typ of
  636. u32bit,s32bit : ;
  637. u8bit,s8bit,
  638. u16bit,s16bit : hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  639. else
  640. CGMessage(type_e_integer_or_real_expr_expected);
  641. end;
  642. end;
  643. floatdef : begin
  644. isreal:=true;
  645. end;
  646. else
  647. CGMessage(type_e_integer_or_real_expr_expected);
  648. end;
  649. { some format options ? }
  650. hpp:=p^.left^.right;
  651. if assigned(hpp) and hpp^.is_colon_para then
  652. begin
  653. if (not is_integer(hpp^.resulttype)) then
  654. CGMessage(type_e_integer_expr_expected)
  655. else
  656. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  657. hpp:=hpp^.right;
  658. if assigned(hpp) and hpp^.is_colon_para then
  659. begin
  660. if isreal then
  661. begin
  662. if (not is_integer(hpp^.resulttype)) then
  663. CGMessage(type_e_integer_expr_expected)
  664. else
  665. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  666. end
  667. else
  668. CGMessage(parser_e_illegal_colon_qualifier);
  669. end;
  670. end;
  671. { for first local use }
  672. must_be_valid:=false;
  673. count_ref:=true;
  674. end
  675. else
  676. CGMessage(parser_e_illegal_parameter_list);
  677. { pass all parameters again for the typeconversions }
  678. if codegenerror then
  679. exit;
  680. must_be_valid:=true;
  681. firstcallparan(p^.left,nil);
  682. { calc registers }
  683. left_right_max(p);
  684. end;
  685. in_include_x_y,
  686. in_exclude_x_y:
  687. begin
  688. p^.resulttype:=voiddef;
  689. if assigned(p^.left) then
  690. begin
  691. firstcallparan(p^.left,nil);
  692. p^.registers32:=p^.left^.registers32;
  693. p^.registersfpu:=p^.left^.registersfpu;
  694. {$ifdef SUPPORT_MMX}
  695. p^.registersmmx:=p^.left^.registersmmx;
  696. {$endif SUPPORT_MMX}
  697. { first param must be var }
  698. if (p^.left^.left^.location.loc<>LOC_REFERENCE) and
  699. (p^.left^.left^.location.loc<>LOC_CREGISTER) then
  700. CGMessage(cg_e_illegal_expression);
  701. { check type }
  702. if (p^.left^.resulttype^.deftype=setdef) then
  703. begin
  704. { two paras ? }
  705. if assigned(p^.left^.right) then
  706. begin
  707. { insert a type conversion }
  708. { to the type of the set elements }
  709. p^.left^.right^.left:=gentypeconvnode(
  710. p^.left^.right^.left,
  711. psetdef(p^.left^.resulttype)^.setof);
  712. { check the type conversion }
  713. firstpass(p^.left^.right^.left);
  714. { only three parameters are allowed }
  715. if assigned(p^.left^.right^.right) then
  716. CGMessage(cg_e_illegal_expression);
  717. end;
  718. end
  719. else
  720. CGMessage(type_e_mismatch);
  721. end
  722. else
  723. CGMessage(type_e_mismatch);
  724. end;
  725. in_low_x,in_high_x:
  726. begin
  727. if p^.left^.treetype in [typen,loadn] then
  728. begin
  729. case p^.left^.resulttype^.deftype of
  730. orddef,enumdef:
  731. begin
  732. do_lowhigh(p^.left^.resulttype);
  733. firstpass(p);
  734. end;
  735. setdef:
  736. begin
  737. do_lowhigh(Psetdef(p^.left^.resulttype)^.setof);
  738. firstpass(p);
  739. end;
  740. arraydef:
  741. begin
  742. if is_open_array(p^.left^.resulttype) then
  743. begin
  744. if p^.inlinenumber=in_low_x then
  745. begin
  746. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef);
  747. disposetree(p);
  748. p:=hp;
  749. firstpass(p);
  750. end
  751. else
  752. begin
  753. p^.resulttype:=s32bitdef;
  754. p^.registers32:=max(1,
  755. p^.registers32);
  756. p^.location.loc:=LOC_REGISTER;
  757. end;
  758. end
  759. else
  760. begin
  761. if p^.inlinenumber=in_low_x then
  762. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef)
  763. else
  764. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.highrange,s32bitdef);
  765. disposetree(p);
  766. p:=hp;
  767. firstpass(p);
  768. end;
  769. end;
  770. stringdef:
  771. begin
  772. if p^.inlinenumber=in_low_x then
  773. hp:=genordinalconstnode(0,u8bitdef)
  774. else
  775. hp:=genordinalconstnode(Pstringdef(p^.left^.resulttype)^.len,u8bitdef);
  776. disposetree(p);
  777. p:=hp;
  778. firstpass(p);
  779. end;
  780. else
  781. CGMessage(type_e_mismatch);
  782. end;
  783. end
  784. else
  785. CGMessage(type_e_varid_or_typeid_expected);
  786. end;
  787. in_assert_x_y :
  788. begin
  789. p^.resulttype:=voiddef;
  790. if assigned(p^.left) then
  791. begin
  792. firstcallparan(p^.left,nil);
  793. p^.registers32:=p^.left^.registers32;
  794. p^.registersfpu:=p^.left^.registersfpu;
  795. {$ifdef SUPPORT_MMX}
  796. p^.registersmmx:=p^.left^.registersmmx;
  797. {$endif SUPPORT_MMX}
  798. { check type }
  799. if is_boolean(p^.left^.resulttype) then
  800. begin
  801. { must always be a string }
  802. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,cstringdef);
  803. firstpass(p^.left^.right^.left);
  804. end
  805. else
  806. CGMessage(type_e_mismatch);
  807. end
  808. else
  809. CGMessage(type_e_mismatch);
  810. end;
  811. else
  812. internalerror(8);
  813. end;
  814. end;
  815. must_be_valid:=store_valid;
  816. count_ref:=store_count_ref;
  817. end;
  818. end.
  819. {
  820. $Log$
  821. Revision 1.4 1998-10-06 20:49:11 peter
  822. * m68k compiler compiles again
  823. Revision 1.3 1998/10/05 12:32:49 peter
  824. + assert() support
  825. Revision 1.2 1998/10/02 09:24:23 peter
  826. * more constant expression evaluators
  827. Revision 1.1 1998/09/23 20:42:24 peter
  828. * splitted pass_1
  829. }