pexpr.pas 131 KB

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