ninl.pas 115 KB

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