ninl.pas 63 KB

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