pexpr.pas 130 KB

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