2
0

pexpr.pas 125 KB

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