tcinl.pas 44 KB

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