pexpr.pas 191 KB

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