ninl.pas 115 KB

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