pexpr.pas 104 KB

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