pexpr.pas 178 KB

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