pexpr.pas 194 KB

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