ninl.pas 67 KB

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