pexpr.pas 196 KB

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