pexpr.pas 126 KB

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