tcinl.pas 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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,tgenm68k
  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. isreal:=(p^.left^.treetype=realconstn);
  102. vl:=p^.left^.value;
  103. vr:=p^.left^.value_real;
  104. case p^.inlinenumber of
  105. in_const_trunc : begin
  106. if isreal then
  107. hp:=genordinalconstnode(trunc(vr),s32bitdef)
  108. else
  109. hp:=genordinalconstnode(trunc(vl),s32bitdef);
  110. end;
  111. in_const_round : begin
  112. if isreal then
  113. hp:=genordinalconstnode(round(vr),s32bitdef)
  114. else
  115. hp:=genordinalconstnode(round(vl),s32bitdef);
  116. end;
  117. in_const_frac : begin
  118. if isreal then
  119. hp:=genrealconstnode(frac(vr))
  120. else
  121. hp:=genrealconstnode(frac(vl));
  122. end;
  123. in_const_int : begin
  124. if isreal then
  125. hp:=genrealconstnode(int(vr))
  126. else
  127. hp:=genrealconstnode(int(vl));
  128. end;
  129. in_const_abs : begin
  130. if isreal then
  131. hp:=genrealconstnode(abs(vr))
  132. else
  133. hp:=genordinalconstnode(abs(vl),p^.left^.resulttype);
  134. end;
  135. in_const_sqr : begin
  136. if isreal then
  137. hp:=genrealconstnode(sqr(vr))
  138. else
  139. hp:=genordinalconstnode(sqr(vl),p^.left^.resulttype);
  140. end;
  141. in_const_odd : begin
  142. if isreal then
  143. CGMessage(type_e_integer_expr_expected)
  144. else
  145. hp:=genordinalconstnode(byte(odd(vl)),booldef);
  146. end;
  147. in_const_swap_word : begin
  148. if isreal then
  149. CGMessage(type_e_integer_expr_expected)
  150. else
  151. hp:=genordinalconstnode((vl and $ff) shl 8+(vl shr 8),p^.left^.resulttype);
  152. end;
  153. in_const_swap_long : begin
  154. if isreal then
  155. CGMessage(type_e_mismatch)
  156. else
  157. hp:=genordinalconstnode((vl and $ffff) shl 16+(vl shr 16),p^.left^.resulttype);
  158. end;
  159. in_const_ptr : begin
  160. if isreal then
  161. CGMessage(type_e_mismatch)
  162. else
  163. hp:=genordinalconstnode(vl,voidpointerdef);
  164. end;
  165. else
  166. internalerror(88);
  167. end;
  168. disposetree(p);
  169. firstpass(hp);
  170. p:=hp;
  171. end
  172. else
  173. begin
  174. case p^.inlinenumber of
  175. in_lo_long,in_hi_long,
  176. in_lo_word,in_hi_word:
  177. begin
  178. if p^.registers32<1 then
  179. p^.registers32:=1;
  180. if p^.inlinenumber in [in_lo_word,in_hi_word] then
  181. p^.resulttype:=u8bitdef
  182. else
  183. p^.resulttype:=u16bitdef;
  184. p^.location.loc:=LOC_REGISTER;
  185. if not is_integer(p^.left^.resulttype) then
  186. CGMessage(type_e_mismatch)
  187. else
  188. begin
  189. if p^.left^.treetype=ordconstn then
  190. begin
  191. case p^.inlinenumber of
  192. in_lo_word : hp:=genordinalconstnode(p^.left^.value and $ff,p^.left^.resulttype);
  193. in_hi_word : hp:=genordinalconstnode(p^.left^.value shr 8,p^.left^.resulttype);
  194. in_lo_long : hp:=genordinalconstnode(p^.left^.value and $ffff,p^.left^.resulttype);
  195. in_hi_long : hp:=genordinalconstnode(p^.left^.value shr 16,p^.left^.resulttype);
  196. end;
  197. disposetree(p);
  198. firstpass(hp);
  199. p:=hp;
  200. end;
  201. end;
  202. end;
  203. in_sizeof_x:
  204. begin
  205. if p^.registers32<1 then
  206. p^.registers32:=1;
  207. p^.resulttype:=s32bitdef;
  208. p^.location.loc:=LOC_REGISTER;
  209. end;
  210. in_typeof_x:
  211. begin
  212. if p^.registers32<1 then
  213. p^.registers32:=1;
  214. p^.location.loc:=LOC_REGISTER;
  215. p^.resulttype:=voidpointerdef;
  216. end;
  217. in_ord_x:
  218. begin
  219. if (p^.left^.treetype=ordconstn) then
  220. begin
  221. hp:=genordinalconstnode(p^.left^.value,s32bitdef);
  222. disposetree(p);
  223. p:=hp;
  224. firstpass(p);
  225. end
  226. else
  227. begin
  228. if (p^.left^.resulttype^.deftype=orddef) then
  229. if (porddef(p^.left^.resulttype)^.typ in [uchar,bool8bit]) then
  230. begin
  231. if porddef(p^.left^.resulttype)^.typ=bool8bit then
  232. begin
  233. hp:=gentypeconvnode(p^.left,u8bitdef);
  234. putnode(p);
  235. p:=hp;
  236. p^.convtyp:=tc_bool_2_int;
  237. p^.explizit:=true;
  238. firstpass(p);
  239. end
  240. else
  241. begin
  242. hp:=gentypeconvnode(p^.left,u8bitdef);
  243. putnode(p);
  244. p:=hp;
  245. p^.explizit:=true;
  246. firstpass(p);
  247. end;
  248. end
  249. { can this happen ? }
  250. else if (porddef(p^.left^.resulttype)^.typ=uvoid) then
  251. CGMessage(type_e_mismatch)
  252. else
  253. { all other orddef need no transformation }
  254. begin
  255. hp:=p^.left;
  256. putnode(p);
  257. p:=hp;
  258. end
  259. else if (p^.left^.resulttype^.deftype=enumdef) then
  260. begin
  261. hp:=gentypeconvnode(p^.left,s32bitdef);
  262. putnode(p);
  263. p:=hp;
  264. p^.explizit:=true;
  265. firstpass(p);
  266. end
  267. else
  268. begin
  269. { can anything else be ord() ?}
  270. CGMessage(type_e_mismatch);
  271. end;
  272. end;
  273. end;
  274. in_chr_byte:
  275. begin
  276. hp:=gentypeconvnode(p^.left,cchardef);
  277. putnode(p);
  278. p:=hp;
  279. p^.explizit:=true;
  280. firstpass(p);
  281. end;
  282. in_length_string:
  283. begin
  284. {$ifdef UseAnsiString}
  285. if is_ansistring(p^.left^.resulttype) then
  286. p^.resulttype:=s32bitdef
  287. else
  288. {$endif UseAnsiString}
  289. p^.resulttype:=u8bitdef;
  290. { wer don't need string conversations here }
  291. if (p^.left^.treetype=typeconvn) and
  292. (p^.left^.left^.resulttype^.deftype=stringdef) then
  293. begin
  294. hp:=p^.left^.left;
  295. putnode(p^.left);
  296. p^.left:=hp;
  297. end;
  298. { evalutes length of constant strings direct }
  299. if (p^.left^.treetype=stringconstn) then
  300. begin
  301. {$ifdef UseAnsiString}
  302. hp:=genordinalconstnode(p^.left^.length,s32bitdef);
  303. {$else UseAnsiString}
  304. hp:=genordinalconstnode(length(p^.left^.value_str^),s32bitdef);
  305. {$endif UseAnsiString}
  306. disposetree(p);
  307. firstpass(hp);
  308. p:=hp;
  309. end;
  310. end;
  311. in_assigned_x:
  312. begin
  313. p^.resulttype:=booldef;
  314. p^.location.loc:=LOC_FLAGS;
  315. end;
  316. in_pred_x,
  317. in_succ_x:
  318. begin
  319. inc(p^.registers32);
  320. p^.resulttype:=p^.left^.resulttype;
  321. p^.location.loc:=LOC_REGISTER;
  322. if not is_ordinal(p^.resulttype) then
  323. CGMessage(type_e_ordinal_expr_expected)
  324. else
  325. begin
  326. if (p^.resulttype^.deftype=enumdef) and
  327. (penumdef(p^.resulttype)^.has_jumps) then
  328. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible)
  329. else
  330. if p^.left^.treetype=ordconstn then
  331. begin
  332. if p^.inlinenumber=in_succ_x then
  333. hp:=genordinalconstnode(p^.left^.value+1,p^.left^.resulttype)
  334. else
  335. hp:=genordinalconstnode(p^.left^.value-1,p^.left^.resulttype);
  336. disposetree(p);
  337. firstpass(hp);
  338. p:=hp;
  339. end;
  340. end;
  341. end;
  342. in_inc_x,
  343. in_dec_x:
  344. begin
  345. p^.resulttype:=voiddef;
  346. if assigned(p^.left) then
  347. begin
  348. firstcallparan(p^.left,nil);
  349. if codegenerror then
  350. exit;
  351. { first param must be var }
  352. if is_constnode(p^.left^.left) then
  353. CGMessage(type_e_variable_id_expected);
  354. { check type }
  355. if (p^.left^.resulttype^.deftype in [enumdef,pointerdef]) or
  356. is_ordinal(p^.left^.resulttype) then
  357. begin
  358. { two paras ? }
  359. if assigned(p^.left^.right) then
  360. begin
  361. { insert a type conversion }
  362. { the second param is always longint }
  363. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,s32bitdef);
  364. { check the type conversion }
  365. firstpass(p^.left^.right^.left);
  366. { need we an additional register ? }
  367. if not(is_constintnode(p^.left^.right^.left)) and
  368. (p^.left^.right^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  369. (p^.left^.right^.left^.registers32<1) then
  370. inc(p^.registers32);
  371. if assigned(p^.left^.right^.right) then
  372. CGMessage(cg_e_illegal_expression);
  373. end;
  374. end
  375. else
  376. CGMessage(type_e_ordinal_expr_expected);
  377. end
  378. else
  379. CGMessage(type_e_mismatch);
  380. end;
  381. in_read_x,
  382. in_readln_x,
  383. in_write_x,
  384. in_writeln_x :
  385. begin
  386. { needs a call }
  387. procinfo.flags:=procinfo.flags or pi_do_call;
  388. p^.resulttype:=voiddef;
  389. { we must know if it is a typed file or not }
  390. { but we must first do the firstpass for it }
  391. file_is_typed:=false;
  392. if assigned(p^.left) then
  393. begin
  394. firstcallparan(p^.left,nil);
  395. { now we can check }
  396. hp:=p^.left;
  397. while assigned(hp^.right) do
  398. hp:=hp^.right;
  399. { if resulttype is not assigned, then automatically }
  400. { file is not typed. }
  401. if assigned(hp) and assigned(hp^.resulttype) then
  402. Begin
  403. if (hp^.resulttype^.deftype=filedef) and
  404. (pfiledef(hp^.resulttype)^.filetype=ft_typed) then
  405. begin
  406. file_is_typed:=true;
  407. { test the type }
  408. hpp:=p^.left;
  409. while (hpp<>hp) do
  410. begin
  411. if (hpp^.left^.treetype=typen) then
  412. CGMessage(type_e_cant_read_write_type);
  413. if not is_equal(hpp^.resulttype,pfiledef(hp^.resulttype)^.typed_as) then
  414. CGMessage(type_e_mismatch);
  415. hpp:=hpp^.right;
  416. end;
  417. end;
  418. end; { endif assigned(hp) }
  419. { insert type conversions for write(ln) }
  420. if (not file_is_typed) then
  421. begin
  422. dowrite:=(p^.inlinenumber in [in_write_x,in_writeln_x]);
  423. hp:=p^.left;
  424. while assigned(hp) do
  425. begin
  426. if (hp^.left^.treetype=typen) then
  427. CGMessage(type_e_cant_read_write_type);
  428. if assigned(hp^.left^.resulttype) then
  429. begin
  430. isreal:=false;
  431. case hp^.left^.resulttype^.deftype of
  432. filedef : begin
  433. { only allowed as first parameter }
  434. if assigned(hp^.right) then
  435. CGMessage(type_e_cant_read_write_type);
  436. end;
  437. stringdef : ;
  438. pointerdef : begin
  439. if not is_equal(ppointerdef(hp^.left^.resulttype)^.definition,cchardef) then
  440. CGMessage(type_e_cant_read_write_type);
  441. end;
  442. floatdef : begin
  443. isreal:=true;
  444. end;
  445. orddef : begin
  446. case porddef(hp^.left^.resulttype)^.typ of
  447. uchar,
  448. u32bit,s32bit : ;
  449. u8bit,s8bit,
  450. u16bit,s16bit : if dowrite then
  451. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  452. bool8bit,
  453. bool16bit,bool32bit : if dowrite then
  454. hp^.left:=gentypeconvnode(hp^.left,booldef)
  455. else
  456. CGMessage(type_e_cant_read_write_type);
  457. else
  458. CGMessage(type_e_cant_read_write_type);
  459. end;
  460. end;
  461. arraydef : begin
  462. if not((parraydef(hp^.left^.resulttype)^.lowrange=0) and
  463. is_equal(parraydef(hp^.left^.resulttype)^.definition,cchardef)) then
  464. begin
  465. { but we convert only if the first index<>0,
  466. because in this case we have a ASCIIZ string }
  467. if dowrite and
  468. (parraydef(hp^.left^.resulttype)^.lowrange<>0) and
  469. (parraydef(hp^.left^.resulttype)^.definition^.deftype=orddef) and
  470. (porddef(parraydef(hp^.left^.resulttype)^.definition)^.typ=uchar) then
  471. hp^.left:=gentypeconvnode(hp^.left,cstringdef)
  472. else
  473. CGMessage(type_e_cant_read_write_type);
  474. end;
  475. end;
  476. else
  477. CGMessage(type_e_cant_read_write_type);
  478. end;
  479. { some format options ? }
  480. (* commented
  481. because supposes reverse order of parameters
  482. PM
  483. hpp:=hp^.right;
  484. if assigned(hpp) and hpp^.is_colon_para then
  485. begin
  486. if (not is_integer(hpp^.resulttype)) then
  487. CGMessage(type_e_integer_expr_expected)
  488. else
  489. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  490. hpp:=hpp^.right;
  491. if assigned(hpp) and hpp^.is_colon_para then
  492. begin
  493. if isreal then
  494. begin
  495. if (not is_integer(hpp^.resulttype)) then
  496. CGMessage(type_e_integer_expr_expected)
  497. else
  498. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  499. end
  500. else
  501. CGMessage(parser_e_illegal_colon_qualifier);
  502. end;
  503. end; *)
  504. end;
  505. hp:=hp^.right;
  506. end;
  507. end;
  508. { pass all parameters again for the typeconversions }
  509. if codegenerror then
  510. exit;
  511. must_be_valid:=true;
  512. firstcallparan(p^.left,nil);
  513. { calc registers }
  514. left_right_max(p);
  515. end;
  516. end;
  517. in_settextbuf_file_x :
  518. begin
  519. { warning here p^.left is the callparannode
  520. not the argument directly }
  521. { p^.left^.left is text var }
  522. { p^.left^.right^.left is the buffer var }
  523. { firstcallparan(p^.left,nil);
  524. already done in firstcalln }
  525. { now we know the type of buffer }
  526. getsymonlyin(systemunit,'SETTEXTBUF');
  527. hp:=gencallnode(pprocsym(srsym),systemunit);
  528. hp^.left:=gencallparanode(
  529. genordinalconstnode(p^.left^.left^.resulttype^.size,s32bitdef),p^.left);
  530. putnode(p);
  531. p:=hp;
  532. firstpass(p);
  533. end;
  534. { the firstpass of the arg has been done in firstcalln ? }
  535. in_reset_typedfile,in_rewrite_typedfile :
  536. begin
  537. procinfo.flags:=procinfo.flags or pi_do_call;
  538. { to be sure the right definition is loaded }
  539. p^.left^.resulttype:=nil;
  540. firstload(p^.left);
  541. p^.resulttype:=voiddef;
  542. end;
  543. in_str_x_string :
  544. begin
  545. procinfo.flags:=procinfo.flags or pi_do_call;
  546. p^.resulttype:=voiddef;
  547. if assigned(p^.left) then
  548. begin
  549. hp:=p^.left^.right;
  550. { first pass just the string for first local use }
  551. must_be_valid:=false;
  552. count_ref:=true;
  553. p^.left^.right:=nil;
  554. firstcallparan(p^.left,nil);
  555. must_be_valid:=true;
  556. p^.left^.right:=hp;
  557. firstcallparan(p^.left^.right,nil);
  558. hp:=p^.left;
  559. { valid string ? }
  560. if not assigned(hp) or
  561. (hp^.left^.resulttype^.deftype<>stringdef) or
  562. (hp^.right=nil) or
  563. (hp^.left^.location.loc<>LOC_REFERENCE) then
  564. CGMessage(cg_e_illegal_expression);
  565. { !!!! check length of string }
  566. while assigned(hp^.right) do
  567. hp:=hp^.right;
  568. { check and convert the first param }
  569. if hp^.is_colon_para then
  570. CGMessage(cg_e_illegal_expression);
  571. isreal:=false;
  572. case hp^.resulttype^.deftype of
  573. orddef : begin
  574. case porddef(hp^.left^.resulttype)^.typ of
  575. u32bit,s32bit : ;
  576. u8bit,s8bit,
  577. u16bit,s16bit : hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  578. else
  579. CGMessage(type_e_integer_or_real_expr_expected);
  580. end;
  581. end;
  582. floatdef : begin
  583. isreal:=true;
  584. end;
  585. else
  586. CGMessage(type_e_integer_or_real_expr_expected);
  587. end;
  588. { some format options ? }
  589. hpp:=p^.left^.right;
  590. if assigned(hpp) and hpp^.is_colon_para then
  591. begin
  592. if (not is_integer(hpp^.resulttype)) then
  593. CGMessage(type_e_integer_expr_expected)
  594. else
  595. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  596. hpp:=hpp^.right;
  597. if assigned(hpp) and hpp^.is_colon_para then
  598. begin
  599. if isreal then
  600. begin
  601. if (not is_integer(hpp^.resulttype)) then
  602. CGMessage(type_e_integer_expr_expected)
  603. else
  604. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  605. end
  606. else
  607. CGMessage(parser_e_illegal_colon_qualifier);
  608. end;
  609. end;
  610. { for first local use }
  611. must_be_valid:=false;
  612. count_ref:=true;
  613. end
  614. else
  615. CGMessage(parser_e_illegal_parameter_list);
  616. { pass all parameters again for the typeconversions }
  617. if codegenerror then
  618. exit;
  619. must_be_valid:=true;
  620. firstcallparan(p^.left,nil);
  621. { calc registers }
  622. left_right_max(p);
  623. end;
  624. in_include_x_y,
  625. in_exclude_x_y:
  626. begin
  627. p^.resulttype:=voiddef;
  628. if assigned(p^.left) then
  629. begin
  630. firstcallparan(p^.left,nil);
  631. p^.registers32:=p^.left^.registers32;
  632. p^.registersfpu:=p^.left^.registersfpu;
  633. {$ifdef SUPPORT_MMX}
  634. p^.registersmmx:=p^.left^.registersmmx;
  635. {$endif SUPPORT_MMX}
  636. { first param must be var }
  637. if (p^.left^.left^.location.loc<>LOC_REFERENCE) and
  638. (p^.left^.left^.location.loc<>LOC_CREGISTER) then
  639. CGMessage(cg_e_illegal_expression);
  640. { check type }
  641. if (p^.left^.resulttype^.deftype=setdef) then
  642. begin
  643. { two paras ? }
  644. if assigned(p^.left^.right) then
  645. begin
  646. { insert a type conversion }
  647. { to the type of the set elements }
  648. p^.left^.right^.left:=gentypeconvnode(
  649. p^.left^.right^.left,
  650. psetdef(p^.left^.resulttype)^.setof);
  651. { check the type conversion }
  652. firstpass(p^.left^.right^.left);
  653. { only three parameters are allowed }
  654. if assigned(p^.left^.right^.right) then
  655. CGMessage(cg_e_illegal_expression);
  656. end;
  657. end
  658. else
  659. CGMessage(type_e_mismatch);
  660. end
  661. else
  662. CGMessage(type_e_mismatch);
  663. end;
  664. in_low_x,in_high_x:
  665. begin
  666. if p^.left^.treetype in [typen,loadn] then
  667. begin
  668. case p^.left^.resulttype^.deftype of
  669. orddef,enumdef:
  670. begin
  671. do_lowhigh(p^.left^.resulttype);
  672. firstpass(p);
  673. end;
  674. setdef:
  675. begin
  676. do_lowhigh(Psetdef(p^.left^.resulttype)^.setof);
  677. firstpass(p);
  678. end;
  679. arraydef:
  680. begin
  681. if is_open_array(p^.left^.resulttype) then
  682. begin
  683. if p^.inlinenumber=in_low_x then
  684. begin
  685. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef);
  686. disposetree(p);
  687. p:=hp;
  688. firstpass(p);
  689. end
  690. else
  691. begin
  692. p^.resulttype:=s32bitdef;
  693. p^.registers32:=max(1,
  694. p^.registers32);
  695. p^.location.loc:=LOC_REGISTER;
  696. end;
  697. end
  698. else
  699. begin
  700. if p^.inlinenumber=in_low_x then
  701. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef)
  702. else
  703. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.highrange,s32bitdef);
  704. disposetree(p);
  705. p:=hp;
  706. firstpass(p);
  707. end;
  708. end;
  709. stringdef:
  710. begin
  711. if p^.inlinenumber=in_low_x then
  712. hp:=genordinalconstnode(0,u8bitdef)
  713. else
  714. hp:=genordinalconstnode(Pstringdef(p^.left^.resulttype)^.len,u8bitdef);
  715. disposetree(p);
  716. p:=hp;
  717. firstpass(p);
  718. end;
  719. else
  720. CGMessage(type_e_mismatch);
  721. end;
  722. end
  723. else
  724. CGMessage(type_e_varid_or_typeid_expected);
  725. end
  726. else internalerror(8);
  727. end;
  728. end;
  729. must_be_valid:=store_valid;
  730. count_ref:=store_count_ref;
  731. end;
  732. end.
  733. {
  734. $Log$
  735. Revision 1.1 1998-09-23 20:42:24 peter
  736. * splitted pass_1
  737. }