pexpr.pas 207 KB

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