tcinl.pas 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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,
  524. s32bit,
  525. s64bitint,
  526. u64bit:
  527. ;
  528. u8bit,s8bit,
  529. u16bit,s16bit : if dowrite then
  530. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  531. bool8bit,
  532. bool16bit,bool32bit : if dowrite then
  533. hp^.left:=gentypeconvnode(hp^.left,booldef)
  534. else
  535. CGMessage(type_e_cant_read_write_type);
  536. else
  537. CGMessage(type_e_cant_read_write_type);
  538. end;
  539. end;
  540. arraydef : begin
  541. if not((parraydef(hp^.left^.resulttype)^.lowrange=0) and
  542. is_equal(parraydef(hp^.left^.resulttype)^.definition,cchardef)) then
  543. begin
  544. { but we convert only if the first index<>0,
  545. because in this case we have a ASCIIZ string }
  546. if dowrite and
  547. (parraydef(hp^.left^.resulttype)^.lowrange<>0) and
  548. (parraydef(hp^.left^.resulttype)^.definition^.deftype=orddef) and
  549. (porddef(parraydef(hp^.left^.resulttype)^.definition)^.typ=uchar) then
  550. hp^.left:=gentypeconvnode(hp^.left,cshortstringdef)
  551. else
  552. CGMessage(type_e_cant_read_write_type);
  553. end;
  554. end;
  555. else
  556. CGMessage(type_e_cant_read_write_type);
  557. end;
  558. { some format options ? }
  559. (* commented
  560. because supposes reverse order of parameters
  561. PM
  562. hpp:=hp^.right;
  563. if assigned(hpp) and hpp^.is_colon_para then
  564. begin
  565. if (not is_integer(hpp^.resulttype)) then
  566. CGMessage(type_e_integer_expr_expected)
  567. else
  568. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  569. hpp:=hpp^.right;
  570. if assigned(hpp) and hpp^.is_colon_para then
  571. begin
  572. if isreal then
  573. begin
  574. if (not is_integer(hpp^.resulttype)) then
  575. CGMessage(type_e_integer_expr_expected)
  576. else
  577. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  578. end
  579. else
  580. CGMessage(parser_e_illegal_colon_qualifier);
  581. end;
  582. end; *)
  583. end;
  584. hp:=hp^.right;
  585. end;
  586. end;
  587. { pass all parameters again for the typeconversions }
  588. if codegenerror then
  589. exit;
  590. must_be_valid:=true;
  591. firstcallparan(p^.left,nil);
  592. { calc registers }
  593. left_right_max(p);
  594. end;
  595. end;
  596. in_settextbuf_file_x :
  597. begin
  598. { warning here p^.left is the callparannode
  599. not the argument directly }
  600. { p^.left^.left is text var }
  601. { p^.left^.right^.left is the buffer var }
  602. { firstcallparan(p^.left,nil);
  603. already done in firstcalln }
  604. { now we know the type of buffer }
  605. getsymonlyin(systemunit,'SETTEXTBUF');
  606. hp:=gencallnode(pprocsym(srsym),systemunit);
  607. hp^.left:=gencallparanode(
  608. genordinalconstnode(p^.left^.left^.resulttype^.size,s32bitdef),p^.left);
  609. putnode(p);
  610. p:=hp;
  611. firstpass(p);
  612. end;
  613. { the firstpass of the arg has been done in firstcalln ? }
  614. in_reset_typedfile,in_rewrite_typedfile :
  615. begin
  616. procinfo.flags:=procinfo.flags or pi_do_call;
  617. { to be sure the right definition is loaded }
  618. p^.left^.resulttype:=nil;
  619. firstload(p^.left);
  620. p^.resulttype:=voiddef;
  621. end;
  622. in_str_x_string :
  623. begin
  624. procinfo.flags:=procinfo.flags or pi_do_call;
  625. p^.resulttype:=voiddef;
  626. { check the amount of parameters }
  627. if not(assigned(p^.left)) or
  628. not(assigned(p^.left^.right)) then
  629. begin
  630. CGMessage(parser_e_wrong_parameter_size);
  631. exit;
  632. end;
  633. { first pass just the string for first local use }
  634. hp:=p^.left^.right;
  635. must_be_valid:=false;
  636. count_ref:=true;
  637. p^.left^.right:=nil;
  638. firstcallparan(p^.left,nil);
  639. must_be_valid:=true;
  640. p^.left^.right:=hp;
  641. firstcallparan(p^.left^.right,nil);
  642. hp:=p^.left;
  643. { valid string ? }
  644. if not assigned(hp) or
  645. (hp^.left^.resulttype^.deftype<>stringdef) or
  646. (hp^.right=nil) or
  647. (hp^.left^.location.loc<>LOC_REFERENCE) then
  648. CGMessage(cg_e_illegal_expression);
  649. { !!!! check length of string }
  650. while assigned(hp^.right) do
  651. hp:=hp^.right;
  652. { check and convert the first param }
  653. if hp^.is_colon_para then
  654. CGMessage(cg_e_illegal_expression);
  655. isreal:=false;
  656. case hp^.resulttype^.deftype of
  657. orddef : begin
  658. case porddef(hp^.left^.resulttype)^.typ of
  659. u32bit,
  660. s32bit,
  661. s64bitint,
  662. u64bit:
  663. ;
  664. u8bit,s8bit,
  665. u16bit,s16bit:
  666. hp^.left:=gentypeconvnode(hp^.left,s32bitdef);
  667. else
  668. CGMessage(type_e_integer_or_real_expr_expected);
  669. end;
  670. end;
  671. floatdef : begin
  672. isreal:=true;
  673. end;
  674. else
  675. CGMessage(type_e_integer_or_real_expr_expected);
  676. end;
  677. { some format options ? }
  678. hpp:=p^.left^.right;
  679. if assigned(hpp) and hpp^.is_colon_para then
  680. begin
  681. if (not is_integer(hpp^.resulttype)) then
  682. CGMessage(type_e_integer_expr_expected)
  683. else
  684. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  685. hpp:=hpp^.right;
  686. if assigned(hpp) and hpp^.is_colon_para then
  687. begin
  688. if isreal then
  689. begin
  690. if (not is_integer(hpp^.resulttype)) then
  691. CGMessage(type_e_integer_expr_expected)
  692. else
  693. hpp^.left:=gentypeconvnode(hpp^.left,s32bitdef);
  694. end
  695. else
  696. CGMessage(parser_e_illegal_colon_qualifier);
  697. end;
  698. end;
  699. { for first local use }
  700. must_be_valid:=false;
  701. count_ref:=true;
  702. { pass all parameters again for the typeconversions }
  703. if codegenerror then
  704. exit;
  705. must_be_valid:=true;
  706. firstcallparan(p^.left,nil);
  707. { calc registers }
  708. left_right_max(p);
  709. end;
  710. in_include_x_y,
  711. in_exclude_x_y:
  712. begin
  713. p^.resulttype:=voiddef;
  714. if assigned(p^.left) then
  715. begin
  716. firstcallparan(p^.left,nil);
  717. p^.registers32:=p^.left^.registers32;
  718. p^.registersfpu:=p^.left^.registersfpu;
  719. {$ifdef SUPPORT_MMX}
  720. p^.registersmmx:=p^.left^.registersmmx;
  721. {$endif SUPPORT_MMX}
  722. { first param must be var }
  723. if (p^.left^.left^.location.loc<>LOC_REFERENCE) and
  724. (p^.left^.left^.location.loc<>LOC_CREGISTER) then
  725. CGMessage(cg_e_illegal_expression);
  726. { check type }
  727. if (p^.left^.resulttype^.deftype=setdef) then
  728. begin
  729. { two paras ? }
  730. if assigned(p^.left^.right) then
  731. begin
  732. { insert a type conversion }
  733. { to the type of the set elements }
  734. p^.left^.right^.left:=gentypeconvnode(
  735. p^.left^.right^.left,
  736. psetdef(p^.left^.resulttype)^.setof);
  737. { check the type conversion }
  738. firstpass(p^.left^.right^.left);
  739. { only three parameters are allowed }
  740. if assigned(p^.left^.right^.right) then
  741. CGMessage(cg_e_illegal_expression);
  742. end;
  743. end
  744. else
  745. CGMessage(type_e_mismatch);
  746. end
  747. else
  748. CGMessage(type_e_mismatch);
  749. end;
  750. in_low_x,in_high_x:
  751. begin
  752. if p^.left^.treetype in [typen,loadn,subscriptn] then
  753. begin
  754. case p^.left^.resulttype^.deftype of
  755. orddef,enumdef:
  756. begin
  757. do_lowhigh(p^.left^.resulttype);
  758. firstpass(p);
  759. end;
  760. setdef:
  761. begin
  762. do_lowhigh(Psetdef(p^.left^.resulttype)^.setof);
  763. firstpass(p);
  764. end;
  765. arraydef:
  766. begin
  767. if p^.inlinenumber=in_low_x then
  768. begin
  769. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.lowrange,s32bitdef);
  770. disposetree(p);
  771. p:=hp;
  772. firstpass(p);
  773. end
  774. else
  775. begin
  776. if is_open_array(p^.left^.resulttype) then
  777. begin
  778. p^.resulttype:=s32bitdef;
  779. p^.registers32:=max(1,p^.registers32);
  780. p^.location.loc:=LOC_REGISTER;
  781. end
  782. else
  783. begin
  784. hp:=genordinalconstnode(Parraydef(p^.left^.resulttype)^.highrange,s32bitdef);
  785. disposetree(p);
  786. p:=hp;
  787. firstpass(p);
  788. end;
  789. end;
  790. end;
  791. stringdef:
  792. begin
  793. if p^.inlinenumber=in_low_x then
  794. begin
  795. hp:=genordinalconstnode(0,u8bitdef);
  796. disposetree(p);
  797. p:=hp;
  798. firstpass(p);
  799. end
  800. else
  801. begin
  802. if is_open_string(p^.left^.resulttype) then
  803. begin
  804. p^.resulttype:=s32bitdef;
  805. p^.registers32:=max(1,p^.registers32);
  806. p^.location.loc:=LOC_REGISTER;
  807. end
  808. else
  809. begin
  810. hp:=genordinalconstnode(Pstringdef(p^.left^.resulttype)^.len,u8bitdef);
  811. disposetree(p);
  812. p:=hp;
  813. firstpass(p);
  814. end;
  815. end;
  816. end;
  817. else
  818. CGMessage(type_e_mismatch);
  819. end;
  820. end
  821. else
  822. CGMessage(type_e_varid_or_typeid_expected);
  823. end;
  824. in_assert_x_y :
  825. begin
  826. p^.resulttype:=voiddef;
  827. if assigned(p^.left) then
  828. begin
  829. firstcallparan(p^.left,nil);
  830. p^.registers32:=p^.left^.registers32;
  831. p^.registersfpu:=p^.left^.registersfpu;
  832. {$ifdef SUPPORT_MMX}
  833. p^.registersmmx:=p^.left^.registersmmx;
  834. {$endif SUPPORT_MMX}
  835. { check type }
  836. if is_boolean(p^.left^.resulttype) then
  837. begin
  838. { must always be a string }
  839. p^.left^.right^.left:=gentypeconvnode(p^.left^.right^.left,cshortstringdef);
  840. firstpass(p^.left^.right^.left);
  841. end
  842. else
  843. CGMessage(type_e_mismatch);
  844. end
  845. else
  846. CGMessage(type_e_mismatch);
  847. end;
  848. else
  849. internalerror(8);
  850. end;
  851. end;
  852. { generate an error if no resulttype is set }
  853. if not assigned(p^.resulttype) then
  854. p^.resulttype:=generrordef;
  855. must_be_valid:=store_valid;
  856. count_ref:=store_count_ref;
  857. end;
  858. end.
  859. {
  860. $Log$
  861. Revision 1.13 1998-12-30 22:13:13 peter
  862. * check the amount of paras for Str()
  863. Revision 1.12 1998/12/15 10:23:31 peter
  864. + -iSO, -iSP, -iTO, -iTP
  865. Revision 1.11 1998/12/11 23:36:08 florian
  866. + again more stuff for int64/qword:
  867. - comparision operators
  868. - code generation for: str, read(ln), write(ln)
  869. Revision 1.10 1998/11/27 14:50:53 peter
  870. + open strings, $P switch support
  871. Revision 1.9 1998/11/24 17:04:28 peter
  872. * fixed length(char) when char is a variable
  873. Revision 1.8 1998/11/14 10:51:33 peter
  874. * fixed low/high for record.field
  875. Revision 1.7 1998/11/13 10:15:52 peter
  876. * fixed ptr() with constants
  877. Revision 1.6 1998/11/05 12:03:05 peter
  878. * released useansistring
  879. * removed -Sv, its now available in fpc modes
  880. Revision 1.5 1998/10/20 11:16:47 pierre
  881. + length(c) where C is a char is allways 1
  882. Revision 1.4 1998/10/06 20:49:11 peter
  883. * m68k compiler compiles again
  884. Revision 1.3 1998/10/05 12:32:49 peter
  885. + assert() support
  886. Revision 1.2 1998/10/02 09:24:23 peter
  887. * more constant expression evaluators
  888. Revision 1.1 1998/09/23 20:42:24 peter
  889. * splitted pass_1
  890. }