pexpr.pas 160 KB

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