pexpr.pas 202 KB

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