pexpr.pas 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784
  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;
  24. { reads a whole expression }
  25. function expr : tnode;
  26. { reads an expression without assignements and .. }
  27. function comp_expr(accept_equal : boolean):tnode;
  28. { reads an expression without assignments and .., but with
  29. definition syms, specvars }
  30. function comp_expr_in_formal_context(accept_equal : boolean):tnode;
  31. { reads an expression without assignments and .., but with
  32. definition syms and specvars.
  33. Furthermore, for fields of classes/records a csubscriptnode is created,
  34. but the "left" pointer of this node is set to NIL }
  35. function comp_expr_in_formal_context_class_header(
  36. accept_equal : boolean): tnode;
  37. { reads a single factor }
  38. function factor(getaddr : boolean) : tnode;
  39. procedure string_dec(var t: ttype);
  40. procedure symlist_to_node(var p1:tnode;st:tsymtable;pl:tsymlist);
  41. function node_to_symlist(p1:tnode):tsymlist;
  42. function parse_paras(__colon : boolean;end_of_paras : ttoken) : tnode;
  43. { the ID token has to be consumed before calling this function }
  44. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callflags:tcallnodeflags);
  45. function get_intconst:TConstExprInt;
  46. function get_stringconst:string;
  47. implementation
  48. uses
  49. { common }
  50. cutils,
  51. { global }
  52. verbose,
  53. systems,widestr,
  54. { symtable }
  55. symconst,symtable,symsym,defutil,defcmp,
  56. { module }
  57. fmodule,ppu,
  58. { pass 1 }
  59. pass_1,htypechk,
  60. nmat,nadd,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  61. { parser }
  62. scanner,
  63. pbase,pinline,
  64. { codegen }
  65. cgbase,procinfo,cpuinfo
  66. ;
  67. var
  68. { Initially false, is set to true iff the expression is
  69. in a formal context (i.e. within _OPEN_FORMAL and _CLOSE_FORMAL) }
  70. in_formal_context : boolean;
  71. { Initially false, is set to true iff in_formal_context and
  72. we are in a class header (thus in_class_header implies in_formal_context) }
  73. in_class_header : boolean;
  74. { sub_expr(opmultiply) is need to get -1 ** 4 to be
  75. read as - (1**4) and not (-1)**4 PM }
  76. type
  77. Toperator_precedence=(opcompare,opaddition,opmultiply,oppower);
  78. const
  79. highest_precedence = oppower;
  80. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;forward;
  81. const
  82. { true, if the inherited call is anonymous }
  83. anon_inherited : boolean = false;
  84. procedure string_dec(var t: ttype);
  85. { reads a string type with optional length }
  86. { and returns a pointer to the string }
  87. { definition }
  88. var
  89. p : tnode;
  90. begin
  91. t:=cshortstringtype;
  92. consume(_STRING);
  93. if try_to_consume(_LECKKLAMMER) then
  94. begin
  95. p:=comp_expr(true);
  96. if not is_constintnode(p) then
  97. begin
  98. Message(parser_e_illegal_expression);
  99. { error recovery }
  100. consume(_RECKKLAMMER);
  101. end
  102. else
  103. begin
  104. if (tordconstnode(p).value<=0) then
  105. begin
  106. Message(parser_e_invalid_string_size);
  107. tordconstnode(p).value:=255;
  108. end;
  109. consume(_RECKKLAMMER);
  110. if tordconstnode(p).value>255 then
  111. begin
  112. { longstring is currently unsupported (CEC)! }
  113. { t.setdef(tstringdef.createlong(tordconstnode(p).value))}
  114. Message(parser_e_invalid_string_size);
  115. tordconstnode(p).value:=255;
  116. t.setdef(tstringdef.createshort(tordconstnode(p).value));
  117. end
  118. else
  119. if tordconstnode(p).value<>255 then
  120. t.setdef(tstringdef.createshort(tordconstnode(p).value));
  121. end;
  122. p.free;
  123. end
  124. else
  125. begin
  126. if cs_ansistrings in aktlocalswitches then
  127. {$ifdef ansistring_bits}
  128. case aktansistring_bits of
  129. sb_16:
  130. t:=cansistringtype16;
  131. sb_32:
  132. t:=cansistringtype32;
  133. sb_64:
  134. t:=cansistringtype64;
  135. end
  136. {$else}
  137. t:=cansistringtype
  138. {$endif}
  139. else
  140. t:=cshortstringtype;
  141. end;
  142. end;
  143. procedure symlist_to_node(var p1:tnode;st:tsymtable;pl:tsymlist);
  144. var
  145. plist : psymlistitem;
  146. begin
  147. plist:=pl.firstsym;
  148. while assigned(plist) do
  149. begin
  150. case plist^.sltype of
  151. sl_load :
  152. begin
  153. inc(plist^.sym.refs);
  154. if not assigned(st) then
  155. st:=plist^.sym.owner;
  156. { p1 can already contain the loadnode of
  157. the class variable. When there is no tree yet we
  158. may need to load it for with or objects }
  159. if not assigned(p1) then
  160. begin
  161. case st.symtabletype of
  162. withsymtable :
  163. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  164. objectsymtable :
  165. p1:=load_self_node;
  166. end;
  167. end;
  168. if assigned(p1) then
  169. p1:=csubscriptnode.create(plist^.sym,p1)
  170. else
  171. p1:=cloadnode.create(plist^.sym,st);
  172. end;
  173. sl_subscript :
  174. begin
  175. inc(plist^.sym.refs);
  176. p1:=csubscriptnode.create(plist^.sym,p1);
  177. end;
  178. sl_typeconv :
  179. p1:=ctypeconvnode.create_explicit(p1,plist^.tt);
  180. sl_absolutetype :
  181. begin
  182. p1:=ctypeconvnode.create(p1,plist^.tt);
  183. include(p1.flags,nf_absolute);
  184. end;
  185. sl_vec :
  186. p1:=cvecnode.create(p1,cordconstnode.create(plist^.value,plist^.valuett,true));
  187. else
  188. internalerror(200110205);
  189. end;
  190. plist:=plist^.next;
  191. end;
  192. end;
  193. function node_to_symlist(p1:tnode):tsymlist;
  194. var
  195. sl : tsymlist;
  196. procedure addnode(p:tnode);
  197. begin
  198. case p.nodetype of
  199. subscriptn :
  200. begin
  201. addnode(tsubscriptnode(p).left);
  202. sl.addsym(sl_subscript,tsubscriptnode(p).vs);
  203. end;
  204. typeconvn :
  205. begin
  206. addnode(ttypeconvnode(p).left);
  207. if nf_absolute in ttypeconvnode(p).flags then
  208. sl.addtype(sl_absolutetype,ttypeconvnode(p).totype)
  209. else
  210. sl.addtype(sl_typeconv,ttypeconvnode(p).totype);
  211. end;
  212. vecn :
  213. begin
  214. addnode(tvecnode(p).left);
  215. if tvecnode(p).right.nodetype=ordconstn then
  216. sl.addconst(sl_vec,tordconstnode(tvecnode(p).right).value,tvecnode(p).right.resulttype)
  217. else
  218. begin
  219. Message(parser_e_illegal_expression);
  220. { recovery }
  221. sl.addconst(sl_vec,0,tvecnode(p).right.resulttype);
  222. end;
  223. end;
  224. loadn :
  225. sl.addsym(sl_load,tloadnode(p).symtableentry);
  226. else
  227. internalerror(200310282);
  228. end;
  229. end;
  230. begin
  231. sl:=tsymlist.create;
  232. addnode(p1);
  233. result:=sl;
  234. end;
  235. function parse_paras(__colon : boolean;end_of_paras : ttoken) : tnode;
  236. var
  237. p1,p2 : tnode;
  238. prev_in_args : boolean;
  239. old_allow_array_constructor : boolean;
  240. begin
  241. if token=end_of_paras then
  242. begin
  243. parse_paras:=nil;
  244. exit;
  245. end;
  246. { save old values }
  247. prev_in_args:=in_args;
  248. old_allow_array_constructor:=allow_array_constructor;
  249. { set para parsing values }
  250. in_args:=true;
  251. inc(parsing_para_level);
  252. allow_array_constructor:=true;
  253. p2:=nil;
  254. repeat
  255. p1:=comp_expr(true);
  256. p2:=ccallparanode.create(p1,p2);
  257. { it's for the str(l:5,s); }
  258. if __colon and (token=_COLON) then
  259. begin
  260. consume(_COLON);
  261. p1:=comp_expr(true);
  262. p2:=ccallparanode.create(p1,p2);
  263. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  264. if try_to_consume(_COLON) then
  265. begin
  266. p1:=comp_expr(true);
  267. p2:=ccallparanode.create(p1,p2);
  268. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  269. end
  270. end;
  271. until not try_to_consume(_COMMA);
  272. allow_array_constructor:=old_allow_array_constructor;
  273. dec(parsing_para_level);
  274. in_args:=prev_in_args;
  275. parse_paras:=p2;
  276. end;
  277. function gen_c_style_operator(ntyp:tnodetype;p1,p2:tnode) : tnode;
  278. var
  279. hp : tnode;
  280. htype : ttype;
  281. temp : ttempcreatenode;
  282. newstatement : tstatementnode;
  283. begin
  284. { Properties are not allowed, because the write can
  285. be different from the read }
  286. if (nf_isproperty in p1.flags) then
  287. begin
  288. Message(type_e_variable_id_expected);
  289. { We can continue with the loading,
  290. it'll not create errors. Only the expected
  291. result can be wrong }
  292. end;
  293. hp:=p1;
  294. while assigned(hp) and
  295. (hp.nodetype in [derefn,subscriptn,vecn,typeconvn]) do
  296. hp:=tunarynode(hp).left;
  297. if not assigned(hp) then
  298. internalerror(200410121);
  299. if (hp.nodetype=calln) then
  300. begin
  301. resulttypepass(p1);
  302. result:=internalstatements(newstatement);
  303. htype.setdef(tpointerdef.create(p1.resulttype));
  304. temp:=ctempcreatenode.create(htype,sizeof(aint),tt_persistent,false);
  305. addstatement(newstatement,temp);
  306. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),caddrnode.create_internal(p1)));
  307. addstatement(newstatement,cassignmentnode.create(
  308. cderefnode.create(ctemprefnode.create(temp)),
  309. caddnode.create(ntyp,
  310. cderefnode.create(ctemprefnode.create(temp)),
  311. p2)));
  312. addstatement(newstatement,ctempdeletenode.create(temp));
  313. end
  314. else
  315. result:=cassignmentnode.create(p1,caddnode.create(ntyp,p1.getcopy,p2));
  316. end;
  317. function statement_syssym(l : longint) : tnode;
  318. var
  319. p1,p2,paras : tnode;
  320. err,
  321. prev_in_args : boolean;
  322. begin
  323. prev_in_args:=in_args;
  324. case l of
  325. in_new_x :
  326. begin
  327. if afterassignment or in_args then
  328. statement_syssym:=new_function
  329. else
  330. statement_syssym:=new_dispose_statement(true);
  331. end;
  332. in_dispose_x :
  333. begin
  334. statement_syssym:=new_dispose_statement(false);
  335. end;
  336. in_ord_x :
  337. begin
  338. consume(_LKLAMMER);
  339. in_args:=true;
  340. p1:=comp_expr(true);
  341. consume(_RKLAMMER);
  342. p1:=geninlinenode(in_ord_x,false,p1);
  343. statement_syssym := p1;
  344. end;
  345. in_exit :
  346. begin
  347. if try_to_consume(_LKLAMMER) then
  348. begin
  349. if not (m_mac in aktmodeswitches) then
  350. begin
  351. if not(try_to_consume(_RKLAMMER)) then
  352. begin
  353. p1:=comp_expr(true);
  354. consume(_RKLAMMER);
  355. if (block_type=bt_except) then
  356. begin
  357. Message(parser_e_exit_with_argument_not__possible);
  358. { recovery }
  359. p1.free;
  360. p1:=nil;
  361. end
  362. else if (not assigned(current_procinfo) or
  363. is_void(current_procinfo.procdef.rettype.def)) then
  364. begin
  365. Message(parser_e_void_function);
  366. { recovery }
  367. p1.free;
  368. p1:=nil;
  369. end;
  370. end
  371. else
  372. p1:=nil;
  373. end
  374. else
  375. begin
  376. if not (current_procinfo.procdef.procsym.name = pattern) then
  377. Message(parser_e_macpas_exit_wrong_param);
  378. consume(_ID);
  379. consume(_RKLAMMER);
  380. p1:=nil;
  381. end
  382. end
  383. else
  384. p1:=nil;
  385. statement_syssym:=cexitnode.create(p1);
  386. end;
  387. in_break :
  388. begin
  389. if not (m_mac in aktmodeswitches) then
  390. statement_syssym:=cbreaknode.create
  391. else
  392. begin
  393. Message1(sym_e_id_not_found, orgpattern);
  394. statement_syssym:=cerrornode.create;
  395. end;
  396. end;
  397. in_continue :
  398. begin
  399. if not (m_mac in aktmodeswitches) then
  400. statement_syssym:=ccontinuenode.create
  401. else
  402. begin
  403. Message1(sym_e_id_not_found, orgpattern);
  404. statement_syssym:=cerrornode.create;
  405. end;
  406. end;
  407. in_leave :
  408. begin
  409. if m_mac in aktmodeswitches then
  410. statement_syssym:=cbreaknode.create
  411. else
  412. begin
  413. Message1(sym_e_id_not_found, orgpattern);
  414. statement_syssym:=cerrornode.create;
  415. end;
  416. end;
  417. in_cycle :
  418. begin
  419. if m_mac in aktmodeswitches then
  420. statement_syssym:=ccontinuenode.create
  421. else
  422. begin
  423. Message1(sym_e_id_not_found, orgpattern);
  424. statement_syssym:=cerrornode.create;
  425. end;
  426. end;
  427. in_typeof_x :
  428. begin
  429. consume(_LKLAMMER);
  430. in_args:=true;
  431. p1:=comp_expr(true);
  432. consume(_RKLAMMER);
  433. if p1.nodetype=typen then
  434. ttypenode(p1).allowed:=true;
  435. { Allow classrefdef, which is required for
  436. Typeof(self) in static class methods }
  437. if (p1.resulttype.def.deftype = objectdef) or
  438. (assigned(current_procinfo) and
  439. ((po_classmethod in current_procinfo.procdef.procoptions) or
  440. (po_staticmethod in current_procinfo.procdef.procoptions)) and
  441. (p1.resulttype.def.deftype=classrefdef)) then
  442. statement_syssym:=geninlinenode(in_typeof_x,false,p1)
  443. else
  444. begin
  445. Message(parser_e_class_id_expected);
  446. p1.destroy;
  447. statement_syssym:=cerrornode.create;
  448. end;
  449. end;
  450. in_sizeof_x :
  451. begin
  452. consume(_LKLAMMER);
  453. in_args:=true;
  454. p1:=comp_expr(true);
  455. consume(_RKLAMMER);
  456. if (p1.nodetype<>typen) and
  457. (
  458. (is_object(p1.resulttype.def) and
  459. (oo_has_constructor in tobjectdef(p1.resulttype.def).objectoptions)) or
  460. is_open_array(p1.resulttype.def) or
  461. is_array_of_const(p1.resulttype.def) or
  462. is_open_string(p1.resulttype.def)
  463. ) then
  464. statement_syssym:=geninlinenode(in_sizeof_x,false,p1)
  465. else
  466. begin
  467. statement_syssym:=cordconstnode.create(p1.resulttype.def.size,sinttype,true);
  468. { p1 not needed !}
  469. p1.destroy;
  470. end;
  471. end;
  472. in_typeinfo_x :
  473. begin
  474. consume(_LKLAMMER);
  475. in_args:=true;
  476. p1:=comp_expr(true);
  477. { When reading a class type it is parsed as loadvmtaddrn,
  478. typeinfo only needs the type so we remove the loadvmtaddrn }
  479. if p1.nodetype=loadvmtaddrn then
  480. begin
  481. p2:=tloadvmtaddrnode(p1).left;
  482. tloadvmtaddrnode(p1).left:=nil;
  483. p1.free;
  484. p1:=p2;
  485. end;
  486. if p1.nodetype=typen then
  487. ttypenode(p1).allowed:=true
  488. else
  489. begin
  490. p1.destroy;
  491. p1:=cerrornode.create;
  492. Message(parser_e_illegal_parameter_list);
  493. end;
  494. consume(_RKLAMMER);
  495. p2:=geninlinenode(in_typeinfo_x,false,p1);
  496. statement_syssym:=p2;
  497. end;
  498. in_assigned_x :
  499. begin
  500. err:=false;
  501. consume(_LKLAMMER);
  502. in_args:=true;
  503. p1:=comp_expr(true);
  504. { When reading a class type it is parsed as loadvmtaddrn,
  505. typeinfo only needs the type so we remove the loadvmtaddrn }
  506. if p1.nodetype=loadvmtaddrn then
  507. begin
  508. p2:=tloadvmtaddrnode(p1).left;
  509. tloadvmtaddrnode(p1).left:=nil;
  510. p1.free;
  511. p1:=p2;
  512. end;
  513. if not codegenerror then
  514. begin
  515. case p1.resulttype.def.deftype of
  516. procdef, { procvar }
  517. pointerdef,
  518. procvardef,
  519. classrefdef : ;
  520. objectdef :
  521. if not is_class_or_interface(p1.resulttype.def) then
  522. begin
  523. Message(parser_e_illegal_parameter_list);
  524. err:=true;
  525. end;
  526. arraydef :
  527. if not is_dynamic_array(p1.resulttype.def) then
  528. begin
  529. Message(parser_e_illegal_parameter_list);
  530. err:=true;
  531. end;
  532. else
  533. begin
  534. Message(parser_e_illegal_parameter_list);
  535. err:=true;
  536. end;
  537. end;
  538. end
  539. else
  540. err:=true;
  541. if not err then
  542. begin
  543. p2:=ccallparanode.create(p1,nil);
  544. p2:=geninlinenode(in_assigned_x,false,p2);
  545. end
  546. else
  547. begin
  548. p1.free;
  549. p2:=cerrornode.create;
  550. end;
  551. consume(_RKLAMMER);
  552. statement_syssym:=p2;
  553. end;
  554. in_addr_x :
  555. begin
  556. consume(_LKLAMMER);
  557. in_args:=true;
  558. p1:=comp_expr(true);
  559. p1:=caddrnode.create(p1);
  560. if cs_typed_addresses in aktlocalswitches then
  561. include(p1.flags,nf_typedaddr);
  562. consume(_RKLAMMER);
  563. statement_syssym:=p1;
  564. end;
  565. in_ofs_x :
  566. begin
  567. consume(_LKLAMMER);
  568. in_args:=true;
  569. p1:=comp_expr(true);
  570. p1:=caddrnode.create(p1);
  571. do_resulttypepass(p1);
  572. { Ofs() returns a cardinal/qword, not a pointer }
  573. p1.resulttype:=uinttype;
  574. consume(_RKLAMMER);
  575. statement_syssym:=p1;
  576. end;
  577. in_seg_x :
  578. begin
  579. consume(_LKLAMMER);
  580. in_args:=true;
  581. p1:=comp_expr(true);
  582. p1:=geninlinenode(in_seg_x,false,p1);
  583. consume(_RKLAMMER);
  584. statement_syssym:=p1;
  585. end;
  586. in_high_x,
  587. in_low_x :
  588. begin
  589. consume(_LKLAMMER);
  590. in_args:=true;
  591. p1:=comp_expr(true);
  592. p2:=geninlinenode(l,false,p1);
  593. consume(_RKLAMMER);
  594. statement_syssym:=p2;
  595. end;
  596. in_succ_x,
  597. in_pred_x :
  598. begin
  599. consume(_LKLAMMER);
  600. in_args:=true;
  601. p1:=comp_expr(true);
  602. p2:=geninlinenode(l,false,p1);
  603. consume(_RKLAMMER);
  604. statement_syssym:=p2;
  605. end;
  606. in_inc_x,
  607. in_dec_x :
  608. begin
  609. consume(_LKLAMMER);
  610. in_args:=true;
  611. p1:=comp_expr(true);
  612. if try_to_consume(_COMMA) then
  613. p2:=ccallparanode.create(comp_expr(true),nil)
  614. else
  615. p2:=nil;
  616. p2:=ccallparanode.create(p1,p2);
  617. statement_syssym:=geninlinenode(l,false,p2);
  618. consume(_RKLAMMER);
  619. end;
  620. in_slice_x:
  621. begin
  622. if not(in_args) then
  623. begin
  624. message(parser_e_illegal_slice);
  625. consume(_LKLAMMER);
  626. in_args:=true;
  627. comp_expr(true).free;
  628. if try_to_consume(_COMMA) then
  629. comp_expr(true).free;
  630. statement_syssym:=cerrornode.create;
  631. consume(_RKLAMMER);
  632. end
  633. else
  634. begin
  635. consume(_LKLAMMER);
  636. in_args:=true;
  637. p1:=comp_expr(true);
  638. Consume(_COMMA);
  639. if not(codegenerror) then
  640. p2:=ccallparanode.create(comp_expr(true),nil)
  641. else
  642. p2:=cerrornode.create;
  643. p2:=ccallparanode.create(p1,p2);
  644. statement_syssym:=geninlinenode(l,false,p2);
  645. consume(_RKLAMMER);
  646. end;
  647. end;
  648. in_initialize_x:
  649. begin
  650. statement_syssym:=inline_initialize;
  651. end;
  652. in_finalize_x:
  653. begin
  654. statement_syssym:=inline_finalize;
  655. end;
  656. in_copy_x:
  657. begin
  658. statement_syssym:=inline_copy;
  659. end;
  660. in_concat_x :
  661. begin
  662. consume(_LKLAMMER);
  663. in_args:=true;
  664. { Translate to x:=x+y[+z]. The addnode will do the
  665. type checking }
  666. p2:=nil;
  667. repeat
  668. p1:=comp_expr(true);
  669. if p2<>nil then
  670. p2:=caddnode.create(addn,p2,p1)
  671. else
  672. begin
  673. { Force string type if it isn't yet }
  674. if not(
  675. (p1.resulttype.def.deftype=stringdef) or
  676. is_chararray(p1.resulttype.def) or
  677. is_char(p1.resulttype.def)
  678. ) then
  679. inserttypeconv(p1,cshortstringtype);
  680. p2:=p1;
  681. end;
  682. until not try_to_consume(_COMMA);
  683. consume(_RKLAMMER);
  684. statement_syssym:=p2;
  685. end;
  686. in_read_x,
  687. in_readln_x :
  688. begin
  689. if try_to_consume(_LKLAMMER) then
  690. begin
  691. paras:=parse_paras(false,_RKLAMMER);
  692. consume(_RKLAMMER);
  693. end
  694. else
  695. paras:=nil;
  696. p1:=geninlinenode(l,false,paras);
  697. statement_syssym := p1;
  698. end;
  699. in_setlength_x:
  700. begin
  701. statement_syssym := inline_setlength;
  702. end;
  703. in_length_x:
  704. begin
  705. consume(_LKLAMMER);
  706. in_args:=true;
  707. p1:=comp_expr(true);
  708. p2:=geninlinenode(l,false,p1);
  709. consume(_RKLAMMER);
  710. statement_syssym:=p2;
  711. end;
  712. in_write_x,
  713. in_writeln_x :
  714. begin
  715. if try_to_consume(_LKLAMMER) then
  716. begin
  717. paras:=parse_paras(true,_RKLAMMER);
  718. consume(_RKLAMMER);
  719. end
  720. else
  721. paras:=nil;
  722. p1 := geninlinenode(l,false,paras);
  723. statement_syssym := p1;
  724. end;
  725. in_str_x_string :
  726. begin
  727. consume(_LKLAMMER);
  728. paras:=parse_paras(true,_RKLAMMER);
  729. consume(_RKLAMMER);
  730. p1 := geninlinenode(l,false,paras);
  731. statement_syssym := p1;
  732. end;
  733. in_val_x:
  734. Begin
  735. consume(_LKLAMMER);
  736. in_args := true;
  737. p1:= ccallparanode.create(comp_expr(true), nil);
  738. consume(_COMMA);
  739. p2 := ccallparanode.create(comp_expr(true),p1);
  740. if try_to_consume(_COMMA) then
  741. p2 := ccallparanode.create(comp_expr(true),p2);
  742. consume(_RKLAMMER);
  743. p2 := geninlinenode(l,false,p2);
  744. statement_syssym := p2;
  745. End;
  746. in_include_x_y,
  747. in_exclude_x_y :
  748. begin
  749. consume(_LKLAMMER);
  750. in_args:=true;
  751. p1:=comp_expr(true);
  752. consume(_COMMA);
  753. p2:=comp_expr(true);
  754. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  755. consume(_RKLAMMER);
  756. end;
  757. in_assert_x_y :
  758. begin
  759. consume(_LKLAMMER);
  760. in_args:=true;
  761. p1:=comp_expr(true);
  762. if try_to_consume(_COMMA) then
  763. p2:=comp_expr(true)
  764. else
  765. begin
  766. { then insert an empty string }
  767. p2:=cstringconstnode.createstr('',st_default);
  768. end;
  769. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  770. consume(_RKLAMMER);
  771. end;
  772. else
  773. internalerror(15);
  774. end;
  775. in_args:=prev_in_args;
  776. end;
  777. function maybe_load_methodpointer(st:tsymtable;var p1:tnode):boolean;
  778. begin
  779. maybe_load_methodpointer:=false;
  780. if not assigned(p1) then
  781. begin
  782. case st.symtabletype of
  783. withsymtable :
  784. begin
  785. if (st.defowner.deftype=objectdef) then
  786. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  787. end;
  788. objectsymtable :
  789. begin
  790. p1:=load_self_node;
  791. { We are calling a member }
  792. maybe_load_methodpointer:=true;
  793. end;
  794. end;
  795. end;
  796. end;
  797. { reads the parameter for a subroutine call }
  798. procedure do_proc_call(sym:tsym;st:tsymtable;obj:tobjectdef;getaddr:boolean;var again : boolean;var p1:tnode;callflags:tcallnodeflags);
  799. var
  800. membercall,
  801. prevafterassn : boolean;
  802. i : integer;
  803. para,p2 : tnode;
  804. currpara : tparavarsym;
  805. aprocdef : tprocdef;
  806. begin
  807. prevafterassn:=afterassignment;
  808. afterassignment:=false;
  809. membercall:=false;
  810. aprocdef:=nil;
  811. { when it is a call to a member we need to load the
  812. methodpointer first }
  813. membercall:=maybe_load_methodpointer(st,p1);
  814. { When we are expecting a procvar we also need
  815. to get the address in some cases }
  816. if assigned(getprocvardef) then
  817. begin
  818. if (block_type=bt_const) or
  819. getaddr then
  820. begin
  821. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  822. getaddr:=true;
  823. end
  824. else
  825. if (m_tp_procvar in aktmodeswitches) or
  826. (m_mac_procvar in aktmodeswitches) then
  827. begin
  828. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  829. if assigned(aprocdef) then
  830. getaddr:=true;
  831. end;
  832. end;
  833. { only need to get the address of the procedure? }
  834. if getaddr then
  835. begin
  836. { Retrieve info which procvar to call. For tp_procvar the
  837. aprocdef is already loaded above so we can reuse it }
  838. if not assigned(aprocdef) and
  839. assigned(getprocvardef) then
  840. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  841. { generate a methodcallnode or proccallnode }
  842. { we shouldn't convert things like @tcollection.load }
  843. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  844. if assigned(p1) then
  845. begin
  846. { for loading methodpointer of an inherited function
  847. we use self as instance and load the address of
  848. the function directly and not through the vmt (PFV) }
  849. if (cnf_inherited in callflags) then
  850. begin
  851. include(p2.flags,nf_inherited);
  852. p1.free;
  853. p1:=load_self_node;
  854. end;
  855. if (p1.nodetype<>typen) then
  856. tloadnode(p2).set_mp(p1)
  857. else
  858. p1.free;
  859. end;
  860. p1:=p2;
  861. { no postfix operators }
  862. again:=false;
  863. end
  864. else
  865. begin
  866. para:=nil;
  867. if anon_inherited then
  868. begin
  869. if not assigned(current_procinfo) then
  870. internalerror(200305054);
  871. for i:=0 to current_procinfo.procdef.paras.count-1 do
  872. begin
  873. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  874. if not(vo_is_hidden_para in currpara.varoptions) then
  875. para:=ccallparanode.create(cloadnode.create(currpara,currpara.owner),para);
  876. end;
  877. end
  878. else
  879. begin
  880. if try_to_consume(_LKLAMMER) then
  881. begin
  882. para:=parse_paras(false,_RKLAMMER);
  883. consume(_RKLAMMER);
  884. end;
  885. end;
  886. { indicate if this call was generated by a member and
  887. no explicit self is used, this is needed to determine
  888. how to handle a destructor call (PFV) }
  889. if membercall then
  890. include(callflags,cnf_member_call);
  891. if assigned(obj) then
  892. begin
  893. if (st.symtabletype<>objectsymtable) then
  894. internalerror(200310031);
  895. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1,callflags);
  896. end
  897. else
  898. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags);
  899. end;
  900. afterassignment:=prevafterassn;
  901. end;
  902. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  903. var
  904. hp,hp2 : tnode;
  905. hpp : ^tnode;
  906. currprocdef : tprocdef;
  907. begin
  908. if not assigned(pv) then
  909. internalerror(200301121);
  910. if (m_tp_procvar in aktmodeswitches) or
  911. (m_mac_procvar in aktmodeswitches) then
  912. begin
  913. hp:=p2;
  914. hpp:=@p2;
  915. while assigned(hp) and
  916. (hp.nodetype=typeconvn) do
  917. begin
  918. hp:=ttypeconvnode(hp).left;
  919. { save orignal address of the old tree so we can replace the node }
  920. hpp:=@hp;
  921. end;
  922. if (hp.nodetype=calln) and
  923. { a procvar can't have parameters! }
  924. not assigned(tcallnode(hp).left) then
  925. begin
  926. currprocdef:=tcallnode(hp).symtableprocentry.search_procdef_byprocvardef(pv);
  927. if assigned(currprocdef) then
  928. begin
  929. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  930. if (po_methodpointer in pv.procoptions) then
  931. tloadnode(hp2).set_mp(tcallnode(hp).get_load_methodpointer);
  932. hp.destroy;
  933. { replace the old callnode with the new loadnode }
  934. hpp^:=hp2;
  935. end;
  936. end;
  937. end;
  938. end;
  939. { the following procedure handles the access to a property symbol }
  940. procedure handle_propertysym(sym : tsym;st : tsymtable;var p1 : tnode);
  941. var
  942. paras : tnode;
  943. p2 : tnode;
  944. membercall : boolean;
  945. callflags : tcallnodeflags;
  946. begin
  947. paras:=nil;
  948. { property parameters? read them only if the property really }
  949. { has parameters }
  950. if (ppo_hasparameters in tpropertysym(sym).propoptions) then
  951. begin
  952. if try_to_consume(_LECKKLAMMER) then
  953. begin
  954. paras:=parse_paras(false,_RECKKLAMMER);
  955. consume(_RECKKLAMMER);
  956. end;
  957. end;
  958. { indexed property }
  959. if (ppo_indexed in tpropertysym(sym).propoptions) then
  960. begin
  961. p2:=cordconstnode.create(tpropertysym(sym).index,tpropertysym(sym).indextype,true);
  962. paras:=ccallparanode.create(p2,paras);
  963. end;
  964. { we need only a write property if a := follows }
  965. { if not(afterassignment) and not(in_args) then }
  966. if token=_ASSIGNMENT then
  967. begin
  968. { write property: }
  969. if not tpropertysym(sym).writeaccess.empty then
  970. begin
  971. case tpropertysym(sym).writeaccess.firstsym^.sym.typ of
  972. procsym :
  973. begin
  974. callflags:=[];
  975. { generate the method call }
  976. membercall:=maybe_load_methodpointer(st,p1);
  977. if membercall then
  978. include(callflags,cnf_member_call);
  979. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).writeaccess.firstsym^.sym),st,p1,callflags);
  980. inc(tpropertysym(sym).writeaccess.firstsym^.sym.refs);
  981. paras:=nil;
  982. consume(_ASSIGNMENT);
  983. { read the expression }
  984. if tpropertysym(sym).proptype.def.deftype=procvardef then
  985. getprocvardef:=tprocvardef(tpropertysym(sym).proptype.def);
  986. p2:=comp_expr(true);
  987. if assigned(getprocvardef) then
  988. handle_procvar(getprocvardef,p2);
  989. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  990. { mark as property, both the tcallnode and the real call block }
  991. include(p1.flags,nf_isproperty);
  992. getprocvardef:=nil;
  993. end;
  994. fieldvarsym :
  995. begin
  996. { generate access code }
  997. symlist_to_node(p1,st,tpropertysym(sym).writeaccess);
  998. include(p1.flags,nf_isproperty);
  999. consume(_ASSIGNMENT);
  1000. { read the expression }
  1001. p2:=comp_expr(true);
  1002. p1:=cassignmentnode.create(p1,p2);
  1003. end
  1004. else
  1005. begin
  1006. p1:=cerrornode.create;
  1007. Message(parser_e_no_procedure_to_access_property);
  1008. end;
  1009. end;
  1010. end
  1011. else
  1012. begin
  1013. p1:=cerrornode.create;
  1014. Message(parser_e_no_procedure_to_access_property);
  1015. end;
  1016. end
  1017. else
  1018. begin
  1019. { read property: }
  1020. if not tpropertysym(sym).readaccess.empty then
  1021. begin
  1022. case tpropertysym(sym).readaccess.firstsym^.sym.typ of
  1023. fieldvarsym :
  1024. begin
  1025. { generate access code }
  1026. symlist_to_node(p1,st,tpropertysym(sym).readaccess);
  1027. include(p1.flags,nf_isproperty);
  1028. end;
  1029. procsym :
  1030. begin
  1031. callflags:=[];
  1032. { generate the method call }
  1033. membercall:=maybe_load_methodpointer(st,p1);
  1034. if membercall then
  1035. include(callflags,cnf_member_call);
  1036. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).readaccess.firstsym^.sym),st,p1,callflags);
  1037. paras:=nil;
  1038. include(p1.flags,nf_isproperty);
  1039. end
  1040. else
  1041. begin
  1042. p1:=cerrornode.create;
  1043. Message(type_e_mismatch);
  1044. end;
  1045. end;
  1046. end
  1047. else
  1048. begin
  1049. { error, no function to read property }
  1050. p1:=cerrornode.create;
  1051. Message(parser_e_no_procedure_to_access_property);
  1052. end;
  1053. end;
  1054. { release paras if not used }
  1055. if assigned(paras) then
  1056. paras.free;
  1057. end;
  1058. { the ID token has to be consumed before calling this function }
  1059. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callflags:tcallnodeflags);
  1060. var
  1061. static_name : string;
  1062. isclassref : boolean;
  1063. srsymtable : tsymtable;
  1064. begin
  1065. if sym=nil then
  1066. begin
  1067. { pattern is still valid unless
  1068. there is another ID just after the ID of sym }
  1069. Message1(sym_e_id_no_member,orgpattern);
  1070. p1.free;
  1071. p1:=cerrornode.create;
  1072. { try to clean up }
  1073. again:=false;
  1074. end
  1075. else
  1076. begin
  1077. if assigned(p1) then
  1078. begin
  1079. if not assigned(p1.resulttype.def) then
  1080. do_resulttypepass(p1);
  1081. isclassref:=(p1.resulttype.def.deftype=classrefdef);
  1082. end
  1083. else
  1084. isclassref:=false;
  1085. { we assume, that only procsyms and varsyms are in an object }
  1086. { symbol table, for classes, properties are allowed }
  1087. case sym.typ of
  1088. procsym:
  1089. begin
  1090. do_proc_call(sym,sym.owner,classh,
  1091. (getaddr and not(token in [_CARET,_POINT])),
  1092. again,p1,callflags);
  1093. { we need to know which procedure is called }
  1094. do_resulttypepass(p1);
  1095. { calling using classref? }
  1096. if isclassref and
  1097. (p1.nodetype=calln) and
  1098. assigned(tcallnode(p1).procdefinition) and
  1099. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1100. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1101. Message(parser_e_only_class_methods_via_class_ref);
  1102. end;
  1103. fieldvarsym:
  1104. begin
  1105. if (sp_static in sym.symoptions) then
  1106. begin
  1107. static_name:=lower(sym.owner.name^)+'_'+sym.name;
  1108. searchsym(static_name,sym,srsymtable);
  1109. if assigned(sym) then
  1110. check_hints(sym,sym.symoptions);
  1111. p1.free;
  1112. p1:=cloadnode.create(sym,srsymtable);
  1113. end
  1114. else
  1115. begin
  1116. if isclassref then
  1117. Message(parser_e_only_class_methods_via_class_ref);
  1118. p1:=csubscriptnode.create(sym,p1);
  1119. end;
  1120. end;
  1121. propertysym:
  1122. begin
  1123. if isclassref then
  1124. Message(parser_e_only_class_methods_via_class_ref);
  1125. handle_propertysym(sym,sym.owner,p1);
  1126. end;
  1127. else internalerror(16);
  1128. end;
  1129. end;
  1130. end;
  1131. {****************************************************************************
  1132. Factor
  1133. ****************************************************************************}
  1134. {$ifdef fpc}
  1135. {$maxfpuregisters 0}
  1136. {$endif fpc}
  1137. function factor(getaddr : boolean) : tnode;
  1138. {---------------------------------------------
  1139. Factor_read_id
  1140. ---------------------------------------------}
  1141. procedure factor_read_id(var p1:tnode;var again:boolean);
  1142. var
  1143. pc : pchar;
  1144. len : longint;
  1145. srsym : tsym;
  1146. possible_error : boolean;
  1147. srsymtable : tsymtable;
  1148. storesymtablestack : tsymtable;
  1149. htype : ttype;
  1150. static_name : string;
  1151. begin
  1152. { allow post fix operators }
  1153. again:=true;
  1154. consume_sym(srsym,srsymtable);
  1155. { Access to funcret or need to call the function? }
  1156. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  1157. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  1158. (
  1159. (token=_LKLAMMER) or
  1160. (
  1161. (
  1162. (m_tp7 in aktmodeswitches) or
  1163. (m_delphi in aktmodeswitches)
  1164. ) and
  1165. (afterassignment or in_args) and
  1166. not(vo_is_result in tabstractvarsym(srsym).varoptions)
  1167. )
  1168. ) then
  1169. begin
  1170. storesymtablestack:=symtablestack;
  1171. symtablestack:=srsym.owner.next;
  1172. searchsym(srsym.name,srsym,srsymtable);
  1173. if not assigned(srsym) then
  1174. srsym:=generrorsym;
  1175. if (srsym.typ<>procsym) then
  1176. Message(parser_e_illegal_expression);
  1177. symtablestack:=storesymtablestack;
  1178. end;
  1179. begin
  1180. case srsym.typ of
  1181. absolutevarsym :
  1182. begin
  1183. if (tabsolutevarsym(srsym).abstyp=tovar) then
  1184. begin
  1185. p1:=nil;
  1186. symlist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  1187. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vartype);
  1188. include(p1.flags,nf_absolute);
  1189. end
  1190. else
  1191. p1:=cloadnode.create(srsym,srsymtable);
  1192. end;
  1193. definitionsym:
  1194. begin
  1195. if not in_formal_context then
  1196. begin
  1197. p1:=cerrornode.create;
  1198. Message(parser_e_illegal_expression);
  1199. end
  1200. else
  1201. p1:=tdefinitionsym(srsym).expr.getcopy
  1202. end;
  1203. globalvarsym,
  1204. localvarsym,
  1205. paravarsym,
  1206. fieldvarsym :
  1207. begin
  1208. if (srsym is tspecvarsym) and not in_formal_context then
  1209. begin
  1210. p1:=cerrornode.create;
  1211. Message(parser_e_illegal_expression);
  1212. end
  1213. else
  1214. begin
  1215. if (sp_static in srsym.symoptions) then
  1216. begin
  1217. static_name:=lower(srsym.owner.name^)+'_'+srsym.name;
  1218. searchsym(static_name,srsym,srsymtable);
  1219. if assigned(srsym) then
  1220. check_hints(srsym,srsym.symoptions);
  1221. end
  1222. else
  1223. begin
  1224. { are we in a class method, we check here the
  1225. srsymtable, because a field in another object
  1226. also has objectsymtable. And withsymtable is
  1227. not possible for self in class methods (PFV) }
  1228. if (srsymtable.symtabletype=objectsymtable) and
  1229. assigned(current_procinfo) and
  1230. (po_classmethod in current_procinfo.procdef.procoptions) then
  1231. Message(parser_e_only_class_methods);
  1232. end;
  1233. case srsymtable.symtabletype of
  1234. objectsymtable :
  1235. begin
  1236. if in_class_header then
  1237. p1:=csubscriptnode.create(srsym,nil)
  1238. else
  1239. p1:=csubscriptnode.create(srsym,load_self_node);
  1240. node_tree_set_filepos(p1,aktfilepos);
  1241. end;
  1242. withsymtable :
  1243. begin
  1244. p1:=csubscriptnode.create(srsym,tnode(twithsymtable(srsymtable).withrefnode).getcopy);
  1245. node_tree_set_filepos(p1,aktfilepos);
  1246. end;
  1247. else
  1248. p1:=cloadnode.create(srsym,srsymtable);
  1249. end;
  1250. end;
  1251. end;
  1252. typedconstsym :
  1253. begin
  1254. p1:=cloadnode.create(srsym,srsymtable);
  1255. end;
  1256. syssym :
  1257. begin
  1258. p1:=statement_syssym(tsyssym(srsym).number);
  1259. end;
  1260. typesym :
  1261. begin
  1262. htype.setsym(srsym);
  1263. if not assigned(htype.def) then
  1264. begin
  1265. again:=false;
  1266. end
  1267. else
  1268. begin
  1269. { We need to know if this unit uses Variants }
  1270. if (htype.def=cvarianttype.def) and
  1271. not(cs_compilesystem in aktmoduleswitches) then
  1272. current_module.flags:=current_module.flags or uf_uses_variants;
  1273. if try_to_consume(_LKLAMMER) then
  1274. begin
  1275. p1:=comp_expr(true);
  1276. consume(_RKLAMMER);
  1277. p1:=ctypeconvnode.create_explicit(p1,htype);
  1278. end
  1279. else { not LKLAMMER }
  1280. if (token=_POINT) and
  1281. is_object(htype.def) then
  1282. begin
  1283. consume(_POINT);
  1284. if assigned(current_procinfo) and
  1285. assigned(current_procinfo.procdef._class) and
  1286. not(getaddr) then
  1287. begin
  1288. if current_procinfo.procdef._class.is_related(tobjectdef(htype.def)) then
  1289. begin
  1290. p1:=ctypenode.create(htype);
  1291. { search also in inherited methods }
  1292. srsym:=searchsym_in_class(tobjectdef(htype.def),pattern);
  1293. if assigned(srsym) then
  1294. check_hints(srsym,srsym.symoptions);
  1295. consume(_ID);
  1296. do_member_read(tobjectdef(htype.def),false,srsym,p1,again,[]);
  1297. end
  1298. else
  1299. begin
  1300. Message(parser_e_no_super_class);
  1301. again:=false;
  1302. end;
  1303. end
  1304. else
  1305. begin
  1306. { allows @TObject.Load }
  1307. { also allows static methods and variables }
  1308. p1:=ctypenode.create(htype);
  1309. { TP allows also @TMenu.Load if Load is only }
  1310. { defined in an anchestor class }
  1311. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1312. if assigned(srsym) then
  1313. begin
  1314. check_hints(srsym,srsym.symoptions);
  1315. if not(getaddr) and not(sp_static in srsym.symoptions) then
  1316. Message(sym_e_only_static_in_static)
  1317. else
  1318. begin
  1319. consume(_ID);
  1320. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1321. end;
  1322. end
  1323. else
  1324. Message1(sym_e_id_no_member,orgpattern);
  1325. end;
  1326. end
  1327. else
  1328. begin
  1329. { class reference ? }
  1330. if is_class(htype.def) then
  1331. begin
  1332. if getaddr and (token=_POINT) then
  1333. begin
  1334. consume(_POINT);
  1335. { allows @Object.Method }
  1336. { also allows static methods and variables }
  1337. p1:=ctypenode.create(htype);
  1338. { TP allows also @TMenu.Load if Load is only }
  1339. { defined in an anchestor class }
  1340. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1341. if assigned(srsym) then
  1342. begin
  1343. check_hints(srsym,srsym.symoptions);
  1344. consume(_ID);
  1345. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1346. end
  1347. else
  1348. begin
  1349. Message1(sym_e_id_no_member,orgpattern);
  1350. consume(_ID);
  1351. end;
  1352. end
  1353. else
  1354. begin
  1355. p1:=ctypenode.create(htype);
  1356. { For a type block we simply return only
  1357. the type. For all other blocks we return
  1358. a loadvmt node }
  1359. if (block_type<>bt_type) then
  1360. p1:=cloadvmtaddrnode.create(p1);
  1361. end;
  1362. end
  1363. else
  1364. p1:=ctypenode.create(htype);
  1365. end;
  1366. end;
  1367. end;
  1368. enumsym :
  1369. begin
  1370. p1:=genenumnode(tenumsym(srsym));
  1371. end;
  1372. constsym :
  1373. begin
  1374. case tconstsym(srsym).consttyp of
  1375. constord :
  1376. begin
  1377. if tconstsym(srsym).consttype.def=nil then
  1378. internalerror(200403232);
  1379. p1:=cordconstnode.create(tconstsym(srsym).value.valueord,tconstsym(srsym).consttype,true);
  1380. end;
  1381. conststring :
  1382. begin
  1383. len:=tconstsym(srsym).value.len;
  1384. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1385. len:=255;
  1386. getmem(pc,len+1);
  1387. move(pchar(tconstsym(srsym).value.valueptr)^,pc^,len);
  1388. pc[len]:=#0;
  1389. p1:=cstringconstnode.createpchar(pc,len);
  1390. end;
  1391. constwstring :
  1392. p1:=cstringconstnode.createwstr(pcompilerwidestring(tconstsym(srsym).value.valueptr));
  1393. constreal :
  1394. p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
  1395. constset :
  1396. p1:=csetconstnode.create(pconstset(tconstsym(srsym).value.valueptr),tconstsym(srsym).consttype);
  1397. constpointer :
  1398. p1:=cpointerconstnode.create(tconstsym(srsym).value.valueordptr,tconstsym(srsym).consttype);
  1399. constnil :
  1400. p1:=cnilnode.create;
  1401. constresourcestring:
  1402. begin
  1403. p1:=cloadnode.create(srsym,srsymtable);
  1404. do_resulttypepass(p1);
  1405. {$ifdef ansistring_bits}
  1406. case aktansistring_bits of
  1407. sb_16:
  1408. p1.resulttype:=cansistringtype16;
  1409. sb_32:
  1410. p1.resulttype:=cansistringtype32;
  1411. sb_64:
  1412. p1.resulttype:=cansistringtype64;
  1413. end;
  1414. {$else}
  1415. p1.resulttype:=cansistringtype;
  1416. {$endif}
  1417. end;
  1418. constguid :
  1419. p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
  1420. else
  1421. internalerror(200507181);
  1422. end;
  1423. end;
  1424. procsym :
  1425. begin
  1426. { are we in a class method ? }
  1427. possible_error:=(srsymtable.symtabletype<>withsymtable) and
  1428. (srsym.owner.symtabletype=objectsymtable) and
  1429. not(is_interface(tdef(srsym.owner.defowner))) and
  1430. assigned(current_procinfo) and
  1431. (po_classmethod in current_procinfo.procdef.procoptions);
  1432. do_proc_call(srsym,srsymtable,nil,
  1433. (getaddr and not(token in [_CARET,_POINT])),
  1434. again,p1,[]);
  1435. { we need to know which procedure is called }
  1436. if possible_error then
  1437. begin
  1438. do_resulttypepass(p1);
  1439. if (p1.nodetype=calln) and
  1440. assigned(tcallnode(p1).procdefinition) and
  1441. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1442. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) then
  1443. Message(parser_e_only_class_methods);
  1444. end;
  1445. end;
  1446. propertysym :
  1447. begin
  1448. { access to property in a method }
  1449. { are we in a class method ? }
  1450. if (srsymtable.symtabletype=objectsymtable) and
  1451. assigned(current_procinfo) and
  1452. (po_classmethod in current_procinfo.procdef.procoptions) then
  1453. Message(parser_e_only_class_methods);
  1454. { no method pointer }
  1455. p1:=nil;
  1456. handle_propertysym(srsym,srsymtable,p1);
  1457. end;
  1458. labelsym :
  1459. begin
  1460. { Support @label }
  1461. if getaddr then
  1462. p1:=cloadnode.create(srsym,srsym.owner)
  1463. else
  1464. begin
  1465. consume(_COLON);
  1466. if tlabelsym(srsym).defined then
  1467. Message(sym_e_label_already_defined);
  1468. tlabelsym(srsym).defined:=true;
  1469. p1:=clabelnode.create(nil);
  1470. tlabelsym(srsym).code:=p1;
  1471. end;
  1472. end;
  1473. errorsym :
  1474. begin
  1475. p1:=cerrornode.create;
  1476. if try_to_consume(_LKLAMMER) then
  1477. begin
  1478. parse_paras(false,_RKLAMMER);
  1479. consume(_RKLAMMER);
  1480. end;
  1481. end;
  1482. else
  1483. begin
  1484. p1:=cerrornode.create;
  1485. Message(parser_e_illegal_expression);
  1486. end;
  1487. end; { end case }
  1488. end;
  1489. end;
  1490. {---------------------------------------------
  1491. Factor_Read_Set
  1492. ---------------------------------------------}
  1493. { Read a set between [] }
  1494. function factor_read_set:tnode;
  1495. var
  1496. p1,p2 : tnode;
  1497. lastp,
  1498. buildp : tarrayconstructornode;
  1499. begin
  1500. buildp:=nil;
  1501. { be sure that a least one arrayconstructn is used, also for an
  1502. empty [] }
  1503. if token=_RECKKLAMMER then
  1504. buildp:=carrayconstructornode.create(nil,buildp)
  1505. else
  1506. repeat
  1507. p1:=comp_expr(true);
  1508. if try_to_consume(_POINTPOINT) then
  1509. begin
  1510. p2:=comp_expr(true);
  1511. p1:=carrayconstructorrangenode.create(p1,p2);
  1512. end;
  1513. { insert at the end of the tree, to get the correct order }
  1514. if not assigned(buildp) then
  1515. begin
  1516. buildp:=carrayconstructornode.create(p1,nil);
  1517. lastp:=buildp;
  1518. end
  1519. else
  1520. begin
  1521. lastp.right:=carrayconstructornode.create(p1,nil);
  1522. lastp:=tarrayconstructornode(lastp.right);
  1523. end;
  1524. { there could be more elements }
  1525. until not try_to_consume(_COMMA);
  1526. factor_read_set:=buildp;
  1527. end;
  1528. {---------------------------------------------
  1529. PostFixOperators
  1530. ---------------------------------------------}
  1531. procedure postfixoperators(var p1:tnode;var again:boolean);
  1532. { tries to avoid syntax errors after invalid qualifiers }
  1533. procedure recoverconsume_postfixops;
  1534. begin
  1535. repeat
  1536. if not try_to_consume(_CARET) then
  1537. if try_to_consume(_POINT) then
  1538. try_to_consume(_ID)
  1539. else if try_to_consume(_LECKKLAMMER) then
  1540. begin
  1541. repeat
  1542. comp_expr(true);
  1543. until not try_to_consume(_COMMA);
  1544. consume(_RECKKLAMMER);
  1545. end
  1546. else
  1547. break;
  1548. until false;
  1549. end;
  1550. procedure handle_variantarray;
  1551. var
  1552. p4 : tnode;
  1553. newstatement : tstatementnode;
  1554. tempresultvariant,
  1555. temp : ttempcreatenode;
  1556. paras : tcallparanode;
  1557. newblock : tnode;
  1558. countindices : aint;
  1559. begin
  1560. { create statements with call initialize the arguments and
  1561. call fpc_dynarr_setlength }
  1562. newblock:=internalstatements(newstatement);
  1563. { get temp for array of indicies,
  1564. we set the real size later }
  1565. temp:=ctempcreatenode.create(sinttype,4,tt_persistent,false);
  1566. addstatement(newstatement,temp);
  1567. countindices:=0;
  1568. repeat
  1569. p4:=comp_expr(true);
  1570. addstatement(newstatement,cassignmentnode.create(
  1571. ctemprefnode.create_offset(temp,countindices*sinttype.def.size),p4));
  1572. inc(countindices);
  1573. until not try_to_consume(_COMMA);
  1574. { set real size }
  1575. temp.size:=countindices*sinttype.def.size;
  1576. consume(_RECKKLAMMER);
  1577. { we need only a write access if a := follows }
  1578. if token=_ASSIGNMENT then
  1579. begin
  1580. consume(_ASSIGNMENT);
  1581. p4:=comp_expr(true);
  1582. { create call to fpc_vararray_put }
  1583. paras:=ccallparanode.create(cordconstnode.create
  1584. (countindices,sinttype,true),
  1585. ccallparanode.create(caddrnode.create_internal
  1586. (ctemprefnode.create(temp)),
  1587. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1588. ccallparanode.create(p1
  1589. ,nil))));
  1590. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1591. addstatement(newstatement,ctempdeletenode.create(temp));
  1592. end
  1593. else
  1594. begin
  1595. { create temp for result }
  1596. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.def.size,tt_persistent,true);
  1597. addstatement(newstatement,tempresultvariant);
  1598. { create call to fpc_vararray_get }
  1599. paras:=ccallparanode.create(cordconstnode.create
  1600. (countindices,sinttype,true),
  1601. ccallparanode.create(caddrnode.create_internal
  1602. (ctemprefnode.create(temp)),
  1603. ccallparanode.create(p1,
  1604. ccallparanode.create(
  1605. ctemprefnode.create(tempresultvariant)
  1606. ,nil))));
  1607. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1608. addstatement(newstatement,ctempdeletenode.create(temp));
  1609. { the last statement should return the value as
  1610. location and type, this is done be referencing the
  1611. temp and converting it first from a persistent temp to
  1612. normal temp }
  1613. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1614. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1615. end;
  1616. p1:=newblock;
  1617. end;
  1618. var
  1619. store_static : boolean;
  1620. protsym : tpropertysym;
  1621. p2,p3 : tnode;
  1622. hsym : tsym;
  1623. classh : tobjectdef;
  1624. label
  1625. skipreckklammercheck;
  1626. begin
  1627. again:=true;
  1628. while again do
  1629. begin
  1630. { we need the resulttype }
  1631. do_resulttypepass(p1);
  1632. if codegenerror then
  1633. begin
  1634. recoverconsume_postfixops;
  1635. exit;
  1636. end;
  1637. { handle token }
  1638. case token of
  1639. _CARET:
  1640. begin
  1641. consume(_CARET);
  1642. { support tp/mac procvar^ if the procvar returns a
  1643. pointer type }
  1644. if ((m_tp_procvar in aktmodeswitches) or
  1645. (m_mac_procvar in aktmodeswitches)) and
  1646. (p1.resulttype.def.deftype=procvardef) and
  1647. (tprocvardef(p1.resulttype.def).rettype.def.deftype=pointerdef) then
  1648. begin
  1649. p1:=ccallnode.create_procvar(nil,p1);
  1650. resulttypepass(p1);
  1651. end;
  1652. if (p1.resulttype.def.deftype<>pointerdef) then
  1653. begin
  1654. { ^ as binary operator is a problem!!!! (FK) }
  1655. again:=false;
  1656. Message(parser_e_invalid_qualifier);
  1657. recoverconsume_postfixops;
  1658. p1.destroy;
  1659. p1:=cerrornode.create;
  1660. end
  1661. else
  1662. p1:=cderefnode.create(p1);
  1663. end;
  1664. _LECKKLAMMER:
  1665. begin
  1666. if is_class_or_interface(p1.resulttype.def) then
  1667. begin
  1668. { default property }
  1669. protsym:=search_default_property(tobjectdef(p1.resulttype.def));
  1670. if not(assigned(protsym)) then
  1671. begin
  1672. p1.destroy;
  1673. p1:=cerrornode.create;
  1674. again:=false;
  1675. message(parser_e_no_default_property_available);
  1676. end
  1677. else
  1678. begin
  1679. { The property symbol is referenced indirect }
  1680. inc(protsym.refs);
  1681. handle_propertysym(protsym,protsym.owner,p1);
  1682. end;
  1683. end
  1684. else
  1685. begin
  1686. consume(_LECKKLAMMER);
  1687. repeat
  1688. case p1.resulttype.def.deftype of
  1689. pointerdef:
  1690. begin
  1691. { support delphi autoderef }
  1692. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=arraydef) and
  1693. (m_autoderef in aktmodeswitches) then
  1694. begin
  1695. p1:=cderefnode.create(p1);
  1696. end;
  1697. p2:=comp_expr(true);
  1698. p1:=cvecnode.create(p1,p2);
  1699. end;
  1700. variantdef:
  1701. begin
  1702. handle_variantarray;
  1703. { the RECKKLAMMER is already read }
  1704. goto skipreckklammercheck;
  1705. end;
  1706. stringdef :
  1707. begin
  1708. p2:=comp_expr(true);
  1709. p1:=cvecnode.create(p1,p2);
  1710. end;
  1711. arraydef :
  1712. begin
  1713. p2:=comp_expr(true);
  1714. { support SEG:OFS for go32v2 Mem[] }
  1715. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  1716. (p1.nodetype=loadn) and
  1717. assigned(tloadnode(p1).symtableentry) and
  1718. assigned(tloadnode(p1).symtableentry.owner.name) and
  1719. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1720. ((tloadnode(p1).symtableentry.name='MEM') or
  1721. (tloadnode(p1).symtableentry.name='MEMW') or
  1722. (tloadnode(p1).symtableentry.name='MEML')) then
  1723. begin
  1724. if try_to_consume(_COLON) then
  1725. begin
  1726. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1727. p2:=comp_expr(true);
  1728. p2:=caddnode.create(addn,p2,p3);
  1729. p1:=cvecnode.create(p1,p2);
  1730. include(tvecnode(p1).flags,nf_memseg);
  1731. include(tvecnode(p1).flags,nf_memindex);
  1732. end
  1733. else
  1734. begin
  1735. p1:=cvecnode.create(p1,p2);
  1736. include(tvecnode(p1).flags,nf_memindex);
  1737. end;
  1738. end
  1739. else
  1740. p1:=cvecnode.create(p1,p2);
  1741. end;
  1742. else
  1743. begin
  1744. Message(parser_e_invalid_qualifier);
  1745. p1.destroy;
  1746. p1:=cerrornode.create;
  1747. comp_expr(true);
  1748. again:=false;
  1749. end;
  1750. end;
  1751. do_resulttypepass(p1);
  1752. until not try_to_consume(_COMMA);
  1753. consume(_RECKKLAMMER);
  1754. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1755. skipreckklammercheck:
  1756. end;
  1757. end;
  1758. _POINT :
  1759. begin
  1760. consume(_POINT);
  1761. if (p1.resulttype.def.deftype=pointerdef) and
  1762. (m_autoderef in aktmodeswitches) then
  1763. begin
  1764. p1:=cderefnode.create(p1);
  1765. do_resulttypepass(p1);
  1766. end;
  1767. case p1.resulttype.def.deftype of
  1768. recorddef:
  1769. begin
  1770. if token=_ID then
  1771. begin
  1772. hsym:=tsym(trecorddef(p1.resulttype.def).symtable.search(pattern));
  1773. if assigned(hsym) and
  1774. (hsym.typ=fieldvarsym) then
  1775. begin
  1776. check_hints(hsym,hsym.symoptions);
  1777. p1:=csubscriptnode.create(hsym,p1)
  1778. end
  1779. else
  1780. begin
  1781. Message1(sym_e_illegal_field,pattern);
  1782. p1.destroy;
  1783. p1:=cerrornode.create;
  1784. end;
  1785. end;
  1786. consume(_ID);
  1787. end;
  1788. variantdef:
  1789. begin
  1790. end;
  1791. classrefdef:
  1792. begin
  1793. if token=_ID then
  1794. begin
  1795. classh:=tobjectdef(tclassrefdef(p1.resulttype.def).pointertype.def);
  1796. hsym:=searchsym_in_class(classh,pattern);
  1797. if hsym=nil then
  1798. begin
  1799. Message1(sym_e_id_no_member,orgpattern);
  1800. p1.destroy;
  1801. p1:=cerrornode.create;
  1802. { try to clean up }
  1803. consume(_ID);
  1804. end
  1805. else
  1806. begin
  1807. check_hints(hsym,hsym.symoptions);
  1808. consume(_ID);
  1809. do_member_read(classh,getaddr,hsym,p1,again,[]);
  1810. end;
  1811. end
  1812. else { Error }
  1813. Consume(_ID);
  1814. end;
  1815. objectdef:
  1816. begin
  1817. if token=_ID then
  1818. begin
  1819. store_static:=allow_only_static;
  1820. allow_only_static:=false;
  1821. classh:=tobjectdef(p1.resulttype.def);
  1822. hsym:=searchsym_in_class(classh,pattern);
  1823. allow_only_static:=store_static;
  1824. if hsym=nil then
  1825. begin
  1826. Message1(sym_e_id_no_member,orgpattern);
  1827. p1.destroy;
  1828. p1:=cerrornode.create;
  1829. { try to clean up }
  1830. consume(_ID);
  1831. end
  1832. else
  1833. begin
  1834. check_hints(hsym,hsym.symoptions);
  1835. consume(_ID);
  1836. do_member_read(classh,getaddr,hsym,p1,again,[]);
  1837. end;
  1838. end
  1839. else { Error }
  1840. Consume(_ID);
  1841. end;
  1842. pointerdef:
  1843. begin
  1844. Message(parser_e_invalid_qualifier);
  1845. if tpointerdef(p1.resulttype.def).pointertype.def.deftype in [recorddef,objectdef,classrefdef] then
  1846. Message(parser_h_maybe_deref_caret_missing);
  1847. end;
  1848. else
  1849. begin
  1850. Message(parser_e_invalid_qualifier);
  1851. p1.destroy;
  1852. p1:=cerrornode.create;
  1853. { Error }
  1854. consume(_ID);
  1855. end;
  1856. end;
  1857. end;
  1858. else
  1859. begin
  1860. { is this a procedure variable ? }
  1861. if assigned(p1.resulttype.def) and
  1862. (p1.resulttype.def.deftype=procvardef) then
  1863. begin
  1864. if assigned(getprocvardef) and
  1865. equal_defs(p1.resulttype.def,getprocvardef) then
  1866. again:=false
  1867. else
  1868. begin
  1869. if try_to_consume(_LKLAMMER) then
  1870. begin
  1871. p2:=parse_paras(false,_RKLAMMER);
  1872. consume(_RKLAMMER);
  1873. p1:=ccallnode.create_procvar(p2,p1);
  1874. { proc():= is never possible }
  1875. if token=_ASSIGNMENT then
  1876. begin
  1877. Message(parser_e_illegal_expression);
  1878. p1.free;
  1879. p1:=cerrornode.create;
  1880. again:=false;
  1881. end;
  1882. end
  1883. else
  1884. again:=false;
  1885. end;
  1886. end
  1887. else
  1888. again:=false;
  1889. end;
  1890. end;
  1891. end; { while again }
  1892. end;
  1893. {---------------------------------------------
  1894. Factor (Main)
  1895. ---------------------------------------------}
  1896. var
  1897. l : longint;
  1898. ic : int64;
  1899. qc : qword;
  1900. {$ifndef cpu64}
  1901. card : cardinal;
  1902. {$endif cpu64}
  1903. oldp1,
  1904. p1 : tnode;
  1905. code : integer;
  1906. again : boolean;
  1907. sym : tsym;
  1908. pd : tprocdef;
  1909. classh : tobjectdef;
  1910. d : bestreal;
  1911. hs,hsorg : string;
  1912. htype : ttype;
  1913. filepos : tfileposinfo;
  1914. {---------------------------------------------
  1915. Helpers
  1916. ---------------------------------------------}
  1917. procedure check_tokenpos;
  1918. begin
  1919. if (p1<>oldp1) then
  1920. begin
  1921. if assigned(p1) then
  1922. p1.fileinfo:=filepos;
  1923. oldp1:=p1;
  1924. filepos:=akttokenpos;
  1925. end;
  1926. end;
  1927. begin
  1928. oldp1:=nil;
  1929. p1:=nil;
  1930. filepos:=akttokenpos;
  1931. again:=false;
  1932. if token=_ID then
  1933. begin
  1934. again:=true;
  1935. { Handle references to self }
  1936. if (idtoken=_SELF) and
  1937. not(block_type in [bt_const,bt_type]) and
  1938. assigned(current_procinfo) and
  1939. assigned(current_procinfo.procdef._class) then
  1940. begin
  1941. p1:=load_self_node;
  1942. consume(_ID);
  1943. again:=true;
  1944. end
  1945. else
  1946. factor_read_id(p1,again);
  1947. if again then
  1948. begin
  1949. check_tokenpos;
  1950. { handle post fix operators }
  1951. postfixoperators(p1,again);
  1952. end;
  1953. end
  1954. else
  1955. case token of
  1956. _RETURN :
  1957. begin
  1958. consume(_RETURN);
  1959. p1 := cexitnode.create(comp_expr(true));
  1960. end;
  1961. _INHERITED :
  1962. begin
  1963. again:=true;
  1964. consume(_INHERITED);
  1965. if assigned(current_procinfo) and
  1966. assigned(current_procinfo.procdef._class) then
  1967. begin
  1968. classh:=current_procinfo.procdef._class.childof;
  1969. { if inherited; only then we need the method with
  1970. the same name }
  1971. if token in endtokens then
  1972. begin
  1973. hs:=current_procinfo.procdef.procsym.name;
  1974. hsorg:=current_procinfo.procdef.procsym.realname;
  1975. anon_inherited:=true;
  1976. { For message methods we need to search using the message
  1977. number or string }
  1978. pd:=tprocsym(current_procinfo.procdef.procsym).first_procdef;
  1979. if (po_msgint in pd.procoptions) then
  1980. sym:=searchsym_in_class_by_msgint(classh,pd.messageinf.i)
  1981. else
  1982. if (po_msgstr in pd.procoptions) then
  1983. sym:=searchsym_in_class_by_msgstr(classh,pd.messageinf.str)
  1984. else
  1985. sym:=searchsym_in_class(classh,hs);
  1986. end
  1987. else
  1988. begin
  1989. hs:=pattern;
  1990. hsorg:=orgpattern;
  1991. consume(_ID);
  1992. anon_inherited:=false;
  1993. sym:=searchsym_in_class(classh,hs);
  1994. end;
  1995. if assigned(sym) then
  1996. begin
  1997. check_hints(sym,sym.symoptions);
  1998. { load the procdef from the inherited class and
  1999. not from self }
  2000. if sym.typ in [procsym,propertysym] then
  2001. begin
  2002. if (sym.typ = procsym) then
  2003. begin
  2004. htype.setdef(classh);
  2005. if (po_classmethod in current_procinfo.procdef.procoptions) or
  2006. (po_staticmethod in current_procinfo.procdef.procoptions) then
  2007. htype.setdef(tclassrefdef.create(htype));
  2008. p1:=ctypenode.create(htype);
  2009. end;
  2010. end
  2011. else
  2012. begin
  2013. Message(parser_e_methode_id_expected);
  2014. p1:=cerrornode.create;
  2015. end;
  2016. do_member_read(classh,getaddr,sym,p1,again,[cnf_inherited,cnf_anon_inherited]);
  2017. end
  2018. else
  2019. begin
  2020. if anon_inherited then
  2021. begin
  2022. { For message methods we need to call DefaultHandler }
  2023. if (po_msgint in pd.procoptions) or
  2024. (po_msgstr in pd.procoptions) then
  2025. begin
  2026. sym:=searchsym_in_class(classh,'DEFAULTHANDLER');
  2027. if not assigned(sym) or
  2028. (sym.typ<>procsym) then
  2029. internalerror(200303171);
  2030. p1:=nil;
  2031. do_proc_call(sym,sym.owner,classh,false,again,p1,[]);
  2032. end
  2033. else
  2034. begin
  2035. { we need to ignore the inherited; }
  2036. p1:=cnothingnode.create;
  2037. end;
  2038. end
  2039. else
  2040. begin
  2041. Message1(sym_e_id_no_member,hsorg);
  2042. p1:=cerrornode.create;
  2043. end;
  2044. again:=false;
  2045. end;
  2046. { turn auto inheriting off }
  2047. anon_inherited:=false;
  2048. end
  2049. else
  2050. begin
  2051. Message(parser_e_generic_methods_only_in_methods);
  2052. again:=false;
  2053. p1:=cerrornode.create;
  2054. end;
  2055. postfixoperators(p1,again);
  2056. end;
  2057. _INTCONST :
  2058. begin
  2059. {$ifdef cpu64}
  2060. { when already running under 64bit must read int64 constant, because reading
  2061. cardinal first will also succeed (code=0) for values > maxcardinal, because
  2062. range checking is off by default (PFV) }
  2063. val(pattern,ic,code);
  2064. if code=0 then
  2065. begin
  2066. consume(_INTCONST);
  2067. int_to_type(ic,htype);
  2068. p1:=cordconstnode.create(ic,htype,true);
  2069. end
  2070. else
  2071. begin
  2072. { try qword next }
  2073. val(pattern,qc,code);
  2074. if code=0 then
  2075. begin
  2076. consume(_INTCONST);
  2077. htype:=u64inttype;
  2078. p1:=cordconstnode.create(qc,htype,true);
  2079. end;
  2080. end;
  2081. {$else}
  2082. { try cardinal first }
  2083. val(pattern,card,code);
  2084. if code=0 then
  2085. begin
  2086. consume(_INTCONST);
  2087. int_to_type(card,htype);
  2088. p1:=cordconstnode.create(card,htype,true);
  2089. end
  2090. else
  2091. begin
  2092. { then longint }
  2093. val(pattern,l,code);
  2094. if code = 0 then
  2095. begin
  2096. consume(_INTCONST);
  2097. int_to_type(l,htype);
  2098. p1:=cordconstnode.create(l,htype,true);
  2099. end
  2100. else
  2101. begin
  2102. { then int64 }
  2103. val(pattern,ic,code);
  2104. if code=0 then
  2105. begin
  2106. consume(_INTCONST);
  2107. int_to_type(ic,htype);
  2108. p1:=cordconstnode.create(ic,htype,true);
  2109. end
  2110. else
  2111. begin
  2112. { try qword next }
  2113. val(pattern,qc,code);
  2114. if code=0 then
  2115. begin
  2116. consume(_INTCONST);
  2117. htype:=u64inttype;
  2118. p1:=cordconstnode.create(tconstexprint(qc),htype,true);
  2119. end;
  2120. end;
  2121. end;
  2122. end;
  2123. {$endif}
  2124. if code<>0 then
  2125. begin
  2126. { finally float }
  2127. val(pattern,d,code);
  2128. if code<>0 then
  2129. begin
  2130. Message(parser_e_invalid_integer);
  2131. consume(_INTCONST);
  2132. l:=1;
  2133. p1:=cordconstnode.create(l,sinttype,true);
  2134. end
  2135. else
  2136. begin
  2137. consume(_INTCONST);
  2138. p1:=crealconstnode.create(d,pbestrealtype^);
  2139. end;
  2140. end;
  2141. end;
  2142. _REALNUMBER :
  2143. begin
  2144. val(pattern,d,code);
  2145. if code<>0 then
  2146. begin
  2147. Message(parser_e_error_in_real);
  2148. d:=1.0;
  2149. end;
  2150. consume(_REALNUMBER);
  2151. p1:=crealconstnode.create(d,pbestrealtype^);
  2152. end;
  2153. _STRING :
  2154. begin
  2155. string_dec(htype);
  2156. { STRING can be also a type cast }
  2157. if try_to_consume(_LKLAMMER) then
  2158. begin
  2159. p1:=comp_expr(true);
  2160. consume(_RKLAMMER);
  2161. p1:=ctypeconvnode.create_explicit(p1,htype);
  2162. { handle postfix operators here e.g. string(a)[10] }
  2163. again:=true;
  2164. postfixoperators(p1,again);
  2165. end
  2166. else
  2167. p1:=ctypenode.create(htype);
  2168. end;
  2169. _FILE :
  2170. begin
  2171. htype:=cfiletype;
  2172. consume(_FILE);
  2173. { FILE can be also a type cast }
  2174. if try_to_consume(_LKLAMMER) then
  2175. begin
  2176. p1:=comp_expr(true);
  2177. consume(_RKLAMMER);
  2178. p1:=ctypeconvnode.create_explicit(p1,htype);
  2179. { handle postfix operators here e.g. string(a)[10] }
  2180. again:=true;
  2181. postfixoperators(p1,again);
  2182. end
  2183. else
  2184. begin
  2185. p1:=ctypenode.create(htype);
  2186. end;
  2187. end;
  2188. _CSTRING :
  2189. begin
  2190. p1:=cstringconstnode.createstr(pattern,st_default);
  2191. consume(_CSTRING);
  2192. end;
  2193. _CCHAR :
  2194. begin
  2195. p1:=cordconstnode.create(ord(pattern[1]),cchartype,true);
  2196. consume(_CCHAR);
  2197. end;
  2198. _CWSTRING:
  2199. begin
  2200. p1:=cstringconstnode.createwstr(patternw);
  2201. consume(_CWSTRING);
  2202. end;
  2203. _CWCHAR:
  2204. begin
  2205. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  2206. consume(_CWCHAR);
  2207. end;
  2208. _KLAMMERAFFE :
  2209. begin
  2210. consume(_KLAMMERAFFE);
  2211. got_addrn:=true;
  2212. { support both @<x> and @(<x>) }
  2213. if try_to_consume(_LKLAMMER) then
  2214. begin
  2215. p1:=factor(true);
  2216. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2217. begin
  2218. again:=true;
  2219. postfixoperators(p1,again);
  2220. end;
  2221. consume(_RKLAMMER);
  2222. end
  2223. else
  2224. p1:=factor(true);
  2225. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2226. begin
  2227. again:=true;
  2228. postfixoperators(p1,again);
  2229. end;
  2230. got_addrn:=false;
  2231. p1:=caddrnode.create(p1);
  2232. if cs_typed_addresses in aktlocalswitches then
  2233. include(p1.flags,nf_typedaddr);
  2234. { Store the procvar that we are expecting, the
  2235. addrn will use the information to find the correct
  2236. procdef or it will return an error }
  2237. if assigned(getprocvardef) and
  2238. (taddrnode(p1).left.nodetype = loadn) then
  2239. taddrnode(p1).getprocvardef:=getprocvardef;
  2240. end;
  2241. _LKLAMMER :
  2242. begin
  2243. consume(_LKLAMMER);
  2244. p1:=comp_expr(true);
  2245. consume(_RKLAMMER);
  2246. { it's not a good solution }
  2247. { but (a+b)^ makes some problems }
  2248. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2249. begin
  2250. again:=true;
  2251. postfixoperators(p1,again);
  2252. end;
  2253. end;
  2254. _LECKKLAMMER :
  2255. begin
  2256. consume(_LECKKLAMMER);
  2257. p1:=factor_read_set;
  2258. consume(_RECKKLAMMER);
  2259. end;
  2260. _PLUS :
  2261. begin
  2262. consume(_PLUS);
  2263. p1:=factor(false);
  2264. { we must generate a new node to do 0+<p1> otherwise the + will
  2265. not be checked }
  2266. p1:=caddnode.create(addn,genintconstnode(0),p1);
  2267. end;
  2268. _MINUS :
  2269. begin
  2270. consume(_MINUS);
  2271. if (token = _INTCONST) then
  2272. begin
  2273. { ugly hack, but necessary to be able to parse }
  2274. { -9223372036854775808 as int64 (JM) }
  2275. pattern := '-'+pattern;
  2276. p1:=sub_expr(oppower,false);
  2277. { -1 ** 4 should be - (1 ** 4) and not
  2278. (-1) ** 4
  2279. This was the reason of tw0869.pp test failure PM }
  2280. if p1.nodetype=starstarn then
  2281. begin
  2282. if tbinarynode(p1).left.nodetype=ordconstn then
  2283. begin
  2284. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  2285. p1:=cunaryminusnode.create(p1);
  2286. end
  2287. else if tbinarynode(p1).left.nodetype=realconstn then
  2288. begin
  2289. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  2290. p1:=cunaryminusnode.create(p1);
  2291. end
  2292. else
  2293. internalerror(20021029);
  2294. end;
  2295. end
  2296. else
  2297. begin
  2298. p1:=sub_expr(oppower,false);
  2299. p1:=cunaryminusnode.create(p1);
  2300. end;
  2301. end;
  2302. _OP_NOT :
  2303. begin
  2304. consume(_OP_NOT);
  2305. p1:=factor(false);
  2306. p1:=cnotnode.create(p1);
  2307. end;
  2308. _TRUE :
  2309. begin
  2310. consume(_TRUE);
  2311. p1:=cordconstnode.create(1,booltype,false);
  2312. end;
  2313. _FALSE :
  2314. begin
  2315. consume(_FALSE);
  2316. p1:=cordconstnode.create(0,booltype,false);
  2317. end;
  2318. _NIL :
  2319. begin
  2320. consume(_NIL);
  2321. p1:=cnilnode.create;
  2322. { It's really ugly code nil^, but delphi allows it }
  2323. if token in [_CARET] then
  2324. begin
  2325. again:=true;
  2326. postfixoperators(p1,again);
  2327. end;
  2328. end;
  2329. else
  2330. begin
  2331. p1:=cerrornode.create;
  2332. consume(token);
  2333. Message(parser_e_illegal_expression);
  2334. end;
  2335. end;
  2336. { generate error node if no node is created }
  2337. if not assigned(p1) then
  2338. begin
  2339. {$ifdef EXTDEBUG}
  2340. Comment(V_Warning,'factor: p1=nil');
  2341. {$endif}
  2342. p1:=cerrornode.create;
  2343. end;
  2344. { get the resulttype for the node }
  2345. if (not assigned(p1.resulttype.def)) then
  2346. do_resulttypepass(p1);
  2347. factor:=p1;
  2348. check_tokenpos;
  2349. end;
  2350. {$ifdef fpc}
  2351. {$maxfpuregisters default}
  2352. {$endif fpc}
  2353. {****************************************************************************
  2354. Sub_Expr
  2355. ****************************************************************************}
  2356. const
  2357. { Warning these stay be ordered !! }
  2358. operator_levels:array[Toperator_precedence] of set of Ttoken=
  2359. ([_LT,_LTE,_GT,_GTE,_EQUAL,_UNEQUAL,_OP_IN],
  2360. [_PLUS,_MINUS,_OP_OR,_PIPE,_OP_XOR],
  2361. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  2362. _OP_AS,_OP_IS,_OP_AND,_AMPERSAND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR],
  2363. [_STARSTAR] );
  2364. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;
  2365. {Reads a subexpression while the operators are of the current precedence
  2366. level, or any higher level. Replaces the old term, simpl_expr and
  2367. simpl2_expr.}
  2368. var
  2369. p1,p2 : tnode;
  2370. oldt : Ttoken;
  2371. filepos : tfileposinfo;
  2372. begin
  2373. if pred_level=highest_precedence then
  2374. p1:=factor(false)
  2375. else
  2376. p1:=sub_expr(succ(pred_level),true);
  2377. repeat
  2378. if (token in operator_levels[pred_level]) and
  2379. ((token<>_EQUAL) or accept_equal) then
  2380. begin
  2381. oldt:=token;
  2382. filepos:=akttokenpos;
  2383. consume(token);
  2384. if pred_level=highest_precedence then
  2385. p2:=factor(false)
  2386. else
  2387. p2:=sub_expr(succ(pred_level),true);
  2388. case oldt of
  2389. _PLUS :
  2390. p1:=caddnode.create(addn,p1,p2);
  2391. _MINUS :
  2392. p1:=caddnode.create(subn,p1,p2);
  2393. _STAR :
  2394. p1:=caddnode.create(muln,p1,p2);
  2395. _SLASH :
  2396. p1:=caddnode.create(slashn,p1,p2);
  2397. _EQUAL :
  2398. p1:=caddnode.create(equaln,p1,p2);
  2399. _GT :
  2400. p1:=caddnode.create(gtn,p1,p2);
  2401. _LT :
  2402. p1:=caddnode.create(ltn,p1,p2);
  2403. _GTE :
  2404. p1:=caddnode.create(gten,p1,p2);
  2405. _LTE :
  2406. p1:=caddnode.create(lten,p1,p2);
  2407. _SYMDIF :
  2408. p1:=caddnode.create(symdifn,p1,p2);
  2409. _STARSTAR :
  2410. p1:=caddnode.create(starstarn,p1,p2);
  2411. _OP_AS :
  2412. p1:=casnode.create(p1,p2);
  2413. _OP_IN :
  2414. p1:=cinnode.create(p1,p2);
  2415. _OP_IS :
  2416. p1:=cisnode.create(p1,p2);
  2417. _OP_OR,
  2418. _PIPE {macpas only} :
  2419. begin
  2420. p1:=caddnode.create(orn,p1,p2);
  2421. if (oldt = _PIPE) then
  2422. include(p1.flags,nf_short_bool);
  2423. end;
  2424. _OP_AND,
  2425. _AMPERSAND {macpas only} :
  2426. begin
  2427. p1:=caddnode.create(andn,p1,p2);
  2428. if (oldt = _AMPERSAND) then
  2429. include(p1.flags,nf_short_bool);
  2430. end;
  2431. _OP_DIV :
  2432. p1:=cmoddivnode.create(divn,p1,p2);
  2433. _OP_NOT :
  2434. p1:=cnotnode.create(p1);
  2435. _OP_MOD :
  2436. p1:=cmoddivnode.create(modn,p1,p2);
  2437. _OP_SHL :
  2438. p1:=cshlshrnode.create(shln,p1,p2);
  2439. _OP_SHR :
  2440. p1:=cshlshrnode.create(shrn,p1,p2);
  2441. _OP_XOR :
  2442. p1:=caddnode.create(xorn,p1,p2);
  2443. _ASSIGNMENT :
  2444. p1:=cassignmentnode.create(p1,p2);
  2445. _CARET :
  2446. p1:=caddnode.create(caretn,p1,p2);
  2447. _UNEQUAL :
  2448. p1:=caddnode.create(unequaln,p1,p2);
  2449. end;
  2450. p1.fileinfo:=filepos;
  2451. end
  2452. else
  2453. break;
  2454. until false;
  2455. sub_expr:=p1;
  2456. end;
  2457. function comp_expr_in_formal_context(accept_equal : boolean):tnode;
  2458. var
  2459. prev : boolean;
  2460. begin
  2461. prev:=in_formal_context;
  2462. in_formal_context:=true;
  2463. comp_expr_in_formal_context:=comp_expr(accept_equal);
  2464. in_formal_context:=prev;
  2465. end;
  2466. function comp_expr_in_formal_context_class_header(accept_equal : boolean)
  2467. : tnode;
  2468. var
  2469. prev : boolean;
  2470. begin
  2471. prev:=in_class_header;
  2472. in_class_header:=true;
  2473. result:=comp_expr_in_formal_context(accept_equal);
  2474. in_class_header:=prev;
  2475. end;
  2476. function comp_expr(accept_equal : boolean):tnode;
  2477. var
  2478. oldafterassignment : boolean;
  2479. p1 : tnode;
  2480. begin
  2481. oldafterassignment:=afterassignment;
  2482. afterassignment:=true;
  2483. p1:=sub_expr(opcompare,accept_equal);
  2484. { get the resulttype for this expression }
  2485. if not assigned(p1.resulttype.def) then
  2486. do_resulttypepass(p1);
  2487. afterassignment:=oldafterassignment;
  2488. comp_expr:=p1;
  2489. end;
  2490. function expr : tnode;
  2491. var
  2492. p1,p2 : tnode;
  2493. oldafterassignment : boolean;
  2494. oldp1 : tnode;
  2495. filepos : tfileposinfo;
  2496. begin
  2497. oldafterassignment:=afterassignment;
  2498. p1:=sub_expr(opcompare,true);
  2499. { get the resulttype for this expression }
  2500. if not assigned(p1.resulttype.def) then
  2501. do_resulttypepass(p1);
  2502. filepos:=akttokenpos;
  2503. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  2504. afterassignment:=true;
  2505. oldp1:=p1;
  2506. case token of
  2507. _POINTPOINT :
  2508. begin
  2509. consume(_POINTPOINT);
  2510. p2:=sub_expr(opcompare,true);
  2511. p1:=crangenode.create(p1,p2);
  2512. end;
  2513. _ASSIGNMENT :
  2514. begin
  2515. consume(_ASSIGNMENT);
  2516. if (p1.resulttype.def.deftype=procvardef) then
  2517. getprocvardef:=tprocvardef(p1.resulttype.def);
  2518. p2:=sub_expr(opcompare,true);
  2519. if assigned(getprocvardef) then
  2520. handle_procvar(getprocvardef,p2);
  2521. getprocvardef:=nil;
  2522. p1:=cassignmentnode.create(p1,p2);
  2523. end;
  2524. _PLUSASN :
  2525. begin
  2526. consume(_PLUSASN);
  2527. p2:=sub_expr(opcompare,true);
  2528. p1:=gen_c_style_operator(addn,p1,p2);
  2529. end;
  2530. _MINUSASN :
  2531. begin
  2532. consume(_MINUSASN);
  2533. p2:=sub_expr(opcompare,true);
  2534. p1:=gen_c_style_operator(subn,p1,p2);
  2535. end;
  2536. _STARASN :
  2537. begin
  2538. consume(_STARASN );
  2539. p2:=sub_expr(opcompare,true);
  2540. p1:=gen_c_style_operator(muln,p1,p2);
  2541. end;
  2542. _SLASHASN :
  2543. begin
  2544. consume(_SLASHASN );
  2545. p2:=sub_expr(opcompare,true);
  2546. p1:=gen_c_style_operator(slashn,p1,p2);
  2547. end;
  2548. end;
  2549. { get the resulttype for this expression }
  2550. if not assigned(p1.resulttype.def) then
  2551. do_resulttypepass(p1);
  2552. afterassignment:=oldafterassignment;
  2553. if p1<>oldp1 then
  2554. p1.fileinfo:=filepos;
  2555. expr:=p1;
  2556. end;
  2557. function get_intconst:TConstExprInt;
  2558. {Reads an expression, tries to evalute it and check if it is an integer
  2559. constant. Then the constant is returned.}
  2560. var
  2561. p:tnode;
  2562. begin
  2563. result:=0;
  2564. p:=comp_expr(true);
  2565. if not codegenerror then
  2566. begin
  2567. if (p.nodetype<>ordconstn) or
  2568. not(is_integer(p.resulttype.def)) then
  2569. Message(parser_e_illegal_expression)
  2570. else
  2571. result:=tordconstnode(p).value;
  2572. end;
  2573. p.free;
  2574. end;
  2575. function get_stringconst:string;
  2576. {Reads an expression, tries to evaluate it and checks if it is a string
  2577. constant. Then the constant is returned.}
  2578. var
  2579. p:tnode;
  2580. begin
  2581. get_stringconst:='';
  2582. p:=comp_expr(true);
  2583. if p.nodetype<>stringconstn then
  2584. begin
  2585. if (p.nodetype=ordconstn) and is_char(p.resulttype.def) then
  2586. get_stringconst:=char(tordconstnode(p).value)
  2587. else
  2588. Message(parser_e_illegal_expression);
  2589. end
  2590. else
  2591. get_stringconst:=strpas(tstringconstnode(p).value_str);
  2592. p.free;
  2593. end;
  2594. initialization
  2595. in_formal_context:=false;
  2596. in_class_header:=false;
  2597. end.