tcinl.pas 39 KB

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