pexpr.pas 99 KB

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