pexpr.pas 100 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Does parsing of expression for Free Pascal
  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 pexpr;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symtype,symdef,symbase,
  23. node,
  24. globals,
  25. cpuinfo;
  26. { reads a whole expression }
  27. function expr : tnode;
  28. { reads an expression without assignements and .. }
  29. function comp_expr(accept_equal : boolean):tnode;
  30. { reads a single factor }
  31. function factor(getaddr : boolean) : tnode;
  32. procedure string_dec(var t: ttype);
  33. procedure symlist_to_node(var p1:tnode;st:tsymtable;pl:tsymlist);
  34. function node_to_symlist(p1:tnode):tsymlist;
  35. function parse_paras(__colon,in_prop_paras : boolean) : tnode;
  36. { the ID token has to be consumed before calling this function }
  37. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callnflags:tnodeflags);
  38. {$ifdef int64funcresok}
  39. function get_intconst:TConstExprInt;
  40. {$else int64funcresok}
  41. function get_intconst:longint;
  42. {$endif int64funcresok}
  43. function get_stringconst:string;
  44. implementation
  45. uses
  46. {$ifdef delphi}
  47. SysUtils,
  48. {$endif}
  49. { common }
  50. cutils,
  51. { global }
  52. globtype,tokens,verbose,
  53. systems,widestr,
  54. { symtable }
  55. symconst,symtable,symsym,defutil,defcmp,
  56. { pass 1 }
  57. pass_1,htypechk,
  58. nmat,nadd,ncal,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  59. { parser }
  60. scanner,
  61. pbase,pinline,
  62. { codegen }
  63. procinfo
  64. ;
  65. { sub_expr(opmultiply) is need to get -1 ** 4 to be
  66. read as - (1**4) and not (-1)**4 PM }
  67. type
  68. Toperator_precedence=(opcompare,opaddition,opmultiply,oppower);
  69. const
  70. highest_precedence = oppower;
  71. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;forward;
  72. const
  73. { true, if the inherited call is anonymous }
  74. anon_inherited : boolean = false;
  75. procedure string_dec(var t: ttype);
  76. { reads a string type with optional length }
  77. { and returns a pointer to the string }
  78. { definition }
  79. var
  80. p : tnode;
  81. begin
  82. t:=cshortstringtype;
  83. consume(_STRING);
  84. if try_to_consume(_LECKKLAMMER) then
  85. begin
  86. p:=comp_expr(true);
  87. if not is_constintnode(p) then
  88. begin
  89. Message(cg_e_illegal_expression);
  90. { error recovery }
  91. consume(_RECKKLAMMER);
  92. end
  93. else
  94. begin
  95. if (tordconstnode(p).value<=0) then
  96. begin
  97. Message(parser_e_invalid_string_size);
  98. tordconstnode(p).value:=255;
  99. end;
  100. consume(_RECKKLAMMER);
  101. if tordconstnode(p).value>255 then
  102. begin
  103. { longstring is currently unsupported (CEC)! }
  104. { t.setdef(tstringdef.createlong(tordconstnode(p).value))}
  105. Message(parser_e_invalid_string_size);
  106. tordconstnode(p).value:=255;
  107. t.setdef(tstringdef.createshort(tordconstnode(p).value));
  108. end
  109. else
  110. if tordconstnode(p).value<>255 then
  111. t.setdef(tstringdef.createshort(tordconstnode(p).value));
  112. end;
  113. p.free;
  114. end
  115. else
  116. begin
  117. if cs_ansistrings in aktlocalswitches then
  118. t:=cansistringtype
  119. else
  120. t:=cshortstringtype;
  121. end;
  122. end;
  123. procedure symlist_to_node(var p1:tnode;st:tsymtable;pl:tsymlist);
  124. var
  125. plist : psymlistitem;
  126. begin
  127. plist:=pl.firstsym;
  128. while assigned(plist) do
  129. begin
  130. case plist^.sltype of
  131. sl_load :
  132. begin
  133. if not assigned(st) then
  134. st:=plist^.sym.owner;
  135. { p1 can already contain the loadnode of
  136. the class variable. When there is no tree yet we
  137. may need to load it for with or objects }
  138. if not assigned(p1) then
  139. begin
  140. case st.symtabletype of
  141. withsymtable :
  142. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  143. objectsymtable :
  144. p1:=load_self_node;
  145. end;
  146. end;
  147. if assigned(p1) then
  148. p1:=csubscriptnode.create(plist^.sym,p1)
  149. else
  150. p1:=cloadnode.create(plist^.sym,st);
  151. end;
  152. sl_subscript :
  153. p1:=csubscriptnode.create(plist^.sym,p1);
  154. sl_typeconv :
  155. p1:=ctypeconvnode.create_explicit(p1,plist^.tt);
  156. sl_vec :
  157. p1:=cvecnode.create(p1,cordconstnode.create(plist^.value,s32inttype,true));
  158. else
  159. internalerror(200110205);
  160. end;
  161. plist:=plist^.next;
  162. end;
  163. end;
  164. function node_to_symlist(p1:tnode):tsymlist;
  165. var
  166. sl : tsymlist;
  167. procedure addnode(p:tnode);
  168. begin
  169. case p.nodetype of
  170. subscriptn :
  171. begin
  172. addnode(tsubscriptnode(p).left);
  173. sl.addsym(sl_subscript,tsubscriptnode(p).vs);
  174. end;
  175. typeconvn :
  176. begin
  177. addnode(ttypeconvnode(p).left);
  178. sl.addtype(sl_typeconv,ttypeconvnode(p).totype);
  179. end;
  180. vecn :
  181. begin
  182. addnode(tvecnode(p).left);
  183. if tvecnode(p).right.nodetype=ordconstn then
  184. sl.addconst(sl_vec,tordconstnode(tvecnode(p).right).value)
  185. else
  186. begin
  187. Message(cg_e_illegal_expression);
  188. { recovery }
  189. sl.addconst(sl_vec,0);
  190. end;
  191. end;
  192. loadn :
  193. sl.addsym(sl_load,tloadnode(p).symtableentry);
  194. else
  195. internalerror(200310282);
  196. end;
  197. end;
  198. begin
  199. sl:=tsymlist.create;
  200. addnode(p1);
  201. result:=sl;
  202. end;
  203. function parse_paras(__colon,in_prop_paras : boolean) : tnode;
  204. var
  205. p1,p2 : tnode;
  206. end_of_paras : ttoken;
  207. prev_in_args : boolean;
  208. old_allow_array_constructor : boolean;
  209. begin
  210. if in_prop_paras then
  211. end_of_paras:=_RECKKLAMMER
  212. else
  213. end_of_paras:=_RKLAMMER;
  214. if token=end_of_paras then
  215. begin
  216. parse_paras:=nil;
  217. exit;
  218. end;
  219. { save old values }
  220. prev_in_args:=in_args;
  221. old_allow_array_constructor:=allow_array_constructor;
  222. { set para parsing values }
  223. in_args:=true;
  224. inc(parsing_para_level);
  225. allow_array_constructor:=true;
  226. p2:=nil;
  227. repeat
  228. p1:=comp_expr(true);
  229. p2:=ccallparanode.create(p1,p2);
  230. { it's for the str(l:5,s); }
  231. if __colon and (token=_COLON) then
  232. begin
  233. consume(_COLON);
  234. p1:=comp_expr(true);
  235. p2:=ccallparanode.create(p1,p2);
  236. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  237. if try_to_consume(_COLON) then
  238. begin
  239. p1:=comp_expr(true);
  240. p2:=ccallparanode.create(p1,p2);
  241. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  242. end
  243. end;
  244. until not try_to_consume(_COMMA);
  245. allow_array_constructor:=old_allow_array_constructor;
  246. dec(parsing_para_level);
  247. in_args:=prev_in_args;
  248. parse_paras:=p2;
  249. end;
  250. function statement_syssym(l : longint) : tnode;
  251. var
  252. p1,p2,paras : tnode;
  253. err,
  254. prev_in_args : boolean;
  255. begin
  256. prev_in_args:=in_args;
  257. case l of
  258. in_new_x :
  259. begin
  260. if afterassignment or in_args then
  261. statement_syssym:=new_function
  262. else
  263. statement_syssym:=new_dispose_statement(true);
  264. end;
  265. in_dispose_x :
  266. begin
  267. statement_syssym:=new_dispose_statement(false);
  268. end;
  269. in_ord_x :
  270. begin
  271. consume(_LKLAMMER);
  272. in_args:=true;
  273. p1:=comp_expr(true);
  274. consume(_RKLAMMER);
  275. p1:=geninlinenode(in_ord_x,false,p1);
  276. statement_syssym := p1;
  277. end;
  278. in_exit :
  279. begin
  280. if try_to_consume(_LKLAMMER) then
  281. begin
  282. p1:=comp_expr(true);
  283. consume(_RKLAMMER);
  284. if (block_type=bt_except) then
  285. begin
  286. Message(parser_e_exit_with_argument_not__possible);
  287. { recovery }
  288. p1.free;
  289. p1:=nil;
  290. end
  291. else if (not assigned(current_procinfo) or
  292. is_void(current_procinfo.procdef.rettype.def)) then
  293. begin
  294. Message(parser_e_void_function);
  295. { recovery }
  296. p1.free;
  297. p1:=nil;
  298. end;
  299. end
  300. else
  301. p1:=nil;
  302. statement_syssym:=cexitnode.create(p1);
  303. end;
  304. in_break :
  305. begin
  306. statement_syssym:=cbreaknode.create;
  307. end;
  308. in_continue :
  309. begin
  310. statement_syssym:=ccontinuenode.create;
  311. end;
  312. in_typeof_x :
  313. begin
  314. consume(_LKLAMMER);
  315. in_args:=true;
  316. p1:=comp_expr(true);
  317. consume(_RKLAMMER);
  318. if p1.nodetype=typen then
  319. ttypenode(p1).allowed:=true;
  320. { Allow classrefdef, which is required for
  321. Typeof(self) in static class methods }
  322. if (p1.resulttype.def.deftype = objectdef) or
  323. (assigned(current_procinfo) and
  324. ((po_classmethod in current_procinfo.procdef.procoptions) or
  325. (po_staticmethod in current_procinfo.procdef.procoptions)) and
  326. (p1.resulttype.def.deftype=classrefdef)) then
  327. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  328. else
  329. begin
  330. Message(parser_e_class_id_expected);
  331. p1.destroy;
  332. statement_syssym:=cerrornode.create;
  333. end;
  334. end;
  335. in_sizeof_x :
  336. begin
  337. consume(_LKLAMMER);
  338. in_args:=true;
  339. p1:=comp_expr(true);
  340. consume(_RKLAMMER);
  341. if (p1.nodetype<>typen) and
  342. (
  343. (is_object(p1.resulttype.def) and
  344. (oo_has_constructor in tobjectdef(p1.resulttype.def).objectoptions)) or
  345. is_open_array(p1.resulttype.def) or
  346. is_open_string(p1.resulttype.def)
  347. ) then
  348. statement_syssym:=geninlinenode(in_sizeof_x,false,p1)
  349. else
  350. begin
  351. statement_syssym:=cordconstnode.create(p1.resulttype.def.size,s32inttype,true);
  352. { p1 not needed !}
  353. p1.destroy;
  354. end;
  355. end;
  356. in_typeinfo_x :
  357. begin
  358. consume(_LKLAMMER);
  359. in_args:=true;
  360. p1:=comp_expr(true);
  361. if p1.nodetype=typen then
  362. ttypenode(p1).allowed:=true
  363. else
  364. begin
  365. p1.destroy;
  366. p1:=cerrornode.create;
  367. Message(parser_e_illegal_parameter_list);
  368. end;
  369. consume(_RKLAMMER);
  370. p2:=geninlinenode(in_typeinfo_x,false,p1);
  371. statement_syssym:=p2;
  372. end;
  373. in_assigned_x :
  374. begin
  375. err:=false;
  376. consume(_LKLAMMER);
  377. in_args:=true;
  378. p1:=comp_expr(true);
  379. if not codegenerror then
  380. begin
  381. case p1.resulttype.def.deftype of
  382. procdef, { procvar }
  383. pointerdef,
  384. procvardef,
  385. classrefdef : ;
  386. objectdef :
  387. if not is_class_or_interface(p1.resulttype.def) then
  388. begin
  389. Message(parser_e_illegal_parameter_list);
  390. err:=true;
  391. end;
  392. else
  393. begin
  394. Message(parser_e_illegal_parameter_list);
  395. err:=true;
  396. end;
  397. end;
  398. end
  399. else
  400. err:=true;
  401. if not err then
  402. begin
  403. p2:=ccallparanode.create(p1,nil);
  404. p2:=geninlinenode(in_assigned_x,false,p2);
  405. end
  406. else
  407. begin
  408. p1.free;
  409. p2:=cerrornode.create;
  410. end;
  411. consume(_RKLAMMER);
  412. statement_syssym:=p2;
  413. end;
  414. in_addr_x :
  415. begin
  416. consume(_LKLAMMER);
  417. in_args:=true;
  418. p1:=comp_expr(true);
  419. p1:=caddrnode.create(p1);
  420. if cs_typed_addresses in aktlocalswitches then
  421. include(p1.flags,nf_typedaddr);
  422. consume(_RKLAMMER);
  423. statement_syssym:=p1;
  424. end;
  425. in_ofs_x :
  426. begin
  427. consume(_LKLAMMER);
  428. in_args:=true;
  429. p1:=comp_expr(true);
  430. p1:=caddrnode.create(p1);
  431. do_resulttypepass(p1);
  432. { Ofs() returns a cardinal, not a pointer }
  433. p1.resulttype:=u32inttype;
  434. consume(_RKLAMMER);
  435. statement_syssym:=p1;
  436. end;
  437. in_seg_x :
  438. begin
  439. consume(_LKLAMMER);
  440. in_args:=true;
  441. p1:=comp_expr(true);
  442. p1:=geninlinenode(in_seg_x,false,p1);
  443. consume(_RKLAMMER);
  444. statement_syssym:=p1;
  445. end;
  446. in_high_x,
  447. in_low_x :
  448. begin
  449. consume(_LKLAMMER);
  450. in_args:=true;
  451. p1:=comp_expr(true);
  452. p2:=geninlinenode(l,false,p1);
  453. consume(_RKLAMMER);
  454. statement_syssym:=p2;
  455. end;
  456. in_succ_x,
  457. in_pred_x :
  458. begin
  459. consume(_LKLAMMER);
  460. in_args:=true;
  461. p1:=comp_expr(true);
  462. p2:=geninlinenode(l,false,p1);
  463. consume(_RKLAMMER);
  464. statement_syssym:=p2;
  465. end;
  466. in_inc_x,
  467. in_dec_x :
  468. begin
  469. consume(_LKLAMMER);
  470. in_args:=true;
  471. p1:=comp_expr(true);
  472. if try_to_consume(_COMMA) then
  473. p2:=ccallparanode.create(comp_expr(true),nil)
  474. else
  475. p2:=nil;
  476. p2:=ccallparanode.create(p1,p2);
  477. statement_syssym:=geninlinenode(l,false,p2);
  478. consume(_RKLAMMER);
  479. end;
  480. in_initialize_x:
  481. begin
  482. statement_syssym:=inline_initialize;
  483. end;
  484. in_finalize_x:
  485. begin
  486. statement_syssym:=inline_finalize;
  487. end;
  488. in_copy_x:
  489. begin
  490. statement_syssym:=inline_copy;
  491. end;
  492. in_concat_x :
  493. begin
  494. consume(_LKLAMMER);
  495. in_args:=true;
  496. p2:=nil;
  497. repeat
  498. p1:=comp_expr(true);
  499. set_varstate(p1,vs_used,true);
  500. if not((p1.resulttype.def.deftype=stringdef) or
  501. ((p1.resulttype.def.deftype=orddef) and
  502. (torddef(p1.resulttype.def).typ=uchar))) then
  503. Message(parser_e_illegal_parameter_list);
  504. if p2<>nil then
  505. p2:=caddnode.create(addn,p2,p1)
  506. else
  507. p2:=p1;
  508. until not try_to_consume(_COMMA);
  509. consume(_RKLAMMER);
  510. statement_syssym:=p2;
  511. end;
  512. in_read_x,
  513. in_readln_x :
  514. begin
  515. if try_to_consume(_LKLAMMER) then
  516. begin
  517. paras:=parse_paras(false,false);
  518. consume(_RKLAMMER);
  519. end
  520. else
  521. paras:=nil;
  522. p1:=geninlinenode(l,false,paras);
  523. statement_syssym := p1;
  524. end;
  525. in_setlength_x:
  526. begin
  527. statement_syssym := inline_setlength;
  528. end;
  529. in_length_x:
  530. begin
  531. consume(_LKLAMMER);
  532. in_args:=true;
  533. p1:=comp_expr(true);
  534. p2:=geninlinenode(l,false,p1);
  535. consume(_RKLAMMER);
  536. statement_syssym:=p2;
  537. end;
  538. in_write_x,
  539. in_writeln_x :
  540. begin
  541. if try_to_consume(_LKLAMMER) then
  542. begin
  543. paras:=parse_paras(true,false);
  544. consume(_RKLAMMER);
  545. end
  546. else
  547. paras:=nil;
  548. p1 := geninlinenode(l,false,paras);
  549. statement_syssym := p1;
  550. end;
  551. in_str_x_string :
  552. begin
  553. consume(_LKLAMMER);
  554. paras:=parse_paras(true,false);
  555. consume(_RKLAMMER);
  556. p1 := geninlinenode(l,false,paras);
  557. statement_syssym := p1;
  558. end;
  559. in_val_x:
  560. Begin
  561. consume(_LKLAMMER);
  562. in_args := true;
  563. p1:= ccallparanode.create(comp_expr(true), nil);
  564. consume(_COMMA);
  565. p2 := ccallparanode.create(comp_expr(true),p1);
  566. if try_to_consume(_COMMA) then
  567. p2 := ccallparanode.create(comp_expr(true),p2);
  568. consume(_RKLAMMER);
  569. p2 := geninlinenode(l,false,p2);
  570. statement_syssym := p2;
  571. End;
  572. in_include_x_y,
  573. in_exclude_x_y :
  574. begin
  575. consume(_LKLAMMER);
  576. in_args:=true;
  577. p1:=comp_expr(true);
  578. consume(_COMMA);
  579. p2:=comp_expr(true);
  580. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  581. consume(_RKLAMMER);
  582. end;
  583. in_assert_x_y :
  584. begin
  585. consume(_LKLAMMER);
  586. in_args:=true;
  587. p1:=comp_expr(true);
  588. if try_to_consume(_COMMA) then
  589. p2:=comp_expr(true)
  590. else
  591. begin
  592. { then insert an empty string }
  593. p2:=cstringconstnode.createstr('',st_default);
  594. end;
  595. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  596. consume(_RKLAMMER);
  597. end;
  598. else
  599. internalerror(15);
  600. end;
  601. in_args:=prev_in_args;
  602. end;
  603. function maybe_load_methodpointer(st:tsymtable;var p1:tnode):boolean;
  604. begin
  605. maybe_load_methodpointer:=false;
  606. if not assigned(p1) then
  607. begin
  608. case st.symtabletype of
  609. withsymtable :
  610. begin
  611. if (st.defowner.deftype=objectdef) then
  612. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  613. end;
  614. objectsymtable :
  615. begin
  616. p1:=load_self_node;
  617. { We are calling a member }
  618. maybe_load_methodpointer:=true;
  619. end;
  620. end;
  621. end;
  622. end;
  623. { reads the parameter for a subroutine call }
  624. procedure do_proc_call(sym:tsym;st:tsymtable;obj:tobjectdef;getaddr:boolean;var again : boolean;var p1:tnode);
  625. var
  626. membercall,
  627. prevafterassn : boolean;
  628. vs : tvarsym;
  629. para,p2 : tnode;
  630. currpara : tparaitem;
  631. aprocdef : tprocdef;
  632. begin
  633. prevafterassn:=afterassignment;
  634. afterassignment:=false;
  635. membercall:=false;
  636. aprocdef:=nil;
  637. { when it is a call to a member we need to load the
  638. methodpointer first }
  639. membercall:=maybe_load_methodpointer(st,p1);
  640. { When we are expecting a procvar we also need
  641. to get the address in some cases }
  642. if assigned(getprocvardef) then
  643. begin
  644. if (block_type=bt_const) or
  645. getaddr then
  646. begin
  647. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  648. getaddr:=true;
  649. end
  650. else
  651. if (m_tp_procvar in aktmodeswitches) then
  652. begin
  653. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  654. if assigned(aprocdef) then
  655. getaddr:=true;
  656. end;
  657. end;
  658. { only need to get the address of the procedure? }
  659. if getaddr then
  660. begin
  661. { Retrieve info which procvar to call. For tp_procvar the
  662. aprocdef is already loaded above so we can reuse it }
  663. if not assigned(aprocdef) and
  664. assigned(getprocvardef) then
  665. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  666. { generate a methodcallnode or proccallnode }
  667. { we shouldn't convert things like @tcollection.load }
  668. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  669. if assigned(p1) then
  670. begin
  671. if (p1.nodetype<>typen) then
  672. tloadnode(p2).set_mp(p1)
  673. else
  674. p1.free;
  675. end;
  676. p1:=p2;
  677. { no postfix operators }
  678. again:=false;
  679. end
  680. else
  681. begin
  682. para:=nil;
  683. if anon_inherited then
  684. begin
  685. if not assigned(current_procinfo) then
  686. internalerror(200305054);
  687. currpara:=tparaitem(current_procinfo.procdef.para.first);
  688. while assigned(currpara) do
  689. begin
  690. if not currpara.is_hidden then
  691. begin
  692. vs:=tvarsym(currpara.parasym);
  693. para:=ccallparanode.create(cloadnode.create(vs,vs.owner),para);
  694. end;
  695. currpara:=tparaitem(currpara.next);
  696. end;
  697. end
  698. else
  699. begin
  700. if try_to_consume(_LKLAMMER) then
  701. begin
  702. para:=parse_paras(false,false);
  703. consume(_RKLAMMER);
  704. end;
  705. end;
  706. if assigned(obj) then
  707. begin
  708. if (st.symtabletype<>objectsymtable) then
  709. internalerror(200310031);
  710. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1);
  711. end
  712. else
  713. p1:=ccallnode.create(para,tprocsym(sym),st,p1);
  714. { indicate if this call was generated by a member and
  715. no explicit self is used, this is needed to determine
  716. how to handle a destructor call (PFV) }
  717. if membercall then
  718. include(p1.flags,nf_member_call);
  719. end;
  720. afterassignment:=prevafterassn;
  721. end;
  722. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  723. var
  724. hp,hp2 : tnode;
  725. hpp : ^tnode;
  726. currprocdef : tprocdef;
  727. begin
  728. if not assigned(pv) then
  729. internalerror(200301121);
  730. if (m_tp_procvar in aktmodeswitches) then
  731. begin
  732. hp:=p2;
  733. hpp:=@p2;
  734. while assigned(hp) and
  735. (hp.nodetype=typeconvn) do
  736. begin
  737. hp:=ttypeconvnode(hp).left;
  738. { save orignal address of the old tree so we can replace the node }
  739. hpp:=@hp;
  740. end;
  741. if (hp.nodetype=calln) and
  742. { a procvar can't have parameters! }
  743. not assigned(tcallnode(hp).left) then
  744. begin
  745. currprocdef:=tcallnode(hp).symtableprocentry.search_procdef_byprocvardef(pv);
  746. if assigned(currprocdef) then
  747. begin
  748. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  749. if (po_methodpointer in pv.procoptions) then
  750. tloadnode(hp2).set_mp(tnode(tcallnode(hp).methodpointer).getcopy);
  751. hp.destroy;
  752. { replace the old callnode with the new loadnode }
  753. hpp^:=hp2;
  754. end;
  755. end;
  756. end;
  757. end;
  758. { the following procedure handles the access to a property symbol }
  759. procedure handle_propertysym(sym : tsym;st : tsymtable;var p1 : tnode);
  760. var
  761. paras : tnode;
  762. p2 : tnode;
  763. membercall : boolean;
  764. begin
  765. paras:=nil;
  766. { property parameters? read them only if the property really }
  767. { has parameters }
  768. if (ppo_hasparameters in tpropertysym(sym).propoptions) then
  769. begin
  770. if try_to_consume(_LECKKLAMMER) then
  771. begin
  772. paras:=parse_paras(false,true);
  773. consume(_RECKKLAMMER);
  774. end;
  775. end;
  776. { indexed property }
  777. if (ppo_indexed in tpropertysym(sym).propoptions) then
  778. begin
  779. p2:=cordconstnode.create(tpropertysym(sym).index,tpropertysym(sym).indextype,true);
  780. paras:=ccallparanode.create(p2,paras);
  781. end;
  782. { we need only a write property if a := follows }
  783. { if not(afterassignment) and not(in_args) then }
  784. if token=_ASSIGNMENT then
  785. begin
  786. { write property: }
  787. if not tpropertysym(sym).writeaccess.empty then
  788. begin
  789. case tpropertysym(sym).writeaccess.firstsym^.sym.typ of
  790. procsym :
  791. begin
  792. { generate the method call }
  793. membercall:=maybe_load_methodpointer(st,p1);
  794. p1:=ccallnode.create(paras,
  795. tprocsym(tpropertysym(sym).writeaccess.firstsym^.sym),st,p1);
  796. if membercall then
  797. include(tcallnode(p1).flags,nf_member_call);
  798. paras:=nil;
  799. consume(_ASSIGNMENT);
  800. { read the expression }
  801. if tpropertysym(sym).proptype.def.deftype=procvardef then
  802. getprocvardef:=tprocvardef(tpropertysym(sym).proptype.def);
  803. p2:=comp_expr(true);
  804. if assigned(getprocvardef) then
  805. handle_procvar(getprocvardef,p2);
  806. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  807. include(tcallnode(p1).flags,nf_isproperty);
  808. getprocvardef:=nil;
  809. end;
  810. varsym :
  811. begin
  812. { generate access code }
  813. symlist_to_node(p1,st,tpropertysym(sym).writeaccess);
  814. include(p1.flags,nf_isproperty);
  815. consume(_ASSIGNMENT);
  816. { read the expression }
  817. p2:=comp_expr(true);
  818. p1:=cassignmentnode.create(p1,p2);
  819. end
  820. else
  821. begin
  822. p1:=cerrornode.create;
  823. Message(parser_e_no_procedure_to_access_property);
  824. end;
  825. end;
  826. end
  827. else
  828. begin
  829. p1:=cerrornode.create;
  830. Message(parser_e_no_procedure_to_access_property);
  831. end;
  832. end
  833. else
  834. begin
  835. { read property: }
  836. if not tpropertysym(sym).readaccess.empty then
  837. begin
  838. case tpropertysym(sym).readaccess.firstsym^.sym.typ of
  839. varsym :
  840. begin
  841. { generate access code }
  842. symlist_to_node(p1,st,tpropertysym(sym).readaccess);
  843. include(p1.flags,nf_isproperty);
  844. end;
  845. procsym :
  846. begin
  847. { generate the method call }
  848. membercall:=maybe_load_methodpointer(st,p1);
  849. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).readaccess.firstsym^.sym),st,p1);
  850. if membercall then
  851. include(tcallnode(p1).flags,nf_member_call);
  852. paras:=nil;
  853. include(p1.flags,nf_isproperty);
  854. end
  855. else
  856. begin
  857. p1:=cerrornode.create;
  858. Message(type_e_mismatch);
  859. end;
  860. end;
  861. end
  862. else
  863. begin
  864. { error, no function to read property }
  865. p1:=cerrornode.create;
  866. Message(parser_e_no_procedure_to_access_property);
  867. end;
  868. end;
  869. { release paras if not used }
  870. if assigned(paras) then
  871. paras.free;
  872. end;
  873. { the ID token has to be consumed before calling this function }
  874. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callnflags:tnodeflags);
  875. var
  876. static_name : string;
  877. isclassref : boolean;
  878. srsymtable : tsymtable;
  879. {$ifdef CHECKINHERITEDRESULT}
  880. newstatement : tstatementnode;
  881. newblock : tblocknode;
  882. {$endif CHECKINHERITEDRESULT}
  883. begin
  884. if sym=nil then
  885. begin
  886. { pattern is still valid unless
  887. there is another ID just after the ID of sym }
  888. Message1(sym_e_id_no_member,pattern);
  889. p1.free;
  890. p1:=cerrornode.create;
  891. { try to clean up }
  892. again:=false;
  893. end
  894. else
  895. begin
  896. if assigned(p1) then
  897. begin
  898. if not assigned(p1.resulttype.def) then
  899. do_resulttypepass(p1);
  900. isclassref:=(p1.resulttype.def.deftype=classrefdef);
  901. end
  902. else
  903. isclassref:=false;
  904. { we assume, that only procsyms and varsyms are in an object }
  905. { symbol table, for classes, properties are allowed }
  906. case sym.typ of
  907. procsym:
  908. begin
  909. do_proc_call(sym,sym.owner,classh,
  910. (getaddr and not(token in [_CARET,_POINT])),
  911. again,p1);
  912. { add provided flags }
  913. if (p1.nodetype=calln) then
  914. p1.flags:=p1.flags+callnflags;
  915. { we need to know which procedure is called }
  916. do_resulttypepass(p1);
  917. { now we know the method that is called }
  918. if (p1.nodetype=calln) and
  919. assigned(tcallnode(p1).procdefinition) then
  920. begin
  921. { calling using classref? }
  922. if isclassref and
  923. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  924. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  925. Message(parser_e_only_class_methods_via_class_ref);
  926. {$ifdef CHECKINHERITEDRESULT}
  927. { when calling inherited constructor we need to check the return value }
  928. if (nf_inherited in callnflags) and
  929. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  930. begin
  931. {
  932. For Classes:
  933. self:=inherited constructor
  934. if self=nil then
  935. exit
  936. For objects:
  937. if inherited constructor=false then
  938. begin
  939. self:=nil;
  940. exit;
  941. end;
  942. }
  943. if is_class(tprocdef(tcallnode(p1).procdefinition)._class) then
  944. begin
  945. newblock:=internalstatements(newstatement,true);
  946. addstatement(newstatement,cassignmentnode.create(
  947. ctypeconvnode.create(
  948. load_self_pointer_node,
  949. voidpointertype),
  950. ctypeconvnode.create(
  951. p1,
  952. voidpointertype)));
  953. addstatement(newstatement,cifnode.create(
  954. caddnode.create(equaln,
  955. load_self_pointer_node,
  956. cnilnode.create),
  957. cexitnode.create(nil),
  958. nil));
  959. p1:=newblock;
  960. end
  961. else
  962. if is_object(tprocdef(tcallnode(p1).procdefinition)._class) then
  963. begin
  964. newblock:=internalstatements(newstatement,true);
  965. addstatement(newstatement,call_fail_node);
  966. addstatement(newstatement,cexitnode.create(nil));
  967. p1:=cifnode.create(
  968. caddnode.create(equaln,
  969. cordconstnode.create(0,booltype,false),
  970. p1),
  971. newblock,
  972. nil);
  973. end
  974. else
  975. internalerror(200305133);
  976. end;
  977. {$endif CHECKINHERITEDRESULT}
  978. do_resulttypepass(p1);
  979. end;
  980. end;
  981. varsym:
  982. begin
  983. if (sp_static in sym.symoptions) then
  984. begin
  985. static_name:=lower(sym.owner.name^)+'_'+sym.name;
  986. searchsym(static_name,sym,srsymtable);
  987. check_hints(sym);
  988. p1.free;
  989. p1:=cloadnode.create(sym,srsymtable);
  990. end
  991. else
  992. begin
  993. if isclassref then
  994. Message(parser_e_only_class_methods_via_class_ref);
  995. p1:=csubscriptnode.create(sym,p1);
  996. end;
  997. end;
  998. propertysym:
  999. begin
  1000. if isclassref then
  1001. Message(parser_e_only_class_methods_via_class_ref);
  1002. handle_propertysym(sym,sym.owner,p1);
  1003. end;
  1004. else internalerror(16);
  1005. end;
  1006. end;
  1007. end;
  1008. {****************************************************************************
  1009. Factor
  1010. ****************************************************************************}
  1011. {$ifdef fpc}
  1012. {$maxfpuregisters 0}
  1013. {$endif fpc}
  1014. function factor(getaddr : boolean) : tnode;
  1015. {---------------------------------------------
  1016. Factor_read_id
  1017. ---------------------------------------------}
  1018. procedure factor_read_id(var p1:tnode;var again:boolean);
  1019. var
  1020. pc : pchar;
  1021. len : longint;
  1022. srsym : tsym;
  1023. possible_error : boolean;
  1024. srsymtable : tsymtable;
  1025. storesymtablestack : tsymtable;
  1026. htype : ttype;
  1027. static_name : string;
  1028. begin
  1029. { allow post fix operators }
  1030. again:=true;
  1031. consume_sym(srsym,srsymtable);
  1032. { Access to funcret or need to call the function? }
  1033. if (srsym.typ in [absolutesym,varsym]) and
  1034. (vo_is_funcret in tvarsym(srsym).varoptions) and
  1035. (
  1036. (token=_LKLAMMER) or
  1037. (not(m_fpc in aktmodeswitches) and
  1038. (afterassignment or in_args) and
  1039. not(vo_is_result in tvarsym(srsym).varoptions))
  1040. ) then
  1041. begin
  1042. storesymtablestack:=symtablestack;
  1043. symtablestack:=srsym.owner.next;
  1044. searchsym(srsym.name,srsym,srsymtable);
  1045. if not assigned(srsym) then
  1046. srsym:=generrorsym;
  1047. if (srsym.typ<>procsym) then
  1048. Message(cg_e_illegal_expression);
  1049. symtablestack:=storesymtablestack;
  1050. end;
  1051. begin
  1052. { check semantics of private }
  1053. if (srsym.typ in [propertysym,procsym,varsym]) and
  1054. (srsym.owner.symtabletype=objectsymtable) then
  1055. begin
  1056. if (sp_private in srsym.symoptions) and
  1057. (tobjectdef(srsym.owner.defowner).owner.symtabletype=globalsymtable) and
  1058. (tobjectdef(srsym.owner.defowner).owner.unitid<>0) then
  1059. Message(parser_e_cant_access_private_member);
  1060. end;
  1061. case srsym.typ of
  1062. absolutesym :
  1063. begin
  1064. if (tabsolutesym(srsym).abstyp=tovar) then
  1065. begin
  1066. p1:=nil;
  1067. symlist_to_node(p1,nil,tabsolutesym(srsym).ref);
  1068. p1:=ctypeconvnode.create(p1,tabsolutesym(srsym).vartype);
  1069. include(p1.flags,nf_absolute);
  1070. end
  1071. else
  1072. p1:=cloadnode.create(srsym,srsymtable);
  1073. end;
  1074. varsym :
  1075. begin
  1076. if (sp_static in srsym.symoptions) then
  1077. begin
  1078. static_name:=lower(srsym.owner.name^)+'_'+srsym.name;
  1079. searchsym(static_name,srsym,srsymtable);
  1080. check_hints(srsym);
  1081. end
  1082. else
  1083. begin
  1084. { are we in a class method, we check here the
  1085. srsymtable, because a field in another object
  1086. also has objectsymtable. And withsymtable is
  1087. not possible for self in class methods (PFV) }
  1088. if (srsymtable.symtabletype=objectsymtable) and
  1089. assigned(current_procinfo) and
  1090. (po_classmethod in current_procinfo.procdef.procoptions) then
  1091. Message(parser_e_only_class_methods);
  1092. end;
  1093. case srsymtable.symtabletype of
  1094. objectsymtable :
  1095. p1:=csubscriptnode.create(srsym,load_self_node);
  1096. withsymtable :
  1097. p1:=csubscriptnode.create(srsym,tnode(twithsymtable(srsymtable).withrefnode).getcopy);
  1098. else
  1099. p1:=cloadnode.create(srsym,srsymtable);
  1100. end;
  1101. end;
  1102. typedconstsym :
  1103. begin
  1104. p1:=cloadnode.create(srsym,srsymtable);
  1105. end;
  1106. syssym :
  1107. begin
  1108. p1:=statement_syssym(tsyssym(srsym).number);
  1109. end;
  1110. typesym :
  1111. begin
  1112. htype.setsym(srsym);
  1113. if not assigned(htype.def) then
  1114. begin
  1115. again:=false;
  1116. end
  1117. else
  1118. begin
  1119. if try_to_consume(_LKLAMMER) then
  1120. begin
  1121. p1:=comp_expr(true);
  1122. consume(_RKLAMMER);
  1123. p1:=ctypeconvnode.create_explicit(p1,htype);
  1124. end
  1125. else { not LKLAMMER }
  1126. if (token=_POINT) and
  1127. is_object(htype.def) then
  1128. begin
  1129. consume(_POINT);
  1130. if assigned(current_procinfo) and
  1131. assigned(current_procinfo.procdef._class) and
  1132. not(getaddr) then
  1133. begin
  1134. if current_procinfo.procdef._class.is_related(tobjectdef(htype.def)) then
  1135. begin
  1136. p1:=ctypenode.create(htype);
  1137. { search also in inherited methods }
  1138. srsym:=searchsym_in_class(tobjectdef(htype.def),pattern);
  1139. check_hints(srsym);
  1140. consume(_ID);
  1141. do_member_read(tobjectdef(htype.def),false,srsym,p1,again,[]);
  1142. end
  1143. else
  1144. begin
  1145. Message(parser_e_no_super_class);
  1146. again:=false;
  1147. end;
  1148. end
  1149. else
  1150. begin
  1151. { allows @TObject.Load }
  1152. { also allows static methods and variables }
  1153. p1:=ctypenode.create(htype);
  1154. { TP allows also @TMenu.Load if Load is only }
  1155. { defined in an anchestor class }
  1156. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1157. check_hints(srsym);
  1158. if not assigned(srsym) then
  1159. Message1(sym_e_id_no_member,pattern)
  1160. else if not(getaddr) and not(sp_static in srsym.symoptions) then
  1161. Message(sym_e_only_static_in_static)
  1162. else
  1163. begin
  1164. consume(_ID);
  1165. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1166. end;
  1167. end;
  1168. end
  1169. else
  1170. begin
  1171. { class reference ? }
  1172. if is_class(htype.def) then
  1173. begin
  1174. if getaddr and (token=_POINT) then
  1175. begin
  1176. consume(_POINT);
  1177. { allows @Object.Method }
  1178. { also allows static methods and variables }
  1179. p1:=ctypenode.create(htype);
  1180. { TP allows also @TMenu.Load if Load is only }
  1181. { defined in an anchestor class }
  1182. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1183. check_hints(srsym);
  1184. if not assigned(srsym) then
  1185. Message1(sym_e_id_no_member,pattern)
  1186. else
  1187. begin
  1188. consume(_ID);
  1189. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1190. end;
  1191. end
  1192. else
  1193. begin
  1194. p1:=ctypenode.create(htype);
  1195. { For a type block we simply return only
  1196. the type. For all other blocks we return
  1197. a loadvmt node }
  1198. if (block_type<>bt_type) then
  1199. p1:=cloadvmtaddrnode.create(p1);
  1200. end;
  1201. end
  1202. else
  1203. p1:=ctypenode.create(htype);
  1204. end;
  1205. end;
  1206. end;
  1207. enumsym :
  1208. begin
  1209. p1:=genenumnode(tenumsym(srsym));
  1210. end;
  1211. constsym :
  1212. begin
  1213. case tconstsym(srsym).consttyp of
  1214. constord :
  1215. begin
  1216. if tconstsym(srsym).consttype.def=nil then
  1217. internalerror(200403232);
  1218. p1:=cordconstnode.create(tconstsym(srsym).value.valueord,tconstsym(srsym).consttype,true);
  1219. end;
  1220. conststring :
  1221. begin
  1222. len:=tconstsym(srsym).value.len;
  1223. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1224. len:=255;
  1225. getmem(pc,len+1);
  1226. move(pchar(tconstsym(srsym).value.valueptr)^,pc^,len);
  1227. pc[len]:=#0;
  1228. p1:=cstringconstnode.createpchar(pc,len);
  1229. end;
  1230. constreal :
  1231. p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
  1232. constset :
  1233. p1:=csetconstnode.create(pconstset(tconstsym(srsym).value.valueptr),tconstsym(srsym).consttype);
  1234. constpointer :
  1235. p1:=cpointerconstnode.create(tconstsym(srsym).value.valueordptr,tconstsym(srsym).consttype);
  1236. constnil :
  1237. p1:=cnilnode.create;
  1238. constresourcestring:
  1239. begin
  1240. p1:=cloadnode.create(srsym,srsymtable);
  1241. do_resulttypepass(p1);
  1242. p1.resulttype:=cansistringtype;
  1243. end;
  1244. constguid :
  1245. p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
  1246. end;
  1247. end;
  1248. procsym :
  1249. begin
  1250. { are we in a class method ? }
  1251. possible_error:=(srsymtable.symtabletype<>withsymtable) and
  1252. (srsym.owner.symtabletype=objectsymtable) and
  1253. not(is_interface(tdef(srsym.owner.defowner))) and
  1254. assigned(current_procinfo) and
  1255. (po_classmethod in current_procinfo.procdef.procoptions);
  1256. do_proc_call(srsym,srsymtable,nil,
  1257. (getaddr and not(token in [_CARET,_POINT])),
  1258. again,p1);
  1259. { we need to know which procedure is called }
  1260. if possible_error then
  1261. begin
  1262. do_resulttypepass(p1);
  1263. if not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1264. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) then
  1265. Message(parser_e_only_class_methods);
  1266. end;
  1267. end;
  1268. propertysym :
  1269. begin
  1270. { access to property in a method }
  1271. { are we in a class method ? }
  1272. if (srsymtable.symtabletype=objectsymtable) and
  1273. assigned(current_procinfo) and
  1274. (po_classmethod in current_procinfo.procdef.procoptions) then
  1275. Message(parser_e_only_class_methods);
  1276. { no method pointer }
  1277. p1:=nil;
  1278. handle_propertysym(srsym,srsymtable,p1);
  1279. end;
  1280. labelsym :
  1281. begin
  1282. consume(_COLON);
  1283. if tlabelsym(srsym).defined then
  1284. Message(sym_e_label_already_defined);
  1285. tlabelsym(srsym).defined:=true;
  1286. p1:=clabelnode.create(tlabelsym(srsym),nil);
  1287. end;
  1288. errorsym :
  1289. begin
  1290. p1:=cerrornode.create;
  1291. if try_to_consume(_LKLAMMER) then
  1292. begin
  1293. parse_paras(false,false);
  1294. consume(_RKLAMMER);
  1295. end;
  1296. end;
  1297. else
  1298. begin
  1299. p1:=cerrornode.create;
  1300. Message(cg_e_illegal_expression);
  1301. end;
  1302. end; { end case }
  1303. end;
  1304. end;
  1305. {---------------------------------------------
  1306. Factor_Read_Set
  1307. ---------------------------------------------}
  1308. { Read a set between [] }
  1309. function factor_read_set:tnode;
  1310. var
  1311. p1,p2 : tnode;
  1312. lastp,
  1313. buildp : tarrayconstructornode;
  1314. begin
  1315. buildp:=nil;
  1316. { be sure that a least one arrayconstructn is used, also for an
  1317. empty [] }
  1318. if token=_RECKKLAMMER then
  1319. buildp:=carrayconstructornode.create(nil,buildp)
  1320. else
  1321. repeat
  1322. p1:=comp_expr(true);
  1323. if try_to_consume(_POINTPOINT) then
  1324. begin
  1325. p2:=comp_expr(true);
  1326. p1:=carrayconstructorrangenode.create(p1,p2);
  1327. end;
  1328. { insert at the end of the tree, to get the correct order }
  1329. if not assigned(buildp) then
  1330. begin
  1331. buildp:=carrayconstructornode.create(p1,nil);
  1332. lastp:=buildp;
  1333. end
  1334. else
  1335. begin
  1336. lastp.right:=carrayconstructornode.create(p1,nil);
  1337. lastp:=tarrayconstructornode(lastp.right);
  1338. end;
  1339. { there could be more elements }
  1340. until not try_to_consume(_COMMA);
  1341. factor_read_set:=buildp;
  1342. end;
  1343. {---------------------------------------------
  1344. PostFixOperators
  1345. ---------------------------------------------}
  1346. procedure postfixoperators(var p1:tnode;var again:boolean);
  1347. { tries to avoid syntax errors after invalid qualifiers }
  1348. procedure recoverconsume_postfixops;
  1349. begin
  1350. repeat
  1351. if not try_to_consume(_CARET) then
  1352. if try_to_consume(_POINT) then
  1353. try_to_consume(_ID)
  1354. else if try_to_consume(_LECKKLAMMER) then
  1355. begin
  1356. repeat
  1357. comp_expr(true);
  1358. until not try_to_consume(_COMMA);
  1359. consume(_RECKKLAMMER);
  1360. end
  1361. else
  1362. break;
  1363. until false;
  1364. end;
  1365. var
  1366. store_static : boolean;
  1367. protsym : tpropertysym;
  1368. p2,p3 : tnode;
  1369. hsym : tsym;
  1370. classh : tobjectdef;
  1371. begin
  1372. again:=true;
  1373. while again do
  1374. begin
  1375. { we need the resulttype }
  1376. do_resulttypepass(p1);
  1377. if codegenerror then
  1378. begin
  1379. recoverconsume_postfixops;
  1380. exit;
  1381. end;
  1382. { handle token }
  1383. case token of
  1384. _CARET:
  1385. begin
  1386. consume(_CARET);
  1387. if (p1.resulttype.def.deftype<>pointerdef) then
  1388. begin
  1389. { ^ as binary operator is a problem!!!! (FK) }
  1390. again:=false;
  1391. Message(cg_e_invalid_qualifier);
  1392. recoverconsume_postfixops;
  1393. p1.destroy;
  1394. p1:=cerrornode.create;
  1395. end
  1396. else
  1397. begin
  1398. p1:=cderefnode.create(p1);
  1399. end;
  1400. end;
  1401. _LECKKLAMMER:
  1402. begin
  1403. if is_class_or_interface(p1.resulttype.def) then
  1404. begin
  1405. { default property }
  1406. protsym:=search_default_property(tobjectdef(p1.resulttype.def));
  1407. if not(assigned(protsym)) then
  1408. begin
  1409. p1.destroy;
  1410. p1:=cerrornode.create;
  1411. again:=false;
  1412. message(parser_e_no_default_property_available);
  1413. end
  1414. else
  1415. begin
  1416. { The property symbol is referenced indirect }
  1417. inc(protsym.refs);
  1418. handle_propertysym(protsym,protsym.owner,p1);
  1419. end;
  1420. end
  1421. else
  1422. begin
  1423. consume(_LECKKLAMMER);
  1424. repeat
  1425. case p1.resulttype.def.deftype of
  1426. pointerdef:
  1427. begin
  1428. { support delphi autoderef }
  1429. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=arraydef) and
  1430. (m_autoderef in aktmodeswitches) then
  1431. begin
  1432. p1:=cderefnode.create(p1);
  1433. end;
  1434. p2:=comp_expr(true);
  1435. p1:=cvecnode.create(p1,p2);
  1436. end;
  1437. variantdef,
  1438. stringdef :
  1439. begin
  1440. p2:=comp_expr(true);
  1441. p1:=cvecnode.create(p1,p2);
  1442. end;
  1443. arraydef :
  1444. begin
  1445. p2:=comp_expr(true);
  1446. { support SEG:OFS for go32v2 Mem[] }
  1447. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  1448. (p1.nodetype=loadn) and
  1449. assigned(tloadnode(p1).symtableentry) and
  1450. assigned(tloadnode(p1).symtableentry.owner.name) and
  1451. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1452. ((tloadnode(p1).symtableentry.name='MEM') or
  1453. (tloadnode(p1).symtableentry.name='MEMW') or
  1454. (tloadnode(p1).symtableentry.name='MEML')) then
  1455. begin
  1456. if try_to_consume(_COLON) then
  1457. begin
  1458. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1459. p2:=comp_expr(true);
  1460. p2:=caddnode.create(addn,p2,p3);
  1461. p1:=cvecnode.create(p1,p2);
  1462. include(tvecnode(p1).flags,nf_memseg);
  1463. include(tvecnode(p1).flags,nf_memindex);
  1464. end
  1465. else
  1466. begin
  1467. p1:=cvecnode.create(p1,p2);
  1468. include(tvecnode(p1).flags,nf_memindex);
  1469. end;
  1470. end
  1471. else
  1472. p1:=cvecnode.create(p1,p2);
  1473. end;
  1474. else
  1475. begin
  1476. Message(cg_e_invalid_qualifier);
  1477. p1.destroy;
  1478. p1:=cerrornode.create;
  1479. comp_expr(true);
  1480. again:=false;
  1481. end;
  1482. end;
  1483. do_resulttypepass(p1);
  1484. until not try_to_consume(_COMMA);;
  1485. consume(_RECKKLAMMER);
  1486. end;
  1487. end;
  1488. _POINT :
  1489. begin
  1490. consume(_POINT);
  1491. if (p1.resulttype.def.deftype=pointerdef) and
  1492. (m_autoderef in aktmodeswitches) then
  1493. begin
  1494. p1:=cderefnode.create(p1);
  1495. do_resulttypepass(p1);
  1496. end;
  1497. case p1.resulttype.def.deftype of
  1498. recorddef:
  1499. begin
  1500. hsym:=tsym(trecorddef(p1.resulttype.def).symtable.search(pattern));
  1501. check_hints(hsym);
  1502. if assigned(hsym) and
  1503. (hsym.typ=varsym) then
  1504. p1:=csubscriptnode.create(hsym,p1)
  1505. else
  1506. begin
  1507. Message1(sym_e_illegal_field,pattern);
  1508. p1.destroy;
  1509. p1:=cerrornode.create;
  1510. end;
  1511. consume(_ID);
  1512. end;
  1513. variantdef:
  1514. begin
  1515. end;
  1516. classrefdef:
  1517. begin
  1518. classh:=tobjectdef(tclassrefdef(p1.resulttype.def).pointertype.def);
  1519. hsym:=searchsym_in_class(classh,pattern);
  1520. check_hints(hsym);
  1521. if hsym=nil then
  1522. begin
  1523. Message1(sym_e_id_no_member,pattern);
  1524. p1.destroy;
  1525. p1:=cerrornode.create;
  1526. { try to clean up }
  1527. consume(_ID);
  1528. end
  1529. else
  1530. begin
  1531. consume(_ID);
  1532. do_member_read(classh,getaddr,hsym,p1,again,[]);
  1533. end;
  1534. end;
  1535. objectdef:
  1536. begin
  1537. store_static:=allow_only_static;
  1538. allow_only_static:=false;
  1539. classh:=tobjectdef(p1.resulttype.def);
  1540. hsym:=searchsym_in_class(classh,pattern);
  1541. check_hints(hsym);
  1542. allow_only_static:=store_static;
  1543. if hsym=nil then
  1544. begin
  1545. Message1(sym_e_id_no_member,pattern);
  1546. p1.destroy;
  1547. p1:=cerrornode.create;
  1548. { try to clean up }
  1549. consume(_ID);
  1550. end
  1551. else
  1552. begin
  1553. consume(_ID);
  1554. do_member_read(classh,getaddr,hsym,p1,again,[]);
  1555. end;
  1556. end;
  1557. pointerdef:
  1558. begin
  1559. Message(cg_e_invalid_qualifier);
  1560. if tpointerdef(p1.resulttype.def).pointertype.def.deftype in [recorddef,objectdef,classrefdef] then
  1561. Message(parser_h_maybe_deref_caret_missing);
  1562. end;
  1563. else
  1564. begin
  1565. Message(cg_e_invalid_qualifier);
  1566. p1.destroy;
  1567. p1:=cerrornode.create;
  1568. consume(_ID);
  1569. end;
  1570. end;
  1571. end;
  1572. else
  1573. begin
  1574. { is this a procedure variable ? }
  1575. if assigned(p1.resulttype.def) and
  1576. (p1.resulttype.def.deftype=procvardef) then
  1577. begin
  1578. if assigned(getprocvardef) and
  1579. equal_defs(p1.resulttype.def,getprocvardef) then
  1580. again:=false
  1581. else
  1582. begin
  1583. if try_to_consume(_LKLAMMER) then
  1584. begin
  1585. p2:=parse_paras(false,false);
  1586. consume(_RKLAMMER);
  1587. p1:=ccallnode.create_procvar(p2,p1);
  1588. { proc():= is never possible }
  1589. if token=_ASSIGNMENT then
  1590. begin
  1591. Message(cg_e_illegal_expression);
  1592. p1.free;
  1593. p1:=cerrornode.create;
  1594. again:=false;
  1595. end;
  1596. end
  1597. else
  1598. again:=false;
  1599. end;
  1600. end
  1601. else
  1602. again:=false;
  1603. end;
  1604. end;
  1605. end; { while again }
  1606. end;
  1607. {---------------------------------------------
  1608. Factor (Main)
  1609. ---------------------------------------------}
  1610. var
  1611. l : longint;
  1612. {$ifndef cpu64bit}
  1613. card : cardinal;
  1614. {$endif cpu64bit}
  1615. ic : TConstExprInt;
  1616. oldp1,
  1617. p1 : tnode;
  1618. code : integer;
  1619. again : boolean;
  1620. sym : tsym;
  1621. pd : tprocdef;
  1622. classh : tobjectdef;
  1623. d : bestreal;
  1624. hs : string;
  1625. htype : ttype;
  1626. filepos : tfileposinfo;
  1627. {---------------------------------------------
  1628. Helpers
  1629. ---------------------------------------------}
  1630. procedure check_tokenpos;
  1631. begin
  1632. if (p1<>oldp1) then
  1633. begin
  1634. if assigned(p1) then
  1635. p1.set_tree_filepos(filepos);
  1636. oldp1:=p1;
  1637. filepos:=akttokenpos;
  1638. end;
  1639. end;
  1640. begin
  1641. oldp1:=nil;
  1642. p1:=nil;
  1643. filepos:=akttokenpos;
  1644. again:=false;
  1645. if token=_ID then
  1646. begin
  1647. again:=true;
  1648. { Handle references to self }
  1649. if (idtoken=_SELF) and
  1650. not(block_type in [bt_const,bt_type]) and
  1651. assigned(current_procinfo) and
  1652. assigned(current_procinfo.procdef._class) then
  1653. begin
  1654. p1:=load_self_node;
  1655. consume(_ID);
  1656. again:=true;
  1657. end
  1658. else
  1659. factor_read_id(p1,again);
  1660. if again then
  1661. begin
  1662. check_tokenpos;
  1663. { handle post fix operators }
  1664. postfixoperators(p1,again);
  1665. end;
  1666. end
  1667. else
  1668. case token of
  1669. _INHERITED :
  1670. begin
  1671. again:=true;
  1672. consume(_INHERITED);
  1673. if assigned(current_procinfo) and
  1674. assigned(current_procinfo.procdef._class) then
  1675. begin
  1676. classh:=current_procinfo.procdef._class.childof;
  1677. { if inherited; only then we need the method with
  1678. the same name }
  1679. if token in endtokens then
  1680. begin
  1681. hs:=current_procinfo.procdef.procsym.name;
  1682. anon_inherited:=true;
  1683. { For message methods we need to search using the message
  1684. number or string }
  1685. pd:=tprocsym(current_procinfo.procdef.procsym).first_procdef;
  1686. if (po_msgint in pd.procoptions) then
  1687. sym:=searchsym_in_class_by_msgint(classh,pd.messageinf.i)
  1688. else
  1689. if (po_msgstr in pd.procoptions) then
  1690. sym:=searchsym_in_class_by_msgstr(classh,pd.messageinf.str)
  1691. else
  1692. sym:=searchsym_in_class(classh,hs);
  1693. end
  1694. else
  1695. begin
  1696. hs:=pattern;
  1697. consume(_ID);
  1698. anon_inherited:=false;
  1699. sym:=searchsym_in_class(classh,hs);
  1700. end;
  1701. if assigned(sym) then
  1702. begin
  1703. check_hints(sym);
  1704. { load the procdef from the inherited class and
  1705. not from self }
  1706. if sym.typ=procsym then
  1707. begin
  1708. htype.setdef(classh);
  1709. if (po_classmethod in current_procinfo.procdef.procoptions) or
  1710. (po_staticmethod in current_procinfo.procdef.procoptions) then
  1711. htype.setdef(tclassrefdef.create(htype));
  1712. p1:=ctypenode.create(htype);
  1713. end;
  1714. do_member_read(classh,false,sym,p1,again,[nf_inherited,nf_anon_inherited]);
  1715. end
  1716. else
  1717. begin
  1718. if anon_inherited then
  1719. begin
  1720. { For message methods we need to call DefaultHandler }
  1721. if (po_msgint in pd.procoptions) or
  1722. (po_msgstr in pd.procoptions) then
  1723. begin
  1724. sym:=searchsym_in_class(classh,'DEFAULTHANDLER');
  1725. if not assigned(sym) or
  1726. (sym.typ<>procsym) then
  1727. internalerror(200303171);
  1728. p1:=nil;
  1729. do_proc_call(sym,sym.owner,classh,false,again,p1);
  1730. end
  1731. else
  1732. begin
  1733. { we need to ignore the inherited; }
  1734. p1:=cnothingnode.create;
  1735. end;
  1736. end
  1737. else
  1738. begin
  1739. Message1(sym_e_id_no_member,hs);
  1740. p1:=cerrornode.create;
  1741. end;
  1742. again:=false;
  1743. end;
  1744. { turn auto inheriting off }
  1745. anon_inherited:=false;
  1746. end
  1747. else
  1748. begin
  1749. Message(parser_e_generic_methods_only_in_methods);
  1750. again:=false;
  1751. p1:=cerrornode.create;
  1752. end;
  1753. postfixoperators(p1,again);
  1754. end;
  1755. _INTCONST :
  1756. begin
  1757. {$ifdef cpu64bit}
  1758. val(pattern,ic,code);
  1759. if code=0 then
  1760. begin
  1761. consume(_INTCONST);
  1762. int_to_type(card,htype);
  1763. p1:=cordconstnode.create(ic,htype,true);
  1764. end;
  1765. {$else cpu64bit}
  1766. { try cardinal first }
  1767. val(pattern,card,code);
  1768. if code=0 then
  1769. begin
  1770. consume(_INTCONST);
  1771. int_to_type(card,htype);
  1772. p1:=cordconstnode.create(card,htype,true);
  1773. end
  1774. else
  1775. begin
  1776. { then longint }
  1777. valint(pattern,l,code);
  1778. if code = 0 then
  1779. begin
  1780. consume(_INTCONST);
  1781. int_to_type(l,htype);
  1782. p1:=cordconstnode.create(l,htype,true);
  1783. end
  1784. else
  1785. begin
  1786. { then int64 }
  1787. val(pattern,ic,code);
  1788. if code=0 then
  1789. begin
  1790. consume(_INTCONST);
  1791. int_to_type(ic,htype);
  1792. p1:=cordconstnode.create(ic,htype,true);
  1793. end;
  1794. end;
  1795. end;
  1796. {$endif cpu64bit}
  1797. if code<>0 then
  1798. begin
  1799. { finally float }
  1800. val(pattern,d,code);
  1801. if code<>0 then
  1802. begin
  1803. Message(cg_e_invalid_integer);
  1804. consume(_INTCONST);
  1805. l:=1;
  1806. p1:=cordconstnode.create(l,sinttype,true);
  1807. end
  1808. else
  1809. begin
  1810. consume(_INTCONST);
  1811. p1:=crealconstnode.create(d,pbestrealtype^);
  1812. end;
  1813. end;
  1814. end;
  1815. _REALNUMBER :
  1816. begin
  1817. val(pattern,d,code);
  1818. if code<>0 then
  1819. begin
  1820. Message(parser_e_error_in_real);
  1821. d:=1.0;
  1822. end;
  1823. consume(_REALNUMBER);
  1824. p1:=crealconstnode.create(d,pbestrealtype^);
  1825. end;
  1826. _STRING :
  1827. begin
  1828. string_dec(htype);
  1829. { STRING can be also a type cast }
  1830. if try_to_consume(_LKLAMMER) then
  1831. begin
  1832. p1:=comp_expr(true);
  1833. consume(_RKLAMMER);
  1834. p1:=ctypeconvnode.create_explicit(p1,htype);
  1835. { handle postfix operators here e.g. string(a)[10] }
  1836. again:=true;
  1837. postfixoperators(p1,again);
  1838. end
  1839. else
  1840. p1:=ctypenode.create(htype);
  1841. end;
  1842. _FILE :
  1843. begin
  1844. htype:=cfiletype;
  1845. consume(_FILE);
  1846. { FILE can be also a type cast }
  1847. if try_to_consume(_LKLAMMER) then
  1848. begin
  1849. p1:=comp_expr(true);
  1850. consume(_RKLAMMER);
  1851. p1:=ctypeconvnode.create_explicit(p1,htype);
  1852. { handle postfix operators here e.g. string(a)[10] }
  1853. again:=true;
  1854. postfixoperators(p1,again);
  1855. end
  1856. else
  1857. begin
  1858. p1:=ctypenode.create(htype);
  1859. end;
  1860. end;
  1861. _CSTRING :
  1862. begin
  1863. p1:=cstringconstnode.createstr(pattern,st_default);
  1864. consume(_CSTRING);
  1865. end;
  1866. _CCHAR :
  1867. begin
  1868. p1:=cordconstnode.create(ord(pattern[1]),cchartype,true);
  1869. consume(_CCHAR);
  1870. end;
  1871. _CWSTRING:
  1872. begin
  1873. p1:=cstringconstnode.createwstr(patternw);
  1874. consume(_CWSTRING);
  1875. end;
  1876. _CWCHAR:
  1877. begin
  1878. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  1879. consume(_CWCHAR);
  1880. end;
  1881. _KLAMMERAFFE :
  1882. begin
  1883. consume(_KLAMMERAFFE);
  1884. got_addrn:=true;
  1885. { support both @<x> and @(<x>) }
  1886. if try_to_consume(_LKLAMMER) then
  1887. begin
  1888. p1:=factor(true);
  1889. if token in [_CARET,_POINT,_LECKKLAMMER] then
  1890. begin
  1891. again:=true;
  1892. postfixoperators(p1,again);
  1893. end;
  1894. consume(_RKLAMMER);
  1895. end
  1896. else
  1897. p1:=factor(true);
  1898. if token in [_CARET,_POINT,_LECKKLAMMER] then
  1899. begin
  1900. again:=true;
  1901. postfixoperators(p1,again);
  1902. end;
  1903. got_addrn:=false;
  1904. p1:=caddrnode.create(p1);
  1905. if cs_typed_addresses in aktlocalswitches then
  1906. include(p1.flags,nf_typedaddr);
  1907. { Store the procvar that we are expecting, the
  1908. addrn will use the information to find the correct
  1909. procdef or it will return an error }
  1910. if assigned(getprocvardef) and
  1911. (taddrnode(p1).left.nodetype = loadn) then
  1912. taddrnode(p1).getprocvardef:=getprocvardef;
  1913. end;
  1914. _LKLAMMER :
  1915. begin
  1916. consume(_LKLAMMER);
  1917. p1:=comp_expr(true);
  1918. consume(_RKLAMMER);
  1919. { it's not a good solution }
  1920. { but (a+b)^ makes some problems }
  1921. if token in [_CARET,_POINT,_LECKKLAMMER] then
  1922. begin
  1923. again:=true;
  1924. postfixoperators(p1,again);
  1925. end;
  1926. end;
  1927. _LECKKLAMMER :
  1928. begin
  1929. consume(_LECKKLAMMER);
  1930. p1:=factor_read_set;
  1931. consume(_RECKKLAMMER);
  1932. end;
  1933. _PLUS :
  1934. begin
  1935. consume(_PLUS);
  1936. p1:=factor(false);
  1937. end;
  1938. _MINUS :
  1939. begin
  1940. consume(_MINUS);
  1941. if (token = _INTCONST) then
  1942. begin
  1943. { ugly hack, but necessary to be able to parse }
  1944. { -9223372036854775808 as int64 (JM) }
  1945. pattern := '-'+pattern;
  1946. p1:=sub_expr(oppower,false);
  1947. { -1 ** 4 should be - (1 ** 4) and not
  1948. (-1) ** 4
  1949. This was the reason of tw0869.pp test failure PM }
  1950. if p1.nodetype=starstarn then
  1951. begin
  1952. if tbinarynode(p1).left.nodetype=ordconstn then
  1953. begin
  1954. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  1955. p1:=cunaryminusnode.create(p1);
  1956. end
  1957. else if tbinarynode(p1).left.nodetype=realconstn then
  1958. begin
  1959. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  1960. p1:=cunaryminusnode.create(p1);
  1961. end
  1962. else
  1963. internalerror(20021029);
  1964. end;
  1965. end
  1966. else
  1967. begin
  1968. p1:=sub_expr(oppower,false);
  1969. p1:=cunaryminusnode.create(p1);
  1970. end;
  1971. end;
  1972. _OP_NOT :
  1973. begin
  1974. consume(_OP_NOT);
  1975. p1:=factor(false);
  1976. p1:=cnotnode.create(p1);
  1977. end;
  1978. _TRUE :
  1979. begin
  1980. consume(_TRUE);
  1981. p1:=cordconstnode.create(1,booltype,false);
  1982. end;
  1983. _FALSE :
  1984. begin
  1985. consume(_FALSE);
  1986. p1:=cordconstnode.create(0,booltype,false);
  1987. end;
  1988. _NIL :
  1989. begin
  1990. consume(_NIL);
  1991. p1:=cnilnode.create;
  1992. { It's really ugly code nil^, but delphi allows it }
  1993. if token in [_CARET] then
  1994. begin
  1995. again:=true;
  1996. postfixoperators(p1,again);
  1997. end;
  1998. end;
  1999. else
  2000. begin
  2001. p1:=cerrornode.create;
  2002. consume(token);
  2003. Message(cg_e_illegal_expression);
  2004. end;
  2005. end;
  2006. { generate error node if no node is created }
  2007. if not assigned(p1) then
  2008. begin
  2009. {$ifdef EXTDEBUG}
  2010. Comment(V_Warning,'factor: p1=nil');
  2011. {$endif}
  2012. p1:=cerrornode.create;
  2013. end;
  2014. { get the resulttype for the node }
  2015. if (not assigned(p1.resulttype.def)) then
  2016. do_resulttypepass(p1);
  2017. factor:=p1;
  2018. check_tokenpos;
  2019. end;
  2020. {$ifdef fpc}
  2021. {$maxfpuregisters default}
  2022. {$endif fpc}
  2023. {****************************************************************************
  2024. Sub_Expr
  2025. ****************************************************************************}
  2026. const
  2027. { Warning these stay be ordered !! }
  2028. operator_levels:array[Toperator_precedence] of set of Ttoken=
  2029. ([_LT,_LTE,_GT,_GTE,_EQUAL,_UNEQUAL,_OP_IN,_OP_IS],
  2030. [_PLUS,_MINUS,_OP_OR,_OP_XOR],
  2031. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  2032. _OP_AS,_OP_AND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR],
  2033. [_STARSTAR] );
  2034. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;
  2035. {Reads a subexpression while the operators are of the current precedence
  2036. level, or any higher level. Replaces the old term, simpl_expr and
  2037. simpl2_expr.}
  2038. var
  2039. p1,p2 : tnode;
  2040. oldt : Ttoken;
  2041. filepos : tfileposinfo;
  2042. begin
  2043. if pred_level=highest_precedence then
  2044. p1:=factor(false)
  2045. else
  2046. p1:=sub_expr(succ(pred_level),true);
  2047. repeat
  2048. if (token in operator_levels[pred_level]) and
  2049. ((token<>_EQUAL) or accept_equal) then
  2050. begin
  2051. oldt:=token;
  2052. filepos:=akttokenpos;
  2053. consume(token);
  2054. if pred_level=highest_precedence then
  2055. p2:=factor(false)
  2056. else
  2057. p2:=sub_expr(succ(pred_level),true);
  2058. case oldt of
  2059. _PLUS :
  2060. p1:=caddnode.create(addn,p1,p2);
  2061. _MINUS :
  2062. p1:=caddnode.create(subn,p1,p2);
  2063. _STAR :
  2064. p1:=caddnode.create(muln,p1,p2);
  2065. _SLASH :
  2066. p1:=caddnode.create(slashn,p1,p2);
  2067. _EQUAL :
  2068. p1:=caddnode.create(equaln,p1,p2);
  2069. _GT :
  2070. p1:=caddnode.create(gtn,p1,p2);
  2071. _LT :
  2072. p1:=caddnode.create(ltn,p1,p2);
  2073. _GTE :
  2074. p1:=caddnode.create(gten,p1,p2);
  2075. _LTE :
  2076. p1:=caddnode.create(lten,p1,p2);
  2077. _SYMDIF :
  2078. p1:=caddnode.create(symdifn,p1,p2);
  2079. _STARSTAR :
  2080. p1:=caddnode.create(starstarn,p1,p2);
  2081. _OP_AS :
  2082. p1:=casnode.create(p1,p2);
  2083. _OP_IN :
  2084. p1:=cinnode.create(p1,p2);
  2085. _OP_IS :
  2086. p1:=cisnode.create(p1,p2);
  2087. _OP_OR :
  2088. p1:=caddnode.create(orn,p1,p2);
  2089. _OP_AND :
  2090. p1:=caddnode.create(andn,p1,p2);
  2091. _OP_DIV :
  2092. p1:=cmoddivnode.create(divn,p1,p2);
  2093. _OP_NOT :
  2094. p1:=cnotnode.create(p1);
  2095. _OP_MOD :
  2096. p1:=cmoddivnode.create(modn,p1,p2);
  2097. _OP_SHL :
  2098. p1:=cshlshrnode.create(shln,p1,p2);
  2099. _OP_SHR :
  2100. p1:=cshlshrnode.create(shrn,p1,p2);
  2101. _OP_XOR :
  2102. p1:=caddnode.create(xorn,p1,p2);
  2103. _ASSIGNMENT :
  2104. p1:=cassignmentnode.create(p1,p2);
  2105. _CARET :
  2106. p1:=caddnode.create(caretn,p1,p2);
  2107. _UNEQUAL :
  2108. p1:=caddnode.create(unequaln,p1,p2);
  2109. end;
  2110. p1.set_tree_filepos(filepos);
  2111. end
  2112. else
  2113. break;
  2114. until false;
  2115. sub_expr:=p1;
  2116. end;
  2117. function comp_expr(accept_equal : boolean):tnode;
  2118. var
  2119. oldafterassignment : boolean;
  2120. p1 : tnode;
  2121. begin
  2122. oldafterassignment:=afterassignment;
  2123. afterassignment:=true;
  2124. p1:=sub_expr(opcompare,accept_equal);
  2125. { get the resulttype for this expression }
  2126. if not assigned(p1.resulttype.def) then
  2127. do_resulttypepass(p1);
  2128. afterassignment:=oldafterassignment;
  2129. comp_expr:=p1;
  2130. end;
  2131. function expr : tnode;
  2132. var
  2133. p1,p2 : tnode;
  2134. oldafterassignment : boolean;
  2135. oldp1 : tnode;
  2136. filepos : tfileposinfo;
  2137. begin
  2138. oldafterassignment:=afterassignment;
  2139. p1:=sub_expr(opcompare,true);
  2140. { get the resulttype for this expression }
  2141. if not assigned(p1.resulttype.def) then
  2142. do_resulttypepass(p1);
  2143. filepos:=akttokenpos;
  2144. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  2145. afterassignment:=true;
  2146. oldp1:=p1;
  2147. case token of
  2148. _POINTPOINT :
  2149. begin
  2150. consume(_POINTPOINT);
  2151. p2:=sub_expr(opcompare,true);
  2152. p1:=crangenode.create(p1,p2);
  2153. end;
  2154. _ASSIGNMENT :
  2155. begin
  2156. consume(_ASSIGNMENT);
  2157. if (p1.resulttype.def.deftype=procvardef) then
  2158. getprocvardef:=tprocvardef(p1.resulttype.def);
  2159. p2:=sub_expr(opcompare,true);
  2160. if assigned(getprocvardef) then
  2161. handle_procvar(getprocvardef,p2);
  2162. getprocvardef:=nil;
  2163. p1:=cassignmentnode.create(p1,p2);
  2164. end;
  2165. _PLUSASN :
  2166. begin
  2167. consume(_PLUSASN);
  2168. p2:=sub_expr(opcompare,true);
  2169. p1:=cassignmentnode.create(p1,caddnode.create(addn,p1.getcopy,p2));
  2170. end;
  2171. _MINUSASN :
  2172. begin
  2173. consume(_MINUSASN);
  2174. p2:=sub_expr(opcompare,true);
  2175. p1:=cassignmentnode.create(p1,caddnode.create(subn,p1.getcopy,p2));
  2176. end;
  2177. _STARASN :
  2178. begin
  2179. consume(_STARASN );
  2180. p2:=sub_expr(opcompare,true);
  2181. p1:=cassignmentnode.create(p1,caddnode.create(muln,p1.getcopy,p2));
  2182. end;
  2183. _SLASHASN :
  2184. begin
  2185. consume(_SLASHASN );
  2186. p2:=sub_expr(opcompare,true);
  2187. p1:=cassignmentnode.create(p1,caddnode.create(slashn,p1.getcopy,p2));
  2188. end;
  2189. end;
  2190. { get the resulttype for this expression }
  2191. if not assigned(p1.resulttype.def) then
  2192. do_resulttypepass(p1);
  2193. afterassignment:=oldafterassignment;
  2194. if p1<>oldp1 then
  2195. p1.set_tree_filepos(filepos);
  2196. expr:=p1;
  2197. end;
  2198. {$ifdef int64funcresok}
  2199. function get_intconst:TConstExprInt;
  2200. {$else int64funcresok}
  2201. function get_intconst:longint;
  2202. {$endif int64funcresok}
  2203. {Reads an expression, tries to evalute it and check if it is an integer
  2204. constant. Then the constant is returned.}
  2205. var
  2206. p:tnode;
  2207. begin
  2208. p:=comp_expr(true);
  2209. if not codegenerror then
  2210. begin
  2211. if (p.nodetype<>ordconstn) or
  2212. not(is_integer(p.resulttype.def)) then
  2213. Message(cg_e_illegal_expression)
  2214. else
  2215. get_intconst:=tordconstnode(p).value;
  2216. end;
  2217. p.free;
  2218. end;
  2219. function get_stringconst:string;
  2220. {Reads an expression, tries to evaluate it and checks if it is a string
  2221. constant. Then the constant is returned.}
  2222. var
  2223. p:tnode;
  2224. begin
  2225. get_stringconst:='';
  2226. p:=comp_expr(true);
  2227. if p.nodetype<>stringconstn then
  2228. begin
  2229. if (p.nodetype=ordconstn) and is_char(p.resulttype.def) then
  2230. get_stringconst:=char(tordconstnode(p).value)
  2231. else
  2232. Message(cg_e_illegal_expression);
  2233. end
  2234. else
  2235. get_stringconst:=strpas(tstringconstnode(p).value_str);
  2236. p.free;
  2237. end;
  2238. end.
  2239. {
  2240. $Log$
  2241. Revision 1.152 2004-03-29 14:42:52 peter
  2242. * variant array support
  2243. Revision 1.151 2004/03/23 22:34:49 peter
  2244. * constants ordinals now always have a type assigned
  2245. * integer constants have the smallest type, unsigned prefered over
  2246. signed
  2247. Revision 1.150 2004/02/20 21:55:59 peter
  2248. * procvar cleanup
  2249. Revision 1.149 2004/02/18 21:58:53 peter
  2250. * constants are now parsed as 64bit for cpu64bit
  2251. Revision 1.148 2004/02/17 23:36:40 daniel
  2252. * Make better use of try_to_consume
  2253. Revision 1.147 2004/02/17 15:57:49 peter
  2254. - fix rtti generation for properties containing sl_vec
  2255. - fix crash when overloaded operator is not available
  2256. - fix record alignment for C style variant records
  2257. Revision 1.146 2004/02/03 22:32:54 peter
  2258. * renamed xNNbittype to xNNinttype
  2259. * renamed registers32 to registersint
  2260. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2261. Revision 1.145 2003/12/29 17:19:35 jonas
  2262. * integrated hack from 1.0.x so we can parse low(int64) as int64 instead
  2263. of as double (in 1.0.x, it was necessary for low(longint))
  2264. Revision 1.144 2003/12/08 22:35:28 peter
  2265. * again procvar fixes
  2266. Revision 1.143 2003/11/29 16:19:54 peter
  2267. * Initialize() added
  2268. Revision 1.142 2003/11/29 14:49:46 peter
  2269. * fix crash with exit() in a procedure
  2270. Revision 1.141 2003/11/29 14:33:13 peter
  2271. * typed address only used for @ and addr() that are parsed
  2272. Revision 1.140 2003/11/10 19:11:39 peter
  2273. * check paralength instead of assigned(left)
  2274. Revision 1.139 2003/11/07 15:58:32 florian
  2275. * Florian's culmutative nr. 1; contains:
  2276. - invalid calling conventions for a certain cpu are rejected
  2277. - arm softfloat calling conventions
  2278. - -Sp for cpu dependend code generation
  2279. - several arm fixes
  2280. - remaining code for value open array paras on heap
  2281. Revision 1.138 2003/11/06 15:54:32 peter
  2282. * fixed calling classmethod for other object from classmethod
  2283. Revision 1.137 2003/11/04 16:42:13 peter
  2284. * assigned(proc()) does not change the calln to loadn
  2285. Revision 1.136 2003/10/28 15:36:01 peter
  2286. * absolute to object field supported, fixes tb0458
  2287. Revision 1.135 2003/10/09 15:20:56 peter
  2288. * self is not a token anymore. It is handled special when found
  2289. in a code block and when parsing an method
  2290. Revision 1.134 2003/10/09 15:00:13 florian
  2291. * fixed constructor call in class methods
  2292. Revision 1.133 2003/10/08 19:19:45 peter
  2293. * set_varstate cleanup
  2294. Revision 1.132 2003/10/05 12:56:04 peter
  2295. * fix assigned(property)
  2296. Revision 1.131 2003/10/02 21:15:31 peter
  2297. * protected visibility fixes
  2298. Revision 1.130 2003/10/01 20:34:49 peter
  2299. * procinfo unit contains tprocinfo
  2300. * cginfo renamed to cgbase
  2301. * moved cgmessage to verbose
  2302. * fixed ppc and sparc compiles
  2303. Revision 1.129 2003/09/23 17:56:05 peter
  2304. * locals and paras are allocated in the code generation
  2305. * tvarsym.localloc contains the location of para/local when
  2306. generating code for the current procedure
  2307. Revision 1.128 2003/09/06 22:27:09 florian
  2308. * fixed web bug 2669
  2309. * cosmetic fix in printnode
  2310. * tobjectdef.gettypename implemented
  2311. Revision 1.127 2003/09/05 17:41:12 florian
  2312. * merged Wiktor's Watcom patches in 1.1
  2313. Revision 1.126 2003/08/23 22:29:51 peter
  2314. * fixed static class check for properties
  2315. Revision 1.125 2003/08/23 18:41:52 peter
  2316. * allow typeof(self) in class methods
  2317. Revision 1.124 2003/08/10 17:25:23 peter
  2318. * fixed some reported bugs
  2319. Revision 1.123 2003/06/13 21:19:31 peter
  2320. * current_procdef removed, use current_procinfo.procdef instead
  2321. Revision 1.122 2003/06/03 21:02:57 peter
  2322. * don't set nf_member when loaded from with symtable
  2323. * allow static variables in class methods
  2324. Revision 1.121 2003/05/22 17:43:21 peter
  2325. * search defaulthandler only for message methods
  2326. Revision 1.120 2003/05/15 18:58:53 peter
  2327. * removed selfpointer_offset, vmtpointer_offset
  2328. * tvarsym.adjusted_address
  2329. * address in localsymtable is now in the real direction
  2330. * removed some obsolete globals
  2331. Revision 1.119 2003/05/13 20:54:39 peter
  2332. * ifdef'd code that checked for failed inherited constructors
  2333. Revision 1.118 2003/05/13 19:14:41 peter
  2334. * failn removed
  2335. * inherited result code check moven to pexpr
  2336. Revision 1.117 2003/05/11 21:37:03 peter
  2337. * moved implicit exception frame from ncgutil to psub
  2338. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2339. Revision 1.116 2003/05/11 14:45:12 peter
  2340. * tloadnode does not support objectsymtable,withsymtable anymore
  2341. * withnode cleanup
  2342. * direct with rewritten to use temprefnode
  2343. Revision 1.115 2003/05/09 17:47:03 peter
  2344. * self moved to hidden parameter
  2345. * removed hdisposen,hnewn,selfn
  2346. Revision 1.114 2003/05/01 07:59:42 florian
  2347. * introduced defaultordconsttype to decribe the default size of ordinal constants
  2348. on 64 bit CPUs it's equal to cs64bitdef while on 32 bit CPUs it's equal to s32bitdef
  2349. + added defines CPU32 and CPU64 for 32 bit and 64 bit CPUs
  2350. * int64s/qwords are allowed as for loop counter on 64 bit CPUs
  2351. Revision 1.113 2003/04/27 11:21:33 peter
  2352. * aktprocdef renamed to current_procinfo.procdef
  2353. * procinfo renamed to current_procinfo
  2354. * procinfo will now be stored in current_module so it can be
  2355. cleaned up properly
  2356. * gen_main_procsym changed to create_main_proc and release_main_proc
  2357. to also generate a tprocinfo structure
  2358. * fixed unit implicit initfinal
  2359. Revision 1.112 2003/04/27 07:29:50 peter
  2360. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2361. a new procdef declaration
  2362. * aktprocsym removed
  2363. * lexlevel removed, use symtable.symtablelevel instead
  2364. * implicit init/final code uses the normal genentry/genexit
  2365. * funcret state checking updated for new funcret handling
  2366. Revision 1.111 2003/04/26 00:33:07 peter
  2367. * vo_is_result flag added for the special RESULT symbol
  2368. Revision 1.110 2003/04/25 20:59:33 peter
  2369. * removed funcretn,funcretsym, function result is now in varsym
  2370. and aliases for result and function name are added using absolutesym
  2371. * vs_hidden parameter for funcret passed in parameter
  2372. * vs_hidden fixes
  2373. * writenode changed to printnode and released from extdebug
  2374. * -vp option added to generate a tree.log with the nodetree
  2375. * nicer printnode for statements, callnode
  2376. Revision 1.109 2003/04/23 10:13:55 peter
  2377. * firstaddr will check procvardef
  2378. Revision 1.108 2003/04/22 23:50:23 peter
  2379. * firstpass uses expectloc
  2380. * checks if there are differences between the expectloc and
  2381. location.loc from secondpass in EXTDEBUG
  2382. Revision 1.107 2003/04/11 15:49:01 peter
  2383. * default property also increased the reference count for the
  2384. property symbol
  2385. Revision 1.106 2003/04/11 14:50:08 peter
  2386. * fix tw2454
  2387. Revision 1.105 2003/03/27 17:44:13 peter
  2388. * fixed small mem leaks
  2389. Revision 1.104 2003/03/17 18:55:30 peter
  2390. * allow more tokens instead of only semicolon after inherited
  2391. Revision 1.103 2003/03/17 16:54:41 peter
  2392. * support DefaultHandler and anonymous inheritance fixed
  2393. for message methods
  2394. Revision 1.102 2003/01/30 21:46:57 peter
  2395. * self fixes for static methods (merged)
  2396. Revision 1.101 2003/01/16 22:12:22 peter
  2397. * Find the correct procvar to load when using @ in fpc mode
  2398. Revision 1.100 2003/01/15 01:44:32 peter
  2399. * merged methodpointer fixes from 1.0.x
  2400. Revision 1.98 2003/01/12 17:51:42 peter
  2401. * tp procvar handling fix for tb0448
  2402. Revision 1.97 2003/01/05 22:44:14 peter
  2403. * remove a lot of code to support typen in loadn-procsym
  2404. Revision 1.96 2002/12/11 22:40:36 peter
  2405. * assigned(procvar) fix for delphi mode, fixes tb0430
  2406. Revision 1.95 2002/11/30 11:12:48 carl
  2407. + checking for symbols used with hint directives is done mostly in pexpr
  2408. only now
  2409. Revision 1.94 2002/11/27 15:33:47 peter
  2410. * the never ending story of tp procvar hacks
  2411. Revision 1.93 2002/11/26 22:58:24 peter
  2412. * fix for tw2178. When a ^ or . follows a procsym then the procsym
  2413. needs to be called
  2414. Revision 1.92 2002/11/25 17:43:22 peter
  2415. * splitted defbase in defutil,symutil,defcmp
  2416. * merged isconvertable and is_equal into compare_defs(_ext)
  2417. * made operator search faster by walking the list only once
  2418. Revision 1.91 2002/11/22 22:48:10 carl
  2419. * memory optimization with tconstsym (1.5%)
  2420. Revision 1.90 2002/11/20 22:49:55 pierre
  2421. * commented check code tht was invalid in 1.1
  2422. Revision 1.89 2002/11/18 18:34:41 peter
  2423. * fix crash with EXTDEBUG code
  2424. Revision 1.88 2002/11/18 17:48:21 peter
  2425. * fix tw2209 (merged)
  2426. Revision 1.87 2002/11/18 17:31:58 peter
  2427. * pass proccalloption to ret_in_xxx and push_xxx functions
  2428. Revision 1.86 2002/10/05 00:48:57 peter
  2429. * support inherited; support for overload as it is handled by
  2430. delphi. This is only for delphi mode as it is working is
  2431. undocumented and hard to predict what is done
  2432. Revision 1.85 2002/10/04 21:13:59 peter
  2433. * ignore vecn,subscriptn when checking for a procvar loadn
  2434. Revision 1.84 2002/10/02 20:51:22 peter
  2435. * don't check interfaces for class methods
  2436. Revision 1.83 2002/10/02 18:20:52 peter
  2437. * Copy() is now internal syssym that calls compilerprocs
  2438. Revision 1.82 2002/09/30 07:00:48 florian
  2439. * fixes to common code to get the alpha compiler compiled applied
  2440. Revision 1.81 2002/09/16 19:06:14 peter
  2441. * allow ^ after nil
  2442. Revision 1.80 2002/09/07 15:25:07 peter
  2443. * old logs removed and tabs fixed
  2444. Revision 1.79 2002/09/07 12:16:03 carl
  2445. * second part bug report 1996 fix, testrange in cordconstnode
  2446. only called if option is set (also make parsing a tiny faster)
  2447. Revision 1.78 2002/09/03 16:26:27 daniel
  2448. * Make Tprocdef.defs protected
  2449. Revision 1.77 2002/08/18 20:06:24 peter
  2450. * inlining is now also allowed in interface
  2451. * renamed write/load to ppuwrite/ppuload
  2452. * tnode storing in ppu
  2453. * nld,ncon,nbas are already updated for storing in ppu
  2454. Revision 1.76 2002/08/17 09:23:39 florian
  2455. * first part of procinfo rewrite
  2456. Revision 1.75 2002/08/01 16:37:47 jonas
  2457. - removed some superfluous "in_paras := true" statements
  2458. Revision 1.74 2002/07/26 21:15:41 florian
  2459. * rewrote the system handling
  2460. Revision 1.73 2002/07/23 09:51:23 daniel
  2461. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2462. are worth comitting.
  2463. Revision 1.72 2002/07/20 11:57:55 florian
  2464. * types.pas renamed to defbase.pas because D6 contains a types
  2465. unit so this would conflicts if D6 programms are compiled
  2466. + Willamette/SSE2 instructions to assembler added
  2467. Revision 1.71 2002/07/16 15:34:20 florian
  2468. * exit is now a syssym instead of a keyword
  2469. Revision 1.70 2002/07/06 20:18:02 carl
  2470. * longstring declaration now gives parser error since its not supported!
  2471. Revision 1.69 2002/06/12 15:46:14 jonas
  2472. * fixed web bug 1995
  2473. Revision 1.68 2002/05/18 13:34:12 peter
  2474. * readded missing revisions
  2475. Revision 1.67 2002/05/16 19:46:43 carl
  2476. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2477. + try to fix temp allocation (still in ifdef)
  2478. + generic constructor calls
  2479. + start of tassembler / tmodulebase class cleanup
  2480. Revision 1.65 2002/05/12 16:53:09 peter
  2481. * moved entry and exitcode to ncgutil and cgobj
  2482. * foreach gets extra argument for passing local data to the
  2483. iterator function
  2484. * -CR checks also class typecasts at runtime by changing them
  2485. into as
  2486. * fixed compiler to cycle with the -CR option
  2487. * fixed stabs with elf writer, finally the global variables can
  2488. be watched
  2489. * removed a lot of routines from cga unit and replaced them by
  2490. calls to cgobj
  2491. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2492. u32bit then the other is typecasted also to u32bit without giving
  2493. a rangecheck warning/error.
  2494. * fixed pascal calling method with reversing also the high tree in
  2495. the parast, detected by tcalcst3 test
  2496. Revision 1.64 2002/04/23 19:16:34 peter
  2497. * add pinline unit that inserts compiler supported functions using
  2498. one or more statements
  2499. * moved finalize and setlength from ninl to pinline
  2500. Revision 1.63 2002/04/21 19:02:05 peter
  2501. * removed newn and disposen nodes, the code is now directly
  2502. inlined from pexpr
  2503. * -an option that will write the secondpass nodes to the .s file, this
  2504. requires EXTDEBUG define to actually write the info
  2505. * fixed various internal errors and crashes due recent code changes
  2506. Revision 1.62 2002/04/16 16:11:17 peter
  2507. * using inherited; without a parent having the same function
  2508. will do nothing like delphi
  2509. Revision 1.61 2002/04/07 13:31:36 carl
  2510. + change unit use
  2511. Revision 1.60 2002/04/01 20:57:13 jonas
  2512. * fixed web bug 1907
  2513. * fixed some other procvar related bugs (all related to accepting procvar
  2514. constructs with either too many or too little parameters)
  2515. (both merged, includes second typo fix of pexpr.pas)
  2516. Revision 1.59 2002/03/31 20:26:35 jonas
  2517. + a_loadfpu_* and a_loadmm_* methods in tcg
  2518. * register allocation is now handled by a class and is mostly processor
  2519. independent (+rgobj.pas and i386/rgcpu.pas)
  2520. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  2521. * some small improvements and fixes to the optimizer
  2522. * some register allocation fixes
  2523. * some fpuvaroffset fixes in the unary minus node
  2524. * push/popusedregisters is now called rg.save/restoreusedregisters and
  2525. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  2526. also better optimizable)
  2527. * fixed and optimized register saving/restoring for new/dispose nodes
  2528. * LOC_FPU locations now also require their "register" field to be set to
  2529. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  2530. - list field removed of the tnode class because it's not used currently
  2531. and can cause hard-to-find bugs
  2532. }