ninl.pas 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854
  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. {$else}
  1167. incrementregisterpushed(ALL_REGISTERS);
  1168. {$endif}
  1169. if (tcallparanode(hp).left.nodetype=typen) then
  1170. CGMessage(type_e_cant_read_write_type);
  1171. if assigned(tcallparanode(hp).left.resulttype.def) then
  1172. begin
  1173. isreal:=false;
  1174. { support writeln(procvar) }
  1175. if (tcallparanode(hp).left.resulttype.def.deftype=procvardef) then
  1176. begin
  1177. p1:=ccallnode.create(nil,nil,nil,nil);
  1178. tcallnode(p1).set_procvar(tcallparanode(hp).left);
  1179. firstpass(p1);
  1180. tcallparanode(hp).left:=p1;
  1181. end;
  1182. case tcallparanode(hp).left.resulttype.def.deftype of
  1183. filedef :
  1184. begin
  1185. { only allowed as first parameter }
  1186. if assigned(tcallparanode(hp).right) then
  1187. CGMessage(type_e_cant_read_write_type);
  1188. end;
  1189. stringdef :
  1190. begin
  1191. { generate the high() value for the shortstring }
  1192. if (not iswrite) and
  1193. is_shortstring(tcallparanode(hp).left.resulttype.def) then
  1194. tcallparanode(hp).gen_high_tree(true);
  1195. end;
  1196. pointerdef :
  1197. begin
  1198. if not is_pchar(tcallparanode(hp).left.resulttype.def) then
  1199. CGMessage(type_e_cant_read_write_type);
  1200. end;
  1201. floatdef :
  1202. begin
  1203. isreal:=true;
  1204. end;
  1205. orddef :
  1206. begin
  1207. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  1208. uchar,
  1209. u32bit,s32bit,
  1210. u64bit,s64bit:
  1211. ;
  1212. u8bit,s8bit,
  1213. u16bit,s16bit :
  1214. if iswrite then
  1215. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,s32bittype);
  1216. bool8bit,
  1217. bool16bit,
  1218. bool32bit :
  1219. if iswrite then
  1220. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,booltype)
  1221. else
  1222. CGMessage(type_e_cant_read_write_type);
  1223. else
  1224. CGMessage(type_e_cant_read_write_type);
  1225. end;
  1226. if not(iswrite) and
  1227. not(is_64bitint(tcallparanode(hp).left.resulttype.def)) then
  1228. extra_register:=true;
  1229. end;
  1230. arraydef :
  1231. begin
  1232. if is_chararray(tcallparanode(hp).left.resulttype.def) then
  1233. tcallparanode(hp).gen_high_tree(true)
  1234. else
  1235. CGMessage(type_e_cant_read_write_type);
  1236. end;
  1237. else
  1238. CGMessage(type_e_cant_read_write_type);
  1239. end;
  1240. { some format options ? }
  1241. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  1242. begin
  1243. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  1244. begin
  1245. frac_para:=hp;
  1246. length_para:=tcallparanode(hp).right;
  1247. hp:=tcallparanode(hp).right;
  1248. hpp:=tcallparanode(hp).right;
  1249. end
  1250. else
  1251. begin
  1252. length_para:=hp;
  1253. frac_para:=nil;
  1254. hpp:=tcallparanode(hp).right;
  1255. end;
  1256. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  1257. if assigned(tcallparanode(hpp).left.resulttype.def) then
  1258. isreal:=(tcallparanode(hpp).left.resulttype.def.deftype=floatdef)
  1259. else exit;
  1260. if (not is_integer(tcallparanode(length_para).left.resulttype.def)) then
  1261. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype.def.typename)
  1262. else
  1263. tcallparanode(length_para).left:=ctypeconvnode.create(tcallparanode(length_para).left,s32bittype);
  1264. if assigned(frac_para) then
  1265. begin
  1266. if isreal then
  1267. begin
  1268. if (not is_integer(tcallparanode(frac_para).left.resulttype.def)) then
  1269. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype.def.typename)
  1270. else
  1271. tcallparanode(frac_para).left:=ctypeconvnode.create(tcallparanode(frac_para).left,s32bittype);
  1272. end
  1273. else
  1274. CGMessage(parser_e_illegal_colon_qualifier);
  1275. end;
  1276. { do the checking for the colon'd arg }
  1277. hp:=length_para;
  1278. end;
  1279. end;
  1280. hp:=tcallparanode(hp).right;
  1281. end;
  1282. end;
  1283. { pass all parameters again for the typeconversions }
  1284. if codegenerror then
  1285. exit;
  1286. tcallparanode(left).firstcallparan(nil,true);
  1287. set_varstate(left,true);
  1288. { calc registers }
  1289. left_max;
  1290. if extra_register then
  1291. inc(registers32);
  1292. end;
  1293. end;
  1294. in_settextbuf_file_x :
  1295. begin
  1296. { warning here left is the callparannode
  1297. not the argument directly }
  1298. { left.left is text var }
  1299. { left.right.left is the buffer var }
  1300. { firstcallparan(left,nil);
  1301. already done in firstcalln }
  1302. { now we know the type of buffer }
  1303. srsym:=searchsymonlyin(systemunit,'SETTEXTBUF');
  1304. hp:=ccallparanode.create(cordconstnode.create(tcallparanode(left).left.resulttype.def.size,s32bittype),left);
  1305. hp:=ccallnode.create(hp,tprocsym(srsym),systemunit,nil);
  1306. left:=nil;
  1307. firstpass(hp);
  1308. result:=hp;
  1309. end;
  1310. in_reset_typedfile,
  1311. in_rewrite_typedfile :
  1312. begin
  1313. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1314. end;
  1315. in_str_x_string :
  1316. begin
  1317. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1318. { first pass just the string for first local use }
  1319. hp:=tcallparanode(left).right;
  1320. tcallparanode(left).right:=nil;
  1321. tcallparanode(left).firstcallparan(nil,true);
  1322. { remove warning when result is passed }
  1323. set_funcret_is_valid(tcallparanode(left).left);
  1324. tcallparanode(left).right:=hp;
  1325. tcallparanode(tcallparanode(left).right).firstcallparan(nil,true);
  1326. set_varstate(tcallparanode(left).right,true);
  1327. hp:=left;
  1328. { valid string ? }
  1329. if not assigned(hp) or
  1330. (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) or
  1331. (tcallparanode(hp).right=nil) then
  1332. CGMessage(cg_e_illegal_expression);
  1333. { we need a var parameter }
  1334. valid_for_assign(tcallparanode(hp).left,false);
  1335. { generate the high() value for the shortstring }
  1336. if is_shortstring(tcallparanode(hp).left.resulttype.def) then
  1337. tcallparanode(hp).gen_high_tree(true);
  1338. { !!!! check length of string }
  1339. while assigned(tcallparanode(hp).right) do
  1340. hp:=tcallparanode(hp).right;
  1341. if not assigned(tcallparanode(hp).resulttype.def) then
  1342. exit;
  1343. { check and convert the first param }
  1344. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  1345. not assigned(hp.resulttype.def) then
  1346. CGMessage(cg_e_illegal_expression);
  1347. isreal:=false;
  1348. case hp.resulttype.def.deftype of
  1349. orddef :
  1350. begin
  1351. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  1352. u32bit,s32bit,
  1353. s64bit,u64bit:
  1354. ;
  1355. u8bit,s8bit,
  1356. u16bit,s16bit:
  1357. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,s32bittype);
  1358. else
  1359. CGMessage(type_e_integer_or_real_expr_expected);
  1360. end;
  1361. end;
  1362. floatdef :
  1363. begin
  1364. isreal:=true;
  1365. end;
  1366. else
  1367. CGMessage(type_e_integer_or_real_expr_expected);
  1368. end;
  1369. { some format options ? }
  1370. hpp:=tcallparanode(left).right;
  1371. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1372. begin
  1373. firstpass(tcallparanode(hpp).left);
  1374. set_varstate(tcallparanode(hpp).left,true);
  1375. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1376. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  1377. else
  1378. tcallparanode(hpp).left:=ctypeconvnode.create(tcallparanode(hpp).left,s32bittype);
  1379. hpp:=tcallparanode(hpp).right;
  1380. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1381. begin
  1382. if isreal then
  1383. begin
  1384. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1385. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  1386. else
  1387. begin
  1388. firstpass(tcallparanode(hpp).left);
  1389. set_varstate(tcallparanode(hpp).left,true);
  1390. tcallparanode(hpp).left:=ctypeconvnode.create(tcallparanode(hpp).left,s32bittype);
  1391. end;
  1392. end
  1393. else
  1394. CGMessage(parser_e_illegal_colon_qualifier);
  1395. end;
  1396. end;
  1397. { pass all parameters again for the typeconversions }
  1398. if codegenerror then
  1399. exit;
  1400. tcallparanode(left).firstcallparan(nil,true);
  1401. { calc registers }
  1402. left_max;
  1403. end;
  1404. in_val_x :
  1405. begin
  1406. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1407. resulttype:=voidtype;
  1408. { check the amount of parameters }
  1409. if not(assigned(left)) or
  1410. not(assigned(tcallparanode(left).right)) then
  1411. begin
  1412. CGMessage(parser_e_wrong_parameter_size);
  1413. exit;
  1414. end;
  1415. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1416. {there is a "code" parameter}
  1417. Begin
  1418. { first pass just the code parameter for first local use}
  1419. hp := tcallparanode(left).right;
  1420. tcallparanode(left).right := nil;
  1421. make_not_regable(tcallparanode(left).left);
  1422. tcallparanode(left).firstcallparan(nil,true);
  1423. set_varstate(left,false);
  1424. if codegenerror then exit;
  1425. tcallparanode(left).right := hp;
  1426. {code has to be a var parameter}
  1427. if valid_for_assign(tcallparanode(left).left,false) then
  1428. begin
  1429. if (tcallparanode(left).left.resulttype.def.deftype <> orddef) or
  1430. not(torddef(tcallparanode(left).left.resulttype.def).typ in
  1431. [u16bit,s16bit,u32bit,s32bit]) then
  1432. CGMessage(type_e_mismatch);
  1433. end;
  1434. hpp := tcallparanode(left).right
  1435. End
  1436. Else hpp := left;
  1437. {now hpp = the destination value tree}
  1438. { first pass just the destination parameter for first local use}
  1439. hp:=tcallparanode(hpp).right;
  1440. tcallparanode(hpp).right:=nil;
  1441. {hpp = destination}
  1442. make_not_regable(tcallparanode(hpp).left);
  1443. tcallparanode(hpp).firstcallparan(nil,true);
  1444. set_varstate(hpp,false);
  1445. if codegenerror then
  1446. exit;
  1447. { remove warning when result is passed }
  1448. set_funcret_is_valid(tcallparanode(hpp).left);
  1449. tcallparanode(hpp).right := hp;
  1450. if valid_for_assign(tcallparanode(hpp).left,false) then
  1451. begin
  1452. If Not((tcallparanode(hpp).left.resulttype.def.deftype = floatdef) or
  1453. ((tcallparanode(hpp).left.resulttype.def.deftype = orddef) And
  1454. (torddef(tcallparanode(hpp).left.resulttype.def).typ in
  1455. [u32bit,s32bit,
  1456. u8bit,s8bit,u16bit,s16bit,s64bit,u64bit]))) Then
  1457. CGMessage(type_e_mismatch);
  1458. end;
  1459. {hp = source (String)}
  1460. { count_ref := false; WHY ?? }
  1461. tcallparanode(hp).firstcallparan(nil,true);
  1462. set_varstate(hp,true);
  1463. if codegenerror then
  1464. exit;
  1465. { if not a stringdef then insert a type conv which
  1466. does the other type checking }
  1467. If (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) then
  1468. begin
  1469. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,cshortstringtype);
  1470. firstpass(tcallparanode(hp).left);
  1471. end;
  1472. { calc registers }
  1473. left_max;
  1474. { val doesn't calculate the registers really }
  1475. { correct, we need one register extra (FK) }
  1476. if is_64bitint(tcallparanode(hpp).left.resulttype.def) then
  1477. inc(registers32,2)
  1478. else
  1479. inc(registers32,1);
  1480. end;
  1481. in_include_x_y,
  1482. in_exclude_x_y:
  1483. begin
  1484. registers32:=left.registers32;
  1485. registersfpu:=left.registersfpu;
  1486. {$ifdef SUPPORT_MMX}
  1487. registersmmx:=left.registersmmx;
  1488. {$endif SUPPORT_MMX}
  1489. end;
  1490. in_low_x,
  1491. in_high_x:
  1492. internalerror(200104047);
  1493. in_cos_extended:
  1494. begin
  1495. location.loc:=LOC_FPU;
  1496. registers32:=left.registers32;
  1497. registersfpu:=left.registersfpu;
  1498. {$ifdef SUPPORT_MMX}
  1499. registersmmx:=left.registersmmx;
  1500. {$endif SUPPORT_MMX}
  1501. end;
  1502. in_sin_extended:
  1503. begin
  1504. location.loc:=LOC_FPU;
  1505. registers32:=left.registers32;
  1506. registersfpu:=left.registersfpu;
  1507. {$ifdef SUPPORT_MMX}
  1508. registersmmx:=left.registersmmx;
  1509. {$endif SUPPORT_MMX}
  1510. end;
  1511. in_arctan_extended:
  1512. begin
  1513. location.loc:=LOC_FPU;
  1514. registers32:=left.registers32;
  1515. registersfpu:=left.registersfpu;
  1516. {$ifdef SUPPORT_MMX}
  1517. registersmmx:=left.registersmmx;
  1518. {$endif SUPPORT_MMX}
  1519. end;
  1520. in_pi:
  1521. begin
  1522. location.loc:=LOC_FPU;
  1523. end;
  1524. in_abs_extended:
  1525. begin
  1526. location.loc:=LOC_FPU;
  1527. registers32:=left.registers32;
  1528. registersfpu:=left.registersfpu;
  1529. {$ifdef SUPPORT_MMX}
  1530. registersmmx:=left.registersmmx;
  1531. {$endif SUPPORT_MMX}
  1532. end;
  1533. in_sqr_extended:
  1534. begin
  1535. location.loc:=LOC_FPU;
  1536. registers32:=left.registers32;
  1537. registersfpu:=left.registersfpu;
  1538. {$ifdef SUPPORT_MMX}
  1539. registersmmx:=left.registersmmx;
  1540. {$endif SUPPORT_MMX}
  1541. end;
  1542. in_sqrt_extended:
  1543. begin
  1544. location.loc:=LOC_FPU;
  1545. registers32:=left.registers32;
  1546. registersfpu:=left.registersfpu;
  1547. {$ifdef SUPPORT_MMX}
  1548. registersmmx:=left.registersmmx;
  1549. {$endif SUPPORT_MMX}
  1550. end;
  1551. in_ln_extended:
  1552. begin
  1553. location.loc:=LOC_FPU;
  1554. registers32:=left.registers32;
  1555. registersfpu:=left.registersfpu;
  1556. {$ifdef SUPPORT_MMX}
  1557. registersmmx:=left.registersmmx;
  1558. {$endif SUPPORT_MMX}
  1559. end;
  1560. {$ifdef SUPPORT_MMX}
  1561. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1562. begin
  1563. end;
  1564. {$endif SUPPORT_MMX}
  1565. in_assert_x_y :
  1566. begin
  1567. { We've checked the whole statement for correctness, now we
  1568. can remove it if assertions are off }
  1569. if not(cs_do_assertion in aktlocalswitches) then
  1570. begin
  1571. { we need a valid node, so insert a nothingn }
  1572. result:=cnothingnode.create;
  1573. end
  1574. else
  1575. begin
  1576. registers32:=left.registers32;
  1577. registersfpu:=left.registersfpu;
  1578. {$ifdef SUPPORT_MMX}
  1579. registersmmx:=left.registersmmx;
  1580. {$endif SUPPORT_MMX}
  1581. end;
  1582. end;
  1583. else
  1584. internalerror(8);
  1585. end;
  1586. dec(parsing_para_level);
  1587. end;
  1588. {$ifdef fpc}
  1589. {$maxfpuregisters default}
  1590. {$endif fpc}
  1591. function tinlinenode.docompare(p: tnode): boolean;
  1592. begin
  1593. docompare :=
  1594. inherited docompare(p) and
  1595. (inlinenumber = tinlinenode(p).inlinenumber);
  1596. end;
  1597. begin
  1598. cinlinenode:=tinlinenode;
  1599. end.
  1600. {
  1601. $Log$
  1602. Revision 1.38 2001-04-21 12:03:11 peter
  1603. * m68k updates merged from fixes branch
  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. }