ninl.pas 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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:=cordconstnode.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. inserttypeconv(ppn.left,s32bittype);
  593. inc(counter);
  594. ppn:=tcallparanode(ppn.right);
  595. end;
  596. { last param must be var }
  597. valid_for_assign(ppn.left,false);
  598. set_varstate(ppn.left,false);
  599. { first param must be a string or dynamic array ...}
  600. if not((ppn.left.resulttype.def.deftype=stringdef) or
  601. (is_dynamic_array(ppn.left.resulttype.def))) then
  602. CGMessage(type_e_mismatch);
  603. { only dynamic arrays accept more dimensions }
  604. if (counter>1) and
  605. (not(is_dynamic_array(left.resulttype.def))) then
  606. CGMessage(type_e_mismatch);
  607. { convert shortstrings to openstring parameters }
  608. { (generate the hightree) (JM) }
  609. if (ppn.left.resulttype.def.deftype = stringdef) and
  610. (tstringdef(ppn.left.resulttype.def).string_typ =
  611. st_shortstring) then
  612. begin
  613. dummycoll:=tparaitem.create;
  614. dummycoll.paratyp:=vs_var;
  615. dummycoll.paratype:=openshortstringtype;
  616. tcallparanode(ppn).insert_typeconv(dummycoll,false);
  617. dummycoll.destroy;
  618. end;
  619. end
  620. else
  621. CGMessage(type_e_mismatch);
  622. end;
  623. in_finalize_x:
  624. begin
  625. resulttype:=voidtype;
  626. if assigned(left) and assigned(tcallparanode(left).left) then
  627. begin
  628. { first param must be var }
  629. valid_for_assign(tcallparanode(left).left,false);
  630. set_varstate(tcallparanode(left).left,true);
  631. { two parameters?, the last parameter must be a longint }
  632. if assigned(tcallparanode(left).right) then
  633. inserttypeconv(tcallparanode(tcallparanode(left).right).left,s32bittype);
  634. end
  635. else
  636. CGMessage(type_e_mismatch);
  637. end;
  638. in_inc_x,
  639. in_dec_x:
  640. begin
  641. resulttype:=voidtype;
  642. if assigned(left) then
  643. begin
  644. set_varstate(left,true);
  645. if codegenerror then
  646. exit;
  647. { first param must be var }
  648. valid_for_assign(tcallparanode(left).left,false);
  649. if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  650. is_ordinal(left.resulttype.def) then
  651. begin
  652. { two paras ? }
  653. if assigned(tcallparanode(left).right) then
  654. begin
  655. { insert a type conversion }
  656. { the second param is always longint }
  657. inserttypeconv(tcallparanode(tcallparanode(left).right).left,s32bittype);
  658. if assigned(tcallparanode(tcallparanode(left).right).right) then
  659. CGMessage(cg_e_illegal_expression);
  660. end;
  661. end
  662. else
  663. CGMessage(type_e_ordinal_expr_expected);
  664. end
  665. else
  666. CGMessage(type_e_mismatch);
  667. end;
  668. in_read_x,
  669. in_readln_x,
  670. in_write_x,
  671. in_writeln_x :
  672. begin
  673. resulttype:=voidtype;
  674. end;
  675. in_settextbuf_file_x :
  676. begin
  677. resulttype:=voidtype;
  678. end;
  679. { the firstpass of the arg has been done in firstcalln ? }
  680. in_reset_typedfile,
  681. in_rewrite_typedfile :
  682. begin
  683. set_varstate(left,true);
  684. resulttype:=voidtype;
  685. end;
  686. in_str_x_string :
  687. begin
  688. resulttype:=voidtype;
  689. set_varstate(left,false);
  690. end;
  691. in_val_x :
  692. begin
  693. resulttype:=voidtype;
  694. end;
  695. in_include_x_y,
  696. in_exclude_x_y:
  697. begin
  698. resulttype:=voidtype;
  699. if assigned(left) then
  700. begin
  701. set_varstate(left,true);
  702. { remove warning when result is passed }
  703. set_funcret_is_valid(tcallparanode(left).left);
  704. { first param must be var }
  705. valid_for_assign(tcallparanode(left).left,false);
  706. { check type }
  707. if assigned(left.resulttype.def) and
  708. (left.resulttype.def.deftype=setdef) then
  709. begin
  710. { two paras ? }
  711. if assigned(tcallparanode(left).right) then
  712. begin
  713. { insert a type conversion }
  714. { to the type of the set elements }
  715. inserttypeconv(tcallparanode(tcallparanode(left).right).left,
  716. tsetdef(left.resulttype.def).elementtype);
  717. { only three parameters are allowed }
  718. if assigned(tcallparanode(tcallparanode(left).right).right) then
  719. CGMessage(cg_e_illegal_expression);
  720. end;
  721. end
  722. else
  723. CGMessage(type_e_mismatch);
  724. end
  725. else
  726. CGMessage(type_e_mismatch);
  727. end;
  728. in_low_x,
  729. in_high_x:
  730. begin
  731. set_varstate(left,false);
  732. case left.resulttype.def.deftype of
  733. orddef,
  734. enumdef:
  735. begin
  736. hp:=do_lowhigh(left.resulttype);
  737. resulttypepass(hp);
  738. result:=hp;
  739. end;
  740. setdef:
  741. begin
  742. hp:=do_lowhigh(tsetdef(left.resulttype.def).elementtype);
  743. resulttypepass(hp);
  744. result:=hp;
  745. end;
  746. arraydef:
  747. begin
  748. if inlinenumber=in_low_x then
  749. begin
  750. hp:=cordconstnode.create(tarraydef(left.resulttype.def).lowrange,tarraydef(left.resulttype.def).rangetype);
  751. resulttypepass(hp);
  752. result:=hp;
  753. end
  754. else
  755. begin
  756. if is_open_array(left.resulttype.def) or
  757. is_array_of_const(left.resulttype.def) then
  758. begin
  759. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  760. hp:=cloadnode.create(tvarsym(srsym),tloadnode(left).symtable);
  761. resulttypepass(hp);
  762. result:=hp;
  763. end
  764. else
  765. begin
  766. hp:=cordconstnode.create(tarraydef(left.resulttype.def).highrange,tarraydef(left.resulttype.def).rangetype);
  767. resulttypepass(hp);
  768. result:=hp;
  769. end;
  770. end;
  771. end;
  772. stringdef:
  773. begin
  774. if inlinenumber=in_low_x then
  775. begin
  776. hp:=cordconstnode.create(0,u8bittype);
  777. resulttypepass(hp);
  778. result:=hp;
  779. end
  780. else
  781. begin
  782. if is_open_string(left.resulttype.def) then
  783. begin
  784. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  785. hp:=cloadnode.create(tvarsym(srsym),tloadnode(left).symtable);
  786. resulttypepass(hp);
  787. result:=hp;
  788. end
  789. else
  790. begin
  791. hp:=cordconstnode.create(tstringdef(left.resulttype.def).len,u8bittype);
  792. resulttypepass(hp);
  793. result:=hp;
  794. end;
  795. end;
  796. end;
  797. else
  798. CGMessage(type_e_mismatch);
  799. end;
  800. end;
  801. in_pi:
  802. begin
  803. if block_type=bt_const then
  804. setconstrealvalue(pi)
  805. else
  806. resulttype:=s80floattype;
  807. end;
  808. in_cos_extended :
  809. begin
  810. if left.nodetype in [ordconstn,realconstn] then
  811. setconstrealvalue(cos(getconstrealvalue))
  812. else
  813. begin
  814. set_varstate(left,true);
  815. inserttypeconv(left,s80floattype);
  816. resulttype:=s80floattype;
  817. end;
  818. end;
  819. in_sin_extended :
  820. begin
  821. if left.nodetype in [ordconstn,realconstn] then
  822. setconstrealvalue(sin(getconstrealvalue))
  823. else
  824. begin
  825. set_varstate(left,true);
  826. inserttypeconv(left,s80floattype);
  827. resulttype:=s80floattype;
  828. end;
  829. end;
  830. in_arctan_extended :
  831. begin
  832. if left.nodetype in [ordconstn,realconstn] then
  833. setconstrealvalue(arctan(getconstrealvalue))
  834. else
  835. begin
  836. set_varstate(left,true);
  837. inserttypeconv(left,s80floattype);
  838. resulttype:=s80floattype;
  839. end;
  840. end;
  841. in_abs_extended :
  842. begin
  843. if left.nodetype in [ordconstn,realconstn] then
  844. setconstrealvalue(abs(getconstrealvalue))
  845. else
  846. begin
  847. set_varstate(left,true);
  848. inserttypeconv(left,s80floattype);
  849. resulttype:=s80floattype;
  850. end;
  851. end;
  852. in_sqr_extended :
  853. begin
  854. if left.nodetype in [ordconstn,realconstn] then
  855. setconstrealvalue(sqr(getconstrealvalue))
  856. else
  857. begin
  858. set_varstate(left,true);
  859. inserttypeconv(left,s80floattype);
  860. resulttype:=s80floattype;
  861. end;
  862. end;
  863. in_sqrt_extended :
  864. begin
  865. if left.nodetype in [ordconstn,realconstn] then
  866. begin
  867. vr:=getconstrealvalue;
  868. if vr<0.0 then
  869. begin
  870. CGMessage(type_e_wrong_math_argument);
  871. setconstrealvalue(0);
  872. end
  873. else
  874. setconstrealvalue(sqrt(vr));
  875. end
  876. else
  877. begin
  878. set_varstate(left,true);
  879. inserttypeconv(left,s80floattype);
  880. resulttype:=s80floattype;
  881. end;
  882. end;
  883. in_ln_extended :
  884. begin
  885. if left.nodetype in [ordconstn,realconstn] then
  886. begin
  887. vr:=getconstrealvalue;
  888. if vr<=0.0 then
  889. begin
  890. CGMessage(type_e_wrong_math_argument);
  891. setconstrealvalue(0);
  892. end
  893. else
  894. setconstrealvalue(ln(vr));
  895. end
  896. else
  897. begin
  898. set_varstate(left,true);
  899. inserttypeconv(left,s80floattype);
  900. resulttype:=s80floattype;
  901. end;
  902. end;
  903. {$ifdef SUPPORT_MMX}
  904. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  905. begin
  906. end;
  907. {$endif SUPPORT_MMX}
  908. in_assert_x_y :
  909. begin
  910. resulttype:=voidtype;
  911. if assigned(left) then
  912. begin
  913. set_varstate(left,true);
  914. { check type }
  915. if is_boolean(left.resulttype.def) then
  916. begin
  917. { must always be a string }
  918. inserttypeconv(tcallparanode(tcallparanode(left).right).left,cshortstringtype);
  919. end
  920. else
  921. CGMessage(type_e_mismatch);
  922. end
  923. else
  924. CGMessage(type_e_mismatch);
  925. end;
  926. else
  927. internalerror(8);
  928. end;
  929. end;
  930. myexit:
  931. dec(parsing_para_level);
  932. end;
  933. {$ifdef fpc}
  934. {$maxfpuregisters 0}
  935. {$endif fpc}
  936. function tinlinenode.pass_1 : tnode;
  937. var
  938. p1,hp,hpp : tnode;
  939. srsym : tsym;
  940. {$ifndef NOCOLONCHECK}
  941. frac_para,length_para : tnode;
  942. {$endif ndef NOCOLONCHECK}
  943. extra_register,
  944. isreal,
  945. iswrite,
  946. file_is_typed : boolean;
  947. begin
  948. result:=nil;
  949. { if we handle writeln; left contains no valid address }
  950. if assigned(left) then
  951. begin
  952. if left.nodetype=callparan then
  953. tcallparanode(left).firstcallparan(nil,false)
  954. else
  955. firstpass(left);
  956. left_max;
  957. set_location(location,left.location);
  958. end;
  959. inc(parsing_para_level);
  960. { intern const should already be handled }
  961. if nf_inlineconst in flags then
  962. internalerror(200104044);
  963. case inlinenumber of
  964. in_lo_qword,
  965. in_hi_qword,
  966. in_lo_long,
  967. in_hi_long,
  968. in_lo_word,
  969. in_hi_word:
  970. begin
  971. if registers32<1 then
  972. registers32:=1;
  973. location.loc:=LOC_REGISTER;
  974. end;
  975. in_sizeof_x:
  976. begin
  977. if push_high_param(left.resulttype.def) then
  978. begin
  979. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  980. hp:=caddnode.create(addn,cloadnode.create(tvarsym(srsym),tloadnode(left).symtable),
  981. cordconstnode.create(1,s32bittype));
  982. if (left.resulttype.def.deftype=arraydef) and
  983. (tarraydef(left.resulttype.def).elesize<>1) then
  984. hp:=caddnode.create(muln,hp,cordconstnode.create(tarraydef(left.resulttype.def).elesize,s32bittype));
  985. firstpass(hp);
  986. result:=hp;
  987. end
  988. else
  989. begin
  990. if registers32<1 then
  991. registers32:=1;
  992. location.loc:=LOC_REGISTER;
  993. end;
  994. end;
  995. in_typeof_x:
  996. begin
  997. if registers32<1 then
  998. registers32:=1;
  999. location.loc:=LOC_REGISTER;
  1000. end;
  1001. in_ord_x,
  1002. in_chr_byte:
  1003. begin
  1004. { should not happend as it's converted to typeconv }
  1005. internalerror(200104045);
  1006. end;
  1007. in_length_string:
  1008. begin
  1009. end;
  1010. in_typeinfo_x:
  1011. begin
  1012. location.loc:=LOC_REGISTER;
  1013. registers32:=1;
  1014. end;
  1015. in_assigned_x:
  1016. begin
  1017. location.loc:=LOC_FLAGS;
  1018. end;
  1019. in_ofs_x :
  1020. internalerror(2000101001);
  1021. in_seg_x :
  1022. internalerror(200104046);
  1023. in_pred_x,
  1024. in_succ_x:
  1025. begin
  1026. if is_64bitint(resulttype.def) then
  1027. begin
  1028. if (registers32<2) then
  1029. registers32:=2
  1030. end
  1031. else
  1032. begin
  1033. if (registers32<1) then
  1034. registers32:=1;
  1035. end;
  1036. location.loc:=LOC_REGISTER;
  1037. end;
  1038. in_setlength_x:
  1039. begin
  1040. end;
  1041. in_finalize_x:
  1042. begin
  1043. end;
  1044. in_inc_x,
  1045. in_dec_x:
  1046. begin
  1047. { check type }
  1048. if is_64bitint(left.resulttype.def) or
  1049. { range/overflow checking doesn't work properly }
  1050. { with the inc/dec code that's generated (JM) }
  1051. ((left.resulttype.def.deftype = orddef) and
  1052. not(is_char(left.resulttype.def)) and
  1053. not(is_boolean(left.resulttype.def)) and
  1054. (aktlocalswitches *
  1055. [cs_check_overflow,cs_check_range] <> [])) then
  1056. { convert to simple add (JM) }
  1057. begin
  1058. { extra parameter? }
  1059. if assigned(tcallparanode(left).right) then
  1060. begin
  1061. { Yes, use for add node }
  1062. hpp := tcallparanode(tcallparanode(left).right).left;
  1063. tcallparanode(tcallparanode(left).right).left := nil;
  1064. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1065. CGMessage(cg_e_illegal_expression);
  1066. end
  1067. else
  1068. { no, create constant 1 }
  1069. hpp := cordconstnode.create(1,s32bittype);
  1070. { addition/substraction depending on inc/dec }
  1071. if inlinenumber = in_inc_x then
  1072. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  1073. else
  1074. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  1075. { assign result of addition }
  1076. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  1077. tcallparanode(left).left := nil;
  1078. { firstpass it }
  1079. firstpass(hpp);
  1080. { return new node }
  1081. result := hpp;
  1082. end
  1083. else if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  1084. is_ordinal(left.resulttype.def) then
  1085. begin
  1086. { two paras ? }
  1087. if assigned(tcallparanode(left).right) then
  1088. begin
  1089. { need we an additional register ? }
  1090. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  1091. (tcallparanode(tcallparanode(left).right).left.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  1092. (tcallparanode(tcallparanode(left).right).left.registers32<=1) then
  1093. inc(registers32);
  1094. { do we need an additional register to restore the first parameter? }
  1095. if tcallparanode(tcallparanode(left).right).left.registers32>=registers32 then
  1096. inc(registers32);
  1097. end;
  1098. end;
  1099. end;
  1100. in_read_x,
  1101. in_readln_x,
  1102. in_write_x,
  1103. in_writeln_x :
  1104. begin
  1105. { needs a call }
  1106. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1107. { true, if readln needs an extra register }
  1108. extra_register:=false;
  1109. { we must know if it is a typed file or not }
  1110. { but we must first do the firstpass for it }
  1111. file_is_typed:=false;
  1112. if assigned(left) then
  1113. begin
  1114. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  1115. tcallparanode(left).firstcallparan(nil,true);
  1116. set_varstate(left,iswrite);
  1117. { now we can check }
  1118. hp:=left;
  1119. while assigned(tcallparanode(hp).right) do
  1120. hp:=tcallparanode(hp).right;
  1121. { if resulttype.def is not assigned, then automatically }
  1122. { file is not typed. }
  1123. if assigned(hp) and assigned(hp.resulttype.def) then
  1124. Begin
  1125. if (hp.resulttype.def.deftype=filedef) then
  1126. if (tfiledef(hp.resulttype.def).filetyp=ft_untyped) then
  1127. begin
  1128. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  1129. CGMessage(type_e_no_readln_writeln_for_typed_file)
  1130. else
  1131. CGMessage(type_e_no_read_write_for_untyped_file);
  1132. end
  1133. else if (tfiledef(hp.resulttype.def).filetyp=ft_typed) then
  1134. begin
  1135. file_is_typed:=true;
  1136. { test the type }
  1137. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  1138. CGMessage(type_e_no_readln_writeln_for_typed_file);
  1139. hpp:=left;
  1140. while (hpp<>hp) do
  1141. begin
  1142. if (tcallparanode(hpp).left.nodetype=typen) then
  1143. CGMessage(type_e_cant_read_write_type);
  1144. if not is_equal(hpp.resulttype.def,tfiledef(hp.resulttype.def).typedfiletype.def) then
  1145. CGMessage(type_e_mismatch);
  1146. { generate the high() value for the shortstring }
  1147. if ((not iswrite) and is_shortstring(tcallparanode(hpp).left.resulttype.def)) or
  1148. (is_chararray(tcallparanode(hpp).left.resulttype.def)) then
  1149. tcallparanode(hpp).gen_high_tree(true);
  1150. { read(ln) is call by reference (JM) }
  1151. if not iswrite then
  1152. make_not_regable(tcallparanode(hpp).left);
  1153. hpp:=tcallparanode(hpp).right;
  1154. end;
  1155. end;
  1156. end; { endif assigned(hp) }
  1157. { insert type conversions for write(ln) }
  1158. if (not file_is_typed) then
  1159. begin
  1160. hp:=left;
  1161. while assigned(hp) do
  1162. begin
  1163. {$ifdef i386}
  1164. incrementregisterpushed($ff);
  1165. {$endif}
  1166. {$ifdef m68k}
  1167. for regi:=R_D0 to R_A6 do
  1168. inc(reg_pushes[regi],t_times*2);
  1169. {$endif}
  1170. if (tcallparanode(hp).left.nodetype=typen) then
  1171. CGMessage(type_e_cant_read_write_type);
  1172. if assigned(tcallparanode(hp).left.resulttype.def) then
  1173. begin
  1174. isreal:=false;
  1175. { support writeln(procvar) }
  1176. if (tcallparanode(hp).left.resulttype.def.deftype=procvardef) then
  1177. begin
  1178. p1:=ccallnode.create(nil,nil,nil,nil);
  1179. tcallnode(p1).set_procvar(tcallparanode(hp).left);
  1180. firstpass(p1);
  1181. tcallparanode(hp).left:=p1;
  1182. end;
  1183. case tcallparanode(hp).left.resulttype.def.deftype of
  1184. filedef :
  1185. begin
  1186. { only allowed as first parameter }
  1187. if assigned(tcallparanode(hp).right) then
  1188. CGMessage(type_e_cant_read_write_type);
  1189. end;
  1190. stringdef :
  1191. begin
  1192. { generate the high() value for the shortstring }
  1193. if (not iswrite) and
  1194. is_shortstring(tcallparanode(hp).left.resulttype.def) then
  1195. tcallparanode(hp).gen_high_tree(true);
  1196. end;
  1197. pointerdef :
  1198. begin
  1199. if not is_pchar(tcallparanode(hp).left.resulttype.def) then
  1200. CGMessage(type_e_cant_read_write_type);
  1201. end;
  1202. floatdef :
  1203. begin
  1204. isreal:=true;
  1205. end;
  1206. orddef :
  1207. begin
  1208. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  1209. uchar,
  1210. u32bit,s32bit,
  1211. u64bit,s64bit:
  1212. ;
  1213. u8bit,s8bit,
  1214. u16bit,s16bit :
  1215. if iswrite then
  1216. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,s32bittype);
  1217. bool8bit,
  1218. bool16bit,
  1219. bool32bit :
  1220. if iswrite then
  1221. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,booltype)
  1222. else
  1223. CGMessage(type_e_cant_read_write_type);
  1224. else
  1225. CGMessage(type_e_cant_read_write_type);
  1226. end;
  1227. if not(iswrite) and
  1228. not(is_64bitint(tcallparanode(hp).left.resulttype.def)) then
  1229. extra_register:=true;
  1230. end;
  1231. arraydef :
  1232. begin
  1233. if is_chararray(tcallparanode(hp).left.resulttype.def) then
  1234. tcallparanode(hp).gen_high_tree(true)
  1235. else
  1236. CGMessage(type_e_cant_read_write_type);
  1237. end;
  1238. else
  1239. CGMessage(type_e_cant_read_write_type);
  1240. end;
  1241. { some format options ? }
  1242. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  1243. begin
  1244. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  1245. begin
  1246. frac_para:=hp;
  1247. length_para:=tcallparanode(hp).right;
  1248. hp:=tcallparanode(hp).right;
  1249. hpp:=tcallparanode(hp).right;
  1250. end
  1251. else
  1252. begin
  1253. length_para:=hp;
  1254. frac_para:=nil;
  1255. hpp:=tcallparanode(hp).right;
  1256. end;
  1257. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  1258. if assigned(tcallparanode(hpp).left.resulttype.def) then
  1259. isreal:=(tcallparanode(hpp).left.resulttype.def.deftype=floatdef)
  1260. else exit;
  1261. if (not is_integer(tcallparanode(length_para).left.resulttype.def)) then
  1262. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype.def.typename)
  1263. else
  1264. tcallparanode(length_para).left:=ctypeconvnode.create(tcallparanode(length_para).left,s32bittype);
  1265. if assigned(frac_para) then
  1266. begin
  1267. if isreal then
  1268. begin
  1269. if (not is_integer(tcallparanode(frac_para).left.resulttype.def)) then
  1270. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype.def.typename)
  1271. else
  1272. tcallparanode(frac_para).left:=ctypeconvnode.create(tcallparanode(frac_para).left,s32bittype);
  1273. end
  1274. else
  1275. CGMessage(parser_e_illegal_colon_qualifier);
  1276. end;
  1277. { do the checking for the colon'd arg }
  1278. hp:=length_para;
  1279. end;
  1280. end;
  1281. hp:=tcallparanode(hp).right;
  1282. end;
  1283. end;
  1284. { pass all parameters again for the typeconversions }
  1285. if codegenerror then
  1286. exit;
  1287. tcallparanode(left).firstcallparan(nil,true);
  1288. set_varstate(left,true);
  1289. { calc registers }
  1290. left_max;
  1291. if extra_register then
  1292. inc(registers32);
  1293. end;
  1294. end;
  1295. in_settextbuf_file_x :
  1296. begin
  1297. { warning here left is the callparannode
  1298. not the argument directly }
  1299. { left.left is text var }
  1300. { left.right.left is the buffer var }
  1301. { firstcallparan(left,nil);
  1302. already done in firstcalln }
  1303. { now we know the type of buffer }
  1304. srsym:=searchsymonlyin(systemunit,'SETTEXTBUF');
  1305. hp:=ccallparanode.create(cordconstnode.create(tcallparanode(left).left.resulttype.def.size,s32bittype),left);
  1306. hp:=ccallnode.create(hp,tprocsym(srsym),systemunit,nil);
  1307. left:=nil;
  1308. firstpass(hp);
  1309. result:=hp;
  1310. end;
  1311. in_reset_typedfile,
  1312. in_rewrite_typedfile :
  1313. begin
  1314. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1315. end;
  1316. in_str_x_string :
  1317. begin
  1318. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1319. { first pass just the string for first local use }
  1320. hp:=tcallparanode(left).right;
  1321. tcallparanode(left).right:=nil;
  1322. tcallparanode(left).firstcallparan(nil,true);
  1323. { remove warning when result is passed }
  1324. set_funcret_is_valid(tcallparanode(left).left);
  1325. tcallparanode(left).right:=hp;
  1326. tcallparanode(tcallparanode(left).right).firstcallparan(nil,true);
  1327. set_varstate(tcallparanode(left).right,true);
  1328. hp:=left;
  1329. { valid string ? }
  1330. if not assigned(hp) or
  1331. (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) or
  1332. (tcallparanode(hp).right=nil) then
  1333. CGMessage(cg_e_illegal_expression);
  1334. { we need a var parameter }
  1335. valid_for_assign(tcallparanode(hp).left,false);
  1336. { generate the high() value for the shortstring }
  1337. if is_shortstring(tcallparanode(hp).left.resulttype.def) then
  1338. tcallparanode(hp).gen_high_tree(true);
  1339. { !!!! check length of string }
  1340. while assigned(tcallparanode(hp).right) do
  1341. hp:=tcallparanode(hp).right;
  1342. if not assigned(tcallparanode(hp).resulttype.def) then
  1343. exit;
  1344. { check and convert the first param }
  1345. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  1346. not assigned(hp.resulttype.def) then
  1347. CGMessage(cg_e_illegal_expression);
  1348. isreal:=false;
  1349. case hp.resulttype.def.deftype of
  1350. orddef :
  1351. begin
  1352. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  1353. u32bit,s32bit,
  1354. s64bit,u64bit:
  1355. ;
  1356. u8bit,s8bit,
  1357. u16bit,s16bit:
  1358. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,s32bittype);
  1359. else
  1360. CGMessage(type_e_integer_or_real_expr_expected);
  1361. end;
  1362. end;
  1363. floatdef :
  1364. begin
  1365. isreal:=true;
  1366. end;
  1367. else
  1368. CGMessage(type_e_integer_or_real_expr_expected);
  1369. end;
  1370. { some format options ? }
  1371. hpp:=tcallparanode(left).right;
  1372. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1373. begin
  1374. firstpass(tcallparanode(hpp).left);
  1375. set_varstate(tcallparanode(hpp).left,true);
  1376. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1377. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  1378. else
  1379. tcallparanode(hpp).left:=ctypeconvnode.create(tcallparanode(hpp).left,s32bittype);
  1380. hpp:=tcallparanode(hpp).right;
  1381. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1382. begin
  1383. if isreal then
  1384. begin
  1385. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1386. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  1387. else
  1388. begin
  1389. firstpass(tcallparanode(hpp).left);
  1390. set_varstate(tcallparanode(hpp).left,true);
  1391. tcallparanode(hpp).left:=ctypeconvnode.create(tcallparanode(hpp).left,s32bittype);
  1392. end;
  1393. end
  1394. else
  1395. CGMessage(parser_e_illegal_colon_qualifier);
  1396. end;
  1397. end;
  1398. { pass all parameters again for the typeconversions }
  1399. if codegenerror then
  1400. exit;
  1401. tcallparanode(left).firstcallparan(nil,true);
  1402. { calc registers }
  1403. left_max;
  1404. end;
  1405. in_val_x :
  1406. begin
  1407. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1408. resulttype:=voidtype;
  1409. { check the amount of parameters }
  1410. if not(assigned(left)) or
  1411. not(assigned(tcallparanode(left).right)) then
  1412. begin
  1413. CGMessage(parser_e_wrong_parameter_size);
  1414. exit;
  1415. end;
  1416. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1417. {there is a "code" parameter}
  1418. Begin
  1419. { first pass just the code parameter for first local use}
  1420. hp := tcallparanode(left).right;
  1421. tcallparanode(left).right := nil;
  1422. make_not_regable(tcallparanode(left).left);
  1423. tcallparanode(left).firstcallparan(nil,true);
  1424. set_varstate(left,false);
  1425. if codegenerror then exit;
  1426. tcallparanode(left).right := hp;
  1427. {code has to be a var parameter}
  1428. if valid_for_assign(tcallparanode(left).left,false) then
  1429. begin
  1430. if (tcallparanode(left).left.resulttype.def.deftype <> orddef) or
  1431. not(torddef(tcallparanode(left).left.resulttype.def).typ in
  1432. [u16bit,s16bit,u32bit,s32bit]) then
  1433. CGMessage(type_e_mismatch);
  1434. end;
  1435. hpp := tcallparanode(left).right
  1436. End
  1437. Else hpp := left;
  1438. {now hpp = the destination value tree}
  1439. { first pass just the destination parameter for first local use}
  1440. hp:=tcallparanode(hpp).right;
  1441. tcallparanode(hpp).right:=nil;
  1442. {hpp = destination}
  1443. make_not_regable(tcallparanode(hpp).left);
  1444. tcallparanode(hpp).firstcallparan(nil,true);
  1445. set_varstate(hpp,false);
  1446. if codegenerror then
  1447. exit;
  1448. { remove warning when result is passed }
  1449. set_funcret_is_valid(tcallparanode(hpp).left);
  1450. tcallparanode(hpp).right := hp;
  1451. if valid_for_assign(tcallparanode(hpp).left,false) then
  1452. begin
  1453. If Not((tcallparanode(hpp).left.resulttype.def.deftype = floatdef) or
  1454. ((tcallparanode(hpp).left.resulttype.def.deftype = orddef) And
  1455. (torddef(tcallparanode(hpp).left.resulttype.def).typ in
  1456. [u32bit,s32bit,
  1457. u8bit,s8bit,u16bit,s16bit,s64bit,u64bit]))) Then
  1458. CGMessage(type_e_mismatch);
  1459. end;
  1460. {hp = source (String)}
  1461. { count_ref := false; WHY ?? }
  1462. tcallparanode(hp).firstcallparan(nil,true);
  1463. set_varstate(hp,true);
  1464. if codegenerror then
  1465. exit;
  1466. { if not a stringdef then insert a type conv which
  1467. does the other type checking }
  1468. If (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) then
  1469. begin
  1470. tcallparanode(hp).left:=ctypeconvnode.create(tcallparanode(hp).left,cshortstringtype);
  1471. firstpass(tcallparanode(hp).left);
  1472. end;
  1473. { calc registers }
  1474. left_max;
  1475. { val doesn't calculate the registers really }
  1476. { correct, we need one register extra (FK) }
  1477. if is_64bitint(tcallparanode(hpp).left.resulttype.def) then
  1478. inc(registers32,2)
  1479. else
  1480. inc(registers32,1);
  1481. end;
  1482. in_include_x_y,
  1483. in_exclude_x_y:
  1484. begin
  1485. registers32:=left.registers32;
  1486. registersfpu:=left.registersfpu;
  1487. {$ifdef SUPPORT_MMX}
  1488. registersmmx:=left.registersmmx;
  1489. {$endif SUPPORT_MMX}
  1490. end;
  1491. in_low_x,
  1492. in_high_x:
  1493. internalerror(200104047);
  1494. in_cos_extended:
  1495. begin
  1496. location.loc:=LOC_FPU;
  1497. registers32:=left.registers32;
  1498. registersfpu:=left.registersfpu;
  1499. {$ifdef SUPPORT_MMX}
  1500. registersmmx:=left.registersmmx;
  1501. {$endif SUPPORT_MMX}
  1502. end;
  1503. in_sin_extended:
  1504. begin
  1505. location.loc:=LOC_FPU;
  1506. registers32:=left.registers32;
  1507. registersfpu:=left.registersfpu;
  1508. {$ifdef SUPPORT_MMX}
  1509. registersmmx:=left.registersmmx;
  1510. {$endif SUPPORT_MMX}
  1511. end;
  1512. in_arctan_extended:
  1513. begin
  1514. location.loc:=LOC_FPU;
  1515. registers32:=left.registers32;
  1516. registersfpu:=left.registersfpu;
  1517. {$ifdef SUPPORT_MMX}
  1518. registersmmx:=left.registersmmx;
  1519. {$endif SUPPORT_MMX}
  1520. end;
  1521. in_pi:
  1522. begin
  1523. location.loc:=LOC_FPU;
  1524. end;
  1525. in_abs_extended:
  1526. begin
  1527. location.loc:=LOC_FPU;
  1528. registers32:=left.registers32;
  1529. registersfpu:=left.registersfpu;
  1530. {$ifdef SUPPORT_MMX}
  1531. registersmmx:=left.registersmmx;
  1532. {$endif SUPPORT_MMX}
  1533. end;
  1534. in_sqr_extended:
  1535. begin
  1536. location.loc:=LOC_FPU;
  1537. registers32:=left.registers32;
  1538. registersfpu:=left.registersfpu;
  1539. {$ifdef SUPPORT_MMX}
  1540. registersmmx:=left.registersmmx;
  1541. {$endif SUPPORT_MMX}
  1542. end;
  1543. in_sqrt_extended:
  1544. begin
  1545. location.loc:=LOC_FPU;
  1546. registers32:=left.registers32;
  1547. registersfpu:=left.registersfpu;
  1548. {$ifdef SUPPORT_MMX}
  1549. registersmmx:=left.registersmmx;
  1550. {$endif SUPPORT_MMX}
  1551. end;
  1552. in_ln_extended:
  1553. begin
  1554. location.loc:=LOC_FPU;
  1555. registers32:=left.registers32;
  1556. registersfpu:=left.registersfpu;
  1557. {$ifdef SUPPORT_MMX}
  1558. registersmmx:=left.registersmmx;
  1559. {$endif SUPPORT_MMX}
  1560. end;
  1561. {$ifdef SUPPORT_MMX}
  1562. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1563. begin
  1564. end;
  1565. {$endif SUPPORT_MMX}
  1566. in_assert_x_y :
  1567. begin
  1568. { We've checked the whole statement for correctness, now we
  1569. can remove it if assertions are off }
  1570. if not(cs_do_assertion in aktlocalswitches) then
  1571. begin
  1572. { we need a valid node, so insert a nothingn }
  1573. result:=cnothingnode.create;
  1574. end
  1575. else
  1576. begin
  1577. registers32:=left.registers32;
  1578. registersfpu:=left.registersfpu;
  1579. {$ifdef SUPPORT_MMX}
  1580. registersmmx:=left.registersmmx;
  1581. {$endif SUPPORT_MMX}
  1582. end;
  1583. end;
  1584. else
  1585. internalerror(8);
  1586. end;
  1587. dec(parsing_para_level);
  1588. end;
  1589. {$ifdef fpc}
  1590. {$maxfpuregisters default}
  1591. {$endif fpc}
  1592. function tinlinenode.docompare(p: tnode): boolean;
  1593. begin
  1594. docompare :=
  1595. inherited docompare(p) and
  1596. (inlinenumber = tinlinenode(p).inlinenumber);
  1597. end;
  1598. begin
  1599. cinlinenode:=tinlinenode;
  1600. end.
  1601. {
  1602. $Log$
  1603. Revision 1.36 2001-04-13 01:22:09 peter
  1604. * symtable change to classes
  1605. * range check generation and errors fixed, make cycle DEBUG=1 works
  1606. * memory leaks fixed
  1607. Revision 1.35 2001/04/05 21:02:13 peter
  1608. * fixed fpu inline functions typeconvs
  1609. Revision 1.34 2001/04/04 22:42:40 peter
  1610. * move constant folding into det_resulttype
  1611. Revision 1.33 2001/04/04 21:30:43 florian
  1612. * applied several fixes to get the DD8 Delphi Unit compiled
  1613. e.g. "forward"-interfaces are working now
  1614. Revision 1.32 2001/04/02 21:20:31 peter
  1615. * resulttype rewrite
  1616. Revision 1.31 2001/03/23 00:16:07 florian
  1617. + some stuff to compile FreeCLX added
  1618. Revision 1.30 2001/03/12 12:47:46 michael
  1619. + Patches from peter
  1620. Revision 1.29 2001/03/03 12:38:08 jonas
  1621. * fixed low() for signed types < 64bit
  1622. Revision 1.28 2001/02/26 19:44:53 peter
  1623. * merged generic m68k updates from fixes branch
  1624. Revision 1.27 2001/02/22 11:24:40 jonas
  1625. * fixed bug in previous fix (hopped over revision 1.26 because that one
  1626. also removed the fix for high(cardinal))
  1627. Revision 1.26 2001/02/21 20:50:59 peter
  1628. * fix to compile again, but high(cardinal) with $R+ still fails!
  1629. Revision 1.25 2001/02/21 12:57:46 jonas
  1630. * fixed high/low for cardinal, int64 and qword
  1631. Revision 1.24 2001/01/06 19:54:11 peter
  1632. * merged fix for 1310
  1633. Revision 1.23 2001/01/06 18:28:39 peter
  1634. * fixed wrong notes about locals
  1635. Revision 1.22 2000/12/31 11:14:10 jonas
  1636. + implemented/fixed docompare() mathods for all nodes (not tested)
  1637. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  1638. and constant strings/chars together
  1639. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  1640. when adding
  1641. Revision 1.21 2000/12/25 00:07:26 peter
  1642. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1643. tlinkedlist objects)
  1644. Revision 1.20 2000/12/17 14:35:41 peter
  1645. * fixed crash with val()
  1646. Revision 1.19 2000/11/29 00:30:33 florian
  1647. * unused units removed from uses clause
  1648. * some changes for widestrings
  1649. Revision 1.18 2000/11/12 15:27:22 jonas
  1650. * also don't do conversion for chars/booleans (hopefully final change :/)
  1651. Revision 1.17 2000/11/11 21:08:13 jonas
  1652. * don't do inc/dec to add/sub conversion for enums
  1653. Revision 1.16 2000/11/11 16:18:35 peter
  1654. * ptr returns farpointer
  1655. Revision 1.15 2000/11/11 15:59:07 jonas
  1656. * convert inc/dec to add/sub when range/overflow checking is on
  1657. Revision 1.14 2000/11/09 17:46:54 florian
  1658. * System.TypeInfo fixed
  1659. + System.Finalize implemented
  1660. + some new keywords for interface support added
  1661. Revision 1.13 2000/11/04 16:48:32 florian
  1662. * innr.inc renamed to make compiler compilation easier because the rtl contains
  1663. a file of the same name
  1664. Revision 1.12 2000/10/31 22:02:48 peter
  1665. * symtable splitted, no real code changes
  1666. Revision 1.11 2000/10/26 14:15:06 jonas
  1667. * fixed setlength for shortstrings
  1668. Revision 1.10 2000/10/21 18:16:11 florian
  1669. * a lot of changes:
  1670. - basic dyn. array support
  1671. - basic C++ support
  1672. - some work for interfaces done
  1673. ....
  1674. Revision 1.9 2000/10/15 08:38:46 jonas
  1675. * added missing getcopy for previous addition
  1676. Revision 1.8 2000/10/14 18:27:53 jonas
  1677. * merged fix for inc/dec on 64bit types from tcinl
  1678. Revision 1.7 2000/10/14 10:14:50 peter
  1679. * moehrendorf oct 2000 rewrite
  1680. Revision 1.6 2000/10/01 19:48:24 peter
  1681. * lot of compile updates for cg11
  1682. Revision 1.5 2000/09/28 19:49:52 florian
  1683. *** empty log message ***
  1684. Revision 1.4 2000/09/28 16:34:47 florian
  1685. *** empty log message ***
  1686. Revision 1.3 2000/09/27 21:33:22 florian
  1687. * finally nadd.pas compiles
  1688. Revision 1.2 2000/09/27 20:25:44 florian
  1689. * more stuff fixed
  1690. Revision 1.1 2000/09/26 14:59:34 florian
  1691. * more conversion work done
  1692. }