ninl.pas 73 KB

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