ninl.pas 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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 16) or vl,voidpointerdef);
  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_inc_x,
  664. in_dec_x:
  665. begin
  666. resulttype:=voiddef;
  667. if assigned(left) then
  668. begin
  669. tcallparanode(left).firstcallparan(nil,true);
  670. set_varstate(left,true);
  671. if codegenerror then
  672. exit;
  673. { first param must be var }
  674. valid_for_assign(tcallparanode(left).left,false);
  675. { check type }
  676. if is_64bitint(left.resulttype) then
  677. { convert to simple add for 64bit (JM) }
  678. begin
  679. { extra parameter? }
  680. if assigned(tcallparanode(left).right) then
  681. begin
  682. { Yes, use for add node }
  683. hpp := tcallparanode(tcallparanode(left).right).left;
  684. tcallparanode(tcallparanode(left).right).left := nil;
  685. if assigned(tcallparanode(tcallparanode(left).right).right) then
  686. CGMessage(cg_e_illegal_expression);
  687. end
  688. else
  689. { no, create constant 1 }
  690. hpp := cordconstnode.create(1,s32bitdef);
  691. { addition/substraction depending on inc/dec }
  692. if inlinenumber = in_inc_x then
  693. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  694. else
  695. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  696. { assign result of addition }
  697. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  698. tcallparanode(left).left := nil;
  699. { firstpass it }
  700. firstpass(hpp);
  701. { return new node }
  702. pass_1 := hpp;
  703. dec(parsing_para_level);
  704. exit;
  705. end;
  706. if (left.resulttype^.deftype in [enumdef,pointerdef]) or
  707. is_ordinal(left.resulttype) then
  708. begin
  709. { two paras ? }
  710. if assigned(tcallparanode(left).right) then
  711. begin
  712. { insert a type conversion }
  713. { the second param is always longint }
  714. tcallparanode(tcallparanode(left).right).left:=
  715. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,s32bitdef);
  716. { check the type conversion }
  717. firstpass(tcallparanode(tcallparanode(left).right).left);
  718. { need we an additional register ? }
  719. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  720. (tcallparanode(tcallparanode(left).right).left.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  721. (tcallparanode(tcallparanode(left).right).left.registers32<=1) then
  722. inc(registers32);
  723. { do we need an additional register to restore the first parameter? }
  724. if tcallparanode(tcallparanode(left).right).left.registers32>=registers32 then
  725. inc(registers32);
  726. if assigned(tcallparanode(tcallparanode(left).right).right) then
  727. CGMessage(cg_e_illegal_expression);
  728. end;
  729. end
  730. else
  731. CGMessage(type_e_ordinal_expr_expected);
  732. end
  733. else
  734. CGMessage(type_e_mismatch);
  735. end;
  736. in_read_x,
  737. in_readln_x,
  738. in_write_x,
  739. in_writeln_x :
  740. begin
  741. { needs a call }
  742. procinfo^.flags:=procinfo^.flags or pi_do_call;
  743. resulttype:=voiddef;
  744. { true, if readln needs an extra register }
  745. extra_register:=false;
  746. { we must know if it is a typed file or not }
  747. { but we must first do the firstpass for it }
  748. file_is_typed:=false;
  749. if assigned(left) then
  750. begin
  751. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  752. tcallparanode(left).firstcallparan(nil,true);
  753. set_varstate(left,iswrite);
  754. { now we can check }
  755. hp:=left;
  756. while assigned(tcallparanode(hp).right) do
  757. hp:=tcallparanode(hp).right;
  758. { if resulttype is not assigned, then automatically }
  759. { file is not typed. }
  760. if assigned(hp) and assigned(hp.resulttype) then
  761. Begin
  762. if (hp.resulttype^.deftype=filedef) then
  763. if (pfiledef(hp.resulttype)^.filetyp=ft_untyped) then
  764. begin
  765. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  766. CGMessage(type_e_no_readln_writeln_for_typed_file)
  767. else
  768. CGMessage(type_e_no_read_write_for_untyped_file);
  769. end
  770. else if (pfiledef(hp.resulttype)^.filetyp=ft_typed) then
  771. begin
  772. file_is_typed:=true;
  773. { test the type }
  774. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  775. CGMessage(type_e_no_readln_writeln_for_typed_file);
  776. hpp:=left;
  777. while (hpp<>hp) do
  778. begin
  779. if (tcallparanode(hpp).left.nodetype=typen) then
  780. CGMessage(type_e_cant_read_write_type);
  781. if not is_equal(hpp.resulttype,pfiledef(hp.resulttype)^.typedfiletype.def) then
  782. CGMessage(type_e_mismatch);
  783. { generate the high() value for the shortstring }
  784. if ((not iswrite) and is_shortstring(tcallparanode(hpp).left.resulttype)) or
  785. (is_chararray(tcallparanode(hpp).left.resulttype)) then
  786. tcallparanode(hpp).gen_high_tree(true);
  787. { read(ln) is call by reference (JM) }
  788. if not iswrite then
  789. make_not_regable(tcallparanode(hpp).left);
  790. hpp:=tcallparanode(hpp).right;
  791. end;
  792. end;
  793. end; { endif assigned(hp) }
  794. { insert type conversions for write(ln) }
  795. if (not file_is_typed) then
  796. begin
  797. hp:=left;
  798. while assigned(hp) do
  799. begin
  800. incrementregisterpushed($ff);
  801. if (tcallparanode(hp).left.nodetype=typen) then
  802. CGMessage(type_e_cant_read_write_type);
  803. if assigned(tcallparanode(hp).left.resulttype) then
  804. begin
  805. isreal:=false;
  806. { support writeln(procvar) }
  807. if (tcallparanode(hp).left.resulttype^.deftype=procvardef) then
  808. begin
  809. p1:=gencallnode(nil,nil);
  810. tcallnode(p1).right:=tcallparanode(hp).left;
  811. p1.resulttype:=pprocvardef(tcallparanode(hp).left.resulttype)^.rettype.def;
  812. firstpass(p1);
  813. tcallparanode(hp).left:=p1;
  814. end;
  815. case tcallparanode(hp).left.resulttype^.deftype of
  816. filedef :
  817. begin
  818. { only allowed as first parameter }
  819. if assigned(tcallparanode(hp).right) then
  820. CGMessage(type_e_cant_read_write_type);
  821. end;
  822. stringdef :
  823. begin
  824. { generate the high() value for the shortstring }
  825. if (not iswrite) and
  826. is_shortstring(tcallparanode(hp).left.resulttype) then
  827. tcallparanode(hp).gen_high_tree(true);
  828. end;
  829. pointerdef :
  830. begin
  831. if not is_pchar(tcallparanode(hp).left.resulttype) then
  832. CGMessage(type_e_cant_read_write_type);
  833. end;
  834. floatdef :
  835. begin
  836. isreal:=true;
  837. end;
  838. orddef :
  839. begin
  840. case porddef(tcallparanode(hp).left.resulttype)^.typ of
  841. uchar,
  842. u32bit,s32bit,
  843. u64bit,s64bit:
  844. ;
  845. u8bit,s8bit,
  846. u16bit,s16bit :
  847. if iswrite then
  848. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,s32bitdef);
  849. bool8bit,
  850. bool16bit,
  851. bool32bit :
  852. if iswrite then
  853. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,booldef)
  854. else
  855. CGMessage(type_e_cant_read_write_type);
  856. else
  857. CGMessage(type_e_cant_read_write_type);
  858. end;
  859. if not(iswrite) and
  860. not(is_64bitint(tcallparanode(hp).left.resulttype)) then
  861. extra_register:=true;
  862. end;
  863. arraydef :
  864. begin
  865. if is_chararray(tcallparanode(hp).left.resulttype) then
  866. tcallparanode(hp).gen_high_tree(true)
  867. else
  868. CGMessage(type_e_cant_read_write_type);
  869. end;
  870. else
  871. CGMessage(type_e_cant_read_write_type);
  872. end;
  873. { some format options ? }
  874. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  875. begin
  876. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  877. begin
  878. frac_para:=hp;
  879. length_para:=tcallparanode(hp).right;
  880. hp:=tcallparanode(hp).right;
  881. hpp:=tcallparanode(hp).right;
  882. end
  883. else
  884. begin
  885. length_para:=hp;
  886. frac_para:=nil;
  887. hpp:=tcallparanode(hp).right;
  888. end;
  889. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  890. if assigned(tcallparanode(hpp).left.resulttype) then
  891. isreal:=(tcallparanode(hpp).left.resulttype^.deftype=floatdef)
  892. else exit;
  893. if (not is_integer(tcallparanode(length_para).left.resulttype)) then
  894. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype^.typename)
  895. else
  896. tcallparanode(length_para).left:=gentypeconvnode(tcallparanode(length_para).left,s32bitdef);
  897. if assigned(frac_para) then
  898. begin
  899. if isreal then
  900. begin
  901. if (not is_integer(tcallparanode(frac_para).left.resulttype)) then
  902. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype^.typename)
  903. else
  904. tcallparanode(frac_para).left:=gentypeconvnode(tcallparanode(frac_para).left,s32bitdef);
  905. end
  906. else
  907. CGMessage(parser_e_illegal_colon_qualifier);
  908. end;
  909. { do the checking for the colon'd arg }
  910. hp:=length_para;
  911. end;
  912. end;
  913. hp:=tcallparanode(hp).right;
  914. end;
  915. end;
  916. { pass all parameters again for the typeconversions }
  917. if codegenerror then
  918. exit;
  919. tcallparanode(left).firstcallparan(nil,true);
  920. set_varstate(left,true);
  921. { calc registers }
  922. left_max;
  923. if extra_register then
  924. inc(registers32);
  925. end;
  926. end;
  927. in_settextbuf_file_x :
  928. begin
  929. { warning here left is the callparannode
  930. not the argument directly }
  931. { left.left is text var }
  932. { left.right.left is the buffer var }
  933. { firstcallparan(left,nil);
  934. already done in firstcalln }
  935. { now we know the type of buffer }
  936. getsymonlyin(systemunit,'SETTEXTBUF');
  937. hp:=gencallnode(pprocsym(srsym),systemunit);
  938. tcallnode(hp).left:=gencallparanode(
  939. genordinalconstnode(tcallparanode(left).left.resulttype^.size,s32bitdef),left);
  940. left:=nil;
  941. firstpass(hp);
  942. result:=hp;
  943. end;
  944. { the firstpass of the arg has been done in firstcalln ? }
  945. in_reset_typedfile,
  946. in_rewrite_typedfile :
  947. begin
  948. procinfo^.flags:=procinfo^.flags or pi_do_call;
  949. firstpass(left);
  950. set_varstate(left,true);
  951. resulttype:=voiddef;
  952. end;
  953. in_str_x_string :
  954. begin
  955. procinfo^.flags:=procinfo^.flags or pi_do_call;
  956. resulttype:=voiddef;
  957. { check the amount of parameters }
  958. if not(assigned(left)) or
  959. not(assigned(tcallparanode(left).right)) then
  960. begin
  961. CGMessage(parser_e_wrong_parameter_size);
  962. exit;
  963. end;
  964. { first pass just the string for first local use }
  965. hp:=tcallparanode(left).right;
  966. tcallparanode(left).right:=nil;
  967. tcallparanode(left).firstcallparan(nil,true);
  968. set_varstate(left,false);
  969. { remove warning when result is passed }
  970. set_funcret_is_valid(tcallparanode(left).left);
  971. tcallparanode(left).right:=hp;
  972. tcallparanode(tcallparanode(left).right).firstcallparan(nil,true);
  973. set_varstate(tcallparanode(left).right,true);
  974. hp:=left;
  975. { valid string ? }
  976. if not assigned(hp) or
  977. (tcallparanode(hp).left.resulttype^.deftype<>stringdef) or
  978. (tcallparanode(hp).right=nil) then
  979. CGMessage(cg_e_illegal_expression);
  980. { we need a var parameter }
  981. valid_for_assign(tcallparanode(hp).left,false);
  982. { generate the high() value for the shortstring }
  983. if is_shortstring(tcallparanode(hp).left.resulttype) then
  984. tcallparanode(hp).gen_high_tree(true);
  985. { !!!! check length of string }
  986. while assigned(tcallparanode(hp).right) do
  987. hp:=tcallparanode(hp).right;
  988. if not assigned(tcallparanode(hp).resulttype) then
  989. exit;
  990. { check and convert the first param }
  991. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  992. not assigned(hp.resulttype) then
  993. CGMessage(cg_e_illegal_expression);
  994. isreal:=false;
  995. case hp.resulttype^.deftype of
  996. orddef :
  997. begin
  998. case porddef(tcallparanode(hp).left.resulttype)^.typ of
  999. u32bit,s32bit,
  1000. s64bit,u64bit:
  1001. ;
  1002. u8bit,s8bit,
  1003. u16bit,s16bit:
  1004. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,s32bitdef);
  1005. else
  1006. CGMessage(type_e_integer_or_real_expr_expected);
  1007. end;
  1008. end;
  1009. floatdef :
  1010. begin
  1011. isreal:=true;
  1012. end;
  1013. else
  1014. CGMessage(type_e_integer_or_real_expr_expected);
  1015. end;
  1016. { some format options ? }
  1017. hpp:=tcallparanode(left).right;
  1018. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1019. begin
  1020. firstpass(tcallparanode(hpp).left);
  1021. set_varstate(tcallparanode(hpp).left,true);
  1022. if (not is_integer(tcallparanode(hpp).left.resulttype)) then
  1023. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype^.typename)
  1024. else
  1025. tcallparanode(hpp).left:=gentypeconvnode(tcallparanode(hpp).left,s32bitdef);
  1026. hpp:=tcallparanode(hpp).right;
  1027. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1028. begin
  1029. if isreal then
  1030. begin
  1031. if (not is_integer(tcallparanode(hpp).left.resulttype)) then
  1032. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype^.typename)
  1033. else
  1034. begin
  1035. firstpass(tcallparanode(hpp).left);
  1036. set_varstate(tcallparanode(hpp).left,true);
  1037. tcallparanode(hpp).left:=gentypeconvnode(tcallparanode(hpp).left,s32bitdef);
  1038. end;
  1039. end
  1040. else
  1041. CGMessage(parser_e_illegal_colon_qualifier);
  1042. end;
  1043. end;
  1044. { pass all parameters again for the typeconversions }
  1045. if codegenerror then
  1046. exit;
  1047. tcallparanode(left).firstcallparan(nil,true);
  1048. { calc registers }
  1049. left_max;
  1050. end;
  1051. in_val_x :
  1052. begin
  1053. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1054. resulttype:=voiddef;
  1055. { check the amount of parameters }
  1056. if not(assigned(left)) or
  1057. not(assigned(tcallparanode(left).right)) then
  1058. begin
  1059. CGMessage(parser_e_wrong_parameter_size);
  1060. exit;
  1061. end;
  1062. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1063. {there is a "code" parameter}
  1064. Begin
  1065. { first pass just the code parameter for first local use}
  1066. hp := tcallparanode(left).right;
  1067. tcallparanode(left).right := nil;
  1068. make_not_regable(tcallparanode(left).left);
  1069. tcallparanode(left).firstcallparan(nil,true);
  1070. set_varstate(left,false);
  1071. if codegenerror then exit;
  1072. tcallparanode(left).right := hp;
  1073. {code has to be a var parameter}
  1074. if valid_for_assign(tcallparanode(left).left,false) then
  1075. begin
  1076. if (tcallparanode(left).left.resulttype^.deftype <> orddef) or
  1077. not(porddef(tcallparanode(left).left.resulttype)^.typ in
  1078. [u16bit,s16bit,u32bit,s32bit]) then
  1079. CGMessage(type_e_mismatch);
  1080. end;
  1081. hpp := tcallparanode(left).right
  1082. End
  1083. Else hpp := left;
  1084. {now hpp = the destination value tree}
  1085. { first pass just the destination parameter for first local use}
  1086. hp:=tcallparanode(hpp).right;
  1087. tcallparanode(hpp).right:=nil;
  1088. {hpp = destination}
  1089. make_not_regable(tcallparanode(hpp).left);
  1090. tcallparanode(hpp).firstcallparan(nil,true);
  1091. set_varstate(hpp,false);
  1092. if codegenerror then
  1093. exit;
  1094. { remove warning when result is passed }
  1095. set_funcret_is_valid(tcallparanode(hpp).left);
  1096. tcallparanode(hpp).right := hp;
  1097. if valid_for_assign(tcallparanode(hpp).left,false) then
  1098. begin
  1099. If Not((tcallparanode(hpp).left.resulttype^.deftype = floatdef) or
  1100. ((tcallparanode(hpp).left.resulttype^.deftype = orddef) And
  1101. (POrdDef(tcallparanode(hpp).left.resulttype)^.typ in
  1102. [u32bit,s32bit,
  1103. u8bit,s8bit,u16bit,s16bit,s64bit,u64bit]))) Then
  1104. CGMessage(type_e_mismatch);
  1105. end;
  1106. {hp = source (String)}
  1107. { count_ref := false; WHY ?? }
  1108. tcallparanode(hp).firstcallparan(nil,true);
  1109. set_varstate(hp,true);
  1110. if codegenerror then
  1111. exit;
  1112. { if not a stringdef then insert a type conv which
  1113. does the other type checking }
  1114. If (tcallparanode(hp).left.resulttype^.deftype<>stringdef) then
  1115. begin
  1116. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,cshortstringdef);
  1117. firstpass(hp);
  1118. end;
  1119. { calc registers }
  1120. left_max;
  1121. { val doesn't calculate the registers really }
  1122. { correct, we need one register extra (FK) }
  1123. if is_64bitint(tcallparanode(hpp).left.resulttype) then
  1124. inc(registers32,2)
  1125. else
  1126. inc(registers32,1);
  1127. end;
  1128. in_include_x_y,
  1129. in_exclude_x_y:
  1130. begin
  1131. resulttype:=voiddef;
  1132. if assigned(left) then
  1133. begin
  1134. tcallparanode(left).firstcallparan(nil,true);
  1135. set_varstate(left,true);
  1136. registers32:=left.registers32;
  1137. registersfpu:=left.registersfpu;
  1138. {$ifdef SUPPORT_MMX}
  1139. registersmmx:=left.registersmmx;
  1140. {$endif SUPPORT_MMX}
  1141. { remove warning when result is passed }
  1142. set_funcret_is_valid(tcallparanode(left).left);
  1143. { first param must be var }
  1144. valid_for_assign(tcallparanode(left).left,false);
  1145. { check type }
  1146. if assigned(left.resulttype) and
  1147. (left.resulttype^.deftype=setdef) then
  1148. begin
  1149. { two paras ? }
  1150. if assigned(tcallparanode(left).right) then
  1151. begin
  1152. { insert a type conversion }
  1153. { to the type of the set elements }
  1154. tcallparanode(tcallparanode(left).right).left:=gentypeconvnode(
  1155. tcallparanode(tcallparanode(left).right).left,
  1156. psetdef(left.resulttype)^.elementtype.def);
  1157. { check the type conversion }
  1158. firstpass(tcallparanode(tcallparanode(left).right).left);
  1159. { only three parameters are allowed }
  1160. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1161. CGMessage(cg_e_illegal_expression);
  1162. end;
  1163. end
  1164. else
  1165. CGMessage(type_e_mismatch);
  1166. end
  1167. else
  1168. CGMessage(type_e_mismatch);
  1169. end;
  1170. in_low_x,
  1171. in_high_x:
  1172. begin
  1173. set_varstate(left,false);
  1174. { this fixes tests\webtbs\tbug879.pp (FK)
  1175. if left.nodetype in [typen,loadn,subscriptn] then
  1176. begin
  1177. }
  1178. case left.resulttype^.deftype of
  1179. orddef,enumdef:
  1180. begin
  1181. hp:=do_lowhigh(left.resulttype);
  1182. firstpass(hp);
  1183. result:=hp;
  1184. end;
  1185. setdef:
  1186. begin
  1187. hp:=do_lowhigh(Psetdef(left.resulttype)^.elementtype.def);
  1188. firstpass(hp);
  1189. result:=hp;
  1190. end;
  1191. arraydef:
  1192. begin
  1193. if inlinenumber=in_low_x then
  1194. begin
  1195. hp:=genordinalconstnode(Parraydef(left.resulttype)^.lowrange,
  1196. Parraydef(left.resulttype)^.rangetype.def);
  1197. firstpass(hp);
  1198. result:=hp;
  1199. end
  1200. else
  1201. begin
  1202. if is_open_array(left.resulttype) or
  1203. is_array_of_const(left.resulttype) then
  1204. begin
  1205. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  1206. hp:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
  1207. firstpass(hp);
  1208. result:=hp;
  1209. end
  1210. else
  1211. begin
  1212. hp:=genordinalconstnode(Parraydef(left.resulttype)^.highrange,
  1213. Parraydef(left.resulttype)^.rangetype.def);
  1214. firstpass(hp);
  1215. result:=hp;
  1216. end;
  1217. end;
  1218. end;
  1219. stringdef:
  1220. begin
  1221. if inlinenumber=in_low_x then
  1222. begin
  1223. hp:=genordinalconstnode(0,u8bitdef);
  1224. firstpass(hp);
  1225. result:=hp;
  1226. end
  1227. else
  1228. begin
  1229. if is_open_string(left.resulttype) then
  1230. begin
  1231. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  1232. hp:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
  1233. firstpass(hp);
  1234. result:=hp;
  1235. end
  1236. else
  1237. begin
  1238. hp:=genordinalconstnode(Pstringdef(left.resulttype)^.len,u8bitdef);
  1239. firstpass(hp);
  1240. result:=hp;
  1241. end;
  1242. end;
  1243. end;
  1244. else
  1245. CGMessage(type_e_mismatch);
  1246. end;
  1247. {
  1248. end
  1249. else
  1250. CGMessage(type_e_varid_or_typeid_expected);
  1251. }
  1252. end;
  1253. in_cos_extended:
  1254. begin
  1255. if left.nodetype in [ordconstn,realconstn] then
  1256. setconstrealvalue(cos(getconstrealvalue))
  1257. else
  1258. handleextendedfunction;
  1259. end;
  1260. in_sin_extended:
  1261. begin
  1262. if left.nodetype in [ordconstn,realconstn] then
  1263. setconstrealvalue(sin(getconstrealvalue))
  1264. else
  1265. handleextendedfunction;
  1266. end;
  1267. in_arctan_extended:
  1268. begin
  1269. if left.nodetype in [ordconstn,realconstn] then
  1270. setconstrealvalue(arctan(getconstrealvalue))
  1271. else
  1272. handleextendedfunction;
  1273. end;
  1274. in_pi:
  1275. if block_type=bt_const then
  1276. setconstrealvalue(pi)
  1277. else
  1278. begin
  1279. location.loc:=LOC_FPU;
  1280. resulttype:=s80floatdef;
  1281. end;
  1282. in_abs_extended:
  1283. begin
  1284. if left.nodetype in [ordconstn,realconstn] then
  1285. setconstrealvalue(abs(getconstrealvalue))
  1286. else
  1287. handleextendedfunction;
  1288. end;
  1289. in_sqr_extended:
  1290. begin
  1291. if left.nodetype in [ordconstn,realconstn] then
  1292. setconstrealvalue(sqr(getconstrealvalue))
  1293. else
  1294. handleextendedfunction;
  1295. end;
  1296. in_sqrt_extended:
  1297. begin
  1298. if left.nodetype in [ordconstn,realconstn] then
  1299. begin
  1300. vr:=getconstrealvalue;
  1301. if vr<0.0 then
  1302. begin
  1303. CGMessage(type_e_wrong_math_argument);
  1304. setconstrealvalue(0);
  1305. end
  1306. else
  1307. setconstrealvalue(sqrt(vr));
  1308. end
  1309. else
  1310. handleextendedfunction;
  1311. end;
  1312. in_ln_extended:
  1313. begin
  1314. if left.nodetype in [ordconstn,realconstn] then
  1315. begin
  1316. vr:=getconstrealvalue;
  1317. if vr<=0.0 then
  1318. begin
  1319. CGMessage(type_e_wrong_math_argument);
  1320. setconstrealvalue(0);
  1321. end
  1322. else
  1323. setconstrealvalue(ln(vr));
  1324. end
  1325. else
  1326. handleextendedfunction;
  1327. end;
  1328. {$ifdef SUPPORT_MMX}
  1329. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1330. begin
  1331. end;
  1332. {$endif SUPPORT_MMX}
  1333. in_assert_x_y :
  1334. begin
  1335. resulttype:=voiddef;
  1336. if assigned(left) then
  1337. begin
  1338. tcallparanode(left).firstcallparan(nil,true);
  1339. set_varstate(left,true);
  1340. registers32:=left.registers32;
  1341. registersfpu:=left.registersfpu;
  1342. {$ifdef SUPPORT_MMX}
  1343. registersmmx:=left.registersmmx;
  1344. {$endif SUPPORT_MMX}
  1345. { check type }
  1346. if is_boolean(left.resulttype) then
  1347. begin
  1348. { must always be a string }
  1349. tcallparanode(tcallparanode(left).right).left:=
  1350. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,cshortstringdef);
  1351. firstpass(tcallparanode(tcallparanode(left).right).left);
  1352. end
  1353. else
  1354. CGMessage(type_e_mismatch);
  1355. end
  1356. else
  1357. CGMessage(type_e_mismatch);
  1358. { We've checked the whole statement for correctness, now we
  1359. can remove it if assertions are off }
  1360. if not(cs_do_assertion in aktlocalswitches) then
  1361. { we need a valid node, so insert a nothingn }
  1362. result:=cnothingnode.create;
  1363. end;
  1364. else
  1365. internalerror(8);
  1366. end;
  1367. end;
  1368. { generate an error if no resulttype is set }
  1369. if not assigned(resulttype) then
  1370. resulttype:=generrordef;
  1371. { ... also if the node will be replaced }
  1372. if assigned(result) and
  1373. (not assigned(result.resulttype)) then
  1374. result.resulttype:=generrordef;
  1375. dec(parsing_para_level);
  1376. end;
  1377. {$ifdef fpc}
  1378. {$maxfpuregisters default}
  1379. {$endif fpc}
  1380. begin
  1381. cinlinenode:=tinlinenode;
  1382. end.
  1383. {
  1384. $Log$
  1385. Revision 1.13 2000-11-04 16:48:32 florian
  1386. * innr.inc renamed to make compiler compilation easier because the rtl contains
  1387. a file of the same name
  1388. Revision 1.12 2000/10/31 22:02:48 peter
  1389. * symtable splitted, no real code changes
  1390. Revision 1.11 2000/10/26 14:15:06 jonas
  1391. * fixed setlength for shortstrings
  1392. Revision 1.10 2000/10/21 18:16:11 florian
  1393. * a lot of changes:
  1394. - basic dyn. array support
  1395. - basic C++ support
  1396. - some work for interfaces done
  1397. ....
  1398. Revision 1.9 2000/10/15 08:38:46 jonas
  1399. * added missing getcopy for previous addition
  1400. Revision 1.8 2000/10/14 18:27:53 jonas
  1401. * merged fix for inc/dec on 64bit types from tcinl
  1402. Revision 1.7 2000/10/14 10:14:50 peter
  1403. * moehrendorf oct 2000 rewrite
  1404. Revision 1.6 2000/10/01 19:48:24 peter
  1405. * lot of compile updates for cg11
  1406. Revision 1.5 2000/09/28 19:49:52 florian
  1407. *** empty log message ***
  1408. Revision 1.4 2000/09/28 16:34:47 florian
  1409. *** empty log message ***
  1410. Revision 1.3 2000/09/27 21:33:22 florian
  1411. * finally nadd.pas compiles
  1412. Revision 1.2 2000/09/27 20:25:44 florian
  1413. * more stuff fixed
  1414. Revision 1.1 2000/09/26 14:59:34 florian
  1415. * more conversion work done
  1416. }