pexpr.pas 203 KB

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