pexpr.pas 204 KB

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