pexpr.pas 203 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036
  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. result.resultdef:=getansistringdef;
  2972. end
  2973. else
  2974. result:=genconstsymtree(tconstsym(srsym));
  2975. end;
  2976. procsym :
  2977. begin
  2978. result:=nil;
  2979. if (m_delphi in current_settings.modeswitches) and
  2980. (sp_generic_dummy in srsym.symoptions) and
  2981. (token in [_LT,_LSHARPBRACKET]) then
  2982. begin
  2983. result:=cspecializenode.create(nil,getaddr,srsym,unit_found)
  2984. end
  2985. { check if it's a method/class method }
  2986. else if is_member_read(srsym,srsymtable,result,hdef) then
  2987. begin
  2988. { if we are accessing a owner procsym from the nested }
  2989. { class we need to call it as a class member }
  2990. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  2991. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2992. result:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  2993. { not srsymtable.symtabletype since that can be }
  2994. { withsymtable as well }
  2995. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2996. begin
  2997. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],spezcontext);
  2998. spezcontext:=nil;
  2999. end
  3000. else
  3001. { no procsyms in records (yet) }
  3002. internalerror(2007012006);
  3003. end
  3004. else
  3005. begin
  3006. { regular procedure/function call }
  3007. if not unit_found then
  3008. callflags:=[]
  3009. else
  3010. callflags:=[cnf_unit_specified];
  3011. { TP7 uglyness: @proc^ is parsed as (@proc)^,
  3012. but @notproc^ is parsed as @(notproc^) }
  3013. if m_tp_procvar in current_settings.modeswitches then
  3014. tmpgetaddr:=getaddr and not(token in [_POINT,_LECKKLAMMER])
  3015. else
  3016. tmpgetaddr:=getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER]);
  3017. do_proc_call(srsym,srsymtable,nil,tmpgetaddr,
  3018. again,result,callflags,spezcontext);
  3019. spezcontext:=nil;
  3020. end;
  3021. end;
  3022. propertysym :
  3023. begin
  3024. result:=nil;
  3025. { property of a class/object? }
  3026. if is_member_read(srsym,srsymtable,result,hdef) then
  3027. begin
  3028. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3029. { if we are accessing a owner procsym from the nested }
  3030. { class or from a static class method we need to call }
  3031. { it as a class member }
  3032. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3033. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  3034. begin
  3035. result:=ctypenode.create(hdef);
  3036. if not is_record(hdef) then
  3037. result:=cloadvmtaddrnode.create(result);
  3038. end
  3039. else
  3040. result:=load_self_node;
  3041. { not srsymtable.symtabletype since that can be }
  3042. { withsymtable as well }
  3043. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3044. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil)
  3045. else
  3046. { no propertysyms in records (yet) }
  3047. internalerror(2009111510);
  3048. end
  3049. else
  3050. { no method pointer }
  3051. begin
  3052. handle_propertysym(tpropertysym(srsym),srsymtable,result);
  3053. end;
  3054. end;
  3055. labelsym :
  3056. begin
  3057. { Support @label }
  3058. if getaddr then
  3059. begin
  3060. if srsym.owner<>current_procinfo.procdef.localst then
  3061. CGMessage(parser_e_label_outside_proc);
  3062. result:=cloadnode.create(srsym,srsym.owner)
  3063. end
  3064. else
  3065. begin
  3066. consume(_COLON);
  3067. if tlabelsym(srsym).defined then
  3068. Message(sym_e_label_already_defined);
  3069. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  3070. begin
  3071. include(current_procinfo.flags,pi_has_interproclabel);
  3072. if (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  3073. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  3074. end;
  3075. tlabelsym(srsym).defined:=true;
  3076. result:=clabelnode.create(nil,tlabelsym(srsym));
  3077. tlabelsym(srsym).code:=result;
  3078. end;
  3079. end;
  3080. undefinedsym :
  3081. begin
  3082. result:=cnothingnode.Create;
  3083. result.resultdef:=cundefineddef.create(true);
  3084. { clean up previously created dummy symbol }
  3085. srsym.free;
  3086. end;
  3087. errorsym :
  3088. begin
  3089. result:=cerrornode.create;
  3090. if try_to_consume(_LKLAMMER) then
  3091. begin
  3092. parse_paras(false,false,_RKLAMMER);
  3093. consume(_RKLAMMER);
  3094. end;
  3095. end;
  3096. else
  3097. begin
  3098. result:=cerrornode.create;
  3099. Message(parser_e_illegal_expression);
  3100. end;
  3101. end; { end case }
  3102. end;
  3103. function factor(getaddr:boolean;flags:texprflags) : tnode;
  3104. {---------------------------------------------
  3105. Factor_read_id
  3106. ---------------------------------------------}
  3107. procedure factor_read_id(out p1:tnode;out again:boolean);
  3108. function findwithsymtable : boolean;
  3109. var
  3110. hp : psymtablestackitem;
  3111. begin
  3112. result:=true;
  3113. hp:=symtablestack.stack;
  3114. while assigned(hp) do
  3115. begin
  3116. if hp^.symtable.symtabletype=withsymtable then
  3117. exit;
  3118. hp:=hp^.next;
  3119. end;
  3120. result:=false;
  3121. end;
  3122. var
  3123. srsym: tsym;
  3124. srsymtable: TSymtable;
  3125. hdef: tdef;
  3126. orgstoredpattern,
  3127. storedpattern: string;
  3128. t : ttoken;
  3129. consumeid,
  3130. wasgenericdummy,
  3131. allowspecialize,
  3132. isspecialize,
  3133. unit_found : boolean;
  3134. dummypos,
  3135. tokenpos: tfileposinfo;
  3136. spezcontext : tspecializationcontext;
  3137. cufflags : tconsume_unitsym_flags;
  3138. begin
  3139. { allow post fix operators }
  3140. again:=true;
  3141. { preinitalize tokenpos }
  3142. tokenpos:=current_filepos;
  3143. p1:=nil;
  3144. spezcontext:=nil;
  3145. { avoid warning }
  3146. fillchar(dummypos,sizeof(dummypos),0);
  3147. allowspecialize:=not (m_delphi in current_settings.modeswitches) and
  3148. not (ef_had_specialize in flags) and
  3149. (block_type in inline_specialization_block_types);
  3150. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  3151. begin
  3152. consume(_ID);
  3153. isspecialize:=true;
  3154. end
  3155. else
  3156. isspecialize:=ef_had_specialize in flags;
  3157. { first check for identifier }
  3158. if token<>_ID then
  3159. begin
  3160. srsym:=generrorsym;
  3161. srsymtable:=nil;
  3162. consume(_ID);
  3163. unit_found:=false;
  3164. end
  3165. else
  3166. begin
  3167. storedpattern:=pattern;
  3168. orgstoredpattern:=orgpattern;
  3169. { store the position of the token before consuming it }
  3170. tokenpos:=current_filepos;
  3171. consumeid:=true;
  3172. srsym:=nil;
  3173. if ef_check_attr_suffix in flags then
  3174. begin
  3175. if not (ef_type_only in flags) then
  3176. internalerror(2019063001);
  3177. consume(_ID);
  3178. consumeid:=false;
  3179. if token<>_POINT then
  3180. searchsym_type(storedpattern+custom_attribute_suffix,srsym,srsymtable);
  3181. end;
  3182. if not assigned(srsym) then
  3183. begin
  3184. if ef_type_only in flags then
  3185. searchsym_type(storedpattern,srsym,srsymtable)
  3186. else
  3187. searchsym(storedpattern,srsym,srsymtable);
  3188. end;
  3189. { handle unit specification like System.Writeln }
  3190. if not isspecialize then
  3191. begin
  3192. cufflags:=[];
  3193. if consumeid then
  3194. include(cufflags,cuf_consume_id);
  3195. if allowspecialize then
  3196. include(cufflags,cuf_allow_specialize);
  3197. if ef_check_attr_suffix in flags then
  3198. include(cufflags,cuf_check_attr_suffix);
  3199. unit_found:=try_consume_unitsym(srsym,srsymtable,t,cufflags,isspecialize,pattern);
  3200. if unit_found then
  3201. consumeid:=true;
  3202. end
  3203. else
  3204. begin
  3205. unit_found:=false;
  3206. t:=_ID;
  3207. end;
  3208. if consumeid then
  3209. begin
  3210. storedpattern:=pattern;
  3211. orgstoredpattern:=orgpattern;
  3212. { store the position of the token before consuming it }
  3213. tokenpos:=current_filepos;
  3214. consume(t);
  3215. end;
  3216. { named parameter support }
  3217. found_arg_name:=false;
  3218. if not(unit_found) and
  3219. not isspecialize and
  3220. named_args_allowed and
  3221. (token=_ASSIGNMENT) then
  3222. begin
  3223. found_arg_name:=true;
  3224. p1:=cstringconstnode.createstr(orgstoredpattern);
  3225. consume(_ASSIGNMENT);
  3226. exit;
  3227. end;
  3228. if isspecialize then
  3229. begin
  3230. if not assigned(srsym) then
  3231. begin
  3232. identifier_not_found(orgstoredpattern,tokenpos);
  3233. srsym:=generrorsym;
  3234. srsymtable:=nil;
  3235. end
  3236. else
  3237. begin
  3238. if not unit_found then
  3239. srsymtable:=nil;
  3240. {$push}
  3241. {$warn 5036 off}
  3242. hdef:=generate_specialization_phase1(spezcontext,nil,unit_found,nil,orgstoredpattern,srsymtable,dummypos);
  3243. {$pop}
  3244. if hdef=generrordef then
  3245. begin
  3246. spezcontext.free;
  3247. spezcontext:=nil;
  3248. srsym:=generrorsym;
  3249. srsymtable:=nil;
  3250. end
  3251. else
  3252. begin
  3253. if hdef.typ in [objectdef,recorddef,procvardef,arraydef] then
  3254. begin
  3255. hdef:=generate_specialization_phase2(spezcontext,tstoreddef(hdef),false,'');
  3256. spezcontext.free;
  3257. spezcontext:=nil;
  3258. if hdef<>generrordef then
  3259. begin
  3260. srsym:=hdef.typesym;
  3261. srsymtable:=srsym.owner;
  3262. end
  3263. else
  3264. begin
  3265. srsym:=generrorsym;
  3266. srsymtable:=nil;
  3267. end;
  3268. end
  3269. else
  3270. if hdef.typ=procdef then
  3271. begin
  3272. if block_type<>bt_body then
  3273. message(parser_e_illegal_expression);
  3274. srsym:=tprocdef(hdef).procsym;
  3275. if assigned(spezcontext.symtable) then
  3276. srsymtable:=spezcontext.symtable
  3277. else
  3278. srsymtable:=srsym.owner;
  3279. end
  3280. else
  3281. internalerror(2015061204);
  3282. end;
  3283. end;
  3284. end;
  3285. wasgenericdummy:=false;
  3286. if assigned(srsym) and
  3287. (sp_generic_dummy in srsym.symoptions) and
  3288. (srsym.typ in [procsym,typesym]) and
  3289. (
  3290. (
  3291. (m_delphi in current_settings.modeswitches) and
  3292. not (token in [_LT, _LSHARPBRACKET]) and
  3293. (
  3294. (
  3295. (srsym.typ=typesym) and
  3296. (ttypesym(srsym).typedef.typ=undefineddef)
  3297. ) or (
  3298. (srsym.typ=procsym) and
  3299. (tprocsym(srsym).procdeflist.count=0)
  3300. )
  3301. )
  3302. )
  3303. or
  3304. (
  3305. not (m_delphi in current_settings.modeswitches) and
  3306. not isspecialize and
  3307. (
  3308. not parse_generic or
  3309. not (
  3310. assigned(current_structdef) and
  3311. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  3312. )
  3313. )
  3314. )
  3315. ) then
  3316. begin
  3317. srsym:=resolve_generic_dummysym(srsym.name);
  3318. if assigned(srsym) then
  3319. srsymtable:=srsym.owner
  3320. else
  3321. begin
  3322. srsymtable:=nil;
  3323. wasgenericdummy:=true;
  3324. end;
  3325. end;
  3326. { check hints, but only if it isn't a potential generic symbol;
  3327. that is checked in sub_expr if it isn't a generic }
  3328. if assigned(srsym) and
  3329. not (
  3330. (srsym.typ=typesym) and
  3331. (
  3332. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) or
  3333. (
  3334. (ttypesym(srsym).typedef.typ=errordef) and
  3335. (sp_generic_dummy in srsym.symoptions)
  3336. )
  3337. ) and
  3338. not (sp_generic_para in srsym.symoptions) and
  3339. (token in [_LT, _LSHARPBRACKET])
  3340. ) then
  3341. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3342. { if nothing found give error and return errorsym }
  3343. if not assigned(srsym) or
  3344. { is this a generic dummy symbol? }
  3345. ((srsym.typ=typesym) and
  3346. assigned(ttypesym(srsym).typedef) and
  3347. (ttypesym(srsym).typedef.typ=undefineddef) and
  3348. not (sp_generic_para in srsym.symoptions) and
  3349. not (token in [_LT, _LSHARPBRACKET]) and
  3350. not (
  3351. { in non-Delphi modes the generic class' name without a
  3352. "specialization" or "<T>" may be used to identify the
  3353. current class }
  3354. (sp_generic_dummy in srsym.symoptions) and
  3355. assigned(current_structdef) and
  3356. (df_generic in current_structdef.defoptions) and
  3357. not (m_delphi in current_settings.modeswitches) and
  3358. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  3359. )) and
  3360. { it could be a rename of a generic para }
  3361. { Note: if this generates false positives we'll need to
  3362. include a "basesym" to tsym to track the original
  3363. symbol }
  3364. not (sp_explicitrename in srsym.symoptions) then
  3365. begin
  3366. { if a generic is parsed and when we are inside an with block,
  3367. a symbol might not be defined }
  3368. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  3369. findwithsymtable then
  3370. begin
  3371. { create dummy symbol, it will be freed later on }
  3372. srsym:=tstoredsym.create(undefinedsym,'$undefinedsym');
  3373. srsymtable:=nil;
  3374. end
  3375. else
  3376. begin
  3377. if wasgenericdummy then
  3378. messagepos(tokenpos,parser_e_no_generics_as_types)
  3379. else
  3380. identifier_not_found(orgstoredpattern,tokenpos);
  3381. srsym:=generrorsym;
  3382. srsymtable:=nil;
  3383. end;
  3384. end;
  3385. end;
  3386. { Access to funcret or need to call the function? }
  3387. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  3388. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  3389. { result(x) is not allowed }
  3390. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  3391. (
  3392. (token=_LKLAMMER) or
  3393. (
  3394. (([m_tp7,m_delphi,m_mac,m_iso,m_extpas] * current_settings.modeswitches) <> []) and
  3395. (afterassignment or in_args)
  3396. )
  3397. ) then
  3398. begin
  3399. hdef:=tdef(srsym.owner.defowner);
  3400. if assigned(hdef) and
  3401. (hdef.typ=procdef) then
  3402. srsym:=tprocdef(hdef).procsym
  3403. else
  3404. begin
  3405. Message(parser_e_illegal_expression);
  3406. srsym:=generrorsym;
  3407. end;
  3408. srsymtable:=srsym.owner;
  3409. end;
  3410. begin
  3411. p1:=factor_handle_sym(srsym,srsymtable,again,getaddr,unit_found,flags,spezcontext);
  3412. if assigned(spezcontext) then
  3413. internalerror(2015061207);
  3414. if assigned(p1) and (p1.nodetype<>errorn) then
  3415. p1.fileinfo:=tokenpos;
  3416. end;
  3417. end;
  3418. {---------------------------------------------
  3419. Factor_Read_Set
  3420. ---------------------------------------------}
  3421. { Read a set between [] }
  3422. function factor_read_set:tnode;
  3423. var
  3424. p1,p2 : tnode;
  3425. lastp,
  3426. buildp : tarrayconstructornode;
  3427. begin
  3428. buildp:=nil;
  3429. lastp:=nil;
  3430. { be sure that a least one arrayconstructn is used, also for an
  3431. empty [] }
  3432. if token=_RECKKLAMMER then
  3433. buildp:=carrayconstructornode.create(nil,buildp)
  3434. else
  3435. repeat
  3436. p1:=comp_expr([ef_accept_equal]);
  3437. if try_to_consume(_POINTPOINT) then
  3438. begin
  3439. p2:=comp_expr([ef_accept_equal]);
  3440. p1:=carrayconstructorrangenode.create(p1,p2);
  3441. end;
  3442. { insert at the end of the tree, to get the correct order }
  3443. if not assigned(buildp) then
  3444. begin
  3445. buildp:=carrayconstructornode.create(p1,nil);
  3446. lastp:=buildp;
  3447. end
  3448. else
  3449. begin
  3450. lastp.right:=carrayconstructornode.create(p1,nil);
  3451. lastp:=tarrayconstructornode(lastp.right);
  3452. end;
  3453. { there could be more elements }
  3454. until not try_to_consume(_COMMA);
  3455. buildp.allow_array_constructor:=block_type in [bt_body,bt_except];
  3456. factor_read_set:=buildp;
  3457. end;
  3458. function can_load_self_node: boolean;
  3459. begin
  3460. result:=false;
  3461. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  3462. not assigned(current_structdef) or
  3463. not assigned(current_procinfo) then
  3464. exit;
  3465. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  3466. end;
  3467. {---------------------------------------------
  3468. Factor (Main)
  3469. ---------------------------------------------}
  3470. var
  3471. l : longint;
  3472. ic : int64;
  3473. qc : qword;
  3474. p1 : tnode;
  3475. code : integer;
  3476. srsym : tsym;
  3477. srsymtable : TSymtable;
  3478. pd : tprocdef;
  3479. hclassdef : tobjectdef;
  3480. d : bestreal;
  3481. hs,hsorg : string;
  3482. hdef : tdef;
  3483. filepos : tfileposinfo;
  3484. callflags : tcallnodeflags;
  3485. idstr : tidstring;
  3486. spezcontext : tspecializationcontext;
  3487. isspecialize,
  3488. mightbegeneric,
  3489. useself,
  3490. dopostfix,
  3491. again,
  3492. updatefpos,
  3493. nodechanged : boolean;
  3494. oldprocvardef : tprocvardef;
  3495. oldfuncrefdef : tobjectdef;
  3496. begin
  3497. { can't keep a copy of p1 and compare pointers afterwards, because
  3498. p1 may be freed and reallocated in the same place! }
  3499. dopostfix:=true;
  3500. updatefpos:=false;
  3501. p1:=nil;
  3502. filepos:=current_tokenpos;
  3503. again:=false;
  3504. pd:=nil;
  3505. isspecialize:=false;
  3506. if token=_ID then
  3507. begin
  3508. again:=true;
  3509. { Handle references to self }
  3510. if (idtoken=_SELF) and can_load_self_node then
  3511. begin
  3512. p1:=load_self_node;
  3513. consume(_ID);
  3514. again:=true;
  3515. end
  3516. else
  3517. factor_read_id(p1,again);
  3518. if assigned(p1) then
  3519. begin
  3520. { factor_read_id will set the filepos to after the id,
  3521. and in case of _SELF the filepos will already be the
  3522. same as filepos (so setting it again doesn't hurt). }
  3523. p1.fileinfo:=filepos;
  3524. filepos:=current_tokenpos;
  3525. end;
  3526. { handle post fix operators }
  3527. if (p1.nodetype=specializen) then
  3528. { post fix operators are handled after specialization }
  3529. dopostfix:=false
  3530. else
  3531. if (m_delphi in current_settings.modeswitches) and
  3532. (block_type=bt_body) and
  3533. (token in [_LT,_LSHARPBRACKET]) then
  3534. begin
  3535. idstr:='';
  3536. case p1.nodetype of
  3537. typen:
  3538. idstr:=ttypenode(p1).typesym.name;
  3539. loadvmtaddrn:
  3540. if tloadvmtaddrnode(p1).left.nodetype=typen then
  3541. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name;
  3542. loadn:
  3543. idstr:=tloadnode(p1).symtableentry.name;
  3544. calln:
  3545. idstr:=tcallnode(p1).symtableprocentry.name;
  3546. else
  3547. ;
  3548. end;
  3549. { if this is the case then the postfix handling is done in
  3550. sub_expr if necessary }
  3551. dopostfix:=not could_be_generic(idstr);
  3552. end;
  3553. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^ is parsed
  3554. as @(notproc^) }
  3555. if (m_tp_procvar in current_settings.modeswitches) and (token=_CARET) and
  3556. getaddr and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym) then
  3557. dopostfix:=false;
  3558. { maybe an additional parameter instead of misusing hadspezialize? }
  3559. if dopostfix and not (ef_had_specialize in flags) then
  3560. updatefpos:=postfixoperators(p1,again,getaddr);
  3561. end
  3562. else
  3563. begin
  3564. updatefpos:=true;
  3565. case token of
  3566. _RETURN :
  3567. begin
  3568. consume(_RETURN);
  3569. p1:=nil;
  3570. if not(token in [_SEMICOLON,_ELSE,_END]) then
  3571. begin
  3572. p1:=comp_expr([ef_accept_equal]);
  3573. if not assigned(current_procinfo) or
  3574. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  3575. is_void(current_procinfo.procdef.returndef) then
  3576. begin
  3577. Message(parser_e_void_function);
  3578. { recovery }
  3579. p1.free;
  3580. p1:=nil;
  3581. end;
  3582. end;
  3583. p1 := cexitnode.create(p1);
  3584. end;
  3585. _INHERITED :
  3586. begin
  3587. again:=true;
  3588. consume(_INHERITED);
  3589. if assigned(current_procinfo) and
  3590. assigned(current_structdef) and
  3591. ((current_structdef.typ=objectdef) or
  3592. ((target_info.system in systems_jvm) and
  3593. (current_structdef.typ=recorddef)))then
  3594. begin
  3595. { for record helpers in mode Delphi "inherited" is not
  3596. allowed }
  3597. if is_objectpascal_helper(current_structdef) and
  3598. (m_delphi in current_settings.modeswitches) and
  3599. (tobjectdef(current_structdef).helpertype=ht_record) then
  3600. Message(parser_e_inherited_not_in_record);
  3601. if (current_structdef.typ=objectdef) then
  3602. begin
  3603. hclassdef:=tobjectdef(current_structdef).childof;
  3604. { Objective-C categories *replace* methods in the class
  3605. they extend, or add methods to it. So calling an
  3606. inherited method always calls the method inherited from
  3607. the parent of the extended class }
  3608. if is_objccategory(current_structdef) then
  3609. hclassdef:=hclassdef.childof;
  3610. end
  3611. else if target_info.system in systems_jvm then
  3612. hclassdef:=java_fpcbaserecordtype
  3613. else
  3614. internalerror(2012012401);
  3615. spezcontext:=nil;
  3616. { if inherited; only then we need the method with
  3617. the same name }
  3618. if token <> _ID then
  3619. begin
  3620. hs:=current_procinfo.procdef.procsym.name;
  3621. hsorg:=current_procinfo.procdef.procsym.realname;
  3622. anon_inherited:=true;
  3623. { For message methods we need to search using the message
  3624. number or string }
  3625. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  3626. srdef:=nil;
  3627. if (po_msgint in pd.procoptions) then
  3628. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  3629. else
  3630. if (po_msgstr in pd.procoptions) then
  3631. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  3632. else
  3633. { helpers have their own ways of dealing with inherited }
  3634. if is_objectpascal_helper(current_structdef) then
  3635. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3636. else
  3637. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3638. end
  3639. else
  3640. begin
  3641. if not (m_delphi in current_settings.modeswitches) and
  3642. (block_type in inline_specialization_block_types) and
  3643. (token=_ID) and
  3644. (idtoken=_SPECIALIZE) then
  3645. begin
  3646. consume(_ID);
  3647. if token<>_ID then
  3648. message(parser_e_methode_id_expected);
  3649. isspecialize:=true;
  3650. end
  3651. else
  3652. isspecialize:=false;
  3653. hs:=pattern;
  3654. hsorg:=orgpattern;
  3655. consume(_ID);
  3656. anon_inherited:=false;
  3657. { helpers have their own ways of dealing with inherited }
  3658. if is_objectpascal_helper(current_structdef) then
  3659. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3660. else
  3661. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3662. if isspecialize and assigned(srsym) then
  3663. begin
  3664. if not handle_specialize_inline_specialization(srsym,false,srsymtable,spezcontext) then
  3665. srsym:=nil;
  3666. end;
  3667. end;
  3668. if assigned(srsym) then
  3669. begin
  3670. mightbegeneric:=(m_delphi in current_settings.modeswitches) and
  3671. (token in [_LT,_LSHARPBRACKET]) and
  3672. (sp_generic_dummy in srsym.symoptions);
  3673. { load the procdef from the inherited class and
  3674. not from self }
  3675. case srsym.typ of
  3676. typesym,
  3677. procsym:
  3678. begin
  3679. { typesym is only a valid choice if we're dealing
  3680. with a potential generic }
  3681. if (srsym.typ=typesym) and not mightbegeneric then
  3682. begin
  3683. Message(parser_e_methode_id_expected);
  3684. p1:=cerrornode.create;
  3685. end
  3686. else
  3687. begin
  3688. useself:=false;
  3689. if is_objectpascal_helper(current_structdef) then
  3690. begin
  3691. { for a helper load the procdef either from the
  3692. extended type, from the parent helper or from
  3693. the extended type of the parent helper
  3694. depending on the def the found symbol belongs
  3695. to }
  3696. if (srsym.Owner.defowner.typ=objectdef) and
  3697. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  3698. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  3699. assigned(tobjectdef(current_structdef).childof) then
  3700. hdef:=tobjectdef(current_structdef).childof
  3701. else
  3702. begin
  3703. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef;
  3704. useself:=true;
  3705. end
  3706. else
  3707. begin
  3708. hdef:=tdef(srsym.Owner.defowner);
  3709. useself:=true;
  3710. end;
  3711. end
  3712. else
  3713. hdef:=hclassdef;
  3714. if (po_classmethod in current_procinfo.procdef.procoptions) or
  3715. (po_staticmethod in current_procinfo.procdef.procoptions) then
  3716. hdef:=cclassrefdef.create(hdef);
  3717. if useself then
  3718. begin
  3719. p1:=ctypeconvnode.create_internal(load_self_node,hdef);
  3720. end
  3721. else
  3722. begin
  3723. p1:=ctypenode.create(hdef);
  3724. { we need to allow helpers here }
  3725. ttypenode(p1).helperallowed:=true;
  3726. end;
  3727. end;
  3728. end;
  3729. propertysym:
  3730. ;
  3731. else
  3732. begin
  3733. Message(parser_e_methode_id_expected);
  3734. p1:=cerrornode.create;
  3735. end;
  3736. end;
  3737. if mightbegeneric then
  3738. begin
  3739. p1:=cspecializenode.create_inherited(p1,getaddr,srsym,hclassdef);
  3740. end
  3741. else
  3742. begin
  3743. if not isspecialize then
  3744. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3745. callflags:=[cnf_inherited];
  3746. include(current_procinfo.flags,pi_has_inherited);
  3747. if anon_inherited then
  3748. include(callflags,cnf_anon_inherited);
  3749. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags,spezcontext);
  3750. end;
  3751. if p1.nodetype=errorn then
  3752. spezcontext.free;
  3753. end
  3754. else
  3755. begin
  3756. if anon_inherited then
  3757. begin
  3758. { For message methods we need to call DefaultHandler }
  3759. if (po_msgint in pd.procoptions) or
  3760. (po_msgstr in pd.procoptions) then
  3761. begin
  3762. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  3763. if not assigned(srsym) or
  3764. (srsym.typ<>procsym) then
  3765. internalerror(200303171);
  3766. p1:=nil;
  3767. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[],nil);
  3768. end
  3769. else
  3770. begin
  3771. { we need to ignore the inherited; }
  3772. p1:=cnothingnode.create;
  3773. end;
  3774. end
  3775. else
  3776. begin
  3777. Message1(sym_e_id_no_member,hsorg);
  3778. p1:=cerrornode.create;
  3779. end;
  3780. again:=false;
  3781. end;
  3782. { turn auto inheriting off }
  3783. anon_inherited:=false;
  3784. end
  3785. else
  3786. begin
  3787. { in case of records we use a more clear error message }
  3788. if assigned(current_structdef) and
  3789. (current_structdef.typ=recorddef) then
  3790. Message(parser_e_inherited_not_in_record)
  3791. else
  3792. Message(parser_e_generic_methods_only_in_methods);
  3793. again:=false;
  3794. p1:=cerrornode.create;
  3795. end;
  3796. if p1.nodetype<>specializen then
  3797. postfixoperators(p1,again,getaddr);
  3798. end;
  3799. _INTCONST :
  3800. begin
  3801. {Try first wether the value fits in an int64.}
  3802. val(pattern,ic,code);
  3803. if code=0 then
  3804. begin
  3805. consume(_INTCONST);
  3806. int_to_type(ic,hdef);
  3807. p1:=cordconstnode.create(ic,hdef,true);
  3808. end
  3809. else
  3810. begin
  3811. { try qword next }
  3812. val(pattern,qc,code);
  3813. if code=0 then
  3814. begin
  3815. consume(_INTCONST);
  3816. int_to_type(qc,hdef);
  3817. p1:=cordconstnode.create(qc,hdef,true);
  3818. end;
  3819. end;
  3820. if code<>0 then
  3821. begin
  3822. { finally float }
  3823. val(pattern,d,code);
  3824. if code<>0 then
  3825. begin
  3826. Message(parser_e_invalid_integer);
  3827. consume(_INTCONST);
  3828. l:=1;
  3829. p1:=cordconstnode.create(l,sinttype,true);
  3830. end
  3831. else
  3832. begin
  3833. consume(_INTCONST);
  3834. p1:=crealconstnode.create(d,pbestrealtype^);
  3835. end;
  3836. end
  3837. else
  3838. { the necessary range checking has already been done by val }
  3839. tordconstnode(p1).rangecheck:=false;
  3840. if token=_POINT then
  3841. begin
  3842. again:=true;
  3843. postfixoperators(p1,again,getaddr);
  3844. end;
  3845. end;
  3846. _REALNUMBER :
  3847. begin
  3848. p1:=real_const_node_from_pattern(pattern);
  3849. consume(_REALNUMBER);
  3850. if token=_POINT then
  3851. begin
  3852. again:=true;
  3853. postfixoperators(p1,again,getaddr);
  3854. end;
  3855. end;
  3856. _STRING :
  3857. begin
  3858. if cs_compilesystem in current_settings.moduleswitches then
  3859. Message(parser_e_nostringaliasinsystem);
  3860. string_dec(hdef,true);
  3861. { STRING can be also a type cast }
  3862. if try_to_consume(_LKLAMMER) then
  3863. begin
  3864. p1:=comp_expr([ef_accept_equal]);
  3865. consume(_RKLAMMER);
  3866. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3867. { handle postfix operators here e.g. string(a)[10] }
  3868. again:=true;
  3869. postfixoperators(p1,again,getaddr);
  3870. end
  3871. else
  3872. begin
  3873. p1:=ctypenode.create(hdef);
  3874. if token=_POINT then
  3875. begin
  3876. again:=true;
  3877. { handle type helpers here }
  3878. postfixoperators(p1,again,getaddr);
  3879. end;
  3880. end;
  3881. end;
  3882. _FILE :
  3883. begin
  3884. hdef:=cfiletype;
  3885. consume(_FILE);
  3886. { FILE can be also a type cast }
  3887. if try_to_consume(_LKLAMMER) then
  3888. begin
  3889. p1:=comp_expr([ef_accept_equal]);
  3890. consume(_RKLAMMER);
  3891. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3892. { handle postfix operators here e.g. string(a)[10] }
  3893. again:=true;
  3894. postfixoperators(p1,again,getaddr);
  3895. end
  3896. else
  3897. begin
  3898. p1:=ctypenode.create(hdef);
  3899. end;
  3900. end;
  3901. _CSTRING :
  3902. begin
  3903. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3904. consume(_CSTRING);
  3905. if token in postfixoperator_tokens then
  3906. begin
  3907. again:=true;
  3908. postfixoperators(p1,again,getaddr);
  3909. end;
  3910. end;
  3911. _CCHAR :
  3912. begin
  3913. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3914. consume(_CCHAR);
  3915. if token=_POINT then
  3916. begin
  3917. again:=true;
  3918. postfixoperators(p1,again,getaddr);
  3919. end;
  3920. end;
  3921. _CWSTRING:
  3922. begin
  3923. if getlengthwidestring(patternw)=1 then
  3924. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true)
  3925. else
  3926. p1:=cstringconstnode.createunistr(patternw);
  3927. consume(_CWSTRING);
  3928. if token in postfixoperator_tokens then
  3929. begin
  3930. again:=true;
  3931. postfixoperators(p1,again,getaddr);
  3932. end;
  3933. end;
  3934. _CWCHAR:
  3935. begin
  3936. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3937. consume(_CWCHAR);
  3938. if token=_POINT then
  3939. begin
  3940. again:=true;
  3941. postfixoperators(p1,again,getaddr);
  3942. end;
  3943. end;
  3944. _KLAMMERAFFE :
  3945. begin
  3946. consume(_KLAMMERAFFE);
  3947. got_addrn:=true;
  3948. { support both @<x> and @(<x>) }
  3949. if try_to_consume(_LKLAMMER) then
  3950. begin
  3951. p1:=factor(true,[]);
  3952. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  3953. if token<>_RKLAMMER then
  3954. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  3955. consume(_RKLAMMER);
  3956. end
  3957. else
  3958. p1:=factor(true,[]);
  3959. if (token in postfixoperator_tokens) and
  3960. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^
  3961. is parsed as @(notproc^) }
  3962. not
  3963. (
  3964. (m_tp_procvar in current_settings.modeswitches) and
  3965. (token=_CARET) and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym)
  3966. )
  3967. then
  3968. begin
  3969. again:=true;
  3970. postfixoperators(p1,again,getaddr);
  3971. end;
  3972. got_addrn:=false;
  3973. p1:=caddrnode.create(p1);
  3974. p1.fileinfo:=filepos;
  3975. if cs_typed_addresses in current_settings.localswitches then
  3976. include(taddrnode(p1).addrnodeflags,anf_typedaddr);
  3977. { Store the procvar that we are expecting, the
  3978. addrn will use the information to find the correct
  3979. procdef or it will return an error }
  3980. if assigned(getprocvardef) and
  3981. (taddrnode(p1).left.nodetype = loadn) then
  3982. taddrnode(p1).getprocvardef:=getprocvardef;
  3983. if (token in postfixoperator_tokens) then
  3984. begin
  3985. again:=true;
  3986. postfixoperators(p1,again,getaddr);
  3987. end;
  3988. end;
  3989. _LKLAMMER :
  3990. begin
  3991. consume(_LKLAMMER);
  3992. p1:=comp_expr([ef_accept_equal]);
  3993. consume(_RKLAMMER);
  3994. { it's not a good solution
  3995. but (a+b)^ makes some problems }
  3996. if token in postfixoperator_tokens then
  3997. begin
  3998. again:=true;
  3999. postfixoperators(p1,again,getaddr);
  4000. end;
  4001. end;
  4002. _LECKKLAMMER :
  4003. begin
  4004. consume(_LECKKLAMMER);
  4005. p1:=factor_read_set;
  4006. consume(_RECKKLAMMER);
  4007. end;
  4008. _PLUS :
  4009. begin
  4010. consume(_PLUS);
  4011. p1:=factor(false,[]);
  4012. p1:=cunaryplusnode.create(p1);
  4013. end;
  4014. _MINUS :
  4015. begin
  4016. consume(_MINUS);
  4017. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  4018. begin
  4019. { ugly hack, but necessary to be able to parse }
  4020. { -9223372036854775808 as int64 (JM) }
  4021. pattern := '-'+pattern;
  4022. p1:=sub_expr(oppower,[],nil);
  4023. { -1 ** 4 should be - (1 ** 4) and not
  4024. (-1) ** 4
  4025. This was the reason of tw0869.pp test failure PM }
  4026. if p1.nodetype=starstarn then
  4027. begin
  4028. if tbinarynode(p1).left.nodetype=ordconstn then
  4029. begin
  4030. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  4031. p1:=cunaryminusnode.create(p1);
  4032. end
  4033. else if tbinarynode(p1).left.nodetype=realconstn then
  4034. begin
  4035. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  4036. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  4037. p1:=cunaryminusnode.create(p1);
  4038. end
  4039. else
  4040. internalerror(20021029);
  4041. end;
  4042. end
  4043. else
  4044. begin
  4045. if m_isolike_unary_minus in current_settings.modeswitches then
  4046. p1:=sub_expr(opmultiply,[],nil)
  4047. else
  4048. p1:=sub_expr(oppower,[],nil);
  4049. p1:=cunaryminusnode.create(p1);
  4050. end;
  4051. end;
  4052. _OP_NOT :
  4053. begin
  4054. consume(_OP_NOT);
  4055. p1:=factor(false,[]);
  4056. p1:=cnotnode.create(p1);
  4057. end;
  4058. _NIL :
  4059. begin
  4060. consume(_NIL);
  4061. p1:=cnilnode.create;
  4062. { It's really ugly code nil^, but delphi allows it }
  4063. if token in [_CARET,_POINT] then
  4064. begin
  4065. again:=true;
  4066. postfixoperators(p1,again,getaddr);
  4067. end;
  4068. end;
  4069. _OBJCPROTOCOL:
  4070. begin
  4071. { The @protocol keyword is used in two ways in Objective-C:
  4072. 1) to declare protocols (~ Object Pascal interfaces)
  4073. 2) to obtain the metaclass (~ Object Pascal) "class of")
  4074. of a declared protocol
  4075. This code is for handling the second case. Because of 1),
  4076. we cannot simply use a system unit symbol.
  4077. }
  4078. consume(_OBJCPROTOCOL);
  4079. consume(_LKLAMMER);
  4080. p1:=factor(false,[]);
  4081. consume(_RKLAMMER);
  4082. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  4083. end;
  4084. _PROCEDURE,
  4085. _FUNCTION:
  4086. begin
  4087. if (block_type=bt_body) and
  4088. (m_anonymous_functions in current_settings.modeswitches) then
  4089. begin
  4090. oldprocvardef:=getprocvardef;
  4091. oldfuncrefdef:=getfuncrefdef;
  4092. getprocvardef:=nil;
  4093. getfuncrefdef:=nil;
  4094. pd:=read_proc([rpf_anonymous],nil);
  4095. getprocvardef:=oldprocvardef;
  4096. getfuncrefdef:=oldfuncrefdef;
  4097. { assume that we try to get the address except if certain
  4098. tokens follow that indicate a call }
  4099. do_proc_call(pd.procsym,pd.owner,nil,not (token in [_POINT,_CARET,_LECKKLAMMER]),
  4100. again,p1,[],nil);
  4101. end
  4102. else
  4103. begin
  4104. Message(parser_e_illegal_expression);
  4105. p1:=cerrornode.create;
  4106. { recover }
  4107. consume(token);
  4108. end;
  4109. end
  4110. else
  4111. begin
  4112. Message(parser_e_illegal_expression);
  4113. p1:=cerrornode.create;
  4114. { recover }
  4115. consume(token);
  4116. end;
  4117. end;
  4118. end;
  4119. { generate error node if no node is created }
  4120. if not assigned(p1) then
  4121. begin
  4122. {$ifdef EXTDEBUG}
  4123. Comment(V_Warning,'factor: p1=nil');
  4124. {$endif}
  4125. p1:=cerrornode.create;
  4126. updatefpos:=true;
  4127. end;
  4128. { get the resultdef for the node if nothing stops us }
  4129. if (not assigned(p1.resultdef)) and dopostfix then
  4130. begin
  4131. do_typecheckpass_changed(p1,nodechanged);
  4132. updatefpos:=updatefpos or nodechanged;
  4133. end;
  4134. if assigned(p1) and
  4135. updatefpos then
  4136. p1.fileinfo:=filepos;
  4137. factor:=p1;
  4138. end;
  4139. {$maxfpuregisters default}
  4140. procedure post_comp_expr_gendef(var def: tdef);
  4141. var
  4142. p1 : tnode;
  4143. again : boolean;
  4144. begin
  4145. if not assigned(def) then
  4146. internalerror(2011053001);
  4147. again:=false;
  4148. { handle potential typecasts, etc }
  4149. p1:=handle_factor_typenode(def,false,again,nil,false);
  4150. { parse postfix operators }
  4151. postfixoperators(p1,again,false);
  4152. if assigned(p1) and (p1.nodetype=typen) then
  4153. def:=ttypenode(p1).typedef
  4154. else
  4155. def:=generrordef;
  4156. end;
  4157. {****************************************************************************
  4158. Sub_Expr
  4159. ****************************************************************************}
  4160. function sub_expr(pred_level:Toperator_precedence;flags:texprflags;factornode:tnode):tnode;
  4161. {Reads a subexpression while the operators are of the current precedence
  4162. level, or any higher level. Replaces the old term, simpl_expr and
  4163. simpl2_expr.}
  4164. function istypenode(n:tnode):boolean;inline;
  4165. { Checks whether the given node is a type node or a VMT node containing a
  4166. typenode. This is used in the code for inline specializations in the
  4167. _LT branch below }
  4168. begin
  4169. result:=assigned(n) and
  4170. (
  4171. (n.nodetype=typen) or
  4172. (
  4173. (n.nodetype=loadvmtaddrn) and
  4174. (tloadvmtaddrnode(n).left.nodetype=typen)
  4175. )
  4176. );
  4177. end;
  4178. function gettypedef(n:tnode):tdef;inline;
  4179. { This returns the typedef that belongs to the given typenode or
  4180. loadvmtaddrnode. n must not be Nil! }
  4181. begin
  4182. if n.nodetype=typen then
  4183. result:=ttypenode(n).typedef
  4184. else
  4185. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  4186. end;
  4187. function gettypedef(sym:tsym):tdef;inline;
  4188. begin
  4189. result:=nil;
  4190. case sym.typ of
  4191. typesym:
  4192. result:=ttypesym(sym).typedef;
  4193. procsym:
  4194. if not (sp_generic_dummy in sym.symoptions) or (tprocsym(sym).procdeflist.count>0) then
  4195. result:=tdef(tprocsym(sym).procdeflist[0]);
  4196. else
  4197. internalerror(2015092701);
  4198. end;
  4199. end;
  4200. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  4201. var
  4202. srsymtable : tsymtable;
  4203. begin
  4204. srsym:=nil;
  4205. case n.nodetype of
  4206. typen:
  4207. srsym:=ttypenode(n).typedef.typesym;
  4208. loadvmtaddrn:
  4209. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  4210. loadn:
  4211. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  4212. srsym:=nil;
  4213. calln:
  4214. srsym:=tcallnode(n).symtableprocentry;
  4215. specializen:
  4216. srsym:=tspecializenode(n).sym;
  4217. { TODO : handle const nodes }
  4218. else
  4219. ;
  4220. end;
  4221. result:=assigned(srsym);
  4222. end;
  4223. function generate_inline_specialization(gendef:tdef;n:tnode;filepos:tfileposinfo;parseddef:tdef;gensym:tsym;p2:tnode):tnode;
  4224. var
  4225. again,
  4226. getaddr,
  4227. unitspecific : boolean;
  4228. pload : tnode;
  4229. spezcontext : tspecializationcontext;
  4230. structdef,
  4231. inheriteddef : tabstractrecorddef;
  4232. callflags : tcallnodeflags;
  4233. begin
  4234. if n.nodetype=specializen then
  4235. begin
  4236. getaddr:=tspecializenode(n).getaddr;
  4237. pload:=tspecializenode(n).left;
  4238. inheriteddef:=tabstractrecorddef(tspecializenode(n).inheriteddef);
  4239. unitspecific:=tspecializenode(n).unit_specific;
  4240. tspecializenode(n).left:=nil;
  4241. end
  4242. else
  4243. begin
  4244. getaddr:=false;
  4245. pload:=nil;
  4246. inheriteddef:=nil;
  4247. unitspecific:=false;
  4248. end;
  4249. if assigned(parseddef) and assigned(gensym) and assigned(p2) then
  4250. gendef:=generate_specialization_phase1(spezcontext,gendef,unitspecific,parseddef,gensym.realname,gensym.owner,p2.fileinfo)
  4251. else
  4252. gendef:=generate_specialization_phase1(spezcontext,gendef,unitspecific);
  4253. case gendef.typ of
  4254. errordef:
  4255. begin
  4256. spezcontext.free;
  4257. spezcontext:=nil;
  4258. gensym:=generrorsym;
  4259. end;
  4260. objectdef,
  4261. recorddef,
  4262. procvardef,
  4263. arraydef:
  4264. begin
  4265. gendef:=generate_specialization_phase2(spezcontext,tstoreddef(gendef),false,'');
  4266. spezcontext.free;
  4267. spezcontext:=nil;
  4268. if gendef.typ=errordef then
  4269. gensym:=generrorsym
  4270. else
  4271. gensym:=gendef.typesym;
  4272. end;
  4273. procdef:
  4274. begin
  4275. if block_type<>bt_body then
  4276. begin
  4277. message(parser_e_illegal_expression);
  4278. gensym:=generrorsym;
  4279. end
  4280. else
  4281. begin
  4282. gensym:=tprocdef(gendef).procsym;
  4283. end;
  4284. end;
  4285. else
  4286. internalerror(2015092702);
  4287. end;
  4288. { in case of a class or a record the specialized generic
  4289. is always a classrefdef }
  4290. again:=false;
  4291. if assigned(pload) then
  4292. begin
  4293. result:=pload;
  4294. typecheckpass(result);
  4295. structdef:=inheriteddef;
  4296. if not assigned(structdef) then
  4297. case result.resultdef.typ of
  4298. objectdef,
  4299. recorddef:
  4300. begin
  4301. structdef:=tabstractrecorddef(result.resultdef);
  4302. end;
  4303. classrefdef:
  4304. begin
  4305. structdef:=tabstractrecorddef(tclassrefdef(result.resultdef).pointeddef);
  4306. end;
  4307. else
  4308. internalerror(2015092703);
  4309. end;
  4310. if not (structdef.typ in [recorddef,objectdef]) then
  4311. internalerror(2018092101);
  4312. if assigned(inheriteddef) then
  4313. begin
  4314. callflags:=[cnf_inherited];
  4315. include(current_procinfo.flags,pi_has_inherited);
  4316. end
  4317. else
  4318. callflags:=[];
  4319. do_member_read(structdef,getaddr,gensym,result,again,callflags,spezcontext);
  4320. spezcontext:=nil;
  4321. end
  4322. else
  4323. begin
  4324. if gensym.typ=procsym then
  4325. begin
  4326. result:=nil;
  4327. { check if it's a method/class method }
  4328. if is_member_read(gensym,gensym.owner,result,parseddef) then
  4329. begin
  4330. { if we are accessing a owner procsym from the nested }
  4331. { class we need to call it as a class member }
  4332. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  4333. assigned(current_structdef) and (current_structdef<>parseddef) and is_owned_by(current_structdef,parseddef) then
  4334. result:=cloadvmtaddrnode.create(ctypenode.create(parseddef));
  4335. { not srsymtable.symtabletype since that can be }
  4336. { withsymtable as well }
  4337. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  4338. begin
  4339. do_member_read(tabstractrecorddef(parseddef),getaddr,gensym,result,again,[],spezcontext);
  4340. spezcontext:=nil;
  4341. end
  4342. else
  4343. { no procsyms in records (yet) }
  4344. internalerror(2015092704);
  4345. end
  4346. else
  4347. begin
  4348. { regular procedure/function call }
  4349. do_proc_call(gensym,gensym.owner,nil,
  4350. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  4351. again,result,[],spezcontext);
  4352. spezcontext:=nil;
  4353. end;
  4354. end
  4355. else
  4356. { handle potential typecasts, etc }
  4357. result:=handle_factor_typenode(gendef,false,again,nil,false);
  4358. end;
  4359. { parse postfix operators }
  4360. if postfixoperators(result,again,false) then
  4361. if assigned(result) then
  4362. result.fileinfo:=filepos
  4363. else
  4364. result:=cerrornode.create;
  4365. spezcontext.free;
  4366. end;
  4367. function maybe_handle_specialization(var p1,p2:tnode;filepos:tfileposinfo):boolean;
  4368. var
  4369. gensym : tsym;
  4370. parseddef,
  4371. gendef : tdef;
  4372. ptmp : tnode;
  4373. begin
  4374. result:=false;
  4375. { we need to decide whether we have an inline specialization
  4376. (type nodes to the left and right of "<", mode Delphi and
  4377. ">" or "," following) or a normal "<" comparison }
  4378. { TODO : p1 could be a non type if e.g. a variable with the
  4379. same name is defined in the same unit where the
  4380. generic is defined (though "same unit" is not
  4381. necessarily needed) }
  4382. if getgenericsym(p1,gensym) and
  4383. { Attention: when nested specializations are supported
  4384. p2 could be a loadn if a "<" follows }
  4385. istypenode(p2) and
  4386. (m_delphi in current_settings.modeswitches) and
  4387. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  4388. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  4389. begin
  4390. { this is an inline specialization }
  4391. { retrieve the defs of two nodes }
  4392. if p1.nodetype=specializen then
  4393. gendef:=gettypedef(tspecializenode(p1).sym)
  4394. else
  4395. gendef:=nil;
  4396. parseddef:=gettypedef(p2);
  4397. { check the hints for parseddef }
  4398. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg,p1.fileinfo);
  4399. ptmp:=generate_inline_specialization(gendef,p1,filepos,parseddef,gensym,p2);
  4400. { we don't need these nodes anymore }
  4401. p1.free;
  4402. p2.free;
  4403. p1:=ptmp;
  4404. result:=true;
  4405. end;
  4406. end;
  4407. label
  4408. SubExprStart;
  4409. var
  4410. p1,p2,ptmp : tnode;
  4411. oldt : Ttoken;
  4412. filepos : tfileposinfo;
  4413. gendef,parseddef : tdef;
  4414. gensym : tsym;
  4415. genlist : tfpobjectlist;
  4416. dummyagain : boolean;
  4417. dummyspezctxt : tspecializationcontext;
  4418. begin
  4419. SubExprStart:
  4420. if pred_level=highest_precedence then
  4421. begin
  4422. if factornode=nil then
  4423. p1:=factor(false,flags)
  4424. else
  4425. p1:=factornode;
  4426. end
  4427. else
  4428. p1:=sub_expr(succ(pred_level),flags+[ef_accept_equal],factornode);
  4429. repeat
  4430. if (token in [NOTOKEN..last_operator]) and
  4431. (token in operator_levels[pred_level]) and
  4432. ((token<>_EQ) or (ef_accept_equal in flags)) then
  4433. begin
  4434. oldt:=token;
  4435. filepos:=current_tokenpos;
  4436. consume(token);
  4437. if pred_level=highest_precedence then
  4438. p2:=factor(false,[])
  4439. else
  4440. p2:=sub_expr(succ(pred_level),flags+[ef_accept_equal],nil);
  4441. case oldt of
  4442. _PLUS :
  4443. p1:=caddnode.create(addn,p1,p2);
  4444. _MINUS :
  4445. p1:=caddnode.create(subn,p1,p2);
  4446. _STAR :
  4447. p1:=caddnode.create(muln,p1,p2);
  4448. _SLASH :
  4449. p1:=caddnode.create(slashn,p1,p2);
  4450. _EQ:
  4451. p1:=caddnode.create(equaln,p1,p2);
  4452. _GT :
  4453. p1:=caddnode.create(gtn,p1,p2);
  4454. _LT :
  4455. begin
  4456. if maybe_handle_specialization(p1,p2,filepos) then
  4457. begin
  4458. { with p1 now set we are in reality directly behind the
  4459. call to "factor" thus we need to call down to that
  4460. again }
  4461. { This is disabled until specializations on the right
  4462. hand side work as well, because
  4463. "not working expressions" is better than "half working
  4464. expressions" }
  4465. {factornode:=p1;
  4466. goto SubExprStart;}
  4467. end
  4468. else
  4469. begin
  4470. { this is a normal "<" comparison }
  4471. { potential generic types that are followed by a "<": }
  4472. if p1.nodetype=specializen then
  4473. begin
  4474. genlist:=tfpobjectlist(current_module.genericdummysyms.find(tspecializenode(p1).sym.name));
  4475. if assigned(genlist) and (genlist.count>0) then
  4476. begin
  4477. gensym:=tgenericdummyentry(genlist.last).resolvedsym;
  4478. check_hints(gensym,gensym.symoptions,gensym.deprecatedmsg,p1.fileinfo);
  4479. dummyagain:=false;
  4480. dummyspezctxt:=nil;
  4481. ptmp:=factor_handle_sym(gensym,
  4482. gensym.owner,
  4483. dummyagain,
  4484. tspecializenode(p1).getaddr,
  4485. false,
  4486. flags,
  4487. dummyspezctxt);
  4488. if dummyagain then
  4489. internalerror(2022012201);
  4490. p1.free;
  4491. p1:=ptmp;
  4492. end
  4493. else
  4494. begin
  4495. identifier_not_found(tspecializenode(p1).sym.realname);
  4496. p1.free;
  4497. p1:=cerrornode.create;
  4498. end;
  4499. end;
  4500. { a) might not have their resultdef set }
  4501. if not assigned(p1.resultdef) then
  4502. do_typecheckpass(p1);
  4503. { b) are not checked whether they are an undefined def,
  4504. but not a generic parameter }
  4505. if (p1.nodetype=typen) and
  4506. (ttypenode(p1).typedef.typ=undefineddef) and
  4507. assigned(ttypenode(p1).typedef.typesym) and
  4508. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  4509. begin
  4510. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  4511. p1.Free;
  4512. p1:=cerrornode.create;
  4513. end;
  4514. { c) don't have their hints checked }
  4515. if istypenode(p1) then
  4516. begin
  4517. gendef:=gettypedef(p1);
  4518. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4519. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4520. end;
  4521. { Note: the second part of the expression will be needed
  4522. for nested specializations }
  4523. if istypenode(p2) {and
  4524. not (token in [_LT, _LSHARPBRACKET])} then
  4525. begin
  4526. gendef:=gettypedef(p2);
  4527. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4528. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4529. end;
  4530. { create the comparison node for "<" }
  4531. p1:=caddnode.create(ltn,p1,p2)
  4532. end;
  4533. end;
  4534. _GTE :
  4535. p1:=caddnode.create(gten,p1,p2);
  4536. _LTE :
  4537. p1:=caddnode.create(lten,p1,p2);
  4538. _SYMDIF :
  4539. p1:=caddnode.create(symdifn,p1,p2);
  4540. _STARSTAR :
  4541. p1:=caddnode.create(starstarn,p1,p2);
  4542. _OP_AS,
  4543. _OP_IS :
  4544. begin
  4545. if (m_delphi in current_settings.modeswitches) and
  4546. (token in [_LT, _LSHARPBRACKET]) and
  4547. getgenericsym(p2,gensym) then
  4548. begin
  4549. { for now we're handling this as a generic declaration;
  4550. there could be cases though (because of operator
  4551. overloading) where this is the wrong decision... }
  4552. if gensym.typ=typesym then
  4553. gendef:=ttypesym(gensym).typedef
  4554. else
  4555. if gensym.typ=procsym then
  4556. gendef:=tdef(tprocsym(gensym).procdeflist[0])
  4557. else
  4558. internalerror(2015072401);
  4559. ptmp:=generate_inline_specialization(gendef,p2,filepos,nil,nil,nil);
  4560. { we don't need the old p2 anymore }
  4561. p2.Free;
  4562. p2:=ptmp;
  4563. { here we don't need to call back down to "factor", thus
  4564. no "goto" }
  4565. end;
  4566. { now generate the "is" or "as" node }
  4567. case oldt of
  4568. _OP_AS:
  4569. p1:=casnode.create(p1,p2);
  4570. _OP_IS:
  4571. p1:=cisnode.create(p1,p2);
  4572. else
  4573. internalerror(2019050528);
  4574. end;
  4575. end;
  4576. _OP_IN :
  4577. p1:=cinnode.create(p1,p2);
  4578. _OP_OR,
  4579. _PIPE {macpas only} :
  4580. begin
  4581. p1:=caddnode.create(orn,p1,p2);
  4582. if (oldt = _PIPE) then
  4583. include(p1.flags,nf_short_bool);
  4584. end;
  4585. _OP_AND,
  4586. _AMPERSAND {macpas only} :
  4587. begin
  4588. p1:=caddnode.create(andn,p1,p2);
  4589. if (oldt = _AMPERSAND) then
  4590. include(p1.flags,nf_short_bool);
  4591. end;
  4592. _OP_DIV :
  4593. p1:=cmoddivnode.create(divn,p1,p2);
  4594. _OP_NOT :
  4595. p1:=cnotnode.create(p1);
  4596. _OP_MOD :
  4597. begin
  4598. p1:=cmoddivnode.create(modn,p1,p2);
  4599. if m_isolike_mod in current_settings.modeswitches then
  4600. include(p1.flags,nf_isomod);
  4601. end;
  4602. _OP_SHL :
  4603. p1:=cshlshrnode.create(shln,p1,p2);
  4604. _OP_SHR :
  4605. p1:=cshlshrnode.create(shrn,p1,p2);
  4606. _OP_XOR :
  4607. p1:=caddnode.create(xorn,p1,p2);
  4608. _ASSIGNMENT :
  4609. p1:=cassignmentnode.create(p1,p2);
  4610. _NE :
  4611. p1:=caddnode.create(unequaln,p1,p2);
  4612. else
  4613. internalerror(2019050529);
  4614. end;
  4615. p1.fileinfo:=filepos;
  4616. end
  4617. else
  4618. break;
  4619. until false;
  4620. if (p1.nodetype=specializen) and
  4621. (token=_LSHARPBRACKET) and
  4622. (m_delphi in current_settings.modeswitches) then
  4623. begin
  4624. filepos:=current_tokenpos;
  4625. consume(token);
  4626. p2:=factor(false,[]);
  4627. if maybe_handle_specialization(p1,p2,filepos) then
  4628. begin
  4629. { with p1 now set we are in reality directly behind the
  4630. call to "factor" thus we need to call down to that
  4631. again }
  4632. { This is disabled until specializations on the right
  4633. hand side work as well, because
  4634. "not working expressions" is better than "half working
  4635. expressions" }
  4636. {factornode:=p1;
  4637. goto SubExprStart;}
  4638. end else
  4639. message(parser_e_illegal_expression);
  4640. end;
  4641. sub_expr:=p1;
  4642. end;
  4643. function comp_expr(flags:texprflags):tnode;
  4644. var
  4645. oldafterassignment : boolean;
  4646. p1 : tnode;
  4647. begin
  4648. oldafterassignment:=afterassignment;
  4649. afterassignment:=true;
  4650. p1:=sub_expr(opcompare,flags,nil);
  4651. { get the resultdef for this expression }
  4652. if not assigned(p1.resultdef) then
  4653. do_typecheckpass(p1);
  4654. afterassignment:=oldafterassignment;
  4655. comp_expr:=p1;
  4656. end;
  4657. function expr(dotypecheck : boolean) : tnode;
  4658. var
  4659. p1,p2 : tnode;
  4660. filepos : tfileposinfo;
  4661. oldafterassignment,
  4662. updatefpos : boolean;
  4663. oldflags : tnodeflags;
  4664. begin
  4665. oldafterassignment:=afterassignment;
  4666. p1:=sub_expr(opcompare,[ef_accept_equal],nil);
  4667. { get the resultdef for this expression }
  4668. if not assigned(p1.resultdef) and
  4669. dotypecheck then
  4670. do_typecheckpass(p1);
  4671. filepos:=current_tokenpos;
  4672. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  4673. afterassignment:=true;
  4674. updatefpos:=true;
  4675. case token of
  4676. _POINTPOINT :
  4677. begin
  4678. consume(_POINTPOINT);
  4679. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4680. p1:=crangenode.create(p1,p2);
  4681. end;
  4682. _ASSIGNMENT :
  4683. begin
  4684. consume(_ASSIGNMENT);
  4685. if assigned(p1.resultdef) then
  4686. if (p1.resultdef.typ=procvardef) then
  4687. getprocvardef:=tprocvardef(p1.resultdef)
  4688. else if is_invokable(p1.resultdef) then
  4689. getfuncrefdef:=tobjectdef(p1.resultdef);
  4690. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4691. if assigned(getprocvardef) then
  4692. handle_procvar(getprocvardef,p2)
  4693. else if assigned(getfuncrefdef) then
  4694. handle_funcref(getfuncrefdef,p2);
  4695. getprocvardef:=nil;
  4696. getfuncrefdef:=nil;
  4697. p1:=cassignmentnode.create(p1,p2);
  4698. end;
  4699. _PLUSASN :
  4700. begin
  4701. consume(_PLUSASN);
  4702. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4703. p1:=gen_c_style_operator(addn,p1,p2);
  4704. end;
  4705. _MINUSASN :
  4706. begin
  4707. consume(_MINUSASN);
  4708. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4709. p1:=gen_c_style_operator(subn,p1,p2);
  4710. end;
  4711. _STARASN :
  4712. begin
  4713. consume(_STARASN );
  4714. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4715. p1:=gen_c_style_operator(muln,p1,p2);
  4716. end;
  4717. _SLASHASN :
  4718. begin
  4719. consume(_SLASHASN );
  4720. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4721. p1:=gen_c_style_operator(slashn,p1,p2);
  4722. end;
  4723. else
  4724. updatefpos:=false;
  4725. end;
  4726. oldflags:=p1.flags;
  4727. { get the resultdef for this expression }
  4728. if not assigned(p1.resultdef) and
  4729. dotypecheck then
  4730. do_typecheckpass(p1);
  4731. { transfer generic parameter flag }
  4732. if nf_generic_para in oldflags then
  4733. include(p1.flags,nf_generic_para);
  4734. afterassignment:=oldafterassignment;
  4735. if updatefpos then
  4736. p1.fileinfo:=filepos;
  4737. expr:=p1;
  4738. end;
  4739. function get_intconst:TConstExprInt;
  4740. {Reads an expression, tries to evalute it and check if it is an integer
  4741. constant. Then the constant is returned.}
  4742. var
  4743. p:tnode;
  4744. begin
  4745. result:=0;
  4746. p:=comp_expr([ef_accept_equal]);
  4747. if not codegenerror then
  4748. begin
  4749. if (p.nodetype<>ordconstn) or
  4750. not(is_integer(p.resultdef)) then
  4751. Message(parser_e_illegal_expression)
  4752. else
  4753. result:=tordconstnode(p).value;
  4754. end;
  4755. p.free;
  4756. end;
  4757. function get_stringconst:string;
  4758. {Reads an expression, tries to evaluate it and checks if it is a string
  4759. constant. Then the constant is returned.}
  4760. var
  4761. p:tnode;
  4762. snode : tstringconstnode absolute p;
  4763. s : string;
  4764. pw : pcompilerwidestring;
  4765. pc : pansichar;
  4766. begin
  4767. get_stringconst:='';
  4768. p:=comp_expr([ef_accept_equal]);
  4769. if p.nodetype<>stringconstn then
  4770. begin
  4771. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  4772. get_stringconst:=char(int64(tordconstnode(p).value))
  4773. else
  4774. Message(parser_e_illegal_expression);
  4775. end
  4776. else if (tstringconstnode(p).cst_type in [cst_unicodestring,cst_widestring]) then
  4777. begin
  4778. pw:=pcompilerwideString(tstringconstnode(p).value_str);
  4779. pc:=getmem(getlengthwidestring(pw));
  4780. unicode2ascii(pw,pc,current_settings.sourcecodepage);
  4781. get_stringconst:=strpas(pc);
  4782. freemem(pc);
  4783. end
  4784. else
  4785. get_stringconst:=strpas(snode.value_str);
  4786. p.free;
  4787. end;
  4788. end.