pexpr.pas 187 KB

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