ninl.pas 69 KB

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