pexpr.pas 193 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778
  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(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. { the def of a string const is an array }
  2258. case tstringconstnode(p1).cst_type of
  2259. cst_conststring:
  2260. if cs_refcountedstrings in current_settings.localswitches then
  2261. if m_default_unicodestring in current_settings.modeswitches then
  2262. strdef:=cunicodestringtype
  2263. else
  2264. strdef:=cansistringtype
  2265. else
  2266. strdef:=cshortstringtype;
  2267. cst_shortstring:
  2268. strdef:=cshortstringtype;
  2269. cst_ansistring:
  2270. { use getansistringdef? }
  2271. strdef:=cansistringtype;
  2272. cst_widestring:
  2273. strdef:=cwidestringtype;
  2274. cst_unicodestring:
  2275. strdef:=cunicodestringtype;
  2276. cst_longstring:
  2277. { let's see when someone stumbles upon this...}
  2278. internalerror(201301111);
  2279. end;
  2280. if try_type_helper(p1,strdef) then
  2281. goto skippointdefcheck;
  2282. end;
  2283. { this is skipped if label skippointdefcheck is used }
  2284. case p1.resultdef.typ of
  2285. recorddef:
  2286. begin
  2287. if isspecialize or (token=_ID) then
  2288. begin
  2289. erroroutp1:=true;
  2290. srsym:=nil;
  2291. structh:=tabstractrecorddef(p1.resultdef);
  2292. if isspecialize then
  2293. begin
  2294. { consume the specialize }
  2295. consume(_ID);
  2296. if token<>_ID then
  2297. consume(_ID)
  2298. else
  2299. begin
  2300. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2301. consume(_ID);
  2302. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  2303. erroroutp1:=false;
  2304. end;
  2305. end
  2306. else
  2307. begin
  2308. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2309. if assigned(srsym) then
  2310. begin
  2311. old_current_filepos:=current_filepos;
  2312. consume(_ID);
  2313. if not (sp_generic_dummy in srsym.symoptions) or
  2314. not (token in [_LT,_LSHARPBRACKET]) then
  2315. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2316. else
  2317. p1:=cspecializenode.create(p1,getaddr,srsym);
  2318. erroroutp1:=false;
  2319. end
  2320. else
  2321. begin
  2322. Message1(sym_e_id_no_member,orgpattern);
  2323. { try to clean up }
  2324. consume(_ID);
  2325. end;
  2326. end;
  2327. if erroroutp1 then
  2328. begin
  2329. p1.free;
  2330. p1:=cerrornode.create;
  2331. end
  2332. else
  2333. if p1.nodetype<>specializen then
  2334. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2335. end
  2336. else
  2337. consume(_ID);
  2338. end;
  2339. enumdef:
  2340. begin
  2341. if token=_ID then
  2342. begin
  2343. srsym:=tsym(tenumdef(p1.resultdef).symtable.Find(pattern));
  2344. if assigned(srsym) and (srsym.typ=enumsym) and (p1.nodetype=typen) then
  2345. begin
  2346. p1.destroy;
  2347. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2348. p1:=genenumnode(tenumsym(srsym));
  2349. consume(_ID);
  2350. end
  2351. else
  2352. if not try_type_helper(p1,nil) then
  2353. begin
  2354. p1.destroy;
  2355. Message1(sym_e_id_no_member,orgpattern);
  2356. p1:=cerrornode.create;
  2357. consume(_ID);
  2358. end;
  2359. end;
  2360. end;
  2361. arraydef:
  2362. begin
  2363. if is_dynamic_array(p1.resultdef) then
  2364. begin
  2365. if token=_ID then
  2366. begin
  2367. if not try_type_helper(p1,nil) then
  2368. begin
  2369. if p1.nodetype=typen then
  2370. begin
  2371. if pattern='CREATE' then
  2372. begin
  2373. consume(_ID);
  2374. p2:=parse_array_constructor(tarraydef(p1.resultdef));
  2375. p1.destroy;
  2376. p1:=p2;
  2377. end
  2378. else
  2379. begin
  2380. Message2(scan_f_syn_expected,'CREATE',pattern);
  2381. p1.destroy;
  2382. p1:=cerrornode.create;
  2383. consume(_ID);
  2384. end;
  2385. end
  2386. else
  2387. begin
  2388. Message(parser_e_invalid_qualifier);
  2389. p1.destroy;
  2390. p1:=cerrornode.create;
  2391. consume(_ID);
  2392. end;
  2393. end;
  2394. end
  2395. else
  2396. begin
  2397. Message(parser_e_invalid_qualifier);
  2398. p1.destroy;
  2399. p1:=cerrornode.create;
  2400. consume(_ID);
  2401. end;
  2402. end
  2403. else
  2404. if (token<>_ID) or not try_type_helper(p1,nil) then
  2405. begin
  2406. Message(parser_e_invalid_qualifier);
  2407. p1.destroy;
  2408. p1:=cerrornode.create;
  2409. consume(_ID);
  2410. end;
  2411. end;
  2412. variantdef:
  2413. begin
  2414. { dispatch call? }
  2415. { lhs := v.ident[parameters] -> property get
  2416. lhs := v.ident(parameters) -> method call
  2417. v.ident[parameters] := rhs -> property put
  2418. v.ident(parameters) := rhs -> also property put }
  2419. if token=_ID then
  2420. begin
  2421. if not try_type_helper(p1,nil) then
  2422. begin
  2423. dispatchstring:=orgpattern;
  2424. consume(_ID);
  2425. calltype:=dct_method;
  2426. if try_to_consume(_LKLAMMER) then
  2427. begin
  2428. p2:=parse_paras(false,true,_RKLAMMER);
  2429. consume(_RKLAMMER);
  2430. end
  2431. else if try_to_consume(_LECKKLAMMER) then
  2432. begin
  2433. p2:=parse_paras(false,true,_RECKKLAMMER);
  2434. consume(_RECKKLAMMER);
  2435. calltype:=dct_propget;
  2436. end
  2437. else
  2438. p2:=nil;
  2439. { property setter? }
  2440. if (token=_ASSIGNMENT) and not(afterassignment) then
  2441. begin
  2442. consume(_ASSIGNMENT);
  2443. { read the expression }
  2444. p3:=comp_expr([ef_accept_equal]);
  2445. { concat value parameter too }
  2446. p2:=ccallparanode.create(p3,p2);
  2447. p1:=translate_disp_call(p1,p2,dct_propput,dispatchstring,0,voidtype);
  2448. end
  2449. else
  2450. { this is only an approximation
  2451. setting useresult if not necessary is only a waste of time, no more, no less (FK) }
  2452. if afterassignment or in_args or (token<>_SEMICOLON) then
  2453. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,cvarianttype)
  2454. else
  2455. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,voidtype);
  2456. end;
  2457. end
  2458. else { Error }
  2459. Consume(_ID);
  2460. end;
  2461. classrefdef:
  2462. begin
  2463. erroroutp1:=true;
  2464. if token=_ID then
  2465. begin
  2466. srsym:=nil;
  2467. structh:=tobjectdef(tclassrefdef(p1.resultdef).pointeddef);
  2468. if isspecialize then
  2469. begin
  2470. { consume the specialize }
  2471. consume(_ID);
  2472. if token<>_ID then
  2473. consume(_ID)
  2474. else
  2475. begin
  2476. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2477. consume(_ID);
  2478. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  2479. erroroutp1:=false;
  2480. end;
  2481. end
  2482. else
  2483. begin
  2484. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2485. if assigned(srsym) then
  2486. begin
  2487. old_current_filepos:=current_filepos;
  2488. consume(_ID);
  2489. if not (sp_generic_dummy in srsym.symoptions) or
  2490. not (token in [_LT,_LSHARPBRACKET]) then
  2491. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2492. else
  2493. p1:=cspecializenode.create(p1,getaddr,srsym);
  2494. erroroutp1:=false;
  2495. end
  2496. else
  2497. begin
  2498. Message1(sym_e_id_no_member,orgpattern);
  2499. { try to clean up }
  2500. consume(_ID);
  2501. end;
  2502. end;
  2503. if erroroutp1 then
  2504. begin
  2505. p1.free;
  2506. p1:=cerrornode.create;
  2507. end
  2508. else
  2509. if p1.nodetype<>specializen then
  2510. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2511. end
  2512. else { Error }
  2513. Consume(_ID);
  2514. end;
  2515. objectdef:
  2516. begin
  2517. if isspecialize or (token=_ID) then
  2518. begin
  2519. erroroutp1:=true;
  2520. srsym:=nil;
  2521. structh:=tobjectdef(p1.resultdef);
  2522. if isspecialize then
  2523. begin
  2524. { consume the "specialize" }
  2525. consume(_ID);
  2526. if token<>_ID then
  2527. consume(_ID)
  2528. else
  2529. begin
  2530. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2531. consume(_ID);
  2532. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  2533. erroroutp1:=false;
  2534. end;
  2535. end
  2536. else
  2537. begin
  2538. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2539. if assigned(srsym) then
  2540. begin
  2541. old_current_filepos:=current_filepos;
  2542. consume(_ID);
  2543. if not (sp_generic_dummy in srsym.symoptions) or
  2544. not (token in [_LT,_LSHARPBRACKET]) then
  2545. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2546. else
  2547. p1:=cspecializenode.create(p1,getaddr,srsym);
  2548. erroroutp1:=false;
  2549. end
  2550. else
  2551. begin
  2552. Message1(sym_e_id_no_member,orgpattern);
  2553. { try to clean up }
  2554. consume(_ID);
  2555. end;
  2556. end;
  2557. if erroroutp1 then
  2558. begin
  2559. p1.free;
  2560. p1:=cerrornode.create;
  2561. end
  2562. else
  2563. if p1.nodetype<>specializen then
  2564. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2565. end
  2566. else { Error }
  2567. Consume(_ID);
  2568. end;
  2569. pointerdef:
  2570. begin
  2571. if (p1.resultdef=objc_idtype) then
  2572. begin
  2573. { objc's id type can be used to call any
  2574. Objective-C method of any Objective-C class
  2575. type that's currently in scope }
  2576. if search_objc_method(pattern,srsym,srsymtable) then
  2577. begin
  2578. consume(_ID);
  2579. do_proc_call(srsym,srsymtable,nil,
  2580. (getaddr and not(token in [_CARET,_POINT])),
  2581. again,p1,[cnf_objc_id_call],nil);
  2582. { we need to know which procedure is called }
  2583. do_typecheckpass(p1);
  2584. end
  2585. else
  2586. begin
  2587. consume(_ID);
  2588. Message(parser_e_methode_id_expected);
  2589. end;
  2590. end
  2591. else
  2592. begin
  2593. if not try_type_helper(p1,nil) then
  2594. begin
  2595. Message(parser_e_invalid_qualifier);
  2596. if tpointerdef(p1.resultdef).pointeddef.typ in [recorddef,objectdef,classrefdef] then
  2597. Message(parser_h_maybe_deref_caret_missing);
  2598. end;
  2599. end
  2600. end;
  2601. else
  2602. begin
  2603. if autoderef then
  2604. begin
  2605. { always try with the not dereferenced node }
  2606. p2:=tderefnode(p1).left;
  2607. found:=try_type_helper(p2,nil);
  2608. if found then
  2609. begin
  2610. tderefnode(p1).left:=nil;
  2611. p1.destroy;
  2612. p1:=p2;
  2613. end;
  2614. end
  2615. else
  2616. found:=try_type_helper(p1,nil);
  2617. if not found then
  2618. begin
  2619. if p1.resultdef.typ<>undefineddef then
  2620. Message(parser_e_invalid_qualifier);
  2621. p1.destroy;
  2622. p1:=cerrornode.create;
  2623. { Error }
  2624. consume(_ID);
  2625. end;
  2626. end;
  2627. end;
  2628. { processing an ordconstnode avoids the resultdef check }
  2629. skippointdefcheck:
  2630. end;
  2631. else
  2632. begin
  2633. { is this a procedure variable ? }
  2634. if assigned(p1.resultdef) and
  2635. (p1.resultdef.typ=procvardef) then
  2636. begin
  2637. { Typenode for typecasting or expecting a procvar }
  2638. if (p1.nodetype=typen) or
  2639. (
  2640. assigned(getprocvardef) and
  2641. equal_defs(p1.resultdef,getprocvardef)
  2642. ) then
  2643. begin
  2644. if try_to_consume(_LKLAMMER) then
  2645. begin
  2646. p1:=comp_expr([ef_accept_equal]);
  2647. consume(_RKLAMMER);
  2648. p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
  2649. end
  2650. else
  2651. again:=false
  2652. end
  2653. else
  2654. begin
  2655. if try_to_consume(_LKLAMMER) then
  2656. begin
  2657. p2:=parse_paras(false,false,_RKLAMMER);
  2658. consume(_RKLAMMER);
  2659. p1:=ccallnode.create_procvar(p2,p1);
  2660. { proc():= is never possible }
  2661. if token=_ASSIGNMENT then
  2662. begin
  2663. Message(parser_e_illegal_expression);
  2664. p1.free;
  2665. p1:=cerrornode.create;
  2666. again:=false;
  2667. end;
  2668. end
  2669. else
  2670. again:=false;
  2671. end;
  2672. end
  2673. else
  2674. again:=false;
  2675. end;
  2676. end;
  2677. { we only try again if p1 was changed }
  2678. if again or
  2679. (p1.nodetype=errorn) then
  2680. result:=true;
  2681. end; { while again }
  2682. end;
  2683. function is_member_read(sym: tsym; st: tsymtable; var p1: tnode;
  2684. out memberparentdef: tdef): boolean;
  2685. var
  2686. hdef : tdef;
  2687. begin
  2688. result:=true;
  2689. memberparentdef:=nil;
  2690. case st.symtabletype of
  2691. ObjectSymtable,
  2692. recordsymtable:
  2693. begin
  2694. memberparentdef:=tdef(st.defowner);
  2695. exit;
  2696. end;
  2697. WithSymtable:
  2698. begin
  2699. if assigned(p1) then
  2700. internalerror(2007012002);
  2701. hdef:=tnode(twithsymtable(st).withrefnode).resultdef;
  2702. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  2703. if not(hdef.typ in [objectdef,classrefdef]) then
  2704. exit;
  2705. if (hdef.typ=classrefdef) then
  2706. hdef:=tclassrefdef(hdef).pointeddef;
  2707. memberparentdef:=hdef;
  2708. end;
  2709. else
  2710. result:=false;
  2711. end;
  2712. end;
  2713. {$maxfpuregisters 0}
  2714. function factor(getaddr:boolean;flags:texprflags) : tnode;
  2715. {---------------------------------------------
  2716. Factor_read_id
  2717. ---------------------------------------------}
  2718. procedure factor_read_id(out p1:tnode;out again:boolean);
  2719. function findwithsymtable : boolean;
  2720. var
  2721. hp : psymtablestackitem;
  2722. begin
  2723. result:=true;
  2724. hp:=symtablestack.stack;
  2725. while assigned(hp) do
  2726. begin
  2727. if hp^.symtable.symtabletype=withsymtable then
  2728. exit;
  2729. hp:=hp^.next;
  2730. end;
  2731. result:=false;
  2732. end;
  2733. var
  2734. srsym: tsym;
  2735. srsymtable: TSymtable;
  2736. hdef: tdef;
  2737. pd: tprocdef;
  2738. orgstoredpattern,
  2739. storedpattern: string;
  2740. callflags: tcallnodeflags;
  2741. t : ttoken;
  2742. consumeid,
  2743. wasgenericdummy,
  2744. allowspecialize,
  2745. isspecialize,
  2746. unit_found, tmpgetaddr: boolean;
  2747. dummypos,
  2748. tokenpos: tfileposinfo;
  2749. spezcontext : tspecializationcontext;
  2750. cufflags : tconsume_unitsym_flags;
  2751. begin
  2752. { allow post fix operators }
  2753. again:=true;
  2754. { preinitalize tokenpos }
  2755. tokenpos:=current_filepos;
  2756. p1:=nil;
  2757. spezcontext:=nil;
  2758. { avoid warning }
  2759. fillchar(dummypos,sizeof(dummypos),0);
  2760. allowspecialize:=not (m_delphi in current_settings.modeswitches) and
  2761. not (ef_had_specialize in flags) and
  2762. (block_type in inline_specialization_block_types);
  2763. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  2764. begin
  2765. consume(_ID);
  2766. isspecialize:=true;
  2767. end
  2768. else
  2769. isspecialize:=ef_had_specialize in flags;
  2770. { first check for identifier }
  2771. if token<>_ID then
  2772. begin
  2773. srsym:=generrorsym;
  2774. srsymtable:=nil;
  2775. consume(_ID);
  2776. unit_found:=false;
  2777. end
  2778. else
  2779. begin
  2780. storedpattern:=pattern;
  2781. orgstoredpattern:=orgpattern;
  2782. { store the position of the token before consuming it }
  2783. tokenpos:=current_filepos;
  2784. consumeid:=true;
  2785. srsym:=nil;
  2786. if ef_check_attr_suffix in flags then
  2787. begin
  2788. if not (ef_type_only in flags) then
  2789. internalerror(2019063001);
  2790. consume(_ID);
  2791. consumeid:=false;
  2792. if token<>_POINT then
  2793. searchsym_type(storedpattern+custom_attribute_suffix,srsym,srsymtable);
  2794. end;
  2795. if not assigned(srsym) then
  2796. begin
  2797. if ef_type_only in flags then
  2798. searchsym_type(storedpattern,srsym,srsymtable)
  2799. else
  2800. searchsym(storedpattern,srsym,srsymtable);
  2801. end;
  2802. { handle unit specification like System.Writeln }
  2803. if not isspecialize then
  2804. begin
  2805. cufflags:=[];
  2806. if consumeid then
  2807. include(cufflags,cuf_consume_id);
  2808. if allowspecialize then
  2809. include(cufflags,cuf_allow_specialize);
  2810. if ef_check_attr_suffix in flags then
  2811. include(cufflags,cuf_check_attr_suffix);
  2812. unit_found:=try_consume_unitsym(srsym,srsymtable,t,cufflags,isspecialize,pattern);
  2813. if unit_found then
  2814. consumeid:=true;
  2815. end
  2816. else
  2817. begin
  2818. unit_found:=false;
  2819. t:=_ID;
  2820. end;
  2821. if consumeid then
  2822. begin
  2823. storedpattern:=pattern;
  2824. orgstoredpattern:=orgpattern;
  2825. { store the position of the token before consuming it }
  2826. tokenpos:=current_filepos;
  2827. consume(t);
  2828. end;
  2829. { named parameter support }
  2830. found_arg_name:=false;
  2831. if not(unit_found) and
  2832. not isspecialize and
  2833. named_args_allowed and
  2834. (token=_ASSIGNMENT) then
  2835. begin
  2836. found_arg_name:=true;
  2837. p1:=cstringconstnode.createstr(orgstoredpattern);
  2838. consume(_ASSIGNMENT);
  2839. exit;
  2840. end;
  2841. if isspecialize then
  2842. begin
  2843. if not assigned(srsym) then
  2844. begin
  2845. identifier_not_found(orgstoredpattern,tokenpos);
  2846. srsym:=generrorsym;
  2847. srsymtable:=nil;
  2848. end
  2849. else
  2850. begin
  2851. {$push}
  2852. {$warn 5036 off}
  2853. hdef:=generate_specialization_phase1(spezcontext,nil,nil,orgstoredpattern,nil,dummypos);
  2854. {$pop}
  2855. if hdef=generrordef then
  2856. begin
  2857. spezcontext.free;
  2858. spezcontext:=nil;
  2859. srsym:=generrorsym;
  2860. srsymtable:=nil;
  2861. end
  2862. else
  2863. begin
  2864. if hdef.typ in [objectdef,recorddef,procvardef,arraydef] then
  2865. begin
  2866. hdef:=generate_specialization_phase2(spezcontext,tstoreddef(hdef),false,'');
  2867. spezcontext.free;
  2868. spezcontext:=nil;
  2869. if hdef<>generrordef then
  2870. begin
  2871. srsym:=hdef.typesym;
  2872. srsymtable:=srsym.owner;
  2873. end
  2874. else
  2875. begin
  2876. srsym:=generrorsym;
  2877. srsymtable:=nil;
  2878. end;
  2879. end
  2880. else
  2881. if hdef.typ=procdef then
  2882. begin
  2883. if block_type<>bt_body then
  2884. begin
  2885. message(parser_e_illegal_expression);
  2886. srsym:=generrorsym;
  2887. srsymtable:=nil;
  2888. end
  2889. else
  2890. begin
  2891. srsym:=tprocdef(hdef).procsym;
  2892. if assigned(spezcontext.symtable) then
  2893. srsymtable:=spezcontext.symtable
  2894. else
  2895. srsymtable:=srsym.owner;
  2896. end;
  2897. end
  2898. else
  2899. internalerror(2015061204);
  2900. end;
  2901. end;
  2902. end;
  2903. wasgenericdummy:=false;
  2904. if assigned(srsym) and
  2905. (sp_generic_dummy in srsym.symoptions) and
  2906. (srsym.typ in [procsym,typesym]) and
  2907. (
  2908. (
  2909. (m_delphi in current_settings.modeswitches) and
  2910. not (token in [_LT, _LSHARPBRACKET]) and
  2911. (
  2912. (
  2913. (srsym.typ=typesym) and
  2914. (ttypesym(srsym).typedef.typ=undefineddef)
  2915. ) or (
  2916. (srsym.typ=procsym) and
  2917. (tprocsym(srsym).procdeflist.count=0)
  2918. )
  2919. )
  2920. )
  2921. or
  2922. (
  2923. not (m_delphi in current_settings.modeswitches) and
  2924. not isspecialize and
  2925. (
  2926. not parse_generic or
  2927. not (
  2928. assigned(current_structdef) and
  2929. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  2930. )
  2931. )
  2932. )
  2933. ) then
  2934. begin
  2935. srsym:=resolve_generic_dummysym(srsym.name);
  2936. if assigned(srsym) then
  2937. srsymtable:=srsym.owner
  2938. else
  2939. begin
  2940. srsymtable:=nil;
  2941. wasgenericdummy:=true;
  2942. end;
  2943. end;
  2944. { check hints, but only if it isn't a potential generic symbol;
  2945. that is checked in sub_expr if it isn't a generic }
  2946. if assigned(srsym) and
  2947. not (
  2948. (srsym.typ=typesym) and
  2949. (
  2950. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) or
  2951. (
  2952. (ttypesym(srsym).typedef.typ=errordef) and
  2953. (sp_generic_dummy in srsym.symoptions)
  2954. )
  2955. ) and
  2956. not (sp_generic_para in srsym.symoptions) and
  2957. (token in [_LT, _LSHARPBRACKET])
  2958. ) then
  2959. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2960. { if nothing found give error and return errorsym }
  2961. if not assigned(srsym) or
  2962. { is this a generic dummy symbol? }
  2963. ((srsym.typ=typesym) and
  2964. assigned(ttypesym(srsym).typedef) and
  2965. (ttypesym(srsym).typedef.typ=undefineddef) and
  2966. not (sp_generic_para in srsym.symoptions) and
  2967. not (token in [_LT, _LSHARPBRACKET]) and
  2968. not (
  2969. { in non-Delphi modes the generic class' name without a
  2970. "specialization" or "<T>" may be used to identify the
  2971. current class }
  2972. (sp_generic_dummy in srsym.symoptions) and
  2973. assigned(current_structdef) and
  2974. (df_generic in current_structdef.defoptions) and
  2975. not (m_delphi in current_settings.modeswitches) and
  2976. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  2977. )) and
  2978. { it could be a rename of a generic para }
  2979. { Note: if this generates false positives we'll need to
  2980. include a "basesym" to tsym to track the original
  2981. symbol }
  2982. not (sp_explicitrename in srsym.symoptions) then
  2983. begin
  2984. { if a generic is parsed and when we are inside an with block,
  2985. a symbol might not be defined }
  2986. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  2987. findwithsymtable then
  2988. begin
  2989. { create dummy symbol, it will be freed later on }
  2990. srsym:=tstoredsym.create(undefinedsym,'$undefinedsym');
  2991. srsymtable:=nil;
  2992. end
  2993. else
  2994. begin
  2995. if wasgenericdummy then
  2996. messagepos(tokenpos,parser_e_no_generics_as_types)
  2997. else
  2998. identifier_not_found(orgstoredpattern,tokenpos);
  2999. srsym:=generrorsym;
  3000. srsymtable:=nil;
  3001. end;
  3002. end;
  3003. end;
  3004. { Access to funcret or need to call the function? }
  3005. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  3006. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  3007. { result(x) is not allowed }
  3008. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  3009. (
  3010. (token=_LKLAMMER) or
  3011. (
  3012. (([m_tp7,m_delphi,m_mac,m_iso,m_extpas] * current_settings.modeswitches) <> []) and
  3013. (afterassignment or in_args)
  3014. )
  3015. ) then
  3016. begin
  3017. hdef:=tdef(srsym.owner.defowner);
  3018. if assigned(hdef) and
  3019. (hdef.typ=procdef) then
  3020. srsym:=tprocdef(hdef).procsym
  3021. else
  3022. begin
  3023. Message(parser_e_illegal_expression);
  3024. srsym:=generrorsym;
  3025. end;
  3026. srsymtable:=srsym.owner;
  3027. end;
  3028. begin
  3029. case srsym.typ of
  3030. absolutevarsym :
  3031. begin
  3032. if (tabsolutevarsym(srsym).abstyp=tovar) then
  3033. begin
  3034. p1:=nil;
  3035. propaccesslist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  3036. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vardef);
  3037. include(p1.flags,nf_absolute);
  3038. end
  3039. else
  3040. p1:=cloadnode.create(srsym,srsymtable);
  3041. end;
  3042. staticvarsym,
  3043. localvarsym,
  3044. paravarsym,
  3045. fieldvarsym :
  3046. begin
  3047. { check if we are reading a field of an object/class/ }
  3048. { record. is_member_read() will deal with withsymtables }
  3049. { if needed. }
  3050. p1:=nil;
  3051. if is_member_read(srsym,srsymtable,p1,hdef) then
  3052. begin
  3053. { if the field was originally found in an }
  3054. { objectsymtable, it means it's part of self }
  3055. { if only method from which it was called is }
  3056. { not class static }
  3057. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3058. { if we are accessing a owner procsym from the nested }
  3059. { class we need to call it as a class member }
  3060. if assigned(current_structdef) and
  3061. (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3062. (sp_static in srsym.symoptions)) then
  3063. if srsymtable.symtabletype=recordsymtable then
  3064. p1:=ctypenode.create(hdef)
  3065. else
  3066. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  3067. else
  3068. begin
  3069. if assigned(current_procinfo) then
  3070. begin
  3071. pd:=current_procinfo.get_normal_proc.procdef;
  3072. if assigned(pd) and pd.no_self_node then
  3073. p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  3074. else
  3075. p1:=load_self_node;
  3076. end
  3077. else
  3078. p1:=load_self_node;
  3079. end;
  3080. { now, if the field itself is part of an objectsymtab }
  3081. { (it can be even if it was found in a withsymtable, }
  3082. { e.g., "with classinstance do field := 5"), then }
  3083. { let do_member_read handle it }
  3084. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3085. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[],nil)
  3086. else
  3087. { otherwise it's a regular record subscript }
  3088. p1:=csubscriptnode.create(srsym,p1);
  3089. end
  3090. else
  3091. { regular non-field load }
  3092. p1:=cloadnode.create(srsym,srsymtable);
  3093. end;
  3094. syssym :
  3095. begin
  3096. p1:=statement_syssym(tsyssym(srsym).number);
  3097. end;
  3098. typesym :
  3099. begin
  3100. hdef:=ttypesym(srsym).typedef;
  3101. if not assigned(hdef) then
  3102. begin
  3103. again:=false;
  3104. end
  3105. else
  3106. begin
  3107. if (m_delphi in current_settings.modeswitches) and
  3108. (sp_generic_dummy in srsym.symoptions) and
  3109. (token in [_LT,_LSHARPBRACKET]) then
  3110. begin
  3111. if block_type in [bt_type,bt_const_type,bt_var_type] then
  3112. begin
  3113. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) or (srsym.typ=procsym) then
  3114. begin
  3115. spezcontext.free;
  3116. p1:=cerrornode.create;
  3117. if try_to_consume(_LKLAMMER) then
  3118. begin
  3119. parse_paras(false,false,_RKLAMMER);
  3120. consume(_RKLAMMER);
  3121. end;
  3122. end
  3123. else
  3124. begin
  3125. if srsym.typ<>typesym then
  3126. internalerror(2015071705);
  3127. hdef:=ttypesym(srsym).typedef;
  3128. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  3129. end;
  3130. end
  3131. else
  3132. p1:=cspecializenode.create(nil,getaddr,srsym)
  3133. end
  3134. else
  3135. begin
  3136. { We need to know if this unit uses Variants }
  3137. if ((hdef=cvarianttype) or (hdef=colevarianttype)) and
  3138. not(cs_compilesystem in current_settings.moduleswitches) then
  3139. include(current_module.moduleflags,mf_uses_variants);
  3140. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  3141. end;
  3142. end;
  3143. end;
  3144. enumsym :
  3145. begin
  3146. p1:=genenumnode(tenumsym(srsym));
  3147. end;
  3148. constsym :
  3149. begin
  3150. if tconstsym(srsym).consttyp=constresourcestring then
  3151. begin
  3152. p1:=cloadnode.create(srsym,srsymtable);
  3153. do_typecheckpass(p1);
  3154. p1.resultdef:=getansistringdef;
  3155. end
  3156. else
  3157. p1:=genconstsymtree(tconstsym(srsym));
  3158. end;
  3159. procsym :
  3160. begin
  3161. p1:=nil;
  3162. if (m_delphi in current_settings.modeswitches) and
  3163. (sp_generic_dummy in srsym.symoptions) and
  3164. (token in [_LT,_LSHARPBRACKET]) then
  3165. begin
  3166. p1:=cspecializenode.create(nil,getaddr,srsym)
  3167. end
  3168. { check if it's a method/class method }
  3169. else if is_member_read(srsym,srsymtable,p1,hdef) then
  3170. begin
  3171. { if we are accessing a owner procsym from the nested }
  3172. { class we need to call it as a class member }
  3173. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  3174. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  3175. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  3176. { not srsymtable.symtabletype since that can be }
  3177. { withsymtable as well }
  3178. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3179. begin
  3180. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[],spezcontext);
  3181. spezcontext:=nil;
  3182. end
  3183. else
  3184. { no procsyms in records (yet) }
  3185. internalerror(2007012006);
  3186. end
  3187. else
  3188. begin
  3189. { regular procedure/function call }
  3190. if not unit_found then
  3191. callflags:=[]
  3192. else
  3193. callflags:=[cnf_unit_specified];
  3194. { TP7 uglyness: @proc^ is parsed as (@proc)^,
  3195. but @notproc^ is parsed as @(notproc^) }
  3196. if m_tp_procvar in current_settings.modeswitches then
  3197. tmpgetaddr:=getaddr and not(token in [_POINT,_LECKKLAMMER])
  3198. else
  3199. tmpgetaddr:=getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER]);
  3200. do_proc_call(srsym,srsymtable,nil,tmpgetaddr,
  3201. again,p1,callflags,spezcontext);
  3202. spezcontext:=nil;
  3203. end;
  3204. end;
  3205. propertysym :
  3206. begin
  3207. p1:=nil;
  3208. { property of a class/object? }
  3209. if is_member_read(srsym,srsymtable,p1,hdef) then
  3210. begin
  3211. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3212. { if we are accessing a owner procsym from the nested }
  3213. { class or from a static class method we need to call }
  3214. { it as a class member }
  3215. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3216. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  3217. begin
  3218. p1:=ctypenode.create(hdef);
  3219. if not is_record(hdef) then
  3220. p1:=cloadvmtaddrnode.create(p1);
  3221. end
  3222. else
  3223. p1:=load_self_node;
  3224. { not srsymtable.symtabletype since that can be }
  3225. { withsymtable as well }
  3226. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3227. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[],nil)
  3228. else
  3229. { no propertysyms in records (yet) }
  3230. internalerror(2009111510);
  3231. end
  3232. else
  3233. { no method pointer }
  3234. begin
  3235. handle_propertysym(tpropertysym(srsym),srsymtable,p1);
  3236. end;
  3237. end;
  3238. labelsym :
  3239. begin
  3240. { Support @label }
  3241. if getaddr then
  3242. begin
  3243. if srsym.owner<>current_procinfo.procdef.localst then
  3244. CGMessage(parser_e_label_outside_proc);
  3245. p1:=cloadnode.create(srsym,srsym.owner)
  3246. end
  3247. else
  3248. begin
  3249. consume(_COLON);
  3250. if tlabelsym(srsym).defined then
  3251. Message(sym_e_label_already_defined);
  3252. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  3253. begin
  3254. include(current_procinfo.flags,pi_has_interproclabel);
  3255. if (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  3256. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  3257. end;
  3258. tlabelsym(srsym).defined:=true;
  3259. p1:=clabelnode.create(nil,tlabelsym(srsym));
  3260. tlabelsym(srsym).code:=p1;
  3261. end;
  3262. end;
  3263. undefinedsym :
  3264. begin
  3265. p1:=cnothingnode.Create;
  3266. p1.resultdef:=cundefineddef.create(true);
  3267. { clean up previously created dummy symbol }
  3268. srsym.free;
  3269. end;
  3270. errorsym :
  3271. begin
  3272. p1:=cerrornode.create;
  3273. if try_to_consume(_LKLAMMER) then
  3274. begin
  3275. parse_paras(false,false,_RKLAMMER);
  3276. consume(_RKLAMMER);
  3277. end;
  3278. end;
  3279. else
  3280. begin
  3281. p1:=cerrornode.create;
  3282. Message(parser_e_illegal_expression);
  3283. end;
  3284. end; { end case }
  3285. if assigned(spezcontext) then
  3286. internalerror(2015061207);
  3287. if assigned(p1) and (p1.nodetype<>errorn) then
  3288. p1.fileinfo:=tokenpos;
  3289. end;
  3290. end;
  3291. {---------------------------------------------
  3292. Factor_Read_Set
  3293. ---------------------------------------------}
  3294. { Read a set between [] }
  3295. function factor_read_set:tnode;
  3296. var
  3297. p1,p2 : tnode;
  3298. lastp,
  3299. buildp : tarrayconstructornode;
  3300. begin
  3301. buildp:=nil;
  3302. lastp:=nil;
  3303. { be sure that a least one arrayconstructn is used, also for an
  3304. empty [] }
  3305. if token=_RECKKLAMMER then
  3306. buildp:=carrayconstructornode.create(nil,buildp)
  3307. else
  3308. repeat
  3309. p1:=comp_expr([ef_accept_equal]);
  3310. if try_to_consume(_POINTPOINT) then
  3311. begin
  3312. p2:=comp_expr([ef_accept_equal]);
  3313. p1:=carrayconstructorrangenode.create(p1,p2);
  3314. end;
  3315. { insert at the end of the tree, to get the correct order }
  3316. if not assigned(buildp) then
  3317. begin
  3318. buildp:=carrayconstructornode.create(p1,nil);
  3319. lastp:=buildp;
  3320. end
  3321. else
  3322. begin
  3323. lastp.right:=carrayconstructornode.create(p1,nil);
  3324. lastp:=tarrayconstructornode(lastp.right);
  3325. end;
  3326. { there could be more elements }
  3327. until not try_to_consume(_COMMA);
  3328. buildp.allow_array_constructor:=block_type in [bt_body,bt_except];
  3329. factor_read_set:=buildp;
  3330. end;
  3331. function can_load_self_node: boolean;
  3332. begin
  3333. result:=false;
  3334. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  3335. not assigned(current_structdef) or
  3336. not assigned(current_procinfo) then
  3337. exit;
  3338. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  3339. end;
  3340. {---------------------------------------------
  3341. Factor (Main)
  3342. ---------------------------------------------}
  3343. var
  3344. l : longint;
  3345. ic : int64;
  3346. qc : qword;
  3347. p1 : tnode;
  3348. code : integer;
  3349. srsym : tsym;
  3350. srsymtable : TSymtable;
  3351. pd : tprocdef;
  3352. hclassdef : tobjectdef;
  3353. d : bestreal;
  3354. hs,hsorg : string;
  3355. hdef : tdef;
  3356. filepos : tfileposinfo;
  3357. callflags : tcallnodeflags;
  3358. idstr : tidstring;
  3359. spezcontext : tspecializationcontext;
  3360. isspecialize,
  3361. mightbegeneric,
  3362. useself,
  3363. dopostfix,
  3364. again,
  3365. updatefpos,
  3366. nodechanged : boolean;
  3367. begin
  3368. { can't keep a copy of p1 and compare pointers afterwards, because
  3369. p1 may be freed and reallocated in the same place! }
  3370. dopostfix:=true;
  3371. updatefpos:=false;
  3372. p1:=nil;
  3373. filepos:=current_tokenpos;
  3374. again:=false;
  3375. pd:=nil;
  3376. isspecialize:=false;
  3377. if token=_ID then
  3378. begin
  3379. again:=true;
  3380. { Handle references to self }
  3381. if (idtoken=_SELF) and can_load_self_node then
  3382. begin
  3383. p1:=load_self_node;
  3384. consume(_ID);
  3385. again:=true;
  3386. end
  3387. else
  3388. factor_read_id(p1,again);
  3389. if assigned(p1) then
  3390. begin
  3391. { factor_read_id will set the filepos to after the id,
  3392. and in case of _SELF the filepos will already be the
  3393. same as filepos (so setting it again doesn't hurt). }
  3394. p1.fileinfo:=filepos;
  3395. filepos:=current_tokenpos;
  3396. end;
  3397. { handle post fix operators }
  3398. if (p1.nodetype=specializen) then
  3399. { post fix operators are handled after specialization }
  3400. dopostfix:=false
  3401. else
  3402. if (m_delphi in current_settings.modeswitches) and
  3403. (block_type=bt_body) and
  3404. (token in [_LT,_LSHARPBRACKET]) then
  3405. begin
  3406. idstr:='';
  3407. case p1.nodetype of
  3408. typen:
  3409. idstr:=ttypenode(p1).typesym.name;
  3410. loadvmtaddrn:
  3411. if tloadvmtaddrnode(p1).left.nodetype=typen then
  3412. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name;
  3413. loadn:
  3414. idstr:=tloadnode(p1).symtableentry.name;
  3415. calln:
  3416. idstr:=tcallnode(p1).symtableprocentry.name;
  3417. else
  3418. ;
  3419. end;
  3420. { if this is the case then the postfix handling is done in
  3421. sub_expr if necessary }
  3422. dopostfix:=not could_be_generic(idstr);
  3423. end;
  3424. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^ is parsed
  3425. as @(notproc^) }
  3426. if (m_tp_procvar in current_settings.modeswitches) and (token=_CARET) and
  3427. getaddr and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym) then
  3428. dopostfix:=false;
  3429. { maybe an additional parameter instead of misusing hadspezialize? }
  3430. if dopostfix and not (ef_had_specialize in flags) then
  3431. updatefpos:=postfixoperators(p1,again,getaddr);
  3432. end
  3433. else
  3434. begin
  3435. updatefpos:=true;
  3436. case token of
  3437. _RETURN :
  3438. begin
  3439. consume(_RETURN);
  3440. p1:=nil;
  3441. if not(token in [_SEMICOLON,_ELSE,_END]) then
  3442. begin
  3443. p1:=comp_expr([ef_accept_equal]);
  3444. if not assigned(current_procinfo) or
  3445. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  3446. is_void(current_procinfo.procdef.returndef) then
  3447. begin
  3448. Message(parser_e_void_function);
  3449. { recovery }
  3450. p1.free;
  3451. p1:=nil;
  3452. end;
  3453. end;
  3454. p1 := cexitnode.create(p1);
  3455. end;
  3456. _INHERITED :
  3457. begin
  3458. again:=true;
  3459. consume(_INHERITED);
  3460. if assigned(current_procinfo) and
  3461. assigned(current_structdef) and
  3462. ((current_structdef.typ=objectdef) or
  3463. ((target_info.system in systems_jvm) and
  3464. (current_structdef.typ=recorddef)))then
  3465. begin
  3466. { for record helpers in mode Delphi "inherited" is not
  3467. allowed }
  3468. if is_objectpascal_helper(current_structdef) and
  3469. (m_delphi in current_settings.modeswitches) and
  3470. (tobjectdef(current_structdef).helpertype=ht_record) then
  3471. Message(parser_e_inherited_not_in_record);
  3472. if (current_structdef.typ=objectdef) then
  3473. begin
  3474. hclassdef:=tobjectdef(current_structdef).childof;
  3475. { Objective-C categories *replace* methods in the class
  3476. they extend, or add methods to it. So calling an
  3477. inherited method always calls the method inherited from
  3478. the parent of the extended class }
  3479. if is_objccategory(current_structdef) then
  3480. hclassdef:=hclassdef.childof;
  3481. end
  3482. else if target_info.system in systems_jvm then
  3483. hclassdef:=java_fpcbaserecordtype
  3484. else
  3485. internalerror(2012012401);
  3486. spezcontext:=nil;
  3487. { if inherited; only then we need the method with
  3488. the same name }
  3489. if token <> _ID then
  3490. begin
  3491. hs:=current_procinfo.procdef.procsym.name;
  3492. hsorg:=current_procinfo.procdef.procsym.realname;
  3493. anon_inherited:=true;
  3494. { For message methods we need to search using the message
  3495. number or string }
  3496. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  3497. srdef:=nil;
  3498. if (po_msgint in pd.procoptions) then
  3499. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  3500. else
  3501. if (po_msgstr in pd.procoptions) then
  3502. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  3503. else
  3504. { helpers have their own ways of dealing with inherited }
  3505. if is_objectpascal_helper(current_structdef) then
  3506. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3507. else
  3508. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3509. end
  3510. else
  3511. begin
  3512. if not (m_delphi in current_settings.modeswitches) and
  3513. (block_type in inline_specialization_block_types) and
  3514. (token=_ID) and
  3515. (idtoken=_SPECIALIZE) then
  3516. begin
  3517. consume(_ID);
  3518. if token<>_ID then
  3519. message(parser_e_methode_id_expected);
  3520. isspecialize:=true;
  3521. end
  3522. else
  3523. isspecialize:=false;
  3524. hs:=pattern;
  3525. hsorg:=orgpattern;
  3526. consume(_ID);
  3527. anon_inherited:=false;
  3528. { helpers have their own ways of dealing with inherited }
  3529. if is_objectpascal_helper(current_structdef) then
  3530. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3531. else
  3532. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3533. if isspecialize and assigned(srsym) then
  3534. begin
  3535. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  3536. srsym:=nil;
  3537. end;
  3538. end;
  3539. if assigned(srsym) then
  3540. begin
  3541. mightbegeneric:=(m_delphi in current_settings.modeswitches) and
  3542. (token in [_LT,_LSHARPBRACKET]) and
  3543. (sp_generic_dummy in srsym.symoptions);
  3544. { load the procdef from the inherited class and
  3545. not from self }
  3546. case srsym.typ of
  3547. typesym,
  3548. procsym:
  3549. begin
  3550. { typesym is only a valid choice if we're dealing
  3551. with a potential generic }
  3552. if (srsym.typ=typesym) and not mightbegeneric then
  3553. begin
  3554. Message(parser_e_methode_id_expected);
  3555. p1:=cerrornode.create;
  3556. end
  3557. else
  3558. begin
  3559. useself:=false;
  3560. if is_objectpascal_helper(current_structdef) then
  3561. begin
  3562. { for a helper load the procdef either from the
  3563. extended type, from the parent helper or from
  3564. the extended type of the parent helper
  3565. depending on the def the found symbol belongs
  3566. to }
  3567. if (srsym.Owner.defowner.typ=objectdef) and
  3568. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  3569. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  3570. assigned(tobjectdef(current_structdef).childof) then
  3571. hdef:=tobjectdef(current_structdef).childof
  3572. else
  3573. begin
  3574. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef;
  3575. useself:=true;
  3576. end
  3577. else
  3578. begin
  3579. hdef:=tdef(srsym.Owner.defowner);
  3580. useself:=true;
  3581. end;
  3582. end
  3583. else
  3584. hdef:=hclassdef;
  3585. if (po_classmethod in current_procinfo.procdef.procoptions) or
  3586. (po_staticmethod in current_procinfo.procdef.procoptions) then
  3587. hdef:=cclassrefdef.create(hdef);
  3588. if useself then
  3589. begin
  3590. p1:=ctypeconvnode.create_internal(load_self_node,hdef);
  3591. end
  3592. else
  3593. begin
  3594. p1:=ctypenode.create(hdef);
  3595. { we need to allow helpers here }
  3596. ttypenode(p1).helperallowed:=true;
  3597. end;
  3598. end;
  3599. end;
  3600. propertysym:
  3601. ;
  3602. else
  3603. begin
  3604. Message(parser_e_methode_id_expected);
  3605. p1:=cerrornode.create;
  3606. end;
  3607. end;
  3608. if mightbegeneric then
  3609. begin
  3610. p1:=cspecializenode.create_inherited(p1,getaddr,srsym,hclassdef);
  3611. end
  3612. else
  3613. begin
  3614. if not isspecialize then
  3615. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3616. callflags:=[cnf_inherited];
  3617. include(current_procinfo.flags,pi_has_inherited);
  3618. if anon_inherited then
  3619. include(callflags,cnf_anon_inherited);
  3620. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags,spezcontext);
  3621. end;
  3622. if p1.nodetype=errorn then
  3623. spezcontext.free;
  3624. end
  3625. else
  3626. begin
  3627. if anon_inherited then
  3628. begin
  3629. { For message methods we need to call DefaultHandler }
  3630. if (po_msgint in pd.procoptions) or
  3631. (po_msgstr in pd.procoptions) then
  3632. begin
  3633. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  3634. if not assigned(srsym) or
  3635. (srsym.typ<>procsym) then
  3636. internalerror(200303171);
  3637. p1:=nil;
  3638. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[],nil);
  3639. end
  3640. else
  3641. begin
  3642. { we need to ignore the inherited; }
  3643. p1:=cnothingnode.create;
  3644. end;
  3645. end
  3646. else
  3647. begin
  3648. Message1(sym_e_id_no_member,hsorg);
  3649. p1:=cerrornode.create;
  3650. end;
  3651. again:=false;
  3652. end;
  3653. { turn auto inheriting off }
  3654. anon_inherited:=false;
  3655. end
  3656. else
  3657. begin
  3658. { in case of records we use a more clear error message }
  3659. if assigned(current_structdef) and
  3660. (current_structdef.typ=recorddef) then
  3661. Message(parser_e_inherited_not_in_record)
  3662. else
  3663. Message(parser_e_generic_methods_only_in_methods);
  3664. again:=false;
  3665. p1:=cerrornode.create;
  3666. end;
  3667. if p1.nodetype<>specializen then
  3668. postfixoperators(p1,again,getaddr);
  3669. end;
  3670. _INTCONST :
  3671. begin
  3672. {Try first wether the value fits in an int64.}
  3673. val(pattern,ic,code);
  3674. if code=0 then
  3675. begin
  3676. consume(_INTCONST);
  3677. int_to_type(ic,hdef);
  3678. p1:=cordconstnode.create(ic,hdef,true);
  3679. end
  3680. else
  3681. begin
  3682. { try qword next }
  3683. val(pattern,qc,code);
  3684. if code=0 then
  3685. begin
  3686. consume(_INTCONST);
  3687. int_to_type(qc,hdef);
  3688. p1:=cordconstnode.create(qc,hdef,true);
  3689. end;
  3690. end;
  3691. if code<>0 then
  3692. begin
  3693. { finally float }
  3694. val(pattern,d,code);
  3695. if code<>0 then
  3696. begin
  3697. Message(parser_e_invalid_integer);
  3698. consume(_INTCONST);
  3699. l:=1;
  3700. p1:=cordconstnode.create(l,sinttype,true);
  3701. end
  3702. else
  3703. begin
  3704. consume(_INTCONST);
  3705. p1:=crealconstnode.create(d,pbestrealtype^);
  3706. end;
  3707. end
  3708. else
  3709. { the necessary range checking has already been done by val }
  3710. tordconstnode(p1).rangecheck:=false;
  3711. if token=_POINT then
  3712. begin
  3713. again:=true;
  3714. postfixoperators(p1,again,getaddr);
  3715. end;
  3716. end;
  3717. _REALNUMBER :
  3718. begin
  3719. p1:=real_const_node_from_pattern(pattern);
  3720. consume(_REALNUMBER);
  3721. if token=_POINT then
  3722. begin
  3723. again:=true;
  3724. postfixoperators(p1,again,getaddr);
  3725. end;
  3726. end;
  3727. _STRING :
  3728. begin
  3729. string_dec(hdef,true);
  3730. { STRING can be also a type cast }
  3731. if try_to_consume(_LKLAMMER) then
  3732. begin
  3733. p1:=comp_expr([ef_accept_equal]);
  3734. consume(_RKLAMMER);
  3735. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3736. { handle postfix operators here e.g. string(a)[10] }
  3737. again:=true;
  3738. postfixoperators(p1,again,getaddr);
  3739. end
  3740. else
  3741. begin
  3742. p1:=ctypenode.create(hdef);
  3743. if token=_POINT then
  3744. begin
  3745. again:=true;
  3746. { handle type helpers here }
  3747. postfixoperators(p1,again,getaddr);
  3748. end;
  3749. end;
  3750. end;
  3751. _FILE :
  3752. begin
  3753. hdef:=cfiletype;
  3754. consume(_FILE);
  3755. { FILE can be also a type cast }
  3756. if try_to_consume(_LKLAMMER) then
  3757. begin
  3758. p1:=comp_expr([ef_accept_equal]);
  3759. consume(_RKLAMMER);
  3760. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3761. { handle postfix operators here e.g. string(a)[10] }
  3762. again:=true;
  3763. postfixoperators(p1,again,getaddr);
  3764. end
  3765. else
  3766. begin
  3767. p1:=ctypenode.create(hdef);
  3768. end;
  3769. end;
  3770. _CSTRING :
  3771. begin
  3772. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3773. consume(_CSTRING);
  3774. if token in postfixoperator_tokens then
  3775. begin
  3776. again:=true;
  3777. postfixoperators(p1,again,getaddr);
  3778. end;
  3779. end;
  3780. _CCHAR :
  3781. begin
  3782. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3783. consume(_CCHAR);
  3784. if token=_POINT then
  3785. begin
  3786. again:=true;
  3787. postfixoperators(p1,again,getaddr);
  3788. end;
  3789. end;
  3790. _CWSTRING:
  3791. begin
  3792. if getlengthwidestring(patternw)=1 then
  3793. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true)
  3794. else
  3795. p1:=cstringconstnode.createunistr(patternw);
  3796. consume(_CWSTRING);
  3797. if token in postfixoperator_tokens then
  3798. begin
  3799. again:=true;
  3800. postfixoperators(p1,again,getaddr);
  3801. end;
  3802. end;
  3803. _CWCHAR:
  3804. begin
  3805. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3806. consume(_CWCHAR);
  3807. if token=_POINT then
  3808. begin
  3809. again:=true;
  3810. postfixoperators(p1,again,getaddr);
  3811. end;
  3812. end;
  3813. _KLAMMERAFFE :
  3814. begin
  3815. consume(_KLAMMERAFFE);
  3816. got_addrn:=true;
  3817. { support both @<x> and @(<x>) }
  3818. if try_to_consume(_LKLAMMER) then
  3819. begin
  3820. p1:=factor(true,[]);
  3821. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  3822. if token<>_RKLAMMER then
  3823. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  3824. consume(_RKLAMMER);
  3825. end
  3826. else
  3827. p1:=factor(true,[]);
  3828. if (token in postfixoperator_tokens) and
  3829. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^
  3830. is parsed as @(notproc^) }
  3831. not
  3832. (
  3833. (m_tp_procvar in current_settings.modeswitches) and
  3834. (token=_CARET) and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym)
  3835. )
  3836. then
  3837. begin
  3838. again:=true;
  3839. postfixoperators(p1,again,getaddr);
  3840. end;
  3841. got_addrn:=false;
  3842. p1:=caddrnode.create(p1);
  3843. p1.fileinfo:=filepos;
  3844. if cs_typed_addresses in current_settings.localswitches then
  3845. include(taddrnode(p1).addrnodeflags,anf_typedaddr);
  3846. { Store the procvar that we are expecting, the
  3847. addrn will use the information to find the correct
  3848. procdef or it will return an error }
  3849. if assigned(getprocvardef) and
  3850. (taddrnode(p1).left.nodetype = loadn) then
  3851. taddrnode(p1).getprocvardef:=getprocvardef;
  3852. if (token in postfixoperator_tokens) then
  3853. begin
  3854. again:=true;
  3855. postfixoperators(p1,again,getaddr);
  3856. end;
  3857. end;
  3858. _LKLAMMER :
  3859. begin
  3860. consume(_LKLAMMER);
  3861. p1:=comp_expr([ef_accept_equal]);
  3862. consume(_RKLAMMER);
  3863. { it's not a good solution
  3864. but (a+b)^ makes some problems }
  3865. if token in postfixoperator_tokens then
  3866. begin
  3867. again:=true;
  3868. postfixoperators(p1,again,getaddr);
  3869. end;
  3870. end;
  3871. _LECKKLAMMER :
  3872. begin
  3873. consume(_LECKKLAMMER);
  3874. p1:=factor_read_set;
  3875. consume(_RECKKLAMMER);
  3876. end;
  3877. _PLUS :
  3878. begin
  3879. consume(_PLUS);
  3880. p1:=factor(false,[]);
  3881. p1:=cunaryplusnode.create(p1);
  3882. end;
  3883. _MINUS :
  3884. begin
  3885. consume(_MINUS);
  3886. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  3887. begin
  3888. { ugly hack, but necessary to be able to parse }
  3889. { -9223372036854775808 as int64 (JM) }
  3890. pattern := '-'+pattern;
  3891. p1:=sub_expr(oppower,[],nil);
  3892. { -1 ** 4 should be - (1 ** 4) and not
  3893. (-1) ** 4
  3894. This was the reason of tw0869.pp test failure PM }
  3895. if p1.nodetype=starstarn then
  3896. begin
  3897. if tbinarynode(p1).left.nodetype=ordconstn then
  3898. begin
  3899. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  3900. p1:=cunaryminusnode.create(p1);
  3901. end
  3902. else if tbinarynode(p1).left.nodetype=realconstn then
  3903. begin
  3904. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  3905. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  3906. p1:=cunaryminusnode.create(p1);
  3907. end
  3908. else
  3909. internalerror(20021029);
  3910. end;
  3911. end
  3912. else
  3913. begin
  3914. if m_isolike_unary_minus in current_settings.modeswitches then
  3915. p1:=sub_expr(opmultiply,[],nil)
  3916. else
  3917. p1:=sub_expr(oppower,[],nil);
  3918. p1:=cunaryminusnode.create(p1);
  3919. end;
  3920. end;
  3921. _OP_NOT :
  3922. begin
  3923. consume(_OP_NOT);
  3924. p1:=factor(false,[]);
  3925. p1:=cnotnode.create(p1);
  3926. end;
  3927. _NIL :
  3928. begin
  3929. consume(_NIL);
  3930. p1:=cnilnode.create;
  3931. { It's really ugly code nil^, but delphi allows it }
  3932. if token in [_CARET,_POINT] then
  3933. begin
  3934. again:=true;
  3935. postfixoperators(p1,again,getaddr);
  3936. end;
  3937. end;
  3938. _OBJCPROTOCOL:
  3939. begin
  3940. { The @protocol keyword is used in two ways in Objective-C:
  3941. 1) to declare protocols (~ Object Pascal interfaces)
  3942. 2) to obtain the metaclass (~ Object Pascal) "class of")
  3943. of a declared protocol
  3944. This code is for handling the second case. Because of 1),
  3945. we cannot simply use a system unit symbol.
  3946. }
  3947. consume(_OBJCPROTOCOL);
  3948. consume(_LKLAMMER);
  3949. p1:=factor(false,[]);
  3950. consume(_RKLAMMER);
  3951. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  3952. end;
  3953. else
  3954. begin
  3955. Message(parser_e_illegal_expression);
  3956. p1:=cerrornode.create;
  3957. { recover }
  3958. consume(token);
  3959. end;
  3960. end;
  3961. end;
  3962. { generate error node if no node is created }
  3963. if not assigned(p1) then
  3964. begin
  3965. {$ifdef EXTDEBUG}
  3966. Comment(V_Warning,'factor: p1=nil');
  3967. {$endif}
  3968. p1:=cerrornode.create;
  3969. updatefpos:=true;
  3970. end;
  3971. { get the resultdef for the node if nothing stops us }
  3972. if (not assigned(p1.resultdef)) and dopostfix then
  3973. begin
  3974. do_typecheckpass_changed(p1,nodechanged);
  3975. updatefpos:=updatefpos or nodechanged;
  3976. end;
  3977. if assigned(p1) and
  3978. updatefpos then
  3979. p1.fileinfo:=filepos;
  3980. factor:=p1;
  3981. end;
  3982. {$maxfpuregisters default}
  3983. procedure post_comp_expr_gendef(var def: tdef);
  3984. var
  3985. p1 : tnode;
  3986. again : boolean;
  3987. begin
  3988. if not assigned(def) then
  3989. internalerror(2011053001);
  3990. again:=false;
  3991. { handle potential typecasts, etc }
  3992. p1:=handle_factor_typenode(def,false,again,nil,false);
  3993. { parse postfix operators }
  3994. postfixoperators(p1,again,false);
  3995. if assigned(p1) and (p1.nodetype=typen) then
  3996. def:=ttypenode(p1).typedef
  3997. else
  3998. def:=generrordef;
  3999. end;
  4000. {****************************************************************************
  4001. Sub_Expr
  4002. ****************************************************************************}
  4003. function sub_expr(pred_level:Toperator_precedence;flags:texprflags;factornode:tnode):tnode;
  4004. {Reads a subexpression while the operators are of the current precedence
  4005. level, or any higher level. Replaces the old term, simpl_expr and
  4006. simpl2_expr.}
  4007. function istypenode(n:tnode):boolean;inline;
  4008. { Checks whether the given node is a type node or a VMT node containing a
  4009. typenode. This is used in the code for inline specializations in the
  4010. _LT branch below }
  4011. begin
  4012. result:=assigned(n) and
  4013. (
  4014. (n.nodetype=typen) or
  4015. (
  4016. (n.nodetype=loadvmtaddrn) and
  4017. (tloadvmtaddrnode(n).left.nodetype=typen)
  4018. )
  4019. );
  4020. end;
  4021. function gettypedef(n:tnode):tdef;inline;
  4022. { This returns the typedef that belongs to the given typenode or
  4023. loadvmtaddrnode. n must not be Nil! }
  4024. begin
  4025. if n.nodetype=typen then
  4026. result:=ttypenode(n).typedef
  4027. else
  4028. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  4029. end;
  4030. function gettypedef(sym:tsym):tdef;inline;
  4031. begin
  4032. result:=nil;
  4033. case sym.typ of
  4034. typesym:
  4035. result:=ttypesym(sym).typedef;
  4036. procsym:
  4037. if not (sp_generic_dummy in sym.symoptions) or (tprocsym(sym).procdeflist.count>0) then
  4038. result:=tdef(tprocsym(sym).procdeflist[0]);
  4039. else
  4040. internalerror(2015092701);
  4041. end;
  4042. end;
  4043. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  4044. var
  4045. srsymtable : tsymtable;
  4046. begin
  4047. srsym:=nil;
  4048. case n.nodetype of
  4049. typen:
  4050. srsym:=ttypenode(n).typedef.typesym;
  4051. loadvmtaddrn:
  4052. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  4053. loadn:
  4054. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  4055. srsym:=nil;
  4056. calln:
  4057. srsym:=tcallnode(n).symtableprocentry;
  4058. specializen:
  4059. srsym:=tspecializenode(n).sym;
  4060. { TODO : handle const nodes }
  4061. else
  4062. ;
  4063. end;
  4064. result:=assigned(srsym);
  4065. end;
  4066. function generate_inline_specialization(gendef:tdef;n:tnode;filepos:tfileposinfo;parseddef:tdef;gensym:tsym;p2:tnode):tnode;
  4067. var
  4068. again,
  4069. getaddr : boolean;
  4070. pload : tnode;
  4071. spezcontext : tspecializationcontext;
  4072. structdef,
  4073. inheriteddef : tabstractrecorddef;
  4074. callflags : tcallnodeflags;
  4075. begin
  4076. if n.nodetype=specializen then
  4077. begin
  4078. getaddr:=tspecializenode(n).getaddr;
  4079. pload:=tspecializenode(n).left;
  4080. inheriteddef:=tabstractrecorddef(tspecializenode(n).inheriteddef);
  4081. tspecializenode(n).left:=nil;
  4082. end
  4083. else
  4084. begin
  4085. getaddr:=false;
  4086. pload:=nil;
  4087. inheriteddef:=nil;
  4088. end;
  4089. if assigned(parseddef) and assigned(gensym) and assigned(p2) then
  4090. gendef:=generate_specialization_phase1(spezcontext,gendef,parseddef,gensym.realname,gensym.owner,p2.fileinfo)
  4091. else
  4092. gendef:=generate_specialization_phase1(spezcontext,gendef);
  4093. case gendef.typ of
  4094. errordef:
  4095. begin
  4096. spezcontext.free;
  4097. spezcontext:=nil;
  4098. gensym:=generrorsym;
  4099. end;
  4100. objectdef,
  4101. recorddef,
  4102. procvardef,
  4103. arraydef:
  4104. begin
  4105. gendef:=generate_specialization_phase2(spezcontext,tstoreddef(gendef),false,'');
  4106. spezcontext.free;
  4107. spezcontext:=nil;
  4108. if gendef.typ=errordef then
  4109. gensym:=generrorsym
  4110. else
  4111. gensym:=gendef.typesym;
  4112. end;
  4113. procdef:
  4114. begin
  4115. if block_type<>bt_body then
  4116. begin
  4117. message(parser_e_illegal_expression);
  4118. gensym:=generrorsym;
  4119. end
  4120. else
  4121. begin
  4122. gensym:=tprocdef(gendef).procsym;
  4123. end;
  4124. end;
  4125. else
  4126. internalerror(2015092702);
  4127. end;
  4128. { in case of a class or a record the specialized generic
  4129. is always a classrefdef }
  4130. again:=false;
  4131. if assigned(pload) then
  4132. begin
  4133. result:=pload;
  4134. typecheckpass(result);
  4135. structdef:=inheriteddef;
  4136. if not assigned(structdef) then
  4137. case result.resultdef.typ of
  4138. objectdef,
  4139. recorddef:
  4140. begin
  4141. structdef:=tabstractrecorddef(result.resultdef);
  4142. end;
  4143. classrefdef:
  4144. begin
  4145. structdef:=tabstractrecorddef(tclassrefdef(result.resultdef).pointeddef);
  4146. end;
  4147. else
  4148. internalerror(2015092703);
  4149. end;
  4150. if not (structdef.typ in [recorddef,objectdef]) then
  4151. internalerror(2018092101);
  4152. if assigned(inheriteddef) then
  4153. begin
  4154. callflags:=[cnf_inherited];
  4155. include(current_procinfo.flags,pi_has_inherited);
  4156. end
  4157. else
  4158. callflags:=[];
  4159. do_member_read(structdef,getaddr,gensym,result,again,callflags,spezcontext);
  4160. spezcontext:=nil;
  4161. end
  4162. else
  4163. begin
  4164. if gensym.typ=procsym then
  4165. begin
  4166. result:=nil;
  4167. { check if it's a method/class method }
  4168. if is_member_read(gensym,gensym.owner,result,parseddef) then
  4169. begin
  4170. { if we are accessing a owner procsym from the nested }
  4171. { class we need to call it as a class member }
  4172. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  4173. assigned(current_structdef) and (current_structdef<>parseddef) and is_owned_by(current_structdef,parseddef) then
  4174. result:=cloadvmtaddrnode.create(ctypenode.create(parseddef));
  4175. { not srsymtable.symtabletype since that can be }
  4176. { withsymtable as well }
  4177. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  4178. begin
  4179. do_member_read(tabstractrecorddef(parseddef),getaddr,gensym,result,again,[],spezcontext);
  4180. spezcontext:=nil;
  4181. end
  4182. else
  4183. { no procsyms in records (yet) }
  4184. internalerror(2015092704);
  4185. end
  4186. else
  4187. begin
  4188. { regular procedure/function call }
  4189. do_proc_call(gensym,gensym.owner,nil,
  4190. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  4191. again,result,[],spezcontext);
  4192. spezcontext:=nil;
  4193. end;
  4194. end
  4195. else
  4196. { handle potential typecasts, etc }
  4197. result:=handle_factor_typenode(gendef,false,again,nil,false);
  4198. end;
  4199. { parse postfix operators }
  4200. if postfixoperators(result,again,false) then
  4201. if assigned(result) then
  4202. result.fileinfo:=filepos
  4203. else
  4204. result:=cerrornode.create;
  4205. spezcontext.free;
  4206. end;
  4207. label
  4208. SubExprStart;
  4209. var
  4210. p1,p2,ptmp : tnode;
  4211. oldt : Ttoken;
  4212. filepos : tfileposinfo;
  4213. gendef,parseddef : tdef;
  4214. gensym : tsym;
  4215. begin
  4216. SubExprStart:
  4217. if pred_level=highest_precedence then
  4218. begin
  4219. if factornode=nil then
  4220. p1:=factor(false,flags)
  4221. else
  4222. p1:=factornode;
  4223. end
  4224. else
  4225. p1:=sub_expr(succ(pred_level),flags+[ef_accept_equal],factornode);
  4226. repeat
  4227. if (token in [NOTOKEN..last_operator]) and
  4228. (token in operator_levels[pred_level]) and
  4229. ((token<>_EQ) or (ef_accept_equal in flags)) then
  4230. begin
  4231. oldt:=token;
  4232. filepos:=current_tokenpos;
  4233. consume(token);
  4234. if pred_level=highest_precedence then
  4235. p2:=factor(false,[])
  4236. else
  4237. p2:=sub_expr(succ(pred_level),flags+[ef_accept_equal],nil);
  4238. case oldt of
  4239. _PLUS :
  4240. p1:=caddnode.create(addn,p1,p2);
  4241. _MINUS :
  4242. p1:=caddnode.create(subn,p1,p2);
  4243. _STAR :
  4244. p1:=caddnode.create(muln,p1,p2);
  4245. _SLASH :
  4246. p1:=caddnode.create(slashn,p1,p2);
  4247. _EQ:
  4248. p1:=caddnode.create(equaln,p1,p2);
  4249. _GT :
  4250. p1:=caddnode.create(gtn,p1,p2);
  4251. _LT :
  4252. begin
  4253. { we need to decice whether we have an inline specialization
  4254. (type nodes to the left and right of "<", mode Delphi and
  4255. ">" or "," following) or a normal "<" comparison }
  4256. { TODO : p1 could be a non type if e.g. a variable with the
  4257. same name is defined in the same unit where the
  4258. generic is defined (though "same unit" is not
  4259. necessarily needed) }
  4260. if getgenericsym(p1,gensym) and
  4261. { Attention: when nested specializations are supported
  4262. p2 could be a loadn if a "<" follows }
  4263. istypenode(p2) and
  4264. (m_delphi in current_settings.modeswitches) and
  4265. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  4266. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  4267. begin
  4268. { this is an inline specialization }
  4269. { retrieve the defs of two nodes }
  4270. if p1.nodetype=specializen then
  4271. gendef:=gettypedef(tspecializenode(p1).sym)
  4272. else
  4273. gendef:=nil;
  4274. parseddef:=gettypedef(p2);
  4275. { check the hints for parseddef }
  4276. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg,p1.fileinfo);
  4277. ptmp:=generate_inline_specialization(gendef,p1,filepos,parseddef,gensym,p2);
  4278. { we don't need these nodes anymore }
  4279. p1.free;
  4280. p2.free;
  4281. p1:=ptmp;
  4282. { with p1 now set we are in reality directly behind the
  4283. call to "factor" thus we need to call down to that
  4284. again }
  4285. { This is disabled until specializations on the right
  4286. hand side work as well, because
  4287. "not working expressions" is better than "half working
  4288. expressions" }
  4289. {factornode:=p1;
  4290. goto SubExprStart;}
  4291. end
  4292. else
  4293. begin
  4294. { this is a normal "<" comparison }
  4295. { potential generic types that are followed by a "<": }
  4296. { a) might not have their resultdef set }
  4297. if not assigned(p1.resultdef) then
  4298. do_typecheckpass(p1);
  4299. { b) are not checked whether they are an undefined def,
  4300. but not a generic parameter }
  4301. if (p1.nodetype=typen) and
  4302. (ttypenode(p1).typedef.typ=undefineddef) and
  4303. assigned(ttypenode(p1).typedef.typesym) and
  4304. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  4305. begin
  4306. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  4307. p1.Free;
  4308. p1:=cerrornode.create;
  4309. end;
  4310. { c) don't have their hints checked }
  4311. if istypenode(p1) then
  4312. begin
  4313. gendef:=gettypedef(p1);
  4314. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4315. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4316. end;
  4317. { Note: the second part of the expression will be needed
  4318. for nested specializations }
  4319. if istypenode(p2) {and
  4320. not (token in [_LT, _LSHARPBRACKET])} then
  4321. begin
  4322. gendef:=gettypedef(p2);
  4323. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4324. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4325. end;
  4326. { create the comparison node for "<" }
  4327. p1:=caddnode.create(ltn,p1,p2)
  4328. end;
  4329. end;
  4330. _GTE :
  4331. p1:=caddnode.create(gten,p1,p2);
  4332. _LTE :
  4333. p1:=caddnode.create(lten,p1,p2);
  4334. _SYMDIF :
  4335. p1:=caddnode.create(symdifn,p1,p2);
  4336. _STARSTAR :
  4337. p1:=caddnode.create(starstarn,p1,p2);
  4338. _OP_AS,
  4339. _OP_IS :
  4340. begin
  4341. if (m_delphi in current_settings.modeswitches) and
  4342. (token in [_LT, _LSHARPBRACKET]) and
  4343. getgenericsym(p2,gensym) then
  4344. begin
  4345. { for now we're handling this as a generic declaration;
  4346. there could be cases though (because of operator
  4347. overloading) where this is the wrong decision... }
  4348. if gensym.typ=typesym then
  4349. gendef:=ttypesym(gensym).typedef
  4350. else
  4351. if gensym.typ=procsym then
  4352. gendef:=tdef(tprocsym(gensym).procdeflist[0])
  4353. else
  4354. internalerror(2015072401);
  4355. ptmp:=generate_inline_specialization(gendef,p2,filepos,nil,nil,nil);
  4356. { we don't need the old p2 anymore }
  4357. p2.Free;
  4358. p2:=ptmp;
  4359. { here we don't need to call back down to "factor", thus
  4360. no "goto" }
  4361. end;
  4362. { now generate the "is" or "as" node }
  4363. case oldt of
  4364. _OP_AS:
  4365. p1:=casnode.create(p1,p2);
  4366. _OP_IS:
  4367. p1:=cisnode.create(p1,p2);
  4368. else
  4369. internalerror(2019050528);
  4370. end;
  4371. end;
  4372. _OP_IN :
  4373. p1:=cinnode.create(p1,p2);
  4374. _OP_OR,
  4375. _PIPE {macpas only} :
  4376. begin
  4377. p1:=caddnode.create(orn,p1,p2);
  4378. if (oldt = _PIPE) then
  4379. include(p1.flags,nf_short_bool);
  4380. end;
  4381. _OP_AND,
  4382. _AMPERSAND {macpas only} :
  4383. begin
  4384. p1:=caddnode.create(andn,p1,p2);
  4385. if (oldt = _AMPERSAND) then
  4386. include(p1.flags,nf_short_bool);
  4387. end;
  4388. _OP_DIV :
  4389. p1:=cmoddivnode.create(divn,p1,p2);
  4390. _OP_NOT :
  4391. p1:=cnotnode.create(p1);
  4392. _OP_MOD :
  4393. begin
  4394. p1:=cmoddivnode.create(modn,p1,p2);
  4395. if m_isolike_mod in current_settings.modeswitches then
  4396. include(p1.flags,nf_isomod);
  4397. end;
  4398. _OP_SHL :
  4399. p1:=cshlshrnode.create(shln,p1,p2);
  4400. _OP_SHR :
  4401. p1:=cshlshrnode.create(shrn,p1,p2);
  4402. _OP_XOR :
  4403. p1:=caddnode.create(xorn,p1,p2);
  4404. _ASSIGNMENT :
  4405. p1:=cassignmentnode.create(p1,p2);
  4406. _NE :
  4407. p1:=caddnode.create(unequaln,p1,p2);
  4408. else
  4409. internalerror(2019050529);
  4410. end;
  4411. p1.fileinfo:=filepos;
  4412. end
  4413. else
  4414. break;
  4415. until false;
  4416. sub_expr:=p1;
  4417. end;
  4418. function comp_expr(flags:texprflags):tnode;
  4419. var
  4420. oldafterassignment : boolean;
  4421. p1 : tnode;
  4422. begin
  4423. oldafterassignment:=afterassignment;
  4424. afterassignment:=true;
  4425. p1:=sub_expr(opcompare,flags,nil);
  4426. { get the resultdef for this expression }
  4427. if not assigned(p1.resultdef) then
  4428. do_typecheckpass(p1);
  4429. afterassignment:=oldafterassignment;
  4430. comp_expr:=p1;
  4431. end;
  4432. function expr(dotypecheck : boolean) : tnode;
  4433. var
  4434. p1,p2 : tnode;
  4435. filepos : tfileposinfo;
  4436. oldafterassignment,
  4437. updatefpos : boolean;
  4438. oldflags : tnodeflags;
  4439. begin
  4440. oldafterassignment:=afterassignment;
  4441. p1:=sub_expr(opcompare,[ef_accept_equal],nil);
  4442. { get the resultdef for this expression }
  4443. if not assigned(p1.resultdef) and
  4444. dotypecheck then
  4445. do_typecheckpass(p1);
  4446. filepos:=current_tokenpos;
  4447. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  4448. afterassignment:=true;
  4449. updatefpos:=true;
  4450. case token of
  4451. _POINTPOINT :
  4452. begin
  4453. consume(_POINTPOINT);
  4454. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4455. p1:=crangenode.create(p1,p2);
  4456. end;
  4457. _ASSIGNMENT :
  4458. begin
  4459. consume(_ASSIGNMENT);
  4460. if assigned(p1.resultdef) and (p1.resultdef.typ=procvardef) then
  4461. getprocvardef:=tprocvardef(p1.resultdef);
  4462. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4463. if assigned(getprocvardef) then
  4464. handle_procvar(getprocvardef,p2);
  4465. getprocvardef:=nil;
  4466. p1:=cassignmentnode.create(p1,p2);
  4467. end;
  4468. _PLUSASN :
  4469. begin
  4470. consume(_PLUSASN);
  4471. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4472. p1:=gen_c_style_operator(addn,p1,p2);
  4473. end;
  4474. _MINUSASN :
  4475. begin
  4476. consume(_MINUSASN);
  4477. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4478. p1:=gen_c_style_operator(subn,p1,p2);
  4479. end;
  4480. _STARASN :
  4481. begin
  4482. consume(_STARASN );
  4483. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4484. p1:=gen_c_style_operator(muln,p1,p2);
  4485. end;
  4486. _SLASHASN :
  4487. begin
  4488. consume(_SLASHASN );
  4489. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4490. p1:=gen_c_style_operator(slashn,p1,p2);
  4491. end;
  4492. else
  4493. updatefpos:=false;
  4494. end;
  4495. oldflags:=p1.flags;
  4496. { get the resultdef for this expression }
  4497. if not assigned(p1.resultdef) and
  4498. dotypecheck then
  4499. do_typecheckpass(p1);
  4500. { transfer generic paramter flag }
  4501. if nf_generic_para in oldflags then
  4502. include(p1.flags,nf_generic_para);
  4503. afterassignment:=oldafterassignment;
  4504. if updatefpos then
  4505. p1.fileinfo:=filepos;
  4506. expr:=p1;
  4507. end;
  4508. function get_intconst:TConstExprInt;
  4509. {Reads an expression, tries to evalute it and check if it is an integer
  4510. constant. Then the constant is returned.}
  4511. var
  4512. p:tnode;
  4513. begin
  4514. result:=0;
  4515. p:=comp_expr([ef_accept_equal]);
  4516. if not codegenerror then
  4517. begin
  4518. if (p.nodetype<>ordconstn) or
  4519. not(is_integer(p.resultdef)) then
  4520. Message(parser_e_illegal_expression)
  4521. else
  4522. result:=tordconstnode(p).value;
  4523. end;
  4524. p.free;
  4525. end;
  4526. function get_stringconst:string;
  4527. {Reads an expression, tries to evaluate it and checks if it is a string
  4528. constant. Then the constant is returned.}
  4529. var
  4530. p:tnode;
  4531. begin
  4532. get_stringconst:='';
  4533. p:=comp_expr([ef_accept_equal]);
  4534. if p.nodetype<>stringconstn then
  4535. begin
  4536. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  4537. get_stringconst:=char(int64(tordconstnode(p).value))
  4538. else
  4539. Message(parser_e_illegal_expression);
  4540. end
  4541. else
  4542. get_stringconst:=strpas(tstringconstnode(p).value_str);
  4543. p.free;
  4544. end;
  4545. end.