pexpr.pas 99 KB

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