pexpr.pas 101 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750
  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_pack_x_y_z,
  744. in_unpack_x_y_z :
  745. begin
  746. consume(_LKLAMMER);
  747. in_args:=true;
  748. p1:=comp_expr(true);
  749. consume(_COMMA);
  750. p2:=comp_expr(true);
  751. consume(_COMMA);
  752. paras:=comp_expr(true);
  753. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,ccallparanode.create(paras,nil))));
  754. consume(_RKLAMMER);
  755. end;
  756. in_assert_x_y :
  757. begin
  758. consume(_LKLAMMER);
  759. in_args:=true;
  760. p1:=comp_expr(true);
  761. if try_to_consume(_COMMA) then
  762. p2:=comp_expr(true)
  763. else
  764. begin
  765. { then insert an empty string }
  766. p2:=cstringconstnode.createstr('');
  767. end;
  768. statement_syssym:=geninlinenode(l,false,ccallparanode.create(p1,ccallparanode.create(p2,nil)));
  769. consume(_RKLAMMER);
  770. end;
  771. in_get_frame:
  772. begin
  773. statement_syssym:=geninlinenode(l,false,nil);
  774. end;
  775. in_get_caller_frame:
  776. begin
  777. if try_to_consume(_LKLAMMER) then
  778. begin
  779. {You used to call get_caller_frame as get_caller_frame(get_frame),
  780. however, as a stack frame may not exist, it does more harm than
  781. good, so ignore it.}
  782. in_args:=true;
  783. p1:=comp_expr(true);
  784. p1.destroy;
  785. consume(_RKLAMMER);
  786. end;
  787. statement_syssym:=geninlinenode(l,false,nil);
  788. end;
  789. else
  790. internalerror(15);
  791. end;
  792. in_args:=prev_in_args;
  793. end;
  794. function maybe_load_methodpointer(st:tsymtable;var p1:tnode):boolean;
  795. begin
  796. maybe_load_methodpointer:=false;
  797. if not assigned(p1) then
  798. begin
  799. case st.symtabletype of
  800. withsymtable :
  801. begin
  802. if (st.defowner.deftype=objectdef) then
  803. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  804. end;
  805. objectsymtable :
  806. begin
  807. p1:=load_self_node;
  808. { We are calling a member }
  809. maybe_load_methodpointer:=true;
  810. end;
  811. end;
  812. end;
  813. end;
  814. { reads the parameter for a subroutine call }
  815. procedure do_proc_call(sym:tsym;st:tsymtable;obj:tobjectdef;getaddr:boolean;var again : boolean;var p1:tnode;callflags:tcallnodeflags);
  816. var
  817. membercall,
  818. prevafterassn : boolean;
  819. i : integer;
  820. para,p2 : tnode;
  821. currpara : tparavarsym;
  822. aprocdef : tprocdef;
  823. begin
  824. prevafterassn:=afterassignment;
  825. afterassignment:=false;
  826. membercall:=false;
  827. aprocdef:=nil;
  828. { when it is a call to a member we need to load the
  829. methodpointer first }
  830. membercall:=maybe_load_methodpointer(st,p1);
  831. { When we are expecting a procvar we also need
  832. to get the address in some cases }
  833. if assigned(getprocvardef) then
  834. begin
  835. if (block_type=bt_const) or
  836. getaddr then
  837. begin
  838. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  839. getaddr:=true;
  840. end
  841. else
  842. if (m_tp_procvar in aktmodeswitches) or
  843. (m_mac_procvar in aktmodeswitches) then
  844. begin
  845. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  846. if assigned(aprocdef) then
  847. getaddr:=true;
  848. end;
  849. end;
  850. { only need to get the address of the procedure? }
  851. if getaddr then
  852. begin
  853. { Retrieve info which procvar to call. For tp_procvar the
  854. aprocdef is already loaded above so we can reuse it }
  855. if not assigned(aprocdef) and
  856. assigned(getprocvardef) then
  857. aprocdef:=Tprocsym(sym).search_procdef_byprocvardef(getprocvardef);
  858. { generate a methodcallnode or proccallnode }
  859. { we shouldn't convert things like @tcollection.load }
  860. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  861. if assigned(p1) then
  862. begin
  863. { for loading methodpointer of an inherited function
  864. we use self as instance and load the address of
  865. the function directly and not through the vmt (PFV) }
  866. if (cnf_inherited in callflags) then
  867. begin
  868. include(p2.flags,nf_inherited);
  869. p1.free;
  870. p1:=load_self_node;
  871. end;
  872. if (p1.nodetype<>typen) then
  873. tloadnode(p2).set_mp(p1)
  874. else
  875. p1.free;
  876. end;
  877. p1:=p2;
  878. { no postfix operators }
  879. again:=false;
  880. end
  881. else
  882. begin
  883. para:=nil;
  884. if anon_inherited then
  885. begin
  886. if not assigned(current_procinfo) then
  887. internalerror(200305054);
  888. for i:=0 to current_procinfo.procdef.paras.count-1 do
  889. begin
  890. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  891. if not(vo_is_hidden_para in currpara.varoptions) then
  892. para:=ccallparanode.create(cloadnode.create(currpara,currpara.owner),para);
  893. end;
  894. end
  895. else
  896. begin
  897. if try_to_consume(_LKLAMMER) then
  898. begin
  899. para:=parse_paras(false,_RKLAMMER);
  900. consume(_RKLAMMER);
  901. end;
  902. end;
  903. { indicate if this call was generated by a member and
  904. no explicit self is used, this is needed to determine
  905. how to handle a destructor call (PFV) }
  906. if membercall then
  907. include(callflags,cnf_member_call);
  908. if assigned(obj) then
  909. begin
  910. if (st.symtabletype<>objectsymtable) then
  911. internalerror(200310031);
  912. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1,callflags);
  913. end
  914. else
  915. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags);
  916. end;
  917. afterassignment:=prevafterassn;
  918. end;
  919. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  920. var
  921. hp,hp2 : tnode;
  922. hpp : ^tnode;
  923. currprocdef : tprocdef;
  924. begin
  925. if not assigned(pv) then
  926. internalerror(200301121);
  927. if (m_tp_procvar in aktmodeswitches) or
  928. (m_mac_procvar in aktmodeswitches) then
  929. begin
  930. hp:=p2;
  931. hpp:=@p2;
  932. while assigned(hp) and
  933. (hp.nodetype=typeconvn) do
  934. begin
  935. hp:=ttypeconvnode(hp).left;
  936. { save orignal address of the old tree so we can replace the node }
  937. hpp:=@hp;
  938. end;
  939. if (hp.nodetype=calln) and
  940. { a procvar can't have parameters! }
  941. not assigned(tcallnode(hp).left) then
  942. begin
  943. currprocdef:=tcallnode(hp).symtableprocentry.search_procdef_byprocvardef(pv);
  944. if assigned(currprocdef) then
  945. begin
  946. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  947. if (po_methodpointer in pv.procoptions) then
  948. tloadnode(hp2).set_mp(tcallnode(hp).get_load_methodpointer);
  949. hp.destroy;
  950. { replace the old callnode with the new loadnode }
  951. hpp^:=hp2;
  952. end;
  953. end;
  954. end;
  955. end;
  956. { the following procedure handles the access to a property symbol }
  957. procedure handle_propertysym(sym : tsym;st : tsymtable;var p1 : tnode);
  958. var
  959. paras : tnode;
  960. p2 : tnode;
  961. membercall : boolean;
  962. callflags : tcallnodeflags;
  963. begin
  964. paras:=nil;
  965. { property parameters? read them only if the property really }
  966. { has parameters }
  967. if (ppo_hasparameters in tpropertysym(sym).propoptions) then
  968. begin
  969. if try_to_consume(_LECKKLAMMER) then
  970. begin
  971. paras:=parse_paras(false,_RECKKLAMMER);
  972. consume(_RECKKLAMMER);
  973. end;
  974. end;
  975. { indexed property }
  976. if (ppo_indexed in tpropertysym(sym).propoptions) then
  977. begin
  978. p2:=cordconstnode.create(tpropertysym(sym).index,tpropertysym(sym).indextype,true);
  979. paras:=ccallparanode.create(p2,paras);
  980. end;
  981. { we need only a write property if a := follows }
  982. { if not(afterassignment) and not(in_args) then }
  983. if token=_ASSIGNMENT then
  984. begin
  985. { write property: }
  986. if not tpropertysym(sym).writeaccess.empty then
  987. begin
  988. case tpropertysym(sym).writeaccess.firstsym^.sym.typ of
  989. procsym :
  990. begin
  991. callflags:=[];
  992. { generate the method call }
  993. membercall:=maybe_load_methodpointer(st,p1);
  994. if membercall then
  995. include(callflags,cnf_member_call);
  996. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).writeaccess.firstsym^.sym),st,p1,callflags);
  997. addsymref(tpropertysym(sym).writeaccess.firstsym^.sym);
  998. paras:=nil;
  999. consume(_ASSIGNMENT);
  1000. { read the expression }
  1001. if tpropertysym(sym).proptype.def.deftype=procvardef then
  1002. getprocvardef:=tprocvardef(tpropertysym(sym).proptype.def);
  1003. p2:=comp_expr(true);
  1004. if assigned(getprocvardef) then
  1005. handle_procvar(getprocvardef,p2);
  1006. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  1007. { mark as property, both the tcallnode and the real call block }
  1008. include(p1.flags,nf_isproperty);
  1009. getprocvardef:=nil;
  1010. end;
  1011. fieldvarsym :
  1012. begin
  1013. { generate access code }
  1014. symlist_to_node(p1,st,tpropertysym(sym).writeaccess);
  1015. include(p1.flags,nf_isproperty);
  1016. consume(_ASSIGNMENT);
  1017. { read the expression }
  1018. p2:=comp_expr(true);
  1019. p1:=cassignmentnode.create(p1,p2);
  1020. end
  1021. else
  1022. begin
  1023. p1:=cerrornode.create;
  1024. Message(parser_e_no_procedure_to_access_property);
  1025. end;
  1026. end;
  1027. end
  1028. else
  1029. begin
  1030. p1:=cerrornode.create;
  1031. Message(parser_e_no_procedure_to_access_property);
  1032. end;
  1033. end
  1034. else
  1035. begin
  1036. { read property: }
  1037. if not tpropertysym(sym).readaccess.empty then
  1038. begin
  1039. case tpropertysym(sym).readaccess.firstsym^.sym.typ of
  1040. fieldvarsym :
  1041. begin
  1042. { generate access code }
  1043. symlist_to_node(p1,st,tpropertysym(sym).readaccess);
  1044. include(p1.flags,nf_isproperty);
  1045. end;
  1046. procsym :
  1047. begin
  1048. callflags:=[];
  1049. { generate the method call }
  1050. membercall:=maybe_load_methodpointer(st,p1);
  1051. if membercall then
  1052. include(callflags,cnf_member_call);
  1053. p1:=ccallnode.create(paras,tprocsym(tpropertysym(sym).readaccess.firstsym^.sym),st,p1,callflags);
  1054. paras:=nil;
  1055. include(p1.flags,nf_isproperty);
  1056. end
  1057. else
  1058. begin
  1059. p1:=cerrornode.create;
  1060. Message(type_e_mismatch);
  1061. end;
  1062. end;
  1063. end
  1064. else
  1065. begin
  1066. { error, no function to read property }
  1067. p1:=cerrornode.create;
  1068. Message(parser_e_no_procedure_to_access_property);
  1069. end;
  1070. end;
  1071. { release paras if not used }
  1072. if assigned(paras) then
  1073. paras.free;
  1074. end;
  1075. { the ID token has to be consumed before calling this function }
  1076. procedure do_member_read(classh:tobjectdef;getaddr : boolean;sym : tsym;var p1 : tnode;var again : boolean;callflags:tcallnodeflags);
  1077. var
  1078. static_name : string;
  1079. isclassref : boolean;
  1080. srsymtable : tsymtable;
  1081. begin
  1082. if sym=nil then
  1083. begin
  1084. { pattern is still valid unless
  1085. there is another ID just after the ID of sym }
  1086. Message1(sym_e_id_no_member,orgpattern);
  1087. p1.free;
  1088. p1:=cerrornode.create;
  1089. { try to clean up }
  1090. again:=false;
  1091. end
  1092. else
  1093. begin
  1094. if assigned(p1) then
  1095. begin
  1096. if not assigned(p1.resulttype.def) then
  1097. do_resulttypepass(p1);
  1098. isclassref:=(p1.resulttype.def.deftype=classrefdef);
  1099. end
  1100. else
  1101. isclassref:=false;
  1102. { we assume, that only procsyms and varsyms are in an object }
  1103. { symbol table, for classes, properties are allowed }
  1104. case sym.typ of
  1105. procsym:
  1106. begin
  1107. do_proc_call(sym,sym.owner,classh,
  1108. (getaddr and not(token in [_CARET,_POINT])),
  1109. again,p1,callflags);
  1110. { we need to know which procedure is called }
  1111. do_resulttypepass(p1);
  1112. { calling using classref? }
  1113. if isclassref and
  1114. (p1.nodetype=calln) and
  1115. assigned(tcallnode(p1).procdefinition) and
  1116. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1117. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1118. Message(parser_e_only_class_methods_via_class_ref);
  1119. end;
  1120. fieldvarsym:
  1121. begin
  1122. if (sp_static in sym.symoptions) then
  1123. begin
  1124. static_name:=lower(sym.owner.name^)+'_'+sym.name;
  1125. searchsym(static_name,sym,srsymtable);
  1126. if assigned(sym) then
  1127. check_hints(sym,sym.symoptions);
  1128. p1.free;
  1129. p1:=cloadnode.create(sym,srsymtable);
  1130. end
  1131. else
  1132. begin
  1133. if isclassref then
  1134. Message(parser_e_only_class_methods_via_class_ref);
  1135. p1:=csubscriptnode.create(sym,p1);
  1136. end;
  1137. end;
  1138. propertysym:
  1139. begin
  1140. if isclassref then
  1141. Message(parser_e_only_class_methods_via_class_ref);
  1142. handle_propertysym(sym,sym.owner,p1);
  1143. end;
  1144. else internalerror(16);
  1145. end;
  1146. end;
  1147. end;
  1148. {****************************************************************************
  1149. Factor
  1150. ****************************************************************************}
  1151. {$ifdef fpc}
  1152. {$maxfpuregisters 0}
  1153. {$endif fpc}
  1154. function factor(getaddr : boolean) : tnode;
  1155. {---------------------------------------------
  1156. Factor_read_id
  1157. ---------------------------------------------}
  1158. procedure factor_read_id(var p1:tnode;var again:boolean);
  1159. var
  1160. pc : pchar;
  1161. len : longint;
  1162. srsym : tsym;
  1163. possible_error : boolean;
  1164. srsymtable : tsymtable;
  1165. hdef : tdef;
  1166. htype : ttype;
  1167. static_name : string;
  1168. begin
  1169. { allow post fix operators }
  1170. again:=true;
  1171. consume_sym(srsym,srsymtable);
  1172. { Access to funcret or need to call the function? }
  1173. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  1174. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  1175. (
  1176. (token=_LKLAMMER) or
  1177. (
  1178. (
  1179. (m_tp7 in aktmodeswitches) or
  1180. (m_delphi in aktmodeswitches)
  1181. ) and
  1182. (afterassignment or in_args) and
  1183. not(vo_is_result in tabstractvarsym(srsym).varoptions)
  1184. )
  1185. ) then
  1186. begin
  1187. hdef:=tdef(srsym.owner.defowner);
  1188. if assigned(hdef) and
  1189. (hdef.deftype=procdef) then
  1190. srsym:=tprocdef(hdef).procsym
  1191. else
  1192. begin
  1193. Message(parser_e_illegal_expression);
  1194. srsym:=generrorsym;
  1195. end;
  1196. srsymtable:=srsym.owner;
  1197. {
  1198. storesymtablestack:=symtablestack;
  1199. symtablestack:=srsym.owner.next;
  1200. searchsym(srsym.name,srsym,srsymtable);
  1201. if not assigned(srsym) then
  1202. srsym:=generrorsym;
  1203. if (srsym.typ<>procsym) then
  1204. Message(parser_e_illegal_expression);
  1205. symtablestack:=storesymtablestack;
  1206. }
  1207. end;
  1208. begin
  1209. case srsym.typ of
  1210. absolutevarsym :
  1211. begin
  1212. if (tabsolutevarsym(srsym).abstyp=tovar) then
  1213. begin
  1214. p1:=nil;
  1215. symlist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  1216. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vartype);
  1217. include(p1.flags,nf_absolute);
  1218. end
  1219. else
  1220. p1:=cloadnode.create(srsym,srsymtable);
  1221. end;
  1222. globalvarsym,
  1223. localvarsym,
  1224. paravarsym,
  1225. fieldvarsym :
  1226. begin
  1227. if (sp_static in srsym.symoptions) then
  1228. begin
  1229. static_name:=lower(srsym.owner.name^)+'_'+srsym.name;
  1230. searchsym(static_name,srsym,srsymtable);
  1231. if assigned(srsym) then
  1232. check_hints(srsym,srsym.symoptions);
  1233. end
  1234. else
  1235. begin
  1236. { are we in a class method, we check here the
  1237. srsymtable, because a field in another object
  1238. also has objectsymtable. And withsymtable is
  1239. not possible for self in class methods (PFV) }
  1240. if (srsymtable.symtabletype=objectsymtable) and
  1241. assigned(current_procinfo) and
  1242. (po_classmethod in current_procinfo.procdef.procoptions) then
  1243. Message(parser_e_only_class_methods);
  1244. end;
  1245. case srsymtable.symtabletype of
  1246. objectsymtable :
  1247. begin
  1248. p1:=csubscriptnode.create(srsym,load_self_node);
  1249. node_tree_set_filepos(p1,aktfilepos);
  1250. end;
  1251. withsymtable :
  1252. begin
  1253. p1:=csubscriptnode.create(srsym,tnode(twithsymtable(srsymtable).withrefnode).getcopy);
  1254. node_tree_set_filepos(p1,aktfilepos);
  1255. end;
  1256. else
  1257. p1:=cloadnode.create(srsym,srsymtable);
  1258. end;
  1259. end;
  1260. typedconstsym :
  1261. begin
  1262. p1:=cloadnode.create(srsym,srsymtable);
  1263. end;
  1264. syssym :
  1265. begin
  1266. p1:=statement_syssym(tsyssym(srsym).number);
  1267. end;
  1268. typesym :
  1269. begin
  1270. htype.setsym(srsym);
  1271. if not assigned(htype.def) then
  1272. begin
  1273. again:=false;
  1274. end
  1275. else
  1276. begin
  1277. { We need to know if this unit uses Variants }
  1278. if (htype.def=cvarianttype.def) and
  1279. not(cs_compilesystem in aktmoduleswitches) then
  1280. current_module.flags:=current_module.flags or uf_uses_variants;
  1281. if (block_type<>bt_specialize) and
  1282. try_to_consume(_LKLAMMER) then
  1283. begin
  1284. p1:=comp_expr(true);
  1285. consume(_RKLAMMER);
  1286. p1:=ctypeconvnode.create_explicit(p1,htype);
  1287. end
  1288. else { not LKLAMMER }
  1289. if (token=_POINT) and
  1290. is_object(htype.def) then
  1291. begin
  1292. consume(_POINT);
  1293. if assigned(current_procinfo) and
  1294. assigned(current_procinfo.procdef._class) and
  1295. not(getaddr) then
  1296. begin
  1297. if current_procinfo.procdef._class.is_related(tobjectdef(htype.def)) then
  1298. begin
  1299. p1:=ctypenode.create(htype);
  1300. { search also in inherited methods }
  1301. searchsym_in_class(tobjectdef(htype.def),current_procinfo.procdef._class,pattern,srsym,srsymtable);
  1302. if assigned(srsym) then
  1303. check_hints(srsym,srsym.symoptions);
  1304. consume(_ID);
  1305. do_member_read(tobjectdef(htype.def),false,srsym,p1,again,[]);
  1306. end
  1307. else
  1308. begin
  1309. Message(parser_e_no_super_class);
  1310. again:=false;
  1311. end;
  1312. end
  1313. else
  1314. begin
  1315. { allows @TObject.Load }
  1316. { also allows static methods and variables }
  1317. p1:=ctypenode.create(htype);
  1318. { TP allows also @TMenu.Load if Load is only }
  1319. { defined in an anchestor class }
  1320. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1321. if assigned(srsym) then
  1322. begin
  1323. check_hints(srsym,srsym.symoptions);
  1324. if not(getaddr) and not(sp_static in srsym.symoptions) then
  1325. Message(sym_e_only_static_in_static)
  1326. else
  1327. begin
  1328. consume(_ID);
  1329. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1330. end;
  1331. end
  1332. else
  1333. Message1(sym_e_id_no_member,orgpattern);
  1334. end;
  1335. end
  1336. else
  1337. begin
  1338. { class reference ? }
  1339. if is_class(htype.def) then
  1340. begin
  1341. if getaddr and (token=_POINT) then
  1342. begin
  1343. consume(_POINT);
  1344. { allows @Object.Method }
  1345. { also allows static methods and variables }
  1346. p1:=ctypenode.create(htype);
  1347. { TP allows also @TMenu.Load if Load is only }
  1348. { defined in an anchestor class }
  1349. srsym:=search_class_member(tobjectdef(htype.def),pattern);
  1350. if assigned(srsym) then
  1351. begin
  1352. check_hints(srsym,srsym.symoptions);
  1353. consume(_ID);
  1354. do_member_read(tobjectdef(htype.def),getaddr,srsym,p1,again,[]);
  1355. end
  1356. else
  1357. begin
  1358. Message1(sym_e_id_no_member,orgpattern);
  1359. consume(_ID);
  1360. end;
  1361. end
  1362. else
  1363. begin
  1364. p1:=ctypenode.create(htype);
  1365. { For a type block we simply return only
  1366. the type. For all other blocks we return
  1367. a loadvmt node }
  1368. if not(block_type in [bt_type,bt_specialize]) then
  1369. p1:=cloadvmtaddrnode.create(p1);
  1370. end;
  1371. end
  1372. else
  1373. p1:=ctypenode.create(htype);
  1374. end;
  1375. end;
  1376. end;
  1377. enumsym :
  1378. begin
  1379. p1:=genenumnode(tenumsym(srsym));
  1380. end;
  1381. constsym :
  1382. begin
  1383. case tconstsym(srsym).consttyp of
  1384. constord :
  1385. begin
  1386. if tconstsym(srsym).consttype.def=nil then
  1387. internalerror(200403232);
  1388. p1:=cordconstnode.create(tconstsym(srsym).value.valueord,tconstsym(srsym).consttype,true);
  1389. end;
  1390. conststring :
  1391. begin
  1392. len:=tconstsym(srsym).value.len;
  1393. if not(cs_ansistrings in aktlocalswitches) and (len>255) then
  1394. len:=255;
  1395. getmem(pc,len+1);
  1396. move(pchar(tconstsym(srsym).value.valueptr)^,pc^,len);
  1397. pc[len]:=#0;
  1398. p1:=cstringconstnode.createpchar(pc,len);
  1399. end;
  1400. constwstring :
  1401. p1:=cstringconstnode.createwstr(pcompilerwidestring(tconstsym(srsym).value.valueptr));
  1402. constreal :
  1403. p1:=crealconstnode.create(pbestreal(tconstsym(srsym).value.valueptr)^,pbestrealtype^);
  1404. constset :
  1405. p1:=csetconstnode.create(pconstset(tconstsym(srsym).value.valueptr),tconstsym(srsym).consttype);
  1406. constpointer :
  1407. p1:=cpointerconstnode.create(tconstsym(srsym).value.valueordptr,tconstsym(srsym).consttype);
  1408. constnil :
  1409. p1:=cnilnode.create;
  1410. constresourcestring:
  1411. begin
  1412. p1:=cloadnode.create(srsym,srsymtable);
  1413. do_resulttypepass(p1);
  1414. p1.resulttype:=cansistringtype;
  1415. end;
  1416. constguid :
  1417. p1:=cguidconstnode.create(pguid(tconstsym(srsym).value.valueptr)^);
  1418. else
  1419. internalerror(200507181);
  1420. end;
  1421. end;
  1422. procsym :
  1423. begin
  1424. { are we in a class method ? }
  1425. possible_error:=(srsymtable.symtabletype<>withsymtable) and
  1426. (srsym.owner.symtabletype=objectsymtable) and
  1427. not(is_interface(tdef(srsym.owner.defowner))) and
  1428. assigned(current_procinfo) and
  1429. (po_classmethod in current_procinfo.procdef.procoptions);
  1430. do_proc_call(srsym,srsymtable,nil,
  1431. (getaddr and not(token in [_CARET,_POINT])),
  1432. again,p1,[]);
  1433. { we need to know which procedure is called }
  1434. if possible_error then
  1435. begin
  1436. do_resulttypepass(p1);
  1437. if (p1.nodetype=calln) and
  1438. assigned(tcallnode(p1).procdefinition) and
  1439. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1440. not(po_classmethod in tcallnode(p1).procdefinition.procoptions) then
  1441. Message(parser_e_only_class_methods);
  1442. end;
  1443. end;
  1444. propertysym :
  1445. begin
  1446. { access to property in a method }
  1447. { are we in a class method ? }
  1448. if (srsymtable.symtabletype=objectsymtable) and
  1449. assigned(current_procinfo) and
  1450. (po_classmethod in current_procinfo.procdef.procoptions) then
  1451. Message(parser_e_only_class_methods);
  1452. { no method pointer }
  1453. p1:=nil;
  1454. handle_propertysym(srsym,srsymtable,p1);
  1455. end;
  1456. labelsym :
  1457. begin
  1458. { Support @label }
  1459. if getaddr then
  1460. p1:=cloadnode.create(srsym,srsym.owner)
  1461. else
  1462. begin
  1463. consume(_COLON);
  1464. if tlabelsym(srsym).defined then
  1465. Message(sym_e_label_already_defined);
  1466. tlabelsym(srsym).defined:=true;
  1467. p1:=clabelnode.create(nil);
  1468. tlabelsym(srsym).code:=p1;
  1469. end;
  1470. end;
  1471. errorsym :
  1472. begin
  1473. p1:=cerrornode.create;
  1474. if try_to_consume(_LKLAMMER) then
  1475. begin
  1476. parse_paras(false,_RKLAMMER);
  1477. consume(_RKLAMMER);
  1478. end;
  1479. end;
  1480. else
  1481. begin
  1482. p1:=cerrornode.create;
  1483. Message(parser_e_illegal_expression);
  1484. end;
  1485. end; { end case }
  1486. end;
  1487. end;
  1488. {---------------------------------------------
  1489. Factor_Read_Set
  1490. ---------------------------------------------}
  1491. { Read a set between [] }
  1492. function factor_read_set:tnode;
  1493. var
  1494. p1,p2 : tnode;
  1495. lastp,
  1496. buildp : tarrayconstructornode;
  1497. begin
  1498. buildp:=nil;
  1499. { be sure that a least one arrayconstructn is used, also for an
  1500. empty [] }
  1501. if token=_RECKKLAMMER then
  1502. buildp:=carrayconstructornode.create(nil,buildp)
  1503. else
  1504. repeat
  1505. p1:=comp_expr(true);
  1506. if try_to_consume(_POINTPOINT) then
  1507. begin
  1508. p2:=comp_expr(true);
  1509. p1:=carrayconstructorrangenode.create(p1,p2);
  1510. end;
  1511. { insert at the end of the tree, to get the correct order }
  1512. if not assigned(buildp) then
  1513. begin
  1514. buildp:=carrayconstructornode.create(p1,nil);
  1515. lastp:=buildp;
  1516. end
  1517. else
  1518. begin
  1519. lastp.right:=carrayconstructornode.create(p1,nil);
  1520. lastp:=tarrayconstructornode(lastp.right);
  1521. end;
  1522. { there could be more elements }
  1523. until not try_to_consume(_COMMA);
  1524. factor_read_set:=buildp;
  1525. end;
  1526. {---------------------------------------------
  1527. PostFixOperators
  1528. ---------------------------------------------}
  1529. procedure postfixoperators(var p1:tnode;var again:boolean);
  1530. { tries to avoid syntax errors after invalid qualifiers }
  1531. procedure recoverconsume_postfixops;
  1532. begin
  1533. repeat
  1534. if not try_to_consume(_CARET) then
  1535. if try_to_consume(_POINT) then
  1536. try_to_consume(_ID)
  1537. else if try_to_consume(_LECKKLAMMER) then
  1538. begin
  1539. repeat
  1540. comp_expr(true);
  1541. until not try_to_consume(_COMMA);
  1542. consume(_RECKKLAMMER);
  1543. end
  1544. else
  1545. break;
  1546. until false;
  1547. end;
  1548. procedure handle_variantarray;
  1549. var
  1550. p4 : tnode;
  1551. newstatement : tstatementnode;
  1552. tempresultvariant,
  1553. temp : ttempcreatenode;
  1554. paras : tcallparanode;
  1555. newblock : tnode;
  1556. countindices : aint;
  1557. begin
  1558. { create statements with call initialize the arguments and
  1559. call fpc_dynarr_setlength }
  1560. newblock:=internalstatements(newstatement);
  1561. { get temp for array of indicies,
  1562. we set the real size later }
  1563. temp:=ctempcreatenode.create(sinttype,4,tt_persistent,false);
  1564. addstatement(newstatement,temp);
  1565. countindices:=0;
  1566. repeat
  1567. p4:=comp_expr(true);
  1568. addstatement(newstatement,cassignmentnode.create(
  1569. ctemprefnode.create_offset(temp,countindices*sinttype.def.size),p4));
  1570. inc(countindices);
  1571. until not try_to_consume(_COMMA);
  1572. { set real size }
  1573. temp.size:=countindices*sinttype.def.size;
  1574. consume(_RECKKLAMMER);
  1575. { we need only a write access if a := follows }
  1576. if token=_ASSIGNMENT then
  1577. begin
  1578. consume(_ASSIGNMENT);
  1579. p4:=comp_expr(true);
  1580. { create call to fpc_vararray_put }
  1581. paras:=ccallparanode.create(cordconstnode.create
  1582. (countindices,sinttype,true),
  1583. ccallparanode.create(caddrnode.create_internal
  1584. (ctemprefnode.create(temp)),
  1585. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1586. ccallparanode.create(p1
  1587. ,nil))));
  1588. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1589. addstatement(newstatement,ctempdeletenode.create(temp));
  1590. end
  1591. else
  1592. begin
  1593. { create temp for result }
  1594. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.def.size,tt_persistent,true);
  1595. addstatement(newstatement,tempresultvariant);
  1596. { create call to fpc_vararray_get }
  1597. paras:=ccallparanode.create(cordconstnode.create
  1598. (countindices,sinttype,true),
  1599. ccallparanode.create(caddrnode.create_internal
  1600. (ctemprefnode.create(temp)),
  1601. ccallparanode.create(p1,
  1602. ccallparanode.create(
  1603. ctemprefnode.create(tempresultvariant)
  1604. ,nil))));
  1605. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1606. addstatement(newstatement,ctempdeletenode.create(temp));
  1607. { the last statement should return the value as
  1608. location and type, this is done be referencing the
  1609. temp and converting it first from a persistent temp to
  1610. normal temp }
  1611. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1612. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1613. end;
  1614. p1:=newblock;
  1615. end;
  1616. var
  1617. store_static : boolean;
  1618. protsym : tpropertysym;
  1619. p2,p3 : tnode;
  1620. srsym : tsym;
  1621. srsymtable : tsymtable;
  1622. classh : tobjectdef;
  1623. label
  1624. skipreckklammercheck;
  1625. begin
  1626. again:=true;
  1627. while again do
  1628. begin
  1629. { we need the resulttype }
  1630. do_resulttypepass(p1);
  1631. if codegenerror then
  1632. begin
  1633. recoverconsume_postfixops;
  1634. exit;
  1635. end;
  1636. { handle token }
  1637. case token of
  1638. _CARET:
  1639. begin
  1640. consume(_CARET);
  1641. { support tp/mac procvar^ if the procvar returns a
  1642. pointer type }
  1643. if ((m_tp_procvar in aktmodeswitches) or
  1644. (m_mac_procvar in aktmodeswitches)) and
  1645. (p1.resulttype.def.deftype=procvardef) and
  1646. (tprocvardef(p1.resulttype.def).rettype.def.deftype=pointerdef) then
  1647. begin
  1648. p1:=ccallnode.create_procvar(nil,p1);
  1649. resulttypepass(p1);
  1650. end;
  1651. if (p1.resulttype.def.deftype<>pointerdef) then
  1652. begin
  1653. { ^ as binary operator is a problem!!!! (FK) }
  1654. again:=false;
  1655. Message(parser_e_invalid_qualifier);
  1656. recoverconsume_postfixops;
  1657. p1.destroy;
  1658. p1:=cerrornode.create;
  1659. end
  1660. else
  1661. p1:=cderefnode.create(p1);
  1662. end;
  1663. _LECKKLAMMER:
  1664. begin
  1665. if is_class_or_interface(p1.resulttype.def) then
  1666. begin
  1667. { default property }
  1668. protsym:=search_default_property(tobjectdef(p1.resulttype.def));
  1669. if not(assigned(protsym)) then
  1670. begin
  1671. p1.destroy;
  1672. p1:=cerrornode.create;
  1673. again:=false;
  1674. message(parser_e_no_default_property_available);
  1675. end
  1676. else
  1677. begin
  1678. { The property symbol is referenced indirect }
  1679. inc(protsym.refs);
  1680. handle_propertysym(protsym,protsym.owner,p1);
  1681. end;
  1682. end
  1683. else
  1684. begin
  1685. consume(_LECKKLAMMER);
  1686. repeat
  1687. case p1.resulttype.def.deftype of
  1688. pointerdef:
  1689. begin
  1690. { support delphi autoderef }
  1691. if (tpointerdef(p1.resulttype.def).pointertype.def.deftype=arraydef) and
  1692. (m_autoderef in aktmodeswitches) then
  1693. begin
  1694. p1:=cderefnode.create(p1);
  1695. end;
  1696. p2:=comp_expr(true);
  1697. p1:=cvecnode.create(p1,p2);
  1698. end;
  1699. variantdef:
  1700. begin
  1701. handle_variantarray;
  1702. { the RECKKLAMMER is already read }
  1703. goto skipreckklammercheck;
  1704. end;
  1705. stringdef :
  1706. begin
  1707. p2:=comp_expr(true);
  1708. p1:=cvecnode.create(p1,p2);
  1709. end;
  1710. arraydef :
  1711. begin
  1712. p2:=comp_expr(true);
  1713. { support SEG:OFS for go32v2 Mem[] }
  1714. if (target_info.system in [system_i386_go32v2,system_i386_watcom]) and
  1715. (p1.nodetype=loadn) and
  1716. assigned(tloadnode(p1).symtableentry) and
  1717. assigned(tloadnode(p1).symtableentry.owner.name) and
  1718. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1719. ((tloadnode(p1).symtableentry.name='MEM') or
  1720. (tloadnode(p1).symtableentry.name='MEMW') or
  1721. (tloadnode(p1).symtableentry.name='MEML')) then
  1722. begin
  1723. if try_to_consume(_COLON) then
  1724. begin
  1725. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1726. p2:=comp_expr(true);
  1727. p2:=caddnode.create(addn,p2,p3);
  1728. p1:=cvecnode.create(p1,p2);
  1729. include(tvecnode(p1).flags,nf_memseg);
  1730. include(tvecnode(p1).flags,nf_memindex);
  1731. end
  1732. else
  1733. begin
  1734. p1:=cvecnode.create(p1,p2);
  1735. include(tvecnode(p1).flags,nf_memindex);
  1736. end;
  1737. end
  1738. else
  1739. p1:=cvecnode.create(p1,p2);
  1740. end;
  1741. else
  1742. begin
  1743. Message(parser_e_invalid_qualifier);
  1744. p1.destroy;
  1745. p1:=cerrornode.create;
  1746. comp_expr(true);
  1747. again:=false;
  1748. end;
  1749. end;
  1750. do_resulttypepass(p1);
  1751. until not try_to_consume(_COMMA);
  1752. consume(_RECKKLAMMER);
  1753. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1754. skipreckklammercheck:
  1755. end;
  1756. end;
  1757. _POINT :
  1758. begin
  1759. consume(_POINT);
  1760. if (p1.resulttype.def.deftype=pointerdef) and
  1761. (m_autoderef in aktmodeswitches) then
  1762. begin
  1763. p1:=cderefnode.create(p1);
  1764. do_resulttypepass(p1);
  1765. end;
  1766. case p1.resulttype.def.deftype of
  1767. recorddef:
  1768. begin
  1769. if token=_ID then
  1770. begin
  1771. srsym:=tsym(trecorddef(p1.resulttype.def).symtable.search(pattern));
  1772. if assigned(srsym) and
  1773. (srsym.typ=fieldvarsym) then
  1774. begin
  1775. check_hints(srsym,srsym.symoptions);
  1776. p1:=csubscriptnode.create(srsym,p1)
  1777. end
  1778. else
  1779. begin
  1780. Message1(sym_e_illegal_field,pattern);
  1781. p1.destroy;
  1782. p1:=cerrornode.create;
  1783. end;
  1784. end;
  1785. consume(_ID);
  1786. end;
  1787. variantdef:
  1788. begin
  1789. { dispatch call }
  1790. if token=_ID then
  1791. begin
  1792. consume(_ID);
  1793. end;
  1794. end;
  1795. classrefdef:
  1796. begin
  1797. if token=_ID then
  1798. begin
  1799. classh:=tobjectdef(tclassrefdef(p1.resulttype.def).pointertype.def);
  1800. searchsym_in_class(classh,classh,pattern,srsym,srsymtable);
  1801. if assigned(srsym) then
  1802. begin
  1803. check_hints(srsym,srsym.symoptions);
  1804. consume(_ID);
  1805. do_member_read(classh,getaddr,srsym,p1,again,[]);
  1806. end
  1807. else
  1808. begin
  1809. Message1(sym_e_id_no_member,orgpattern);
  1810. p1.destroy;
  1811. p1:=cerrornode.create;
  1812. { try to clean up }
  1813. consume(_ID);
  1814. end;
  1815. end
  1816. else { Error }
  1817. Consume(_ID);
  1818. end;
  1819. objectdef:
  1820. begin
  1821. if token=_ID then
  1822. begin
  1823. store_static:=allow_only_static;
  1824. allow_only_static:=false;
  1825. classh:=tobjectdef(p1.resulttype.def);
  1826. searchsym_in_class(classh,classh,pattern,srsym,srsymtable);
  1827. allow_only_static:=store_static;
  1828. if assigned(srsym) then
  1829. begin
  1830. check_hints(srsym,srsym.symoptions);
  1831. consume(_ID);
  1832. do_member_read(classh,getaddr,srsym,p1,again,[]);
  1833. end
  1834. else
  1835. begin
  1836. Message1(sym_e_id_no_member,orgpattern);
  1837. p1.destroy;
  1838. p1:=cerrornode.create;
  1839. { try to clean up }
  1840. consume(_ID);
  1841. end;
  1842. end
  1843. else { Error }
  1844. Consume(_ID);
  1845. end;
  1846. pointerdef:
  1847. begin
  1848. Message(parser_e_invalid_qualifier);
  1849. if tpointerdef(p1.resulttype.def).pointertype.def.deftype in [recorddef,objectdef,classrefdef] then
  1850. Message(parser_h_maybe_deref_caret_missing);
  1851. end;
  1852. else
  1853. begin
  1854. Message(parser_e_invalid_qualifier);
  1855. p1.destroy;
  1856. p1:=cerrornode.create;
  1857. { Error }
  1858. consume(_ID);
  1859. end;
  1860. end;
  1861. end;
  1862. else
  1863. begin
  1864. { is this a procedure variable ? }
  1865. if assigned(p1.resulttype.def) and
  1866. (p1.resulttype.def.deftype=procvardef) then
  1867. begin
  1868. if assigned(getprocvardef) and
  1869. equal_defs(p1.resulttype.def,getprocvardef) then
  1870. again:=false
  1871. else
  1872. begin
  1873. if try_to_consume(_LKLAMMER) then
  1874. begin
  1875. p2:=parse_paras(false,_RKLAMMER);
  1876. consume(_RKLAMMER);
  1877. p1:=ccallnode.create_procvar(p2,p1);
  1878. { proc():= is never possible }
  1879. if token=_ASSIGNMENT then
  1880. begin
  1881. Message(parser_e_illegal_expression);
  1882. p1.free;
  1883. p1:=cerrornode.create;
  1884. again:=false;
  1885. end;
  1886. end
  1887. else
  1888. again:=false;
  1889. end;
  1890. end
  1891. else
  1892. again:=false;
  1893. end;
  1894. end;
  1895. end; { while again }
  1896. end;
  1897. {---------------------------------------------
  1898. Factor (Main)
  1899. ---------------------------------------------}
  1900. var
  1901. l : longint;
  1902. ic : int64;
  1903. qc : qword;
  1904. {$ifndef cpu64}
  1905. card : cardinal;
  1906. {$endif cpu64}
  1907. oldp1,
  1908. p1 : tnode;
  1909. code : integer;
  1910. again : boolean;
  1911. srsym : tsym;
  1912. srsymtable : tsymtable;
  1913. pd : tprocdef;
  1914. classh : tobjectdef;
  1915. d : bestreal;
  1916. hs,hsorg : string;
  1917. htype : ttype;
  1918. filepos : tfileposinfo;
  1919. begin
  1920. oldp1:=nil;
  1921. p1:=nil;
  1922. filepos:=akttokenpos;
  1923. again:=false;
  1924. if token=_ID then
  1925. begin
  1926. again:=true;
  1927. { Handle references to self }
  1928. if (idtoken=_SELF) and
  1929. not(block_type in [bt_const,bt_type]) and
  1930. assigned(current_procinfo) and
  1931. assigned(current_procinfo.procdef._class) then
  1932. begin
  1933. p1:=load_self_node;
  1934. consume(_ID);
  1935. again:=true;
  1936. end
  1937. else
  1938. factor_read_id(p1,again);
  1939. if again then
  1940. begin
  1941. if (p1<>oldp1) then
  1942. begin
  1943. if assigned(p1) then
  1944. p1.fileinfo:=filepos;
  1945. oldp1:=p1;
  1946. filepos:=akttokenpos;
  1947. end;
  1948. { handle post fix operators }
  1949. postfixoperators(p1,again);
  1950. end;
  1951. end
  1952. else
  1953. case token of
  1954. _RETURN :
  1955. begin
  1956. consume(_RETURN);
  1957. p1 := cexitnode.create(comp_expr(true));
  1958. end;
  1959. _INHERITED :
  1960. begin
  1961. again:=true;
  1962. consume(_INHERITED);
  1963. if assigned(current_procinfo) and
  1964. assigned(current_procinfo.procdef._class) then
  1965. begin
  1966. classh:=current_procinfo.procdef._class.childof;
  1967. { if inherited; only then we need the method with
  1968. the same name }
  1969. if token in endtokens then
  1970. begin
  1971. hs:=current_procinfo.procdef.procsym.name;
  1972. hsorg:=current_procinfo.procdef.procsym.realname;
  1973. anon_inherited:=true;
  1974. { For message methods we need to search using the message
  1975. number or string }
  1976. pd:=tprocsym(current_procinfo.procdef.procsym).first_procdef;
  1977. if (po_msgint in pd.procoptions) then
  1978. searchsym_in_class_by_msgint(classh,pd.messageinf.i,srsym,srsymtable)
  1979. else
  1980. if (po_msgstr in pd.procoptions) then
  1981. searchsym_in_class_by_msgstr(classh,pd.messageinf.str^,srsym,srsymtable)
  1982. else
  1983. searchsym_in_class(classh,current_procinfo.procdef._class,hs,srsym,srsymtable);
  1984. end
  1985. else
  1986. begin
  1987. hs:=pattern;
  1988. hsorg:=orgpattern;
  1989. consume(_ID);
  1990. anon_inherited:=false;
  1991. searchsym_in_class(classh,current_procinfo.procdef._class,hs,srsym,srsymtable);
  1992. end;
  1993. if assigned(srsym) then
  1994. begin
  1995. check_hints(srsym,srsym.symoptions);
  1996. { load the procdef from the inherited class and
  1997. not from self }
  1998. if srsym.typ in [procsym,propertysym] then
  1999. begin
  2000. if (srsym.typ = procsym) then
  2001. begin
  2002. htype.setdef(classh);
  2003. if (po_classmethod in current_procinfo.procdef.procoptions) or
  2004. (po_staticmethod in current_procinfo.procdef.procoptions) then
  2005. htype.setdef(tclassrefdef.create(htype));
  2006. p1:=ctypenode.create(htype);
  2007. end;
  2008. end
  2009. else
  2010. begin
  2011. Message(parser_e_methode_id_expected);
  2012. p1:=cerrornode.create;
  2013. end;
  2014. do_member_read(classh,getaddr,srsym,p1,again,[cnf_inherited,cnf_anon_inherited]);
  2015. end
  2016. else
  2017. begin
  2018. if anon_inherited then
  2019. begin
  2020. { For message methods we need to call DefaultHandler }
  2021. if (po_msgint in pd.procoptions) or
  2022. (po_msgstr in pd.procoptions) then
  2023. begin
  2024. searchsym_in_class(classh,classh,'DEFAULTHANDLER',srsym,srsymtable);
  2025. if not assigned(srsym) or
  2026. (srsym.typ<>procsym) then
  2027. internalerror(200303171);
  2028. p1:=nil;
  2029. do_proc_call(srsym,srsym.owner,classh,false,again,p1,[]);
  2030. end
  2031. else
  2032. begin
  2033. { we need to ignore the inherited; }
  2034. p1:=cnothingnode.create;
  2035. end;
  2036. end
  2037. else
  2038. begin
  2039. Message1(sym_e_id_no_member,hsorg);
  2040. p1:=cerrornode.create;
  2041. end;
  2042. again:=false;
  2043. end;
  2044. { turn auto inheriting off }
  2045. anon_inherited:=false;
  2046. end
  2047. else
  2048. begin
  2049. Message(parser_e_generic_methods_only_in_methods);
  2050. again:=false;
  2051. p1:=cerrornode.create;
  2052. end;
  2053. postfixoperators(p1,again);
  2054. end;
  2055. _INTCONST :
  2056. begin
  2057. {$ifdef cpu64}
  2058. { when already running under 64bit must read int64 constant, because reading
  2059. cardinal first will also succeed (code=0) for values > maxcardinal, because
  2060. range checking is off by default (PFV) }
  2061. val(pattern,ic,code);
  2062. if code=0 then
  2063. begin
  2064. consume(_INTCONST);
  2065. int_to_type(ic,htype);
  2066. p1:=cordconstnode.create(ic,htype,true);
  2067. end
  2068. else
  2069. begin
  2070. { try qword next }
  2071. val(pattern,qc,code);
  2072. if code=0 then
  2073. begin
  2074. consume(_INTCONST);
  2075. htype:=u64inttype;
  2076. p1:=cordconstnode.create(qc,htype,true);
  2077. end;
  2078. end;
  2079. {$else}
  2080. { try cardinal first }
  2081. val(pattern,card,code);
  2082. if code=0 then
  2083. begin
  2084. consume(_INTCONST);
  2085. int_to_type(card,htype);
  2086. p1:=cordconstnode.create(card,htype,true);
  2087. end
  2088. else
  2089. begin
  2090. { then longint }
  2091. val(pattern,l,code);
  2092. if code = 0 then
  2093. begin
  2094. consume(_INTCONST);
  2095. int_to_type(l,htype);
  2096. p1:=cordconstnode.create(l,htype,true);
  2097. end
  2098. else
  2099. begin
  2100. { then int64 }
  2101. val(pattern,ic,code);
  2102. if code=0 then
  2103. begin
  2104. consume(_INTCONST);
  2105. int_to_type(ic,htype);
  2106. p1:=cordconstnode.create(ic,htype,true);
  2107. end
  2108. else
  2109. begin
  2110. { try qword next }
  2111. val(pattern,qc,code);
  2112. if code=0 then
  2113. begin
  2114. consume(_INTCONST);
  2115. htype:=u64inttype;
  2116. p1:=cordconstnode.create(tconstexprint(qc),htype,true);
  2117. end;
  2118. end;
  2119. end;
  2120. end;
  2121. {$endif}
  2122. if code<>0 then
  2123. begin
  2124. { finally float }
  2125. val(pattern,d,code);
  2126. if code<>0 then
  2127. begin
  2128. Message(parser_e_invalid_integer);
  2129. consume(_INTCONST);
  2130. l:=1;
  2131. p1:=cordconstnode.create(l,sinttype,true);
  2132. end
  2133. else
  2134. begin
  2135. consume(_INTCONST);
  2136. p1:=crealconstnode.create(d,pbestrealtype^);
  2137. end;
  2138. end;
  2139. end;
  2140. _REALNUMBER :
  2141. begin
  2142. val(pattern,d,code);
  2143. if code<>0 then
  2144. begin
  2145. Message(parser_e_error_in_real);
  2146. d:=1.0;
  2147. end;
  2148. consume(_REALNUMBER);
  2149. p1:=crealconstnode.create(d,pbestrealtype^);
  2150. end;
  2151. _STRING :
  2152. begin
  2153. string_dec(htype);
  2154. { STRING can be also a type cast }
  2155. if try_to_consume(_LKLAMMER) then
  2156. begin
  2157. p1:=comp_expr(true);
  2158. consume(_RKLAMMER);
  2159. p1:=ctypeconvnode.create_explicit(p1,htype);
  2160. { handle postfix operators here e.g. string(a)[10] }
  2161. again:=true;
  2162. postfixoperators(p1,again);
  2163. end
  2164. else
  2165. p1:=ctypenode.create(htype);
  2166. end;
  2167. _FILE :
  2168. begin
  2169. htype:=cfiletype;
  2170. consume(_FILE);
  2171. { FILE can be also a type cast }
  2172. if try_to_consume(_LKLAMMER) then
  2173. begin
  2174. p1:=comp_expr(true);
  2175. consume(_RKLAMMER);
  2176. p1:=ctypeconvnode.create_explicit(p1,htype);
  2177. { handle postfix operators here e.g. string(a)[10] }
  2178. again:=true;
  2179. postfixoperators(p1,again);
  2180. end
  2181. else
  2182. begin
  2183. p1:=ctypenode.create(htype);
  2184. end;
  2185. end;
  2186. _CSTRING :
  2187. begin
  2188. p1:=cstringconstnode.createstr(pattern);
  2189. consume(_CSTRING);
  2190. end;
  2191. _CCHAR :
  2192. begin
  2193. p1:=cordconstnode.create(ord(pattern[1]),cchartype,true);
  2194. consume(_CCHAR);
  2195. end;
  2196. _CWSTRING:
  2197. begin
  2198. p1:=cstringconstnode.createwstr(patternw);
  2199. consume(_CWSTRING);
  2200. end;
  2201. _CWCHAR:
  2202. begin
  2203. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  2204. consume(_CWCHAR);
  2205. end;
  2206. _KLAMMERAFFE :
  2207. begin
  2208. consume(_KLAMMERAFFE);
  2209. got_addrn:=true;
  2210. { support both @<x> and @(<x>) }
  2211. if try_to_consume(_LKLAMMER) then
  2212. begin
  2213. p1:=factor(true);
  2214. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2215. begin
  2216. again:=true;
  2217. postfixoperators(p1,again);
  2218. end;
  2219. consume(_RKLAMMER);
  2220. end
  2221. else
  2222. p1:=factor(true);
  2223. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2224. begin
  2225. again:=true;
  2226. postfixoperators(p1,again);
  2227. end;
  2228. got_addrn:=false;
  2229. p1:=caddrnode.create(p1);
  2230. if cs_typed_addresses in aktlocalswitches then
  2231. include(p1.flags,nf_typedaddr);
  2232. { Store the procvar that we are expecting, the
  2233. addrn will use the information to find the correct
  2234. procdef or it will return an error }
  2235. if assigned(getprocvardef) and
  2236. (taddrnode(p1).left.nodetype = loadn) then
  2237. taddrnode(p1).getprocvardef:=getprocvardef;
  2238. end;
  2239. _LKLAMMER :
  2240. begin
  2241. consume(_LKLAMMER);
  2242. p1:=comp_expr(true);
  2243. consume(_RKLAMMER);
  2244. { it's not a good solution }
  2245. { but (a+b)^ makes some problems }
  2246. if token in [_CARET,_POINT,_LECKKLAMMER] then
  2247. begin
  2248. again:=true;
  2249. postfixoperators(p1,again);
  2250. end;
  2251. end;
  2252. _LECKKLAMMER :
  2253. begin
  2254. consume(_LECKKLAMMER);
  2255. p1:=factor_read_set;
  2256. consume(_RECKKLAMMER);
  2257. end;
  2258. _PLUS :
  2259. begin
  2260. consume(_PLUS);
  2261. p1:=factor(false);
  2262. { we must generate a new node to do 0+<p1> otherwise the + will
  2263. not be checked }
  2264. p1:=caddnode.create(addn,genintconstnode(0),p1);
  2265. end;
  2266. _MINUS :
  2267. begin
  2268. consume(_MINUS);
  2269. if (token = _INTCONST) then
  2270. begin
  2271. { ugly hack, but necessary to be able to parse }
  2272. { -9223372036854775808 as int64 (JM) }
  2273. pattern := '-'+pattern;
  2274. p1:=sub_expr(oppower,false);
  2275. { -1 ** 4 should be - (1 ** 4) and not
  2276. (-1) ** 4
  2277. This was the reason of tw0869.pp test failure PM }
  2278. if p1.nodetype=starstarn then
  2279. begin
  2280. if tbinarynode(p1).left.nodetype=ordconstn then
  2281. begin
  2282. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  2283. p1:=cunaryminusnode.create(p1);
  2284. end
  2285. else if tbinarynode(p1).left.nodetype=realconstn then
  2286. begin
  2287. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  2288. p1:=cunaryminusnode.create(p1);
  2289. end
  2290. else
  2291. internalerror(20021029);
  2292. end;
  2293. end
  2294. else
  2295. begin
  2296. p1:=sub_expr(oppower,false);
  2297. p1:=cunaryminusnode.create(p1);
  2298. end;
  2299. end;
  2300. _OP_NOT :
  2301. begin
  2302. consume(_OP_NOT);
  2303. p1:=factor(false);
  2304. p1:=cnotnode.create(p1);
  2305. end;
  2306. _TRUE :
  2307. begin
  2308. consume(_TRUE);
  2309. p1:=cordconstnode.create(1,booltype,false);
  2310. end;
  2311. _FALSE :
  2312. begin
  2313. consume(_FALSE);
  2314. p1:=cordconstnode.create(0,booltype,false);
  2315. end;
  2316. _NIL :
  2317. begin
  2318. consume(_NIL);
  2319. p1:=cnilnode.create;
  2320. { It's really ugly code nil^, but delphi allows it }
  2321. if token in [_CARET] then
  2322. begin
  2323. again:=true;
  2324. postfixoperators(p1,again);
  2325. end;
  2326. end;
  2327. else
  2328. begin
  2329. Message(parser_e_illegal_expression);
  2330. p1:=cerrornode.create;
  2331. { recover }
  2332. consume(token);
  2333. end;
  2334. end;
  2335. { generate error node if no node is created }
  2336. if not assigned(p1) then
  2337. begin
  2338. {$ifdef EXTDEBUG}
  2339. Comment(V_Warning,'factor: p1=nil');
  2340. {$endif}
  2341. p1:=cerrornode.create;
  2342. end;
  2343. { get the resulttype for the node }
  2344. if (not assigned(p1.resulttype.def)) then
  2345. do_resulttypepass(p1);
  2346. if assigned(p1) and
  2347. (p1<>oldp1) then
  2348. p1.fileinfo:=filepos;
  2349. factor:=p1;
  2350. end;
  2351. {$ifdef fpc}
  2352. {$maxfpuregisters default}
  2353. {$endif fpc}
  2354. {****************************************************************************
  2355. Sub_Expr
  2356. ****************************************************************************}
  2357. const
  2358. { Warning these stay be ordered !! }
  2359. operator_levels:array[Toperator_precedence] of set of Ttoken=
  2360. ([_LT,_LTE,_GT,_GTE,_EQUAL,_UNEQUAL,_OP_IN],
  2361. [_PLUS,_MINUS,_OP_OR,_PIPE,_OP_XOR],
  2362. [_CARET,_SYMDIF,_STARSTAR,_STAR,_SLASH,
  2363. _OP_AS,_OP_IS,_OP_AND,_AMPERSAND,_OP_DIV,_OP_MOD,_OP_SHL,_OP_SHR],
  2364. [_STARSTAR] );
  2365. function sub_expr(pred_level:Toperator_precedence;accept_equal : boolean):tnode;
  2366. {Reads a subexpression while the operators are of the current precedence
  2367. level, or any higher level. Replaces the old term, simpl_expr and
  2368. simpl2_expr.}
  2369. var
  2370. p1,p2 : tnode;
  2371. oldt : Ttoken;
  2372. filepos : tfileposinfo;
  2373. begin
  2374. if pred_level=highest_precedence then
  2375. p1:=factor(false)
  2376. else
  2377. p1:=sub_expr(succ(pred_level),true);
  2378. repeat
  2379. if (token in operator_levels[pred_level]) and
  2380. ((token<>_EQUAL) or accept_equal) then
  2381. begin
  2382. oldt:=token;
  2383. filepos:=akttokenpos;
  2384. consume(token);
  2385. if pred_level=highest_precedence then
  2386. p2:=factor(false)
  2387. else
  2388. p2:=sub_expr(succ(pred_level),true);
  2389. case oldt of
  2390. _PLUS :
  2391. p1:=caddnode.create(addn,p1,p2);
  2392. _MINUS :
  2393. p1:=caddnode.create(subn,p1,p2);
  2394. _STAR :
  2395. p1:=caddnode.create(muln,p1,p2);
  2396. _SLASH :
  2397. p1:=caddnode.create(slashn,p1,p2);
  2398. _EQUAL :
  2399. p1:=caddnode.create(equaln,p1,p2);
  2400. _GT :
  2401. p1:=caddnode.create(gtn,p1,p2);
  2402. _LT :
  2403. p1:=caddnode.create(ltn,p1,p2);
  2404. _GTE :
  2405. p1:=caddnode.create(gten,p1,p2);
  2406. _LTE :
  2407. p1:=caddnode.create(lten,p1,p2);
  2408. _SYMDIF :
  2409. p1:=caddnode.create(symdifn,p1,p2);
  2410. _STARSTAR :
  2411. p1:=caddnode.create(starstarn,p1,p2);
  2412. _OP_AS :
  2413. p1:=casnode.create(p1,p2);
  2414. _OP_IN :
  2415. p1:=cinnode.create(p1,p2);
  2416. _OP_IS :
  2417. p1:=cisnode.create(p1,p2);
  2418. _OP_OR,
  2419. _PIPE {macpas only} :
  2420. begin
  2421. p1:=caddnode.create(orn,p1,p2);
  2422. if (oldt = _PIPE) then
  2423. include(p1.flags,nf_short_bool);
  2424. end;
  2425. _OP_AND,
  2426. _AMPERSAND {macpas only} :
  2427. begin
  2428. p1:=caddnode.create(andn,p1,p2);
  2429. if (oldt = _AMPERSAND) then
  2430. include(p1.flags,nf_short_bool);
  2431. end;
  2432. _OP_DIV :
  2433. p1:=cmoddivnode.create(divn,p1,p2);
  2434. _OP_NOT :
  2435. p1:=cnotnode.create(p1);
  2436. _OP_MOD :
  2437. p1:=cmoddivnode.create(modn,p1,p2);
  2438. _OP_SHL :
  2439. p1:=cshlshrnode.create(shln,p1,p2);
  2440. _OP_SHR :
  2441. p1:=cshlshrnode.create(shrn,p1,p2);
  2442. _OP_XOR :
  2443. p1:=caddnode.create(xorn,p1,p2);
  2444. _ASSIGNMENT :
  2445. p1:=cassignmentnode.create(p1,p2);
  2446. _CARET :
  2447. p1:=caddnode.create(caretn,p1,p2);
  2448. _UNEQUAL :
  2449. p1:=caddnode.create(unequaln,p1,p2);
  2450. end;
  2451. p1.fileinfo:=filepos;
  2452. end
  2453. else
  2454. break;
  2455. until false;
  2456. sub_expr:=p1;
  2457. end;
  2458. function comp_expr(accept_equal : boolean):tnode;
  2459. var
  2460. oldafterassignment : boolean;
  2461. p1 : tnode;
  2462. begin
  2463. oldafterassignment:=afterassignment;
  2464. afterassignment:=true;
  2465. p1:=sub_expr(opcompare,accept_equal);
  2466. { get the resulttype for this expression }
  2467. if not assigned(p1.resulttype.def) then
  2468. do_resulttypepass(p1);
  2469. afterassignment:=oldafterassignment;
  2470. comp_expr:=p1;
  2471. end;
  2472. function expr : tnode;
  2473. var
  2474. p1,p2 : tnode;
  2475. oldafterassignment : boolean;
  2476. oldp1 : tnode;
  2477. filepos : tfileposinfo;
  2478. begin
  2479. oldafterassignment:=afterassignment;
  2480. p1:=sub_expr(opcompare,true);
  2481. { get the resulttype for this expression }
  2482. if not assigned(p1.resulttype.def) then
  2483. do_resulttypepass(p1);
  2484. filepos:=akttokenpos;
  2485. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  2486. afterassignment:=true;
  2487. oldp1:=p1;
  2488. case token of
  2489. _POINTPOINT :
  2490. begin
  2491. consume(_POINTPOINT);
  2492. p2:=sub_expr(opcompare,true);
  2493. p1:=crangenode.create(p1,p2);
  2494. end;
  2495. _ASSIGNMENT :
  2496. begin
  2497. consume(_ASSIGNMENT);
  2498. if (p1.resulttype.def.deftype=procvardef) then
  2499. getprocvardef:=tprocvardef(p1.resulttype.def);
  2500. p2:=sub_expr(opcompare,true);
  2501. if assigned(getprocvardef) then
  2502. handle_procvar(getprocvardef,p2);
  2503. getprocvardef:=nil;
  2504. p1:=cassignmentnode.create(p1,p2);
  2505. end;
  2506. _PLUSASN :
  2507. begin
  2508. consume(_PLUSASN);
  2509. p2:=sub_expr(opcompare,true);
  2510. p1:=gen_c_style_operator(addn,p1,p2);
  2511. end;
  2512. _MINUSASN :
  2513. begin
  2514. consume(_MINUSASN);
  2515. p2:=sub_expr(opcompare,true);
  2516. p1:=gen_c_style_operator(subn,p1,p2);
  2517. end;
  2518. _STARASN :
  2519. begin
  2520. consume(_STARASN );
  2521. p2:=sub_expr(opcompare,true);
  2522. p1:=gen_c_style_operator(muln,p1,p2);
  2523. end;
  2524. _SLASHASN :
  2525. begin
  2526. consume(_SLASHASN );
  2527. p2:=sub_expr(opcompare,true);
  2528. p1:=gen_c_style_operator(slashn,p1,p2);
  2529. end;
  2530. end;
  2531. { get the resulttype for this expression }
  2532. if not assigned(p1.resulttype.def) then
  2533. do_resulttypepass(p1);
  2534. afterassignment:=oldafterassignment;
  2535. if p1<>oldp1 then
  2536. p1.fileinfo:=filepos;
  2537. expr:=p1;
  2538. end;
  2539. function get_intconst:TConstExprInt;
  2540. {Reads an expression, tries to evalute it and check if it is an integer
  2541. constant. Then the constant is returned.}
  2542. var
  2543. p:tnode;
  2544. begin
  2545. result:=0;
  2546. p:=comp_expr(true);
  2547. if not codegenerror then
  2548. begin
  2549. if (p.nodetype<>ordconstn) or
  2550. not(is_integer(p.resulttype.def)) then
  2551. Message(parser_e_illegal_expression)
  2552. else
  2553. result:=tordconstnode(p).value;
  2554. end;
  2555. p.free;
  2556. end;
  2557. function get_stringconst:string;
  2558. {Reads an expression, tries to evaluate it and checks if it is a string
  2559. constant. Then the constant is returned.}
  2560. var
  2561. p:tnode;
  2562. begin
  2563. get_stringconst:='';
  2564. p:=comp_expr(true);
  2565. if p.nodetype<>stringconstn then
  2566. begin
  2567. if (p.nodetype=ordconstn) and is_char(p.resulttype.def) then
  2568. get_stringconst:=char(tordconstnode(p).value)
  2569. else
  2570. Message(parser_e_illegal_expression);
  2571. end
  2572. else
  2573. get_stringconst:=strpas(tstringconstnode(p).value_str);
  2574. p.free;
  2575. end;
  2576. end.