pexpr.pas 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does parsing of expression for Free Pascal
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pexpr;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symtype,symdef,symbase,
  22. node,ncal,
  23. tokens,globtype,globals,constexp;
  24. { reads a whole expression }
  25. function expr(dotypecheck:boolean) : tnode;
  26. { reads an expression without assignements and .. }
  27. function comp_expr(accept_equal,typeonly:boolean):tnode;
  28. { reads a single factor }
  29. function factor(getaddr,typeonly:boolean) : tnode;
  30. procedure string_dec(var def: tdef; allowtypedef: boolean);
  31. function parse_paras(__colon,__namedpara : boolean;end_of_paras : ttoken) : tnode;
  32. { the ID token has to be consumed before calling this function }
  33. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags);
  34. function get_intconst:TConstExprInt;
  35. function get_stringconst:string;
  36. { Does some postprocessing for a generic type (especially when nested types
  37. of the specialization are used) }
  38. procedure post_comp_expr_gendef(var def: tdef);
  39. implementation
  40. uses
  41. { common }
  42. cutils,
  43. { global }
  44. verbose,
  45. systems,widestr,
  46. { symtable }
  47. symconst,symtable,symsym,defutil,defcmp,
  48. { module }
  49. fmodule,ppu,
  50. { pass 1 }
  51. pass_1,htypechk,
  52. nmat,nadd,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  53. { parser }
  54. scanner,
  55. pbase,pinline,ptype,pgenutil,
  56. { codegen }
  57. cgbase,procinfo,cpuinfo
  58. ;
  59. { sub_expr(opmultiply) is need to get -1 ** 4 to be
  60. read as - (1**4) and not (-1)**4 PM }
  61. type
  62. Toperator_precedence=(opcompare,opaddition,opmultiply,oppower);
  63. const
  64. highest_precedence = oppower;
  65. function sub_expr(pred_level:Toperator_precedence;accept_equal,typeonly:boolean;factornode:tnode):tnode;forward;
  66. const
  67. { true, if the inherited call is anonymous }
  68. anon_inherited : boolean = false;
  69. { last def found, only used by anon. inherited calls to insert proper type casts }
  70. srdef : tdef = nil;
  71. procedure string_dec(var def:tdef; allowtypedef: boolean);
  72. { reads a string type with optional length }
  73. { and returns a pointer to the string }
  74. { definition }
  75. var
  76. p : tnode;
  77. begin
  78. def:=cshortstringtype;
  79. consume(_STRING);
  80. if token=_LECKKLAMMER then
  81. begin
  82. if not(allowtypedef) then
  83. Message(parser_e_no_local_para_def);
  84. consume(_LECKKLAMMER);
  85. p:=comp_expr(true,false);
  86. if not is_constintnode(p) then
  87. begin
  88. Message(parser_e_illegal_expression);
  89. { error recovery }
  90. consume(_RECKKLAMMER);
  91. end
  92. else
  93. begin
  94. if (tordconstnode(p).value<=0) then
  95. begin
  96. Message(parser_e_invalid_string_size);
  97. tordconstnode(p).value:=255;
  98. end;
  99. if tordconstnode(p).value>255 then
  100. begin
  101. { longstring is currently unsupported (CEC)! }
  102. { t:=tstringdef.createlong(tordconstnode(p).value))}
  103. Message(parser_e_invalid_string_size);
  104. tordconstnode(p).value:=255;
  105. def:=tstringdef.createshort(int64(tordconstnode(p).value));
  106. end
  107. else
  108. if tordconstnode(p).value<>255 then
  109. def:=tstringdef.createshort(int64(tordconstnode(p).value));
  110. consume(_RECKKLAMMER);
  111. end;
  112. p.free;
  113. end
  114. else
  115. begin
  116. if cs_ansistrings in current_settings.localswitches then
  117. def:=getansistringdef
  118. else
  119. def:=cshortstringtype;
  120. end;
  121. end;
  122. function parse_paras(__colon,__namedpara : boolean;end_of_paras : ttoken) : tnode;
  123. var
  124. p1,p2,argname : tnode;
  125. prev_in_args,
  126. old_named_args_allowed,
  127. old_allow_array_constructor : boolean;
  128. begin
  129. if token=end_of_paras then
  130. begin
  131. parse_paras:=nil;
  132. exit;
  133. end;
  134. { save old values }
  135. prev_in_args:=in_args;
  136. old_allow_array_constructor:=allow_array_constructor;
  137. old_named_args_allowed:=named_args_allowed;
  138. { set para parsing values }
  139. in_args:=true;
  140. named_args_allowed:=false;
  141. allow_array_constructor:=true;
  142. p2:=nil;
  143. repeat
  144. if __namedpara then
  145. begin
  146. if token=_COMMA then
  147. begin
  148. { empty parameter }
  149. p2:=ccallparanode.create(cnothingnode.create,p2);
  150. end
  151. else
  152. begin
  153. named_args_allowed:=true;
  154. p1:=comp_expr(true,false);
  155. named_args_allowed:=false;
  156. if found_arg_name then
  157. begin
  158. argname:=p1;
  159. p1:=comp_expr(true,false);
  160. p2:=ccallparanode.create(p1,p2);
  161. tcallparanode(p2).parametername:=argname;
  162. end
  163. else
  164. p2:=ccallparanode.create(p1,p2);
  165. found_arg_name:=false;
  166. end;
  167. end
  168. else
  169. begin
  170. p1:=comp_expr(true,false);
  171. p2:=ccallparanode.create(p1,p2);
  172. end;
  173. { it's for the str(l:5,s); }
  174. if __colon and (token=_COLON) then
  175. begin
  176. consume(_COLON);
  177. p1:=comp_expr(true,false);
  178. p2:=ccallparanode.create(p1,p2);
  179. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  180. if try_to_consume(_COLON) then
  181. begin
  182. p1:=comp_expr(true,false);
  183. p2:=ccallparanode.create(p1,p2);
  184. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  185. end
  186. end;
  187. until not try_to_consume(_COMMA);
  188. allow_array_constructor:=old_allow_array_constructor;
  189. in_args:=prev_in_args;
  190. named_args_allowed:=old_named_args_allowed;
  191. parse_paras:=p2;
  192. end;
  193. function gen_c_style_operator(ntyp:tnodetype;p1,p2:tnode) : tnode;
  194. var
  195. hp : tnode;
  196. hdef : tdef;
  197. temp : ttempcreatenode;
  198. newstatement : tstatementnode;
  199. begin
  200. { Properties are not allowed, because the write can
  201. be different from the read }
  202. if (nf_isproperty in p1.flags) then
  203. begin
  204. Message(type_e_variable_id_expected);
  205. { We can continue with the loading,
  206. it'll not create errors. Only the expected
  207. result can be wrong }
  208. end;
  209. hp:=p1;
  210. while assigned(hp) and
  211. (hp.nodetype in [derefn,subscriptn,vecn,typeconvn]) do
  212. hp:=tunarynode(hp).left;
  213. if not assigned(hp) then
  214. internalerror(200410121);
  215. if (hp.nodetype=calln) then
  216. begin
  217. typecheckpass(p1);
  218. result:=internalstatements(newstatement);
  219. hdef:=tpointerdef.create(p1.resultdef);
  220. temp:=ctempcreatenode.create(hdef,sizeof(pint),tt_persistent,false);
  221. addstatement(newstatement,temp);
  222. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),caddrnode.create_internal(p1)));
  223. addstatement(newstatement,cassignmentnode.create(
  224. cderefnode.create(ctemprefnode.create(temp)),
  225. caddnode.create(ntyp,
  226. cderefnode.create(ctemprefnode.create(temp)),
  227. p2)));
  228. addstatement(newstatement,ctempdeletenode.create(temp));
  229. end
  230. else
  231. result:=cassignmentnode.create(p1,caddnode.create(ntyp,p1.getcopy,p2));
  232. end;
  233. function statement_syssym(l : byte) : tnode;
  234. var
  235. p1,p2,paras : tnode;
  236. err,
  237. prev_in_args : boolean;
  238. begin
  239. prev_in_args:=in_args;
  240. case l of
  241. in_new_x :
  242. begin
  243. if afterassignment or in_args then
  244. statement_syssym:=new_function
  245. else
  246. statement_syssym:=new_dispose_statement(true);
  247. end;
  248. in_dispose_x :
  249. begin
  250. statement_syssym:=new_dispose_statement(false);
  251. end;
  252. in_ord_x :
  253. begin
  254. consume(_LKLAMMER);
  255. in_args:=true;
  256. p1:=comp_expr(true,false);
  257. consume(_RKLAMMER);
  258. p1:=geninlinenode(in_ord_x,false,p1);
  259. statement_syssym := p1;
  260. end;
  261. in_exit :
  262. begin
  263. if try_to_consume(_LKLAMMER) then
  264. begin
  265. if not (m_mac in current_settings.modeswitches) then
  266. begin
  267. if not(try_to_consume(_RKLAMMER)) then
  268. begin
  269. p1:=comp_expr(true,false);
  270. consume(_RKLAMMER);
  271. if (not assigned(current_procinfo) or
  272. is_void(current_procinfo.procdef.returndef)) then
  273. begin
  274. Message(parser_e_void_function);
  275. { recovery }
  276. p1.free;
  277. p1:=nil;
  278. end;
  279. end
  280. else
  281. p1:=nil;
  282. end
  283. else
  284. begin
  285. if not (current_procinfo.procdef.procsym.name = pattern) then
  286. Message(parser_e_macpas_exit_wrong_param);
  287. consume(_ID);
  288. consume(_RKLAMMER);
  289. p1:=nil;
  290. end
  291. end
  292. else
  293. p1:=nil;
  294. statement_syssym:=cexitnode.create(p1);
  295. end;
  296. in_break :
  297. begin
  298. statement_syssym:=cbreaknode.create
  299. end;
  300. in_continue :
  301. begin
  302. statement_syssym:=ccontinuenode.create
  303. end;
  304. in_leave :
  305. begin
  306. if m_mac in current_settings.modeswitches then
  307. statement_syssym:=cbreaknode.create
  308. else
  309. begin
  310. Message1(sym_e_id_not_found, orgpattern);
  311. statement_syssym:=cerrornode.create;
  312. end;
  313. end;
  314. in_cycle :
  315. begin
  316. if m_mac in current_settings.modeswitches then
  317. statement_syssym:=ccontinuenode.create
  318. else
  319. begin
  320. Message1(sym_e_id_not_found, orgpattern);
  321. statement_syssym:=cerrornode.create;
  322. end;
  323. end;
  324. in_typeof_x :
  325. begin
  326. consume(_LKLAMMER);
  327. in_args:=true;
  328. p1:=comp_expr(true,false);
  329. consume(_RKLAMMER);
  330. if p1.nodetype=typen then
  331. ttypenode(p1).allowed:=true;
  332. { Allow classrefdef, which is required for
  333. Typeof(self) in static class methods }
  334. if not(is_objc_class_or_protocol(p1.resultdef)) and
  335. ((p1.resultdef.typ = objectdef) or
  336. (assigned(current_procinfo) and
  337. ((po_classmethod in current_procinfo.procdef.procoptions) or
  338. (po_staticmethod in current_procinfo.procdef.procoptions)) and
  339. (p1.resultdef.typ=classrefdef))) then
  340. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  341. else
  342. begin
  343. Message(parser_e_class_id_expected);
  344. p1.destroy;
  345. statement_syssym:=cerrornode.create;
  346. end;
  347. end;
  348. in_sizeof_x,
  349. in_bitsizeof_x :
  350. begin
  351. consume(_LKLAMMER);
  352. in_args:=true;
  353. p1:=comp_expr(true,false);
  354. consume(_RKLAMMER);
  355. if ((p1.nodetype<>typen) and
  356. (
  357. (is_object(p1.resultdef) and
  358. (oo_has_constructor in tobjectdef(p1.resultdef).objectoptions)) or
  359. is_open_array(p1.resultdef) or
  360. is_array_of_const(p1.resultdef) or
  361. is_open_string(p1.resultdef)
  362. )) or
  363. { keep the function call if it is a type parameter to avoid arithmetic errors due to constant folding }
  364. (p1.resultdef.typ=undefineddef) then
  365. begin
  366. statement_syssym:=geninlinenode(in_sizeof_x,false,p1);
  367. { no packed bit support for these things }
  368. if (l = in_bitsizeof_x) then
  369. statement_syssym:=caddnode.create(muln,statement_syssym,cordconstnode.create(8,sinttype,true));
  370. end
  371. else
  372. begin
  373. { allow helpers for SizeOf and BitSizeOf }
  374. if p1.nodetype=typen then
  375. ttypenode(p1).helperallowed:=true;
  376. if (p1.resultdef.typ=forwarddef) then
  377. Message1(type_e_type_is_not_completly_defined,tforwarddef(p1.resultdef).tosymname^);
  378. if (l = in_sizeof_x) or
  379. (not((p1.nodetype = vecn) and
  380. is_packed_array(tvecnode(p1).left.resultdef)) and
  381. not((p1.nodetype = subscriptn) and
  382. is_packed_record_or_object(tsubscriptnode(p1).left.resultdef))) then
  383. begin
  384. statement_syssym:=cordconstnode.create(p1.resultdef.size,sinttype,true);
  385. if (l = in_bitsizeof_x) then
  386. statement_syssym:=caddnode.create(muln,statement_syssym,cordconstnode.create(8,sinttype,true));
  387. end
  388. else
  389. statement_syssym:=cordconstnode.create(p1.resultdef.packedbitsize,sinttype,true);
  390. { p1 not needed !}
  391. p1.destroy;
  392. end;
  393. end;
  394. in_typeinfo_x,
  395. in_objc_encode_x :
  396. begin
  397. if (l=in_typeinfo_x) or
  398. (m_objectivec1 in current_settings.modeswitches) then
  399. begin
  400. consume(_LKLAMMER);
  401. in_args:=true;
  402. p1:=comp_expr(true,false);
  403. { When reading a class type it is parsed as loadvmtaddrn,
  404. typeinfo only needs the type so we remove the loadvmtaddrn }
  405. if p1.nodetype=loadvmtaddrn then
  406. begin
  407. p2:=tloadvmtaddrnode(p1).left;
  408. tloadvmtaddrnode(p1).left:=nil;
  409. p1.free;
  410. p1:=p2;
  411. end;
  412. if p1.nodetype=typen then
  413. begin
  414. ttypenode(p1).allowed:=true;
  415. { allow helpers for TypeInfo }
  416. if l=in_typeinfo_x then
  417. ttypenode(p1).helperallowed:=true;
  418. end;
  419. { else
  420. begin
  421. p1.destroy;
  422. p1:=cerrornode.create;
  423. Message(parser_e_illegal_parameter_list);
  424. end;}
  425. consume(_RKLAMMER);
  426. p2:=geninlinenode(l,false,p1);
  427. statement_syssym:=p2;
  428. end
  429. else
  430. begin
  431. Message1(sym_e_id_not_found, orgpattern);
  432. statement_syssym:=cerrornode.create;
  433. end;
  434. end;
  435. in_unaligned_x :
  436. begin
  437. err:=false;
  438. consume(_LKLAMMER);
  439. in_args:=true;
  440. p1:=comp_expr(true,false);
  441. p2:=ccallparanode.create(p1,nil);
  442. p2:=geninlinenode(in_unaligned_x,false,p2);
  443. consume(_RKLAMMER);
  444. statement_syssym:=p2;
  445. end;
  446. in_assigned_x :
  447. begin
  448. err:=false;
  449. consume(_LKLAMMER);
  450. in_args:=true;
  451. p1:=comp_expr(true,false);
  452. { When reading a class type it is parsed as loadvmtaddrn,
  453. typeinfo only needs the type so we remove the loadvmtaddrn }
  454. if p1.nodetype=loadvmtaddrn then
  455. begin
  456. p2:=tloadvmtaddrnode(p1).left;
  457. tloadvmtaddrnode(p1).left:=nil;
  458. p1.free;
  459. p1:=p2;
  460. end;
  461. if not codegenerror then
  462. begin
  463. case p1.resultdef.typ of
  464. procdef, { procvar }
  465. pointerdef,
  466. procvardef,
  467. classrefdef : ;
  468. objectdef :
  469. if not is_implicit_pointer_object_type(p1.resultdef) then
  470. begin
  471. Message(parser_e_illegal_parameter_list);
  472. err:=true;
  473. end;
  474. arraydef :
  475. if not is_dynamic_array(p1.resultdef) then
  476. begin
  477. Message(parser_e_illegal_parameter_list);
  478. err:=true;
  479. end;
  480. else
  481. if p1.resultdef.typ<>undefineddef then
  482. begin
  483. Message(parser_e_illegal_parameter_list);
  484. err:=true;
  485. end;
  486. end;
  487. end
  488. else
  489. err:=true;
  490. if not err then
  491. begin
  492. p2:=ccallparanode.create(p1,nil);
  493. p2:=geninlinenode(in_assigned_x,false,p2);
  494. end
  495. else
  496. begin
  497. p1.free;
  498. p2:=cerrornode.create;
  499. end;
  500. consume(_RKLAMMER);
  501. statement_syssym:=p2;
  502. end;
  503. in_addr_x :
  504. begin
  505. consume(_LKLAMMER);
  506. in_args:=true;
  507. p1:=comp_expr(true,false);
  508. p1:=caddrnode.create(p1);
  509. consume(_RKLAMMER);
  510. statement_syssym:=p1;
  511. end;
  512. in_ofs_x :
  513. begin
  514. consume(_LKLAMMER);
  515. in_args:=true;
  516. p1:=comp_expr(true,false);
  517. p1:=caddrnode.create(p1);
  518. do_typecheckpass(p1);
  519. { Ofs() returns a cardinal/qword, not a pointer }
  520. p1.resultdef:=uinttype;
  521. consume(_RKLAMMER);
  522. statement_syssym:=p1;
  523. end;
  524. in_seg_x :
  525. begin
  526. consume(_LKLAMMER);
  527. in_args:=true;
  528. p1:=comp_expr(true,false);
  529. p1:=geninlinenode(in_seg_x,false,p1);
  530. consume(_RKLAMMER);
  531. statement_syssym:=p1;
  532. end;
  533. in_high_x,
  534. in_low_x :
  535. begin
  536. consume(_LKLAMMER);
  537. in_args:=true;
  538. p1:=comp_expr(true,false);
  539. p2:=geninlinenode(l,false,p1);
  540. consume(_RKLAMMER);
  541. statement_syssym:=p2;
  542. end;
  543. in_succ_x,
  544. in_pred_x :
  545. begin
  546. consume(_LKLAMMER);
  547. in_args:=true;
  548. p1:=comp_expr(true,false);
  549. p2:=geninlinenode(l,false,p1);
  550. consume(_RKLAMMER);
  551. statement_syssym:=p2;
  552. end;
  553. in_inc_x,
  554. in_dec_x :
  555. begin
  556. consume(_LKLAMMER);
  557. in_args:=true;
  558. p1:=comp_expr(true,false);
  559. if try_to_consume(_COMMA) then
  560. p2:=ccallparanode.create(comp_expr(true,false),nil)
  561. else
  562. p2:=nil;
  563. p2:=ccallparanode.create(p1,p2);
  564. statement_syssym:=geninlinenode(l,false,p2);
  565. consume(_RKLAMMER);
  566. end;
  567. in_slice_x:
  568. begin
  569. if not(in_args) then
  570. begin
  571. message(parser_e_illegal_slice);
  572. consume(_LKLAMMER);
  573. in_args:=true;
  574. comp_expr(true,false).free;
  575. if try_to_consume(_COMMA) then
  576. comp_expr(true,false).free;
  577. statement_syssym:=cerrornode.create;
  578. consume(_RKLAMMER);
  579. end
  580. else
  581. begin
  582. consume(_LKLAMMER);
  583. in_args:=true;
  584. p1:=comp_expr(true,false);
  585. Consume(_COMMA);
  586. if not(codegenerror) then
  587. p2:=ccallparanode.create(comp_expr(true,false),nil)
  588. else
  589. p2:=cerrornode.create;
  590. p2:=ccallparanode.create(p1,p2);
  591. statement_syssym:=geninlinenode(l,false,p2);
  592. consume(_RKLAMMER);
  593. end;
  594. end;
  595. in_initialize_x:
  596. begin
  597. statement_syssym:=inline_initialize;
  598. end;
  599. in_finalize_x:
  600. begin
  601. statement_syssym:=inline_finalize;
  602. end;
  603. in_copy_x:
  604. begin
  605. statement_syssym:=inline_copy;
  606. end;
  607. in_concat_x :
  608. begin
  609. consume(_LKLAMMER);
  610. in_args:=true;
  611. { Translate to x:=x+y[+z]. The addnode will do the
  612. type checking }
  613. p2:=nil;
  614. repeat
  615. p1:=comp_expr(true,false);
  616. if p2<>nil then
  617. p2:=caddnode.create(addn,p2,p1)
  618. else
  619. begin
  620. { Force string type if it isn't yet }
  621. if not(
  622. (p1.resultdef.typ=stringdef) or
  623. is_chararray(p1.resultdef) or
  624. is_char(p1.resultdef)
  625. ) then
  626. inserttypeconv(p1,cshortstringtype);
  627. p2:=p1;
  628. end;
  629. until not try_to_consume(_COMMA);
  630. consume(_RKLAMMER);
  631. statement_syssym:=p2;
  632. end;
  633. in_read_x,
  634. in_readln_x,
  635. in_readstr_x:
  636. begin
  637. if try_to_consume(_LKLAMMER) then
  638. begin
  639. paras:=parse_paras(false,false,_RKLAMMER);
  640. consume(_RKLAMMER);
  641. end
  642. else
  643. paras:=nil;
  644. p1:=geninlinenode(l,false,paras);
  645. statement_syssym := p1;
  646. end;
  647. in_setlength_x:
  648. begin
  649. statement_syssym := inline_setlength;
  650. end;
  651. in_objc_selector_x:
  652. begin
  653. if (m_objectivec1 in current_settings.modeswitches) then
  654. begin
  655. consume(_LKLAMMER);
  656. in_args:=true;
  657. { don't turn procsyms into calls (getaddr = true) }
  658. p1:=factor(true,false);
  659. p2:=geninlinenode(l,false,p1);
  660. consume(_RKLAMMER);
  661. statement_syssym:=p2;
  662. end
  663. else
  664. begin
  665. Message1(sym_e_id_not_found, orgpattern);
  666. statement_syssym:=cerrornode.create;
  667. end;
  668. end;
  669. in_length_x:
  670. begin
  671. consume(_LKLAMMER);
  672. in_args:=true;
  673. p1:=comp_expr(true,false);
  674. p2:=geninlinenode(l,false,p1);
  675. consume(_RKLAMMER);
  676. statement_syssym:=p2;
  677. end;
  678. in_write_x,
  679. in_writeln_x,
  680. in_writestr_x :
  681. begin
  682. if try_to_consume(_LKLAMMER) then
  683. begin
  684. paras:=parse_paras(true,false,_RKLAMMER);
  685. consume(_RKLAMMER);
  686. end
  687. else
  688. paras:=nil;
  689. p1 := geninlinenode(l,false,paras);
  690. statement_syssym := p1;
  691. end;
  692. in_str_x_string :
  693. begin
  694. consume(_LKLAMMER);
  695. paras:=parse_paras(true,false,_RKLAMMER);
  696. consume(_RKLAMMER);
  697. p1 := geninlinenode(l,false,paras);
  698. statement_syssym := p1;
  699. end;
  700. in_val_x:
  701. Begin
  702. consume(_LKLAMMER);
  703. in_args := true;
  704. p1:= ccallparanode.create(comp_expr(true,false), nil);
  705. consume(_COMMA);
  706. p2 := ccallparanode.create(comp_expr(true,false),p1);
  707. if try_to_consume(_COMMA) then
  708. p2 := ccallparanode.create(comp_expr(true,false),p2);
  709. consume(_RKLAMMER);
  710. p2 := geninlinenode(l,false,p2);
  711. statement_syssym := p2;
  712. End;
  713. in_include_x_y,
  714. in_exclude_x_y :
  715. begin
  716. consume(_LKLAMMER);
  717. in_args:=true;
  718. p1:=comp_expr(true,false);
  719. consume(_COMMA);
  720. p2:=comp_expr(true,false);
  721. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  722. consume(_RKLAMMER);
  723. end;
  724. in_pack_x_y_z,
  725. in_unpack_x_y_z :
  726. begin
  727. consume(_LKLAMMER);
  728. in_args:=true;
  729. p1:=comp_expr(true,false);
  730. consume(_COMMA);
  731. p2:=comp_expr(true,false);
  732. consume(_COMMA);
  733. paras:=comp_expr(true,false);
  734. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,ccallparanode.create(paras,nil))));
  735. consume(_RKLAMMER);
  736. end;
  737. in_assert_x_y :
  738. begin
  739. consume(_LKLAMMER);
  740. in_args:=true;
  741. p1:=comp_expr(true,false);
  742. if try_to_consume(_COMMA) then
  743. p2:=comp_expr(true,false)
  744. else
  745. begin
  746. { then insert an empty string }
  747. p2:=cstringconstnode.createstr('');
  748. end;
  749. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  750. consume(_RKLAMMER);
  751. end;
  752. in_get_frame:
  753. begin
  754. statement_syssym:=geninlinenode(l,false,nil);
  755. end;
  756. (*
  757. in_get_caller_frame:
  758. begin
  759. if try_to_consume(_LKLAMMER) then
  760. begin
  761. {You used to call get_caller_frame as get_caller_frame(get_frame),
  762. however, as a stack frame may not exist, it does more harm than
  763. good, so ignore it.}
  764. in_args:=true;
  765. p1:=comp_expr(true,false);
  766. p1.destroy;
  767. consume(_RKLAMMER);
  768. end;
  769. statement_syssym:=geninlinenode(l,false,nil);
  770. end;
  771. *)
  772. else
  773. internalerror(15);
  774. end;
  775. in_args:=prev_in_args;
  776. end;
  777. function maybe_load_methodpointer(st:TSymtable;var p1:tnode):boolean;
  778. begin
  779. maybe_load_methodpointer:=false;
  780. if not assigned(p1) then
  781. begin
  782. case st.symtabletype of
  783. withsymtable :
  784. begin
  785. if (st.defowner.typ=objectdef) then
  786. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  787. end;
  788. ObjectSymtable,
  789. recordsymtable:
  790. begin
  791. { We are calling from the static class method which has no self node }
  792. if assigned(current_procinfo) and current_procinfo.procdef.no_self_node then
  793. p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef.struct))
  794. else
  795. p1:=load_self_node;
  796. { We are calling a member }
  797. maybe_load_methodpointer:=true;
  798. end;
  799. end;
  800. end;
  801. end;
  802. { reads the parameter for a subroutine call }
  803. procedure do_proc_call(sym:tsym;st:TSymtable;obj:tabstractrecorddef;getaddr:boolean;var again : boolean;var p1:tnode;callflags:tcallnodeflags);
  804. var
  805. membercall,
  806. prevafterassn : boolean;
  807. i : integer;
  808. para,p2 : tnode;
  809. currpara : tparavarsym;
  810. aprocdef : tprocdef;
  811. begin
  812. prevafterassn:=afterassignment;
  813. afterassignment:=false;
  814. membercall:=false;
  815. aprocdef:=nil;
  816. { when it is a call to a member we need to load the
  817. methodpointer first
  818. }
  819. membercall:=maybe_load_methodpointer(st,p1);
  820. { When we are expecting a procvar we also need
  821. to get the address in some cases }
  822. if assigned(getprocvardef) then
  823. begin
  824. if (block_type=bt_const) or
  825. getaddr then
  826. begin
  827. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  828. getaddr:=true;
  829. end
  830. else
  831. if ((m_tp_procvar in current_settings.modeswitches) or
  832. (m_mac_procvar in current_settings.modeswitches)) and
  833. not(token in [_CARET,_POINT,_LKLAMMER]) then
  834. begin
  835. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  836. if assigned(aprocdef) then
  837. getaddr:=true;
  838. end;
  839. end;
  840. { only need to get the address of the procedure? }
  841. if getaddr then
  842. begin
  843. { Retrieve info which procvar to call. For tp_procvar the
  844. aprocdef is already loaded above so we can reuse it }
  845. if not assigned(aprocdef) and
  846. assigned(getprocvardef) then
  847. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  848. { generate a methodcallnode or proccallnode }
  849. { we shouldn't convert things like @tcollection.load }
  850. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  851. if assigned(p1) then
  852. begin
  853. { for loading methodpointer of an inherited function
  854. we use self as instance and load the address of
  855. the function directly and not through the vmt (PFV) }
  856. if (cnf_inherited in callflags) then
  857. begin
  858. include(tloadnode(p2).loadnodeflags,loadnf_inherited);
  859. p1.free;
  860. p1:=load_self_node;
  861. end;
  862. if (p1.nodetype<>typen) then
  863. tloadnode(p2).set_mp(p1)
  864. else
  865. p1.free;
  866. end;
  867. p1:=p2;
  868. { no postfix operators }
  869. again:=false;
  870. end
  871. else
  872. begin
  873. para:=nil;
  874. if anon_inherited then
  875. begin
  876. if not assigned(current_procinfo) then
  877. internalerror(200305054);
  878. for i:=0 to current_procinfo.procdef.paras.count-1 do
  879. begin
  880. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  881. if not(vo_is_hidden_para in currpara.varoptions) then
  882. begin
  883. { inheritance by msgint? }
  884. if assigned(srdef) then
  885. { anonymous inherited via msgid calls only require a var parameter for
  886. both methods, so we need some type casting here }
  887. para:=ccallparanode.create(ctypeconvnode.create_internal(ctypeconvnode.create_internal(
  888. cloadnode.create(currpara,currpara.owner),cformaltype),tparavarsym(tprocdef(srdef).paras[i]).vardef),
  889. para)
  890. else
  891. para:=ccallparanode.create(cloadnode.create(currpara,currpara.owner),para);
  892. end;
  893. end;
  894. end
  895. else
  896. begin
  897. if try_to_consume(_LKLAMMER) then
  898. begin
  899. para:=parse_paras(false,false,_RKLAMMER);
  900. consume(_RKLAMMER);
  901. end;
  902. end;
  903. { indicate if this call was generated by a member and
  904. no explicit self is used, this is needed to determine
  905. how to handle a destructor call (PFV) }
  906. if membercall then
  907. include(callflags,cnf_member_call);
  908. if assigned(obj) then
  909. begin
  910. if not (st.symtabletype in [ObjectSymtable,recordsymtable]) then
  911. internalerror(200310031);
  912. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1,callflags);
  913. end
  914. else
  915. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags);
  916. end;
  917. afterassignment:=prevafterassn;
  918. end;
  919. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  920. var
  921. hp,hp2 : tnode;
  922. hpp : ^tnode;
  923. currprocdef : tprocdef;
  924. begin
  925. if not assigned(pv) then
  926. internalerror(200301121);
  927. if (m_tp_procvar in current_settings.modeswitches) or
  928. (m_mac_procvar in current_settings.modeswitches) then
  929. begin
  930. hp:=p2;
  931. hpp:=@p2;
  932. while assigned(hp) and
  933. (hp.nodetype=typeconvn) do
  934. begin
  935. hp:=ttypeconvnode(hp).left;
  936. { save orignal address of the old tree so we can replace the node }
  937. hpp:=@hp;
  938. end;
  939. if (hp.nodetype=calln) and
  940. { a procvar can't have parameters! }
  941. not assigned(tcallnode(hp).left) then
  942. begin
  943. currprocdef:=tcallnode(hp).symtableprocentry.Find_procdef_byprocvardef(pv);
  944. if assigned(currprocdef) then
  945. begin
  946. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  947. if (po_methodpointer in pv.procoptions) then
  948. tloadnode(hp2).set_mp(tcallnode(hp).methodpointer.getcopy);
  949. hp.destroy;
  950. { replace the old callnode with the new loadnode }
  951. hpp^:=hp2;
  952. end;
  953. end;
  954. end;
  955. end;
  956. { checks whether sym is a static field and if so, translates the access
  957. to the appropriate node tree }
  958. function handle_staticfield_access(sym: tsym; nested: boolean; var p1: tnode): boolean;
  959. var
  960. static_name: shortstring;
  961. srsymtable: tsymtable;
  962. begin
  963. result:=false;
  964. { generate access code }
  965. if (sp_static in sym.symoptions) then
  966. begin
  967. result:=true;
  968. if not nested then
  969. static_name:=lower(sym.owner.name^)+'_'+sym.name
  970. else
  971. static_name:=lower(generate_nested_name(sym.owner,'_'))+'_'+sym.name;
  972. if sym.owner.defowner.typ=objectdef then
  973. searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable,true)
  974. else
  975. searchsym_in_record(trecorddef(sym.owner.defowner),static_name,sym,srsymtable);
  976. if assigned(sym) then
  977. check_hints(sym,sym.symoptions,sym.deprecatedmsg);
  978. p1.free;
  979. p1:=nil;
  980. { static syms are always stored as absolutevarsym to handle scope and storage properly }
  981. propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref);
  982. end;
  983. end;
  984. { the following procedure handles the access to a property symbol }
  985. procedure handle_propertysym(propsym : tpropertysym;st : TSymtable;var p1 : tnode);
  986. var
  987. paras : tnode;
  988. p2 : tnode;
  989. membercall : boolean;
  990. callflags : tcallnodeflags;
  991. propaccesslist : tpropaccesslist;
  992. sym: tsym;
  993. begin
  994. { property parameters? read them only if the property really }
  995. { has parameters }
  996. paras:=nil;
  997. if (ppo_hasparameters in propsym.propoptions) then
  998. begin
  999. if try_to_consume(_LECKKLAMMER) then
  1000. begin
  1001. paras:=parse_paras(false,false,_RECKKLAMMER);
  1002. consume(_RECKKLAMMER);
  1003. end;
  1004. end;
  1005. { indexed property }
  1006. if (ppo_indexed in propsym.propoptions) then
  1007. begin
  1008. p2:=cordconstnode.create(propsym.index,propsym.indexdef,true);
  1009. paras:=ccallparanode.create(p2,paras);
  1010. end;
  1011. { we need only a write property if a := follows }
  1012. { if not(afterassignment) and not(in_args) then }
  1013. if token=_ASSIGNMENT then
  1014. begin
  1015. if getpropaccesslist(propsym,palt_write,propaccesslist) then
  1016. begin
  1017. sym:=propaccesslist.firstsym^.sym;
  1018. case sym.typ of
  1019. procsym :
  1020. begin
  1021. callflags:=[];
  1022. { generate the method call }
  1023. membercall:=maybe_load_methodpointer(st,p1);
  1024. if membercall then
  1025. include(callflags,cnf_member_call);
  1026. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags);
  1027. addsymref(sym);
  1028. paras:=nil;
  1029. consume(_ASSIGNMENT);
  1030. { read the expression }
  1031. if propsym.propdef.typ=procvardef then
  1032. getprocvardef:=tprocvardef(propsym.propdef);
  1033. p2:=comp_expr(true,false);
  1034. if assigned(getprocvardef) then
  1035. handle_procvar(getprocvardef,p2);
  1036. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  1037. { mark as property, both the tcallnode and the real call block }
  1038. include(p1.flags,nf_isproperty);
  1039. getprocvardef:=nil;
  1040. end;
  1041. fieldvarsym :
  1042. begin
  1043. { generate access code }
  1044. if not handle_staticfield_access(sym,false,p1) then
  1045. propaccesslist_to_node(p1,st,propaccesslist);
  1046. include(p1.flags,nf_isproperty);
  1047. consume(_ASSIGNMENT);
  1048. { read the expression }
  1049. p2:=comp_expr(true,false);
  1050. p1:=cassignmentnode.create(p1,p2);
  1051. end
  1052. else
  1053. begin
  1054. p1:=cerrornode.create;
  1055. Message(parser_e_no_procedure_to_access_property);
  1056. end;
  1057. end;
  1058. end
  1059. else
  1060. begin
  1061. p1:=cerrornode.create;
  1062. Message(parser_e_no_procedure_to_access_property);
  1063. end;
  1064. end
  1065. else
  1066. begin
  1067. if getpropaccesslist(propsym,palt_read,propaccesslist) then
  1068. begin
  1069. sym := propaccesslist.firstsym^.sym;
  1070. case sym.typ of
  1071. fieldvarsym :
  1072. begin
  1073. { generate access code }
  1074. if not handle_staticfield_access(sym,false,p1) then
  1075. propaccesslist_to_node(p1,st,propaccesslist);
  1076. include(p1.flags,nf_isproperty);
  1077. { catch expressions like "(propx):=1;" }
  1078. include(p1.flags,nf_no_lvalue);
  1079. end;
  1080. procsym :
  1081. begin
  1082. callflags:=[];
  1083. { generate the method call }
  1084. membercall:=maybe_load_methodpointer(st,p1);
  1085. if membercall then
  1086. include(callflags,cnf_member_call);
  1087. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags);
  1088. paras:=nil;
  1089. include(p1.flags,nf_isproperty);
  1090. include(p1.flags,nf_no_lvalue);
  1091. end
  1092. else
  1093. begin
  1094. p1:=cerrornode.create;
  1095. Message(type_e_mismatch);
  1096. end;
  1097. end;
  1098. end
  1099. else
  1100. begin
  1101. { error, no function to read property }
  1102. p1:=cerrornode.create;
  1103. Message(parser_e_no_procedure_to_access_property);
  1104. end;
  1105. end;
  1106. { release paras if not used }
  1107. if assigned(paras) then
  1108. paras.free;
  1109. end;
  1110. { the ID token has to be consumed before calling this function }
  1111. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags);
  1112. var
  1113. isclassref:boolean;
  1114. begin
  1115. if sym=nil then
  1116. begin
  1117. { pattern is still valid unless
  1118. there is another ID just after the ID of sym }
  1119. Message1(sym_e_id_no_member,orgpattern);
  1120. p1.free;
  1121. p1:=cerrornode.create;
  1122. { try to clean up }
  1123. again:=false;
  1124. end
  1125. else
  1126. begin
  1127. if assigned(p1) then
  1128. begin
  1129. if not assigned(p1.resultdef) then
  1130. do_typecheckpass(p1);
  1131. isclassref:=(p1.resultdef.typ=classrefdef);
  1132. end
  1133. else
  1134. isclassref:=false;
  1135. { we assume, that only procsyms and varsyms are in an object }
  1136. { symbol table, for classes, properties are allowed }
  1137. case sym.typ of
  1138. procsym:
  1139. begin
  1140. do_proc_call(sym,sym.owner,structh,
  1141. (getaddr and not(token in [_CARET,_POINT])),
  1142. again,p1,callflags);
  1143. { we need to know which procedure is called }
  1144. do_typecheckpass(p1);
  1145. { calling using classref? }
  1146. if isclassref and
  1147. (p1.nodetype=calln) and
  1148. assigned(tcallnode(p1).procdefinition) and
  1149. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1150. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1151. Message(parser_e_only_class_members_via_class_ref);
  1152. end;
  1153. fieldvarsym:
  1154. begin
  1155. if not handle_staticfield_access(sym,true,p1) then
  1156. begin
  1157. if isclassref then
  1158. if assigned(p1) and
  1159. (
  1160. is_self_node(p1) or
  1161. (assigned(current_procinfo) and (current_procinfo.procdef.no_self_node) and
  1162. (current_procinfo.procdef.struct=structh))) then
  1163. Message(parser_e_only_class_members)
  1164. else
  1165. Message(parser_e_only_class_members_via_class_ref);
  1166. p1:=csubscriptnode.create(sym,p1);
  1167. end;
  1168. end;
  1169. propertysym:
  1170. begin
  1171. if isclassref and not (sp_static in sym.symoptions) then
  1172. Message(parser_e_only_class_members_via_class_ref);
  1173. handle_propertysym(tpropertysym(sym),sym.owner,p1);
  1174. end;
  1175. typesym:
  1176. begin
  1177. p1.free;
  1178. if try_to_consume(_LKLAMMER) then
  1179. begin
  1180. p1:=comp_expr(true,false);
  1181. consume(_RKLAMMER);
  1182. p1:=ctypeconvnode.create_explicit(p1,ttypesym(sym).typedef);
  1183. end
  1184. else
  1185. begin
  1186. p1:=ctypenode.create(ttypesym(sym).typedef);
  1187. if (is_class(ttypesym(sym).typedef) or is_objcclass(ttypesym(sym).typedef)) and
  1188. not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1189. p1:=cloadvmtaddrnode.create(p1);
  1190. end;
  1191. end;
  1192. constsym:
  1193. begin
  1194. p1.free;
  1195. p1:=genconstsymtree(tconstsym(sym));
  1196. end;
  1197. staticvarsym:
  1198. begin
  1199. { typed constant is a staticvarsym
  1200. now they are absolutevarsym }
  1201. p1.free;
  1202. p1:=cloadnode.create(sym,sym.Owner);
  1203. end;
  1204. absolutevarsym:
  1205. begin
  1206. p1.free;
  1207. p1:=nil;
  1208. { typed constants are absolutebarsyms now to handle storage properly }
  1209. propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref);
  1210. end
  1211. else
  1212. internalerror(16);
  1213. end;
  1214. end;
  1215. end;
  1216. function handle_factor_typenode(hdef:tdef;getaddr:boolean;var again:boolean;sym:tsym;typeonly:boolean):tnode;
  1217. var
  1218. srsym : tsym;
  1219. srsymtable : tsymtable;
  1220. begin
  1221. if sym=nil then
  1222. sym:=hdef.typesym;
  1223. { allow Ordinal(Value) for type declarations since it
  1224. can be an enummeration declaration or a set lke:
  1225. (OrdinalType(const1)..OrdinalType(const2) }
  1226. if (not typeonly or is_ordinal(hdef))and try_to_consume(_LKLAMMER) then
  1227. begin
  1228. result:=comp_expr(true,false);
  1229. consume(_RKLAMMER);
  1230. { type casts to class helpers aren't allowed }
  1231. if is_objectpascal_helper(hdef) then
  1232. Message(parser_e_no_category_as_types)
  1233. { recovery by not creating a conversion node }
  1234. else
  1235. result:=ctypeconvnode.create_explicit(result,hdef);
  1236. end
  1237. else { not LKLAMMER }
  1238. if (token=_POINT) and
  1239. (is_object(hdef) or is_record(hdef)) then
  1240. begin
  1241. consume(_POINT);
  1242. { handles calling methods declared in parent objects
  1243. using "parentobject.methodname()" }
  1244. if assigned(current_structdef) and
  1245. not(getaddr) and
  1246. current_structdef.is_related(hdef) then
  1247. begin
  1248. result:=ctypenode.create(hdef);
  1249. ttypenode(result).typesym:=sym;
  1250. { search also in inherited methods }
  1251. searchsym_in_class(tobjectdef(hdef),tobjectdef(current_structdef),pattern,srsym,srsymtable,true);
  1252. if assigned(srsym) then
  1253. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1254. consume(_ID);
  1255. do_member_read(tabstractrecorddef(hdef),false,srsym,result,again,[]);
  1256. end
  1257. else
  1258. begin
  1259. { handles:
  1260. * @TObject.Load
  1261. * static methods and variables }
  1262. result:=ctypenode.create(hdef);
  1263. ttypenode(result).typesym:=sym;
  1264. { TP allows also @TMenu.Load if Load is only }
  1265. { defined in an anchestor class }
  1266. srsym:=search_struct_member(tabstractrecorddef(hdef),pattern);
  1267. if assigned(srsym) then
  1268. begin
  1269. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1270. consume(_ID);
  1271. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[]);
  1272. end
  1273. else
  1274. Message1(sym_e_id_no_member,orgpattern);
  1275. end;
  1276. end
  1277. else
  1278. begin
  1279. { Normally here would be the check against the usage
  1280. of "TClassHelper.Something", but as that might be
  1281. used inside of system symbols like sizeof and
  1282. typeinfo this check is put into ttypenode.pass_1
  1283. (for "TClassHelper" alone) and tcallnode.pass_1
  1284. (for "TClassHelper.Something") }
  1285. { class reference ? }
  1286. if is_class(hdef) or
  1287. is_objcclass(hdef) then
  1288. begin
  1289. if getaddr and (token=_POINT) then
  1290. begin
  1291. consume(_POINT);
  1292. { allows @Object.Method }
  1293. { also allows static methods and variables }
  1294. result:=ctypenode.create(hdef);
  1295. ttypenode(result).typesym:=sym;
  1296. { TP allows also @TMenu.Load if Load is only }
  1297. { defined in an anchestor class }
  1298. srsym:=search_struct_member(tobjectdef(hdef),pattern);
  1299. if assigned(srsym) then
  1300. begin
  1301. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1302. consume(_ID);
  1303. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[]);
  1304. end
  1305. else
  1306. begin
  1307. Message1(sym_e_id_no_member,orgpattern);
  1308. consume(_ID);
  1309. end;
  1310. end
  1311. else
  1312. begin
  1313. result:=ctypenode.create(hdef);
  1314. ttypenode(result).typesym:=sym;
  1315. { For a type block we simply return only
  1316. the type. For all other blocks we return
  1317. a loadvmt node }
  1318. if not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1319. result:=cloadvmtaddrnode.create(result);
  1320. end;
  1321. end
  1322. else
  1323. begin
  1324. result:=ctypenode.create(hdef);
  1325. ttypenode(result).typesym:=sym;
  1326. end;
  1327. end;
  1328. end;
  1329. {****************************************************************************
  1330. Factor
  1331. ****************************************************************************}
  1332. {---------------------------------------------
  1333. PostFixOperators
  1334. ---------------------------------------------}
  1335. { returns whether or not p1 has been changed }
  1336. function postfixoperators(var p1:tnode;var again:boolean;getaddr:boolean): boolean;
  1337. { tries to avoid syntax errors after invalid qualifiers }
  1338. procedure recoverconsume_postfixops;
  1339. begin
  1340. repeat
  1341. if not try_to_consume(_CARET) then
  1342. if try_to_consume(_POINT) then
  1343. try_to_consume(_ID)
  1344. else if try_to_consume(_LECKKLAMMER) then
  1345. begin
  1346. repeat
  1347. comp_expr(true,false);
  1348. until not try_to_consume(_COMMA);
  1349. consume(_RECKKLAMMER);
  1350. end
  1351. else if try_to_consume(_LKLAMMER) then
  1352. begin
  1353. repeat
  1354. comp_expr(true,false);
  1355. until not try_to_consume(_COMMA);
  1356. consume(_RKLAMMER);
  1357. end
  1358. else
  1359. break;
  1360. until false;
  1361. end;
  1362. procedure handle_variantarray;
  1363. var
  1364. p4 : tnode;
  1365. newstatement : tstatementnode;
  1366. tempresultvariant,
  1367. temp : ttempcreatenode;
  1368. paras : tcallparanode;
  1369. newblock : tnode;
  1370. countindices : aint;
  1371. begin
  1372. { create statements with call initialize the arguments and
  1373. call fpc_dynarr_setlength }
  1374. newblock:=internalstatements(newstatement);
  1375. { get temp for array of indicies,
  1376. we set the real size later }
  1377. temp:=ctempcreatenode.create(s32inttype,4,tt_persistent,false);
  1378. addstatement(newstatement,temp);
  1379. countindices:=0;
  1380. repeat
  1381. p4:=comp_expr(true,false);
  1382. addstatement(newstatement,cassignmentnode.create(
  1383. ctemprefnode.create_offset(temp,countindices*s32inttype.size),p4));
  1384. inc(countindices);
  1385. until not try_to_consume(_COMMA);
  1386. { set real size }
  1387. temp.size:=countindices*s32inttype.size;
  1388. consume(_RECKKLAMMER);
  1389. { we need only a write access if a := follows }
  1390. if token=_ASSIGNMENT then
  1391. begin
  1392. consume(_ASSIGNMENT);
  1393. p4:=comp_expr(true,false);
  1394. { create call to fpc_vararray_put }
  1395. paras:=ccallparanode.create(cordconstnode.create
  1396. (countindices,s32inttype,true),
  1397. ccallparanode.create(caddrnode.create_internal
  1398. (ctemprefnode.create(temp)),
  1399. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1400. ccallparanode.create(ctypeconvnode.create_internal(p1,cvarianttype)
  1401. ,nil))));
  1402. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1403. addstatement(newstatement,ctempdeletenode.create(temp));
  1404. end
  1405. else
  1406. begin
  1407. { create temp for result }
  1408. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.size,tt_persistent,true);
  1409. addstatement(newstatement,tempresultvariant);
  1410. { create call to fpc_vararray_get }
  1411. paras:=ccallparanode.create(cordconstnode.create
  1412. (countindices,s32inttype,true),
  1413. ccallparanode.create(caddrnode.create_internal
  1414. (ctemprefnode.create(temp)),
  1415. ccallparanode.create(p1,
  1416. ccallparanode.create(
  1417. ctemprefnode.create(tempresultvariant)
  1418. ,nil))));
  1419. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1420. addstatement(newstatement,ctempdeletenode.create(temp));
  1421. { the last statement should return the value as
  1422. location and type, this is done be referencing the
  1423. temp and converting it first from a persistent temp to
  1424. normal temp }
  1425. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1426. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1427. end;
  1428. p1:=newblock;
  1429. end;
  1430. function parse_array_constructor(arrdef:tarraydef): tnode;
  1431. var
  1432. newstatement,assstatement:tstatementnode;
  1433. arrnode:ttempcreatenode;
  1434. temp2:ttempcreatenode;
  1435. assnode:tnode;
  1436. paracount:integer;
  1437. begin
  1438. result:=internalstatements(newstatement);
  1439. { create temp for result }
  1440. arrnode:=ctempcreatenode.create(arrdef,arrdef.size,tt_persistent,true);
  1441. addstatement(newstatement,arrnode);
  1442. paracount:=0;
  1443. { check arguments and create an assignment calls }
  1444. if try_to_consume(_LKLAMMER) then
  1445. begin
  1446. assnode:=internalstatements(assstatement);
  1447. repeat
  1448. { arr[i] := param_i }
  1449. addstatement(assstatement,
  1450. cassignmentnode.create(
  1451. cvecnode.create(
  1452. ctemprefnode.create(arrnode),
  1453. cordconstnode.create(paracount,arrdef.rangedef,false)),
  1454. comp_expr(true,false)));
  1455. inc(paracount);
  1456. until not try_to_consume(_COMMA);
  1457. consume(_RKLAMMER);
  1458. end
  1459. else
  1460. assnode:=nil;
  1461. { get temp for array of lengths }
  1462. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1463. addstatement(newstatement,temp2);
  1464. { one dimensional }
  1465. addstatement(newstatement,cassignmentnode.create(
  1466. ctemprefnode.create_offset(temp2,0),
  1467. cordconstnode.create
  1468. (paracount,s32inttype,true)));
  1469. { create call to fpc_dynarr_setlength }
  1470. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1471. ccallparanode.create(caddrnode.create_internal
  1472. (ctemprefnode.create(temp2)),
  1473. ccallparanode.create(cordconstnode.create
  1474. (1,s32inttype,true),
  1475. ccallparanode.create(caddrnode.create_internal
  1476. (crttinode.create(tstoreddef(arrdef),initrtti,rdt_normal)),
  1477. ccallparanode.create(
  1478. ctypeconvnode.create_internal(
  1479. ctemprefnode.create(arrnode),voidpointertype),
  1480. nil))))
  1481. ));
  1482. { add assignment statememnts }
  1483. addstatement(newstatement,ctempdeletenode.create(temp2));
  1484. if assigned(assnode) then
  1485. addstatement(newstatement,assnode);
  1486. { the last statement should return the value as
  1487. location and type, this is done be referencing the
  1488. temp and converting it first from a persistent temp to
  1489. normal temp }
  1490. addstatement(newstatement,ctempdeletenode.create_normal_temp(arrnode));
  1491. addstatement(newstatement,ctemprefnode.create(arrnode));
  1492. end;
  1493. var
  1494. protsym : tpropertysym;
  1495. p2,p3 : tnode;
  1496. srsym : tsym;
  1497. srsymtable : TSymtable;
  1498. structh : tabstractrecorddef;
  1499. { shouldn't be used that often, so the extra overhead is ok to save
  1500. stack space }
  1501. dispatchstring : ansistring;
  1502. nodechanged : boolean;
  1503. calltype: tdispcalltype;
  1504. label
  1505. skipreckklammercheck;
  1506. begin
  1507. result:=false;
  1508. again:=true;
  1509. while again do
  1510. begin
  1511. { we need the resultdef }
  1512. do_typecheckpass_changed(p1,nodechanged);
  1513. result:=result or nodechanged;
  1514. if codegenerror then
  1515. begin
  1516. recoverconsume_postfixops;
  1517. exit;
  1518. end;
  1519. { handle token }
  1520. case token of
  1521. _CARET:
  1522. begin
  1523. consume(_CARET);
  1524. { support tp/mac procvar^ if the procvar returns a
  1525. pointer type }
  1526. if ((m_tp_procvar in current_settings.modeswitches) or
  1527. (m_mac_procvar in current_settings.modeswitches)) and
  1528. (p1.resultdef.typ=procvardef) and
  1529. (tprocvardef(p1.resultdef).returndef.typ=pointerdef) then
  1530. begin
  1531. p1:=ccallnode.create_procvar(nil,p1);
  1532. typecheckpass(p1);
  1533. end;
  1534. if (p1.resultdef.typ<>pointerdef) then
  1535. begin
  1536. { ^ as binary operator is a problem!!!! (FK) }
  1537. again:=false;
  1538. Message(parser_e_invalid_qualifier);
  1539. recoverconsume_postfixops;
  1540. p1.destroy;
  1541. p1:=cerrornode.create;
  1542. end
  1543. else
  1544. p1:=cderefnode.create(p1);
  1545. end;
  1546. _LECKKLAMMER:
  1547. begin
  1548. if is_class_or_interface_or_object(p1.resultdef) or
  1549. is_dispinterface(p1.resultdef) or is_record(p1.resultdef) then
  1550. begin
  1551. { default property }
  1552. protsym:=search_default_property(tabstractrecorddef(p1.resultdef));
  1553. if not(assigned(protsym)) then
  1554. begin
  1555. p1.destroy;
  1556. p1:=cerrornode.create;
  1557. again:=false;
  1558. message(parser_e_no_default_property_available);
  1559. end
  1560. else
  1561. begin
  1562. { The property symbol is referenced indirect }
  1563. protsym.IncRefCount;
  1564. handle_propertysym(protsym,protsym.owner,p1);
  1565. end;
  1566. end
  1567. else
  1568. begin
  1569. consume(_LECKKLAMMER);
  1570. repeat
  1571. { in all of the cases below, p1 is changed }
  1572. case p1.resultdef.typ of
  1573. pointerdef:
  1574. begin
  1575. { support delphi autoderef }
  1576. if (tpointerdef(p1.resultdef).pointeddef.typ=arraydef) and
  1577. (m_autoderef in current_settings.modeswitches) then
  1578. p1:=cderefnode.create(p1);
  1579. p2:=comp_expr(true,false);
  1580. { Support Pbytevar[0..9] which returns array [0..9].}
  1581. if try_to_consume(_POINTPOINT) then
  1582. p2:=crangenode.create(p2,comp_expr(true,false));
  1583. p1:=cvecnode.create(p1,p2);
  1584. end;
  1585. variantdef:
  1586. begin
  1587. handle_variantarray;
  1588. { the RECKKLAMMER is already read }
  1589. goto skipreckklammercheck;
  1590. end;
  1591. stringdef :
  1592. begin
  1593. p2:=comp_expr(true,false);
  1594. { Support string[0..9] which returns array [0..9] of char.}
  1595. if try_to_consume(_POINTPOINT) then
  1596. p2:=crangenode.create(p2,comp_expr(true,false));
  1597. p1:=cvecnode.create(p1,p2);
  1598. end;
  1599. arraydef:
  1600. begin
  1601. p2:=comp_expr(true,false);
  1602. { support SEG:OFS for go32v2 Mem[] }
  1603. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  1604. (p1.nodetype=loadn) and
  1605. assigned(tloadnode(p1).symtableentry) and
  1606. assigned(tloadnode(p1).symtableentry.owner.name) and
  1607. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1608. ((tloadnode(p1).symtableentry.name='MEM') or
  1609. (tloadnode(p1).symtableentry.name='MEMW') or
  1610. (tloadnode(p1).symtableentry.name='MEML')) then
  1611. begin
  1612. if try_to_consume(_COLON) then
  1613. begin
  1614. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1615. p2:=comp_expr(true,false);
  1616. p2:=caddnode.create(addn,p2,p3);
  1617. if try_to_consume(_POINTPOINT) then
  1618. { Support mem[$a000:$0000..$07ff] which returns array [0..$7ff] of memtype.}
  1619. p2:=crangenode.create(p2,caddnode.create(addn,comp_expr(true,false),p3.getcopy));
  1620. p1:=cvecnode.create(p1,p2);
  1621. include(tvecnode(p1).flags,nf_memseg);
  1622. include(tvecnode(p1).flags,nf_memindex);
  1623. end
  1624. else
  1625. begin
  1626. if try_to_consume(_POINTPOINT) then
  1627. { Support mem[$80000000..$80000002] which returns array [0..2] of memtype.}
  1628. p2:=crangenode.create(p2,comp_expr(true,false));
  1629. p1:=cvecnode.create(p1,p2);
  1630. include(tvecnode(p1).flags,nf_memindex);
  1631. end;
  1632. end
  1633. else
  1634. begin
  1635. if try_to_consume(_POINTPOINT) then
  1636. { Support arrayvar[0..9] which returns array [0..9] of arraytype.}
  1637. p2:=crangenode.create(p2,comp_expr(true,false));
  1638. p1:=cvecnode.create(p1,p2);
  1639. end;
  1640. end;
  1641. else
  1642. begin
  1643. if p1.resultdef.typ<>undefineddef then
  1644. Message(parser_e_invalid_qualifier);
  1645. p1.destroy;
  1646. p1:=cerrornode.create;
  1647. comp_expr(true,false);
  1648. again:=false;
  1649. end;
  1650. end;
  1651. do_typecheckpass(p1);
  1652. until not try_to_consume(_COMMA);
  1653. consume(_RECKKLAMMER);
  1654. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1655. skipreckklammercheck:
  1656. end;
  1657. end;
  1658. _POINT :
  1659. begin
  1660. consume(_POINT);
  1661. if (p1.resultdef.typ=pointerdef) and
  1662. (m_autoderef in current_settings.modeswitches) and
  1663. { don't auto-deref objc.id, because then the code
  1664. below for supporting id.anyobjcmethod isn't triggered }
  1665. (p1.resultdef<>objc_idtype) then
  1666. begin
  1667. p1:=cderefnode.create(p1);
  1668. do_typecheckpass(p1);
  1669. end;
  1670. { procvar.<something> can never mean anything so always
  1671. try to call it in case it returns a record/object/... }
  1672. maybe_call_procvar(p1,false);
  1673. case p1.resultdef.typ of
  1674. recorddef:
  1675. begin
  1676. if token=_ID then
  1677. begin
  1678. structh:=tabstractrecorddef(p1.resultdef);
  1679. searchsym_in_record(structh,pattern,srsym,srsymtable);
  1680. if assigned(srsym) then
  1681. begin
  1682. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1683. consume(_ID);
  1684. do_member_read(structh,getaddr,srsym,p1,again,[]);
  1685. end
  1686. else
  1687. begin
  1688. Message1(sym_e_id_no_member,orgpattern);
  1689. p1.destroy;
  1690. p1:=cerrornode.create;
  1691. { try to clean up }
  1692. consume(_ID);
  1693. end;
  1694. end
  1695. else
  1696. consume(_ID);
  1697. end;
  1698. enumdef:
  1699. begin
  1700. if token=_ID then
  1701. begin
  1702. srsym:=tsym(tenumdef(p1.resultdef).symtable.Find(pattern));
  1703. p1.destroy;
  1704. if assigned(srsym) and (srsym.typ=enumsym) then
  1705. begin
  1706. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1707. p1:=genenumnode(tenumsym(srsym));
  1708. end
  1709. else
  1710. begin
  1711. Message1(sym_e_id_no_member,orgpattern);
  1712. p1:=cerrornode.create;
  1713. end;
  1714. end;
  1715. consume(_ID);
  1716. end;
  1717. arraydef:
  1718. begin
  1719. if is_dynamic_array(p1.resultdef) then
  1720. begin
  1721. if token=_ID then
  1722. begin
  1723. if pattern='CREATE' then
  1724. begin
  1725. consume(_ID);
  1726. p2:=parse_array_constructor(tarraydef(p1.resultdef));
  1727. p1.destroy;
  1728. p1:=p2;
  1729. end
  1730. else
  1731. begin
  1732. Message2(scan_f_syn_expected,'CREATE',pattern);
  1733. p1.destroy;
  1734. p1:=cerrornode.create;
  1735. consume(_ID);
  1736. end;
  1737. end;
  1738. end
  1739. else
  1740. begin
  1741. Message(parser_e_invalid_qualifier);
  1742. p1.destroy;
  1743. p1:=cerrornode.create;
  1744. consume(_ID);
  1745. end;
  1746. end;
  1747. variantdef:
  1748. begin
  1749. { dispatch call? }
  1750. { lhs := v.ident[parameters] -> property get
  1751. lhs := v.ident(parameters) -> method call
  1752. v.ident[parameters] := rhs -> property put
  1753. v.ident(parameters) := rhs -> also property put }
  1754. if token=_ID then
  1755. begin
  1756. dispatchstring:=orgpattern;
  1757. consume(_ID);
  1758. calltype:=dct_method;
  1759. if try_to_consume(_LKLAMMER) then
  1760. begin
  1761. p2:=parse_paras(false,true,_RKLAMMER);
  1762. consume(_RKLAMMER);
  1763. end
  1764. else if try_to_consume(_LECKKLAMMER) then
  1765. begin
  1766. p2:=parse_paras(false,true,_RECKKLAMMER);
  1767. consume(_RECKKLAMMER);
  1768. calltype:=dct_propget;
  1769. end
  1770. else
  1771. p2:=nil;
  1772. { property setter? }
  1773. if (token=_ASSIGNMENT) and not(afterassignment) then
  1774. begin
  1775. consume(_ASSIGNMENT);
  1776. { read the expression }
  1777. p3:=comp_expr(true,false);
  1778. { concat value parameter too }
  1779. p2:=ccallparanode.create(p3,p2);
  1780. p1:=translate_disp_call(p1,p2,dct_propput,dispatchstring,0,voidtype);
  1781. end
  1782. else
  1783. { this is only an approximation
  1784. setting useresult if not necessary is only a waste of time, no more, no less (FK) }
  1785. if afterassignment or in_args or (token<>_SEMICOLON) then
  1786. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,cvarianttype)
  1787. else
  1788. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,voidtype);
  1789. end
  1790. else { Error }
  1791. Consume(_ID);
  1792. end;
  1793. classrefdef:
  1794. begin
  1795. if token=_ID then
  1796. begin
  1797. structh:=tobjectdef(tclassrefdef(p1.resultdef).pointeddef);
  1798. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,true);
  1799. if assigned(srsym) then
  1800. begin
  1801. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1802. consume(_ID);
  1803. do_member_read(structh,getaddr,srsym,p1,again,[]);
  1804. end
  1805. else
  1806. begin
  1807. Message1(sym_e_id_no_member,orgpattern);
  1808. p1.destroy;
  1809. p1:=cerrornode.create;
  1810. { try to clean up }
  1811. consume(_ID);
  1812. end;
  1813. end
  1814. else { Error }
  1815. Consume(_ID);
  1816. end;
  1817. objectdef:
  1818. begin
  1819. if token=_ID then
  1820. begin
  1821. structh:=tobjectdef(p1.resultdef);
  1822. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,true);
  1823. if assigned(srsym) then
  1824. begin
  1825. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1826. consume(_ID);
  1827. do_member_read(structh,getaddr,srsym,p1,again,[]);
  1828. end
  1829. else
  1830. begin
  1831. Message1(sym_e_id_no_member,orgpattern);
  1832. p1.destroy;
  1833. p1:=cerrornode.create;
  1834. { try to clean up }
  1835. consume(_ID);
  1836. end;
  1837. end
  1838. else { Error }
  1839. Consume(_ID);
  1840. end;
  1841. pointerdef:
  1842. begin
  1843. if (p1.resultdef=objc_idtype) then
  1844. begin
  1845. { objc's id type can be used to call any
  1846. Objective-C method of any Objective-C class
  1847. type that's currently in scope }
  1848. if search_objc_method(pattern,srsym,srsymtable) then
  1849. begin
  1850. consume(_ID);
  1851. do_proc_call(srsym,srsymtable,nil,
  1852. (getaddr and not(token in [_CARET,_POINT])),
  1853. again,p1,[cnf_objc_id_call]);
  1854. { we need to know which procedure is called }
  1855. do_typecheckpass(p1);
  1856. end
  1857. else
  1858. begin
  1859. consume(_ID);
  1860. Message(parser_e_methode_id_expected);
  1861. end;
  1862. end
  1863. else
  1864. begin
  1865. Message(parser_e_invalid_qualifier);
  1866. if tpointerdef(p1.resultdef).pointeddef.typ in [recorddef,objectdef,classrefdef] then
  1867. Message(parser_h_maybe_deref_caret_missing);
  1868. end
  1869. end;
  1870. else
  1871. begin
  1872. if p1.resultdef.typ<>undefineddef then
  1873. Message(parser_e_invalid_qualifier);
  1874. p1.destroy;
  1875. p1:=cerrornode.create;
  1876. { Error }
  1877. consume(_ID);
  1878. end;
  1879. end;
  1880. end;
  1881. else
  1882. begin
  1883. { is this a procedure variable ? }
  1884. if assigned(p1.resultdef) and
  1885. (p1.resultdef.typ=procvardef) then
  1886. begin
  1887. { Typenode for typecasting or expecting a procvar }
  1888. if (p1.nodetype=typen) or
  1889. (
  1890. assigned(getprocvardef) and
  1891. equal_defs(p1.resultdef,getprocvardef)
  1892. ) then
  1893. begin
  1894. if try_to_consume(_LKLAMMER) then
  1895. begin
  1896. p1:=comp_expr(true,false);
  1897. consume(_RKLAMMER);
  1898. p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
  1899. end
  1900. else
  1901. again:=false
  1902. end
  1903. else
  1904. begin
  1905. if try_to_consume(_LKLAMMER) then
  1906. begin
  1907. p2:=parse_paras(false,false,_RKLAMMER);
  1908. consume(_RKLAMMER);
  1909. p1:=ccallnode.create_procvar(p2,p1);
  1910. { proc():= is never possible }
  1911. if token=_ASSIGNMENT then
  1912. begin
  1913. Message(parser_e_illegal_expression);
  1914. p1.free;
  1915. p1:=cerrornode.create;
  1916. again:=false;
  1917. end;
  1918. end
  1919. else
  1920. again:=false;
  1921. end;
  1922. end
  1923. else
  1924. again:=false;
  1925. end;
  1926. end;
  1927. { we only try again if p1 was changed }
  1928. if again or
  1929. (p1.nodetype=errorn) then
  1930. result:=true;
  1931. end; { while again }
  1932. end;
  1933. function is_member_read(sym: tsym; st: tsymtable; var p1: tnode;
  1934. out memberparentdef: tdef): boolean;
  1935. var
  1936. hdef : tdef;
  1937. begin
  1938. result:=true;
  1939. memberparentdef:=nil;
  1940. case st.symtabletype of
  1941. ObjectSymtable,
  1942. recordsymtable:
  1943. begin
  1944. memberparentdef:=tdef(st.defowner);
  1945. exit;
  1946. end;
  1947. WithSymtable:
  1948. begin
  1949. if assigned(p1) then
  1950. internalerror(2007012002);
  1951. hdef:=tnode(twithsymtable(st).withrefnode).resultdef;
  1952. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  1953. if not(hdef.typ in [objectdef,classrefdef]) then
  1954. exit;
  1955. if (hdef.typ=classrefdef) then
  1956. hdef:=tclassrefdef(hdef).pointeddef;
  1957. memberparentdef:=hdef;
  1958. end;
  1959. else
  1960. result:=false;
  1961. end;
  1962. end;
  1963. {$maxfpuregisters 0}
  1964. function factor(getaddr,typeonly:boolean) : tnode;
  1965. {---------------------------------------------
  1966. Factor_read_id
  1967. ---------------------------------------------}
  1968. procedure factor_read_id(out p1:tnode;var again:boolean);
  1969. var
  1970. srsym : tsym;
  1971. srsymtable : TSymtable;
  1972. hdef : tdef;
  1973. orgstoredpattern,
  1974. storedpattern : string;
  1975. callflags: tcallnodeflags;
  1976. t : ttoken;
  1977. unit_found : boolean;
  1978. begin
  1979. { allow post fix operators }
  1980. again:=true;
  1981. { first check for identifier }
  1982. if token<>_ID then
  1983. begin
  1984. srsym:=generrorsym;
  1985. srsymtable:=nil;
  1986. consume(_ID);
  1987. end
  1988. else
  1989. begin
  1990. if typeonly then
  1991. searchsym_type(pattern,srsym,srsymtable)
  1992. else
  1993. searchsym(pattern,srsym,srsymtable);
  1994. { handle unit specification like System.Writeln }
  1995. unit_found:=try_consume_unitsym(srsym,srsymtable,t,true);
  1996. storedpattern:=pattern;
  1997. orgstoredpattern:=orgpattern;
  1998. consume(t);
  1999. { named parameter support }
  2000. found_arg_name:=false;
  2001. if not(unit_found) and
  2002. named_args_allowed and
  2003. (token=_ASSIGNMENT) then
  2004. begin
  2005. found_arg_name:=true;
  2006. p1:=cstringconstnode.createstr(storedpattern);
  2007. consume(_ASSIGNMENT);
  2008. exit;
  2009. end;
  2010. { check hints, but only if it isn't a potential generic symbol;
  2011. that is checked in sub_expr if it isn't a generic }
  2012. if assigned(srsym) and
  2013. not (
  2014. (srsym.typ=typesym) and
  2015. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) and
  2016. not (sp_generic_para in srsym.symoptions) and
  2017. (token in [_LT, _LSHARPBRACKET])
  2018. ) then
  2019. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2020. { if nothing found give error and return errorsym }
  2021. if not assigned(srsym) or
  2022. { is this a generic dummy symbol? }
  2023. ((srsym.typ=typesym) and
  2024. assigned(ttypesym(srsym).typedef) and
  2025. (ttypesym(srsym).typedef.typ=undefineddef) and
  2026. not (sp_generic_para in srsym.symoptions) and
  2027. not (token in [_LT, _LSHARPBRACKET]) and
  2028. not (
  2029. { in non-Delphi modes the generic class' name without a
  2030. "specialization" or "<T>" may be used to identify the
  2031. current class }
  2032. (sp_generic_dummy in srsym.symoptions) and
  2033. assigned(current_structdef) and
  2034. (df_generic in current_structdef.defoptions) and
  2035. not (m_delphi in current_settings.modeswitches) and
  2036. (upper(srsym.realname)=copy(current_structdef.objname^,1,pos('$',current_structdef.objname^)-1))
  2037. )) and
  2038. { it could be a rename of a generic para }
  2039. { Note: if this generates false positives we'll need to
  2040. include a "basesym" to tsym to track the original
  2041. symbol }
  2042. not (sp_explicitrename in srsym.symoptions) then
  2043. begin
  2044. identifier_not_found(orgstoredpattern);
  2045. srsym:=generrorsym;
  2046. srsymtable:=nil;
  2047. end;
  2048. end;
  2049. { Access to funcret or need to call the function? }
  2050. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  2051. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  2052. { result(x) is not allowed }
  2053. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  2054. (
  2055. (token=_LKLAMMER) or
  2056. (
  2057. (
  2058. (m_tp7 in current_settings.modeswitches) or
  2059. (m_delphi in current_settings.modeswitches)
  2060. ) and
  2061. (afterassignment or in_args)
  2062. )
  2063. ) then
  2064. begin
  2065. hdef:=tdef(srsym.owner.defowner);
  2066. if assigned(hdef) and
  2067. (hdef.typ=procdef) then
  2068. srsym:=tprocdef(hdef).procsym
  2069. else
  2070. begin
  2071. Message(parser_e_illegal_expression);
  2072. srsym:=generrorsym;
  2073. end;
  2074. srsymtable:=srsym.owner;
  2075. end;
  2076. begin
  2077. case srsym.typ of
  2078. absolutevarsym :
  2079. begin
  2080. if (tabsolutevarsym(srsym).abstyp=tovar) then
  2081. begin
  2082. p1:=nil;
  2083. propaccesslist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  2084. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vardef);
  2085. include(p1.flags,nf_absolute);
  2086. end
  2087. else
  2088. p1:=cloadnode.create(srsym,srsymtable);
  2089. end;
  2090. staticvarsym,
  2091. localvarsym,
  2092. paravarsym,
  2093. fieldvarsym :
  2094. begin
  2095. { check if we are reading a field of an object/class/ }
  2096. { record. is_member_read() will deal with withsymtables }
  2097. { if needed. }
  2098. p1:=nil;
  2099. if is_member_read(srsym,srsymtable,p1,hdef) then
  2100. begin
  2101. { if the field was originally found in an }
  2102. { objectsymtable, it means it's part of self }
  2103. { if only method from which it was called is }
  2104. { not class static }
  2105. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2106. { if we are accessing a owner procsym from the nested }
  2107. { class we need to call it as a class member }
  2108. if assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2109. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2110. else
  2111. if assigned(current_procinfo) and current_procinfo.procdef.no_self_node then
  2112. p1:=cloadvmtaddrnode.create(ctypenode.create(current_procinfo.procdef.struct))
  2113. else
  2114. p1:=load_self_node;
  2115. { now, if the field itself is part of an objectsymtab }
  2116. { (it can be even if it was found in a withsymtable, }
  2117. { e.g., "with classinstance do field := 5"), then }
  2118. { let do_member_read handle it }
  2119. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2120. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2121. else
  2122. { otherwise it's a regular record subscript }
  2123. p1:=csubscriptnode.create(srsym,p1);
  2124. end
  2125. else
  2126. { regular non-field load }
  2127. p1:=cloadnode.create(srsym,srsymtable);
  2128. end;
  2129. syssym :
  2130. begin
  2131. p1:=statement_syssym(tsyssym(srsym).number);
  2132. end;
  2133. typesym :
  2134. begin
  2135. hdef:=ttypesym(srsym).typedef;
  2136. if not assigned(hdef) then
  2137. begin
  2138. again:=false;
  2139. end
  2140. else
  2141. begin
  2142. { We need to know if this unit uses Variants }
  2143. if (hdef=cvarianttype) and
  2144. not(cs_compilesystem in current_settings.moduleswitches) then
  2145. current_module.flags:=current_module.flags or uf_uses_variants;
  2146. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,typeonly);
  2147. end;
  2148. end;
  2149. enumsym :
  2150. begin
  2151. p1:=genenumnode(tenumsym(srsym));
  2152. end;
  2153. constsym :
  2154. begin
  2155. if tconstsym(srsym).consttyp=constresourcestring then
  2156. begin
  2157. p1:=cloadnode.create(srsym,srsymtable);
  2158. do_typecheckpass(p1);
  2159. p1.resultdef:=getansistringdef;
  2160. end
  2161. else
  2162. p1:=genconstsymtree(tconstsym(srsym));
  2163. end;
  2164. procsym :
  2165. begin
  2166. p1:=nil;
  2167. { check if it's a method/class method }
  2168. if is_member_read(srsym,srsymtable,p1,hdef) then
  2169. begin
  2170. { if we are accessing a owner procsym from the nested }
  2171. { class we need to call it as a class member }
  2172. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  2173. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2174. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  2175. { not srsymtable.symtabletype since that can be }
  2176. { withsymtable as well }
  2177. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2178. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2179. else
  2180. { no procsyms in records (yet) }
  2181. internalerror(2007012006);
  2182. end
  2183. else
  2184. begin
  2185. { regular procedure/function call }
  2186. if not unit_found then
  2187. callflags:=[]
  2188. else
  2189. callflags:=[cnf_unit_specified];
  2190. do_proc_call(srsym,srsymtable,nil,
  2191. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  2192. again,p1,callflags);
  2193. end;
  2194. end;
  2195. propertysym :
  2196. begin
  2197. p1:=nil;
  2198. { property of a class/object? }
  2199. if is_member_read(srsym,srsymtable,p1,hdef) then
  2200. begin
  2201. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2202. { if we are accessing a owner procsym from the nested }
  2203. { class we need to call it as a class member }
  2204. if assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2205. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2206. else
  2207. if assigned(current_procinfo) and current_procinfo.procdef.no_self_node then
  2208. { no self node in static class methods }
  2209. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2210. else
  2211. p1:=load_self_node;
  2212. { not srsymtable.symtabletype since that can be }
  2213. { withsymtable as well }
  2214. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2215. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2216. else
  2217. { no propertysyms in records (yet) }
  2218. internalerror(2009111510);
  2219. end
  2220. else
  2221. { no method pointer }
  2222. begin
  2223. handle_propertysym(tpropertysym(srsym),srsymtable,p1);
  2224. end;
  2225. end;
  2226. labelsym :
  2227. begin
  2228. { Support @label }
  2229. if getaddr then
  2230. begin
  2231. if srsym.owner<>current_procinfo.procdef.localst then
  2232. CGMessage(parser_e_label_outside_proc);
  2233. p1:=cloadnode.create(srsym,srsym.owner)
  2234. end
  2235. else
  2236. begin
  2237. consume(_COLON);
  2238. if tlabelsym(srsym).defined then
  2239. Message(sym_e_label_already_defined);
  2240. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  2241. begin
  2242. tlabelsym(srsym).nonlocal:=true;
  2243. exclude(current_procinfo.procdef.procoptions,po_inline);
  2244. end;
  2245. if tlabelsym(srsym).nonlocal and
  2246. (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  2247. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  2248. tlabelsym(srsym).defined:=true;
  2249. p1:=clabelnode.create(nil,tlabelsym(srsym));
  2250. tlabelsym(srsym).code:=p1;
  2251. end;
  2252. end;
  2253. errorsym :
  2254. begin
  2255. p1:=cerrornode.create;
  2256. if try_to_consume(_LKLAMMER) then
  2257. begin
  2258. parse_paras(false,false,_RKLAMMER);
  2259. consume(_RKLAMMER);
  2260. end;
  2261. end;
  2262. else
  2263. begin
  2264. p1:=cerrornode.create;
  2265. Message(parser_e_illegal_expression);
  2266. end;
  2267. end; { end case }
  2268. end;
  2269. end;
  2270. {---------------------------------------------
  2271. Factor_Read_Set
  2272. ---------------------------------------------}
  2273. { Read a set between [] }
  2274. function factor_read_set:tnode;
  2275. var
  2276. p1,p2 : tnode;
  2277. lastp,
  2278. buildp : tarrayconstructornode;
  2279. old_allow_array_constructor : boolean;
  2280. begin
  2281. buildp:=nil;
  2282. { be sure that a least one arrayconstructn is used, also for an
  2283. empty [] }
  2284. if token=_RECKKLAMMER then
  2285. buildp:=carrayconstructornode.create(nil,buildp)
  2286. else
  2287. repeat
  2288. { nested array constructors are not allowed, see also tests/webtbs/tw17213.pp }
  2289. old_allow_array_constructor:=allow_array_constructor;
  2290. allow_array_constructor:=false;
  2291. p1:=comp_expr(true,false);
  2292. if try_to_consume(_POINTPOINT) then
  2293. begin
  2294. p2:=comp_expr(true,false);
  2295. p1:=carrayconstructorrangenode.create(p1,p2);
  2296. end;
  2297. { insert at the end of the tree, to get the correct order }
  2298. if not assigned(buildp) then
  2299. begin
  2300. buildp:=carrayconstructornode.create(p1,nil);
  2301. lastp:=buildp;
  2302. end
  2303. else
  2304. begin
  2305. lastp.right:=carrayconstructornode.create(p1,nil);
  2306. lastp:=tarrayconstructornode(lastp.right);
  2307. end;
  2308. allow_array_constructor:=old_allow_array_constructor;
  2309. { there could be more elements }
  2310. until not try_to_consume(_COMMA);
  2311. factor_read_set:=buildp;
  2312. end;
  2313. {---------------------------------------------
  2314. Factor (Main)
  2315. ---------------------------------------------}
  2316. var
  2317. l : longint;
  2318. ic : int64;
  2319. qc : qword;
  2320. p1 : tnode;
  2321. code : integer;
  2322. srsym : tsym;
  2323. srsymtable : TSymtable;
  2324. pd : tprocdef;
  2325. hclassdef : tobjectdef;
  2326. d : bestreal;
  2327. cur : currency;
  2328. hs,hsorg : string;
  2329. hdef : tdef;
  2330. filepos : tfileposinfo;
  2331. callflags : tcallnodeflags;
  2332. again,
  2333. updatefpos,
  2334. nodechanged : boolean;
  2335. begin
  2336. { can't keep a copy of p1 and compare pointers afterwards, because
  2337. p1 may be freed and reallocated in the same place! }
  2338. updatefpos:=false;
  2339. p1:=nil;
  2340. filepos:=current_tokenpos;
  2341. again:=false;
  2342. if token=_ID then
  2343. begin
  2344. again:=true;
  2345. { Handle references to self }
  2346. if (idtoken=_SELF) and
  2347. not(block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) and
  2348. assigned(current_structdef) then
  2349. begin
  2350. p1:=load_self_node;
  2351. consume(_ID);
  2352. again:=true;
  2353. end
  2354. else
  2355. factor_read_id(p1,again);
  2356. if assigned(p1) then
  2357. begin
  2358. { factor_read_id will set the filepos to after the id,
  2359. and in case of _SELF the filepos will already be the
  2360. same as filepos (so setting it again doesn't hurt). }
  2361. p1.fileinfo:=filepos;
  2362. filepos:=current_tokenpos;
  2363. end;
  2364. { handle post fix operators }
  2365. updatefpos:=postfixoperators(p1,again,getaddr);
  2366. end
  2367. else
  2368. begin
  2369. updatefpos:=true;
  2370. case token of
  2371. _RETURN :
  2372. begin
  2373. consume(_RETURN);
  2374. if not(token in [_SEMICOLON,_ELSE,_END]) then
  2375. p1 := cexitnode.create(comp_expr(true,false))
  2376. else
  2377. p1 := cexitnode.create(nil);
  2378. end;
  2379. _INHERITED :
  2380. begin
  2381. again:=true;
  2382. consume(_INHERITED);
  2383. if assigned(current_procinfo) and
  2384. assigned(current_structdef) and
  2385. (current_structdef.typ=objectdef) then
  2386. begin
  2387. { for record helpers in mode Delphi "inherited" is not
  2388. allowed }
  2389. if is_objectpascal_helper(current_structdef) and
  2390. (m_delphi in current_settings.modeswitches) and
  2391. is_record(tobjectdef(current_structdef).extendeddef) then
  2392. Message(parser_e_inherited_not_in_record);
  2393. hclassdef:=tobjectdef(current_structdef).childof;
  2394. { Objective-C categories *replace* methods in the class
  2395. they extend, or add methods to it. So calling an
  2396. inherited method always calls the method inherited from
  2397. the parent of the extended class }
  2398. if is_objccategory(current_structdef) then
  2399. hclassdef:=hclassdef.childof;
  2400. { if inherited; only then we need the method with
  2401. the same name }
  2402. if token <> _ID then
  2403. begin
  2404. hs:=current_procinfo.procdef.procsym.name;
  2405. hsorg:=current_procinfo.procdef.procsym.realname;
  2406. anon_inherited:=true;
  2407. { For message methods we need to search using the message
  2408. number or string }
  2409. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  2410. srdef:=nil;
  2411. if (po_msgint in pd.procoptions) then
  2412. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  2413. else
  2414. if (po_msgstr in pd.procoptions) then
  2415. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  2416. else
  2417. { helpers have their own ways of dealing with inherited }
  2418. if is_objectpascal_helper(current_structdef) then
  2419. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,true)
  2420. else
  2421. searchsym_in_class(hclassdef,tobjectdef(current_structdef),hs,srsym,srsymtable,true);
  2422. end
  2423. else
  2424. begin
  2425. hs:=pattern;
  2426. hsorg:=orgpattern;
  2427. consume(_ID);
  2428. anon_inherited:=false;
  2429. { helpers have their own ways of dealing with inherited }
  2430. if is_objectpascal_helper(current_structdef) then
  2431. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,true)
  2432. else
  2433. searchsym_in_class(hclassdef,tobjectdef(current_structdef),hs,srsym,srsymtable,true);
  2434. end;
  2435. if assigned(srsym) then
  2436. begin
  2437. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2438. { load the procdef from the inherited class and
  2439. not from self }
  2440. case srsym.typ of
  2441. procsym:
  2442. begin
  2443. if is_objectpascal_helper(current_structdef) then
  2444. begin
  2445. { for a helper load the procdef either from the
  2446. extended type, from the parent helper or from
  2447. the extended type of the parent helper
  2448. depending on the def the found symbol belongs
  2449. to }
  2450. if (srsym.Owner.defowner.typ=objectdef) and
  2451. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  2452. if current_structdef.is_related(tdef(srsym.Owner.defowner)) and
  2453. assigned(tobjectdef(current_structdef).childof) then
  2454. hdef:=tobjectdef(current_structdef).childof
  2455. else
  2456. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef
  2457. else
  2458. hdef:=tdef(srsym.Owner.defowner);
  2459. end
  2460. else
  2461. hdef:=hclassdef;
  2462. if (po_classmethod in current_procinfo.procdef.procoptions) or
  2463. (po_staticmethod in current_procinfo.procdef.procoptions) then
  2464. hdef:=tclassrefdef.create(hdef);
  2465. p1:=ctypenode.create(hdef);
  2466. { we need to allow helpers here }
  2467. ttypenode(p1).helperallowed:=true;
  2468. end;
  2469. propertysym:
  2470. ;
  2471. else
  2472. begin
  2473. Message(parser_e_methode_id_expected);
  2474. p1:=cerrornode.create;
  2475. end;
  2476. end;
  2477. callflags:=[cnf_inherited];
  2478. if anon_inherited then
  2479. include(callflags,cnf_anon_inherited);
  2480. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags);
  2481. end
  2482. else
  2483. begin
  2484. if anon_inherited then
  2485. begin
  2486. { For message methods we need to call DefaultHandler }
  2487. if (po_msgint in pd.procoptions) or
  2488. (po_msgstr in pd.procoptions) then
  2489. begin
  2490. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,true);
  2491. if not assigned(srsym) or
  2492. (srsym.typ<>procsym) then
  2493. internalerror(200303171);
  2494. p1:=nil;
  2495. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[]);
  2496. end
  2497. else
  2498. begin
  2499. { we need to ignore the inherited; }
  2500. p1:=cnothingnode.create;
  2501. end;
  2502. end
  2503. else
  2504. begin
  2505. Message1(sym_e_id_no_member,hsorg);
  2506. p1:=cerrornode.create;
  2507. end;
  2508. again:=false;
  2509. end;
  2510. { turn auto inheriting off }
  2511. anon_inherited:=false;
  2512. end
  2513. else
  2514. begin
  2515. { in case of records we use a more clear error message }
  2516. if assigned(current_structdef) and
  2517. (current_structdef.typ=recorddef) then
  2518. Message(parser_e_inherited_not_in_record)
  2519. else
  2520. Message(parser_e_generic_methods_only_in_methods);
  2521. again:=false;
  2522. p1:=cerrornode.create;
  2523. end;
  2524. postfixoperators(p1,again,getaddr);
  2525. end;
  2526. _INTCONST :
  2527. begin
  2528. {Try first wether the value fits in an int64.}
  2529. val(pattern,ic,code);
  2530. if code=0 then
  2531. begin
  2532. consume(_INTCONST);
  2533. int_to_type(ic,hdef);
  2534. p1:=cordconstnode.create(ic,hdef,true);
  2535. end
  2536. else
  2537. begin
  2538. { try qword next }
  2539. val(pattern,qc,code);
  2540. if code=0 then
  2541. begin
  2542. consume(_INTCONST);
  2543. int_to_type(qc,hdef);
  2544. p1:=cordconstnode.create(qc,hdef,true);
  2545. end;
  2546. end;
  2547. if code<>0 then
  2548. begin
  2549. { finally float }
  2550. val(pattern,d,code);
  2551. if code<>0 then
  2552. begin
  2553. Message(parser_e_invalid_integer);
  2554. consume(_INTCONST);
  2555. l:=1;
  2556. p1:=cordconstnode.create(l,sinttype,true);
  2557. end
  2558. else
  2559. begin
  2560. consume(_INTCONST);
  2561. p1:=crealconstnode.create(d,pbestrealtype^);
  2562. end;
  2563. end
  2564. else
  2565. { the necessary range checking has already been done by val }
  2566. tordconstnode(p1).rangecheck:=false;
  2567. end;
  2568. _REALNUMBER :
  2569. begin
  2570. val(pattern,d,code);
  2571. if code<>0 then
  2572. begin
  2573. Message(parser_e_error_in_real);
  2574. d:=1.0;
  2575. end;
  2576. consume(_REALNUMBER);
  2577. {$ifdef FPC_REAL2REAL_FIXED}
  2578. if current_settings.fputype=fpu_none then
  2579. Message(parser_e_unsupported_real);
  2580. if (current_settings.minfpconstprec=s32real) and
  2581. (d = single(d)) then
  2582. p1:=crealconstnode.create(d,s32floattype)
  2583. else if (current_settings.minfpconstprec=s64real) and
  2584. (d = double(d)) then
  2585. p1:=crealconstnode.create(d,s64floattype)
  2586. else
  2587. {$endif FPC_REAL2REAL_FIXED}
  2588. p1:=crealconstnode.create(d,pbestrealtype^);
  2589. {$ifdef FPC_HAS_STR_CURRENCY}
  2590. val(pattern,cur,code);
  2591. if code=0 then
  2592. trealconstnode(p1).value_currency:=cur;
  2593. {$endif FPC_HAS_STR_CURRENCY}
  2594. end;
  2595. _STRING :
  2596. begin
  2597. string_dec(hdef,true);
  2598. { STRING can be also a type cast }
  2599. if try_to_consume(_LKLAMMER) then
  2600. begin
  2601. p1:=comp_expr(true,false);
  2602. consume(_RKLAMMER);
  2603. p1:=ctypeconvnode.create_explicit(p1,hdef);
  2604. { handle postfix operators here e.g. string(a)[10] }
  2605. again:=true;
  2606. postfixoperators(p1,again,getaddr);
  2607. end
  2608. else
  2609. p1:=ctypenode.create(hdef);
  2610. end;
  2611. _FILE :
  2612. begin
  2613. hdef:=cfiletype;
  2614. consume(_FILE);
  2615. { FILE can be also a type cast }
  2616. if try_to_consume(_LKLAMMER) then
  2617. begin
  2618. p1:=comp_expr(true,false);
  2619. consume(_RKLAMMER);
  2620. p1:=ctypeconvnode.create_explicit(p1,hdef);
  2621. { handle postfix operators here e.g. string(a)[10] }
  2622. again:=true;
  2623. postfixoperators(p1,again,getaddr);
  2624. end
  2625. else
  2626. begin
  2627. p1:=ctypenode.create(hdef);
  2628. end;
  2629. end;
  2630. _CSTRING :
  2631. begin
  2632. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern));
  2633. consume(_CSTRING);
  2634. end;
  2635. _CCHAR :
  2636. begin
  2637. p1:=cordconstnode.create(ord(pattern[1]),cchartype,true);
  2638. consume(_CCHAR);
  2639. end;
  2640. _CWSTRING:
  2641. begin
  2642. p1:=cstringconstnode.createwstr(patternw);
  2643. consume(_CWSTRING);
  2644. end;
  2645. _CWCHAR:
  2646. begin
  2647. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  2648. consume(_CWCHAR);
  2649. end;
  2650. _KLAMMERAFFE :
  2651. begin
  2652. consume(_KLAMMERAFFE);
  2653. got_addrn:=true;
  2654. { support both @<x> and @(<x>) }
  2655. if try_to_consume(_LKLAMMER) then
  2656. begin
  2657. p1:=factor(true,false);
  2658. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2659. begin
  2660. again:=true;
  2661. postfixoperators(p1,again,getaddr);
  2662. end
  2663. else
  2664. consume(_RKLAMMER);
  2665. end
  2666. else
  2667. p1:=factor(true,false);
  2668. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2669. begin
  2670. again:=true;
  2671. postfixoperators(p1,again,getaddr);
  2672. end;
  2673. got_addrn:=false;
  2674. p1:=caddrnode.create(p1);
  2675. p1.fileinfo:=filepos;
  2676. if cs_typed_addresses in current_settings.localswitches then
  2677. include(p1.flags,nf_typedaddr);
  2678. { Store the procvar that we are expecting, the
  2679. addrn will use the information to find the correct
  2680. procdef or it will return an error }
  2681. if assigned(getprocvardef) and
  2682. (taddrnode(p1).left.nodetype = loadn) then
  2683. taddrnode(p1).getprocvardef:=getprocvardef;
  2684. end;
  2685. _LKLAMMER :
  2686. begin
  2687. consume(_LKLAMMER);
  2688. p1:=comp_expr(true,false);
  2689. consume(_RKLAMMER);
  2690. { it's not a good solution }
  2691. { but (a+b)^ makes some problems }
  2692. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2693. begin
  2694. again:=true;
  2695. postfixoperators(p1,again,getaddr);
  2696. end;
  2697. end;
  2698. _LECKKLAMMER :
  2699. begin
  2700. consume(_LECKKLAMMER);
  2701. p1:=factor_read_set;
  2702. consume(_RECKKLAMMER);
  2703. end;
  2704. _PLUS :
  2705. begin
  2706. consume(_PLUS);
  2707. p1:=factor(false,false);
  2708. p1:=cunaryplusnode.create(p1);
  2709. end;
  2710. _MINUS :
  2711. begin
  2712. consume(_MINUS);
  2713. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  2714. begin
  2715. { ugly hack, but necessary to be able to parse }
  2716. { -9223372036854775808 as int64 (JM) }
  2717. pattern := '-'+pattern;
  2718. p1:=sub_expr(oppower,false,false,nil);
  2719. { -1 ** 4 should be - (1 ** 4) and not
  2720. (-1) ** 4
  2721. This was the reason of tw0869.pp test failure PM }
  2722. if p1.nodetype=starstarn then
  2723. begin
  2724. if tbinarynode(p1).left.nodetype=ordconstn then
  2725. begin
  2726. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  2727. p1:=cunaryminusnode.create(p1);
  2728. end
  2729. else if tbinarynode(p1).left.nodetype=realconstn then
  2730. begin
  2731. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  2732. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  2733. p1:=cunaryminusnode.create(p1);
  2734. end
  2735. else
  2736. internalerror(20021029);
  2737. end;
  2738. end
  2739. else
  2740. begin
  2741. if m_isolike_unary_minus in current_settings.modeswitches then
  2742. p1:=sub_expr(opmultiply,false,false,nil)
  2743. else
  2744. p1:=sub_expr(oppower,false,false,nil);
  2745. p1:=cunaryminusnode.create(p1);
  2746. end;
  2747. end;
  2748. _OP_NOT :
  2749. begin
  2750. consume(_OP_NOT);
  2751. p1:=factor(false,false);
  2752. p1:=cnotnode.create(p1);
  2753. end;
  2754. _TRUE :
  2755. begin
  2756. consume(_TRUE);
  2757. p1:=cordconstnode.create(1,pasbool8type,false);
  2758. end;
  2759. _FALSE :
  2760. begin
  2761. consume(_FALSE);
  2762. p1:=cordconstnode.create(0,pasbool8type,false);
  2763. end;
  2764. _NIL :
  2765. begin
  2766. consume(_NIL);
  2767. p1:=cnilnode.create;
  2768. { It's really ugly code nil^, but delphi allows it }
  2769. if token in [_CARET] then
  2770. begin
  2771. again:=true;
  2772. postfixoperators(p1,again,getaddr);
  2773. end;
  2774. end;
  2775. _OBJCPROTOCOL:
  2776. begin
  2777. { The @protocol keyword is used in two ways in Objective-C:
  2778. 1) to declare protocols (~ Object Pascal interfaces)
  2779. 2) to obtain the metaclass (~ Object Pascal) "class of")
  2780. of a declared protocol
  2781. This code is for handling the second case. Because of 1),
  2782. we cannot simply use a system unit symbol.
  2783. }
  2784. consume(_OBJCPROTOCOL);
  2785. consume(_LKLAMMER);
  2786. p1:=factor(false,false);
  2787. consume(_RKLAMMER);
  2788. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  2789. end;
  2790. else
  2791. begin
  2792. Message(parser_e_illegal_expression);
  2793. p1:=cerrornode.create;
  2794. { recover }
  2795. consume(token);
  2796. end;
  2797. end;
  2798. end;
  2799. { generate error node if no node is created }
  2800. if not assigned(p1) then
  2801. begin
  2802. {$ifdef EXTDEBUG}
  2803. Comment(V_Warning,'factor: p1=nil');
  2804. {$endif}
  2805. p1:=cerrornode.create;
  2806. updatefpos:=true;
  2807. end;
  2808. { get the resultdef for the node }
  2809. if (not assigned(p1.resultdef)) then
  2810. begin
  2811. do_typecheckpass_changed(p1,nodechanged);
  2812. updatefpos:=updatefpos or nodechanged;
  2813. end;
  2814. if assigned(p1) and
  2815. updatefpos then
  2816. p1.fileinfo:=filepos;
  2817. factor:=p1;
  2818. end;
  2819. {$maxfpuregisters default}
  2820. procedure post_comp_expr_gendef(var def: tdef);
  2821. var
  2822. p1 : tnode;
  2823. again : boolean;
  2824. begin
  2825. if not assigned(def) then
  2826. internalerror(2011053001);
  2827. again:=false;
  2828. { handle potential typecasts, etc }
  2829. p1:=handle_factor_typenode(def,false,again,nil,false);
  2830. { parse postfix operators }
  2831. postfixoperators(p1,again,false);
  2832. if assigned(p1) and (p1.nodetype=typen) then
  2833. def:=ttypenode(p1).typedef
  2834. else
  2835. def:=generrordef;
  2836. end;
  2837. {****************************************************************************
  2838. Sub_Expr
  2839. ****************************************************************************}
  2840. const
  2841. { Warning these stay be ordered !! }
  2842. operator_levels:array[Toperator_precedence] of set of NOTOKEN..last_operator=
  2843. ([_LT,_LTE,_GT,_GTE,_EQ,_NE,_OP_IN],
  2844. [_PLUS,_MINUS,_OP_OR,_PIPE,_OP_XOR],
  2845. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  2846. _OP_AS,_OP_IS,_OP_AND,_AMPERSAND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR],
  2847. [_STARSTAR] );
  2848. function sub_expr(pred_level:Toperator_precedence;accept_equal,typeonly:boolean;factornode:tnode):tnode;
  2849. {Reads a subexpression while the operators are of the current precedence
  2850. level, or any higher level. Replaces the old term, simpl_expr and
  2851. simpl2_expr.}
  2852. function istypenode(n:tnode):boolean;inline;
  2853. { Checks whether the given node is a type node or a VMT node containing a
  2854. typenode. This is used in the code for inline specializations in the
  2855. _LT branch below }
  2856. begin
  2857. result:=assigned(n) and
  2858. (
  2859. (n.nodetype=typen) or
  2860. (
  2861. (n.nodetype=loadvmtaddrn) and
  2862. (tloadvmtaddrnode(n).left.nodetype=typen)
  2863. )
  2864. );
  2865. end;
  2866. function gettypedef(n:tnode):tdef;inline;
  2867. { This returns the typedef that belongs to the given typenode or
  2868. loadvmtaddrnode. n must not be Nil! }
  2869. begin
  2870. if n.nodetype=typen then
  2871. result:=ttypenode(n).typedef
  2872. else
  2873. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  2874. end;
  2875. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  2876. var
  2877. srsymtable : tsymtable;
  2878. begin
  2879. srsym:=nil;
  2880. case n.nodetype of
  2881. typen:
  2882. srsym:=ttypenode(n).typedef.typesym;
  2883. loadvmtaddrn:
  2884. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  2885. loadn:
  2886. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  2887. srsym:=nil;
  2888. { TODO : handle const nodes }
  2889. end;
  2890. result:=assigned(srsym);
  2891. end;
  2892. label
  2893. SubExprStart;
  2894. var
  2895. p1,p2 : tnode;
  2896. oldt : Ttoken;
  2897. filepos : tfileposinfo;
  2898. again : boolean;
  2899. gendef,parseddef : tdef;
  2900. gensym : tsym;
  2901. begin
  2902. SubExprStart:
  2903. if pred_level=highest_precedence then
  2904. begin
  2905. if factornode=nil then
  2906. p1:=factor(false,typeonly)
  2907. else
  2908. p1:=factornode;
  2909. end
  2910. else
  2911. p1:=sub_expr(succ(pred_level),true,typeonly,factornode);
  2912. repeat
  2913. if (token in [NOTOKEN..last_operator]) and
  2914. (token in operator_levels[pred_level]) and
  2915. ((token<>_EQ) or accept_equal) then
  2916. begin
  2917. oldt:=token;
  2918. filepos:=current_tokenpos;
  2919. consume(token);
  2920. if pred_level=highest_precedence then
  2921. p2:=factor(false,false)
  2922. else
  2923. p2:=sub_expr(succ(pred_level),true,typeonly,nil);
  2924. case oldt of
  2925. _PLUS :
  2926. p1:=caddnode.create(addn,p1,p2);
  2927. _MINUS :
  2928. p1:=caddnode.create(subn,p1,p2);
  2929. _STAR :
  2930. p1:=caddnode.create(muln,p1,p2);
  2931. _SLASH :
  2932. p1:=caddnode.create(slashn,p1,p2);
  2933. _EQ:
  2934. p1:=caddnode.create(equaln,p1,p2);
  2935. _GT :
  2936. p1:=caddnode.create(gtn,p1,p2);
  2937. _LT :
  2938. begin
  2939. { we need to decice whether we have an inline specialization
  2940. (type nodes to the left and right of "<", mode Delphi and
  2941. ">" or "," following) or a normal "<" comparison }
  2942. { TODO : p1 could be a non type if e.g. a variable with the
  2943. same name is defined in the same unit where the
  2944. generic is defined (though "same unit" is not
  2945. necessarily needed) }
  2946. if getgenericsym(p1,gensym) and
  2947. { Attention: when nested specializations are supported
  2948. p2 could be a loadn if a "<" follows }
  2949. istypenode(p2) and
  2950. (m_delphi in current_settings.modeswitches) and
  2951. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  2952. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  2953. begin
  2954. { this is an inline specialization }
  2955. { retrieve the defs of two nodes }
  2956. gendef:=nil;
  2957. parseddef:=gettypedef(p2);
  2958. if parseddef.typesym.typ<>typesym then
  2959. Internalerror(2011051001);
  2960. { check the hints for parseddef }
  2961. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg);
  2962. { generate the specialization }
  2963. generate_specialization(gendef,false,'',parseddef,gensym.RealName);
  2964. { we don't need the old left and right nodes anymore }
  2965. p1.Free;
  2966. p2.Free;
  2967. { in case of a class or a record the specialized generic
  2968. is always a classrefdef }
  2969. again:=false;
  2970. { handle potential typecasts, etc }
  2971. p1:=handle_factor_typenode(gendef,false,again,nil,false);
  2972. { parse postfix operators }
  2973. if postfixoperators(p1,again,false) then
  2974. if assigned(p1) then
  2975. p1.fileinfo:=filepos
  2976. else
  2977. p1:=cerrornode.create;
  2978. { with p1 now set we are in reality directly behind the
  2979. call to "factor" thus we need to call down to that
  2980. again }
  2981. { This is disabled until specializations on the right
  2982. hand side work as well, because
  2983. "not working expressions" is better than "half working
  2984. expressions" }
  2985. {factornode:=p1;
  2986. goto SubExprStart;}
  2987. end
  2988. else
  2989. begin
  2990. { this is a normal "<" comparison }
  2991. { potential generic types that are followed by a "<" }
  2992. { a) are not checked whether they are an undefined def,
  2993. but not a generic parameter }
  2994. if (p1.nodetype=typen) and
  2995. (ttypenode(p1).typedef.typ=undefineddef) and
  2996. assigned(ttypenode(p1).typedef.typesym) and
  2997. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  2998. begin
  2999. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  3000. p1.Free;
  3001. p1:=cerrornode.create;
  3002. end;
  3003. { b) don't have their hints checked }
  3004. if istypenode(p1) then
  3005. begin
  3006. gendef:=gettypedef(p1);
  3007. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  3008. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  3009. end;
  3010. { Note: the second part of the expression will be needed
  3011. for nested specializations }
  3012. if istypenode(p2) {and
  3013. not (token in [_LT, _LSHARPBRACKET])} then
  3014. begin
  3015. gendef:=gettypedef(p2);
  3016. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  3017. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  3018. end;
  3019. { create the comparison node for "<" }
  3020. p1:=caddnode.create(ltn,p1,p2)
  3021. end;
  3022. end;
  3023. _GTE :
  3024. p1:=caddnode.create(gten,p1,p2);
  3025. _LTE :
  3026. p1:=caddnode.create(lten,p1,p2);
  3027. _SYMDIF :
  3028. p1:=caddnode.create(symdifn,p1,p2);
  3029. _STARSTAR :
  3030. p1:=caddnode.create(starstarn,p1,p2);
  3031. _OP_AS,
  3032. _OP_IS :
  3033. begin
  3034. if token in [_LT, _LSHARPBRACKET] then
  3035. begin
  3036. { for now we're handling this as a generic declaration;
  3037. there could be cases though (because of operator
  3038. overloading) where this is the wrong decision... }
  3039. { TODO : here the same note as in _LT applies as p2 could
  3040. point to a variable, etc }
  3041. gendef:=gettypedef(p2);
  3042. if gendef.typesym.typ<>typesym then
  3043. Internalerror(2011071401);
  3044. { generate the specialization }
  3045. generate_specialization(gendef,false,'',nil,'');
  3046. { we don't need the old p2 anymore }
  3047. p2.Free;
  3048. again:=false;
  3049. { handle potential typecasts, etc }
  3050. p2:=handle_factor_typenode(gendef,false,again,nil,false);
  3051. { parse postfix operators }
  3052. if postfixoperators(p2,again,false) then
  3053. if assigned(p2) then
  3054. p2.fileinfo:=filepos
  3055. else
  3056. p2:=cerrornode.create;
  3057. { here we don't need to call back down to "factor", thus
  3058. no "goto" }
  3059. end;
  3060. { now generate the "is" or "as" node }
  3061. case oldt of
  3062. _OP_AS:
  3063. p1:=casnode.create(p1,p2);
  3064. _OP_IS:
  3065. p1:=cisnode.create(p1,p2);
  3066. end;
  3067. end;
  3068. _OP_IN :
  3069. p1:=cinnode.create(p1,p2);
  3070. _OP_OR,
  3071. _PIPE {macpas only} :
  3072. begin
  3073. p1:=caddnode.create(orn,p1,p2);
  3074. if (oldt = _PIPE) then
  3075. include(p1.flags,nf_short_bool);
  3076. end;
  3077. _OP_AND,
  3078. _AMPERSAND {macpas only} :
  3079. begin
  3080. p1:=caddnode.create(andn,p1,p2);
  3081. if (oldt = _AMPERSAND) then
  3082. include(p1.flags,nf_short_bool);
  3083. end;
  3084. _OP_DIV :
  3085. p1:=cmoddivnode.create(divn,p1,p2);
  3086. _OP_NOT :
  3087. p1:=cnotnode.create(p1);
  3088. _OP_MOD :
  3089. begin
  3090. p1:=cmoddivnode.create(modn,p1,p2);
  3091. if m_iso in current_settings.modeswitches then
  3092. include(p1.flags,nf_isomod);
  3093. end;
  3094. _OP_SHL :
  3095. p1:=cshlshrnode.create(shln,p1,p2);
  3096. _OP_SHR :
  3097. p1:=cshlshrnode.create(shrn,p1,p2);
  3098. _OP_XOR :
  3099. p1:=caddnode.create(xorn,p1,p2);
  3100. _ASSIGNMENT :
  3101. p1:=cassignmentnode.create(p1,p2);
  3102. _NE :
  3103. p1:=caddnode.create(unequaln,p1,p2);
  3104. end;
  3105. p1.fileinfo:=filepos;
  3106. end
  3107. else
  3108. break;
  3109. until false;
  3110. sub_expr:=p1;
  3111. end;
  3112. function comp_expr(accept_equal,typeonly:boolean):tnode;
  3113. var
  3114. oldafterassignment : boolean;
  3115. p1 : tnode;
  3116. begin
  3117. oldafterassignment:=afterassignment;
  3118. afterassignment:=true;
  3119. p1:=sub_expr(opcompare,accept_equal,typeonly,nil);
  3120. { get the resultdef for this expression }
  3121. if not assigned(p1.resultdef) then
  3122. do_typecheckpass(p1);
  3123. afterassignment:=oldafterassignment;
  3124. comp_expr:=p1;
  3125. end;
  3126. function expr(dotypecheck : boolean) : tnode;
  3127. var
  3128. p1,p2 : tnode;
  3129. filepos : tfileposinfo;
  3130. oldafterassignment,
  3131. updatefpos : boolean;
  3132. begin
  3133. oldafterassignment:=afterassignment;
  3134. p1:=sub_expr(opcompare,true,false,nil);
  3135. { get the resultdef for this expression }
  3136. if not assigned(p1.resultdef) and
  3137. dotypecheck then
  3138. do_typecheckpass(p1);
  3139. filepos:=current_tokenpos;
  3140. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  3141. afterassignment:=true;
  3142. updatefpos:=true;
  3143. case token of
  3144. _POINTPOINT :
  3145. begin
  3146. consume(_POINTPOINT);
  3147. p2:=sub_expr(opcompare,true,false,nil);
  3148. p1:=crangenode.create(p1,p2);
  3149. end;
  3150. _ASSIGNMENT :
  3151. begin
  3152. consume(_ASSIGNMENT);
  3153. if assigned(p1.resultdef) and (p1.resultdef.typ=procvardef) then
  3154. getprocvardef:=tprocvardef(p1.resultdef);
  3155. p2:=sub_expr(opcompare,true,false,nil);
  3156. if assigned(getprocvardef) then
  3157. handle_procvar(getprocvardef,p2);
  3158. getprocvardef:=nil;
  3159. p1:=cassignmentnode.create(p1,p2);
  3160. end;
  3161. _PLUSASN :
  3162. begin
  3163. consume(_PLUSASN);
  3164. p2:=sub_expr(opcompare,true,false,nil);
  3165. p1:=gen_c_style_operator(addn,p1,p2);
  3166. end;
  3167. _MINUSASN :
  3168. begin
  3169. consume(_MINUSASN);
  3170. p2:=sub_expr(opcompare,true,false,nil);
  3171. p1:=gen_c_style_operator(subn,p1,p2);
  3172. end;
  3173. _STARASN :
  3174. begin
  3175. consume(_STARASN );
  3176. p2:=sub_expr(opcompare,true,false,nil);
  3177. p1:=gen_c_style_operator(muln,p1,p2);
  3178. end;
  3179. _SLASHASN :
  3180. begin
  3181. consume(_SLASHASN );
  3182. p2:=sub_expr(opcompare,true,false,nil);
  3183. p1:=gen_c_style_operator(slashn,p1,p2);
  3184. end;
  3185. else
  3186. updatefpos:=false;
  3187. end;
  3188. { get the resultdef for this expression }
  3189. if not assigned(p1.resultdef) and
  3190. dotypecheck then
  3191. do_typecheckpass(p1);
  3192. afterassignment:=oldafterassignment;
  3193. if updatefpos then
  3194. p1.fileinfo:=filepos;
  3195. expr:=p1;
  3196. end;
  3197. function get_intconst:TConstExprInt;
  3198. {Reads an expression, tries to evalute it and check if it is an integer
  3199. constant. Then the constant is returned.}
  3200. var
  3201. p:tnode;
  3202. begin
  3203. result:=0;
  3204. p:=comp_expr(true,false);
  3205. if not codegenerror then
  3206. begin
  3207. if (p.nodetype<>ordconstn) or
  3208. not(is_integer(p.resultdef)) then
  3209. Message(parser_e_illegal_expression)
  3210. else
  3211. result:=tordconstnode(p).value;
  3212. end;
  3213. p.free;
  3214. end;
  3215. function get_stringconst:string;
  3216. {Reads an expression, tries to evaluate it and checks if it is a string
  3217. constant. Then the constant is returned.}
  3218. var
  3219. p:tnode;
  3220. begin
  3221. get_stringconst:='';
  3222. p:=comp_expr(true,false);
  3223. if p.nodetype<>stringconstn then
  3224. begin
  3225. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  3226. get_stringconst:=char(int64(tordconstnode(p).value))
  3227. else
  3228. Message(parser_e_illegal_expression);
  3229. end
  3230. else
  3231. get_stringconst:=strpas(tstringconstnode(p).value_str);
  3232. p.free;
  3233. end;
  3234. end.