ninl.pas 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Type checking and register allocation for inline nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ninl;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,htypechk,cpuinfo;
  23. {$i compinnr.inc}
  24. type
  25. tinlinenode = class(tunarynode)
  26. inlinenumber : byte;
  27. constructor create(number : byte;is_const:boolean;l : tnode);virtual;
  28. function getcopy : tnode;override;
  29. function pass_1 : tnode;override;
  30. function det_resulttype:tnode;override;
  31. function docompare(p: tnode): boolean; override;
  32. end;
  33. var
  34. cinlinenode : class of tinlinenode;
  35. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  36. implementation
  37. uses
  38. verbose,globals,systems,
  39. globtype,
  40. symconst,symtype,symdef,symsym,symtable,types,
  41. pass_1,
  42. ncal,ncon,ncnv,nadd,nld,nbas,
  43. cpubase,hcodegen,tgcpu
  44. {$ifdef newcg}
  45. ,cgbase
  46. {$endif newcg}
  47. ;
  48. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  49. begin
  50. geninlinenode:=cinlinenode.create(number,is_const,l);
  51. end;
  52. {*****************************************************************************
  53. TINLINENODE
  54. *****************************************************************************}
  55. constructor tinlinenode.create(number : byte;is_const:boolean;l : tnode);
  56. begin
  57. inherited create(inlinen,l);
  58. if is_const then
  59. include(flags,nf_inlineconst);
  60. inlinenumber:=number;
  61. end;
  62. function tinlinenode.getcopy : tnode;
  63. var
  64. n : tinlinenode;
  65. begin
  66. n:=tinlinenode(inherited getcopy);
  67. n.inlinenumber:=inlinenumber;
  68. result:=n;
  69. end;
  70. function tinlinenode.det_resulttype:tnode;
  71. function do_lowhigh(const t:ttype) : tnode;
  72. var
  73. v : tconstexprint;
  74. enum : tenumsym;
  75. hp : tnode;
  76. begin
  77. case t.def.deftype of
  78. orddef:
  79. begin
  80. if inlinenumber=in_low_x then
  81. v:=torddef(t.def).low
  82. else
  83. v:=torddef(t.def).high;
  84. { low/high of torddef are longints, so we need special }
  85. { handling for cardinal and 64bit types (JM) }
  86. if is_signed(t.def) and
  87. is_64bitint(t.def) then
  88. if (inlinenumber=in_low_x) then
  89. v := int64($80000000) shl 32
  90. else
  91. v := (int64($7fffffff) shl 32) or $ffffffff
  92. else
  93. if is_64bitint(t.def) then
  94. { we have to use a dirty trick for high(qword), }
  95. { because it's bigger than high(tconstexprint) (JM) }
  96. v := 0
  97. else
  98. if not is_signed(t.def) then
  99. v := cardinal(v);
  100. hp:=cordconstnode.create(v,t);
  101. resulttypepass(hp);
  102. { fix high(qword) }
  103. if not is_signed(t.def) and
  104. is_64bitint(t.def) and
  105. (inlinenumber = in_high_x) then
  106. tordconstnode(hp).value := -1; { is the same as qword($ffffffffffffffff) }
  107. do_lowhigh:=hp;
  108. end;
  109. enumdef:
  110. begin
  111. enum:=tenumsym(tenumdef(t.def).firstenum);
  112. v:=tenumdef(t.def).maxval;
  113. if inlinenumber=in_high_x then
  114. while assigned(enum) and (enum.value <> v) do
  115. enum:=enum.nextenum;
  116. if not assigned(enum) then
  117. internalerror(309993)
  118. else
  119. hp:=genenumnode(enum);
  120. do_lowhigh:=hp;
  121. end;
  122. else
  123. internalerror(87);
  124. end;
  125. end;
  126. function getconstrealvalue : bestreal;
  127. begin
  128. case left.nodetype of
  129. ordconstn:
  130. getconstrealvalue:=tordconstnode(left).value;
  131. realconstn:
  132. getconstrealvalue:=trealconstnode(left).value_real;
  133. else
  134. internalerror(309992);
  135. end;
  136. end;
  137. procedure setconstrealvalue(r : bestreal);
  138. var
  139. hp : tnode;
  140. begin
  141. hp:=crealconstnode.create(r,pbestrealtype^);
  142. resulttypepass(hp);
  143. result:=hp;
  144. end;
  145. var
  146. counter : longint;
  147. ppn : tcallparanode;
  148. dummycoll : tparaitem;
  149. vl,vl2 : longint;
  150. vr : bestreal;
  151. hp : tnode;
  152. srsym : tsym;
  153. p1,hpp : tnode;
  154. frac_para,
  155. length_para : tnode;
  156. isreal,
  157. iswrite,
  158. file_is_typed : boolean;
  159. label
  160. myexit;
  161. begin
  162. result:=nil;
  163. { if we handle writeln; left contains no valid address }
  164. if assigned(left) then
  165. begin
  166. if left.nodetype=callparan then
  167. tcallparanode(left).get_paratype
  168. else
  169. resulttypepass(left);
  170. end;
  171. inc(parsing_para_level);
  172. { handle intern constant functions in separate case }
  173. if nf_inlineconst in flags then
  174. begin
  175. { no parameters? }
  176. if not assigned(left) then
  177. begin
  178. case inlinenumber of
  179. in_const_pi :
  180. hp:=crealconstnode.create(pi,pbestrealtype^);
  181. else
  182. internalerror(89);
  183. end;
  184. end
  185. else
  186. begin
  187. vl:=0;
  188. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  189. vr:=0;
  190. isreal:=false;
  191. case left.nodetype of
  192. realconstn :
  193. begin
  194. isreal:=true;
  195. vr:=trealconstnode(left).value_real;
  196. end;
  197. ordconstn :
  198. vl:=tordconstnode(left).value;
  199. callparan :
  200. begin
  201. { both exists, else it was not generated }
  202. vl:=tordconstnode(tcallparanode(left).left).value;
  203. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  204. end;
  205. else
  206. CGMessage(cg_e_illegal_expression);
  207. end;
  208. case inlinenumber of
  209. in_const_trunc :
  210. begin
  211. if isreal then
  212. begin
  213. if (vr>=2147483648.0) or (vr<=-2147483649.0) then
  214. begin
  215. CGMessage(parser_e_range_check_error);
  216. hp:=cordconstnode.create(1,s32bittype)
  217. end
  218. else
  219. hp:=cordconstnode.create(trunc(vr),s32bittype)
  220. end
  221. else
  222. hp:=cordconstnode.create(trunc(vl),s32bittype);
  223. end;
  224. in_const_round :
  225. begin
  226. if isreal then
  227. begin
  228. if (vr>=2147483647.5) or (vr<=-2147483648.5) then
  229. begin
  230. CGMessage(parser_e_range_check_error);
  231. hp:=cordconstnode.create(1,s32bittype)
  232. end
  233. else
  234. hp:=cordconstnode.create(round(vr),s32bittype)
  235. end
  236. else
  237. hp:=cordconstnode.create(round(vl),s32bittype);
  238. end;
  239. in_const_frac :
  240. begin
  241. if isreal then
  242. hp:=crealconstnode.create(frac(vr),pbestrealtype^)
  243. else
  244. hp:=crealconstnode.create(frac(vl),pbestrealtype^);
  245. end;
  246. in_const_int :
  247. begin
  248. if isreal then
  249. hp:=crealconstnode.create(int(vr),pbestrealtype^)
  250. else
  251. hp:=crealconstnode.create(int(vl),pbestrealtype^);
  252. end;
  253. in_const_abs :
  254. begin
  255. if isreal then
  256. hp:=crealconstnode.create(abs(vr),pbestrealtype^)
  257. else
  258. hp:=cordconstnode.create(abs(vl),left.resulttype);
  259. end;
  260. in_const_sqr :
  261. begin
  262. if isreal then
  263. hp:=crealconstnode.create(sqr(vr),pbestrealtype^)
  264. else
  265. hp:=cordconstnode.create(sqr(vl),left.resulttype);
  266. end;
  267. in_const_odd :
  268. begin
  269. if isreal then
  270. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  271. else
  272. hp:=cordconstnode.create(byte(odd(vl)),booltype);
  273. end;
  274. in_const_swap_word :
  275. begin
  276. if isreal then
  277. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  278. else
  279. hp:=cordconstnode.create((vl and $ff) shl 8+(vl shr 8),left.resulttype);
  280. end;
  281. in_const_swap_long :
  282. begin
  283. if isreal then
  284. CGMessage(type_e_mismatch)
  285. else
  286. hp:=cordconstnode.create((vl and $ffff) shl 16+(vl shr 16),left.resulttype);
  287. end;
  288. in_const_ptr :
  289. begin
  290. if isreal then
  291. CGMessage(type_e_mismatch)
  292. else
  293. hp:=cpointerconstnode.create((vl2 shl 4)+vl,voidfarpointertype);
  294. end;
  295. in_const_sqrt :
  296. begin
  297. if isreal then
  298. begin
  299. if vr<0.0 then
  300. CGMessage(type_e_wrong_math_argument)
  301. else
  302. hp:=crealconstnode.create(sqrt(vr),pbestrealtype^)
  303. end
  304. else
  305. begin
  306. if vl<0 then
  307. CGMessage(type_e_wrong_math_argument)
  308. else
  309. hp:=crealconstnode.create(sqrt(vl),pbestrealtype^);
  310. end;
  311. end;
  312. in_const_arctan :
  313. begin
  314. if isreal then
  315. hp:=crealconstnode.create(arctan(vr),pbestrealtype^)
  316. else
  317. hp:=crealconstnode.create(arctan(vl),pbestrealtype^);
  318. end;
  319. in_const_cos :
  320. begin
  321. if isreal then
  322. hp:=crealconstnode.create(cos(vr),pbestrealtype^)
  323. else
  324. hp:=crealconstnode.create(cos(vl),pbestrealtype^);
  325. end;
  326. in_const_sin :
  327. begin
  328. if isreal then
  329. hp:=crealconstnode.create(sin(vr),pbestrealtype^)
  330. else
  331. hp:=crealconstnode.create(sin(vl),pbestrealtype^);
  332. end;
  333. in_const_exp :
  334. begin
  335. if isreal then
  336. hp:=crealconstnode.create(exp(vr),pbestrealtype^)
  337. else
  338. hp:=crealconstnode.create(exp(vl),pbestrealtype^);
  339. end;
  340. in_const_ln :
  341. begin
  342. if isreal then
  343. begin
  344. if vr<=0.0 then
  345. CGMessage(type_e_wrong_math_argument)
  346. else
  347. hp:=crealconstnode.create(ln(vr),pbestrealtype^)
  348. end
  349. else
  350. begin
  351. if vl<=0 then
  352. CGMessage(type_e_wrong_math_argument)
  353. else
  354. hp:=crealconstnode.create(ln(vl),pbestrealtype^);
  355. end;
  356. end;
  357. else
  358. internalerror(88);
  359. end;
  360. end;
  361. if hp=nil then
  362. hp:=tnode.create(errorn);
  363. resulttypepass(hp);
  364. result:=hp;
  365. goto myexit;
  366. end
  367. else
  368. begin
  369. case inlinenumber of
  370. in_lo_long,
  371. in_hi_long,
  372. in_lo_qword,
  373. in_hi_qword,
  374. in_lo_word,
  375. in_hi_word :
  376. begin
  377. { give warning for incompatibility with tp and delphi }
  378. if (inlinenumber in [in_lo_long,in_hi_long,in_lo_qword,in_hi_qword]) and
  379. ((m_tp in aktmodeswitches) or
  380. (m_delphi in aktmodeswitches)) then
  381. CGMessage(type_w_maybe_wrong_hi_lo);
  382. { constant folding }
  383. if left.nodetype=ordconstn then
  384. begin
  385. case inlinenumber of
  386. in_lo_word :
  387. hp:=cordconstnode.create(tordconstnode(left).value and $ff,left.resulttype);
  388. in_hi_word :
  389. hp:=cordconstnode.create(tordconstnode(left).value shr 8,left.resulttype);
  390. in_lo_long :
  391. hp:=cordconstnode.create(tordconstnode(left).value and $ffff,left.resulttype);
  392. in_hi_long :
  393. hp:=cordconstnode.create(tordconstnode(left).value shr 16,left.resulttype);
  394. in_lo_qword :
  395. hp:=cordconstnode.create(tordconstnode(left).value and $ffffffff,left.resulttype);
  396. in_hi_qword :
  397. hp:=cordconstnode.create(tordconstnode(left).value shr 32,left.resulttype);
  398. end;
  399. resulttypepass(hp);
  400. result:=hp;
  401. goto myexit;
  402. end;
  403. set_varstate(left,true);
  404. if not is_integer(left.resulttype.def) then
  405. CGMessage(type_e_mismatch);
  406. case inlinenumber of
  407. in_lo_word,
  408. in_hi_word :
  409. resulttype:=u8bittype;
  410. in_lo_long,
  411. in_hi_long :
  412. resulttype:=u16bittype;
  413. in_lo_qword,
  414. in_hi_qword :
  415. resulttype:=u32bittype;
  416. end;
  417. end;
  418. in_sizeof_x:
  419. begin
  420. set_varstate(left,false);
  421. resulttype:=s32bittype;
  422. end;
  423. in_typeof_x:
  424. begin
  425. set_varstate(left,false);
  426. resulttype:=voidpointertype;
  427. end;
  428. in_ord_x:
  429. begin
  430. if (left.nodetype=ordconstn) then
  431. begin
  432. hp:=cordconstnode.create(tordconstnode(left).value,s32bittype);
  433. resulttypepass(hp);
  434. result:=hp;
  435. goto myexit;
  436. end;
  437. set_varstate(left,true);
  438. case left.resulttype.def.deftype of
  439. orddef :
  440. begin
  441. case torddef(left.resulttype.def).typ of
  442. bool8bit,
  443. uchar:
  444. begin
  445. { change to byte() }
  446. hp:=ctypeconvnode.create(left,u8bittype);
  447. left:=nil;
  448. include(hp.flags,nf_explizit);
  449. resulttypepass(hp);
  450. result:=hp;
  451. end;
  452. bool16bit,
  453. uwidechar :
  454. begin
  455. { change to word() }
  456. hp:=ctypeconvnode.create(left,u16bittype);
  457. left:=nil;
  458. include(hp.flags,nf_explizit);
  459. resulttypepass(hp);
  460. result:=hp;
  461. end;
  462. bool32bit :
  463. begin
  464. { change to dword() }
  465. hp:=ctypeconvnode.create(left,u32bittype);
  466. left:=nil;
  467. include(hp.flags,nf_explizit);
  468. resulttypepass(hp);
  469. result:=hp;
  470. end;
  471. uvoid :
  472. CGMessage(type_e_mismatch)
  473. else
  474. begin
  475. { all other orddef need no transformation }
  476. hp:=left;
  477. left:=nil;
  478. result:=hp;
  479. end;
  480. end;
  481. end;
  482. enumdef :
  483. begin
  484. hp:=ctypeconvnode.create(left,s32bittype);
  485. left:=nil;
  486. include(hp.flags,nf_explizit);
  487. resulttypepass(hp);
  488. result:=hp;
  489. end;
  490. else
  491. CGMessage(type_e_mismatch);
  492. end;
  493. end;
  494. in_chr_byte:
  495. begin
  496. { convert to explicit char() }
  497. set_varstate(left,true);
  498. hp:=ctypeconvnode.create(left,cchartype);
  499. include(hp.flags,nf_explizit);
  500. left:=nil;
  501. resulttypepass(hp);
  502. result:=hp;
  503. end;
  504. in_length_string:
  505. begin
  506. set_varstate(left,true);
  507. { we don't need string convertions here }
  508. if (left.nodetype=typeconvn) and
  509. (ttypeconvnode(left).left.resulttype.def.deftype=stringdef) then
  510. begin
  511. hp:=ttypeconvnode(left).left;
  512. ttypeconvnode(left).left:=nil;
  513. left.free;
  514. left:=hp;
  515. end;
  516. { evaluates length of constant strings direct }
  517. if (left.nodetype=stringconstn) then
  518. begin
  519. hp:=cordconstnode.create(tstringconstnode(left).len,s32bittype);
  520. resulttypepass(hp);
  521. result:=hp;
  522. goto myexit;
  523. end
  524. { length of char is one allways }
  525. else if is_constcharnode(left) then
  526. begin
  527. hp:=cordconstnode.create(1,s32bittype);
  528. resulttypepass(hp);
  529. result:=hp;
  530. goto myexit;
  531. end;
  532. if is_ansistring(left.resulttype.def) or
  533. is_widestring(left.resulttype.def) or
  534. is_dynamic_array(left.resulttype.def) then
  535. resulttype:=s32bittype
  536. else
  537. resulttype:=u8bittype;
  538. { check the type, must be string or char }
  539. if (left.resulttype.def.deftype<>stringdef) and
  540. (not is_char(left.resulttype.def)) then
  541. CGMessage(type_e_mismatch);
  542. end;
  543. in_typeinfo_x:
  544. begin
  545. set_varstate(left,true);
  546. resulttype:=voidpointertype;
  547. end;
  548. in_assigned_x:
  549. begin
  550. set_varstate(left,true);
  551. resulttype:=booltype;
  552. end;
  553. in_ofs_x :
  554. internalerror(2000101001);
  555. in_seg_x :
  556. begin
  557. set_varstate(left,false);
  558. hp:=cordconstnode.create(0,s32bittype);
  559. resulttypepass(hp);
  560. result:=hp;
  561. goto myexit;
  562. end;
  563. in_pred_x,
  564. in_succ_x:
  565. begin
  566. set_varstate(left,true);
  567. resulttype:=left.resulttype;
  568. if not is_ordinal(resulttype.def) then
  569. CGMessage(type_e_ordinal_expr_expected)
  570. else
  571. begin
  572. if (resulttype.def.deftype=enumdef) and
  573. (tenumdef(resulttype.def).has_jumps) then
  574. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
  575. end;
  576. { do constant folding after check for jumps }
  577. if left.nodetype=ordconstn then
  578. begin
  579. if inlinenumber=in_succ_x then
  580. hp:=cordconstnode.create(tordconstnode(left).value+1,left.resulttype)
  581. else
  582. hp:=cordconstnode.create(tordconstnode(left).value-1,left.resulttype);
  583. resulttypepass(hp);
  584. result:=hp;
  585. end;
  586. end;
  587. in_setlength_x:
  588. begin
  589. resulttype:=voidtype;
  590. if assigned(left) then
  591. begin
  592. ppn:=tcallparanode(left);
  593. counter:=0;
  594. { check type }
  595. while assigned(ppn.right) do
  596. begin
  597. set_varstate(ppn.left,true);
  598. inserttypeconv(ppn.left,s32bittype);
  599. inc(counter);
  600. ppn:=tcallparanode(ppn.right);
  601. end;
  602. { last param must be var }
  603. valid_for_assign(ppn.left,false);
  604. set_varstate(ppn.left,false);
  605. { first param must be a string or dynamic array ...}
  606. if not((ppn.left.resulttype.def.deftype=stringdef) or
  607. (is_dynamic_array(ppn.left.resulttype.def))) then
  608. CGMessage(type_e_mismatch);
  609. { only dynamic arrays accept more dimensions }
  610. if (counter>1) and
  611. (not(is_dynamic_array(left.resulttype.def))) then
  612. CGMessage(type_e_mismatch);
  613. { convert shortstrings to openstring parameters }
  614. { (generate the hightree) (JM) }
  615. if (ppn.left.resulttype.def.deftype = stringdef) and
  616. (tstringdef(ppn.left.resulttype.def).string_typ =
  617. st_shortstring) then
  618. begin
  619. dummycoll:=tparaitem.create;
  620. dummycoll.paratyp:=vs_var;
  621. dummycoll.paratype:=openshortstringtype;
  622. tcallparanode(ppn).insert_typeconv(dummycoll,false);
  623. dummycoll.destroy;
  624. end;
  625. end
  626. else
  627. CGMessage(type_e_mismatch);
  628. end;
  629. in_finalize_x:
  630. begin
  631. resulttype:=voidtype;
  632. if assigned(left) and assigned(tcallparanode(left).left) then
  633. begin
  634. { first param must be var }
  635. valid_for_assign(tcallparanode(left).left,false);
  636. set_varstate(tcallparanode(left).left,true);
  637. { two parameters?, the last parameter must be a longint }
  638. if assigned(tcallparanode(left).right) then
  639. inserttypeconv(tcallparanode(tcallparanode(left).right).left,s32bittype);
  640. end
  641. else
  642. CGMessage(type_e_mismatch);
  643. end;
  644. in_inc_x,
  645. in_dec_x:
  646. begin
  647. resulttype:=voidtype;
  648. if assigned(left) then
  649. begin
  650. set_varstate(left,true);
  651. if codegenerror then
  652. exit;
  653. { first param must be var }
  654. valid_for_assign(tcallparanode(left).left,false);
  655. if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  656. is_ordinal(left.resulttype.def) then
  657. begin
  658. { two paras ? }
  659. if assigned(tcallparanode(left).right) then
  660. begin
  661. { insert a type conversion }
  662. { the second param is always longint }
  663. inserttypeconv(tcallparanode(tcallparanode(left).right).left,s32bittype);
  664. if assigned(tcallparanode(tcallparanode(left).right).right) then
  665. CGMessage(cg_e_illegal_expression);
  666. end;
  667. end
  668. else
  669. CGMessage(type_e_ordinal_expr_expected);
  670. end
  671. else
  672. CGMessage(type_e_mismatch);
  673. end;
  674. in_read_x,
  675. in_readln_x,
  676. in_write_x,
  677. in_writeln_x :
  678. begin
  679. resulttype:=voidtype;
  680. { we must know if it is a typed file or not }
  681. { but we must first do the firstpass for it }
  682. file_is_typed:=false;
  683. if assigned(left) then
  684. begin
  685. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  686. set_varstate(left,iswrite);
  687. { now we can check }
  688. hp:=left;
  689. while assigned(tcallparanode(hp).right) do
  690. hp:=tcallparanode(hp).right;
  691. { if resulttype.def is not assigned, then automatically }
  692. { file is not typed. }
  693. if assigned(hp) and assigned(hp.resulttype.def) then
  694. Begin
  695. if (hp.resulttype.def.deftype=filedef) then
  696. if (tfiledef(hp.resulttype.def).filetyp=ft_untyped) then
  697. begin
  698. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  699. CGMessage(type_e_no_readln_writeln_for_typed_file)
  700. else
  701. CGMessage(type_e_no_read_write_for_untyped_file);
  702. end
  703. else if (tfiledef(hp.resulttype.def).filetyp=ft_typed) then
  704. begin
  705. file_is_typed:=true;
  706. { test the type }
  707. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  708. CGMessage(type_e_no_readln_writeln_for_typed_file);
  709. hpp:=left;
  710. while (hpp<>hp) do
  711. begin
  712. if (tcallparanode(hpp).left.nodetype=typen) then
  713. CGMessage(type_e_cant_read_write_type);
  714. if not is_equal(hpp.resulttype.def,tfiledef(hp.resulttype.def).typedfiletype.def) then
  715. CGMessage(type_e_mismatch);
  716. { generate the high() value for the shortstring }
  717. if ((not iswrite) and is_shortstring(tcallparanode(hpp).left.resulttype.def)) or
  718. (is_chararray(tcallparanode(hpp).left.resulttype.def)) then
  719. tcallparanode(hpp).gen_high_tree(true);
  720. { read(ln) is call by reference (JM) }
  721. if not iswrite then
  722. make_not_regable(tcallparanode(hpp).left);
  723. hpp:=tcallparanode(hpp).right;
  724. end;
  725. end;
  726. end; { endif assigned(hp) }
  727. { insert type conversions for write(ln) }
  728. if (not file_is_typed) then
  729. begin
  730. hp:=left;
  731. while assigned(hp) do
  732. begin
  733. if (tcallparanode(hp).left.nodetype=typen) then
  734. CGMessage(type_e_cant_read_write_type);
  735. if assigned(tcallparanode(hp).left.resulttype.def) then
  736. begin
  737. isreal:=false;
  738. { support writeln(procvar) }
  739. if (tcallparanode(hp).left.resulttype.def.deftype=procvardef) then
  740. begin
  741. p1:=ccallnode.create(nil,nil,nil,nil);
  742. tcallnode(p1).set_procvar(tcallparanode(hp).left);
  743. resulttypepass(p1);
  744. tcallparanode(hp).left:=p1;
  745. end;
  746. case tcallparanode(hp).left.resulttype.def.deftype of
  747. filedef :
  748. begin
  749. { only allowed as first parameter }
  750. if assigned(tcallparanode(hp).right) then
  751. CGMessage(type_e_cant_read_write_type);
  752. end;
  753. stringdef :
  754. begin
  755. { generate the high() value for the shortstring }
  756. if (not iswrite) and
  757. is_shortstring(tcallparanode(hp).left.resulttype.def) then
  758. tcallparanode(hp).gen_high_tree(true);
  759. end;
  760. pointerdef :
  761. begin
  762. if not is_pchar(tcallparanode(hp).left.resulttype.def) then
  763. CGMessage(type_e_cant_read_write_type);
  764. end;
  765. floatdef :
  766. begin
  767. isreal:=true;
  768. end;
  769. orddef :
  770. begin
  771. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  772. uchar,
  773. u32bit,s32bit,
  774. u64bit,s64bit:
  775. ;
  776. u8bit,s8bit,
  777. u16bit,s16bit :
  778. if iswrite then
  779. inserttypeconv(tcallparanode(hp).left,s32bittype);
  780. bool8bit,
  781. bool16bit,
  782. bool32bit :
  783. if iswrite then
  784. inserttypeconv(tcallparanode(hp).left,booltype)
  785. else
  786. CGMessage(type_e_cant_read_write_type);
  787. else
  788. CGMessage(type_e_cant_read_write_type);
  789. end;
  790. end;
  791. arraydef :
  792. begin
  793. if is_chararray(tcallparanode(hp).left.resulttype.def) then
  794. tcallparanode(hp).gen_high_tree(true)
  795. else
  796. CGMessage(type_e_cant_read_write_type);
  797. end;
  798. else
  799. CGMessage(type_e_cant_read_write_type);
  800. end;
  801. { some format options ? }
  802. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  803. begin
  804. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  805. begin
  806. frac_para:=hp;
  807. length_para:=tcallparanode(hp).right;
  808. hp:=tcallparanode(hp).right;
  809. hpp:=tcallparanode(hp).right;
  810. end
  811. else
  812. begin
  813. length_para:=hp;
  814. frac_para:=nil;
  815. hpp:=tcallparanode(hp).right;
  816. end;
  817. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  818. if assigned(tcallparanode(hpp).left.resulttype.def) then
  819. isreal:=(tcallparanode(hpp).left.resulttype.def.deftype=floatdef)
  820. else
  821. exit;
  822. if (not is_integer(tcallparanode(length_para).left.resulttype.def)) then
  823. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype.def.typename)
  824. else
  825. inserttypeconv(tcallparanode(length_para).left,s32bittype);
  826. if assigned(frac_para) then
  827. begin
  828. if isreal then
  829. begin
  830. if (not is_integer(tcallparanode(frac_para).left.resulttype.def)) then
  831. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype.def.typename)
  832. else
  833. inserttypeconv(tcallparanode(frac_para).left,s32bittype);
  834. end
  835. else
  836. CGMessage(parser_e_illegal_colon_qualifier);
  837. end;
  838. { do the checking for the colon'd arg }
  839. hp:=length_para;
  840. end;
  841. end;
  842. hp:=tcallparanode(hp).right;
  843. end;
  844. end;
  845. if codegenerror then
  846. exit;
  847. set_varstate(left,true);
  848. end;
  849. end;
  850. in_settextbuf_file_x :
  851. begin
  852. resulttype:=voidtype;
  853. { now we know the type of buffer }
  854. srsym:=searchsymonlyin(systemunit,'SETTEXTBUF');
  855. hp:=ccallparanode.create(cordconstnode.create(tcallparanode(left).left.resulttype.def.size,s32bittype),left);
  856. hp:=ccallnode.create(hp,tprocsym(srsym),systemunit,nil);
  857. left:=nil;
  858. resulttypepass(hp);
  859. result:=hp;
  860. end;
  861. { the firstpass of the arg has been done in firstcalln ? }
  862. in_reset_typedfile,
  863. in_rewrite_typedfile :
  864. begin
  865. set_varstate(left,true);
  866. resulttype:=voidtype;
  867. end;
  868. in_str_x_string :
  869. begin
  870. resulttype:=voidtype;
  871. set_varstate(left,false);
  872. { remove warning when result is passed }
  873. set_funcret_is_valid(tcallparanode(left).left);
  874. set_varstate(tcallparanode(tcallparanode(left).right).left,true);
  875. hp:=left;
  876. { valid string ? }
  877. if not assigned(hp) or
  878. (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) or
  879. (tcallparanode(hp).right=nil) then
  880. CGMessage(cg_e_illegal_expression);
  881. { we need a var parameter }
  882. valid_for_assign(tcallparanode(hp).left,false);
  883. { generate the high() value for the shortstring }
  884. if is_shortstring(tcallparanode(hp).left.resulttype.def) then
  885. tcallparanode(hp).gen_high_tree(true);
  886. { !!!! check length of string }
  887. while assigned(tcallparanode(hp).right) do
  888. hp:=tcallparanode(hp).right;
  889. if not assigned(tcallparanode(hp).resulttype.def) then
  890. exit;
  891. { check and convert the first param }
  892. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  893. not assigned(hp.resulttype.def) then
  894. CGMessage(cg_e_illegal_expression);
  895. isreal:=false;
  896. case hp.resulttype.def.deftype of
  897. orddef :
  898. begin
  899. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  900. u32bit,s32bit,
  901. s64bit,u64bit:
  902. ;
  903. u8bit,s8bit,
  904. u16bit,s16bit:
  905. inserttypeconv(tcallparanode(hp).left,s32bittype);
  906. else
  907. CGMessage(type_e_integer_or_real_expr_expected);
  908. end;
  909. end;
  910. floatdef :
  911. begin
  912. isreal:=true;
  913. end;
  914. else
  915. CGMessage(type_e_integer_or_real_expr_expected);
  916. end;
  917. { some format options ? }
  918. hpp:=tcallparanode(left).right;
  919. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  920. begin
  921. set_varstate(tcallparanode(hpp).left,true);
  922. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  923. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  924. else
  925. inserttypeconv(tcallparanode(hpp).left,s32bittype);
  926. hpp:=tcallparanode(hpp).right;
  927. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  928. begin
  929. if isreal then
  930. begin
  931. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  932. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  933. else
  934. begin
  935. set_varstate(tcallparanode(hpp).left,true);
  936. inserttypeconv(tcallparanode(hpp).left,s32bittype);
  937. end;
  938. end
  939. else
  940. CGMessage(parser_e_illegal_colon_qualifier);
  941. end;
  942. end;
  943. end;
  944. in_val_x :
  945. begin
  946. resulttype:=voidtype;
  947. { check the amount of parameters }
  948. if not(assigned(left)) or
  949. not(assigned(tcallparanode(left).right)) then
  950. begin
  951. CGMessage(parser_e_wrong_parameter_size);
  952. exit;
  953. end;
  954. { there is a "code" parameter }
  955. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  956. Begin
  957. { first pass just the code parameter for first local use}
  958. hp := tcallparanode(left).right;
  959. tcallparanode(left).right := nil;
  960. make_not_regable(tcallparanode(left).left);
  961. set_varstate(left,false);
  962. if codegenerror then
  963. exit;
  964. tcallparanode(left).right := hp;
  965. { code has to be a var parameter }
  966. if valid_for_assign(tcallparanode(left).left,false) then
  967. begin
  968. if (tcallparanode(left).left.resulttype.def.deftype <> orddef) or
  969. not(torddef(tcallparanode(left).left.resulttype.def).typ in [u16bit,s16bit,u32bit,s32bit]) then
  970. CGMessage(type_e_mismatch);
  971. end;
  972. hpp := tcallparanode(left).right
  973. End
  974. Else
  975. hpp := left;
  976. { now hpp = the destination value tree }
  977. { first pass just the destination parameter for first local use }
  978. hp:=tcallparanode(hpp).right;
  979. tcallparanode(hpp).right:=nil;
  980. { hpp = destination }
  981. make_not_regable(tcallparanode(hpp).left);
  982. set_varstate(hpp,false);
  983. if codegenerror then
  984. exit;
  985. { remove warning when result is passed }
  986. set_funcret_is_valid(tcallparanode(hpp).left);
  987. tcallparanode(hpp).right := hp;
  988. if valid_for_assign(tcallparanode(hpp).left,false) then
  989. begin
  990. If Not((tcallparanode(hpp).left.resulttype.def.deftype = floatdef) or
  991. is_integer(tcallparanode(hpp).left.resulttype.def)) then
  992. CGMessage(type_e_mismatch);
  993. end;
  994. { hp = source (String) }
  995. { if not a stringdef then insert a type conv which
  996. does the other type checking }
  997. If (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) then
  998. inserttypeconv(tcallparanode(hp).left,cshortstringtype);
  999. set_varstate(hp,true);
  1000. end;
  1001. in_include_x_y,
  1002. in_exclude_x_y:
  1003. begin
  1004. resulttype:=voidtype;
  1005. if assigned(left) then
  1006. begin
  1007. set_varstate(left,true);
  1008. { remove warning when result is passed }
  1009. set_funcret_is_valid(tcallparanode(left).left);
  1010. { first param must be var }
  1011. valid_for_assign(tcallparanode(left).left,false);
  1012. { check type }
  1013. if assigned(left.resulttype.def) and
  1014. (left.resulttype.def.deftype=setdef) then
  1015. begin
  1016. { two paras ? }
  1017. if assigned(tcallparanode(left).right) then
  1018. begin
  1019. { insert a type conversion }
  1020. { to the type of the set elements }
  1021. inserttypeconv(tcallparanode(tcallparanode(left).right).left,
  1022. tsetdef(left.resulttype.def).elementtype);
  1023. { only three parameters are allowed }
  1024. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1025. CGMessage(cg_e_illegal_expression);
  1026. end;
  1027. end
  1028. else
  1029. CGMessage(type_e_mismatch);
  1030. end
  1031. else
  1032. CGMessage(type_e_mismatch);
  1033. end;
  1034. in_low_x,
  1035. in_high_x:
  1036. begin
  1037. set_varstate(left,false);
  1038. case left.resulttype.def.deftype of
  1039. orddef,
  1040. enumdef:
  1041. begin
  1042. hp:=do_lowhigh(left.resulttype);
  1043. resulttypepass(hp);
  1044. result:=hp;
  1045. end;
  1046. setdef:
  1047. begin
  1048. hp:=do_lowhigh(tsetdef(left.resulttype.def).elementtype);
  1049. resulttypepass(hp);
  1050. result:=hp;
  1051. end;
  1052. arraydef:
  1053. begin
  1054. if inlinenumber=in_low_x then
  1055. begin
  1056. hp:=cordconstnode.create(tarraydef(left.resulttype.def).lowrange,tarraydef(left.resulttype.def).rangetype);
  1057. resulttypepass(hp);
  1058. result:=hp;
  1059. end
  1060. else
  1061. begin
  1062. if is_open_array(left.resulttype.def) or
  1063. is_array_of_const(left.resulttype.def) then
  1064. begin
  1065. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  1066. hp:=cloadnode.create(tvarsym(srsym),tloadnode(left).symtable);
  1067. resulttypepass(hp);
  1068. result:=hp;
  1069. end
  1070. else
  1071. if is_dynamic_array(left.resulttype.def) then
  1072. begin
  1073. {
  1074. Doesn't work because that procedure isn't in
  1075. the interface of the system unit :( (JM)
  1076. srsym:=searchsymonlyin(systemunit,'FPC_DYNARRAY_HIGH');
  1077. if not assigned(srsym) then
  1078. internalerror(200104291);
  1079. inserttypeconv(left,voidpointertype);
  1080. hp:=ccallparanode.create(left,nil);
  1081. hp:=ccallnode.create(hp,tprocsym(srsym),systemunit,nil);
  1082. left:=nil;
  1083. resulttypepass(hp);
  1084. result:=hp;}
  1085. {$warning "high(dynamic_array)" isn't implemented yet }
  1086. end
  1087. else
  1088. begin
  1089. hp:=cordconstnode.create(tarraydef(left.resulttype.def).highrange,tarraydef(left.resulttype.def).rangetype);
  1090. resulttypepass(hp);
  1091. result:=hp;
  1092. end;
  1093. end;
  1094. end;
  1095. stringdef:
  1096. begin
  1097. if inlinenumber=in_low_x then
  1098. begin
  1099. hp:=cordconstnode.create(0,u8bittype);
  1100. resulttypepass(hp);
  1101. result:=hp;
  1102. end
  1103. else
  1104. begin
  1105. if is_open_string(left.resulttype.def) then
  1106. begin
  1107. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  1108. hp:=cloadnode.create(tvarsym(srsym),tloadnode(left).symtable);
  1109. resulttypepass(hp);
  1110. result:=hp;
  1111. end
  1112. else
  1113. begin
  1114. hp:=cordconstnode.create(tstringdef(left.resulttype.def).len,u8bittype);
  1115. resulttypepass(hp);
  1116. result:=hp;
  1117. end;
  1118. end;
  1119. end;
  1120. else
  1121. CGMessage(type_e_mismatch);
  1122. end;
  1123. end;
  1124. in_pi:
  1125. begin
  1126. if block_type=bt_const then
  1127. setconstrealvalue(pi)
  1128. else
  1129. resulttype:=s80floattype;
  1130. end;
  1131. in_cos_extended :
  1132. begin
  1133. if left.nodetype in [ordconstn,realconstn] then
  1134. setconstrealvalue(cos(getconstrealvalue))
  1135. else
  1136. begin
  1137. set_varstate(left,true);
  1138. inserttypeconv(left,s80floattype);
  1139. resulttype:=s80floattype;
  1140. end;
  1141. end;
  1142. in_sin_extended :
  1143. begin
  1144. if left.nodetype in [ordconstn,realconstn] then
  1145. setconstrealvalue(sin(getconstrealvalue))
  1146. else
  1147. begin
  1148. set_varstate(left,true);
  1149. inserttypeconv(left,s80floattype);
  1150. resulttype:=s80floattype;
  1151. end;
  1152. end;
  1153. in_arctan_extended :
  1154. begin
  1155. if left.nodetype in [ordconstn,realconstn] then
  1156. setconstrealvalue(arctan(getconstrealvalue))
  1157. else
  1158. begin
  1159. set_varstate(left,true);
  1160. inserttypeconv(left,s80floattype);
  1161. resulttype:=s80floattype;
  1162. end;
  1163. end;
  1164. in_abs_extended :
  1165. begin
  1166. if left.nodetype in [ordconstn,realconstn] then
  1167. setconstrealvalue(abs(getconstrealvalue))
  1168. else
  1169. begin
  1170. set_varstate(left,true);
  1171. inserttypeconv(left,s80floattype);
  1172. resulttype:=s80floattype;
  1173. end;
  1174. end;
  1175. in_sqr_extended :
  1176. begin
  1177. if left.nodetype in [ordconstn,realconstn] then
  1178. setconstrealvalue(sqr(getconstrealvalue))
  1179. else
  1180. begin
  1181. set_varstate(left,true);
  1182. inserttypeconv(left,s80floattype);
  1183. resulttype:=s80floattype;
  1184. end;
  1185. end;
  1186. in_sqrt_extended :
  1187. begin
  1188. if left.nodetype in [ordconstn,realconstn] then
  1189. begin
  1190. vr:=getconstrealvalue;
  1191. if vr<0.0 then
  1192. begin
  1193. CGMessage(type_e_wrong_math_argument);
  1194. setconstrealvalue(0);
  1195. end
  1196. else
  1197. setconstrealvalue(sqrt(vr));
  1198. end
  1199. else
  1200. begin
  1201. set_varstate(left,true);
  1202. inserttypeconv(left,s80floattype);
  1203. resulttype:=s80floattype;
  1204. end;
  1205. end;
  1206. in_ln_extended :
  1207. begin
  1208. if left.nodetype in [ordconstn,realconstn] then
  1209. begin
  1210. vr:=getconstrealvalue;
  1211. if vr<=0.0 then
  1212. begin
  1213. CGMessage(type_e_wrong_math_argument);
  1214. setconstrealvalue(0);
  1215. end
  1216. else
  1217. setconstrealvalue(ln(vr));
  1218. end
  1219. else
  1220. begin
  1221. set_varstate(left,true);
  1222. inserttypeconv(left,s80floattype);
  1223. resulttype:=s80floattype;
  1224. end;
  1225. end;
  1226. {$ifdef SUPPORT_MMX}
  1227. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1228. begin
  1229. end;
  1230. {$endif SUPPORT_MMX}
  1231. in_assert_x_y :
  1232. begin
  1233. resulttype:=voidtype;
  1234. if assigned(left) then
  1235. begin
  1236. set_varstate(left,true);
  1237. { check type }
  1238. if is_boolean(left.resulttype.def) then
  1239. begin
  1240. { must always be a string }
  1241. inserttypeconv(tcallparanode(tcallparanode(left).right).left,cshortstringtype);
  1242. end
  1243. else
  1244. CGMessage(type_e_mismatch);
  1245. end
  1246. else
  1247. CGMessage(type_e_mismatch);
  1248. end;
  1249. else
  1250. internalerror(8);
  1251. end;
  1252. end;
  1253. myexit:
  1254. { Run get_paratype again to update maybe inserted typeconvs }
  1255. if not codegenerror then
  1256. begin
  1257. if assigned(left) and
  1258. (left.nodetype=callparan) then
  1259. tcallparanode(left).get_paratype;
  1260. end;
  1261. dec(parsing_para_level);
  1262. end;
  1263. {$ifdef fpc}
  1264. {$maxfpuregisters 0}
  1265. {$endif fpc}
  1266. function tinlinenode.pass_1 : tnode;
  1267. var
  1268. srsym : tsym;
  1269. hp,hpp : tnode;
  1270. extra_register,
  1271. iswrite,
  1272. file_is_typed : boolean;
  1273. begin
  1274. result:=nil;
  1275. { if we handle writeln; left contains no valid address }
  1276. if assigned(left) then
  1277. begin
  1278. if left.nodetype=callparan then
  1279. tcallparanode(left).firstcallparan(nil,false)
  1280. else
  1281. firstpass(left);
  1282. left_max;
  1283. set_location(location,left.location);
  1284. end;
  1285. inc(parsing_para_level);
  1286. { intern const should already be handled }
  1287. if nf_inlineconst in flags then
  1288. internalerror(200104044);
  1289. case inlinenumber of
  1290. in_lo_qword,
  1291. in_hi_qword,
  1292. in_lo_long,
  1293. in_hi_long,
  1294. in_lo_word,
  1295. in_hi_word:
  1296. begin
  1297. if registers32<1 then
  1298. registers32:=1;
  1299. location.loc:=LOC_REGISTER;
  1300. end;
  1301. in_sizeof_x:
  1302. begin
  1303. if push_high_param(left.resulttype.def) then
  1304. begin
  1305. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  1306. hp:=caddnode.create(addn,cloadnode.create(tvarsym(srsym),tloadnode(left).symtable),
  1307. cordconstnode.create(1,s32bittype));
  1308. if (left.resulttype.def.deftype=arraydef) and
  1309. (tarraydef(left.resulttype.def).elesize<>1) then
  1310. hp:=caddnode.create(muln,hp,cordconstnode.create(tarraydef(left.resulttype.def).elesize,s32bittype));
  1311. firstpass(hp);
  1312. result:=hp;
  1313. end
  1314. else
  1315. begin
  1316. if registers32<1 then
  1317. registers32:=1;
  1318. location.loc:=LOC_REGISTER;
  1319. end;
  1320. end;
  1321. in_typeof_x:
  1322. begin
  1323. if registers32<1 then
  1324. registers32:=1;
  1325. location.loc:=LOC_REGISTER;
  1326. end;
  1327. in_ord_x,
  1328. in_chr_byte:
  1329. begin
  1330. { should not happend as it's converted to typeconv }
  1331. internalerror(200104045);
  1332. end;
  1333. in_length_string:
  1334. begin
  1335. end;
  1336. in_typeinfo_x:
  1337. begin
  1338. location.loc:=LOC_REGISTER;
  1339. registers32:=1;
  1340. end;
  1341. in_assigned_x:
  1342. begin
  1343. location.loc:=LOC_FLAGS;
  1344. end;
  1345. in_ofs_x :
  1346. internalerror(2000101001);
  1347. in_seg_x :
  1348. internalerror(200104046);
  1349. in_pred_x,
  1350. in_succ_x:
  1351. begin
  1352. if is_64bitint(resulttype.def) then
  1353. begin
  1354. if (registers32<2) then
  1355. registers32:=2
  1356. end
  1357. else
  1358. begin
  1359. if (registers32<1) then
  1360. registers32:=1;
  1361. end;
  1362. location.loc:=LOC_REGISTER;
  1363. end;
  1364. in_setlength_x:
  1365. begin
  1366. end;
  1367. in_finalize_x:
  1368. begin
  1369. end;
  1370. in_inc_x,
  1371. in_dec_x:
  1372. begin
  1373. { check type }
  1374. if is_64bitint(left.resulttype.def) or
  1375. { range/overflow checking doesn't work properly }
  1376. { with the inc/dec code that's generated (JM) }
  1377. ((left.resulttype.def.deftype = orddef) and
  1378. not(is_char(left.resulttype.def)) and
  1379. not(is_boolean(left.resulttype.def)) and
  1380. (aktlocalswitches *
  1381. [cs_check_overflow,cs_check_range] <> [])) then
  1382. { convert to simple add (JM) }
  1383. begin
  1384. { extra parameter? }
  1385. if assigned(tcallparanode(left).right) then
  1386. begin
  1387. { Yes, use for add node }
  1388. hpp := tcallparanode(tcallparanode(left).right).left;
  1389. tcallparanode(tcallparanode(left).right).left := nil;
  1390. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1391. CGMessage(cg_e_illegal_expression);
  1392. end
  1393. else
  1394. { no, create constant 1 }
  1395. hpp := cordconstnode.create(1,s32bittype);
  1396. { addition/substraction depending on inc/dec }
  1397. if inlinenumber = in_inc_x then
  1398. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  1399. else
  1400. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  1401. { assign result of addition }
  1402. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  1403. tcallparanode(left).left := nil;
  1404. { firstpass it }
  1405. firstpass(hpp);
  1406. { return new node }
  1407. result := hpp;
  1408. end
  1409. else if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  1410. is_ordinal(left.resulttype.def) then
  1411. begin
  1412. { two paras ? }
  1413. if assigned(tcallparanode(left).right) then
  1414. begin
  1415. { need we an additional register ? }
  1416. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  1417. (tcallparanode(tcallparanode(left).right).left.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  1418. (tcallparanode(tcallparanode(left).right).left.registers32<=1) then
  1419. inc(registers32);
  1420. { do we need an additional register to restore the first parameter? }
  1421. if tcallparanode(tcallparanode(left).right).left.registers32>=registers32 then
  1422. inc(registers32);
  1423. end;
  1424. end;
  1425. end;
  1426. in_read_x,
  1427. in_readln_x,
  1428. in_write_x,
  1429. in_writeln_x :
  1430. begin
  1431. { needs a call }
  1432. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1433. { true, if readln needs an extra register }
  1434. extra_register:=false;
  1435. { we must know if it is a typed file or not }
  1436. { but we must first do the firstpass for it }
  1437. file_is_typed:=false;
  1438. if assigned(left) then
  1439. begin
  1440. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  1441. { now we can check }
  1442. hp:=left;
  1443. while assigned(tcallparanode(hp).right) do
  1444. hp:=tcallparanode(hp).right;
  1445. { if resulttype.def is not assigned, then automatically }
  1446. { file is not typed. }
  1447. if assigned(hp) then
  1448. Begin
  1449. if (hp.resulttype.def.deftype=filedef) and
  1450. (tfiledef(hp.resulttype.def).filetyp=ft_typed) then
  1451. file_is_typed:=true;
  1452. end; { endif assigned(hp) }
  1453. if (not file_is_typed) then
  1454. begin
  1455. hp:=left;
  1456. while assigned(hp) do
  1457. begin
  1458. {$ifdef i386}
  1459. incrementregisterpushed($ff);
  1460. {$else}
  1461. incrementregisterpushed(ALL_REGISTERS);
  1462. {$endif}
  1463. if assigned(tcallparanode(hp).left.resulttype.def) then
  1464. begin
  1465. case tcallparanode(hp).left.resulttype.def.deftype of
  1466. orddef :
  1467. begin
  1468. if not(iswrite) and
  1469. not(is_64bitint(tcallparanode(hp).left.resulttype.def)) then
  1470. extra_register:=true;
  1471. end;
  1472. end;
  1473. end;
  1474. hp:=tcallparanode(hp).right;
  1475. end;
  1476. end;
  1477. { calc registers }
  1478. left_max;
  1479. if extra_register then
  1480. inc(registers32);
  1481. end;
  1482. end;
  1483. in_settextbuf_file_x :
  1484. internalerror(200104262);
  1485. in_reset_typedfile,
  1486. in_rewrite_typedfile :
  1487. begin
  1488. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1489. end;
  1490. in_str_x_string :
  1491. begin
  1492. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1493. { calc registers }
  1494. left_max;
  1495. end;
  1496. in_val_x :
  1497. begin
  1498. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1499. { calc registers }
  1500. left_max;
  1501. { val doesn't calculate the registers really }
  1502. { correct, we need one register extra (FK) }
  1503. { there is a "code" parameter }
  1504. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1505. hpp := tcallparanode(left).right
  1506. Else
  1507. hpp := left;
  1508. { now hpp = the destination value tree }
  1509. if is_64bitint(tcallparanode(hpp).left.resulttype.def) then
  1510. inc(registers32,2)
  1511. else
  1512. inc(registers32,1);
  1513. end;
  1514. in_include_x_y,
  1515. in_exclude_x_y:
  1516. begin
  1517. registers32:=left.registers32;
  1518. registersfpu:=left.registersfpu;
  1519. {$ifdef SUPPORT_MMX}
  1520. registersmmx:=left.registersmmx;
  1521. {$endif SUPPORT_MMX}
  1522. end;
  1523. in_low_x,
  1524. in_high_x:
  1525. internalerror(200104047);
  1526. in_cos_extended:
  1527. begin
  1528. location.loc:=LOC_FPU;
  1529. registers32:=left.registers32;
  1530. registersfpu:=left.registersfpu;
  1531. {$ifdef SUPPORT_MMX}
  1532. registersmmx:=left.registersmmx;
  1533. {$endif SUPPORT_MMX}
  1534. end;
  1535. in_sin_extended:
  1536. begin
  1537. location.loc:=LOC_FPU;
  1538. registers32:=left.registers32;
  1539. registersfpu:=left.registersfpu;
  1540. {$ifdef SUPPORT_MMX}
  1541. registersmmx:=left.registersmmx;
  1542. {$endif SUPPORT_MMX}
  1543. end;
  1544. in_arctan_extended:
  1545. begin
  1546. location.loc:=LOC_FPU;
  1547. registers32:=left.registers32;
  1548. registersfpu:=left.registersfpu;
  1549. {$ifdef SUPPORT_MMX}
  1550. registersmmx:=left.registersmmx;
  1551. {$endif SUPPORT_MMX}
  1552. end;
  1553. in_pi:
  1554. begin
  1555. location.loc:=LOC_FPU;
  1556. end;
  1557. in_abs_extended:
  1558. begin
  1559. location.loc:=LOC_FPU;
  1560. registers32:=left.registers32;
  1561. registersfpu:=left.registersfpu;
  1562. {$ifdef SUPPORT_MMX}
  1563. registersmmx:=left.registersmmx;
  1564. {$endif SUPPORT_MMX}
  1565. end;
  1566. in_sqr_extended:
  1567. begin
  1568. location.loc:=LOC_FPU;
  1569. registers32:=left.registers32;
  1570. registersfpu:=left.registersfpu;
  1571. {$ifdef SUPPORT_MMX}
  1572. registersmmx:=left.registersmmx;
  1573. {$endif SUPPORT_MMX}
  1574. end;
  1575. in_sqrt_extended:
  1576. begin
  1577. location.loc:=LOC_FPU;
  1578. registers32:=left.registers32;
  1579. registersfpu:=left.registersfpu;
  1580. {$ifdef SUPPORT_MMX}
  1581. registersmmx:=left.registersmmx;
  1582. {$endif SUPPORT_MMX}
  1583. end;
  1584. in_ln_extended:
  1585. begin
  1586. location.loc:=LOC_FPU;
  1587. registers32:=left.registers32;
  1588. registersfpu:=left.registersfpu;
  1589. {$ifdef SUPPORT_MMX}
  1590. registersmmx:=left.registersmmx;
  1591. {$endif SUPPORT_MMX}
  1592. end;
  1593. {$ifdef SUPPORT_MMX}
  1594. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1595. begin
  1596. end;
  1597. {$endif SUPPORT_MMX}
  1598. in_assert_x_y :
  1599. begin
  1600. { We've checked the whole statement for correctness, now we
  1601. can remove it if assertions are off }
  1602. if not(cs_do_assertion in aktlocalswitches) then
  1603. begin
  1604. { we need a valid node, so insert a nothingn }
  1605. result:=cnothingnode.create;
  1606. end
  1607. else
  1608. begin
  1609. registers32:=left.registers32;
  1610. registersfpu:=left.registersfpu;
  1611. {$ifdef SUPPORT_MMX}
  1612. registersmmx:=left.registersmmx;
  1613. {$endif SUPPORT_MMX}
  1614. end;
  1615. end;
  1616. else
  1617. internalerror(8);
  1618. end;
  1619. dec(parsing_para_level);
  1620. end;
  1621. {$ifdef fpc}
  1622. {$maxfpuregisters default}
  1623. {$endif fpc}
  1624. function tinlinenode.docompare(p: tnode): boolean;
  1625. begin
  1626. docompare :=
  1627. inherited docompare(p) and
  1628. (inlinenumber = tinlinenode(p).inlinenumber);
  1629. end;
  1630. begin
  1631. cinlinenode:=tinlinenode;
  1632. end.
  1633. {
  1634. $Log$
  1635. Revision 1.40 2001-05-06 17:16:43 jonas
  1636. + added warning about missing implementation for high(dynamic_array)
  1637. Revision 1.39 2001/04/26 21:57:05 peter
  1638. * moved code from firstpass to det_resulttype and remove extraneous
  1639. calls to firstcallparan for in_str,in_write,in_val
  1640. Revision 1.38 2001/04/21 12:03:11 peter
  1641. * m68k updates merged from fixes branch
  1642. Revision 1.37 2001/04/13 22:22:30 peter
  1643. * call set_varstate for setlength
  1644. * ptr returns pointerconstnode instead of ordconstnode
  1645. Revision 1.36 2001/04/13 01:22:09 peter
  1646. * symtable change to classes
  1647. * range check generation and errors fixed, make cycle DEBUG=1 works
  1648. * memory leaks fixed
  1649. Revision 1.35 2001/04/05 21:02:13 peter
  1650. * fixed fpu inline functions typeconvs
  1651. Revision 1.34 2001/04/04 22:42:40 peter
  1652. * move constant folding into det_resulttype
  1653. Revision 1.33 2001/04/04 21:30:43 florian
  1654. * applied several fixes to get the DD8 Delphi Unit compiled
  1655. e.g. "forward"-interfaces are working now
  1656. Revision 1.32 2001/04/02 21:20:31 peter
  1657. * resulttype rewrite
  1658. Revision 1.31 2001/03/23 00:16:07 florian
  1659. + some stuff to compile FreeCLX added
  1660. Revision 1.30 2001/03/12 12:47:46 michael
  1661. + Patches from peter
  1662. Revision 1.29 2001/03/03 12:38:08 jonas
  1663. * fixed low() for signed types < 64bit
  1664. Revision 1.28 2001/02/26 19:44:53 peter
  1665. * merged generic m68k updates from fixes branch
  1666. Revision 1.27 2001/02/22 11:24:40 jonas
  1667. * fixed bug in previous fix (hopped over revision 1.26 because that one
  1668. also removed the fix for high(cardinal))
  1669. Revision 1.26 2001/02/21 20:50:59 peter
  1670. * fix to compile again, but high(cardinal) with $R+ still fails!
  1671. Revision 1.25 2001/02/21 12:57:46 jonas
  1672. * fixed high/low for cardinal, int64 and qword
  1673. Revision 1.24 2001/01/06 19:54:11 peter
  1674. * merged fix for 1310
  1675. Revision 1.23 2001/01/06 18:28:39 peter
  1676. * fixed wrong notes about locals
  1677. Revision 1.22 2000/12/31 11:14:10 jonas
  1678. + implemented/fixed docompare() mathods for all nodes (not tested)
  1679. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  1680. and constant strings/chars together
  1681. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  1682. when adding
  1683. Revision 1.21 2000/12/25 00:07:26 peter
  1684. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1685. tlinkedlist objects)
  1686. Revision 1.20 2000/12/17 14:35:41 peter
  1687. * fixed crash with val()
  1688. Revision 1.19 2000/11/29 00:30:33 florian
  1689. * unused units removed from uses clause
  1690. * some changes for widestrings
  1691. Revision 1.18 2000/11/12 15:27:22 jonas
  1692. * also don't do conversion for chars/booleans (hopefully final change :/)
  1693. Revision 1.17 2000/11/11 21:08:13 jonas
  1694. * don't do inc/dec to add/sub conversion for enums
  1695. Revision 1.16 2000/11/11 16:18:35 peter
  1696. * ptr returns farpointer
  1697. Revision 1.15 2000/11/11 15:59:07 jonas
  1698. * convert inc/dec to add/sub when range/overflow checking is on
  1699. Revision 1.14 2000/11/09 17:46:54 florian
  1700. * System.TypeInfo fixed
  1701. + System.Finalize implemented
  1702. + some new keywords for interface support added
  1703. Revision 1.13 2000/11/04 16:48:32 florian
  1704. * innr.inc renamed to make compiler compilation easier because the rtl contains
  1705. a file of the same name
  1706. Revision 1.12 2000/10/31 22:02:48 peter
  1707. * symtable splitted, no real code changes
  1708. Revision 1.11 2000/10/26 14:15:06 jonas
  1709. * fixed setlength for shortstrings
  1710. Revision 1.10 2000/10/21 18:16:11 florian
  1711. * a lot of changes:
  1712. - basic dyn. array support
  1713. - basic C++ support
  1714. - some work for interfaces done
  1715. ....
  1716. Revision 1.9 2000/10/15 08:38:46 jonas
  1717. * added missing getcopy for previous addition
  1718. Revision 1.8 2000/10/14 18:27:53 jonas
  1719. * merged fix for inc/dec on 64bit types from tcinl
  1720. Revision 1.7 2000/10/14 10:14:50 peter
  1721. * moehrendorf oct 2000 rewrite
  1722. Revision 1.6 2000/10/01 19:48:24 peter
  1723. * lot of compile updates for cg11
  1724. Revision 1.5 2000/09/28 19:49:52 florian
  1725. *** empty log message ***
  1726. Revision 1.4 2000/09/28 16:34:47 florian
  1727. *** empty log message ***
  1728. Revision 1.3 2000/09/27 21:33:22 florian
  1729. * finally nadd.pas compiles
  1730. Revision 1.2 2000/09/27 20:25:44 florian
  1731. * more stuff fixed
  1732. Revision 1.1 2000/09/26 14:59:34 florian
  1733. * more conversion work done
  1734. }