pexpr.pas 151 KB

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