pexpr.pas 191 KB

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