ninl.pas 71 KB

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