ninl.pas 66 KB

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