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