pexpr.pas 195 KB

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