ninl.pas 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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 ninl;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,htypechk,cpuinfo;
  23. {$i compinnr.inc}
  24. type
  25. tinlinenode = class(tunarynode)
  26. inlinenumber : byte;
  27. constructor create(number : byte;is_const:boolean;l : tnode);virtual;
  28. function getcopy : tnode;override;
  29. function pass_1 : tnode;override;
  30. function docompare(p: tnode): boolean; override;
  31. end;
  32. var
  33. cinlinenode : class of tinlinenode;
  34. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  35. implementation
  36. uses
  37. verbose,globals,systems,
  38. globtype,
  39. symconst,symtype,symdef,symsym,symtable,types,
  40. pass_1,
  41. ncal,ncon,ncnv,nadd,nld,nbas,
  42. cpubase,hcodegen,tgcpu
  43. {$ifdef newcg}
  44. ,cgbase
  45. {$endif newcg}
  46. ;
  47. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  48. begin
  49. geninlinenode:=cinlinenode.create(number,is_const,l);
  50. end;
  51. {*****************************************************************************
  52. TINLINENODE
  53. *****************************************************************************}
  54. constructor tinlinenode.create(number : byte;is_const:boolean;l : tnode);
  55. begin
  56. inherited create(inlinen,l);
  57. if is_const then
  58. include(flags,nf_inlineconst);
  59. inlinenumber:=number;
  60. end;
  61. function tinlinenode.getcopy : tnode;
  62. var
  63. n : tinlinenode;
  64. begin
  65. n:=tinlinenode(inherited getcopy);
  66. n.inlinenumber:=inlinenumber;
  67. result:=n;
  68. end;
  69. {$ifdef fpc}
  70. {$maxfpuregisters 0}
  71. {$endif fpc}
  72. function tinlinenode.pass_1 : tnode;
  73. var
  74. vl,vl2,counter : longint;
  75. vr : bestreal;
  76. p1,hp,hpp : tnode;
  77. ppn : tcallparanode;
  78. dummycoll: tparaitem;
  79. {$ifndef NOCOLONCHECK}
  80. frac_para,length_para : tnode;
  81. {$endif ndef NOCOLONCHECK}
  82. extra_register,
  83. isreal,
  84. iswrite,
  85. file_is_typed : boolean;
  86. function do_lowhigh(adef : pdef) : tnode;
  87. var
  88. v : tconstexprint;
  89. enum : penumsym;
  90. begin
  91. case Adef^.deftype of
  92. orddef:
  93. begin
  94. if inlinenumber=in_low_x then
  95. v:=porddef(adef)^.low
  96. else
  97. v:=porddef(adef)^.high;
  98. { low/high of torddef are longints, so we need special }
  99. { handling for cardinal and 64bit types (JM) }
  100. if is_signed(adef) and
  101. is_64bitint(adef) then
  102. if (inlinenumber=in_low_x) then
  103. v := int64($80000000) shl 32
  104. else
  105. v := (int64($7fffffff) shl 32) or $ffffffff
  106. else
  107. if is_64bitint(adef) then
  108. { we have to use a dirty trick for high(qword), }
  109. { because it's bigger than high(tconstexprint) (JM) }
  110. v := 0
  111. else
  112. v := cardinal(v);
  113. hp:=genordinalconstnode(v,adef);
  114. firstpass(hp);
  115. { fix high(qword) }
  116. if not is_signed(adef) and
  117. is_64bitint(adef) and
  118. (inlinenumber = in_high_x) then
  119. tordconstnode(hp).value :=
  120. tconstexprint(qword($ffffffff) shl 32 or $ffffffff);
  121. do_lowhigh:=hp;
  122. end;
  123. enumdef:
  124. begin
  125. enum:=penumsym(Penumdef(Adef)^.firstenum);
  126. v:=Penumdef(adef)^.maxval;
  127. if inlinenumber=in_high_x then
  128. while assigned(enum) and (enum^.value <> v) do
  129. enum:=enum^.nextenum;
  130. if not assigned(enum) then
  131. internalerror(309993)
  132. else
  133. hp:=genenumnode(enum);
  134. do_lowhigh:=hp;
  135. end;
  136. else
  137. internalerror(87);
  138. end;
  139. end;
  140. function getconstrealvalue : bestreal;
  141. begin
  142. case left.nodetype of
  143. ordconstn:
  144. getconstrealvalue:=tordconstnode(left).value;
  145. realconstn:
  146. getconstrealvalue:=trealconstnode(left).value_real;
  147. else
  148. internalerror(309992);
  149. end;
  150. end;
  151. procedure setconstrealvalue(r : bestreal);
  152. var
  153. hp : tnode;
  154. begin
  155. hp:=genrealconstnode(r,bestrealdef^);
  156. firstpass(hp);
  157. pass_1:=hp;
  158. end;
  159. procedure handleextendedfunction;
  160. begin
  161. location.loc:=LOC_FPU;
  162. resulttype:=s80floatdef;
  163. { redo firstpass for varstate status PM }
  164. set_varstate(left,true);
  165. if (left.resulttype^.deftype<>floatdef) or
  166. (pfloatdef(left.resulttype)^.typ<>s80real) then
  167. begin
  168. left:=gentypeconvnode(left,s80floatdef);
  169. firstpass(left);
  170. end;
  171. registers32:=left.registers32;
  172. registersfpu:=left.registersfpu;
  173. {$ifdef SUPPORT_MMX}
  174. registersmmx:=left.registersmmx;
  175. {$endif SUPPORT_MMX}
  176. end;
  177. begin
  178. result:=nil;
  179. { if we handle writeln; left contains no valid address }
  180. if assigned(left) then
  181. begin
  182. if left.nodetype=callparan then
  183. tcallparanode(left).firstcallparan(nil,false)
  184. else
  185. firstpass(left);
  186. left_max;
  187. set_location(location,left.location);
  188. end;
  189. inc(parsing_para_level);
  190. { handle intern constant functions in separate case }
  191. if nf_inlineconst in flags then
  192. begin
  193. hp:=nil;
  194. { no parameters? }
  195. if not assigned(left) then
  196. begin
  197. case inlinenumber of
  198. in_const_pi :
  199. hp:=genrealconstnode(pi,bestrealdef^);
  200. else
  201. internalerror(89);
  202. end;
  203. end
  204. else
  205. { process constant expression with parameter }
  206. begin
  207. vl:=0;
  208. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  209. vr:=0;
  210. isreal:=false;
  211. case left.nodetype of
  212. realconstn :
  213. begin
  214. isreal:=true;
  215. vr:=trealconstnode(left).value_real;
  216. end;
  217. ordconstn :
  218. vl:=tordconstnode(left).value;
  219. callparan :
  220. begin
  221. { both exists, else it was not generated }
  222. vl:=tordconstnode(tcallparanode(left).left).value;
  223. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  224. end;
  225. else
  226. CGMessage(cg_e_illegal_expression);
  227. end;
  228. case inlinenumber of
  229. in_const_trunc :
  230. begin
  231. if isreal then
  232. begin
  233. if (vr>=2147483648.0) or (vr<=-2147483649.0) then
  234. begin
  235. CGMessage(parser_e_range_check_error);
  236. hp:=genordinalconstnode(1,s32bitdef)
  237. end
  238. else
  239. hp:=genordinalconstnode(trunc(vr),s32bitdef)
  240. end
  241. else
  242. hp:=genordinalconstnode(trunc(vl),s32bitdef);
  243. end;
  244. in_const_round :
  245. begin
  246. if isreal then
  247. begin
  248. if (vr>=2147483647.5) or (vr<=-2147483648.5) then
  249. begin
  250. CGMessage(parser_e_range_check_error);
  251. hp:=genordinalconstnode(1,s32bitdef)
  252. end
  253. else
  254. hp:=genordinalconstnode(round(vr),s32bitdef)
  255. end
  256. else
  257. hp:=genordinalconstnode(round(vl),s32bitdef);
  258. end;
  259. in_const_frac :
  260. begin
  261. if isreal then
  262. hp:=genrealconstnode(frac(vr),bestrealdef^)
  263. else
  264. hp:=genrealconstnode(frac(vl),bestrealdef^);
  265. end;
  266. in_const_int :
  267. begin
  268. if isreal then
  269. hp:=genrealconstnode(int(vr),bestrealdef^)
  270. else
  271. hp:=genrealconstnode(int(vl),bestrealdef^);
  272. end;
  273. in_const_abs :
  274. begin
  275. if isreal then
  276. hp:=genrealconstnode(abs(vr),bestrealdef^)
  277. else
  278. hp:=genordinalconstnode(abs(vl),left.resulttype);
  279. end;
  280. in_const_sqr :
  281. begin
  282. if isreal then
  283. hp:=genrealconstnode(sqr(vr),bestrealdef^)
  284. else
  285. hp:=genordinalconstnode(sqr(vl),left.resulttype);
  286. end;
  287. in_const_odd :
  288. begin
  289. if isreal then
  290. CGMessage1(type_e_integer_expr_expected,left.resulttype^.typename)
  291. else
  292. hp:=genordinalconstnode(byte(odd(vl)),booldef);
  293. end;
  294. in_const_swap_word :
  295. begin
  296. if isreal then
  297. CGMessage1(type_e_integer_expr_expected,left.resulttype^.typename)
  298. else
  299. hp:=genordinalconstnode((vl and $ff) shl 8+(vl shr 8),left.resulttype);
  300. end;
  301. in_const_swap_long :
  302. begin
  303. if isreal then
  304. CGMessage(type_e_mismatch)
  305. else
  306. hp:=genordinalconstnode((vl and $ffff) shl 16+(vl shr 16),left.resulttype);
  307. end;
  308. in_const_ptr :
  309. begin
  310. if isreal then
  311. CGMessage(type_e_mismatch)
  312. else
  313. hp:=genordinalconstnode((vl2 shl 4)+vl,voidfarpointerdef);
  314. end;
  315. in_const_sqrt :
  316. begin
  317. if isreal then
  318. begin
  319. if vr<0.0 then
  320. CGMessage(type_e_wrong_math_argument)
  321. else
  322. hp:=genrealconstnode(sqrt(vr),bestrealdef^)
  323. end
  324. else
  325. begin
  326. if vl<0 then
  327. CGMessage(type_e_wrong_math_argument)
  328. else
  329. hp:=genrealconstnode(sqrt(vl),bestrealdef^);
  330. end;
  331. end;
  332. in_const_arctan :
  333. begin
  334. if isreal then
  335. hp:=genrealconstnode(arctan(vr),bestrealdef^)
  336. else
  337. hp:=genrealconstnode(arctan(vl),bestrealdef^);
  338. end;
  339. in_const_cos :
  340. begin
  341. if isreal then
  342. hp:=genrealconstnode(cos(vr),bestrealdef^)
  343. else
  344. hp:=genrealconstnode(cos(vl),bestrealdef^);
  345. end;
  346. in_const_sin :
  347. begin
  348. if isreal then
  349. hp:=genrealconstnode(sin(vr),bestrealdef^)
  350. else
  351. hp:=genrealconstnode(sin(vl),bestrealdef^);
  352. end;
  353. in_const_exp :
  354. begin
  355. if isreal then
  356. hp:=genrealconstnode(exp(vr),bestrealdef^)
  357. else
  358. hp:=genrealconstnode(exp(vl),bestrealdef^);
  359. end;
  360. in_const_ln :
  361. begin
  362. if isreal then
  363. begin
  364. if vr<=0.0 then
  365. CGMessage(type_e_wrong_math_argument)
  366. else
  367. hp:=genrealconstnode(ln(vr),bestrealdef^)
  368. end
  369. else
  370. begin
  371. if vl<=0 then
  372. CGMessage(type_e_wrong_math_argument)
  373. else
  374. hp:=genrealconstnode(ln(vl),bestrealdef^);
  375. end;
  376. end;
  377. else
  378. internalerror(88);
  379. end;
  380. end;
  381. if hp=nil then
  382. hp:=tnode.create(errorn);
  383. firstpass(hp);
  384. result:=hp;
  385. end
  386. else
  387. begin
  388. case inlinenumber of
  389. in_lo_qword,
  390. in_hi_qword,
  391. in_lo_long,
  392. in_hi_long,
  393. in_lo_word,
  394. in_hi_word:
  395. begin
  396. set_varstate(left,true);
  397. if registers32<1 then
  398. registers32:=1;
  399. if inlinenumber in [in_lo_word,in_hi_word] then
  400. resulttype:=u8bitdef
  401. else if inlinenumber in [in_lo_qword,in_hi_qword] then
  402. begin
  403. resulttype:=u32bitdef;
  404. if (m_tp in aktmodeswitches) or
  405. (m_delphi in aktmodeswitches) then
  406. CGMessage(type_w_maybe_wrong_hi_lo);
  407. end
  408. else
  409. begin
  410. resulttype:=u16bitdef;
  411. if (m_tp in aktmodeswitches) or
  412. (m_delphi in aktmodeswitches) then
  413. CGMessage(type_w_maybe_wrong_hi_lo);
  414. end;
  415. location.loc:=LOC_REGISTER;
  416. if not is_integer(left.resulttype) then
  417. CGMessage(type_e_mismatch)
  418. else
  419. begin
  420. if left.nodetype=ordconstn then
  421. begin
  422. case inlinenumber of
  423. in_lo_word : hp:=genordinalconstnode(tordconstnode(left).value and $ff,left.resulttype);
  424. in_hi_word : hp:=genordinalconstnode(tordconstnode(left).value shr 8,left.resulttype);
  425. in_lo_long : hp:=genordinalconstnode(tordconstnode(left).value and $ffff,left.resulttype);
  426. in_hi_long : hp:=genordinalconstnode(tordconstnode(left).value shr 16,left.resulttype);
  427. in_lo_qword : hp:=genordinalconstnode(tordconstnode(left).value and $ffffffff,left.resulttype);
  428. in_hi_qword : hp:=genordinalconstnode(tordconstnode(left).value shr 32,left.resulttype);
  429. end;
  430. firstpass(hp);
  431. result:=hp;
  432. end;
  433. end;
  434. end;
  435. in_sizeof_x:
  436. begin
  437. set_varstate(left,false);
  438. if push_high_param(left.resulttype) then
  439. begin
  440. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  441. hp:=caddnode.create(addn,genloadnode(pvarsym(srsym),tloadnode(left).symtable),
  442. genordinalconstnode(1,s32bitdef));
  443. if (left.resulttype^.deftype=arraydef) and
  444. (parraydef(left.resulttype)^.elesize<>1) then
  445. hp:=caddnode.create(muln,hp,genordinalconstnode(parraydef(left.resulttype)^.elesize,s32bitdef));
  446. firstpass(hp);
  447. result:=hp;
  448. end
  449. else
  450. begin
  451. if registers32<1 then
  452. registers32:=1;
  453. resulttype:=s32bitdef;
  454. location.loc:=LOC_REGISTER;
  455. end;
  456. end;
  457. in_typeof_x:
  458. begin
  459. set_varstate(left,false);
  460. if registers32<1 then
  461. registers32:=1;
  462. location.loc:=LOC_REGISTER;
  463. resulttype:=voidpointerdef;
  464. end;
  465. in_ord_x:
  466. begin
  467. set_varstate(left,true);
  468. if (left.nodetype=ordconstn) then
  469. begin
  470. hp:=genordinalconstnode(tordconstnode(left).value,s32bitdef);
  471. firstpass(hp);
  472. result:=hp;
  473. end
  474. else
  475. begin
  476. { otherwise you get a crash if you try ord on an expression containing }
  477. { an undeclared variable (JM) }
  478. if not assigned(left.resulttype) then
  479. exit;
  480. if (left.resulttype^.deftype=orddef) then
  481. if (porddef(left.resulttype)^.typ in [uchar,uwidechar,bool8bit]) then
  482. case porddef(left.resulttype)^.typ of
  483. uchar:
  484. begin
  485. hp:=gentypeconvnode(left,u8bitdef);
  486. left:=nil;
  487. include(hp.flags,nf_explizit);
  488. firstpass(hp);
  489. result:=hp;
  490. end;
  491. uwidechar:
  492. begin
  493. hp:=gentypeconvnode(left,u16bitdef);
  494. left:=nil;
  495. include(hp.flags,nf_explizit);
  496. firstpass(hp);
  497. result:=hp;
  498. end;
  499. bool8bit:
  500. begin
  501. hp:=gentypeconvnode(left,u8bitdef);
  502. left:=nil;
  503. ttypeconvnode(hp).convtype:=tc_bool_2_int;
  504. include(hp.flags,nf_explizit);
  505. firstpass(hp);
  506. result:=hp;
  507. end
  508. end
  509. { can this happen ? }
  510. else if (porddef(left.resulttype)^.typ=uvoid) then
  511. CGMessage(type_e_mismatch)
  512. else
  513. { all other orddef need no transformation }
  514. begin
  515. hp:=left;
  516. left:=nil;
  517. result:=hp;
  518. end
  519. else if (left.resulttype^.deftype=enumdef) then
  520. begin
  521. hp:=gentypeconvnode(left,s32bitdef);
  522. left:=nil;
  523. include(hp.flags,nf_explizit);
  524. firstpass(hp);
  525. result:=hp;
  526. end
  527. else
  528. begin
  529. { can anything else be ord() ?}
  530. CGMessage(type_e_mismatch);
  531. end;
  532. end;
  533. end;
  534. in_chr_byte:
  535. begin
  536. set_varstate(left,true);
  537. hp:=gentypeconvnode(left,cchardef);
  538. left:=nil;
  539. include(hp.flags,nf_explizit);
  540. firstpass(hp);
  541. result:=hp;
  542. end;
  543. in_length_string:
  544. begin
  545. set_varstate(left,true);
  546. if is_ansistring(left.resulttype) then
  547. resulttype:=s32bitdef
  548. else
  549. resulttype:=u8bitdef;
  550. { we don't need string conversations here }
  551. if (left.nodetype=typeconvn) and
  552. (ttypeconvnode(left).left.resulttype^.deftype=stringdef) then
  553. begin
  554. hp:=ttypeconvnode(left).left;
  555. ttypeconvnode(left).left:=nil;
  556. left.free;
  557. left:=hp;
  558. end;
  559. { check the type, must be string or char }
  560. if (left.resulttype^.deftype<>stringdef) and
  561. (not is_char(left.resulttype)) then
  562. CGMessage(type_e_mismatch);
  563. { evaluates length of constant strings direct }
  564. if (left.nodetype=stringconstn) then
  565. begin
  566. hp:=genordinalconstnode(tstringconstnode(left).len,s32bitdef);
  567. firstpass(hp);
  568. result:=hp;
  569. end
  570. { length of char is one allways }
  571. else if is_constcharnode(left) then
  572. begin
  573. hp:=genordinalconstnode(1,s32bitdef);
  574. firstpass(hp);
  575. result:=hp;
  576. end;
  577. end;
  578. in_typeinfo_x:
  579. begin
  580. resulttype:=voidpointerdef;
  581. location.loc:=LOC_REGISTER;
  582. registers32:=1;
  583. end;
  584. in_assigned_x:
  585. begin
  586. set_varstate(left,true);
  587. resulttype:=booldef;
  588. location.loc:=LOC_FLAGS;
  589. end;
  590. in_ofs_x :
  591. internalerror(2000101001);
  592. in_seg_x :
  593. begin
  594. set_varstate(left,false);
  595. hp:=genordinalconstnode(0,s32bitdef);
  596. firstpass(hp);
  597. result:=hp;
  598. end;
  599. in_pred_x,
  600. in_succ_x:
  601. begin
  602. resulttype:=left.resulttype;
  603. if is_64bitint(resulttype) then
  604. begin
  605. if (registers32<2) then
  606. registers32:=2
  607. end
  608. else
  609. begin
  610. if (registers32<1) then
  611. registers32:=1;
  612. end;
  613. location.loc:=LOC_REGISTER;
  614. set_varstate(left,true);
  615. if not is_ordinal(resulttype) then
  616. CGMessage(type_e_ordinal_expr_expected)
  617. else
  618. begin
  619. if (resulttype^.deftype=enumdef) and
  620. (penumdef(resulttype)^.has_jumps) then
  621. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible)
  622. else
  623. if left.nodetype=ordconstn then
  624. begin
  625. if inlinenumber=in_succ_x then
  626. hp:=genordinalconstnode(tordconstnode(left).value+1,left.resulttype)
  627. else
  628. hp:=genordinalconstnode(tordconstnode(left).value-1,left.resulttype);
  629. firstpass(hp);
  630. result:=hp;
  631. end;
  632. end;
  633. end;
  634. in_setlength_x:
  635. begin
  636. resulttype:=voiddef;
  637. if assigned(left) then
  638. begin
  639. ppn:=tcallparanode(left);
  640. counter:=0;
  641. { check type }
  642. while assigned(ppn.right) do
  643. begin
  644. ppn.left:=gentypeconvnode(ppn.left,s32bitdef);
  645. firstpass(ppn.left);
  646. if codegenerror then
  647. exit;
  648. inc(counter);
  649. ppn:=tcallparanode(ppn.right);
  650. end;
  651. firstpass(ppn.left);
  652. if codegenerror then
  653. exit;
  654. { last param must be var }
  655. valid_for_assign(ppn.left,false);
  656. set_varstate(ppn.left,false);
  657. { first param must be a string or dynamic array ...}
  658. if not((ppn.left.resulttype^.deftype=stringdef) or
  659. (is_dynamic_array(ppn.left.resulttype))) then
  660. CGMessage(type_e_mismatch);
  661. { only dynamic arrays accept more dimensions }
  662. if (counter>1) and
  663. (not(is_dynamic_array(left.resulttype))) then
  664. CGMessage(type_e_mismatch);
  665. { convert shortstrings to openstring parameters }
  666. { (generate the hightree) (JM) }
  667. if (ppn.left.resulttype^.deftype = stringdef) and
  668. (pstringdef(ppn.left.resulttype)^.string_typ =
  669. st_shortstring) then
  670. begin
  671. dummycoll:=tparaitem.create;
  672. dummycoll.paratyp:=vs_var;
  673. dummycoll.paratype.setdef(openshortstringdef);
  674. tcallparanode(ppn).firstcallparan(dummycoll,false);
  675. if codegenerror then
  676. exit;
  677. end;
  678. end
  679. else
  680. CGMessage(type_e_mismatch);
  681. end;
  682. in_finalize_x:
  683. begin
  684. resulttype:=voiddef;
  685. if assigned(left) and assigned(tcallparanode(left).left) then
  686. begin
  687. firstpass(tcallparanode(left).left);
  688. if codegenerror then
  689. exit;
  690. { first param must be var }
  691. valid_for_assign(tcallparanode(left).left,false);
  692. set_varstate(tcallparanode(left).left,true);
  693. { two parameters? }
  694. if assigned(tcallparanode(left).right) then
  695. begin
  696. { the last parameter must be a longint }
  697. tcallparanode(tcallparanode(left).right).left:=
  698. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,s32bitdef);
  699. firstpass(tcallparanode(tcallparanode(left).right).left);
  700. if codegenerror then
  701. exit;
  702. end;
  703. end
  704. else
  705. CGMessage(type_e_mismatch);
  706. end;
  707. in_inc_x,
  708. in_dec_x:
  709. begin
  710. resulttype:=voiddef;
  711. if assigned(left) then
  712. begin
  713. tcallparanode(left).firstcallparan(nil,true);
  714. set_varstate(left,true);
  715. if codegenerror then
  716. exit;
  717. { first param must be var }
  718. valid_for_assign(tcallparanode(left).left,false);
  719. { check type }
  720. if is_64bitint(left.resulttype) or
  721. { range/overflow checking doesn't work properly }
  722. { with the inc/dec code that's generated (JM) }
  723. ((left.resulttype^.deftype = orddef) and
  724. not(is_char(left.resulttype)) and
  725. not(is_boolean(left.resulttype)) and
  726. (aktlocalswitches *
  727. [cs_check_overflow,cs_check_range] <> [])) then
  728. { convert to simple add (JM) }
  729. begin
  730. { extra parameter? }
  731. if assigned(tcallparanode(left).right) then
  732. begin
  733. { Yes, use for add node }
  734. hpp := tcallparanode(tcallparanode(left).right).left;
  735. tcallparanode(tcallparanode(left).right).left := nil;
  736. if assigned(tcallparanode(tcallparanode(left).right).right) then
  737. CGMessage(cg_e_illegal_expression);
  738. end
  739. else
  740. { no, create constant 1 }
  741. hpp := cordconstnode.create(1,s32bitdef);
  742. { addition/substraction depending on inc/dec }
  743. if inlinenumber = in_inc_x then
  744. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  745. else
  746. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  747. { assign result of addition }
  748. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  749. tcallparanode(left).left := nil;
  750. { firstpass it }
  751. firstpass(hpp);
  752. { return new node }
  753. pass_1 := hpp;
  754. dec(parsing_para_level);
  755. exit;
  756. end;
  757. if (left.resulttype^.deftype in [enumdef,pointerdef]) or
  758. is_ordinal(left.resulttype) then
  759. begin
  760. { two paras ? }
  761. if assigned(tcallparanode(left).right) then
  762. begin
  763. { insert a type conversion }
  764. { the second param is always longint }
  765. tcallparanode(tcallparanode(left).right).left:=
  766. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,s32bitdef);
  767. { check the type conversion }
  768. firstpass(tcallparanode(tcallparanode(left).right).left);
  769. { need we an additional register ? }
  770. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  771. (tcallparanode(tcallparanode(left).right).left.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  772. (tcallparanode(tcallparanode(left).right).left.registers32<=1) then
  773. inc(registers32);
  774. { do we need an additional register to restore the first parameter? }
  775. if tcallparanode(tcallparanode(left).right).left.registers32>=registers32 then
  776. inc(registers32);
  777. if assigned(tcallparanode(tcallparanode(left).right).right) then
  778. CGMessage(cg_e_illegal_expression);
  779. end;
  780. end
  781. else
  782. CGMessage(type_e_ordinal_expr_expected);
  783. end
  784. else
  785. CGMessage(type_e_mismatch);
  786. end;
  787. in_read_x,
  788. in_readln_x,
  789. in_write_x,
  790. in_writeln_x :
  791. begin
  792. { needs a call }
  793. procinfo^.flags:=procinfo^.flags or pi_do_call;
  794. resulttype:=voiddef;
  795. { true, if readln needs an extra register }
  796. extra_register:=false;
  797. { we must know if it is a typed file or not }
  798. { but we must first do the firstpass for it }
  799. file_is_typed:=false;
  800. if assigned(left) then
  801. begin
  802. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  803. tcallparanode(left).firstcallparan(nil,true);
  804. set_varstate(left,iswrite);
  805. { now we can check }
  806. hp:=left;
  807. while assigned(tcallparanode(hp).right) do
  808. hp:=tcallparanode(hp).right;
  809. { if resulttype is not assigned, then automatically }
  810. { file is not typed. }
  811. if assigned(hp) and assigned(hp.resulttype) then
  812. Begin
  813. if (hp.resulttype^.deftype=filedef) then
  814. if (pfiledef(hp.resulttype)^.filetyp=ft_untyped) then
  815. begin
  816. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  817. CGMessage(type_e_no_readln_writeln_for_typed_file)
  818. else
  819. CGMessage(type_e_no_read_write_for_untyped_file);
  820. end
  821. else if (pfiledef(hp.resulttype)^.filetyp=ft_typed) then
  822. begin
  823. file_is_typed:=true;
  824. { test the type }
  825. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  826. CGMessage(type_e_no_readln_writeln_for_typed_file);
  827. hpp:=left;
  828. while (hpp<>hp) do
  829. begin
  830. if (tcallparanode(hpp).left.nodetype=typen) then
  831. CGMessage(type_e_cant_read_write_type);
  832. if not is_equal(hpp.resulttype,pfiledef(hp.resulttype)^.typedfiletype.def) then
  833. CGMessage(type_e_mismatch);
  834. { generate the high() value for the shortstring }
  835. if ((not iswrite) and is_shortstring(tcallparanode(hpp).left.resulttype)) or
  836. (is_chararray(tcallparanode(hpp).left.resulttype)) then
  837. tcallparanode(hpp).gen_high_tree(true);
  838. { read(ln) is call by reference (JM) }
  839. if not iswrite then
  840. make_not_regable(tcallparanode(hpp).left);
  841. hpp:=tcallparanode(hpp).right;
  842. end;
  843. end;
  844. end; { endif assigned(hp) }
  845. { insert type conversions for write(ln) }
  846. if (not file_is_typed) then
  847. begin
  848. hp:=left;
  849. while assigned(hp) do
  850. begin
  851. incrementregisterpushed($ff);
  852. if (tcallparanode(hp).left.nodetype=typen) then
  853. CGMessage(type_e_cant_read_write_type);
  854. if assigned(tcallparanode(hp).left.resulttype) then
  855. begin
  856. isreal:=false;
  857. { support writeln(procvar) }
  858. if (tcallparanode(hp).left.resulttype^.deftype=procvardef) then
  859. begin
  860. p1:=gencallnode(nil,nil);
  861. tcallnode(p1).right:=tcallparanode(hp).left;
  862. p1.resulttype:=pprocvardef(tcallparanode(hp).left.resulttype)^.rettype.def;
  863. firstpass(p1);
  864. tcallparanode(hp).left:=p1;
  865. end;
  866. case tcallparanode(hp).left.resulttype^.deftype of
  867. filedef :
  868. begin
  869. { only allowed as first parameter }
  870. if assigned(tcallparanode(hp).right) then
  871. CGMessage(type_e_cant_read_write_type);
  872. end;
  873. stringdef :
  874. begin
  875. { generate the high() value for the shortstring }
  876. if (not iswrite) and
  877. is_shortstring(tcallparanode(hp).left.resulttype) then
  878. tcallparanode(hp).gen_high_tree(true);
  879. end;
  880. pointerdef :
  881. begin
  882. if not is_pchar(tcallparanode(hp).left.resulttype) then
  883. CGMessage(type_e_cant_read_write_type);
  884. end;
  885. floatdef :
  886. begin
  887. isreal:=true;
  888. end;
  889. orddef :
  890. begin
  891. case porddef(tcallparanode(hp).left.resulttype)^.typ of
  892. uchar,
  893. u32bit,s32bit,
  894. u64bit,s64bit:
  895. ;
  896. u8bit,s8bit,
  897. u16bit,s16bit :
  898. if iswrite then
  899. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,s32bitdef);
  900. bool8bit,
  901. bool16bit,
  902. bool32bit :
  903. if iswrite then
  904. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,booldef)
  905. else
  906. CGMessage(type_e_cant_read_write_type);
  907. else
  908. CGMessage(type_e_cant_read_write_type);
  909. end;
  910. if not(iswrite) and
  911. not(is_64bitint(tcallparanode(hp).left.resulttype)) then
  912. extra_register:=true;
  913. end;
  914. arraydef :
  915. begin
  916. if is_chararray(tcallparanode(hp).left.resulttype) then
  917. tcallparanode(hp).gen_high_tree(true)
  918. else
  919. CGMessage(type_e_cant_read_write_type);
  920. end;
  921. else
  922. CGMessage(type_e_cant_read_write_type);
  923. end;
  924. { some format options ? }
  925. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  926. begin
  927. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  928. begin
  929. frac_para:=hp;
  930. length_para:=tcallparanode(hp).right;
  931. hp:=tcallparanode(hp).right;
  932. hpp:=tcallparanode(hp).right;
  933. end
  934. else
  935. begin
  936. length_para:=hp;
  937. frac_para:=nil;
  938. hpp:=tcallparanode(hp).right;
  939. end;
  940. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  941. if assigned(tcallparanode(hpp).left.resulttype) then
  942. isreal:=(tcallparanode(hpp).left.resulttype^.deftype=floatdef)
  943. else exit;
  944. if (not is_integer(tcallparanode(length_para).left.resulttype)) then
  945. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype^.typename)
  946. else
  947. tcallparanode(length_para).left:=gentypeconvnode(tcallparanode(length_para).left,s32bitdef);
  948. if assigned(frac_para) then
  949. begin
  950. if isreal then
  951. begin
  952. if (not is_integer(tcallparanode(frac_para).left.resulttype)) then
  953. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype^.typename)
  954. else
  955. tcallparanode(frac_para).left:=gentypeconvnode(tcallparanode(frac_para).left,s32bitdef);
  956. end
  957. else
  958. CGMessage(parser_e_illegal_colon_qualifier);
  959. end;
  960. { do the checking for the colon'd arg }
  961. hp:=length_para;
  962. end;
  963. end;
  964. hp:=tcallparanode(hp).right;
  965. end;
  966. end;
  967. { pass all parameters again for the typeconversions }
  968. if codegenerror then
  969. exit;
  970. tcallparanode(left).firstcallparan(nil,true);
  971. set_varstate(left,true);
  972. { calc registers }
  973. left_max;
  974. if extra_register then
  975. inc(registers32);
  976. end;
  977. end;
  978. in_settextbuf_file_x :
  979. begin
  980. { warning here left is the callparannode
  981. not the argument directly }
  982. { left.left is text var }
  983. { left.right.left is the buffer var }
  984. { firstcallparan(left,nil);
  985. already done in firstcalln }
  986. { now we know the type of buffer }
  987. getsymonlyin(systemunit,'SETTEXTBUF');
  988. hp:=gencallnode(pprocsym(srsym),systemunit);
  989. tcallnode(hp).left:=gencallparanode(
  990. genordinalconstnode(tcallparanode(left).left.resulttype^.size,s32bitdef),left);
  991. left:=nil;
  992. firstpass(hp);
  993. result:=hp;
  994. end;
  995. { the firstpass of the arg has been done in firstcalln ? }
  996. in_reset_typedfile,
  997. in_rewrite_typedfile :
  998. begin
  999. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1000. firstpass(left);
  1001. set_varstate(left,true);
  1002. resulttype:=voiddef;
  1003. end;
  1004. in_str_x_string :
  1005. begin
  1006. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1007. resulttype:=voiddef;
  1008. { check the amount of parameters }
  1009. if not(assigned(left)) or
  1010. not(assigned(tcallparanode(left).right)) then
  1011. begin
  1012. CGMessage(parser_e_wrong_parameter_size);
  1013. exit;
  1014. end;
  1015. { first pass just the string for first local use }
  1016. hp:=tcallparanode(left).right;
  1017. tcallparanode(left).right:=nil;
  1018. tcallparanode(left).firstcallparan(nil,true);
  1019. set_varstate(left,false);
  1020. { remove warning when result is passed }
  1021. set_funcret_is_valid(tcallparanode(left).left);
  1022. tcallparanode(left).right:=hp;
  1023. tcallparanode(tcallparanode(left).right).firstcallparan(nil,true);
  1024. set_varstate(tcallparanode(left).right,true);
  1025. hp:=left;
  1026. { valid string ? }
  1027. if not assigned(hp) or
  1028. (tcallparanode(hp).left.resulttype^.deftype<>stringdef) or
  1029. (tcallparanode(hp).right=nil) then
  1030. CGMessage(cg_e_illegal_expression);
  1031. { we need a var parameter }
  1032. valid_for_assign(tcallparanode(hp).left,false);
  1033. { generate the high() value for the shortstring }
  1034. if is_shortstring(tcallparanode(hp).left.resulttype) then
  1035. tcallparanode(hp).gen_high_tree(true);
  1036. { !!!! check length of string }
  1037. while assigned(tcallparanode(hp).right) do
  1038. hp:=tcallparanode(hp).right;
  1039. if not assigned(tcallparanode(hp).resulttype) then
  1040. exit;
  1041. { check and convert the first param }
  1042. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  1043. not assigned(hp.resulttype) then
  1044. CGMessage(cg_e_illegal_expression);
  1045. isreal:=false;
  1046. case hp.resulttype^.deftype of
  1047. orddef :
  1048. begin
  1049. case porddef(tcallparanode(hp).left.resulttype)^.typ of
  1050. u32bit,s32bit,
  1051. s64bit,u64bit:
  1052. ;
  1053. u8bit,s8bit,
  1054. u16bit,s16bit:
  1055. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,s32bitdef);
  1056. else
  1057. CGMessage(type_e_integer_or_real_expr_expected);
  1058. end;
  1059. end;
  1060. floatdef :
  1061. begin
  1062. isreal:=true;
  1063. end;
  1064. else
  1065. CGMessage(type_e_integer_or_real_expr_expected);
  1066. end;
  1067. { some format options ? }
  1068. hpp:=tcallparanode(left).right;
  1069. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1070. begin
  1071. firstpass(tcallparanode(hpp).left);
  1072. set_varstate(tcallparanode(hpp).left,true);
  1073. if (not is_integer(tcallparanode(hpp).left.resulttype)) then
  1074. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype^.typename)
  1075. else
  1076. tcallparanode(hpp).left:=gentypeconvnode(tcallparanode(hpp).left,s32bitdef);
  1077. hpp:=tcallparanode(hpp).right;
  1078. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1079. begin
  1080. if isreal then
  1081. begin
  1082. if (not is_integer(tcallparanode(hpp).left.resulttype)) then
  1083. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype^.typename)
  1084. else
  1085. begin
  1086. firstpass(tcallparanode(hpp).left);
  1087. set_varstate(tcallparanode(hpp).left,true);
  1088. tcallparanode(hpp).left:=gentypeconvnode(tcallparanode(hpp).left,s32bitdef);
  1089. end;
  1090. end
  1091. else
  1092. CGMessage(parser_e_illegal_colon_qualifier);
  1093. end;
  1094. end;
  1095. { pass all parameters again for the typeconversions }
  1096. if codegenerror then
  1097. exit;
  1098. tcallparanode(left).firstcallparan(nil,true);
  1099. { calc registers }
  1100. left_max;
  1101. end;
  1102. in_val_x :
  1103. begin
  1104. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1105. resulttype:=voiddef;
  1106. { check the amount of parameters }
  1107. if not(assigned(left)) or
  1108. not(assigned(tcallparanode(left).right)) then
  1109. begin
  1110. CGMessage(parser_e_wrong_parameter_size);
  1111. exit;
  1112. end;
  1113. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1114. {there is a "code" parameter}
  1115. Begin
  1116. { first pass just the code parameter for first local use}
  1117. hp := tcallparanode(left).right;
  1118. tcallparanode(left).right := nil;
  1119. make_not_regable(tcallparanode(left).left);
  1120. tcallparanode(left).firstcallparan(nil,true);
  1121. set_varstate(left,false);
  1122. if codegenerror then exit;
  1123. tcallparanode(left).right := hp;
  1124. {code has to be a var parameter}
  1125. if valid_for_assign(tcallparanode(left).left,false) then
  1126. begin
  1127. if (tcallparanode(left).left.resulttype^.deftype <> orddef) or
  1128. not(porddef(tcallparanode(left).left.resulttype)^.typ in
  1129. [u16bit,s16bit,u32bit,s32bit]) then
  1130. CGMessage(type_e_mismatch);
  1131. end;
  1132. hpp := tcallparanode(left).right
  1133. End
  1134. Else hpp := left;
  1135. {now hpp = the destination value tree}
  1136. { first pass just the destination parameter for first local use}
  1137. hp:=tcallparanode(hpp).right;
  1138. tcallparanode(hpp).right:=nil;
  1139. {hpp = destination}
  1140. make_not_regable(tcallparanode(hpp).left);
  1141. tcallparanode(hpp).firstcallparan(nil,true);
  1142. set_varstate(hpp,false);
  1143. if codegenerror then
  1144. exit;
  1145. { remove warning when result is passed }
  1146. set_funcret_is_valid(tcallparanode(hpp).left);
  1147. tcallparanode(hpp).right := hp;
  1148. if valid_for_assign(tcallparanode(hpp).left,false) then
  1149. begin
  1150. If Not((tcallparanode(hpp).left.resulttype^.deftype = floatdef) or
  1151. ((tcallparanode(hpp).left.resulttype^.deftype = orddef) And
  1152. (POrdDef(tcallparanode(hpp).left.resulttype)^.typ in
  1153. [u32bit,s32bit,
  1154. u8bit,s8bit,u16bit,s16bit,s64bit,u64bit]))) Then
  1155. CGMessage(type_e_mismatch);
  1156. end;
  1157. {hp = source (String)}
  1158. { count_ref := false; WHY ?? }
  1159. tcallparanode(hp).firstcallparan(nil,true);
  1160. set_varstate(hp,true);
  1161. if codegenerror then
  1162. exit;
  1163. { if not a stringdef then insert a type conv which
  1164. does the other type checking }
  1165. If (tcallparanode(hp).left.resulttype^.deftype<>stringdef) then
  1166. begin
  1167. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,cshortstringdef);
  1168. firstpass(tcallparanode(hp).left);
  1169. end;
  1170. { calc registers }
  1171. left_max;
  1172. { val doesn't calculate the registers really }
  1173. { correct, we need one register extra (FK) }
  1174. if is_64bitint(tcallparanode(hpp).left.resulttype) then
  1175. inc(registers32,2)
  1176. else
  1177. inc(registers32,1);
  1178. end;
  1179. in_include_x_y,
  1180. in_exclude_x_y:
  1181. begin
  1182. resulttype:=voiddef;
  1183. if assigned(left) then
  1184. begin
  1185. tcallparanode(left).firstcallparan(nil,true);
  1186. set_varstate(left,true);
  1187. registers32:=left.registers32;
  1188. registersfpu:=left.registersfpu;
  1189. {$ifdef SUPPORT_MMX}
  1190. registersmmx:=left.registersmmx;
  1191. {$endif SUPPORT_MMX}
  1192. { remove warning when result is passed }
  1193. set_funcret_is_valid(tcallparanode(left).left);
  1194. { first param must be var }
  1195. valid_for_assign(tcallparanode(left).left,false);
  1196. { check type }
  1197. if assigned(left.resulttype) and
  1198. (left.resulttype^.deftype=setdef) then
  1199. begin
  1200. { two paras ? }
  1201. if assigned(tcallparanode(left).right) then
  1202. begin
  1203. { insert a type conversion }
  1204. { to the type of the set elements }
  1205. tcallparanode(tcallparanode(left).right).left:=gentypeconvnode(
  1206. tcallparanode(tcallparanode(left).right).left,
  1207. psetdef(left.resulttype)^.elementtype.def);
  1208. { check the type conversion }
  1209. firstpass(tcallparanode(tcallparanode(left).right).left);
  1210. { only three parameters are allowed }
  1211. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1212. CGMessage(cg_e_illegal_expression);
  1213. end;
  1214. end
  1215. else
  1216. CGMessage(type_e_mismatch);
  1217. end
  1218. else
  1219. CGMessage(type_e_mismatch);
  1220. end;
  1221. in_low_x,
  1222. in_high_x:
  1223. begin
  1224. set_varstate(left,false);
  1225. { this fixes tests\webtbs\tbug879.pp (FK)
  1226. if left.nodetype in [typen,loadn,subscriptn] then
  1227. begin
  1228. }
  1229. case left.resulttype^.deftype of
  1230. orddef,enumdef:
  1231. begin
  1232. hp:=do_lowhigh(left.resulttype);
  1233. firstpass(hp);
  1234. result:=hp;
  1235. end;
  1236. setdef:
  1237. begin
  1238. hp:=do_lowhigh(Psetdef(left.resulttype)^.elementtype.def);
  1239. firstpass(hp);
  1240. result:=hp;
  1241. end;
  1242. arraydef:
  1243. begin
  1244. if inlinenumber=in_low_x then
  1245. begin
  1246. hp:=genordinalconstnode(Parraydef(left.resulttype)^.lowrange,
  1247. Parraydef(left.resulttype)^.rangetype.def);
  1248. firstpass(hp);
  1249. result:=hp;
  1250. end
  1251. else
  1252. begin
  1253. if is_open_array(left.resulttype) or
  1254. is_array_of_const(left.resulttype) then
  1255. begin
  1256. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  1257. hp:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
  1258. firstpass(hp);
  1259. result:=hp;
  1260. end
  1261. else
  1262. begin
  1263. hp:=genordinalconstnode(Parraydef(left.resulttype)^.highrange,
  1264. Parraydef(left.resulttype)^.rangetype.def);
  1265. firstpass(hp);
  1266. result:=hp;
  1267. end;
  1268. end;
  1269. end;
  1270. stringdef:
  1271. begin
  1272. if inlinenumber=in_low_x then
  1273. begin
  1274. hp:=genordinalconstnode(0,u8bitdef);
  1275. firstpass(hp);
  1276. result:=hp;
  1277. end
  1278. else
  1279. begin
  1280. if is_open_string(left.resulttype) then
  1281. begin
  1282. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  1283. hp:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
  1284. firstpass(hp);
  1285. result:=hp;
  1286. end
  1287. else
  1288. begin
  1289. hp:=genordinalconstnode(Pstringdef(left.resulttype)^.len,u8bitdef);
  1290. firstpass(hp);
  1291. result:=hp;
  1292. end;
  1293. end;
  1294. end;
  1295. else
  1296. CGMessage(type_e_mismatch);
  1297. end;
  1298. {
  1299. end
  1300. else
  1301. CGMessage(type_e_varid_or_typeid_expected);
  1302. }
  1303. end;
  1304. in_cos_extended:
  1305. begin
  1306. if left.nodetype in [ordconstn,realconstn] then
  1307. setconstrealvalue(cos(getconstrealvalue))
  1308. else
  1309. handleextendedfunction;
  1310. end;
  1311. in_sin_extended:
  1312. begin
  1313. if left.nodetype in [ordconstn,realconstn] then
  1314. setconstrealvalue(sin(getconstrealvalue))
  1315. else
  1316. handleextendedfunction;
  1317. end;
  1318. in_arctan_extended:
  1319. begin
  1320. if left.nodetype in [ordconstn,realconstn] then
  1321. setconstrealvalue(arctan(getconstrealvalue))
  1322. else
  1323. handleextendedfunction;
  1324. end;
  1325. in_pi:
  1326. if block_type=bt_const then
  1327. setconstrealvalue(pi)
  1328. else
  1329. begin
  1330. location.loc:=LOC_FPU;
  1331. resulttype:=s80floatdef;
  1332. end;
  1333. in_abs_extended:
  1334. begin
  1335. if left.nodetype in [ordconstn,realconstn] then
  1336. setconstrealvalue(abs(getconstrealvalue))
  1337. else
  1338. handleextendedfunction;
  1339. end;
  1340. in_sqr_extended:
  1341. begin
  1342. if left.nodetype in [ordconstn,realconstn] then
  1343. setconstrealvalue(sqr(getconstrealvalue))
  1344. else
  1345. handleextendedfunction;
  1346. end;
  1347. in_sqrt_extended:
  1348. begin
  1349. if left.nodetype in [ordconstn,realconstn] then
  1350. begin
  1351. vr:=getconstrealvalue;
  1352. if vr<0.0 then
  1353. begin
  1354. CGMessage(type_e_wrong_math_argument);
  1355. setconstrealvalue(0);
  1356. end
  1357. else
  1358. setconstrealvalue(sqrt(vr));
  1359. end
  1360. else
  1361. handleextendedfunction;
  1362. end;
  1363. in_ln_extended:
  1364. begin
  1365. if left.nodetype in [ordconstn,realconstn] then
  1366. begin
  1367. vr:=getconstrealvalue;
  1368. if vr<=0.0 then
  1369. begin
  1370. CGMessage(type_e_wrong_math_argument);
  1371. setconstrealvalue(0);
  1372. end
  1373. else
  1374. setconstrealvalue(ln(vr));
  1375. end
  1376. else
  1377. handleextendedfunction;
  1378. end;
  1379. {$ifdef SUPPORT_MMX}
  1380. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1381. begin
  1382. end;
  1383. {$endif SUPPORT_MMX}
  1384. in_assert_x_y :
  1385. begin
  1386. resulttype:=voiddef;
  1387. if assigned(left) then
  1388. begin
  1389. tcallparanode(left).firstcallparan(nil,true);
  1390. set_varstate(left,true);
  1391. registers32:=left.registers32;
  1392. registersfpu:=left.registersfpu;
  1393. {$ifdef SUPPORT_MMX}
  1394. registersmmx:=left.registersmmx;
  1395. {$endif SUPPORT_MMX}
  1396. { check type }
  1397. if is_boolean(left.resulttype) then
  1398. begin
  1399. { must always be a string }
  1400. tcallparanode(tcallparanode(left).right).left:=
  1401. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,cshortstringdef);
  1402. firstpass(tcallparanode(tcallparanode(left).right).left);
  1403. end
  1404. else
  1405. CGMessage(type_e_mismatch);
  1406. end
  1407. else
  1408. CGMessage(type_e_mismatch);
  1409. { We've checked the whole statement for correctness, now we
  1410. can remove it if assertions are off }
  1411. if not(cs_do_assertion in aktlocalswitches) then
  1412. { we need a valid node, so insert a nothingn }
  1413. result:=cnothingnode.create;
  1414. end;
  1415. else
  1416. internalerror(8);
  1417. end;
  1418. end;
  1419. { generate an error if no resulttype is set }
  1420. if not assigned(resulttype) then
  1421. resulttype:=generrordef;
  1422. { ... also if the node will be replaced }
  1423. if assigned(result) and
  1424. (not assigned(result.resulttype)) then
  1425. result.resulttype:=generrordef;
  1426. dec(parsing_para_level);
  1427. end;
  1428. {$ifdef fpc}
  1429. {$maxfpuregisters default}
  1430. {$endif fpc}
  1431. function tinlinenode.docompare(p: tnode): boolean;
  1432. begin
  1433. docompare :=
  1434. inherited docompare(p) and
  1435. (inlinenumber = tinlinenode(p).inlinenumber);
  1436. end;
  1437. begin
  1438. cinlinenode:=tinlinenode;
  1439. end.
  1440. {
  1441. $Log$
  1442. Revision 1.27 2001-02-22 11:24:40 jonas
  1443. * fixed bug in previous fix (hopped over revision 1.26 because that one
  1444. also removed the fix for high(cardinal))
  1445. Revision 1.26 2001/02/21 20:50:59 peter
  1446. * fix to compile again, but high(cardinal) with $R+ still fails!
  1447. Revision 1.25 2001/02/21 12:57:46 jonas
  1448. * fixed high/low for cardinal, int64 and qword
  1449. Revision 1.24 2001/01/06 19:54:11 peter
  1450. * merged fix for 1310
  1451. Revision 1.23 2001/01/06 18:28:39 peter
  1452. * fixed wrong notes about locals
  1453. Revision 1.22 2000/12/31 11:14:10 jonas
  1454. + implemented/fixed docompare() mathods for all nodes (not tested)
  1455. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  1456. and constant strings/chars together
  1457. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  1458. when adding
  1459. Revision 1.21 2000/12/25 00:07:26 peter
  1460. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1461. tlinkedlist objects)
  1462. Revision 1.20 2000/12/17 14:35:41 peter
  1463. * fixed crash with val()
  1464. Revision 1.19 2000/11/29 00:30:33 florian
  1465. * unused units removed from uses clause
  1466. * some changes for widestrings
  1467. Revision 1.18 2000/11/12 15:27:22 jonas
  1468. * also don't do conversion for chars/booleans (hopefully final change :/)
  1469. Revision 1.17 2000/11/11 21:08:13 jonas
  1470. * don't do inc/dec to add/sub conversion for enums
  1471. Revision 1.16 2000/11/11 16:18:35 peter
  1472. * ptr returns farpointer
  1473. Revision 1.15 2000/11/11 15:59:07 jonas
  1474. * convert inc/dec to add/sub when range/overflow checking is on
  1475. Revision 1.14 2000/11/09 17:46:54 florian
  1476. * System.TypeInfo fixed
  1477. + System.Finalize implemented
  1478. + some new keywords for interface support added
  1479. Revision 1.13 2000/11/04 16:48:32 florian
  1480. * innr.inc renamed to make compiler compilation easier because the rtl contains
  1481. a file of the same name
  1482. Revision 1.12 2000/10/31 22:02:48 peter
  1483. * symtable splitted, no real code changes
  1484. Revision 1.11 2000/10/26 14:15:06 jonas
  1485. * fixed setlength for shortstrings
  1486. Revision 1.10 2000/10/21 18:16:11 florian
  1487. * a lot of changes:
  1488. - basic dyn. array support
  1489. - basic C++ support
  1490. - some work for interfaces done
  1491. ....
  1492. Revision 1.9 2000/10/15 08:38:46 jonas
  1493. * added missing getcopy for previous addition
  1494. Revision 1.8 2000/10/14 18:27:53 jonas
  1495. * merged fix for inc/dec on 64bit types from tcinl
  1496. Revision 1.7 2000/10/14 10:14:50 peter
  1497. * moehrendorf oct 2000 rewrite
  1498. Revision 1.6 2000/10/01 19:48:24 peter
  1499. * lot of compile updates for cg11
  1500. Revision 1.5 2000/09/28 19:49:52 florian
  1501. *** empty log message ***
  1502. Revision 1.4 2000/09/28 16:34:47 florian
  1503. *** empty log message ***
  1504. Revision 1.3 2000/09/27 21:33:22 florian
  1505. * finally nadd.pas compiles
  1506. Revision 1.2 2000/09/27 20:25:44 florian
  1507. * more stuff fixed
  1508. Revision 1.1 2000/09/26 14:59:34 florian
  1509. * more conversion work done
  1510. }