pexpr.pas 193 KB

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