tcinl.pas 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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. globtype,
  27. symtable,aasm,types,
  28. hcodegen,htypechk,pass_1,
  29. tccal,tcld
  30. {$ifdef i386}
  31. {$ifdef ag386bin}
  32. ,i386base
  33. {$else}
  34. ,i386
  35. {$endif}
  36. ,tgeni386
  37. {$endif}
  38. {$ifdef m68k}
  39. ,m68k,tgen68k
  40. {$endif}
  41. ;
  42. {*****************************************************************************
  43. FirstInLine
  44. *****************************************************************************}
  45. procedure firstinline(var p : ptree);
  46. var
  47. vl,vl2 : longint;
  48. vr : bestreal;
  49. hp,hpp : ptree;
  50. {$ifndef NOCOLONCHECK}
  51. frac_para,length_para : ptree;
  52. {$endif ndef NOCOLONCHECK}
  53. store_count_ref,
  54. isreal,
  55. dowrite,
  56. store_valid,
  57. file_is_typed : boolean;
  58. procedure do_lowhigh(adef : pdef);
  59. var
  60. v : longint;
  61. enum : penumsym;
  62. begin
  63. case Adef^.deftype of
  64. orddef:
  65. begin
  66. if p^.inlinenumber=in_low_x then
  67. v:=porddef(Adef)^.low
  68. else
  69. v:=porddef(Adef)^.high;
  70. hp:=genordinalconstnode(v,adef);
  71. firstpass(hp);
  72. disposetree(p);
  73. p:=hp;
  74. end;
  75. enumdef:
  76. begin
  77. enum:=Penumdef(Adef)^.first;
  78. if p^.inlinenumber=in_high_x then
  79. while enum^.next<>nil do
  80. enum:=enum^.next;
  81. hp:=genenumnode(enum);
  82. disposetree(p);
  83. p:=hp;
  84. end
  85. end;
  86. end;
  87. begin
  88. store_valid:=must_be_valid;
  89. store_count_ref:=count_ref;
  90. count_ref:=false;
  91. if not (p^.inlinenumber in [in_read_x,in_readln_x,in_sizeof_x,
  92. in_typeof_x,in_ord_x,in_str_x_string,
  93. in_reset_typedfile,in_rewrite_typedfile]) then
  94. must_be_valid:=true
  95. else
  96. must_be_valid:=false;
  97. { if we handle writeln; p^.left contains no valid address }
  98. if assigned(p^.left) then
  99. begin
  100. if p^.left^.treetype=callparan then
  101. firstcallparan(p^.left,nil)
  102. else
  103. firstpass(p^.left);
  104. left_right_max(p);
  105. set_location(p^.location,p^.left^.location);
  106. end;
  107. { handle intern constant functions in separate case }
  108. if p^.inlineconst then
  109. begin
  110. { no parameters? }
  111. if not assigned(p^.left) then
  112. begin
  113. case p^.inlinenumber of
  114. in_const_pi : begin
  115. hp:=genrealconstnode(pi);
  116. end;
  117. else
  118. internalerror(89);
  119. end;
  120. end
  121. else
  122. { process constant expression with parameter }
  123. begin
  124. vl:=0;
  125. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  126. vr:=0;
  127. isreal:=false;
  128. case p^.left^.treetype of
  129. realconstn :
  130. begin
  131. isreal:=true;
  132. vr:=p^.left^.value_real;
  133. end;
  134. ordconstn :
  135. vl:=p^.left^.value;
  136. callparan :
  137. begin
  138. { both exists, else it was not generated }
  139. vl:=p^.left^.left^.value;
  140. vl2:=p^.left^.right^.left^.value;
  141. end;
  142. else
  143. CGMessage(cg_e_illegal_expression);
  144. end;
  145. case p^.inlinenumber of
  146. in_const_trunc : begin
  147. if isreal then
  148. begin
  149. if (vr>=2147483648.0) or (vr<=-2147483649.0) then
  150. begin
  151. CGMessage(parser_e_range_check_error);
  152. hp:=genordinalconstnode(1,s32bitdef)
  153. end
  154. else
  155. hp:=genordinalconstnode(trunc(vr),s32bitdef)
  156. end
  157. else
  158. hp:=genordinalconstnode(trunc(vl),s32bitdef);
  159. end;
  160. in_const_round : begin
  161. if isreal then
  162. begin
  163. if (vr>=2147483647.5) or (vr<=-2147483648.5) then
  164. begin
  165. CGMessage(parser_e_range_check_error);
  166. hp:=genordinalconstnode(1,s32bitdef)
  167. end
  168. else
  169. hp:=genordinalconstnode(round(vr),s32bitdef)
  170. end
  171. else
  172. hp:=genordinalconstnode(round(vl),s32bitdef);
  173. end;
  174. in_const_frac : begin
  175. if isreal then
  176. hp:=genrealconstnode(frac(vr))
  177. else
  178. hp:=genrealconstnode(frac(vl));
  179. end;
  180. in_const_int : begin
  181. if isreal then
  182. hp:=genrealconstnode(int(vr))
  183. else
  184. hp:=genrealconstnode(int(vl));
  185. end;
  186. in_const_abs : begin
  187. if isreal then
  188. hp:=genrealconstnode(abs(vr))
  189. else
  190. hp:=genordinalconstnode(abs(vl),p^.left^.resulttype);
  191. end;
  192. in_const_sqr : begin
  193. if isreal then
  194. hp:=genrealconstnode(sqr(vr))
  195. else
  196. hp:=genordinalconstnode(sqr(vl),p^.left^.resulttype);
  197. end;
  198. in_const_odd : begin
  199. if isreal then
  200. CGMessage(type_e_integer_expr_expected)
  201. else
  202. hp:=genordinalconstnode(byte(odd(vl)),booldef);
  203. end;
  204. in_const_swap_word : begin
  205. if isreal then
  206. CGMessage(type_e_integer_expr_expected)
  207. else
  208. hp:=genordinalconstnode((vl and $ff) shl 8+(vl shr 8),p^.left^.resulttype);
  209. end;
  210. in_const_swap_long : begin
  211. if isreal then
  212. CGMessage(type_e_mismatch)
  213. else
  214. hp:=genordinalconstnode((vl and $ffff) shl 16+(vl shr 16),p^.left^.resulttype);
  215. end;
  216. in_const_ptr : begin
  217. if isreal then
  218. CGMessage(type_e_mismatch)
  219. else
  220. hp:=genordinalconstnode((vl2 shl 16) or vl,voidpointerdef);
  221. end;
  222. in_const_sqrt : begin
  223. if isreal then
  224. hp:=genrealconstnode(sqrt(vr))
  225. else
  226. hp:=genrealconstnode(sqrt(vl));
  227. end;
  228. in_const_arctan : begin
  229. if isreal then
  230. hp:=genrealconstnode(arctan(vr))
  231. else
  232. hp:=genrealconstnode(arctan(vl));
  233. end;
  234. in_const_cos : begin
  235. if isreal then
  236. hp:=genrealconstnode(cos(vr))
  237. else
  238. hp:=genrealconstnode(cos(vl));
  239. end;
  240. in_const_sin : begin
  241. if isreal then
  242. hp:=genrealconstnode(sin(vr))
  243. else
  244. hp:=genrealconstnode(sin(vl));
  245. end;
  246. in_const_exp : begin
  247. if isreal then
  248. hp:=genrealconstnode(exp(vr))
  249. else
  250. hp:=genrealconstnode(exp(vl));
  251. end;
  252. in_const_ln : begin
  253. if isreal then
  254. hp:=genrealconstnode(ln(vr))
  255. else
  256. hp:=genrealconstnode(ln(vl));
  257. end;
  258. else
  259. internalerror(88);
  260. end;
  261. end;
  262. disposetree(p);
  263. firstpass(hp);
  264. p:=hp;
  265. end
  266. else
  267. begin
  268. case p^.inlinenumber of
  269. in_lo_long,in_hi_long,
  270. in_lo_word,in_hi_word:
  271. begin
  272. if p^.registers32<1 then
  273. p^.registers32:=1;
  274. if p^.inlinenumber in [in_lo_word,in_hi_word] then
  275. p^.resulttype:=u8bitdef
  276. else
  277. begin
  278. p^.resulttype:=u16bitdef;
  279. if (m_tp in aktmodeswitches) or
  280. (m_delphi in aktmodeswitches) then
  281. CGMessage(type_w_maybe_wrong_hi_lo);
  282. end;
  283. p^.location.loc:=LOC_REGISTER;
  284. if not is_integer(p^.left^.resulttype) then
  285. CGMessage(type_e_mismatch)
  286. else
  287. begin
  288. if p^.left^.treetype=ordconstn then
  289. begin
  290. case p^.inlinenumber of
  291. in_lo_word : hp:=genordinalconstnode(p^.left^.value and $ff,p^.left^.resulttype);
  292. in_hi_word : hp:=genordinalconstnode(p^.left^.value shr 8,p^.left^.resulttype);
  293. in_lo_long : hp:=genordinalconstnode(p^.left^.value and $ffff,p^.left^.resulttype);
  294. in_hi_long : hp:=genordinalconstnode(p^.left^.value shr 16,p^.left^.resulttype);
  295. end;
  296. disposetree(p);
  297. firstpass(hp);
  298. p:=hp;
  299. end;
  300. end;
  301. end;
  302. in_sizeof_x:
  303. begin
  304. {$ifndef OLDHIGH}
  305. if push_high_param(p^.left^.resulttype) then
  306. begin
  307. getsymonlyin(p^.left^.symtable,'high'+pvarsym(p^.left^.symtableentry)^.name);
  308. hp:=gennode(addn,genloadnode(pvarsym(srsym),p^.left^.symtable),
  309. genordinalconstnode(1,s32bitdef));
  310. if (p^.left^.resulttype^.deftype=arraydef) and
  311. (parraydef(p^.left^.resulttype)^.elesize<>1) then
  312. hp:=gennode(muln,hp,genordinalconstnode(parraydef(p^.left^.resulttype)^.elesize,s32bitdef));
  313. disposetree(p);
  314. p:=hp;
  315. firstpass(p);
  316. end;
  317. {$endif OLDHIGH}
  318. if p^.registers32<1 then
  319. p^.registers32:=1;
  320. p^.resulttype:=s32bitdef;
  321. p^.location.loc:=LOC_REGISTER;
  322. end;
  323. in_typeof_x:
  324. begin
  325. if p^.registers32<1 then
  326. p^.registers32:=1;
  327. p^.location.loc:=LOC_REGISTER;
  328. p^.resulttype:=voidpointerdef;
  329. end;
  330. in_ord_x:
  331. begin
  332. if (p^.left^.treetype=ordconstn) then
  333. begin
  334. hp:=genordinalconstnode(p^.left^.value,s32bitdef);
  335. disposetree(p);
  336. p:=hp;
  337. firstpass(p);
  338. end
  339. else
  340. begin
  341. if (p^.left^.resulttype^.deftype=orddef) then
  342. if (porddef(p^.left^.resulttype)^.typ in [uchar,bool8bit]) then
  343. begin
  344. if porddef(p^.left^.resulttype)^.typ=bool8bit then
  345. begin
  346. hp:=gentypeconvnode(p^.left,u8bitdef);
  347. putnode(p);
  348. p:=hp;
  349. p^.convtyp:=tc_bool_2_int;
  350. p^.explizit:=true;
  351. firstpass(p);
  352. end
  353. else
  354. begin
  355. hp:=gentypeconvnode(p^.left,u8bitdef);
  356. putnode(p);
  357. p:=hp;
  358. p^.explizit:=true;
  359. firstpass(p);
  360. end;
  361. end
  362. { can this happen ? }
  363. else if (porddef(p^.left^.resulttype)^.typ=uvoid) then
  364. CGMessage(type_e_mismatch)
  365. else
  366. { all other orddef need no transformation }
  367. begin
  368. hp:=p^.left;
  369. putnode(p);
  370. p:=hp;
  371. end
  372. else if (p^.left^.resulttype^.deftype=enumdef) then
  373. begin
  374. hp:=gentypeconvnode(p^.left,s32bitdef);
  375. putnode(p);
  376. p:=hp;
  377. p^.explizit:=true;
  378. firstpass(p);
  379. end
  380. else
  381. begin
  382. { can anything else be ord() ?}
  383. CGMessage(type_e_mismatch);
  384. end;
  385. end;
  386. end;
  387. in_chr_byte:
  388. begin
  389. hp:=gentypeconvnode(p^.left,cchardef);
  390. putnode(p);
  391. p:=hp;
  392. p^.explizit:=true;
  393. firstpass(p);
  394. end;
  395. in_length_string:
  396. begin
  397. if is_ansistring(p^.left^.resulttype) then
  398. p^.resulttype:=s32bitdef
  399. else
  400. p^.resulttype:=u8bitdef;
  401. { we don't need string conversations here }
  402. if (p^.left^.treetype=typeconvn) and
  403. (p^.left^.left^.resulttype^.deftype=stringdef) then
  404. begin
  405. hp:=p^.left^.left;
  406. putnode(p^.left);
  407. p^.left:=hp;
  408. end;
  409. { check the type, must be string or char }
  410. if (p^.left^.resulttype^.deftype<>stringdef) and
  411. (not is_char(p^.left^.resulttype)) then
  412. CGMessage(type_e_mismatch);
  413. { evaluates length of constant strings direct }
  414. if (p^.left^.treetype=stringconstn) then
  415. begin
  416. hp:=genordinalconstnode(p^.left^.length,s32bitdef);
  417. disposetree(p);
  418. firstpass(hp);
  419. p:=hp;
  420. end
  421. { length of char is one allways }
  422. else if is_constcharnode(p^.left) then
  423. begin
  424. hp:=genordinalconstnode(1,s32bitdef);
  425. disposetree(p);
  426. firstpass(hp);
  427. p:=hp;
  428. end;
  429. end;
  430. in_assigned_x:
  431. begin
  432. p^.resulttype:=booldef;
  433. p^.location.loc:=LOC_FLAGS;
  434. end;
  435. in_pred_x,
  436. in_succ_x:
  437. begin
  438. inc(p^.registers32);
  439. p^.resulttype:=p^.left^.resulttype;
  440. p^.location.loc:=LOC_REGISTER;
  441. if not is_ordinal(p^.resulttype) then
  442. CGMessage(type_e_ordinal_expr_expected)
  443. else
  444. begin
  445. if (p^.resulttype^.deftype=enumdef) and
  446. (penumdef(p^.resulttype)^.has_jumps) then
  447. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible)
  448. else
  449. if p^.left^.treetype=ordconstn then
  450. begin
  451. if p^.inlinenumber=in_succ_x then
  452. hp:=genordinalconstnode(p^.left^.value+1,p^.left^.resulttype)
  453. else
  454. hp:=genordinalconstnode(p^.left^.value-1,p^.left^.resulttype);
  455. disposetree(p);
  456. firstpass(hp);
  457. p:=hp;
  458. end;
  459. end;
  460. end;
  461. in_inc_x,
  462. in_dec_x:
  463. begin
  464. p^.resulttype:=voiddef;
  465. if assigned(p^.left) then
  466. begin
  467. firstcallparan(p^.left,nil);
  468. if codegenerror then
  469. exit;
  470. { first param must be var }
  471. if is_constnode(p^.left^.left) then
  472. CGMessage(type_e_variable_id_expected);
  473. { check type }
  474. if (p^.left^.resulttype^.deftype in [enumdef,pointerdef]) or
  475. is_ordinal(p^.left^.resulttype) then
  476. begin
  477. { two paras ? }
  478. if assigned(p^.left^.right) then
  479. begin
  480. { insert a type conversion }
  481. { the second param is always longint }
  482. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,s32bitdef);
  483. { check the type conversion }
  484. firstpass(p^.left^.right^.left);
  485. { need we an additional register ? }
  486. if not(is_constintnode(p^.left^.right^.left)) and
  487. (p^.left^.right^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  488. (p^.left^.right^.left^.registers32<1) then
  489. inc(p^.registers32);
  490. if assigned(p^.left^.right^.right) then
  491. CGMessage(cg_e_illegal_expression);
  492. end;
  493. end
  494. else
  495. CGMessage(type_e_ordinal_expr_expected);
  496. end
  497. else
  498. CGMessage(type_e_mismatch);
  499. end;
  500. in_read_x,
  501. in_readln_x,
  502. in_write_x,
  503. in_writeln_x :
  504. begin
  505. { needs a call }
  506. procinfo.flags:=procinfo.flags or pi_do_call;
  507. p^.resulttype:=voiddef;
  508. { we must know if it is a typed file or not }
  509. { but we must first do the firstpass for it }
  510. file_is_typed:=false;
  511. if assigned(p^.left) then
  512. begin
  513. firstcallparan(p^.left,nil);
  514. { now we can check }
  515. hp:=p^.left;
  516. while assigned(hp^.right) do
  517. hp:=hp^.right;
  518. { if resulttype is not assigned, then automatically }
  519. { file is not typed. }
  520. if assigned(hp) and assigned(hp^.resulttype) then
  521. Begin
  522. if (hp^.resulttype^.deftype=filedef) and
  523. (pfiledef(hp^.resulttype)^.filetype=ft_typed) then
  524. begin
  525. file_is_typed:=true;
  526. { test the type }
  527. hpp:=p^.left;
  528. while (hpp<>hp) do
  529. begin
  530. if (hpp^.left^.treetype=typen) then
  531. CGMessage(type_e_cant_read_write_type);
  532. if not is_equal(hpp^.resulttype,pfiledef(hp^.resulttype)^.typed_as) then
  533. CGMessage(type_e_mismatch);
  534. hpp:=hpp^.right;
  535. end;
  536. end;
  537. end; { endif assigned(hp) }
  538. { insert type conversions for write(ln) }
  539. if (not file_is_typed) then
  540. begin
  541. dowrite:=(p^.inlinenumber in [in_write_x,in_writeln_x]);
  542. hp:=p^.left;
  543. while assigned(hp) do
  544. begin
  545. if (hp^.left^.treetype=typen) then
  546. CGMessage(type_e_cant_read_write_type);
  547. if assigned(hp^.left^.resulttype) then
  548. begin
  549. isreal:=false;
  550. case hp^.left^.resulttype^.deftype of
  551. filedef : begin
  552. { only allowed as first parameter }
  553. if assigned(hp^.right) then
  554. CGMessage(type_e_cant_read_write_type);
  555. end;
  556. stringdef : begin
  557. { generate the high() value for the shortstring }
  558. if (not dowrite) and
  559. is_shortstring(hp^.left^.resulttype) then
  560. gen_high_tree(hp,true);
  561. end;
  562. pointerdef : begin
  563. if not is_equal(ppointerdef(hp^.left^.resulttype)^.definition,cchardef) then
  564. CGMessage(type_e_cant_read_write_type);
  565. end;
  566. floatdef : begin
  567. isreal:=true;
  568. end;
  569. orddef : begin
  570. case porddef(hp^.left^.resulttype)^.typ of
  571. uchar,
  572. u32bit,
  573. s32bit,
  574. s64bitint,
  575. u64bit:
  576. ;
  577. u8bit,s8bit,
  578. u16bit,s16bit : if dowrite then
  579. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  580. bool8bit,
  581. bool16bit,bool32bit : if dowrite then
  582. hp^.left:=gentypeconvnode(hp^.left,booldef)
  583. else
  584. CGMessage(type_e_cant_read_write_type);
  585. else
  586. CGMessage(type_e_cant_read_write_type);
  587. end;
  588. end;
  589. arraydef : begin
  590. if not((parraydef(hp^.left^.resulttype)^.lowrange=0) and
  591. is_equal(parraydef(hp^.left^.resulttype)^.definition,cchardef)) then
  592. begin
  593. { but we convert only if the first index<>0,
  594. because in this case we have a ASCIIZ string }
  595. if dowrite and
  596. (parraydef(hp^.left^.resulttype)^.lowrange<>0) and
  597. (parraydef(hp^.left^.resulttype)^.definition^.deftype=orddef) and
  598. (porddef(parraydef(hp^.left^.resulttype)^.definition)^.typ=uchar) then
  599. hp^.left:=gentypeconvnode(hp^.left,cshortstringdef)
  600. else
  601. CGMessage(type_e_cant_read_write_type);
  602. end;
  603. end;
  604. else
  605. CGMessage(type_e_cant_read_write_type);
  606. end;
  607. { some format options ? }
  608. {$ifndef NOCOLONCHECK}
  609. { commented
  610. because supposes reverse order of parameters
  611. PM : now restored PM }
  612. if hp^.is_colon_para then
  613. begin
  614. if hp^.right^.is_colon_para then
  615. begin
  616. frac_para:=hp;
  617. length_para:=hp^.right;
  618. hp:=hp^.right;
  619. hpp:=hp^.right;
  620. end
  621. else
  622. begin
  623. length_para:=hp;
  624. frac_para:=nil;
  625. hpp:=hp^.right;
  626. end;
  627. isreal:=hpp^.resulttype^.deftype=floatdef;
  628. if (not is_integer(length_para^.resulttype)) then
  629. CGMessage(type_e_integer_expr_expected)
  630. else
  631. length_para^.left:=gentypeconvnode(length_para^.left,s32bitdef);
  632. if assigned(frac_para) then
  633. begin
  634. if isreal then
  635. begin
  636. if (not is_integer(frac_para^.resulttype)) then
  637. CGMessage(type_e_integer_expr_expected)
  638. else
  639. frac_para^.left:=gentypeconvnode(frac_para^.left,s32bitdef);
  640. end
  641. else
  642. CGMessage(parser_e_illegal_colon_qualifier);
  643. end;
  644. { do the checking for the colon'd arg }
  645. hp:=length_para;
  646. end;
  647. {$endif ndef NOCOLONCHECK}
  648. end;
  649. hp:=hp^.right;
  650. end;
  651. end;
  652. { pass all parameters again for the typeconversions }
  653. if codegenerror then
  654. exit;
  655. must_be_valid:=true;
  656. firstcallparan(p^.left,nil);
  657. { calc registers }
  658. left_right_max(p);
  659. end;
  660. end;
  661. in_settextbuf_file_x :
  662. begin
  663. { warning here p^.left is the callparannode
  664. not the argument directly }
  665. { p^.left^.left is text var }
  666. { p^.left^.right^.left is the buffer var }
  667. { firstcallparan(p^.left,nil);
  668. already done in firstcalln }
  669. { now we know the type of buffer }
  670. getsymonlyin(systemunit,'SETTEXTBUF');
  671. hp:=gencallnode(pprocsym(srsym),systemunit);
  672. hp^.left:=gencallparanode(
  673. genordinalconstnode(p^.left^.left^.resulttype^.size,s32bitdef),p^.left);
  674. putnode(p);
  675. p:=hp;
  676. firstpass(p);
  677. end;
  678. { the firstpass of the arg has been done in firstcalln ? }
  679. in_reset_typedfile,in_rewrite_typedfile :
  680. begin
  681. procinfo.flags:=procinfo.flags or pi_do_call;
  682. { to be sure the right definition is loaded }
  683. p^.left^.resulttype:=nil;
  684. firstload(p^.left);
  685. p^.resulttype:=voiddef;
  686. end;
  687. in_str_x_string :
  688. begin
  689. procinfo.flags:=procinfo.flags or pi_do_call;
  690. p^.resulttype:=voiddef;
  691. { check the amount of parameters }
  692. if not(assigned(p^.left)) or
  693. not(assigned(p^.left^.right)) then
  694. begin
  695. CGMessage(parser_e_wrong_parameter_size);
  696. exit;
  697. end;
  698. { first pass just the string for first local use }
  699. hp:=p^.left^.right;
  700. must_be_valid:=false;
  701. count_ref:=true;
  702. p^.left^.right:=nil;
  703. firstcallparan(p^.left,nil);
  704. must_be_valid:=true;
  705. p^.left^.right:=hp;
  706. firstcallparan(p^.left^.right,nil);
  707. hp:=p^.left;
  708. { valid string ? }
  709. if not assigned(hp) or
  710. (hp^.left^.resulttype^.deftype<>stringdef) or
  711. (hp^.right=nil) or
  712. (hp^.left^.location.loc<>LOC_REFERENCE) then
  713. CGMessage(cg_e_illegal_expression);
  714. { generate the high() value for the shortstring }
  715. if is_shortstring(hp^.left^.resulttype) then
  716. gen_high_tree(hp,true);
  717. { !!!! check length of string }
  718. while assigned(hp^.right) do
  719. hp:=hp^.right;
  720. { check and convert the first param }
  721. if hp^.is_colon_para then
  722. CGMessage(cg_e_illegal_expression);
  723. isreal:=false;
  724. case hp^.resulttype^.deftype of
  725. orddef : begin
  726. case porddef(hp^.left^.resulttype)^.typ of
  727. u32bit,
  728. s32bit,
  729. s64bitint,
  730. u64bit:
  731. ;
  732. u8bit,s8bit,
  733. u16bit,s16bit:
  734. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  735. else
  736. CGMessage(type_e_integer_or_real_expr_expected);
  737. end;
  738. end;
  739. floatdef : begin
  740. isreal:=true;
  741. end;
  742. else
  743. CGMessage(type_e_integer_or_real_expr_expected);
  744. end;
  745. { some format options ? }
  746. hpp:=p^.left^.right;
  747. if assigned(hpp) and hpp^.is_colon_para then
  748. begin
  749. if (not is_integer(hpp^.resulttype)) then
  750. CGMessage(type_e_integer_expr_expected)
  751. else
  752. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  753. hpp:=hpp^.right;
  754. if assigned(hpp) and hpp^.is_colon_para then
  755. begin
  756. if isreal then
  757. begin
  758. if (not is_integer(hpp^.resulttype)) then
  759. CGMessage(type_e_integer_expr_expected)
  760. else
  761. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  762. end
  763. else
  764. CGMessage(parser_e_illegal_colon_qualifier);
  765. end;
  766. end;
  767. { for first local use }
  768. must_be_valid:=false;
  769. count_ref:=true;
  770. { pass all parameters again for the typeconversions }
  771. if codegenerror then
  772. exit;
  773. must_be_valid:=true;
  774. firstcallparan(p^.left,nil);
  775. { calc registers }
  776. left_right_max(p);
  777. end;
  778. in_include_x_y,
  779. in_exclude_x_y:
  780. begin
  781. p^.resulttype:=voiddef;
  782. if assigned(p^.left) then
  783. begin
  784. firstcallparan(p^.left,nil);
  785. p^.registers32:=p^.left^.registers32;
  786. p^.registersfpu:=p^.left^.registersfpu;
  787. {$ifdef SUPPORT_MMX}
  788. p^.registersmmx:=p^.left^.registersmmx;
  789. {$endif SUPPORT_MMX}
  790. { first param must be var }
  791. if (p^.left^.left^.location.loc<>LOC_REFERENCE) and
  792. (p^.left^.left^.location.loc<>LOC_CREGISTER) then
  793. CGMessage(cg_e_illegal_expression);
  794. { check type }
  795. if (p^.left^.resulttype^.deftype=setdef) then
  796. begin
  797. { two paras ? }
  798. if assigned(p^.left^.right) then
  799. begin
  800. { insert a type conversion }
  801. { to the type of the set elements }
  802. p^.left^.right^.left:=gentypeconvnode(
  803. p^.left^.right^.left,
  804. psetdef(p^.left^.resulttype)^.setof);
  805. { check the type conversion }
  806. firstpass(p^.left^.right^.left);
  807. { only three parameters are allowed }
  808. if assigned(p^.left^.right^.right) then
  809. CGMessage(cg_e_illegal_expression);
  810. end;
  811. end
  812. else
  813. CGMessage(type_e_mismatch);
  814. end
  815. else
  816. CGMessage(type_e_mismatch);
  817. end;
  818. in_low_x,in_high_x:
  819. begin
  820. if p^.left^.treetype in [typen,loadn,subscriptn] then
  821. begin
  822. case p^.left^.resulttype^.deftype of
  823. orddef,enumdef:
  824. begin
  825. do_lowhigh(p^.left^.resulttype);
  826. firstpass(p);
  827. end;
  828. setdef:
  829. begin
  830. do_lowhigh(Psetdef(p^.left^.resulttype)^.setof);
  831. firstpass(p);
  832. end;
  833. arraydef:
  834. begin
  835. if p^.inlinenumber=in_low_x then
  836. begin
  837. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef);
  838. disposetree(p);
  839. p:=hp;
  840. firstpass(p);
  841. end
  842. else
  843. begin
  844. if is_open_array(p^.left^.resulttype) then
  845. begin
  846. {$ifndef OLDHIGH}
  847. getsymonlyin(p^.left^.symtable,'high'+pvarsym(p^.left^.symtableentry)^.name);
  848. hp:=genloadnode(pvarsym(srsym),p^.left^.symtable);
  849. disposetree(p);
  850. p:=hp;
  851. firstpass(p);
  852. {$else OLDHIGH}
  853. p^.resulttype:=s32bitdef;
  854. p^.registers32:=max(1,p^.registers32);
  855. p^.location.loc:=LOC_REGISTER;
  856. {$endif OLDHIGH}
  857. end
  858. else
  859. begin
  860. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.highrange,s32bitdef);
  861. disposetree(p);
  862. p:=hp;
  863. firstpass(p);
  864. end;
  865. end;
  866. end;
  867. stringdef:
  868. begin
  869. if p^.inlinenumber=in_low_x then
  870. begin
  871. hp:=genordinalconstnode(0,u8bitdef);
  872. disposetree(p);
  873. p:=hp;
  874. firstpass(p);
  875. end
  876. else
  877. begin
  878. if is_open_string(p^.left^.resulttype) then
  879. begin
  880. {$ifndef OLDHIGH}
  881. getsymonlyin(p^.left^.symtable,'high'+pvarsym(p^.left^.symtableentry)^.name);
  882. hp:=genloadnode(pvarsym(srsym),p^.left^.symtable);
  883. disposetree(p);
  884. p:=hp;
  885. firstpass(p);
  886. {$else OLDHIGH}
  887. p^.resulttype:=s32bitdef;
  888. p^.registers32:=max(1,p^.registers32);
  889. p^.location.loc:=LOC_REGISTER;
  890. {$endif OLDHIGH}
  891. end
  892. else
  893. begin
  894. hp:=genordinalconstnode(Pstringdef(p^.left^.resulttype)^.len,u8bitdef);
  895. disposetree(p);
  896. p:=hp;
  897. firstpass(p);
  898. end;
  899. end;
  900. end;
  901. else
  902. CGMessage(type_e_mismatch);
  903. end;
  904. end
  905. else
  906. CGMessage(type_e_varid_or_typeid_expected);
  907. end;
  908. in_assert_x_y :
  909. begin
  910. p^.resulttype:=voiddef;
  911. if assigned(p^.left) then
  912. begin
  913. firstcallparan(p^.left,nil);
  914. p^.registers32:=p^.left^.registers32;
  915. p^.registersfpu:=p^.left^.registersfpu;
  916. {$ifdef SUPPORT_MMX}
  917. p^.registersmmx:=p^.left^.registersmmx;
  918. {$endif SUPPORT_MMX}
  919. { check type }
  920. if is_boolean(p^.left^.resulttype) then
  921. begin
  922. { must always be a string }
  923. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,cshortstringdef);
  924. firstpass(p^.left^.right^.left);
  925. end
  926. else
  927. CGMessage(type_e_mismatch);
  928. end
  929. else
  930. CGMessage(type_e_mismatch);
  931. end;
  932. else
  933. internalerror(8);
  934. end;
  935. end;
  936. { generate an error if no resulttype is set }
  937. if not assigned(p^.resulttype) then
  938. p^.resulttype:=generrordef;
  939. must_be_valid:=store_valid;
  940. count_ref:=store_count_ref;
  941. end;
  942. end.
  943. {
  944. $Log$
  945. Revision 1.19 1999-02-22 12:36:34 florian
  946. + warning for lo/hi(longint/dword) in -So and -Sd mode added
  947. Revision 1.18 1999/02/22 02:15:49 peter
  948. * updates for ag386bin
  949. Revision 1.17 1999/02/01 00:00:50 florian
  950. * compiler crash fixed when constant arguments passed to round/trunc
  951. exceeds the longint range
  952. Revision 1.16 1999/01/28 19:43:43 peter
  953. * fixed high generation for ansistrings with str,writeln
  954. Revision 1.15 1999/01/27 16:28:22 pierre
  955. * bug0157 solved : write(x:5.3) is rejected now
  956. Revision 1.14 1999/01/21 22:10:50 peter
  957. * fixed array of const
  958. * generic platform independent high() support
  959. Revision 1.13 1998/12/30 22:13:13 peter
  960. * check the amount of paras for Str()
  961. Revision 1.12 1998/12/15 10:23:31 peter
  962. + -iSO, -iSP, -iTO, -iTP
  963. Revision 1.11 1998/12/11 23:36:08 florian
  964. + again more stuff for int64/qword:
  965. - comparision operators
  966. - code generation for: str, read(ln), write(ln)
  967. Revision 1.10 1998/11/27 14:50:53 peter
  968. + open strings, $P switch support
  969. Revision 1.9 1998/11/24 17:04:28 peter
  970. * fixed length(char) when char is a variable
  971. Revision 1.8 1998/11/14 10:51:33 peter
  972. * fixed low/high for record.field
  973. Revision 1.7 1998/11/13 10:15:52 peter
  974. * fixed ptr() with constants
  975. Revision 1.6 1998/11/05 12:03:05 peter
  976. * released useansistring
  977. * removed -Sv, its now available in fpc modes
  978. Revision 1.5 1998/10/20 11:16:47 pierre
  979. + length(c) where C is a char is allways 1
  980. Revision 1.4 1998/10/06 20:49:11 peter
  981. * m68k compiler compiles again
  982. Revision 1.3 1998/10/05 12:32:49 peter
  983. + assert() support
  984. Revision 1.2 1998/10/02 09:24:23 peter
  985. * more constant expression evaluators
  986. Revision 1.1 1998/09/23 20:42:24 peter
  987. * splitted pass_1
  988. }