ninl.pas 115 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910
  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. {$ifdef hascompilerproc}
  33. private
  34. function handle_str: tnode;
  35. function handle_reset_rewrite_typed: tnode;
  36. function handle_read_write: tnode;
  37. function handle_val: tnode;
  38. {$endif hascompilerproc}
  39. end;
  40. var
  41. cinlinenode : class of tinlinenode;
  42. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  43. implementation
  44. uses
  45. verbose,globals,systems,
  46. globtype, cutils, aasm,
  47. symbase,symconst,symtype,symdef,symsym,symtable,types,
  48. pass_1,
  49. ncal,ncon,ncnv,nadd,nld,nbas,nflw,nmem,
  50. cpubase,hcodegen,tgcpu
  51. {$ifdef newcg}
  52. ,cgbase
  53. {$endif newcg}
  54. ;
  55. function geninlinenode(number : byte;is_const:boolean;l : tnode) : tinlinenode;
  56. begin
  57. geninlinenode:=cinlinenode.create(number,is_const,l);
  58. end;
  59. {*****************************************************************************
  60. TINLINENODE
  61. *****************************************************************************}
  62. constructor tinlinenode.create(number : byte;is_const:boolean;l : tnode);
  63. begin
  64. inherited create(inlinen,l);
  65. if is_const then
  66. include(flags,nf_inlineconst);
  67. inlinenumber:=number;
  68. end;
  69. function tinlinenode.getcopy : tnode;
  70. var
  71. n : tinlinenode;
  72. begin
  73. n:=tinlinenode(inherited getcopy);
  74. n.inlinenumber:=inlinenumber;
  75. result:=n;
  76. end;
  77. {$ifdef hascompilerproc}
  78. function tinlinenode.handle_str : tnode;
  79. var
  80. lenpara,
  81. fracpara,
  82. newparas,
  83. dest,
  84. source : tcallparanode;
  85. newnode : tnode;
  86. len,
  87. fraclen : longint;
  88. procname: string;
  89. is_real : boolean;
  90. begin
  91. result := cerrornode.create;
  92. { make sure we got at least two parameters (if we got only one, }
  93. { this parameter may not be encapsulated in a callparan) }
  94. if not assigned(left) or
  95. (left.nodetype <> callparan) then
  96. begin
  97. CGMessage(parser_e_wrong_parameter_size);
  98. exit;
  99. end;
  100. { get destination string }
  101. dest := tcallparanode(left);
  102. { get source para (number) }
  103. source := dest;
  104. while assigned(source.right) do
  105. source := tcallparanode(source.right);
  106. is_real := source.resulttype.def.deftype = floatdef;
  107. if not assigned(dest) or
  108. (dest.left.resulttype.def.deftype<>stringdef) or
  109. not(is_real or
  110. (source.left.resulttype.def.deftype = orddef)) then
  111. begin
  112. { the parser will give this message already because we }
  113. { return an errornode (JM) }
  114. { CGMessagePos(fileinfo,cg_e_illegal_expression); }
  115. exit;
  116. end;
  117. { get len/frac parameters }
  118. lenpara := nil;
  119. fracpara := nil;
  120. if (cpf_is_colon_para in tcallparanode(dest.right).callparaflags) then
  121. begin
  122. lenpara := tcallparanode(dest.right);
  123. { we can let the callnode do the type checking of these parameters too, }
  124. { but then the error messages aren't as nice }
  125. if not is_integer(lenpara.resulttype.def) then
  126. begin
  127. CGMessagePos1(lenpara.fileinfo,
  128. type_e_integer_expr_expected,lenpara.resulttype.def.typename);
  129. exit;
  130. end;
  131. if (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
  132. begin
  133. { parameters are in reverse order! }
  134. fracpara := lenpara;
  135. lenpara := tcallparanode(lenpara.right);
  136. if not is_real then
  137. begin
  138. CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
  139. exit
  140. end;
  141. if not is_integer(lenpara.resulttype.def) then
  142. begin
  143. CGMessagePos1(lenpara.fileinfo,
  144. type_e_integer_expr_expected,lenpara.resulttype.def.typename);
  145. exit;
  146. end;
  147. end;
  148. end;
  149. { generate the parameter list for the compilerproc }
  150. newparas := dest;
  151. { if we have a float parameter, insert the realtype, len and fracpara parameters }
  152. if is_real then
  153. begin
  154. { insert realtype parameter }
  155. newparas.right := ccallparanode.create(cordconstnode.create(
  156. ord(tfloatdef(source.left.resulttype.def).typ),s32bittype),newparas.right);
  157. { if necessary, insert a fraction parameter }
  158. if not assigned(fracpara) then
  159. begin
  160. tcallparanode(newparas.right).right := ccallparanode.create(
  161. cordconstnode.create(-1,s32bittype),tcallparanode(newparas.right).right);
  162. fracpara := tcallparanode(tcallparanode(newparas.right).right);
  163. end;
  164. { if necessary, insert a length para }
  165. if not assigned(lenpara) then
  166. fracpara.right := ccallparanode.create(cordconstnode.create(-32767,s32bittype),
  167. fracpara.right);
  168. end
  169. else
  170. { for a normal parameter, insert a only length parameter if one is missing }
  171. if not assigned(lenpara) then
  172. newparas.right := ccallparanode.create(cordconstnode.create(-1,s32bittype),
  173. newparas.right);
  174. { remove the parameters from the original node so they won't get disposed, }
  175. { since they're reused }
  176. left := nil;
  177. { create procedure name }
  178. procname := 'fpc_' + lower(tstringdef(dest.resulttype.def).stringtypname)+'_';
  179. if is_real then
  180. procname := procname + 'float'
  181. else
  182. case torddef(source.resulttype.def).typ of
  183. u32bit:
  184. procname := procname + 'cardinal';
  185. u64bit:
  186. procname := procname + 'qword';
  187. s64bit:
  188. procname := procname + 'int64';
  189. else
  190. procname := procname + 'longint';
  191. end;
  192. { create the call node, }
  193. newnode := ccallnode.createintern(procname,newparas);
  194. { resulttypepass it }
  195. resulttypepass(newnode);
  196. { and return it (but first free the errornode we generated in the beginning) }
  197. result.free;
  198. result := newnode;
  199. end;
  200. function tinlinenode.handle_reset_rewrite_typed: tnode;
  201. begin
  202. { since this is a "in_xxxx_typedfile" node, we can be sure we have }
  203. { a typed file as argument and we don't have to check it again (JM) }
  204. { add the recsize parameter }
  205. { note: for some reason, the parameter of intern procedures with only one }
  206. { parameter is gets lifted out of its original tcallparanode (see round }
  207. { line 1306 of ncal.pas), so recreate a tcallparanode here (JM) }
  208. left := ccallparanode.create(cordconstnode.create(
  209. tfiledef(left.resulttype.def).typedfiletype.def.size,s32bittype),
  210. ccallparanode.create(left,nil));
  211. { create the correct call }
  212. if inlinenumber=in_reset_typedfile then
  213. result := ccallnode.createintern('fpc_reset_typed',left)
  214. else
  215. result := ccallnode.createintern('fpc_rewrite_typed',left);
  216. firstpass(result);
  217. { make sure left doesn't get disposed, since we use it in the new call }
  218. left := nil;
  219. end;
  220. function tinlinenode.handle_read_write: tnode;
  221. const
  222. procnames: array[boolean,boolean] of string[11] =
  223. (('write_text_','read_text_'),('typed_write','typed_read'));
  224. var
  225. filepara,
  226. lenpara,
  227. fracpara,
  228. nextpara,
  229. para : tcallparanode;
  230. newstatement : tstatementnode;
  231. newblock : tblocknode;
  232. p1 : tnode;
  233. filetemp,
  234. temp : ttempcreatenode;
  235. tempref : ttemprefnode;
  236. procprefix,
  237. name : string[31];
  238. srsym : tsym;
  239. tempowner : tsymtable;
  240. restype : ^ttype;
  241. is_typed,
  242. do_read,
  243. is_real,
  244. error_para,
  245. found_error,
  246. is_ordinal : boolean;
  247. begin
  248. filepara := nil;
  249. is_typed := false;
  250. filetemp := nil;
  251. do_read := inlinenumber in [in_read_x,in_readln_x];
  252. { if we fail, we can quickly exit this way. We must generate something }
  253. { instead of the inline node, because firstpass will bomb with an }
  254. { internalerror if it encounters a read/write }
  255. result := cerrornode.create;
  256. { reverse the parameters (needed to get the colon parameters in the }
  257. { correct order when processing write(ln) }
  258. left := reverseparameters(tcallparanode(left));
  259. if assigned(left) then
  260. begin
  261. { check if we have a file parameter and if yes, what kind it is }
  262. filepara := tcallparanode(left);
  263. if (filepara.resulttype.def.deftype=filedef) then
  264. begin
  265. if (tfiledef(filepara.resulttype.def).filetyp=ft_untyped) then
  266. begin
  267. CGMessagePos(fileinfo,type_e_no_read_write_for_untyped_file);
  268. exit;
  269. end
  270. else
  271. begin
  272. if (tfiledef(filepara.resulttype.def).filetyp=ft_typed) then
  273. begin
  274. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  275. begin
  276. CGMessagePos(fileinfo,type_e_no_readln_writeln_for_typed_file);
  277. exit;
  278. end;
  279. is_typed := true;
  280. end
  281. end;
  282. end
  283. else
  284. filepara := nil;
  285. end;
  286. { create a blocknode in which the successive write/read statements will be }
  287. { put, since they belong together. Also create a dummy statement already to }
  288. { make inserting of additional statements easier }
  289. newstatement := cstatementnode.create(nil,cnothingnode.create);
  290. newblock := cblocknode.create(newstatement);
  291. { if we don't have a filepara, create one containing the default }
  292. if not assigned(filepara) then
  293. begin
  294. { create a loadnode for the standard input/output handle }
  295. if do_read then
  296. name := 'INPUT'
  297. else
  298. name := 'OUTPUT';
  299. { if we are compiling the system unit, the systemunit symtable is nil. }
  300. { however, if we aren't compiling the system unit, another unit could }
  301. { also have defined the INPUT or OUTPUT symbols. Therefore we need the }
  302. { separate cases (JM) }
  303. if not (cs_compilesystem in aktmoduleswitches) then
  304. begin
  305. srsym := searchsymonlyin(systemunit,name);
  306. tempowner := systemunit;
  307. end
  308. else
  309. searchsym(name,srsym,tempowner);
  310. if not assigned(srsym) then
  311. internalerror(200108141);
  312. { create the file parameter }
  313. filepara := ccallparanode.create(cloadnode.create(srsym,tempowner),nil);
  314. end
  315. else
  316. { remove filepara from the parameter chain }
  317. begin
  318. left := filepara.right;
  319. filepara.right := nil;
  320. { the file para is a var parameter, but it must be valid already }
  321. set_varstate(filepara,true);
  322. { check if we should make a temp to store the result of a complex }
  323. { expression (better heuristics, anyone?) (JM) }
  324. if (filepara.left.nodetype <> loadn) then
  325. begin
  326. { create a temp which will hold a pointer to the file }
  327. filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,true);
  328. { add it to the statements }
  329. newstatement.left := cstatementnode.create(nil,filetemp);
  330. newstatement := tstatementnode(newstatement.left);
  331. { make sure the resulttype of the temp (and as such of the }
  332. { temprefs coming after it) is set (necessary because the }
  333. { temprefs will be part of the filepara, of which we need }
  334. { the resulttype later on and temprefs can only be }
  335. { resulttypepassed if the resulttype of the temp is known) }
  336. resulttypepass(filetemp);
  337. { assign the address of the file to the temp }
  338. newstatement.left := cstatementnode.create(nil,
  339. cassignmentnode.create(ctemprefnode.create(filetemp),
  340. caddrnode.create(filepara.left)));
  341. newstatement := tstatementnode(newstatement.left);
  342. resulttypepass(newstatement.right);
  343. { create a new fileparameter as follows: file_type(temp^) }
  344. { (so that we pass the value and not the address of the temp }
  345. { to the read/write routine) }
  346. nextpara := ccallparanode.create(ctypeconvnode.create(
  347. cderefnode.create(ctemprefnode.create(filetemp)),filepara.left.resulttype),nil);
  348. { make sure the type conversion is explicit, otherwise this }
  349. { typecast won't work }
  350. nextpara.left.toggleflag(nf_explizit);
  351. { replace the old file para with the new one }
  352. filepara.left := nil;
  353. filepara.free;
  354. filepara := nextpara;
  355. { the resulttype of the filepara must be set since it's }
  356. { used below }
  357. filepara.get_paratype;
  358. end;
  359. end;
  360. { now, filepara is nowhere referenced anymore, so we can safely dispose it }
  361. { if something goes wrong or at the end of the procedure }
  362. { choose the correct procedure prefix }
  363. procprefix := 'fpc_'+procnames[is_typed,do_read];
  364. { we're going to reuse the paranodes, so make sure they don't get freed }
  365. { twice }
  366. para := tcallparanode(left);
  367. left := nil;
  368. { no errors found yet... }
  369. found_error := false;
  370. if is_typed then
  371. begin
  372. { add the typesize to the filepara }
  373. filepara.right := ccallparanode.create(cordconstnode.create(
  374. tfiledef(filepara.resulttype.def).typedfiletype.def.size,s32bittype),nil);
  375. { check for "no parameters" (you need at least one extra para for typed files) }
  376. if not assigned(para) then
  377. begin
  378. CGMessage(parser_e_wrong_parameter_size);
  379. found_error := true;
  380. end;
  381. { process all parameters }
  382. while assigned(para) do
  383. begin
  384. { check if valid parameter }
  385. if para.left.nodetype=typen then
  386. begin
  387. CGMessagePos(para.left.fileinfo,type_e_cant_read_write_type);
  388. found_error := true;
  389. end;
  390. if not is_equal(para.left.resulttype.def,tfiledef(filepara.resulttype.def).typedfiletype.def) then
  391. begin
  392. CGMessagePos(para.left.fileinfo,type_e_mismatch);
  393. found_error := true;
  394. end;
  395. if assigned(para.right) and
  396. (cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
  397. begin
  398. CGMessagePos(para.right.fileinfo,parser_e_illegal_colon_qualifier);
  399. { skip all colon para's }
  400. nextpara := tcallparanode(tcallparanode(para.right).right);
  401. while assigned(nextpara) and
  402. (cpf_is_colon_para in nextpara.callparaflags) do
  403. nextpara := tcallparanode(nextpara.right);
  404. found_error := true;
  405. end
  406. else
  407. { get next parameter }
  408. nextpara := tcallparanode(para.right);
  409. { add fileparameter }
  410. para.right := filepara.getcopy;
  411. { create call statment }
  412. { since the parameters are in the correct order, we have to insert }
  413. { the statements always at the end of the current block }
  414. newstatement.left := cstatementnode.create(nil,
  415. ccallnode.createintern(procprefix,para));
  416. newstatement := tstatementnode(newstatement.left);
  417. { process next parameter }
  418. para := nextpara;
  419. end;
  420. { free the file parameter }
  421. filepara.free;
  422. end
  423. else
  424. { text read/write }
  425. begin
  426. while assigned(para) do
  427. begin
  428. { is this parameter faulty? }
  429. error_para := false;
  430. { is this parameter an ordinal? }
  431. is_ordinal := false;
  432. { is this parameter a real? }
  433. is_real:=false;
  434. { can't read/write types }
  435. if para.left.nodetype=typen then
  436. begin
  437. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  438. error_para := true;
  439. end;
  440. { support writeln(procvar) }
  441. if (para.left.resulttype.def.deftype=procvardef) then
  442. begin
  443. p1:=ccallnode.create(nil,nil,nil,nil);
  444. tcallnode(p1).set_procvar(para.left);
  445. resulttypepass(p1);
  446. para.left:=p1;
  447. end;
  448. case para.left.resulttype.def.deftype of
  449. stringdef :
  450. begin
  451. name := procprefix+lower(tstringdef(para.left.resulttype.def).stringtypname);
  452. end;
  453. pointerdef :
  454. begin
  455. if not is_pchar(para.left.resulttype.def) then
  456. begin
  457. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  458. error_para := true;
  459. end
  460. else
  461. name := procprefix+'pchar_as_pointer';
  462. end;
  463. floatdef :
  464. begin
  465. is_real:=true;
  466. name := procprefix+'float';
  467. end;
  468. orddef :
  469. begin
  470. is_ordinal := true;
  471. case torddef(para.left.resulttype.def).typ of
  472. s8bit,s16bit,s32bit :
  473. name := procprefix+'sint';
  474. u8bit,u16bit,u32bit :
  475. name := procprefix+'uint';
  476. uchar :
  477. name := procprefix+'char';
  478. uwidechar :
  479. name := procprefix+'widechar';
  480. s64bit :
  481. name := procprefix+'int64';
  482. u64bit :
  483. name := procprefix+'qword';
  484. bool8bit,
  485. bool16bit,
  486. bool32bit :
  487. begin
  488. if do_read then
  489. begin
  490. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  491. error_para := true;
  492. end
  493. else
  494. name := procprefix+'boolean'
  495. end
  496. else
  497. begin
  498. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  499. error_para := true;
  500. end;
  501. end;
  502. end;
  503. arraydef :
  504. begin
  505. if is_chararray(para.left.resulttype.def) then
  506. name := procprefix+'pchar_as_array'
  507. else
  508. begin
  509. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  510. error_para := true;
  511. end
  512. end
  513. else
  514. begin
  515. CGMessagePos(para.fileinfo,type_e_cant_read_write_type);
  516. error_para := true;
  517. end
  518. end;
  519. { check for length/fractional colon para's }
  520. fracpara := nil;
  521. lenpara := nil;
  522. if assigned(para.right) and
  523. (cpf_is_colon_para in tcallparanode(para.right).callparaflags) then
  524. begin
  525. lenpara := tcallparanode(para.right);
  526. if assigned(lenpara.right) and
  527. (cpf_is_colon_para in tcallparanode(lenpara.right).callparaflags) then
  528. fracpara:=tcallparanode(lenpara.right);
  529. end;
  530. { get the next parameter now already, because we're going }
  531. { to muck around with the pointers }
  532. if assigned(fracpara) then
  533. nextpara := tcallparanode(fracpara.right)
  534. else if assigned(lenpara) then
  535. nextpara := tcallparanode(lenpara.right)
  536. else
  537. nextpara := tcallparanode(para.right);
  538. { check if a fracpara is allowed }
  539. if assigned(fracpara) and not is_real then
  540. begin
  541. CGMessagePos(fracpara.fileinfo,parser_e_illegal_colon_qualifier);
  542. error_para := true;
  543. end
  544. else if assigned(lenpara) and do_read then
  545. begin
  546. { I think this is already filtered out by parsing, but I'm not sure (JM) }
  547. CGMessagePos(lenpara.fileinfo,parser_e_illegal_colon_qualifier);
  548. error_para := true;
  549. end;
  550. { adjust found_error }
  551. found_error := found_error or error_para;
  552. if not error_para then
  553. begin
  554. { create dummy frac/len para's if necessary }
  555. if not do_read then
  556. begin
  557. { difference in default value for floats and the rest :( }
  558. if not is_real then
  559. begin
  560. if not assigned(lenpara) then
  561. lenpara := ccallparanode.create(cordconstnode.create(0,s32bittype),nil)
  562. else
  563. { make sure we don't pass the successive }
  564. { parameters too. We also already have a }
  565. { reference to the next parameter in }
  566. { nextpara }
  567. lenpara.right := nil;
  568. end
  569. else
  570. begin
  571. if not assigned(lenpara) then
  572. lenpara := ccallparanode.create(
  573. cordconstnode.create(-32767,s32bittype),nil);
  574. { also create a default fracpara if necessary }
  575. if not assigned(fracpara) then
  576. fracpara := ccallparanode.create(
  577. cordconstnode.create(-1,s32bittype),nil);
  578. { add it to the lenpara }
  579. lenpara.right := fracpara;
  580. { and add the realtype para (this also removes the link }
  581. { to any parameters coming after it) }
  582. fracpara.right := ccallparanode.create(
  583. cordconstnode.create(ord(tfloatdef(para.left.resulttype.def).typ),
  584. s32bittype),nil);
  585. end;
  586. end;
  587. if do_read and
  588. ((is_ordinal and
  589. (torddef(para.left.resulttype.def).typ in [s8bit,s16bit,u8bit,u16bit])
  590. ) or
  591. (is_real and
  592. not is_equal(para.left.resulttype.def,pbestrealtype^.def)
  593. )
  594. ) then
  595. { special handling of reading small numbers, because the helpers }
  596. { expect a longint/card/bestreal var parameter. Use a temp. can't }
  597. { use functions because then the call to FPC_IOCHECK destroys }
  598. { their result before we can store it }
  599. begin
  600. { get the resulttype of the var parameter of the helper }
  601. if is_real then
  602. restype := pbestrealtype
  603. else if is_signed(para.left.resulttype.def) then
  604. restype := @s32bittype
  605. else
  606. restype := @u32bittype;
  607. { create the parameter list: the temp ... }
  608. temp := ctempcreatenode.create(restype^,restype^.def.size,true);
  609. newstatement.left := cstatementnode.create(nil,temp);
  610. newstatement := tstatementnode(newstatement.left);
  611. { ... and the file }
  612. p1 := ccallparanode.create(ctemprefnode.create(temp),
  613. filepara.getcopy);
  614. { create the call to the helper }
  615. newstatement.left := cstatementnode.create(nil,
  616. ccallnode.createintern(name,tcallparanode(p1)));
  617. newstatement := tstatementnode(newstatement.left);
  618. { assign the result to the original var (this automatically }
  619. { takes care of range checking) }
  620. newstatement.left := cstatementnode.create(nil,
  621. cassignmentnode.create(para.left,
  622. ctemprefnode.create(temp)));
  623. newstatement := tstatementnode(newstatement.left);
  624. { release the temp location }
  625. newstatement.left := cstatementnode.create(nil,
  626. ctempdeletenode.create(temp));
  627. newstatement := tstatementnode(newstatement.left);
  628. { statement of para is used }
  629. para.left := nil;
  630. { free the enclosing tcallparanode, but not the }
  631. { parameters coming after it }
  632. para.right := nil;
  633. para.free;
  634. end
  635. else
  636. { read of non s/u-8/16bit, or a write }
  637. begin
  638. { add the filepara to the current parameter }
  639. para.right := filepara.getcopy;
  640. { add the lenpara (fracpara and realtype are already linked }
  641. { with it if necessary) }
  642. tcallparanode(para.right).right := lenpara;
  643. { create the call statement }
  644. newstatement.left := cstatementnode.create(nil,
  645. ccallnode.createintern(name,para));
  646. newstatement := tstatementnode(newstatement.left);
  647. end
  648. end
  649. else
  650. { error_para = true }
  651. begin
  652. { free the parameter, since it isn't referenced anywhere anymore }
  653. para.right := nil;
  654. para.free;
  655. if assigned(lenpara) then
  656. begin
  657. lenpara.right := nil;
  658. lenpara.free;
  659. end;
  660. if assigned(fracpara) then
  661. begin
  662. fracpara.right := nil;
  663. fracpara.free;
  664. end;
  665. end;
  666. { process next parameter }
  667. para := nextpara;
  668. end;
  669. { if no error, add the write(ln)/read(ln) end calls }
  670. if not found_error then
  671. begin
  672. case inlinenumber of
  673. in_read_x:
  674. newstatement.left := ccallnode.createintern('fpc_read_end',filepara);
  675. in_write_x:
  676. newstatement.left := ccallnode.createintern('fpc_write_end',filepara);
  677. in_readln_x:
  678. newstatement.left := ccallnode.createintern('fpc_readln_end',filepara);
  679. in_writeln_x:
  680. newstatement.left := ccallnode.createintern('fpc_writeln_end',filepara);
  681. end;
  682. newstatement.left := cstatementnode.create(nil,newstatement.left);
  683. newstatement := tstatementnode(newstatement.left);
  684. end;
  685. end;
  686. { if we found an error, simply delete the generated blocknode }
  687. if found_error then
  688. newblock.free
  689. else
  690. begin
  691. { deallocate the temp for the file para if we used one }
  692. if assigned(filetemp) then
  693. begin
  694. newstatement.left := cstatementnode.create(nil,
  695. ctempdeletenode.create(filetemp));
  696. newstatement := tstatementnode(newstatement.left);
  697. end;
  698. { otherwise return the newly generated block of instructions, }
  699. { but first free the errornode we generated at the beginning }
  700. result.free;
  701. resulttypepass(newblock);
  702. result := newblock
  703. end;
  704. end;
  705. function tinlinenode.handle_val: tnode;
  706. var
  707. procname,
  708. suffix : string[31];
  709. sourcepara,
  710. destpara,
  711. codepara,
  712. sizepara,
  713. newparas : tcallparanode;
  714. orgcode : tnode;
  715. newstatement : tstatementnode;
  716. newblock : tblocknode;
  717. tempcode : ttempcreatenode;
  718. begin
  719. { for easy exiting if something goes wrong }
  720. result := cerrornode.create;
  721. { check the amount of parameters }
  722. if not(assigned(left)) or
  723. not(assigned(tcallparanode(left).right)) then
  724. begin
  725. CGMessage(parser_e_wrong_parameter_size);
  726. exit;
  727. end;
  728. { reverse parameters for easier processing }
  729. left := reverseparameters(tcallparanode(left));
  730. { get the parameters }
  731. tempcode := nil;
  732. orgcode := nil;
  733. sizepara := nil;
  734. sourcepara := tcallparanode(left);
  735. destpara := tcallparanode(sourcepara.right);
  736. codepara := tcallparanode(destpara.right);
  737. { check if codepara is valid }
  738. if assigned(codepara) and
  739. ((codepara.resulttype.def.deftype <> orddef) or
  740. is_64bitint(codepara.resulttype.def)) then
  741. begin
  742. CGMessagePos(codepara.fileinfo,type_e_mismatch);
  743. exit;
  744. end;
  745. { check if dest para is valid }
  746. if not(destpara.resulttype.def.deftype in [orddef,floatdef]) then
  747. begin
  748. CGMessagePos(destpara.fileinfo,type_e_integer_or_real_expr_expected);
  749. exit;
  750. end;
  751. { we're going to reuse the exisiting para's, so make sure they }
  752. { won't be disposed }
  753. left := nil;
  754. { create the blocknode which will hold the generated statements + }
  755. { an initial dummy statement }
  756. newstatement := cstatementnode.create(nil,cnothingnode.create);
  757. newblock := cblocknode.create(newstatement);
  758. { do we need a temp for code? Yes, if no code specified, or if }
  759. { code is not a 32bit parameter (we already checked whether the }
  760. { the code para, if specified, was an orddef) }
  761. if not assigned(codepara) or
  762. (torddef(codepara.resulttype.def).typ in [u8bit,u16bit,s8bit,s16bit]) then
  763. begin
  764. tempcode := ctempcreatenode.create(s32bittype,4,true);
  765. newstatement.left := cstatementnode.create(nil,tempcode);
  766. newstatement := tstatementnode(newstatement.left);
  767. { set the resulttype of the temp (needed to be able to get }
  768. { the resulttype of the tempref used in the new code para) }
  769. resulttypepass(tempcode);
  770. { create a temp codepara, but save the original code para to }
  771. { assign the result to later on }
  772. if assigned(codepara) then
  773. orgcode := codepara.left
  774. else
  775. codepara := ccallparanode.create(nil,nil);
  776. codepara.left := ctemprefnode.create(tempcode);
  777. { we need its resulttype later on }
  778. codepara.get_paratype;
  779. end
  780. else if (torddef(codepara.resulttype.def).typ = u32bit) then
  781. { because code is a var parameter, it must match types exactly }
  782. { however, since it will return values in [0..255], both longints }
  783. { and cardinals are fine. Since the formal code para type is }
  784. { longint, insert a typecoversion to longint for cardinal para's }
  785. begin
  786. codepara.left := ctypeconvnode.create(codepara.left,s32bittype);
  787. codepara.get_paratype;
  788. end;
  789. { create the procedure name }
  790. procname := 'fpc_val_';
  791. case destpara.resulttype.def.deftype of
  792. orddef:
  793. begin
  794. case torddef(destpara.resulttype.def).typ of
  795. s8bit,s16bit,s32bit:
  796. begin
  797. suffix := 'sint_';
  798. { we also need a destsize para in this case }
  799. sizepara := ccallparanode.create(cordconstnode.create
  800. (destpara.resulttype.def.size,s32bittype),nil);
  801. end;
  802. u8bit,u16bit,u32bit:
  803. suffix := 'uint_';
  804. s64bit: suffix := 'int64_';
  805. u64bit: suffix := 'qword_';
  806. end;
  807. end;
  808. floatdef:
  809. begin
  810. suffix := 'real_';
  811. end;
  812. end;
  813. procname := procname + suffix;
  814. { play a trick to have tcallnode handle invalid source parameters: }
  815. { the shortstring-longint val routine by default }
  816. if (sourcepara.resulttype.def.deftype = stringdef) then
  817. procname := procname + lower(tstringdef(sourcepara.resulttype.def).stringtypname)
  818. else procname := procname + 'shortstr';
  819. { set up the correct parameters for the call: the code para... }
  820. newparas := codepara;
  821. { and the source para }
  822. codepara.right := sourcepara;
  823. { sizepara either contains nil if none is needed (which is ok, since }
  824. { then the next statement severes any possible links with other paras }
  825. { that sourcepara may have) or it contains the necessary size para and }
  826. { its right field is nil }
  827. sourcepara.right := sizepara;
  828. { create the call and assign the result to dest }
  829. { (val helpers are functions) }
  830. { the assignment will take care of rangechecking }
  831. newstatement.left := cstatementnode.create(nil,cassignmentnode.create(
  832. destpara.left,ccallnode.createintern(procname,newparas)));
  833. newstatement := tstatementnode(newstatement.left);
  834. { dispose of the enclosing paranode of the destination }
  835. destpara.left := nil;
  836. destpara.right := nil;
  837. destpara.free;
  838. { check if we used a temp for code and whether we have to store }
  839. { it to the real code parameter }
  840. if assigned(orgcode) then
  841. begin
  842. newstatement.left := cstatementnode.create(nil,cassignmentnode.create(
  843. orgcode,ctemprefnode.create(tempcode)));
  844. newstatement := tstatementnode(newstatement.left);
  845. end;
  846. { release the temp if we allocated one }
  847. if assigned(tempcode) then
  848. begin
  849. newstatement.left := cstatementnode.create(nil,
  850. ctempdeletenode.create(tempcode));
  851. newstatement := tstatementnode(newstatement.left);
  852. end;
  853. { free the errornode }
  854. result.free;
  855. { resulttypepass our new code }
  856. resulttypepass(newblock);
  857. { and return it }
  858. result := newblock;
  859. end;
  860. {$endif hascompilerproc}
  861. function tinlinenode.det_resulttype:tnode;
  862. function do_lowhigh(const t:ttype) : tnode;
  863. var
  864. v : tconstexprint;
  865. enum : tenumsym;
  866. hp : tnode;
  867. begin
  868. case t.def.deftype of
  869. orddef:
  870. begin
  871. if inlinenumber=in_low_x then
  872. v:=torddef(t.def).low
  873. else
  874. v:=torddef(t.def).high;
  875. { low/high of torddef are longints, so we need special }
  876. { handling for cardinal and 64bit types (JM) }
  877. { 1.0.x doesn't support int64($ffffffff) correct, it'll expand
  878. to -1 instead of staying $ffffffff. Therefor we use $ffff with
  879. shl twice (PFV) }
  880. if is_signed(t.def) and
  881. is_64bitint(t.def) then
  882. if (inlinenumber=in_low_x) then
  883. v := int64($80000000) shl 32
  884. else
  885. v := (int64($7fffffff) shl 32) or int64($ffff) shl 16 or int64($ffff)
  886. else
  887. if is_64bitint(t.def) then
  888. { we have to use a dirty trick for high(qword), }
  889. { because it's bigger than high(tconstexprint) (JM) }
  890. v := 0
  891. else
  892. if not is_signed(t.def) then
  893. v := cardinal(v);
  894. hp:=cordconstnode.create(v,t);
  895. resulttypepass(hp);
  896. { fix high(qword) }
  897. if not is_signed(t.def) and
  898. is_64bitint(t.def) and
  899. (inlinenumber = in_high_x) then
  900. tordconstnode(hp).value := -1; { is the same as qword($ffffffffffffffff) }
  901. do_lowhigh:=hp;
  902. end;
  903. enumdef:
  904. begin
  905. enum:=tenumsym(tenumdef(t.def).firstenum);
  906. v:=tenumdef(t.def).maxval;
  907. if inlinenumber=in_high_x then
  908. while assigned(enum) and (enum.value <> v) do
  909. enum:=enum.nextenum;
  910. if not assigned(enum) then
  911. internalerror(309993)
  912. else
  913. hp:=genenumnode(enum);
  914. do_lowhigh:=hp;
  915. end;
  916. else
  917. internalerror(87);
  918. end;
  919. end;
  920. function getconstrealvalue : bestreal;
  921. begin
  922. case left.nodetype of
  923. ordconstn:
  924. getconstrealvalue:=tordconstnode(left).value;
  925. realconstn:
  926. getconstrealvalue:=trealconstnode(left).value_real;
  927. else
  928. internalerror(309992);
  929. end;
  930. end;
  931. procedure setconstrealvalue(r : bestreal);
  932. var
  933. hp : tnode;
  934. begin
  935. hp:=crealconstnode.create(r,pbestrealtype^);
  936. resulttypepass(hp);
  937. result:=hp;
  938. end;
  939. var
  940. counter : longint;
  941. ppn : tcallparanode;
  942. dummycoll : tparaitem;
  943. vl,vl2 : longint;
  944. vr : bestreal;
  945. hp : tnode;
  946. srsym : tsym;
  947. p1,hpp : tnode;
  948. frac_para,
  949. length_para : tnode;
  950. isreal,
  951. iswrite,
  952. file_is_typed : boolean;
  953. label
  954. myexit;
  955. begin
  956. result:=nil;
  957. { if we handle writeln; left contains no valid address }
  958. if assigned(left) then
  959. begin
  960. if left.nodetype=callparan then
  961. tcallparanode(left).get_paratype
  962. else
  963. resulttypepass(left);
  964. end;
  965. inc(parsing_para_level);
  966. { handle intern constant functions in separate case }
  967. if nf_inlineconst in flags then
  968. begin
  969. { no parameters? }
  970. if not assigned(left) then
  971. begin
  972. case inlinenumber of
  973. in_const_pi :
  974. hp:=crealconstnode.create(pi,pbestrealtype^);
  975. else
  976. internalerror(89);
  977. end;
  978. end
  979. else
  980. begin
  981. vl:=0;
  982. vl2:=0; { second parameter Ex: ptr(vl,vl2) }
  983. vr:=0;
  984. isreal:=false;
  985. case left.nodetype of
  986. realconstn :
  987. begin
  988. isreal:=true;
  989. vr:=trealconstnode(left).value_real;
  990. end;
  991. ordconstn :
  992. vl:=tordconstnode(left).value;
  993. callparan :
  994. begin
  995. { both exists, else it was not generated }
  996. vl:=tordconstnode(tcallparanode(left).left).value;
  997. vl2:=tordconstnode(tcallparanode(tcallparanode(left).right).left).value;
  998. end;
  999. else
  1000. CGMessage(cg_e_illegal_expression);
  1001. end;
  1002. case inlinenumber of
  1003. in_const_trunc :
  1004. begin
  1005. if isreal then
  1006. begin
  1007. if (vr>=2147483648.0) or (vr<=-2147483649.0) then
  1008. begin
  1009. CGMessage(parser_e_range_check_error);
  1010. hp:=cordconstnode.create(1,s32bittype)
  1011. end
  1012. else
  1013. hp:=cordconstnode.create(trunc(vr),s32bittype)
  1014. end
  1015. else
  1016. hp:=cordconstnode.create(trunc(vl),s32bittype);
  1017. end;
  1018. in_const_round :
  1019. begin
  1020. if isreal then
  1021. begin
  1022. if (vr>=2147483647.5) or (vr<=-2147483648.5) then
  1023. begin
  1024. CGMessage(parser_e_range_check_error);
  1025. hp:=cordconstnode.create(1,s32bittype)
  1026. end
  1027. else
  1028. hp:=cordconstnode.create(round(vr),s32bittype)
  1029. end
  1030. else
  1031. hp:=cordconstnode.create(round(vl),s32bittype);
  1032. end;
  1033. in_const_frac :
  1034. begin
  1035. if isreal then
  1036. hp:=crealconstnode.create(frac(vr),pbestrealtype^)
  1037. else
  1038. hp:=crealconstnode.create(frac(vl),pbestrealtype^);
  1039. end;
  1040. in_const_int :
  1041. begin
  1042. if isreal then
  1043. hp:=crealconstnode.create(int(vr),pbestrealtype^)
  1044. else
  1045. hp:=crealconstnode.create(int(vl),pbestrealtype^);
  1046. end;
  1047. in_const_abs :
  1048. begin
  1049. if isreal then
  1050. hp:=crealconstnode.create(abs(vr),pbestrealtype^)
  1051. else
  1052. hp:=cordconstnode.create(abs(vl),left.resulttype);
  1053. end;
  1054. in_const_sqr :
  1055. begin
  1056. if isreal then
  1057. hp:=crealconstnode.create(sqr(vr),pbestrealtype^)
  1058. else
  1059. hp:=cordconstnode.create(sqr(vl),left.resulttype);
  1060. end;
  1061. in_const_odd :
  1062. begin
  1063. if isreal then
  1064. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1065. else
  1066. hp:=cordconstnode.create(byte(odd(vl)),booltype);
  1067. end;
  1068. in_const_swap_word :
  1069. begin
  1070. if isreal then
  1071. CGMessage1(type_e_integer_expr_expected,left.resulttype.def.typename)
  1072. else
  1073. hp:=cordconstnode.create((vl and $ff) shl 8+(vl shr 8),left.resulttype);
  1074. end;
  1075. in_const_swap_long :
  1076. begin
  1077. if isreal then
  1078. CGMessage(type_e_mismatch)
  1079. else
  1080. hp:=cordconstnode.create((vl and $ffff) shl 16+(vl shr 16),left.resulttype);
  1081. end;
  1082. in_const_ptr :
  1083. begin
  1084. if isreal then
  1085. CGMessage(type_e_mismatch)
  1086. else
  1087. hp:=cpointerconstnode.create((vl2 shl 4)+vl,voidfarpointertype);
  1088. end;
  1089. in_const_sqrt :
  1090. begin
  1091. if isreal then
  1092. begin
  1093. if vr<0.0 then
  1094. CGMessage(type_e_wrong_math_argument)
  1095. else
  1096. hp:=crealconstnode.create(sqrt(vr),pbestrealtype^)
  1097. end
  1098. else
  1099. begin
  1100. if vl<0 then
  1101. CGMessage(type_e_wrong_math_argument)
  1102. else
  1103. hp:=crealconstnode.create(sqrt(vl),pbestrealtype^);
  1104. end;
  1105. end;
  1106. in_const_arctan :
  1107. begin
  1108. if isreal then
  1109. hp:=crealconstnode.create(arctan(vr),pbestrealtype^)
  1110. else
  1111. hp:=crealconstnode.create(arctan(vl),pbestrealtype^);
  1112. end;
  1113. in_const_cos :
  1114. begin
  1115. if isreal then
  1116. hp:=crealconstnode.create(cos(vr),pbestrealtype^)
  1117. else
  1118. hp:=crealconstnode.create(cos(vl),pbestrealtype^);
  1119. end;
  1120. in_const_sin :
  1121. begin
  1122. if isreal then
  1123. hp:=crealconstnode.create(sin(vr),pbestrealtype^)
  1124. else
  1125. hp:=crealconstnode.create(sin(vl),pbestrealtype^);
  1126. end;
  1127. in_const_exp :
  1128. begin
  1129. if isreal then
  1130. hp:=crealconstnode.create(exp(vr),pbestrealtype^)
  1131. else
  1132. hp:=crealconstnode.create(exp(vl),pbestrealtype^);
  1133. end;
  1134. in_const_ln :
  1135. begin
  1136. if isreal then
  1137. begin
  1138. if vr<=0.0 then
  1139. CGMessage(type_e_wrong_math_argument)
  1140. else
  1141. hp:=crealconstnode.create(ln(vr),pbestrealtype^)
  1142. end
  1143. else
  1144. begin
  1145. if vl<=0 then
  1146. CGMessage(type_e_wrong_math_argument)
  1147. else
  1148. hp:=crealconstnode.create(ln(vl),pbestrealtype^);
  1149. end;
  1150. end;
  1151. else
  1152. internalerror(88);
  1153. end;
  1154. end;
  1155. if hp=nil then
  1156. hp:=tnode.create(errorn);
  1157. resulttypepass(hp);
  1158. result:=hp;
  1159. goto myexit;
  1160. end
  1161. else
  1162. begin
  1163. case inlinenumber of
  1164. in_lo_long,
  1165. in_hi_long,
  1166. in_lo_qword,
  1167. in_hi_qword,
  1168. in_lo_word,
  1169. in_hi_word :
  1170. begin
  1171. { give warning for incompatibility with tp and delphi }
  1172. if (inlinenumber in [in_lo_long,in_hi_long,in_lo_qword,in_hi_qword]) and
  1173. ((m_tp in aktmodeswitches) or
  1174. (m_delphi in aktmodeswitches)) then
  1175. CGMessage(type_w_maybe_wrong_hi_lo);
  1176. { constant folding }
  1177. if left.nodetype=ordconstn then
  1178. begin
  1179. case inlinenumber of
  1180. in_lo_word :
  1181. hp:=cordconstnode.create(tordconstnode(left).value and $ff,left.resulttype);
  1182. in_hi_word :
  1183. hp:=cordconstnode.create(tordconstnode(left).value shr 8,left.resulttype);
  1184. in_lo_long :
  1185. hp:=cordconstnode.create(tordconstnode(left).value and $ffff,left.resulttype);
  1186. in_hi_long :
  1187. hp:=cordconstnode.create(tordconstnode(left).value shr 16,left.resulttype);
  1188. in_lo_qword :
  1189. hp:=cordconstnode.create(tordconstnode(left).value and $ffffffff,left.resulttype);
  1190. in_hi_qword :
  1191. hp:=cordconstnode.create(tordconstnode(left).value shr 32,left.resulttype);
  1192. end;
  1193. resulttypepass(hp);
  1194. result:=hp;
  1195. goto myexit;
  1196. end;
  1197. set_varstate(left,true);
  1198. if not is_integer(left.resulttype.def) then
  1199. CGMessage(type_e_mismatch);
  1200. case inlinenumber of
  1201. in_lo_word,
  1202. in_hi_word :
  1203. resulttype:=u8bittype;
  1204. in_lo_long,
  1205. in_hi_long :
  1206. resulttype:=u16bittype;
  1207. in_lo_qword,
  1208. in_hi_qword :
  1209. resulttype:=u32bittype;
  1210. end;
  1211. end;
  1212. in_sizeof_x:
  1213. begin
  1214. set_varstate(left,false);
  1215. resulttype:=s32bittype;
  1216. end;
  1217. in_typeof_x:
  1218. begin
  1219. set_varstate(left,false);
  1220. resulttype:=voidpointertype;
  1221. end;
  1222. in_ord_x:
  1223. begin
  1224. if (left.nodetype=ordconstn) then
  1225. begin
  1226. hp:=cordconstnode.create(tordconstnode(left).value,s32bittype);
  1227. resulttypepass(hp);
  1228. result:=hp;
  1229. goto myexit;
  1230. end;
  1231. set_varstate(left,true);
  1232. case left.resulttype.def.deftype of
  1233. orddef :
  1234. begin
  1235. case torddef(left.resulttype.def).typ of
  1236. bool8bit,
  1237. uchar:
  1238. begin
  1239. { change to byte() }
  1240. hp:=ctypeconvnode.create(left,u8bittype);
  1241. left:=nil;
  1242. include(hp.flags,nf_explizit);
  1243. resulttypepass(hp);
  1244. result:=hp;
  1245. end;
  1246. bool16bit,
  1247. uwidechar :
  1248. begin
  1249. { change to word() }
  1250. hp:=ctypeconvnode.create(left,u16bittype);
  1251. left:=nil;
  1252. include(hp.flags,nf_explizit);
  1253. resulttypepass(hp);
  1254. result:=hp;
  1255. end;
  1256. bool32bit :
  1257. begin
  1258. { change to dword() }
  1259. hp:=ctypeconvnode.create(left,u32bittype);
  1260. left:=nil;
  1261. include(hp.flags,nf_explizit);
  1262. resulttypepass(hp);
  1263. result:=hp;
  1264. end;
  1265. uvoid :
  1266. CGMessage(type_e_mismatch)
  1267. else
  1268. begin
  1269. { all other orddef need no transformation }
  1270. hp:=left;
  1271. left:=nil;
  1272. result:=hp;
  1273. end;
  1274. end;
  1275. end;
  1276. enumdef :
  1277. begin
  1278. hp:=ctypeconvnode.create(left,s32bittype);
  1279. left:=nil;
  1280. include(hp.flags,nf_explizit);
  1281. resulttypepass(hp);
  1282. result:=hp;
  1283. end;
  1284. else
  1285. CGMessage(type_e_mismatch);
  1286. end;
  1287. end;
  1288. in_chr_byte:
  1289. begin
  1290. { convert to explicit char() }
  1291. set_varstate(left,true);
  1292. hp:=ctypeconvnode.create(left,cchartype);
  1293. include(hp.flags,nf_explizit);
  1294. left:=nil;
  1295. resulttypepass(hp);
  1296. result:=hp;
  1297. end;
  1298. in_length_x:
  1299. begin
  1300. set_varstate(left,true);
  1301. case left.resulttype.def.deftype of
  1302. stringdef :
  1303. begin
  1304. { we don't need string convertions here }
  1305. if (left.nodetype=typeconvn) and
  1306. (ttypeconvnode(left).left.resulttype.def.deftype=stringdef) then
  1307. begin
  1308. hp:=ttypeconvnode(left).left;
  1309. ttypeconvnode(left).left:=nil;
  1310. left.free;
  1311. left:=hp;
  1312. end;
  1313. { evaluates length of constant strings direct }
  1314. if (left.nodetype=stringconstn) then
  1315. begin
  1316. hp:=cordconstnode.create(tstringconstnode(left).len,s32bittype);
  1317. resulttypepass(hp);
  1318. result:=hp;
  1319. goto myexit;
  1320. end;
  1321. end;
  1322. orddef :
  1323. begin
  1324. { length of char is one allways }
  1325. if is_char(left.resulttype.def) or
  1326. is_widechar(left.resulttype.def) then
  1327. begin
  1328. hp:=cordconstnode.create(1,s32bittype);
  1329. resulttypepass(hp);
  1330. result:=hp;
  1331. goto myexit;
  1332. end
  1333. else
  1334. CGMessage(type_e_mismatch);
  1335. end;
  1336. arraydef :
  1337. begin
  1338. if is_open_array(left.resulttype.def) or
  1339. is_array_of_const(left.resulttype.def) then
  1340. begin
  1341. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  1342. hp:=caddnode.create(addn,cloadnode.create(tvarsym(srsym),tloadnode(left).symtable),
  1343. cordconstnode.create(1,s32bittype));
  1344. resulttypepass(hp);
  1345. result:=hp;
  1346. goto myexit;
  1347. end
  1348. else
  1349. if not is_dynamic_array(left.resulttype.def) then
  1350. begin
  1351. hp:=cordconstnode.create(tarraydef(left.resulttype.def).highrange-
  1352. tarraydef(left.resulttype.def).lowrange+1,
  1353. s32bittype);
  1354. resulttypepass(hp);
  1355. result:=hp;
  1356. goto myexit;
  1357. end;
  1358. end;
  1359. else
  1360. CGMessage(type_e_mismatch);
  1361. end;
  1362. { shortstring return an 8 bit value as the length
  1363. is the first byte of the string }
  1364. if is_shortstring(left.resulttype.def) then
  1365. resulttype:=u8bittype
  1366. else
  1367. resulttype:=s32bittype;
  1368. end;
  1369. in_typeinfo_x:
  1370. begin
  1371. set_varstate(left,true);
  1372. resulttype:=voidpointertype;
  1373. end;
  1374. in_assigned_x:
  1375. begin
  1376. set_varstate(left,true);
  1377. resulttype:=booltype;
  1378. end;
  1379. in_ofs_x :
  1380. internalerror(2000101001);
  1381. in_seg_x :
  1382. begin
  1383. set_varstate(left,false);
  1384. hp:=cordconstnode.create(0,s32bittype);
  1385. resulttypepass(hp);
  1386. result:=hp;
  1387. goto myexit;
  1388. end;
  1389. in_pred_x,
  1390. in_succ_x:
  1391. begin
  1392. set_varstate(left,true);
  1393. resulttype:=left.resulttype;
  1394. if not is_ordinal(resulttype.def) then
  1395. CGMessage(type_e_ordinal_expr_expected)
  1396. else
  1397. begin
  1398. if (resulttype.def.deftype=enumdef) and
  1399. (tenumdef(resulttype.def).has_jumps) then
  1400. CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
  1401. end;
  1402. { do constant folding after check for jumps }
  1403. if left.nodetype=ordconstn then
  1404. begin
  1405. if inlinenumber=in_succ_x then
  1406. hp:=cordconstnode.create(tordconstnode(left).value+1,left.resulttype)
  1407. else
  1408. hp:=cordconstnode.create(tordconstnode(left).value-1,left.resulttype);
  1409. resulttypepass(hp);
  1410. result:=hp;
  1411. end;
  1412. end;
  1413. in_setlength_x:
  1414. begin
  1415. resulttype:=voidtype;
  1416. if assigned(left) then
  1417. begin
  1418. ppn:=tcallparanode(left);
  1419. counter:=0;
  1420. { check type }
  1421. while assigned(ppn.right) do
  1422. begin
  1423. set_varstate(ppn.left,true);
  1424. inserttypeconv(ppn.left,s32bittype);
  1425. inc(counter);
  1426. ppn:=tcallparanode(ppn.right);
  1427. end;
  1428. { last param must be var }
  1429. valid_for_var(ppn.left);
  1430. set_varstate(ppn.left,false);
  1431. { first param must be a string or dynamic array ...}
  1432. if not((ppn.left.resulttype.def.deftype=stringdef) or
  1433. (is_dynamic_array(ppn.left.resulttype.def))) then
  1434. CGMessage(type_e_mismatch);
  1435. { only dynamic arrays accept more dimensions }
  1436. if (counter>1) and
  1437. (not(is_dynamic_array(left.resulttype.def))) then
  1438. CGMessage(type_e_mismatch);
  1439. { convert shortstrings to openstring parameters }
  1440. { (generate the hightree) (JM) }
  1441. if (ppn.left.resulttype.def.deftype = stringdef) and
  1442. (tstringdef(ppn.left.resulttype.def).string_typ =
  1443. st_shortstring) then
  1444. begin
  1445. dummycoll:=tparaitem.create;
  1446. dummycoll.paratyp:=vs_var;
  1447. dummycoll.paratype:=openshortstringtype;
  1448. tcallparanode(ppn).insert_typeconv(dummycoll,false);
  1449. dummycoll.destroy;
  1450. end;
  1451. end
  1452. else
  1453. CGMessage(type_e_mismatch);
  1454. end;
  1455. in_finalize_x:
  1456. begin
  1457. resulttype:=voidtype;
  1458. if assigned(left) and assigned(tcallparanode(left).left) then
  1459. begin
  1460. { first param must be var }
  1461. valid_for_var(tcallparanode(left).left);
  1462. set_varstate(tcallparanode(left).left,true);
  1463. { two parameters?, the last parameter must be a longint }
  1464. if assigned(tcallparanode(left).right) then
  1465. inserttypeconv(tcallparanode(tcallparanode(left).right).left,s32bittype);
  1466. end
  1467. else
  1468. CGMessage(type_e_mismatch);
  1469. end;
  1470. in_inc_x,
  1471. in_dec_x:
  1472. begin
  1473. resulttype:=voidtype;
  1474. if assigned(left) then
  1475. begin
  1476. set_varstate(left,true);
  1477. if codegenerror then
  1478. exit;
  1479. { first param must be var }
  1480. valid_for_var(tcallparanode(left).left);
  1481. if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  1482. is_ordinal(left.resulttype.def) then
  1483. begin
  1484. { two paras ? }
  1485. if assigned(tcallparanode(left).right) then
  1486. begin
  1487. { insert a type conversion }
  1488. { the second param is always longint }
  1489. inserttypeconv(tcallparanode(tcallparanode(left).right).left,s32bittype);
  1490. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1491. CGMessage(cg_e_illegal_expression);
  1492. end;
  1493. end
  1494. else
  1495. CGMessage(type_e_ordinal_expr_expected);
  1496. end
  1497. else
  1498. CGMessage(type_e_mismatch);
  1499. end;
  1500. in_read_x,
  1501. in_readln_x,
  1502. in_write_x,
  1503. in_writeln_x :
  1504. begin
  1505. {$ifdef hascompilerproc}
  1506. result := handle_read_write;
  1507. {$else hascompilerproc}
  1508. resulttype:=voidtype;
  1509. { we must know if it is a typed file or not }
  1510. { but we must first do the firstpass for it }
  1511. file_is_typed:=false;
  1512. if assigned(left) then
  1513. begin
  1514. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  1515. set_varstate(left,iswrite);
  1516. { now we can check }
  1517. hp:=left;
  1518. while assigned(tcallparanode(hp).right) do
  1519. hp:=tcallparanode(hp).right;
  1520. { if resulttype.def is not assigned, then automatically }
  1521. { file is not typed. }
  1522. if assigned(hp) and assigned(hp.resulttype.def) then
  1523. Begin
  1524. if (hp.resulttype.def.deftype=filedef) then
  1525. if (tfiledef(hp.resulttype.def).filetyp=ft_untyped) then
  1526. begin
  1527. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  1528. CGMessage(type_e_no_readln_writeln_for_typed_file)
  1529. else
  1530. CGMessage(type_e_no_read_write_for_untyped_file);
  1531. end
  1532. else if (tfiledef(hp.resulttype.def).filetyp=ft_typed) then
  1533. begin
  1534. file_is_typed:=true;
  1535. { test the type }
  1536. if (inlinenumber in [in_readln_x,in_writeln_x]) then
  1537. CGMessage(type_e_no_readln_writeln_for_typed_file);
  1538. hpp:=left;
  1539. while (hpp<>hp) do
  1540. begin
  1541. if (tcallparanode(hpp).left.nodetype=typen) then
  1542. CGMessage(type_e_cant_read_write_type);
  1543. if not is_equal(hpp.resulttype.def,tfiledef(hp.resulttype.def).typedfiletype.def) then
  1544. CGMessage(type_e_mismatch);
  1545. { generate the high() value for the shortstring }
  1546. if ((not iswrite) and is_shortstring(tcallparanode(hpp).left.resulttype.def)) or
  1547. (is_chararray(tcallparanode(hpp).left.resulttype.def)) then
  1548. tcallparanode(hpp).gen_high_tree(true);
  1549. { read(ln) is call by reference (JM) }
  1550. { and so is the data param of FPC_TYPED_WRITE (JM) }
  1551. if not iswrite or file_is_typed then
  1552. make_not_regable(tcallparanode(hpp).left);
  1553. hpp:=tcallparanode(hpp).right;
  1554. end;
  1555. end;
  1556. end; { endif assigned(hp) }
  1557. { insert type conversions for write(ln) }
  1558. if (not file_is_typed) then
  1559. begin
  1560. hp:=left;
  1561. while assigned(hp) do
  1562. begin
  1563. if (tcallparanode(hp).left.nodetype=typen) then
  1564. CGMessage(type_e_cant_read_write_type);
  1565. if assigned(tcallparanode(hp).left.resulttype.def) then
  1566. begin
  1567. isreal:=false;
  1568. { support writeln(procvar) }
  1569. if (tcallparanode(hp).left.resulttype.def.deftype=procvardef) then
  1570. begin
  1571. p1:=ccallnode.create(nil,nil,nil,nil);
  1572. tcallnode(p1).set_procvar(tcallparanode(hp).left);
  1573. resulttypepass(p1);
  1574. tcallparanode(hp).left:=p1;
  1575. end;
  1576. case tcallparanode(hp).left.resulttype.def.deftype of
  1577. filedef :
  1578. begin
  1579. { only allowed as first parameter }
  1580. if assigned(tcallparanode(hp).right) then
  1581. CGMessage(type_e_cant_read_write_type);
  1582. end;
  1583. stringdef :
  1584. begin
  1585. { generate the high() value for the shortstring }
  1586. if (not iswrite) and
  1587. is_shortstring(tcallparanode(hp).left.resulttype.def) then
  1588. tcallparanode(hp).gen_high_tree(true);
  1589. end;
  1590. pointerdef :
  1591. begin
  1592. if not is_pchar(tcallparanode(hp).left.resulttype.def) then
  1593. CGMessage(type_e_cant_read_write_type);
  1594. end;
  1595. floatdef :
  1596. begin
  1597. isreal:=true;
  1598. end;
  1599. orddef :
  1600. begin
  1601. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  1602. uchar,uwidechar,
  1603. u32bit,s32bit,
  1604. u64bit,s64bit:
  1605. ;
  1606. u8bit,s8bit,
  1607. u16bit,s16bit :
  1608. if iswrite then
  1609. inserttypeconv(tcallparanode(hp).left,s32bittype);
  1610. bool8bit,
  1611. bool16bit,
  1612. bool32bit :
  1613. if iswrite then
  1614. inserttypeconv(tcallparanode(hp).left,booltype)
  1615. else
  1616. CGMessage(type_e_cant_read_write_type);
  1617. else
  1618. CGMessage(type_e_cant_read_write_type);
  1619. end;
  1620. end;
  1621. arraydef :
  1622. begin
  1623. if is_chararray(tcallparanode(hp).left.resulttype.def) then
  1624. tcallparanode(hp).gen_high_tree(true)
  1625. else
  1626. CGMessage(type_e_cant_read_write_type);
  1627. end;
  1628. else
  1629. CGMessage(type_e_cant_read_write_type);
  1630. end;
  1631. { some format options ? }
  1632. if cpf_is_colon_para in tcallparanode(hp).callparaflags then
  1633. begin
  1634. if cpf_is_colon_para in tcallparanode(tcallparanode(hp).right).callparaflags then
  1635. begin
  1636. frac_para:=hp;
  1637. length_para:=tcallparanode(hp).right;
  1638. hp:=tcallparanode(hp).right;
  1639. hpp:=tcallparanode(hp).right;
  1640. end
  1641. else
  1642. begin
  1643. length_para:=hp;
  1644. frac_para:=nil;
  1645. hpp:=tcallparanode(hp).right;
  1646. end;
  1647. { can be nil if you use "write(e:0:6)" while e is undeclared (JM) }
  1648. if assigned(tcallparanode(hpp).left.resulttype.def) then
  1649. isreal:=(tcallparanode(hpp).left.resulttype.def.deftype=floatdef)
  1650. else
  1651. exit;
  1652. if (not is_integer(tcallparanode(length_para).left.resulttype.def)) then
  1653. CGMessage1(type_e_integer_expr_expected,tcallparanode(length_para).left.resulttype.def.typename)
  1654. else
  1655. inserttypeconv(tcallparanode(length_para).left,s32bittype);
  1656. if assigned(frac_para) then
  1657. begin
  1658. if isreal then
  1659. begin
  1660. if (not is_integer(tcallparanode(frac_para).left.resulttype.def)) then
  1661. CGMessage1(type_e_integer_expr_expected,tcallparanode(frac_para).left.resulttype.def.typename)
  1662. else
  1663. inserttypeconv(tcallparanode(frac_para).left,s32bittype);
  1664. end
  1665. else
  1666. CGMessage(parser_e_illegal_colon_qualifier);
  1667. end;
  1668. { do the checking for the colon'd arg }
  1669. hp:=length_para;
  1670. end;
  1671. end;
  1672. hp:=tcallparanode(hp).right;
  1673. end;
  1674. end;
  1675. if codegenerror then
  1676. exit;
  1677. set_varstate(left,true);
  1678. end;
  1679. {$endif hascompilerproc}
  1680. end;
  1681. in_settextbuf_file_x :
  1682. begin
  1683. resulttype:=voidtype;
  1684. { now we know the type of buffer }
  1685. srsym:=searchsymonlyin(systemunit,'SETTEXTBUF');
  1686. hp:=ccallparanode.create(cordconstnode.create(tcallparanode(left).left.resulttype.def.size,s32bittype),left);
  1687. hp:=ccallnode.create(hp,tprocsym(srsym),systemunit,nil);
  1688. left:=nil;
  1689. resulttypepass(hp);
  1690. result:=hp;
  1691. end;
  1692. { the firstpass of the arg has been done in firstcalln ? }
  1693. in_reset_typedfile,
  1694. in_rewrite_typedfile :
  1695. begin
  1696. {$ifdef hascompilerproc}
  1697. result := handle_reset_rewrite_typed;
  1698. {$else hascompilerproc}
  1699. set_varstate(left,true);
  1700. resulttype:=voidtype;
  1701. {$endif hascompilerproc}
  1702. end;
  1703. in_str_x_string :
  1704. begin
  1705. {$ifdef hascompilerproc}
  1706. result := handle_str;
  1707. {$else hascompilerproc}
  1708. resulttype:=voidtype;
  1709. set_varstate(left,false);
  1710. { remove warning when result is passed }
  1711. set_funcret_is_valid(tcallparanode(left).left);
  1712. set_varstate(tcallparanode(tcallparanode(left).right).left,true);
  1713. hp:=left;
  1714. { valid string ? }
  1715. if not assigned(hp) or
  1716. (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) or
  1717. (tcallparanode(hp).right=nil) then
  1718. CGMessage(cg_e_illegal_expression);
  1719. { we need a var parameter }
  1720. valid_for_var(tcallparanode(hp).left);
  1721. { with compilerproc's, this is not necessary anymore, the callnode }
  1722. { will convert it to an openstring itself if necessary (JM) }
  1723. { generate the high() value for the shortstring }
  1724. if is_shortstring(tcallparanode(hp).left.resulttype.def) then
  1725. tcallparanode(hp).gen_high_tree(true);
  1726. { !!!! check length of string }
  1727. while assigned(tcallparanode(hp).right) do
  1728. hp:=tcallparanode(hp).right;
  1729. if not assigned(tcallparanode(hp).resulttype.def) then
  1730. exit;
  1731. { check and convert the first param }
  1732. if (cpf_is_colon_para in tcallparanode(hp).callparaflags) or
  1733. not assigned(hp.resulttype.def) then
  1734. CGMessage(cg_e_illegal_expression);
  1735. isreal:=false;
  1736. case hp.resulttype.def.deftype of
  1737. orddef :
  1738. begin
  1739. case torddef(tcallparanode(hp).left.resulttype.def).typ of
  1740. u32bit,s32bit,
  1741. s64bit,u64bit:
  1742. ;
  1743. u8bit,s8bit,
  1744. u16bit,s16bit:
  1745. inserttypeconv(tcallparanode(hp).left,s32bittype);
  1746. else
  1747. CGMessage(type_e_integer_or_real_expr_expected);
  1748. end;
  1749. end;
  1750. floatdef :
  1751. begin
  1752. isreal:=true;
  1753. end;
  1754. else
  1755. CGMessage(type_e_integer_or_real_expr_expected);
  1756. end;
  1757. { some format options ? }
  1758. hpp:=tcallparanode(left).right;
  1759. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1760. begin
  1761. set_varstate(tcallparanode(hpp).left,true);
  1762. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1763. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  1764. else
  1765. inserttypeconv(tcallparanode(hpp).left,s32bittype);
  1766. hpp:=tcallparanode(hpp).right;
  1767. if assigned(hpp) and (cpf_is_colon_para in tcallparanode(hpp).callparaflags) then
  1768. begin
  1769. if isreal then
  1770. begin
  1771. if (not is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1772. CGMessage1(type_e_integer_expr_expected,tcallparanode(hpp).left.resulttype.def.typename)
  1773. else
  1774. begin
  1775. set_varstate(tcallparanode(hpp).left,true);
  1776. inserttypeconv(tcallparanode(hpp).left,s32bittype);
  1777. end;
  1778. end
  1779. else
  1780. CGMessage(parser_e_illegal_colon_qualifier);
  1781. end;
  1782. end;
  1783. {$endif hascompilerproc}
  1784. end;
  1785. in_val_x :
  1786. begin
  1787. {$ifdef hascompilerproc}
  1788. result := handle_val;
  1789. {$else hascompilerproc}
  1790. resulttype:=voidtype;
  1791. { check the amount of parameters }
  1792. if not(assigned(left)) or
  1793. not(assigned(tcallparanode(left).right)) then
  1794. begin
  1795. CGMessage(parser_e_wrong_parameter_size);
  1796. exit;
  1797. end;
  1798. { there is a "code" parameter }
  1799. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  1800. Begin
  1801. { first pass just the code parameter for first local use}
  1802. hp := tcallparanode(left).right;
  1803. tcallparanode(left).right := nil;
  1804. make_not_regable(tcallparanode(left).left);
  1805. set_varstate(left,false);
  1806. if codegenerror then
  1807. exit;
  1808. tcallparanode(left).right := hp;
  1809. { code has to be a var parameter }
  1810. if valid_for_var(tcallparanode(left).left) then
  1811. begin
  1812. if (tcallparanode(left).left.resulttype.def.deftype <> orddef) or
  1813. not(torddef(tcallparanode(left).left.resulttype.def).typ in [u16bit,s16bit,u32bit,s32bit]) then
  1814. CGMessage(type_e_mismatch);
  1815. end;
  1816. hpp := tcallparanode(left).right
  1817. End
  1818. Else
  1819. hpp := left;
  1820. { now hpp = the destination value tree }
  1821. { first pass just the destination parameter for first local use }
  1822. hp:=tcallparanode(hpp).right;
  1823. tcallparanode(hpp).right:=nil;
  1824. { hpp = destination }
  1825. make_not_regable(tcallparanode(hpp).left);
  1826. set_varstate(hpp,false);
  1827. if codegenerror then
  1828. exit;
  1829. { remove warning when result is passed }
  1830. set_funcret_is_valid(tcallparanode(hpp).left);
  1831. tcallparanode(hpp).right := hp;
  1832. if valid_for_var(tcallparanode(hpp).left) then
  1833. begin
  1834. If Not((tcallparanode(hpp).left.resulttype.def.deftype = floatdef) or
  1835. is_integer(tcallparanode(hpp).left.resulttype.def)) then
  1836. CGMessage(type_e_mismatch);
  1837. end;
  1838. { hp = source (String) }
  1839. { if not a stringdef then insert a type conv which
  1840. does the other type checking }
  1841. If (tcallparanode(hp).left.resulttype.def.deftype<>stringdef) then
  1842. inserttypeconv(tcallparanode(hp).left,cshortstringtype);
  1843. set_varstate(hp,true);
  1844. {$endif hascompilerproc}
  1845. end;
  1846. in_include_x_y,
  1847. in_exclude_x_y:
  1848. begin
  1849. resulttype:=voidtype;
  1850. if assigned(left) then
  1851. begin
  1852. set_varstate(left,true);
  1853. { remove warning when result is passed }
  1854. set_funcret_is_valid(tcallparanode(left).left);
  1855. { first param must be var }
  1856. valid_for_var(tcallparanode(left).left);
  1857. { check type }
  1858. if assigned(left.resulttype.def) and
  1859. (left.resulttype.def.deftype=setdef) then
  1860. begin
  1861. { two paras ? }
  1862. if assigned(tcallparanode(left).right) then
  1863. begin
  1864. { insert a type conversion }
  1865. { to the type of the set elements }
  1866. inserttypeconv(tcallparanode(tcallparanode(left).right).left,
  1867. tsetdef(left.resulttype.def).elementtype);
  1868. { only three parameters are allowed }
  1869. if assigned(tcallparanode(tcallparanode(left).right).right) then
  1870. CGMessage(cg_e_illegal_expression);
  1871. end;
  1872. end
  1873. else
  1874. CGMessage(type_e_mismatch);
  1875. end
  1876. else
  1877. CGMessage(type_e_mismatch);
  1878. end;
  1879. in_low_x,
  1880. in_high_x:
  1881. begin
  1882. set_varstate(left,false);
  1883. case left.resulttype.def.deftype of
  1884. orddef,
  1885. enumdef:
  1886. begin
  1887. hp:=do_lowhigh(left.resulttype);
  1888. resulttypepass(hp);
  1889. result:=hp;
  1890. end;
  1891. setdef:
  1892. begin
  1893. hp:=do_lowhigh(tsetdef(left.resulttype.def).elementtype);
  1894. resulttypepass(hp);
  1895. result:=hp;
  1896. end;
  1897. arraydef:
  1898. begin
  1899. if inlinenumber=in_low_x then
  1900. begin
  1901. hp:=cordconstnode.create(tarraydef(left.resulttype.def).lowrange,tarraydef(left.resulttype.def).rangetype);
  1902. resulttypepass(hp);
  1903. result:=hp;
  1904. end
  1905. else
  1906. begin
  1907. if is_open_array(left.resulttype.def) or
  1908. is_array_of_const(left.resulttype.def) then
  1909. begin
  1910. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  1911. hp:=cloadnode.create(tvarsym(srsym),tloadnode(left).symtable);
  1912. resulttypepass(hp);
  1913. result:=hp;
  1914. end
  1915. else
  1916. if is_dynamic_array(left.resulttype.def) then
  1917. begin
  1918. {$ifndef hascompilerproc}
  1919. writeln('Error: high(dynamic_array) isn''t implemented yet');
  1920. codegenerror := true;
  1921. {$else hascompilerproc}
  1922. { can't use inserttypeconv because we need }
  1923. { an explicit type conversion (JM) }
  1924. hp := ctypeconvnode.create(left,voidpointertype);
  1925. hp.toggleflag(nf_explizit);
  1926. hp := ccallparanode.create(hp,nil);
  1927. hp := ccallnode.createintern('fpc_dynarray_high',hp);
  1928. { make sure the left node doesn't get disposed, since it's }
  1929. { reused in the new node (JM) }
  1930. left:=nil;
  1931. resulttypepass(hp);
  1932. result:=hp;
  1933. {$endif hascompilerproc}
  1934. end
  1935. else
  1936. begin
  1937. hp:=cordconstnode.create(tarraydef(left.resulttype.def).highrange,tarraydef(left.resulttype.def).rangetype);
  1938. resulttypepass(hp);
  1939. result:=hp;
  1940. end;
  1941. end;
  1942. end;
  1943. stringdef:
  1944. begin
  1945. if inlinenumber=in_low_x then
  1946. begin
  1947. hp:=cordconstnode.create(0,u8bittype);
  1948. resulttypepass(hp);
  1949. result:=hp;
  1950. end
  1951. else
  1952. begin
  1953. if is_open_string(left.resulttype.def) then
  1954. begin
  1955. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  1956. hp:=cloadnode.create(tvarsym(srsym),tloadnode(left).symtable);
  1957. resulttypepass(hp);
  1958. result:=hp;
  1959. end
  1960. else
  1961. begin
  1962. hp:=cordconstnode.create(tstringdef(left.resulttype.def).len,u8bittype);
  1963. resulttypepass(hp);
  1964. result:=hp;
  1965. end;
  1966. end;
  1967. end;
  1968. else
  1969. CGMessage(type_e_mismatch);
  1970. end;
  1971. end;
  1972. in_pi:
  1973. begin
  1974. if block_type=bt_const then
  1975. setconstrealvalue(pi)
  1976. else
  1977. resulttype:=s80floattype;
  1978. end;
  1979. in_cos_extended :
  1980. begin
  1981. if left.nodetype in [ordconstn,realconstn] then
  1982. setconstrealvalue(cos(getconstrealvalue))
  1983. else
  1984. begin
  1985. set_varstate(left,true);
  1986. inserttypeconv(left,s80floattype);
  1987. resulttype:=s80floattype;
  1988. end;
  1989. end;
  1990. in_sin_extended :
  1991. begin
  1992. if left.nodetype in [ordconstn,realconstn] then
  1993. setconstrealvalue(sin(getconstrealvalue))
  1994. else
  1995. begin
  1996. set_varstate(left,true);
  1997. inserttypeconv(left,s80floattype);
  1998. resulttype:=s80floattype;
  1999. end;
  2000. end;
  2001. in_arctan_extended :
  2002. begin
  2003. if left.nodetype in [ordconstn,realconstn] then
  2004. setconstrealvalue(arctan(getconstrealvalue))
  2005. else
  2006. begin
  2007. set_varstate(left,true);
  2008. inserttypeconv(left,s80floattype);
  2009. resulttype:=s80floattype;
  2010. end;
  2011. end;
  2012. in_abs_extended :
  2013. begin
  2014. if left.nodetype in [ordconstn,realconstn] then
  2015. setconstrealvalue(abs(getconstrealvalue))
  2016. else
  2017. begin
  2018. set_varstate(left,true);
  2019. inserttypeconv(left,s80floattype);
  2020. resulttype:=s80floattype;
  2021. end;
  2022. end;
  2023. in_sqr_extended :
  2024. begin
  2025. if left.nodetype in [ordconstn,realconstn] then
  2026. setconstrealvalue(sqr(getconstrealvalue))
  2027. else
  2028. begin
  2029. set_varstate(left,true);
  2030. inserttypeconv(left,s80floattype);
  2031. resulttype:=s80floattype;
  2032. end;
  2033. end;
  2034. in_sqrt_extended :
  2035. begin
  2036. if left.nodetype in [ordconstn,realconstn] then
  2037. begin
  2038. vr:=getconstrealvalue;
  2039. if vr<0.0 then
  2040. begin
  2041. CGMessage(type_e_wrong_math_argument);
  2042. setconstrealvalue(0);
  2043. end
  2044. else
  2045. setconstrealvalue(sqrt(vr));
  2046. end
  2047. else
  2048. begin
  2049. set_varstate(left,true);
  2050. inserttypeconv(left,s80floattype);
  2051. resulttype:=s80floattype;
  2052. end;
  2053. end;
  2054. in_ln_extended :
  2055. begin
  2056. if left.nodetype in [ordconstn,realconstn] then
  2057. begin
  2058. vr:=getconstrealvalue;
  2059. if vr<=0.0 then
  2060. begin
  2061. CGMessage(type_e_wrong_math_argument);
  2062. setconstrealvalue(0);
  2063. end
  2064. else
  2065. setconstrealvalue(ln(vr));
  2066. end
  2067. else
  2068. begin
  2069. set_varstate(left,true);
  2070. inserttypeconv(left,s80floattype);
  2071. resulttype:=s80floattype;
  2072. end;
  2073. end;
  2074. {$ifdef SUPPORT_MMX}
  2075. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  2076. begin
  2077. end;
  2078. {$endif SUPPORT_MMX}
  2079. in_assert_x_y :
  2080. begin
  2081. resulttype:=voidtype;
  2082. if assigned(left) then
  2083. begin
  2084. set_varstate(left,true);
  2085. { check type }
  2086. if is_boolean(left.resulttype.def) then
  2087. begin
  2088. { must always be a string }
  2089. inserttypeconv(tcallparanode(tcallparanode(left).right).left,cshortstringtype);
  2090. end
  2091. else
  2092. CGMessage(type_e_mismatch);
  2093. end
  2094. else
  2095. CGMessage(type_e_mismatch);
  2096. end;
  2097. else
  2098. internalerror(8);
  2099. end;
  2100. end;
  2101. myexit:
  2102. { Run get_paratype again to update maybe inserted typeconvs }
  2103. if not codegenerror then
  2104. begin
  2105. if assigned(left) and
  2106. (left.nodetype=callparan) then
  2107. tcallparanode(left).get_paratype;
  2108. end;
  2109. dec(parsing_para_level);
  2110. end;
  2111. {$ifdef fpc}
  2112. {$maxfpuregisters 0}
  2113. {$endif fpc}
  2114. function tinlinenode.pass_1 : tnode;
  2115. var
  2116. srsym : tsym;
  2117. hp,hpp : tnode;
  2118. extra_register,
  2119. iswrite,
  2120. file_is_typed : boolean;
  2121. begin
  2122. result:=nil;
  2123. { if we handle writeln; left contains no valid address }
  2124. if assigned(left) then
  2125. begin
  2126. if left.nodetype=callparan then
  2127. tcallparanode(left).firstcallparan(nil,false)
  2128. else
  2129. firstpass(left);
  2130. left_max;
  2131. set_location(location,left.location);
  2132. end;
  2133. inc(parsing_para_level);
  2134. { intern const should already be handled }
  2135. if nf_inlineconst in flags then
  2136. internalerror(200104044);
  2137. case inlinenumber of
  2138. in_lo_qword,
  2139. in_hi_qword,
  2140. in_lo_long,
  2141. in_hi_long,
  2142. in_lo_word,
  2143. in_hi_word:
  2144. begin
  2145. if registers32<1 then
  2146. registers32:=1;
  2147. location.loc:=LOC_REGISTER;
  2148. end;
  2149. in_sizeof_x:
  2150. begin
  2151. if push_high_param(left.resulttype.def) then
  2152. begin
  2153. srsym:=searchsymonlyin(tloadnode(left).symtable,'high'+tvarsym(tloadnode(left).symtableentry).name);
  2154. hp:=caddnode.create(addn,cloadnode.create(tvarsym(srsym),tloadnode(left).symtable),
  2155. cordconstnode.create(1,s32bittype));
  2156. if (left.resulttype.def.deftype=arraydef) and
  2157. (tarraydef(left.resulttype.def).elesize<>1) then
  2158. hp:=caddnode.create(muln,hp,cordconstnode.create(tarraydef(left.resulttype.def).elesize,s32bittype));
  2159. firstpass(hp);
  2160. result:=hp;
  2161. end
  2162. else
  2163. begin
  2164. if registers32<1 then
  2165. registers32:=1;
  2166. location.loc:=LOC_REGISTER;
  2167. end;
  2168. end;
  2169. in_typeof_x:
  2170. begin
  2171. if registers32<1 then
  2172. registers32:=1;
  2173. location.loc:=LOC_REGISTER;
  2174. end;
  2175. in_ord_x,
  2176. in_chr_byte:
  2177. begin
  2178. { should not happend as it's converted to typeconv }
  2179. internalerror(200104045);
  2180. end;
  2181. in_length_x:
  2182. begin
  2183. if is_shortstring(left.resulttype.def) then
  2184. location.loc:=LOC_REFERENCE
  2185. else
  2186. begin
  2187. { ansi/wide string }
  2188. if registers32<1 then
  2189. registers32:=1;
  2190. location.loc:=LOC_REGISTER;
  2191. end;
  2192. end;
  2193. in_typeinfo_x:
  2194. begin
  2195. location.loc:=LOC_REGISTER;
  2196. registers32:=1;
  2197. end;
  2198. in_assigned_x:
  2199. begin
  2200. location.loc:=LOC_FLAGS;
  2201. end;
  2202. in_ofs_x :
  2203. internalerror(2000101001);
  2204. in_seg_x :
  2205. internalerror(200104046);
  2206. in_pred_x,
  2207. in_succ_x:
  2208. begin
  2209. if is_64bitint(resulttype.def) then
  2210. begin
  2211. if (registers32<2) then
  2212. registers32:=2
  2213. end
  2214. else
  2215. begin
  2216. if (registers32<1) then
  2217. registers32:=1;
  2218. end;
  2219. location.loc:=LOC_REGISTER;
  2220. end;
  2221. in_setlength_x:
  2222. begin
  2223. end;
  2224. in_finalize_x:
  2225. begin
  2226. end;
  2227. in_inc_x,
  2228. in_dec_x:
  2229. begin
  2230. { check type }
  2231. if is_64bitint(left.resulttype.def) or
  2232. { range/overflow checking doesn't work properly }
  2233. { with the inc/dec code that's generated (JM) }
  2234. ((left.resulttype.def.deftype = orddef) and
  2235. not(is_char(left.resulttype.def)) and
  2236. not(is_boolean(left.resulttype.def)) and
  2237. (aktlocalswitches *
  2238. [cs_check_overflow,cs_check_range] <> [])) then
  2239. { convert to simple add (JM) }
  2240. begin
  2241. { extra parameter? }
  2242. if assigned(tcallparanode(left).right) then
  2243. begin
  2244. { Yes, use for add node }
  2245. hpp := tcallparanode(tcallparanode(left).right).left;
  2246. tcallparanode(tcallparanode(left).right).left := nil;
  2247. if assigned(tcallparanode(tcallparanode(left).right).right) then
  2248. CGMessage(cg_e_illegal_expression);
  2249. end
  2250. else
  2251. { no, create constant 1 }
  2252. hpp := cordconstnode.create(1,s32bittype);
  2253. { addition/substraction depending on inc/dec }
  2254. if inlinenumber = in_inc_x then
  2255. hp := caddnode.create(addn,tcallparanode(left).left.getcopy,hpp)
  2256. else
  2257. hp := caddnode.create(subn,tcallparanode(left).left.getcopy,hpp);
  2258. { assign result of addition }
  2259. hpp := cassignmentnode.create(tcallparanode(left).left,hp);
  2260. tcallparanode(left).left := nil;
  2261. { firstpass it }
  2262. firstpass(hpp);
  2263. { return new node }
  2264. result := hpp;
  2265. end
  2266. else if (left.resulttype.def.deftype in [enumdef,pointerdef]) or
  2267. is_ordinal(left.resulttype.def) then
  2268. begin
  2269. { two paras ? }
  2270. if assigned(tcallparanode(left).right) then
  2271. begin
  2272. { need we an additional register ? }
  2273. if not(is_constintnode(tcallparanode(tcallparanode(left).right).left)) and
  2274. (tcallparanode(tcallparanode(left).right).left.location.loc in [LOC_MEM,LOC_REFERENCE]) and
  2275. (tcallparanode(tcallparanode(left).right).left.registers32<=1) then
  2276. inc(registers32);
  2277. { do we need an additional register to restore the first parameter? }
  2278. if tcallparanode(tcallparanode(left).right).left.registers32>=registers32 then
  2279. inc(registers32);
  2280. end;
  2281. end;
  2282. end;
  2283. in_read_x,
  2284. in_readln_x,
  2285. in_write_x,
  2286. in_writeln_x :
  2287. begin
  2288. {$ifdef hascompilerproc}
  2289. { should be handled by det_resulttype }
  2290. internalerror(200108234);
  2291. {$else hascompilerproc}
  2292. { needs a call }
  2293. procinfo^.flags:=procinfo^.flags or pi_do_call;
  2294. { true, if readln needs an extra register }
  2295. extra_register:=false;
  2296. { we must know if it is a typed file or not }
  2297. { but we must first do the firstpass for it }
  2298. file_is_typed:=false;
  2299. if assigned(left) then
  2300. begin
  2301. iswrite:=(inlinenumber in [in_write_x,in_writeln_x]);
  2302. { now we can check }
  2303. hp:=left;
  2304. while assigned(tcallparanode(hp).right) do
  2305. hp:=tcallparanode(hp).right;
  2306. { if resulttype.def is not assigned, then automatically }
  2307. { file is not typed. }
  2308. if assigned(hp) then
  2309. Begin
  2310. if (hp.resulttype.def.deftype=filedef) and
  2311. (tfiledef(hp.resulttype.def).filetyp=ft_typed) then
  2312. file_is_typed:=true;
  2313. end; { endif assigned(hp) }
  2314. if (not file_is_typed) then
  2315. begin
  2316. hp:=left;
  2317. while assigned(hp) do
  2318. begin
  2319. {$ifdef i386}
  2320. incrementregisterpushed($ff);
  2321. {$else}
  2322. incrementregisterpushed(ALL_REGISTERS);
  2323. {$endif}
  2324. if assigned(tcallparanode(hp).left.resulttype.def) then
  2325. begin
  2326. case tcallparanode(hp).left.resulttype.def.deftype of
  2327. orddef :
  2328. begin
  2329. if not(iswrite) and
  2330. not(is_64bitint(tcallparanode(hp).left.resulttype.def)) then
  2331. extra_register:=true;
  2332. end;
  2333. end;
  2334. end;
  2335. hp:=tcallparanode(hp).right;
  2336. end;
  2337. end;
  2338. { calc registers }
  2339. left_max;
  2340. if extra_register then
  2341. inc(registers32);
  2342. end;
  2343. {$endif hascompilerproc}
  2344. end;
  2345. in_settextbuf_file_x :
  2346. internalerror(200104262);
  2347. in_reset_typedfile,
  2348. in_rewrite_typedfile :
  2349. begin
  2350. {$ifndef hascompilerproc}
  2351. procinfo^.flags:=procinfo^.flags or pi_do_call;
  2352. {$else not hascompilerproc}
  2353. { should already be removed in det_resulttype (JM) }
  2354. internalerror(200108236);
  2355. {$endif not hascompilerproc}
  2356. end;
  2357. in_str_x_string :
  2358. begin
  2359. {$ifndef hascompilerproc}
  2360. procinfo^.flags:=procinfo^.flags or pi_do_call;
  2361. { calc registers }
  2362. left_max;
  2363. {$else not hascompilerproc}
  2364. { should already be removed in det_resulttype (JM) }
  2365. internalerror(200108235);
  2366. {$endif not hascompilerproc}
  2367. end;
  2368. in_val_x :
  2369. begin
  2370. {$ifdef hascompilerproc}
  2371. { should already be removed in det_resulttype (JM) }
  2372. internalerror(200108242);
  2373. {$else hascompilerproc}
  2374. procinfo^.flags:=procinfo^.flags or pi_do_call;
  2375. { calc registers }
  2376. left_max;
  2377. { val doesn't calculate the registers really }
  2378. { correct, we need one register extra (FK) }
  2379. { there is a "code" parameter }
  2380. If Assigned(tcallparanode(tcallparanode(left).right).right) Then
  2381. hpp := tcallparanode(left).right
  2382. Else
  2383. hpp := left;
  2384. { now hpp = the destination value tree }
  2385. if is_64bitint(tcallparanode(hpp).left.resulttype.def) then
  2386. inc(registers32,2)
  2387. else
  2388. inc(registers32,1);
  2389. {$endif hascompilerproc}
  2390. end;
  2391. in_include_x_y,
  2392. in_exclude_x_y:
  2393. begin
  2394. registers32:=left.registers32;
  2395. registersfpu:=left.registersfpu;
  2396. {$ifdef SUPPORT_MMX}
  2397. registersmmx:=left.registersmmx;
  2398. {$endif SUPPORT_MMX}
  2399. end;
  2400. in_low_x,
  2401. in_high_x:
  2402. internalerror(200104047);
  2403. in_cos_extended:
  2404. begin
  2405. location.loc:=LOC_FPU;
  2406. registers32:=left.registers32;
  2407. registersfpu:=left.registersfpu;
  2408. {$ifdef SUPPORT_MMX}
  2409. registersmmx:=left.registersmmx;
  2410. {$endif SUPPORT_MMX}
  2411. end;
  2412. in_sin_extended:
  2413. begin
  2414. location.loc:=LOC_FPU;
  2415. registers32:=left.registers32;
  2416. registersfpu:=left.registersfpu;
  2417. {$ifdef SUPPORT_MMX}
  2418. registersmmx:=left.registersmmx;
  2419. {$endif SUPPORT_MMX}
  2420. end;
  2421. in_arctan_extended:
  2422. begin
  2423. location.loc:=LOC_FPU;
  2424. registers32:=left.registers32;
  2425. registersfpu:=left.registersfpu;
  2426. {$ifdef SUPPORT_MMX}
  2427. registersmmx:=left.registersmmx;
  2428. {$endif SUPPORT_MMX}
  2429. end;
  2430. in_pi:
  2431. begin
  2432. location.loc:=LOC_FPU;
  2433. end;
  2434. in_abs_extended:
  2435. begin
  2436. location.loc:=LOC_FPU;
  2437. registers32:=left.registers32;
  2438. registersfpu:=left.registersfpu;
  2439. {$ifdef SUPPORT_MMX}
  2440. registersmmx:=left.registersmmx;
  2441. {$endif SUPPORT_MMX}
  2442. end;
  2443. in_sqr_extended:
  2444. begin
  2445. location.loc:=LOC_FPU;
  2446. registers32:=left.registers32;
  2447. registersfpu:=left.registersfpu;
  2448. {$ifdef SUPPORT_MMX}
  2449. registersmmx:=left.registersmmx;
  2450. {$endif SUPPORT_MMX}
  2451. end;
  2452. in_sqrt_extended:
  2453. begin
  2454. location.loc:=LOC_FPU;
  2455. registers32:=left.registers32;
  2456. registersfpu:=left.registersfpu;
  2457. {$ifdef SUPPORT_MMX}
  2458. registersmmx:=left.registersmmx;
  2459. {$endif SUPPORT_MMX}
  2460. end;
  2461. in_ln_extended:
  2462. begin
  2463. location.loc:=LOC_FPU;
  2464. registers32:=left.registers32;
  2465. registersfpu:=left.registersfpu;
  2466. {$ifdef SUPPORT_MMX}
  2467. registersmmx:=left.registersmmx;
  2468. {$endif SUPPORT_MMX}
  2469. end;
  2470. {$ifdef SUPPORT_MMX}
  2471. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  2472. begin
  2473. end;
  2474. {$endif SUPPORT_MMX}
  2475. in_assert_x_y :
  2476. begin
  2477. { We've checked the whole statement for correctness, now we
  2478. can remove it if assertions are off }
  2479. if not(cs_do_assertion in aktlocalswitches) then
  2480. begin
  2481. { we need a valid node, so insert a nothingn }
  2482. result:=cnothingnode.create;
  2483. end
  2484. else
  2485. begin
  2486. registers32:=left.registers32;
  2487. registersfpu:=left.registersfpu;
  2488. {$ifdef SUPPORT_MMX}
  2489. registersmmx:=left.registersmmx;
  2490. {$endif SUPPORT_MMX}
  2491. end;
  2492. end;
  2493. else
  2494. internalerror(8);
  2495. end;
  2496. dec(parsing_para_level);
  2497. end;
  2498. {$ifdef fpc}
  2499. {$maxfpuregisters default}
  2500. {$endif fpc}
  2501. function tinlinenode.docompare(p: tnode): boolean;
  2502. begin
  2503. docompare :=
  2504. inherited docompare(p) and
  2505. (inlinenumber = tinlinenode(p).inlinenumber);
  2506. end;
  2507. begin
  2508. cinlinenode:=tinlinenode;
  2509. end.
  2510. {
  2511. $Log$
  2512. Revision 1.51 2001-08-24 13:47:27 jonas
  2513. * moved "reverseparameters" from ninl.pas to ncal.pas
  2514. + support for non-persistent temps in ttempcreatenode.create, for use
  2515. with typeconversion nodes
  2516. Revision 1.50 2001/08/24 12:33:54 jonas
  2517. * fixed big bug in handle_str that caused it to (almost) always call
  2518. fpc_<stringtype>_longint
  2519. * fixed small bug in handle_read_write that caused wrong warnigns about
  2520. uninitialized vars with read(ln)
  2521. + handle_val (processor independent val() handling)
  2522. Revision 1.49 2001/08/23 14:28:35 jonas
  2523. + tempcreate/ref/delete nodes (allows the use of temps in the
  2524. resulttype and first pass)
  2525. * made handling of read(ln)/write(ln) processor independent
  2526. * moved processor independent handling for str and reset/rewrite-typed
  2527. from firstpass to resulttype pass
  2528. * changed names of helpers in text.inc to be generic for use as
  2529. compilerprocs + added "iocheck" directive for most of them
  2530. * reading of ordinals is done by procedures instead of functions
  2531. because otherwise FPC_IOCHECK overwrote the result before it could
  2532. be stored elsewhere (range checking still works)
  2533. * compilerprocs can now be used in the system unit before they are
  2534. implemented
  2535. * added note to errore.msg that booleans can't be read using read/readln
  2536. Revision 1.48 2001/08/13 15:39:52 jonas
  2537. * made in_reset_typedfile/in_rewrite_typedfile handling processor
  2538. independent
  2539. Revision 1.47 2001/08/13 12:41:57 jonas
  2540. * made code for str(x,y) completely processor independent
  2541. Revision 1.46 2001/08/06 12:47:31 jonas
  2542. * parameters to FPC_TYPED_WRITE can't be regvars (merged)
  2543. Revision 1.45 2001/08/06 09:44:10 jonas
  2544. + support for high(dynarray) using compilerproc (forgot to commit
  2545. previously)
  2546. Revision 1.44 2001/07/09 21:15:40 peter
  2547. * Length made internal
  2548. * Add array support for Length
  2549. Revision 1.43 2001/07/08 21:00:15 peter
  2550. * various widestring updates, it works now mostly without charset
  2551. mapping supported
  2552. Revision 1.42 2001/06/04 11:48:01 peter
  2553. * better const to var checking
  2554. Revision 1.41 2001/06/03 20:12:53 peter
  2555. * changed int64($ffffffff) that is buggy under 1.0.x to expression
  2556. with a shl
  2557. Revision 1.40 2001/05/06 17:16:43 jonas
  2558. + added warning about missing implementation for high(dynamic_array)
  2559. Revision 1.39 2001/04/26 21:57:05 peter
  2560. * moved code from firstpass to det_resulttype and remove extraneous
  2561. calls to firstcallparan for in_str,in_write,in_val
  2562. Revision 1.38 2001/04/21 12:03:11 peter
  2563. * m68k updates merged from fixes branch
  2564. Revision 1.37 2001/04/13 22:22:30 peter
  2565. * call set_varstate for setlength
  2566. * ptr returns pointerconstnode instead of ordconstnode
  2567. Revision 1.36 2001/04/13 01:22:09 peter
  2568. * symtable change to classes
  2569. * range check generation and errors fixed, make cycle DEBUG=1 works
  2570. * memory leaks fixed
  2571. Revision 1.35 2001/04/05 21:02:13 peter
  2572. * fixed fpu inline functions typeconvs
  2573. Revision 1.34 2001/04/04 22:42:40 peter
  2574. * move constant folding into det_resulttype
  2575. Revision 1.33 2001/04/04 21:30:43 florian
  2576. * applied several fixes to get the DD8 Delphi Unit compiled
  2577. e.g. "forward"-interfaces are working now
  2578. Revision 1.32 2001/04/02 21:20:31 peter
  2579. * resulttype rewrite
  2580. Revision 1.31 2001/03/23 00:16:07 florian
  2581. + some stuff to compile FreeCLX added
  2582. Revision 1.30 2001/03/12 12:47:46 michael
  2583. + Patches from peter
  2584. Revision 1.29 2001/03/03 12:38:08 jonas
  2585. * fixed low() for signed types < 64bit
  2586. Revision 1.28 2001/02/26 19:44:53 peter
  2587. * merged generic m68k updates from fixes branch
  2588. Revision 1.27 2001/02/22 11:24:40 jonas
  2589. * fixed bug in previous fix (hopped over revision 1.26 because that one
  2590. also removed the fix for high(cardinal))
  2591. Revision 1.26 2001/02/21 20:50:59 peter
  2592. * fix to compile again, but high(cardinal) with $R+ still fails!
  2593. Revision 1.25 2001/02/21 12:57:46 jonas
  2594. * fixed high/low for cardinal, int64 and qword
  2595. Revision 1.24 2001/01/06 19:54:11 peter
  2596. * merged fix for 1310
  2597. Revision 1.23 2001/01/06 18:28:39 peter
  2598. * fixed wrong notes about locals
  2599. Revision 1.22 2000/12/31 11:14:10 jonas
  2600. + implemented/fixed docompare() mathods for all nodes (not tested)
  2601. + nopt.pas, nadd.pas, i386/n386opt.pas: optimized nodes for adding strings
  2602. and constant strings/chars together
  2603. * n386add.pas: don't copy temp strings (of size 256) to another temp string
  2604. when adding
  2605. Revision 1.21 2000/12/25 00:07:26 peter
  2606. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  2607. tlinkedlist objects)
  2608. Revision 1.20 2000/12/17 14:35:41 peter
  2609. * fixed crash with val()
  2610. Revision 1.19 2000/11/29 00:30:33 florian
  2611. * unused units removed from uses clause
  2612. * some changes for widestrings
  2613. Revision 1.18 2000/11/12 15:27:22 jonas
  2614. * also don't do conversion for chars/booleans (hopefully final change :/)
  2615. Revision 1.17 2000/11/11 21:08:13 jonas
  2616. * don't do inc/dec to add/sub conversion for enums
  2617. Revision 1.16 2000/11/11 16:18:35 peter
  2618. * ptr returns farpointer
  2619. Revision 1.15 2000/11/11 15:59:07 jonas
  2620. * convert inc/dec to add/sub when range/overflow checking is on
  2621. Revision 1.14 2000/11/09 17:46:54 florian
  2622. * System.TypeInfo fixed
  2623. + System.Finalize implemented
  2624. + some new keywords for interface support added
  2625. Revision 1.13 2000/11/04 16:48:32 florian
  2626. * innr.inc renamed to make compiler compilation easier because the rtl contains
  2627. a file of the same name
  2628. Revision 1.12 2000/10/31 22:02:48 peter
  2629. * symtable splitted, no real code changes
  2630. Revision 1.11 2000/10/26 14:15:06 jonas
  2631. * fixed setlength for shortstrings
  2632. Revision 1.10 2000/10/21 18:16:11 florian
  2633. * a lot of changes:
  2634. - basic dyn. array support
  2635. - basic C++ support
  2636. - some work for interfaces done
  2637. ....
  2638. Revision 1.9 2000/10/15 08:38:46 jonas
  2639. * added missing getcopy for previous addition
  2640. Revision 1.8 2000/10/14 18:27:53 jonas
  2641. * merged fix for inc/dec on 64bit types from tcinl
  2642. Revision 1.7 2000/10/14 10:14:50 peter
  2643. * moehrendorf oct 2000 rewrite
  2644. Revision 1.6 2000/10/01 19:48:24 peter
  2645. * lot of compile updates for cg11
  2646. Revision 1.5 2000/09/28 19:49:52 florian
  2647. *** empty log message ***
  2648. Revision 1.4 2000/09/28 16:34:47 florian
  2649. *** empty log message ***
  2650. Revision 1.3 2000/09/27 21:33:22 florian
  2651. * finally nadd.pas compiles
  2652. Revision 1.2 2000/09/27 20:25:44 florian
  2653. * more stuff fixed
  2654. Revision 1.1 2000/09/26 14:59:34 florian
  2655. * more conversion work done
  2656. }