pexpr.pas 150 KB

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