ninl.pas 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  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;
  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. end;
  31. var
  32. cinlinenode : class of tinlinenode;
  33. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  34. implementation
  35. uses
  36. verbose,globals,systems,
  37. globtype,
  38. symconst,symtype,symdef,symsym,symtable,types,
  39. pass_1,
  40. ncal,ncon,ncnv,nadd,nld,nbas,
  41. cpubase,hcodegen,tgcpu
  42. {$ifdef newcg}
  43. ,cgbase
  44. {$endif newcg}
  45. ;
  46. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  47. begin
  48. geninlinenode:=cinlinenode.create(number,is_const,l);
  49. end;
  50. {*****************************************************************************
  51. TINLINENODE
  52. *****************************************************************************}
  53. constructor tinlinenode.create(number : byte;is_const:boolean;l : tnode);
  54. begin
  55. inherited create(inlinen,l);
  56. if is_const then
  57. include(flags,nf_inlineconst);
  58. inlinenumber:=number;
  59. end;
  60. function tinlinenode.getcopy : tnode;
  61. var
  62. n : tinlinenode;
  63. begin
  64. n:=tinlinenode(inherited getcopy);
  65. n.inlinenumber:=inlinenumber;
  66. result:=n;
  67. end;
  68. {$ifdef fpc}
  69. {$maxfpuregisters 0}
  70. {$endif fpc}
  71. function tinlinenode.pass_1 : tnode;
  72. var
  73. vl,vl2,counter : longint;
  74. vr : bestreal;
  75. p1,hp,hpp : tnode;
  76. ppn : tcallparanode;
  77. dummycoll: tparaitem;
  78. {$ifndef NOCOLONCHECK}
  79. frac_para,length_para : tnode;
  80. {$endif ndef NOCOLONCHECK}
  81. extra_register,
  82. isreal,
  83. iswrite,
  84. file_is_typed : boolean;
  85. function do_lowhigh(adef : pdef) : tnode;
  86. var
  87. v : longint;
  88. enum : penumsym;
  89. begin
  90. case Adef^.deftype of
  91. orddef:
  92. begin
  93. if inlinenumber=in_low_x then
  94. v:=porddef(adef)^.low
  95. else
  96. v:=porddef(adef)^.high;
  97. hp:=genordinalconstnode(v,adef);
  98. firstpass(hp);
  99. do_lowhigh:=hp;
  100. end;
  101. enumdef:
  102. begin
  103. enum:=penumsym(Penumdef(Adef)^.firstenum);
  104. if inlinenumber=in_high_x then
  105. while enum^.nextenum<>nil do
  106. enum:=enum^.nextenum;
  107. hp:=genenumnode(enum);
  108. do_lowhigh:=hp;
  109. end;
  110. else
  111. internalerror(87);
  112. end;
  113. end;
  114. function getconstrealvalue : bestreal;
  115. begin
  116. case left.nodetype of
  117. ordconstn:
  118. getconstrealvalue:=tordconstnode(left).value;
  119. realconstn:
  120. getconstrealvalue:=trealconstnode(left).value_real;
  121. else
  122. internalerror(309992);
  123. end;
  124. end;
  125. procedure setconstrealvalue(r : bestreal);
  126. var
  127. hp : tnode;
  128. begin
  129. hp:=genrealconstnode(r,bestrealdef^);
  130. firstpass(hp);
  131. pass_1:=hp;
  132. end;
  133. procedure handleextendedfunction;
  134. begin
  135. location.loc:=LOC_FPU;
  136. resulttype:=s80floatdef;
  137. { redo firstpass for varstate status PM }
  138. set_varstate(left,true);
  139. if (left.resulttype^.deftype<>floatdef) or
  140. (pfloatdef(left.resulttype)^.typ<>s80real) then
  141. begin
  142. left:=gentypeconvnode(left,s80floatdef);
  143. firstpass(left);
  144. end;
  145. registers32:=left.registers32;
  146. registersfpu:=left.registersfpu;
  147. {$ifdef SUPPORT_MMX}
  148. registersmmx:=left.registersmmx;
  149. {$endif SUPPORT_MMX}
  150. end;
  151. begin
  152. result:=nil;
  153. { if we handle writeln; left contains no valid address }
  154. if assigned(left) then
  155. begin
  156. if left.nodetype=callparan then
  157. tcallparanode(left).firstcallparan(nil,false)
  158. else
  159. firstpass(left);
  160. left_max;
  161. set_location(location,left.location);
  162. end;
  163. inc(parsing_para_level);
  164. { handle intern constant functions in separate case }
  165. if nf_inlineconst in flags then
  166. begin
  167. hp:=nil;
  168. { no parameters? }
  169. if not assigned(left) then
  170. begin
  171. case inlinenumber of
  172. in_const_pi :
  173. hp:=genrealconstnode(pi,bestrealdef^);
  174. else
  175. internalerror(89);
  176. end;
  177. end
  178. else
  179. { process constant expression with parameter }
  180. begin
  181. vl:=0;
  182. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  183. vr:=0;
  184. isreal:=false;
  185. case left.nodetype of
  186. realconstn :
  187. begin
  188. isreal:=true;
  189. vr:=trealconstnode(left).value_real;
  190. end;
  191. ordconstn :
  192. vl:=tordconstnode(left).value;
  193. callparan :
  194. begin
  195. { both exists, else it was not generated }
  196. vl:=tordconstnode(tcallparanode(left).left).value;
  197. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  198. end;
  199. else
  200. CGMessage(cg_e_illegal_expression);
  201. end;
  202. case inlinenumber of
  203. in_const_trunc :
  204. begin
  205. if isreal then
  206. begin
  207. if (vr>=2147483648.0) or (vr<=-2147483649.0) then
  208. begin
  209. CGMessage(parser_e_range_check_error);
  210. hp:=genordinalconstnode(1,s32bitdef)
  211. end
  212. else
  213. hp:=genordinalconstnode(trunc(vr),s32bitdef)
  214. end
  215. else
  216. hp:=genordinalconstnode(trunc(vl),s32bitdef);
  217. end;
  218. in_const_round :
  219. begin
  220. if isreal then
  221. begin
  222. if (vr>=2147483647.5) or (vr<=-2147483648.5) then
  223. begin
  224. CGMessage(parser_e_range_check_error);
  225. hp:=genordinalconstnode(1,s32bitdef)
  226. end
  227. else
  228. hp:=genordinalconstnode(round(vr),s32bitdef)
  229. end
  230. else
  231. hp:=genordinalconstnode(round(vl),s32bitdef);
  232. end;
  233. in_const_frac :
  234. begin
  235. if isreal then
  236. hp:=genrealconstnode(frac(vr),bestrealdef^)
  237. else
  238. hp:=genrealconstnode(frac(vl),bestrealdef^);
  239. end;
  240. in_const_int :
  241. begin
  242. if isreal then
  243. hp:=genrealconstnode(int(vr),bestrealdef^)
  244. else
  245. hp:=genrealconstnode(int(vl),bestrealdef^);
  246. end;
  247. in_const_abs :
  248. begin
  249. if isreal then
  250. hp:=genrealconstnode(abs(vr),bestrealdef^)
  251. else
  252. hp:=genordinalconstnode(abs(vl),left.resulttype);
  253. end;
  254. in_const_sqr :
  255. begin
  256. if isreal then
  257. hp:=genrealconstnode(sqr(vr),bestrealdef^)
  258. else
  259. hp:=genordinalconstnode(sqr(vl),left.resulttype);
  260. end;
  261. in_const_odd :
  262. begin
  263. if isreal then
  264. CGMessage1(type_e_integer_expr_expected,left.resulttype^.typename)
  265. else
  266. hp:=genordinalconstnode(byte(odd(vl)),booldef);
  267. end;
  268. in_const_swap_word :
  269. begin
  270. if isreal then
  271. CGMessage1(type_e_integer_expr_expected,left.resulttype^.typename)
  272. else
  273. hp:=genordinalconstnode((vl and $ff) shl 8+(vl shr 8),left.resulttype);
  274. end;
  275. in_const_swap_long :
  276. begin
  277. if isreal then
  278. CGMessage(type_e_mismatch)
  279. else
  280. hp:=genordinalconstnode((vl and $ffff) shl 16+(vl shr 16),left.resulttype);
  281. end;
  282. in_const_ptr :
  283. begin
  284. if isreal then
  285. CGMessage(type_e_mismatch)
  286. else
  287. hp:=genordinalconstnode((vl2 shl 4)+vl,voidfarpointerdef);
  288. end;
  289. in_const_sqrt :
  290. begin
  291. if isreal then
  292. begin
  293. if vr<0.0 then
  294. CGMessage(type_e_wrong_math_argument)
  295. else
  296. hp:=genrealconstnode(sqrt(vr),bestrealdef^)
  297. end
  298. else
  299. begin
  300. if vl<0 then
  301. CGMessage(type_e_wrong_math_argument)
  302. else
  303. hp:=genrealconstnode(sqrt(vl),bestrealdef^);
  304. end;
  305. end;
  306. in_const_arctan :
  307. begin
  308. if isreal then
  309. hp:=genrealconstnode(arctan(vr),bestrealdef^)
  310. else
  311. hp:=genrealconstnode(arctan(vl),bestrealdef^);
  312. end;
  313. in_const_cos :
  314. begin
  315. if isreal then
  316. hp:=genrealconstnode(cos(vr),bestrealdef^)
  317. else
  318. hp:=genrealconstnode(cos(vl),bestrealdef^);
  319. end;
  320. in_const_sin :
  321. begin
  322. if isreal then
  323. hp:=genrealconstnode(sin(vr),bestrealdef^)
  324. else
  325. hp:=genrealconstnode(sin(vl),bestrealdef^);
  326. end;
  327. in_const_exp :
  328. begin
  329. if isreal then
  330. hp:=genrealconstnode(exp(vr),bestrealdef^)
  331. else
  332. hp:=genrealconstnode(exp(vl),bestrealdef^);
  333. end;
  334. in_const_ln :
  335. begin
  336. if isreal then
  337. begin
  338. if vr<=0.0 then
  339. CGMessage(type_e_wrong_math_argument)
  340. else
  341. hp:=genrealconstnode(ln(vr),bestrealdef^)
  342. end
  343. else
  344. begin
  345. if vl<=0 then
  346. CGMessage(type_e_wrong_math_argument)
  347. else
  348. hp:=genrealconstnode(ln(vl),bestrealdef^);
  349. end;
  350. end;
  351. else
  352. internalerror(88);
  353. end;
  354. end;
  355. if hp=nil then
  356. hp:=tnode.create(errorn);
  357. firstpass(hp);
  358. result:=hp;
  359. end
  360. else
  361. begin
  362. case inlinenumber of
  363. in_lo_qword,
  364. in_hi_qword,
  365. in_lo_long,
  366. in_hi_long,
  367. in_lo_word,
  368. in_hi_word:
  369. begin
  370. set_varstate(left,true);
  371. if registers32<1 then
  372. registers32:=1;
  373. if inlinenumber in [in_lo_word,in_hi_word] then
  374. resulttype:=u8bitdef
  375. else if inlinenumber in [in_lo_qword,in_hi_qword] then
  376. begin
  377. resulttype:=u32bitdef;
  378. if (m_tp in aktmodeswitches) or
  379. (m_delphi in aktmodeswitches) then
  380. CGMessage(type_w_maybe_wrong_hi_lo);
  381. end
  382. else
  383. begin
  384. resulttype:=u16bitdef;
  385. if (m_tp in aktmodeswitches) or
  386. (m_delphi in aktmodeswitches) then
  387. CGMessage(type_w_maybe_wrong_hi_lo);
  388. end;
  389. location.loc:=LOC_REGISTER;
  390. if not is_integer(left.resulttype) then
  391. CGMessage(type_e_mismatch)
  392. else
  393. begin
  394. if left.nodetype=ordconstn then
  395. begin
  396. case inlinenumber of
  397. in_lo_word : hp:=genordinalconstnode(tordconstnode(left).value and $ff,left.resulttype);
  398. in_hi_word : hp:=genordinalconstnode(tordconstnode(left).value shr 8,left.resulttype);
  399. in_lo_long : hp:=genordinalconstnode(tordconstnode(left).value and $ffff,left.resulttype);
  400. in_hi_long : hp:=genordinalconstnode(tordconstnode(left).value shr 16,left.resulttype);
  401. in_lo_qword : hp:=genordinalconstnode(tordconstnode(left).value and $ffffffff,left.resulttype);
  402. in_hi_qword : hp:=genordinalconstnode(tordconstnode(left).value shr 32,left.resulttype);
  403. end;
  404. firstpass(hp);
  405. result:=hp;
  406. end;
  407. end;
  408. end;
  409. in_sizeof_x:
  410. begin
  411. set_varstate(left,false);
  412. if push_high_param(left.resulttype) then
  413. begin
  414. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  415. hp:=caddnode.create(addn,genloadnode(pvarsym(srsym),tloadnode(left).symtable),
  416. genordinalconstnode(1,s32bitdef));
  417. if (left.resulttype^.deftype=arraydef) and
  418. (parraydef(left.resulttype)^.elesize<>1) then
  419. hp:=caddnode.create(muln,hp,genordinalconstnode(parraydef(left.resulttype)^.elesize,s32bitdef));
  420. firstpass(hp);
  421. result:=hp;
  422. end
  423. else
  424. begin
  425. if registers32<1 then
  426. registers32:=1;
  427. resulttype:=s32bitdef;
  428. location.loc:=LOC_REGISTER;
  429. end;
  430. end;
  431. in_typeof_x:
  432. begin
  433. set_varstate(left,false);
  434. if registers32<1 then
  435. registers32:=1;
  436. location.loc:=LOC_REGISTER;
  437. resulttype:=voidpointerdef;
  438. end;
  439. in_ord_x:
  440. begin
  441. set_varstate(left,true);
  442. if (left.nodetype=ordconstn) then
  443. begin
  444. hp:=genordinalconstnode(tordconstnode(left).value,s32bitdef);
  445. firstpass(hp);
  446. result:=hp;
  447. end
  448. else
  449. begin
  450. { otherwise you get a crash if you try ord on an expression containing }
  451. { an undeclared variable (JM) }
  452. if not assigned(left.resulttype) then
  453. exit;
  454. if (left.resulttype^.deftype=orddef) then
  455. if (porddef(left.resulttype)^.typ in [uchar,uwidechar,bool8bit]) then
  456. case porddef(left.resulttype)^.typ of
  457. uchar:
  458. begin
  459. hp:=gentypeconvnode(left,u8bitdef);
  460. left:=nil;
  461. include(hp.flags,nf_explizit);
  462. firstpass(hp);
  463. result:=hp;
  464. end;
  465. uwidechar:
  466. begin
  467. hp:=gentypeconvnode(left,u16bitdef);
  468. left:=nil;
  469. include(hp.flags,nf_explizit);
  470. firstpass(hp);
  471. result:=hp;
  472. end;
  473. bool8bit:
  474. begin
  475. hp:=gentypeconvnode(left,u8bitdef);
  476. left:=nil;
  477. ttypeconvnode(hp).convtype:=tc_bool_2_int;
  478. include(hp.flags,nf_explizit);
  479. firstpass(hp);
  480. result:=hp;
  481. end
  482. end
  483. { can this happen ? }
  484. else if (porddef(left.resulttype)^.typ=uvoid) then
  485. CGMessage(type_e_mismatch)
  486. else
  487. { all other orddef need no transformation }
  488. begin
  489. hp:=left;
  490. left:=nil;
  491. result:=hp;
  492. end
  493. else if (left.resulttype^.deftype=enumdef) then
  494. begin
  495. hp:=gentypeconvnode(left,s32bitdef);
  496. left:=nil;
  497. include(hp.flags,nf_explizit);
  498. firstpass(hp);
  499. result:=hp;
  500. end
  501. else
  502. begin
  503. { can anything else be ord() ?}
  504. CGMessage(type_e_mismatch);
  505. end;
  506. end;
  507. end;
  508. in_chr_byte:
  509. begin
  510. set_varstate(left,true);
  511. hp:=gentypeconvnode(left,cchardef);
  512. left:=nil;
  513. include(hp.flags,nf_explizit);
  514. firstpass(hp);
  515. result:=hp;
  516. end;
  517. in_length_string:
  518. begin
  519. set_varstate(left,true);
  520. if is_ansistring(left.resulttype) then
  521. resulttype:=s32bitdef
  522. else
  523. resulttype:=u8bitdef;
  524. { we don't need string conversations here }
  525. if (left.nodetype=typeconvn) and
  526. (ttypeconvnode(left).left.resulttype^.deftype=stringdef) then
  527. begin
  528. hp:=ttypeconvnode(left).left;
  529. ttypeconvnode(left).left:=nil;
  530. left.free;
  531. left:=hp;
  532. end;
  533. { check the type, must be string or char }
  534. if (left.resulttype^.deftype<>stringdef) and
  535. (not is_char(left.resulttype)) then
  536. CGMessage(type_e_mismatch);
  537. { evaluates length of constant strings direct }
  538. if (left.nodetype=stringconstn) then
  539. begin
  540. hp:=genordinalconstnode(tstringconstnode(left).len,s32bitdef);
  541. firstpass(hp);
  542. result:=hp;
  543. end
  544. { length of char is one allways }
  545. else if is_constcharnode(left) then
  546. begin
  547. hp:=genordinalconstnode(1,s32bitdef);
  548. firstpass(hp);
  549. result:=hp;
  550. end;
  551. end;
  552. in_typeinfo_x:
  553. begin
  554. resulttype:=voidpointerdef;
  555. location.loc:=LOC_REGISTER;
  556. registers32:=1;
  557. end;
  558. in_assigned_x:
  559. begin
  560. set_varstate(left,true);
  561. resulttype:=booldef;
  562. location.loc:=LOC_FLAGS;
  563. end;
  564. in_ofs_x :
  565. internalerror(2000101001);
  566. in_seg_x :
  567. begin
  568. set_varstate(left,false);
  569. hp:=genordinalconstnode(0,s32bitdef);
  570. firstpass(hp);
  571. result:=hp;
  572. end;
  573. in_pred_x,
  574. in_succ_x:
  575. begin
  576. resulttype:=left.resulttype;
  577. if is_64bitint(resulttype) then
  578. begin
  579. if (registers32<2) then
  580. registers32:=2
  581. end
  582. else
  583. begin
  584. if (registers32<1) then
  585. registers32:=1;
  586. end;
  587. location.loc:=LOC_REGISTER;
  588. set_varstate(left,true);
  589. if not is_ordinal(resulttype) then
  590. CGMessage(type_e_ordinal_expr_expected)
  591. else
  592. begin
  593. if (resulttype^.deftype=enumdef) and
  594. (penumdef(resulttype)^.has_jumps) then
  595. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible)
  596. else
  597. if left.nodetype=ordconstn then
  598. begin
  599. if inlinenumber=in_succ_x then
  600. hp:=genordinalconstnode(tordconstnode(left).value+1,left.resulttype)
  601. else
  602. hp:=genordinalconstnode(tordconstnode(left).value-1,left.resulttype);
  603. firstpass(hp);
  604. result:=hp;
  605. end;
  606. end;
  607. end;
  608. in_setlength_x:
  609. begin
  610. resulttype:=voiddef;
  611. if assigned(left) then
  612. begin
  613. ppn:=tcallparanode(left);
  614. counter:=0;
  615. { check type }
  616. while assigned(ppn.right) do
  617. begin
  618. ppn.left:=gentypeconvnode(ppn.left,s32bitdef);
  619. firstpass(ppn.left);
  620. if codegenerror then
  621. exit;
  622. inc(counter);
  623. ppn:=tcallparanode(ppn.right);
  624. end;
  625. firstpass(ppn.left);
  626. if codegenerror then
  627. exit;
  628. { last param must be var }
  629. valid_for_assign(ppn.left,false);
  630. set_varstate(ppn.left,true);
  631. { first param must be a string or dynamic array ...}
  632. if not((ppn.left.resulttype^.deftype=stringdef) or
  633. (is_dynamic_array(ppn.left.resulttype))) then
  634. CGMessage(type_e_mismatch);
  635. { only dynamic arrays accept more dimensions }
  636. if (counter>1) and
  637. (not(is_dynamic_array(left.resulttype))) then
  638. CGMessage(type_e_mismatch);
  639. { convert shortstrings to openstring parameters }
  640. { (generate the hightree) (JM) }
  641. if (ppn.left.resulttype^.deftype = stringdef) and
  642. (pstringdef(ppn.left.resulttype)^.string_typ =
  643. st_shortstring) then
  644. begin
  645. dummycoll:=tparaitem.create;
  646. dummycoll.paratyp:=vs_var;
  647. dummycoll.paratype.setdef(openshortstringdef);
  648. tcallparanode(ppn).firstcallparan(dummycoll,false);
  649. if codegenerror then
  650. exit;
  651. end;
  652. end
  653. else
  654. CGMessage(type_e_mismatch);
  655. end;
  656. in_finalize_x:
  657. begin
  658. resulttype:=voiddef;
  659. if assigned(left) and assigned(tcallparanode(left).left) then
  660. begin
  661. firstpass(tcallparanode(left).left);
  662. if codegenerror then
  663. exit;
  664. { first param must be var }
  665. valid_for_assign(tcallparanode(left).left,false);
  666. set_varstate(tcallparanode(left).left,true);
  667. { two parameters? }
  668. if assigned(tcallparanode(left).right) then
  669. begin
  670. { the last parameter must be a longint }
  671. tcallparanode(tcallparanode(left).right).left:=
  672. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,s32bitdef);
  673. firstpass(tcallparanode(tcallparanode(left).right).left);
  674. if codegenerror then
  675. exit;
  676. end;
  677. end
  678. else
  679. CGMessage(type_e_mismatch);
  680. end;
  681. in_inc_x,
  682. in_dec_x:
  683. begin
  684. resulttype:=voiddef;
  685. if assigned(left) then
  686. begin
  687. tcallparanode(left).firstcallparan(nil,true);
  688. set_varstate(left,true);
  689. if codegenerror then
  690. exit;
  691. { first param must be var }
  692. valid_for_assign(tcallparanode(left).left,false);
  693. { check type }
  694. if is_64bitint(left.resulttype) or
  695. { range/overflow checking doesn't work properly }
  696. { with the inc/dec code that's generated (JM) }
  697. ((left.resulttype^.deftype = orddef) and
  698. not(is_char(left.resulttype)) and
  699. not(is_boolean(left.resulttype)) and
  700. (aktlocalswitches *
  701. [cs_check_overflow,cs_check_range] <> [])) then
  702. { convert to simple add (JM) }
  703. begin
  704. { extra parameter? }
  705. if assigned(tcallparanode(left).right) then
  706. begin
  707. { Yes, use for add node }
  708. hpp := tcallparanode(tcallparanode(left).right).left;
  709. tcallparanode(tcallparanode(left).right).left := nil;
  710. if assigned(tcallparanode(tcallparanode(left).right).right) then
  711. CGMessage(cg_e_illegal_expression);
  712. end
  713. else
  714. { no, create constant 1 }
  715. hpp := cordconstnode.create(1,s32bitdef);
  716. { addition/substraction depending on inc/dec }
  717. if inlinenumber = in_inc_x then
  718. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  719. else
  720. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  721. { assign result of addition }
  722. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  723. tcallparanode(left).left := nil;
  724. { firstpass it }
  725. firstpass(hpp);
  726. { return new node }
  727. pass_1 := hpp;
  728. dec(parsing_para_level);
  729. exit;
  730. end;
  731. if (left.resulttype^.deftype in [enumdef,pointerdef]) or
  732. is_ordinal(left.resulttype) then
  733. begin
  734. { two paras ? }
  735. if assigned(tcallparanode(left).right) then
  736. begin
  737. { insert a type conversion }
  738. { the second param is always longint }
  739. tcallparanode(tcallparanode(left).right).left:=
  740. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,s32bitdef);
  741. { check the type conversion }
  742. firstpass(tcallparanode(tcallparanode(left).right).left);
  743. { need we an additional register ? }
  744. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  745. (tcallparanode(tcallparanode(left).right).left.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  746. (tcallparanode(tcallparanode(left).right).left.registers32<=1) then
  747. inc(registers32);
  748. { do we need an additional register to restore the first parameter? }
  749. if tcallparanode(tcallparanode(left).right).left.registers32>=registers32 then
  750. inc(registers32);
  751. if assigned(tcallparanode(tcallparanode(left).right).right) then
  752. CGMessage(cg_e_illegal_expression);
  753. end;
  754. end
  755. else
  756. CGMessage(type_e_ordinal_expr_expected);
  757. end
  758. else
  759. CGMessage(type_e_mismatch);
  760. end;
  761. in_read_x,
  762. in_readln_x,
  763. in_write_x,
  764. in_writeln_x :
  765. begin
  766. { needs a call }
  767. procinfo^.flags:=procinfo^.flags or pi_do_call;
  768. resulttype:=voiddef;
  769. { true, if readln needs an extra register }
  770. extra_register:=false;
  771. { we must know if it is a typed file or not }
  772. { but we must first do the firstpass for it }
  773. file_is_typed:=false;
  774. if assigned(left) then
  775. begin
  776. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  777. tcallparanode(left).firstcallparan(nil,true);
  778. set_varstate(left,iswrite);
  779. { now we can check }
  780. hp:=left;
  781. while assigned(tcallparanode(hp).right) do
  782. hp:=tcallparanode(hp).right;
  783. { if resulttype is not assigned, then automatically }
  784. { file is not typed. }
  785. if assigned(hp) and assigned(hp.resulttype) then
  786. Begin
  787. if (hp.resulttype^.deftype=filedef) then
  788. if (pfiledef(hp.resulttype)^.filetyp=ft_untyped) then
  789. begin
  790. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  791. CGMessage(type_e_no_readln_writeln_for_typed_file)
  792. else
  793. CGMessage(type_e_no_read_write_for_untyped_file);
  794. end
  795. else if (pfiledef(hp.resulttype)^.filetyp=ft_typed) then
  796. begin
  797. file_is_typed:=true;
  798. { test the type }
  799. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  800. CGMessage(type_e_no_readln_writeln_for_typed_file);
  801. hpp:=left;
  802. while (hpp<>hp) do
  803. begin
  804. if (tcallparanode(hpp).left.nodetype=typen) then
  805. CGMessage(type_e_cant_read_write_type);
  806. if not is_equal(hpp.resulttype,pfiledef(hp.resulttype)^.typedfiletype.def) then
  807. CGMessage(type_e_mismatch);
  808. { generate the high() value for the shortstring }
  809. if ((not iswrite) and is_shortstring(tcallparanode(hpp).left.resulttype)) or
  810. (is_chararray(tcallparanode(hpp).left.resulttype)) then
  811. tcallparanode(hpp).gen_high_tree(true);
  812. { read(ln) is call by reference (JM) }
  813. if not iswrite then
  814. make_not_regable(tcallparanode(hpp).left);
  815. hpp:=tcallparanode(hpp).right;
  816. end;
  817. end;
  818. end; { endif assigned(hp) }
  819. { insert type conversions for write(ln) }
  820. if (not file_is_typed) then
  821. begin
  822. hp:=left;
  823. while assigned(hp) do
  824. begin
  825. incrementregisterpushed($ff);
  826. if (tcallparanode(hp).left.nodetype=typen) then
  827. CGMessage(type_e_cant_read_write_type);
  828. if assigned(tcallparanode(hp).left.resulttype) then
  829. begin
  830. isreal:=false;
  831. { support writeln(procvar) }
  832. if (tcallparanode(hp).left.resulttype^.deftype=procvardef) then
  833. begin
  834. p1:=gencallnode(nil,nil);
  835. tcallnode(p1).right:=tcallparanode(hp).left;
  836. p1.resulttype:=pprocvardef(tcallparanode(hp).left.resulttype)^.rettype.def;
  837. firstpass(p1);
  838. tcallparanode(hp).left:=p1;
  839. end;
  840. case tcallparanode(hp).left.resulttype^.deftype of
  841. filedef :
  842. begin
  843. { only allowed as first parameter }
  844. if assigned(tcallparanode(hp).right) then
  845. CGMessage(type_e_cant_read_write_type);
  846. end;
  847. stringdef :
  848. begin
  849. { generate the high() value for the shortstring }
  850. if (not iswrite) and
  851. is_shortstring(tcallparanode(hp).left.resulttype) then
  852. tcallparanode(hp).gen_high_tree(true);
  853. end;
  854. pointerdef :
  855. begin
  856. if not is_pchar(tcallparanode(hp).left.resulttype) then
  857. CGMessage(type_e_cant_read_write_type);
  858. end;
  859. floatdef :
  860. begin
  861. isreal:=true;
  862. end;
  863. orddef :
  864. begin
  865. case porddef(tcallparanode(hp).left.resulttype)^.typ of
  866. uchar,
  867. u32bit,s32bit,
  868. u64bit,s64bit:
  869. ;
  870. u8bit,s8bit,
  871. u16bit,s16bit :
  872. if iswrite then
  873. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,s32bitdef);
  874. bool8bit,
  875. bool16bit,
  876. bool32bit :
  877. if iswrite then
  878. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,booldef)
  879. else
  880. CGMessage(type_e_cant_read_write_type);
  881. else
  882. CGMessage(type_e_cant_read_write_type);
  883. end;
  884. if not(iswrite) and
  885. not(is_64bitint(tcallparanode(hp).left.resulttype)) then
  886. extra_register:=true;
  887. end;
  888. arraydef :
  889. begin
  890. if is_chararray(tcallparanode(hp).left.resulttype) then
  891. tcallparanode(hp).gen_high_tree(true)
  892. else
  893. CGMessage(type_e_cant_read_write_type);
  894. end;
  895. else
  896. CGMessage(type_e_cant_read_write_type);
  897. end;
  898. { some format options ? }
  899. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  900. begin
  901. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  902. begin
  903. frac_para:=hp;
  904. length_para:=tcallparanode(hp).right;
  905. hp:=tcallparanode(hp).right;
  906. hpp:=tcallparanode(hp).right;
  907. end
  908. else
  909. begin
  910. length_para:=hp;
  911. frac_para:=nil;
  912. hpp:=tcallparanode(hp).right;
  913. end;
  914. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  915. if assigned(tcallparanode(hpp).left.resulttype) then
  916. isreal:=(tcallparanode(hpp).left.resulttype^.deftype=floatdef)
  917. else exit;
  918. if (not is_integer(tcallparanode(length_para).left.resulttype)) then
  919. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype^.typename)
  920. else
  921. tcallparanode(length_para).left:=gentypeconvnode(tcallparanode(length_para).left,s32bitdef);
  922. if assigned(frac_para) then
  923. begin
  924. if isreal then
  925. begin
  926. if (not is_integer(tcallparanode(frac_para).left.resulttype)) then
  927. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype^.typename)
  928. else
  929. tcallparanode(frac_para).left:=gentypeconvnode(tcallparanode(frac_para).left,s32bitdef);
  930. end
  931. else
  932. CGMessage(parser_e_illegal_colon_qualifier);
  933. end;
  934. { do the checking for the colon'd arg }
  935. hp:=length_para;
  936. end;
  937. end;
  938. hp:=tcallparanode(hp).right;
  939. end;
  940. end;
  941. { pass all parameters again for the typeconversions }
  942. if codegenerror then
  943. exit;
  944. tcallparanode(left).firstcallparan(nil,true);
  945. set_varstate(left,true);
  946. { calc registers }
  947. left_max;
  948. if extra_register then
  949. inc(registers32);
  950. end;
  951. end;
  952. in_settextbuf_file_x :
  953. begin
  954. { warning here left is the callparannode
  955. not the argument directly }
  956. { left.left is text var }
  957. { left.right.left is the buffer var }
  958. { firstcallparan(left,nil);
  959. already done in firstcalln }
  960. { now we know the type of buffer }
  961. getsymonlyin(systemunit,'SETTEXTBUF');
  962. hp:=gencallnode(pprocsym(srsym),systemunit);
  963. tcallnode(hp).left:=gencallparanode(
  964. genordinalconstnode(tcallparanode(left).left.resulttype^.size,s32bitdef),left);
  965. left:=nil;
  966. firstpass(hp);
  967. result:=hp;
  968. end;
  969. { the firstpass of the arg has been done in firstcalln ? }
  970. in_reset_typedfile,
  971. in_rewrite_typedfile :
  972. begin
  973. procinfo^.flags:=procinfo^.flags or pi_do_call;
  974. firstpass(left);
  975. set_varstate(left,true);
  976. resulttype:=voiddef;
  977. end;
  978. in_str_x_string :
  979. begin
  980. procinfo^.flags:=procinfo^.flags or pi_do_call;
  981. resulttype:=voiddef;
  982. { check the amount of parameters }
  983. if not(assigned(left)) or
  984. not(assigned(tcallparanode(left).right)) then
  985. begin
  986. CGMessage(parser_e_wrong_parameter_size);
  987. exit;
  988. end;
  989. { first pass just the string for first local use }
  990. hp:=tcallparanode(left).right;
  991. tcallparanode(left).right:=nil;
  992. tcallparanode(left).firstcallparan(nil,true);
  993. set_varstate(left,false);
  994. { remove warning when result is passed }
  995. set_funcret_is_valid(tcallparanode(left).left);
  996. tcallparanode(left).right:=hp;
  997. tcallparanode(tcallparanode(left).right).firstcallparan(nil,true);
  998. set_varstate(tcallparanode(left).right,true);
  999. hp:=left;
  1000. { valid string ? }
  1001. if not assigned(hp) or
  1002. (tcallparanode(hp).left.resulttype^.deftype<>stringdef) or
  1003. (tcallparanode(hp).right=nil) then
  1004. CGMessage(cg_e_illegal_expression);
  1005. { we need a var parameter }
  1006. valid_for_assign(tcallparanode(hp).left,false);
  1007. { generate the high() value for the shortstring }
  1008. if is_shortstring(tcallparanode(hp).left.resulttype) then
  1009. tcallparanode(hp).gen_high_tree(true);
  1010. { !!!! check length of string }
  1011. while assigned(tcallparanode(hp).right) do
  1012. hp:=tcallparanode(hp).right;
  1013. if not assigned(tcallparanode(hp).resulttype) then
  1014. exit;
  1015. { check and convert the first param }
  1016. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  1017. not assigned(hp.resulttype) then
  1018. CGMessage(cg_e_illegal_expression);
  1019. isreal:=false;
  1020. case hp.resulttype^.deftype of
  1021. orddef :
  1022. begin
  1023. case porddef(tcallparanode(hp).left.resulttype)^.typ of
  1024. u32bit,s32bit,
  1025. s64bit,u64bit:
  1026. ;
  1027. u8bit,s8bit,
  1028. u16bit,s16bit:
  1029. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,s32bitdef);
  1030. else
  1031. CGMessage(type_e_integer_or_real_expr_expected);
  1032. end;
  1033. end;
  1034. floatdef :
  1035. begin
  1036. isreal:=true;
  1037. end;
  1038. else
  1039. CGMessage(type_e_integer_or_real_expr_expected);
  1040. end;
  1041. { some format options ? }
  1042. hpp:=tcallparanode(left).right;
  1043. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1044. begin
  1045. firstpass(tcallparanode(hpp).left);
  1046. set_varstate(tcallparanode(hpp).left,true);
  1047. if (not is_integer(tcallparanode(hpp).left.resulttype)) then
  1048. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype^.typename)
  1049. else
  1050. tcallparanode(hpp).left:=gentypeconvnode(tcallparanode(hpp).left,s32bitdef);
  1051. hpp:=tcallparanode(hpp).right;
  1052. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1053. begin
  1054. if isreal then
  1055. begin
  1056. if (not is_integer(tcallparanode(hpp).left.resulttype)) then
  1057. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype^.typename)
  1058. else
  1059. begin
  1060. firstpass(tcallparanode(hpp).left);
  1061. set_varstate(tcallparanode(hpp).left,true);
  1062. tcallparanode(hpp).left:=gentypeconvnode(tcallparanode(hpp).left,s32bitdef);
  1063. end;
  1064. end
  1065. else
  1066. CGMessage(parser_e_illegal_colon_qualifier);
  1067. end;
  1068. end;
  1069. { pass all parameters again for the typeconversions }
  1070. if codegenerror then
  1071. exit;
  1072. tcallparanode(left).firstcallparan(nil,true);
  1073. { calc registers }
  1074. left_max;
  1075. end;
  1076. in_val_x :
  1077. begin
  1078. procinfo^.flags:=procinfo^.flags or pi_do_call;
  1079. resulttype:=voiddef;
  1080. { check the amount of parameters }
  1081. if not(assigned(left)) or
  1082. not(assigned(tcallparanode(left).right)) then
  1083. begin
  1084. CGMessage(parser_e_wrong_parameter_size);
  1085. exit;
  1086. end;
  1087. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1088. {there is a "code" parameter}
  1089. Begin
  1090. { first pass just the code parameter for first local use}
  1091. hp := tcallparanode(left).right;
  1092. tcallparanode(left).right := nil;
  1093. make_not_regable(tcallparanode(left).left);
  1094. tcallparanode(left).firstcallparan(nil,true);
  1095. set_varstate(left,false);
  1096. if codegenerror then exit;
  1097. tcallparanode(left).right := hp;
  1098. {code has to be a var parameter}
  1099. if valid_for_assign(tcallparanode(left).left,false) then
  1100. begin
  1101. if (tcallparanode(left).left.resulttype^.deftype <> orddef) or
  1102. not(porddef(tcallparanode(left).left.resulttype)^.typ in
  1103. [u16bit,s16bit,u32bit,s32bit]) then
  1104. CGMessage(type_e_mismatch);
  1105. end;
  1106. hpp := tcallparanode(left).right
  1107. End
  1108. Else hpp := left;
  1109. {now hpp = the destination value tree}
  1110. { first pass just the destination parameter for first local use}
  1111. hp:=tcallparanode(hpp).right;
  1112. tcallparanode(hpp).right:=nil;
  1113. {hpp = destination}
  1114. make_not_regable(tcallparanode(hpp).left);
  1115. tcallparanode(hpp).firstcallparan(nil,true);
  1116. set_varstate(hpp,false);
  1117. if codegenerror then
  1118. exit;
  1119. { remove warning when result is passed }
  1120. set_funcret_is_valid(tcallparanode(hpp).left);
  1121. tcallparanode(hpp).right := hp;
  1122. if valid_for_assign(tcallparanode(hpp).left,false) then
  1123. begin
  1124. If Not((tcallparanode(hpp).left.resulttype^.deftype = floatdef) or
  1125. ((tcallparanode(hpp).left.resulttype^.deftype = orddef) And
  1126. (POrdDef(tcallparanode(hpp).left.resulttype)^.typ in
  1127. [u32bit,s32bit,
  1128. u8bit,s8bit,u16bit,s16bit,s64bit,u64bit]))) Then
  1129. CGMessage(type_e_mismatch);
  1130. end;
  1131. {hp = source (String)}
  1132. { count_ref := false; WHY ?? }
  1133. tcallparanode(hp).firstcallparan(nil,true);
  1134. set_varstate(hp,true);
  1135. if codegenerror then
  1136. exit;
  1137. { if not a stringdef then insert a type conv which
  1138. does the other type checking }
  1139. If (tcallparanode(hp).left.resulttype^.deftype<>stringdef) then
  1140. begin
  1141. tcallparanode(hp).left:=gentypeconvnode(tcallparanode(hp).left,cshortstringdef);
  1142. firstpass(tcallparanode(hp).left);
  1143. end;
  1144. { calc registers }
  1145. left_max;
  1146. { val doesn't calculate the registers really }
  1147. { correct, we need one register extra (FK) }
  1148. if is_64bitint(tcallparanode(hpp).left.resulttype) then
  1149. inc(registers32,2)
  1150. else
  1151. inc(registers32,1);
  1152. end;
  1153. in_include_x_y,
  1154. in_exclude_x_y:
  1155. begin
  1156. resulttype:=voiddef;
  1157. if assigned(left) then
  1158. begin
  1159. tcallparanode(left).firstcallparan(nil,true);
  1160. set_varstate(left,true);
  1161. registers32:=left.registers32;
  1162. registersfpu:=left.registersfpu;
  1163. {$ifdef SUPPORT_MMX}
  1164. registersmmx:=left.registersmmx;
  1165. {$endif SUPPORT_MMX}
  1166. { remove warning when result is passed }
  1167. set_funcret_is_valid(tcallparanode(left).left);
  1168. { first param must be var }
  1169. valid_for_assign(tcallparanode(left).left,false);
  1170. { check type }
  1171. if assigned(left.resulttype) and
  1172. (left.resulttype^.deftype=setdef) then
  1173. begin
  1174. { two paras ? }
  1175. if assigned(tcallparanode(left).right) then
  1176. begin
  1177. { insert a type conversion }
  1178. { to the type of the set elements }
  1179. tcallparanode(tcallparanode(left).right).left:=gentypeconvnode(
  1180. tcallparanode(tcallparanode(left).right).left,
  1181. psetdef(left.resulttype)^.elementtype.def);
  1182. { check the type conversion }
  1183. firstpass(tcallparanode(tcallparanode(left).right).left);
  1184. { only three parameters are allowed }
  1185. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1186. CGMessage(cg_e_illegal_expression);
  1187. end;
  1188. end
  1189. else
  1190. CGMessage(type_e_mismatch);
  1191. end
  1192. else
  1193. CGMessage(type_e_mismatch);
  1194. end;
  1195. in_low_x,
  1196. in_high_x:
  1197. begin
  1198. set_varstate(left,false);
  1199. { this fixes tests\webtbs\tbug879.pp (FK)
  1200. if left.nodetype in [typen,loadn,subscriptn] then
  1201. begin
  1202. }
  1203. case left.resulttype^.deftype of
  1204. orddef,enumdef:
  1205. begin
  1206. hp:=do_lowhigh(left.resulttype);
  1207. firstpass(hp);
  1208. result:=hp;
  1209. end;
  1210. setdef:
  1211. begin
  1212. hp:=do_lowhigh(Psetdef(left.resulttype)^.elementtype.def);
  1213. firstpass(hp);
  1214. result:=hp;
  1215. end;
  1216. arraydef:
  1217. begin
  1218. if inlinenumber=in_low_x then
  1219. begin
  1220. hp:=genordinalconstnode(Parraydef(left.resulttype)^.lowrange,
  1221. Parraydef(left.resulttype)^.rangetype.def);
  1222. firstpass(hp);
  1223. result:=hp;
  1224. end
  1225. else
  1226. begin
  1227. if is_open_array(left.resulttype) or
  1228. is_array_of_const(left.resulttype) then
  1229. begin
  1230. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  1231. hp:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
  1232. firstpass(hp);
  1233. result:=hp;
  1234. end
  1235. else
  1236. begin
  1237. hp:=genordinalconstnode(Parraydef(left.resulttype)^.highrange,
  1238. Parraydef(left.resulttype)^.rangetype.def);
  1239. firstpass(hp);
  1240. result:=hp;
  1241. end;
  1242. end;
  1243. end;
  1244. stringdef:
  1245. begin
  1246. if inlinenumber=in_low_x then
  1247. begin
  1248. hp:=genordinalconstnode(0,u8bitdef);
  1249. firstpass(hp);
  1250. result:=hp;
  1251. end
  1252. else
  1253. begin
  1254. if is_open_string(left.resulttype) then
  1255. begin
  1256. getsymonlyin(tloadnode(left).symtable,'high'+pvarsym(tloadnode(left).symtableentry)^.name);
  1257. hp:=genloadnode(pvarsym(srsym),tloadnode(left).symtable);
  1258. firstpass(hp);
  1259. result:=hp;
  1260. end
  1261. else
  1262. begin
  1263. hp:=genordinalconstnode(Pstringdef(left.resulttype)^.len,u8bitdef);
  1264. firstpass(hp);
  1265. result:=hp;
  1266. end;
  1267. end;
  1268. end;
  1269. else
  1270. CGMessage(type_e_mismatch);
  1271. end;
  1272. {
  1273. end
  1274. else
  1275. CGMessage(type_e_varid_or_typeid_expected);
  1276. }
  1277. end;
  1278. in_cos_extended:
  1279. begin
  1280. if left.nodetype in [ordconstn,realconstn] then
  1281. setconstrealvalue(cos(getconstrealvalue))
  1282. else
  1283. handleextendedfunction;
  1284. end;
  1285. in_sin_extended:
  1286. begin
  1287. if left.nodetype in [ordconstn,realconstn] then
  1288. setconstrealvalue(sin(getconstrealvalue))
  1289. else
  1290. handleextendedfunction;
  1291. end;
  1292. in_arctan_extended:
  1293. begin
  1294. if left.nodetype in [ordconstn,realconstn] then
  1295. setconstrealvalue(arctan(getconstrealvalue))
  1296. else
  1297. handleextendedfunction;
  1298. end;
  1299. in_pi:
  1300. if block_type=bt_const then
  1301. setconstrealvalue(pi)
  1302. else
  1303. begin
  1304. location.loc:=LOC_FPU;
  1305. resulttype:=s80floatdef;
  1306. end;
  1307. in_abs_extended:
  1308. begin
  1309. if left.nodetype in [ordconstn,realconstn] then
  1310. setconstrealvalue(abs(getconstrealvalue))
  1311. else
  1312. handleextendedfunction;
  1313. end;
  1314. in_sqr_extended:
  1315. begin
  1316. if left.nodetype in [ordconstn,realconstn] then
  1317. setconstrealvalue(sqr(getconstrealvalue))
  1318. else
  1319. handleextendedfunction;
  1320. end;
  1321. in_sqrt_extended:
  1322. begin
  1323. if left.nodetype in [ordconstn,realconstn] then
  1324. begin
  1325. vr:=getconstrealvalue;
  1326. if vr<0.0 then
  1327. begin
  1328. CGMessage(type_e_wrong_math_argument);
  1329. setconstrealvalue(0);
  1330. end
  1331. else
  1332. setconstrealvalue(sqrt(vr));
  1333. end
  1334. else
  1335. handleextendedfunction;
  1336. end;
  1337. in_ln_extended:
  1338. begin
  1339. if left.nodetype in [ordconstn,realconstn] then
  1340. begin
  1341. vr:=getconstrealvalue;
  1342. if vr<=0.0 then
  1343. begin
  1344. CGMessage(type_e_wrong_math_argument);
  1345. setconstrealvalue(0);
  1346. end
  1347. else
  1348. setconstrealvalue(ln(vr));
  1349. end
  1350. else
  1351. handleextendedfunction;
  1352. end;
  1353. {$ifdef SUPPORT_MMX}
  1354. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  1355. begin
  1356. end;
  1357. {$endif SUPPORT_MMX}
  1358. in_assert_x_y :
  1359. begin
  1360. resulttype:=voiddef;
  1361. if assigned(left) then
  1362. begin
  1363. tcallparanode(left).firstcallparan(nil,true);
  1364. set_varstate(left,true);
  1365. registers32:=left.registers32;
  1366. registersfpu:=left.registersfpu;
  1367. {$ifdef SUPPORT_MMX}
  1368. registersmmx:=left.registersmmx;
  1369. {$endif SUPPORT_MMX}
  1370. { check type }
  1371. if is_boolean(left.resulttype) then
  1372. begin
  1373. { must always be a string }
  1374. tcallparanode(tcallparanode(left).right).left:=
  1375. gentypeconvnode(tcallparanode(tcallparanode(left).right).left,cshortstringdef);
  1376. firstpass(tcallparanode(tcallparanode(left).right).left);
  1377. end
  1378. else
  1379. CGMessage(type_e_mismatch);
  1380. end
  1381. else
  1382. CGMessage(type_e_mismatch);
  1383. { We've checked the whole statement for correctness, now we
  1384. can remove it if assertions are off }
  1385. if not(cs_do_assertion in aktlocalswitches) then
  1386. { we need a valid node, so insert a nothingn }
  1387. result:=cnothingnode.create;
  1388. end;
  1389. else
  1390. internalerror(8);
  1391. end;
  1392. end;
  1393. { generate an error if no resulttype is set }
  1394. if not assigned(resulttype) then
  1395. resulttype:=generrordef;
  1396. { ... also if the node will be replaced }
  1397. if assigned(result) and
  1398. (not assigned(result.resulttype)) then
  1399. result.resulttype:=generrordef;
  1400. dec(parsing_para_level);
  1401. end;
  1402. {$ifdef fpc}
  1403. {$maxfpuregisters default}
  1404. {$endif fpc}
  1405. begin
  1406. cinlinenode:=tinlinenode;
  1407. end.
  1408. {
  1409. $Log$
  1410. Revision 1.21 2000-12-25 00:07:26 peter
  1411. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1412. tlinkedlist objects)
  1413. Revision 1.20 2000/12/17 14:35:41 peter
  1414. * fixed crash with val()
  1415. Revision 1.19 2000/11/29 00:30:33 florian
  1416. * unused units removed from uses clause
  1417. * some changes for widestrings
  1418. Revision 1.18 2000/11/12 15:27:22 jonas
  1419. * also don't do conversion for chars/booleans (hopefully final change :/)
  1420. Revision 1.17 2000/11/11 21:08:13 jonas
  1421. * don't do inc/dec to add/sub conversion for enums
  1422. Revision 1.16 2000/11/11 16:18:35 peter
  1423. * ptr returns farpointer
  1424. Revision 1.15 2000/11/11 15:59:07 jonas
  1425. * convert inc/dec to add/sub when range/overflow checking is on
  1426. Revision 1.14 2000/11/09 17:46:54 florian
  1427. * System.TypeInfo fixed
  1428. + System.Finalize implemented
  1429. + some new keywords for interface support added
  1430. Revision 1.13 2000/11/04 16:48:32 florian
  1431. * innr.inc renamed to make compiler compilation easier because the rtl contains
  1432. a file of the same name
  1433. Revision 1.12 2000/10/31 22:02:48 peter
  1434. * symtable splitted, no real code changes
  1435. Revision 1.11 2000/10/26 14:15:06 jonas
  1436. * fixed setlength for shortstrings
  1437. Revision 1.10 2000/10/21 18:16:11 florian
  1438. * a lot of changes:
  1439. - basic dyn. array support
  1440. - basic C++ support
  1441. - some work for interfaces done
  1442. ....
  1443. Revision 1.9 2000/10/15 08:38:46 jonas
  1444. * added missing getcopy for previous addition
  1445. Revision 1.8 2000/10/14 18:27:53 jonas
  1446. * merged fix for inc/dec on 64bit types from tcinl
  1447. Revision 1.7 2000/10/14 10:14:50 peter
  1448. * moehrendorf oct 2000 rewrite
  1449. Revision 1.6 2000/10/01 19:48:24 peter
  1450. * lot of compile updates for cg11
  1451. Revision 1.5 2000/09/28 19:49:52 florian
  1452. *** empty log message ***
  1453. Revision 1.4 2000/09/28 16:34:47 florian
  1454. *** empty log message ***
  1455. Revision 1.3 2000/09/27 21:33:22 florian
  1456. * finally nadd.pas compiles
  1457. Revision 1.2 2000/09/27 20:25:44 florian
  1458. * more stuff fixed
  1459. Revision 1.1 2000/09/26 14:59:34 florian
  1460. * more conversion work done
  1461. }