pexpr.pas 100 KB

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