pexpr.pas 201 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994
  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. end;
  1075. afterassignment:=prevafterassn;
  1076. end;
  1077. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  1078. var
  1079. hp,hp2 : tnode;
  1080. hpp : ^tnode;
  1081. currprocdef : tprocdef;
  1082. begin
  1083. if not assigned(pv) then
  1084. internalerror(200301121);
  1085. if (m_tp_procvar in current_settings.modeswitches) or
  1086. (m_mac_procvar in current_settings.modeswitches) then
  1087. begin
  1088. hp:=p2;
  1089. hpp:=@p2;
  1090. while assigned(hp) and
  1091. (hp.nodetype=typeconvn) do
  1092. begin
  1093. hp:=ttypeconvnode(hp).left;
  1094. { save orignal address of the old tree so we can replace the node }
  1095. hpp:=@hp;
  1096. end;
  1097. if (hp.nodetype=calln) and
  1098. { a procvar can't have parameters! }
  1099. not assigned(tcallnode(hp).left) then
  1100. begin
  1101. currprocdef:=tcallnode(hp).symtableprocentry.Find_procdef_byprocvardef(pv);
  1102. if assigned(currprocdef) then
  1103. begin
  1104. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  1105. if (po_methodpointer in pv.procoptions) then
  1106. tloadnode(hp2).set_mp(tcallnode(hp).methodpointer.getcopy);
  1107. hp.free;
  1108. { replace the old callnode with the new loadnode }
  1109. hpp^:=hp2;
  1110. end;
  1111. end;
  1112. end;
  1113. end;
  1114. procedure handle_funcref(fr:tobjectdef;var p2:tnode);
  1115. var
  1116. hp,hp2 : tnode;
  1117. hpp : ^tnode;
  1118. currprocdef : tprocdef;
  1119. begin
  1120. if not assigned(fr) then
  1121. internalerror(2022032401);
  1122. if not is_invokable(fr) then
  1123. internalerror(2022032402);
  1124. if (m_tp_procvar in current_settings.modeswitches) or
  1125. (m_mac_procvar in current_settings.modeswitches) then
  1126. begin
  1127. hp:=p2;
  1128. hpp:=@p2;
  1129. while assigned(hp) and
  1130. (hp.nodetype=typeconvn) do
  1131. begin
  1132. hp:=ttypeconvnode(hp).left;
  1133. { save orignal address of the old tree so we can replace the node }
  1134. hpp:=@hp;
  1135. end;
  1136. if (hp.nodetype=calln) and
  1137. { a procvar can't have parameters! }
  1138. not assigned(tcallnode(hp).left) then
  1139. begin
  1140. currprocdef:=tcallnode(hp).symtableprocentry.Find_procdef_byfuncrefdef(fr);
  1141. if assigned(currprocdef) then
  1142. begin
  1143. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  1144. hp.free;
  1145. { replace the old callnode with the new loadnode }
  1146. hpp^:=hp2;
  1147. end;
  1148. end;
  1149. end;
  1150. end;
  1151. { the following procedure handles the access to a property symbol }
  1152. procedure handle_propertysym(propsym : tpropertysym;st : TSymtable;var p1 : tnode);
  1153. var
  1154. paras : tnode;
  1155. p2 : tnode;
  1156. membercall : boolean;
  1157. callflags : tcallnodeflags;
  1158. propaccesslist : tpropaccesslist;
  1159. sym: tsym;
  1160. begin
  1161. { property parameters? read them only if the property really }
  1162. { has parameters }
  1163. paras:=nil;
  1164. if (ppo_hasparameters in propsym.propoptions) then
  1165. begin
  1166. if try_to_consume(_LECKKLAMMER) then
  1167. begin
  1168. paras:=parse_paras(false,false,_RECKKLAMMER);
  1169. consume(_RECKKLAMMER);
  1170. end;
  1171. end;
  1172. { indexed property }
  1173. if (ppo_indexed in propsym.propoptions) then
  1174. begin
  1175. p2:=cordconstnode.create(propsym.index,propsym.indexdef,true);
  1176. paras:=ccallparanode.create(p2,paras);
  1177. end;
  1178. { we need only a write property if a := follows }
  1179. { if not(afterassignment) and not(in_args) then }
  1180. if token=_ASSIGNMENT then
  1181. begin
  1182. if propsym.getpropaccesslist(palt_write,propaccesslist) then
  1183. begin
  1184. sym:=propaccesslist.firstsym^.sym;
  1185. case sym.typ of
  1186. procsym :
  1187. begin
  1188. callflags:=[];
  1189. { generate the method call }
  1190. membercall:=maybe_load_methodpointer(st,p1);
  1191. if membercall then
  1192. include(callflags,cnf_member_call);
  1193. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags,nil);
  1194. addsymref(sym);
  1195. paras:=nil;
  1196. consume(_ASSIGNMENT);
  1197. { read the expression }
  1198. if propsym.propdef.typ=procvardef then
  1199. getprocvardef:=tprocvardef(propsym.propdef)
  1200. else if is_invokable(propsym.propdef) then
  1201. getfuncrefdef:=tobjectdef(propsym.propdef);
  1202. p2:=comp_expr([ef_accept_equal]);
  1203. if assigned(getprocvardef) then
  1204. handle_procvar(getprocvardef,p2)
  1205. else if assigned(getfuncrefdef) then
  1206. handle_funcref(getfuncrefdef,p2);
  1207. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  1208. { mark as property, both the tcallnode and the real call block }
  1209. include(p1.flags,nf_isproperty);
  1210. getprocvardef:=nil;
  1211. getfuncrefdef:=nil;
  1212. end;
  1213. fieldvarsym :
  1214. begin
  1215. { generate access code }
  1216. if not handle_staticfield_access(sym,p1) then
  1217. propaccesslist_to_node(p1,st,propaccesslist);
  1218. include(p1.flags,nf_isproperty);
  1219. consume(_ASSIGNMENT);
  1220. { read the expression }
  1221. if propsym.propdef.typ=procvardef then
  1222. getprocvardef:=tprocvardef(propsym.propdef)
  1223. else if is_invokable(propsym.propdef) then
  1224. getfuncrefdef:=tobjectdef(propsym.propdef);
  1225. p2:=comp_expr([ef_accept_equal]);
  1226. if assigned(getprocvardef) then
  1227. handle_procvar(getprocvardef,p2)
  1228. else if assigned(getfuncrefdef) then
  1229. handle_funcref(getfuncrefdef,p2);
  1230. getprocvardef:=nil;
  1231. getfuncrefdef:=nil;
  1232. p1:=cassignmentnode.create(p1,p2);
  1233. end
  1234. else
  1235. begin
  1236. p1:=cerrornode.create;
  1237. Message(parser_e_no_procedure_to_access_property);
  1238. end;
  1239. end;
  1240. end
  1241. else
  1242. begin
  1243. p1:=cerrornode.create;
  1244. Message(parser_e_no_procedure_to_access_property);
  1245. end;
  1246. end
  1247. else
  1248. begin
  1249. if propsym.getpropaccesslist(palt_read,propaccesslist) then
  1250. begin
  1251. sym := propaccesslist.firstsym^.sym;
  1252. case sym.typ of
  1253. fieldvarsym :
  1254. begin
  1255. { generate access code }
  1256. if not handle_staticfield_access(sym,p1) then
  1257. propaccesslist_to_node(p1,st,propaccesslist);
  1258. include(p1.flags,nf_isproperty);
  1259. { catch expressions like "(propx):=1;" }
  1260. include(p1.flags,nf_no_lvalue);
  1261. end;
  1262. procsym :
  1263. begin
  1264. callflags:=[];
  1265. { generate the method call }
  1266. membercall:=maybe_load_methodpointer(st,p1);
  1267. if membercall then
  1268. include(callflags,cnf_member_call);
  1269. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags,nil);
  1270. paras:=nil;
  1271. include(p1.flags,nf_isproperty);
  1272. include(p1.flags,nf_no_lvalue);
  1273. end
  1274. else
  1275. begin
  1276. p1:=cerrornode.create;
  1277. Message(type_e_mismatch);
  1278. end;
  1279. end;
  1280. end
  1281. else
  1282. begin
  1283. { error, no function to read property }
  1284. p1:=cerrornode.create;
  1285. Message(parser_e_no_procedure_to_access_property);
  1286. end;
  1287. end;
  1288. { release paras if not used }
  1289. if assigned(paras) then
  1290. paras.free;
  1291. end;
  1292. { the ID token has to be consumed before calling this function }
  1293. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags;spezcontext:tspecializationcontext);
  1294. var
  1295. isclassref:boolean;
  1296. isrecordtype:boolean;
  1297. isobjecttype:boolean;
  1298. ishelpertype:boolean;
  1299. begin
  1300. if sym=nil then
  1301. begin
  1302. { pattern is still valid unless
  1303. there is another ID just after the ID of sym }
  1304. Message1(sym_e_id_no_member,orgpattern);
  1305. p1.free;
  1306. p1:=cerrornode.create;
  1307. { try to clean up }
  1308. spezcontext.free;
  1309. again:=false;
  1310. end
  1311. else
  1312. begin
  1313. if assigned(p1) then
  1314. begin
  1315. if not assigned(p1.resultdef) then
  1316. do_typecheckpass(p1);
  1317. isclassref:=(p1.resultdef.typ=classrefdef);
  1318. isrecordtype:=(p1.nodetype=typen) and (p1.resultdef.typ=recorddef);
  1319. isobjecttype:=(p1.nodetype=typen) and is_object(p1.resultdef);
  1320. ishelpertype:=is_objectpascal_helper(tdef(sym.owner.defowner)) and
  1321. (p1.nodetype=typen) and
  1322. not is_objectpascal_helper(p1.resultdef)
  1323. {and
  1324. not (cnf_inherited in callflags)};
  1325. end
  1326. else
  1327. begin
  1328. isclassref:=false;
  1329. isrecordtype:=false;
  1330. isobjecttype:=false;
  1331. ishelpertype:=false;
  1332. end;
  1333. if assigned(spezcontext) and not (sym.typ=procsym) then
  1334. internalerror(2015091801);
  1335. { we assume, that only procsyms and varsyms are in an object }
  1336. { symbol table, for classes, properties are allowed }
  1337. case sym.typ of
  1338. procsym:
  1339. begin
  1340. do_proc_call(sym,sym.owner,structh,
  1341. (getaddr and not(token in [_CARET,_POINT])),
  1342. again,p1,callflags,spezcontext);
  1343. { we need to know which procedure is called }
  1344. do_typecheckpass(p1);
  1345. { We are loading... }
  1346. if p1.nodetype=loadn then
  1347. begin
  1348. { an instance method }
  1349. if not (po_classmethod in tloadnode(p1).procdef.procoptions) and
  1350. { into a method pointer (not just taking a code address) }
  1351. not getaddr and
  1352. { and the selfarg is... }
  1353. (
  1354. { either a record/object/helper type, }
  1355. not assigned(tloadnode(p1).left) or
  1356. { or a class/metaclass type, or a class reference }
  1357. (tloadnode(p1).left.resultdef.typ=classrefdef)
  1358. ) then
  1359. Message(parser_e_only_class_members_via_class_ref);
  1360. end
  1361. { calling using classref? }
  1362. else if (
  1363. isclassref or
  1364. (
  1365. (isobjecttype or
  1366. isrecordtype or
  1367. ishelpertype) and
  1368. not (cnf_inherited in callflags)
  1369. )
  1370. ) and
  1371. (p1.nodetype=calln) and
  1372. assigned(tcallnode(p1).procdefinition) then
  1373. begin
  1374. if not isobjecttype then
  1375. begin
  1376. if not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1377. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1378. Message(parser_e_only_class_members_via_class_ref);
  1379. end
  1380. else
  1381. begin
  1382. { with objects, you can also do this:
  1383. type
  1384. tparent = object
  1385. procedure test;
  1386. end;
  1387. tchild = object(tchild)
  1388. procedure test;
  1389. end;
  1390. procedure tparent.test;
  1391. begin
  1392. end;
  1393. procedure tchild.test;
  1394. begin
  1395. tparent.test;
  1396. end;
  1397. }
  1398. if (tcallnode(p1).procdefinition.proctypeoption<>potype_constructor) and
  1399. not(po_staticmethod in tcallnode(p1).procdefinition.procoptions) and
  1400. (not assigned(current_structdef) or
  1401. not def_is_related(current_structdef,structh)) then
  1402. begin
  1403. p1.free;
  1404. p1:=cerrornode.create;
  1405. Message(parser_e_only_static_members_via_object_type);
  1406. exit;
  1407. end;
  1408. end;
  1409. { in Java, constructors are not automatically inherited
  1410. -> calling a constructor from a parent type will create
  1411. an instance of that parent type! }
  1412. if is_javaclass(structh) and
  1413. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1414. (tcallnode(p1).procdefinition.owner.defowner<>find_real_class_definition(tobjectdef(structh),false)) then
  1415. Message(parser_e_java_no_inherited_constructor);
  1416. { Provide a warning if we try to create an instance of a
  1417. abstract class using the type name of that class. We
  1418. must not provide a warning if we use a "class of"
  1419. variable of that type though as we don't know the
  1420. type of the class
  1421. Note: structh might be Nil in case of a type helper }
  1422. if assigned(structh) and
  1423. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1424. (oo_is_abstract in structh.objectoptions) and
  1425. assigned(tcallnode(p1).methodpointer) and
  1426. (tcallnode(p1).methodpointer.nodetype=loadvmtaddrn) then
  1427. Message1(type_w_instance_abstract_class,structh.RttiName);
  1428. end
  1429. end;
  1430. fieldvarsym:
  1431. begin
  1432. if not handle_staticfield_access(sym,p1) then
  1433. begin
  1434. if isclassref then
  1435. if assigned(p1) and
  1436. (
  1437. is_self_node(p1) or
  1438. (assigned(current_procinfo) and (current_procinfo.get_normal_proc.procdef.no_self_node) and
  1439. (current_procinfo.procdef.struct=structh))) then
  1440. Message(parser_e_only_class_members)
  1441. else
  1442. Message(parser_e_only_class_members_via_class_ref);
  1443. p1:=csubscriptnode.create(sym,p1);
  1444. end;
  1445. end;
  1446. propertysym:
  1447. begin
  1448. if isclassref and not (sp_static in sym.symoptions) then
  1449. Message(parser_e_only_class_members_via_class_ref);
  1450. handle_propertysym(tpropertysym(sym),sym.owner,p1);
  1451. end;
  1452. typesym:
  1453. begin
  1454. p1.free;
  1455. if try_to_consume(_LKLAMMER) then
  1456. begin
  1457. p1:=comp_expr([ef_accept_equal]);
  1458. consume(_RKLAMMER);
  1459. p1:=ctypeconvnode.create_explicit(p1,ttypesym(sym).typedef);
  1460. end
  1461. else
  1462. begin
  1463. p1:=ctypenode.create(ttypesym(sym).typedef);
  1464. if (is_class(ttypesym(sym).typedef) or
  1465. is_objcclass(ttypesym(sym).typedef) or
  1466. is_javaclass(ttypesym(sym).typedef)) and
  1467. not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1468. p1:=cloadvmtaddrnode.create(p1);
  1469. end;
  1470. end;
  1471. constsym:
  1472. begin
  1473. p1.free;
  1474. p1:=genconstsymtree(tconstsym(sym));
  1475. end;
  1476. staticvarsym:
  1477. begin
  1478. { typed constant is a staticvarsym
  1479. now they are absolutevarsym }
  1480. p1.free;
  1481. p1:=cloadnode.create(sym,sym.Owner);
  1482. end;
  1483. absolutevarsym:
  1484. begin
  1485. p1.free;
  1486. p1:=nil;
  1487. { typed constants are absolutebarsyms now to handle storage properly }
  1488. propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref);
  1489. end
  1490. else
  1491. internalerror(16);
  1492. end;
  1493. end;
  1494. end;
  1495. function handle_specialize_inline_specialization(var srsym:tsym;out srsymtable:tsymtable;out spezcontext:tspecializationcontext):boolean;
  1496. var
  1497. spezdef : tdef;
  1498. symname : tsymstr;
  1499. begin
  1500. result:=false;
  1501. spezcontext:=nil;
  1502. srsymtable:=nil;
  1503. if not assigned(srsym) then
  1504. message1(sym_e_id_no_member,orgpattern)
  1505. else
  1506. if not (srsym.typ in [typesym,procsym]) then
  1507. message(type_e_type_id_expected)
  1508. else
  1509. begin
  1510. if srsym.typ=typesym then
  1511. spezdef:=ttypesym(srsym).typedef
  1512. else if tprocsym(srsym).procdeflist.count>0 then
  1513. spezdef:=tdef(tprocsym(srsym).procdeflist[0])
  1514. else
  1515. spezdef:=nil;
  1516. if (not assigned(spezdef) or (spezdef.typ=errordef)) and (sp_generic_dummy in srsym.symoptions) then
  1517. symname:=srsym.RealName
  1518. else
  1519. symname:='';
  1520. spezdef:=generate_specialization_phase1(spezcontext,spezdef,symname,srsym.owner);
  1521. case spezdef.typ of
  1522. errordef:
  1523. begin
  1524. spezcontext.free;
  1525. spezcontext:=nil;
  1526. srsym:=generrorsym;
  1527. end;
  1528. procdef:
  1529. begin
  1530. if block_type<>bt_body then
  1531. begin
  1532. message(parser_e_illegal_expression);
  1533. spezcontext.free;
  1534. spezcontext:=nil;
  1535. srsym:=generrorsym;
  1536. end
  1537. else
  1538. begin
  1539. srsym:=tprocdef(spezdef).procsym;
  1540. srsymtable:=srsym.owner;
  1541. result:=true;
  1542. end;
  1543. end;
  1544. objectdef,
  1545. recorddef,
  1546. arraydef,
  1547. procvardef:
  1548. begin
  1549. spezdef:=generate_specialization_phase2(spezcontext,tstoreddef(spezdef),false,'');
  1550. spezcontext.free;
  1551. spezcontext:=nil;
  1552. if spezdef<>generrordef then
  1553. begin
  1554. srsym:=spezdef.typesym;
  1555. srsymtable:=srsym.owner;
  1556. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1557. result:=true;
  1558. end;
  1559. end;
  1560. else
  1561. internalerror(2015070302);
  1562. end;
  1563. end;
  1564. end;
  1565. function handle_factor_typenode(hdef:tdef;getaddr:boolean;var again:boolean;sym:tsym;typeonly:boolean):tnode;
  1566. var
  1567. srsym : tsym;
  1568. srsymtable : tsymtable;
  1569. erroroutresult,
  1570. isspecialize : boolean;
  1571. spezcontext : tspecializationcontext;
  1572. savedfilepos : tfileposinfo;
  1573. begin
  1574. spezcontext:=nil;
  1575. if sym=nil then
  1576. sym:=hdef.typesym;
  1577. { allow Ordinal(Value) for type declarations since it
  1578. can be an enummeration declaration or a set lke:
  1579. (OrdinalType(const1)..OrdinalType(const2) }
  1580. if (not typeonly or is_ordinal(hdef)) and
  1581. try_to_consume(_LKLAMMER) then
  1582. begin
  1583. result:=comp_expr([ef_accept_equal]);
  1584. consume(_RKLAMMER);
  1585. { type casts to class helpers aren't allowed }
  1586. if is_objectpascal_helper(hdef) then
  1587. Message(parser_e_no_category_as_types)
  1588. { recovery by not creating a conversion node }
  1589. else
  1590. result:=ctypeconvnode.create_explicit(result,hdef);
  1591. end
  1592. { not LKLAMMER }
  1593. else if (token=_POINT) and
  1594. (is_object(hdef) or is_record(hdef)) then
  1595. begin
  1596. consume(_POINT);
  1597. { handles calling methods declared in parent objects
  1598. using "parentobject.methodname()" }
  1599. if assigned(current_structdef) and
  1600. not(getaddr) and
  1601. def_is_related(current_structdef,hdef) then
  1602. begin
  1603. result:=ctypenode.create(hdef);
  1604. ttypenode(result).typesym:=sym;
  1605. if not (m_delphi in current_settings.modeswitches) and
  1606. (block_type in inline_specialization_block_types) and
  1607. (token=_ID) and
  1608. (idtoken=_SPECIALIZE) then
  1609. begin
  1610. consume(_ID);
  1611. if token<>_ID then
  1612. message(type_e_type_id_expected);
  1613. isspecialize:=true;
  1614. end
  1615. else
  1616. isspecialize:=false;
  1617. { search also in inherited methods }
  1618. searchsym_in_class(tobjectdef(hdef),tobjectdef(current_structdef),pattern,srsym,srsymtable,[ssf_search_helper]);
  1619. if isspecialize then
  1620. begin
  1621. consume(_ID);
  1622. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  1623. begin
  1624. result.free;
  1625. result:=cerrornode.create;
  1626. end;
  1627. end
  1628. else
  1629. begin
  1630. if assigned(srsym) then
  1631. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1632. consume(_ID);
  1633. end;
  1634. if result.nodetype<>errorn then
  1635. do_member_read(tabstractrecorddef(hdef),false,srsym,result,again,[],spezcontext)
  1636. else
  1637. spezcontext.free;
  1638. end
  1639. else
  1640. begin
  1641. { handles:
  1642. * @TObject.Load
  1643. * static methods and variables }
  1644. result:=ctypenode.create(hdef);
  1645. ttypenode(result).typesym:=sym;
  1646. if not (m_delphi in current_settings.modeswitches) and
  1647. (block_type in inline_specialization_block_types) and
  1648. (token=_ID) and
  1649. (idtoken=_SPECIALIZE) then
  1650. begin
  1651. consume(_ID);
  1652. if token<>_ID then
  1653. message(type_e_type_id_expected);
  1654. isspecialize:=true;
  1655. end
  1656. else
  1657. isspecialize:=false;
  1658. erroroutresult:=true;
  1659. { TP allows also @TMenu.Load if Load is only }
  1660. { defined in an anchestor class }
  1661. srsym:=search_struct_member(tabstractrecorddef(hdef),pattern);
  1662. if isspecialize and assigned(srsym) then
  1663. begin
  1664. consume(_ID);
  1665. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  1666. erroroutresult:=false;
  1667. end
  1668. else
  1669. begin
  1670. if assigned(srsym) then
  1671. begin
  1672. savedfilepos:=current_filepos;
  1673. consume(_ID);
  1674. if not (sp_generic_dummy in srsym.symoptions) or
  1675. not (token in [_LT,_LSHARPBRACKET]) then
  1676. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,savedfilepos)
  1677. else
  1678. result:=cspecializenode.create(result,getaddr,srsym);
  1679. erroroutresult:=false;
  1680. end
  1681. else
  1682. Message1(sym_e_id_no_member,orgpattern);
  1683. end;
  1684. if erroroutresult then
  1685. begin
  1686. result.free;
  1687. result:=cerrornode.create;
  1688. end
  1689. else
  1690. if result.nodetype<>specializen then
  1691. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],spezcontext);
  1692. end;
  1693. end
  1694. else
  1695. begin
  1696. { Normally here would be the check against the usage
  1697. of "TClassHelper.Something", but as that might be
  1698. used inside of system symbols like sizeof and
  1699. typeinfo this check is put into ttypenode.pass_1
  1700. (for "TClassHelper" alone) and tcallnode.pass_1
  1701. (for "TClassHelper.Something") }
  1702. { class reference ? }
  1703. if is_class(hdef) or
  1704. is_objcclass(hdef) or
  1705. { Java interfaces also can have loadvmtaddrnodes,
  1706. e.g. for expressions such as JLClass(intftype) }
  1707. is_java_class_or_interface(hdef) then
  1708. begin
  1709. if getaddr and (token=_POINT) and
  1710. not is_javainterface(hdef) then
  1711. begin
  1712. consume(_POINT);
  1713. { allows @Object.Method }
  1714. { also allows static methods and variables }
  1715. result:=ctypenode.create(hdef);
  1716. ttypenode(result).typesym:=sym;
  1717. { TP allows also @TMenu.Load if Load is only }
  1718. { defined in an anchestor class }
  1719. srsym:=search_struct_member(tobjectdef(hdef),pattern);
  1720. if assigned(srsym) then
  1721. begin
  1722. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1723. consume(_ID);
  1724. { in case of @Object.Method1.Method2, we have to call
  1725. Method1 -> create a loadvmtaddr node as self instead of
  1726. a typen (the typenode would be changed to self of the
  1727. current method in case Method1 is a constructor, see
  1728. mantis #24844) }
  1729. if not(block_type in [bt_type,bt_const_type,bt_var_type]) and
  1730. (srsym.typ=procsym) and
  1731. (token in [_CARET,_POINT]) then
  1732. result:=cloadvmtaddrnode.create(result);
  1733. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil);
  1734. end
  1735. else
  1736. begin
  1737. Message1(sym_e_id_no_member,orgpattern);
  1738. consume(_ID);
  1739. end;
  1740. end
  1741. else
  1742. begin
  1743. result:=ctypenode.create(hdef);
  1744. ttypenode(result).typesym:=sym;
  1745. { For a type block we simply return only
  1746. the type. For all other blocks we return
  1747. a loadvmt node }
  1748. if not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1749. result:=cloadvmtaddrnode.create(result);
  1750. end;
  1751. end
  1752. else
  1753. begin
  1754. result:=ctypenode.create(hdef);
  1755. ttypenode(result).typesym:=sym;
  1756. end;
  1757. end;
  1758. end;
  1759. {****************************************************************************
  1760. Factor
  1761. ****************************************************************************}
  1762. function real_const_node_from_pattern(const s:string):tnode;
  1763. var
  1764. d : bestreal;
  1765. code : integer;
  1766. cur : currency;
  1767. begin
  1768. val(s,d,code);
  1769. if code<>0 then
  1770. begin
  1771. Message(parser_e_error_in_real);
  1772. d:=1.0;
  1773. end;
  1774. if current_settings.fputype=fpu_none then
  1775. begin
  1776. Message(parser_e_unsupported_real);
  1777. result:=cerrornode.create;
  1778. exit;
  1779. end;
  1780. if (current_settings.minfpconstprec=s32real) and
  1781. (d = single(d)) then
  1782. result:=crealconstnode.create(d,s32floattype)
  1783. else if (current_settings.minfpconstprec=s64real) and
  1784. (d = double(d)) then
  1785. result:=crealconstnode.create(d,s64floattype)
  1786. else
  1787. result:=crealconstnode.create(d,pbestrealtype^);
  1788. val(pattern,cur,code);
  1789. if code=0 then
  1790. trealconstnode(result).value_currency:=cur;
  1791. end;
  1792. {---------------------------------------------
  1793. PostFixOperators
  1794. ---------------------------------------------}
  1795. { returns whether or not p1 has been changed }
  1796. function postfixoperators(var p1:tnode;var again:boolean;getaddr:boolean): boolean;
  1797. { tries to avoid syntax errors after invalid qualifiers }
  1798. procedure recoverconsume_postfixops;
  1799. begin
  1800. repeat
  1801. if not try_to_consume(_CARET) then
  1802. if try_to_consume(_POINT) then
  1803. try_to_consume(_ID)
  1804. else if try_to_consume(_LECKKLAMMER) then
  1805. begin
  1806. repeat
  1807. comp_expr([ef_accept_equal]);
  1808. until not try_to_consume(_COMMA);
  1809. consume(_RECKKLAMMER);
  1810. end
  1811. else if try_to_consume(_LKLAMMER) then
  1812. begin
  1813. repeat
  1814. comp_expr([ef_accept_equal]);
  1815. until not try_to_consume(_COMMA);
  1816. consume(_RKLAMMER);
  1817. end
  1818. else
  1819. break;
  1820. until false;
  1821. end;
  1822. procedure handle_variantarray;
  1823. var
  1824. p4 : tnode;
  1825. newstatement : tstatementnode;
  1826. tempresultvariant,
  1827. temp : ttempcreatenode;
  1828. paras : tcallparanode;
  1829. newblock : tnode;
  1830. countindices : longint;
  1831. elements: tfplist;
  1832. arraydef: tdef;
  1833. begin
  1834. { create statements with call initialize the arguments and
  1835. call fpc_dynarr_setlength }
  1836. newblock:=internalstatements(newstatement);
  1837. { store all indices in a temporary array }
  1838. countindices:=0;
  1839. elements:=tfplist.Create;
  1840. repeat
  1841. p4:=comp_expr([ef_accept_equal]);
  1842. elements.add(p4);
  1843. until not try_to_consume(_COMMA);
  1844. arraydef:=carraydef.getreusable(s32inttype,elements.count);
  1845. temp:=ctempcreatenode.create(arraydef,arraydef.size,tt_persistent,false);
  1846. addstatement(newstatement,temp);
  1847. for countindices:=0 to elements.count-1 do
  1848. begin
  1849. addstatement(newstatement,
  1850. cassignmentnode.create(
  1851. cvecnode.create(
  1852. ctemprefnode.create(temp),
  1853. genintconstnode(countindices)
  1854. ),
  1855. tnode(elements[countindices])
  1856. )
  1857. );
  1858. end;
  1859. countindices:=elements.count;
  1860. elements.free;
  1861. consume(_RECKKLAMMER);
  1862. { we need only a write access if a := follows }
  1863. if token=_ASSIGNMENT then
  1864. begin
  1865. consume(_ASSIGNMENT);
  1866. p4:=comp_expr([ef_accept_equal]);
  1867. { create call to fpc_vararray_put }
  1868. paras:=ccallparanode.create(cordconstnode.create
  1869. (countindices,s32inttype,true),
  1870. ccallparanode.create(caddrnode.create_internal
  1871. (cvecnode.create(ctemprefnode.create(temp),genintconstnode(0))),
  1872. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1873. ccallparanode.create(ctypeconvnode.create_internal(p1,cvarianttype)
  1874. ,nil))));
  1875. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1876. addstatement(newstatement,ctempdeletenode.create(temp));
  1877. end
  1878. else
  1879. begin
  1880. { create temp for result }
  1881. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.size,tt_persistent,true);
  1882. addstatement(newstatement,tempresultvariant);
  1883. { create call to fpc_vararray_get }
  1884. paras:=ccallparanode.create(cordconstnode.create
  1885. (countindices,s32inttype,true),
  1886. ccallparanode.create(caddrnode.create_internal
  1887. (ctemprefnode.create(temp)),
  1888. ccallparanode.create(p1,
  1889. ccallparanode.create(
  1890. ctemprefnode.create(tempresultvariant)
  1891. ,nil))));
  1892. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1893. addstatement(newstatement,ctempdeletenode.create(temp));
  1894. { the last statement should return the value as
  1895. location and type, this is done be referencing the
  1896. temp and converting it first from a persistent temp to
  1897. normal temp }
  1898. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1899. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1900. end;
  1901. p1:=newblock;
  1902. end;
  1903. function parse_array_constructor(arrdef:tarraydef): tnode;
  1904. var
  1905. newstatement,assstatement:tstatementnode;
  1906. arrnode:ttempcreatenode;
  1907. temp2:ttempcreatenode;
  1908. assnode:tnode;
  1909. paracount:integer;
  1910. begin
  1911. result:=internalstatements(newstatement);
  1912. { create temp for result }
  1913. arrnode:=ctempcreatenode.create(arrdef,arrdef.size,tt_persistent,true);
  1914. addstatement(newstatement,arrnode);
  1915. paracount:=0;
  1916. { check arguments and create an assignment calls }
  1917. if try_to_consume(_LKLAMMER) then
  1918. begin
  1919. assnode:=internalstatements(assstatement);
  1920. repeat
  1921. { arr[i] := param_i }
  1922. addstatement(assstatement,
  1923. cassignmentnode.create(
  1924. cvecnode.create(
  1925. ctemprefnode.create(arrnode),
  1926. cordconstnode.create(paracount,arrdef.rangedef,false)),
  1927. comp_expr([ef_accept_equal])));
  1928. inc(paracount);
  1929. until not try_to_consume(_COMMA);
  1930. consume(_RKLAMMER);
  1931. end
  1932. else
  1933. assnode:=nil;
  1934. { get temp for array of lengths }
  1935. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1936. addstatement(newstatement,temp2);
  1937. { one dimensional }
  1938. addstatement(newstatement,cassignmentnode.create(
  1939. ctemprefnode.create(temp2),
  1940. cordconstnode.create
  1941. (paracount,s32inttype,true)));
  1942. { create call to fpc_dynarr_setlength }
  1943. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1944. ccallparanode.create(caddrnode.create_internal
  1945. (ctemprefnode.create(temp2)),
  1946. ccallparanode.create(cordconstnode.create
  1947. (1,s32inttype,true),
  1948. ccallparanode.create(caddrnode.create_internal
  1949. (crttinode.create(tstoreddef(arrdef),initrtti,rdt_normal)),
  1950. ccallparanode.create(
  1951. ctypeconvnode.create_internal(
  1952. ctemprefnode.create(arrnode),voidpointertype),
  1953. nil))))
  1954. ));
  1955. { add assignment statememnts }
  1956. addstatement(newstatement,ctempdeletenode.create(temp2));
  1957. if assigned(assnode) then
  1958. addstatement(newstatement,assnode);
  1959. { the last statement should return the value as
  1960. location and type, this is done be referencing the
  1961. temp and converting it first from a persistent temp to
  1962. normal temp }
  1963. addstatement(newstatement,ctempdeletenode.create_normal_temp(arrnode));
  1964. addstatement(newstatement,ctemprefnode.create(arrnode));
  1965. end;
  1966. function try_type_helper(var node:tnode;def:tdef):boolean;
  1967. var
  1968. srsym : tsym;
  1969. srsymtable : tsymtable;
  1970. n : tnode;
  1971. newstatement : tstatementnode;
  1972. temp : ttempcreatenode;
  1973. extdef : tdef;
  1974. begin
  1975. result:=false;
  1976. if (token=_ID) and (block_type in [bt_body,bt_general,bt_except,bt_const]) then
  1977. begin
  1978. if not assigned(def) then
  1979. if node.nodetype=addrn then
  1980. { always use the pointer type for addr nodes as otherwise
  1981. we'll have an anonymous pointertype with no name }
  1982. def:=voidpointertype
  1983. else
  1984. def:=node.resultdef;
  1985. result:=search_objectpascal_helper(def,nil,pattern,srsym,srsymtable);
  1986. if result then
  1987. begin
  1988. if not (srsymtable.symtabletype=objectsymtable) or
  1989. not is_objectpascal_helper(tdef(srsymtable.defowner)) then
  1990. internalerror(2013011401);
  1991. { convert const node to temp node of the extended type }
  1992. if node.nodetype in (nodetype_const+[addrn]) then
  1993. begin
  1994. extdef:=tobjectdef(srsymtable.defowner).extendeddef;
  1995. newstatement:=nil;
  1996. n:=internalstatements(newstatement);
  1997. temp:=ctempcreatenode.create(extdef,extdef.size,tt_persistent,false);
  1998. addstatement(newstatement,temp);
  1999. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),node));
  2000. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  2001. addstatement(newstatement,ctemprefnode.create(temp));
  2002. node:=n;
  2003. do_typecheckpass(node)
  2004. end;
  2005. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2006. consume(_ID);
  2007. do_member_read(nil,getaddr,srsym,node,again,[],nil);
  2008. end;
  2009. end;
  2010. end;
  2011. var
  2012. protsym : tpropertysym;
  2013. p2,p3 : tnode;
  2014. srsym : tsym;
  2015. srsymtable : TSymtable;
  2016. structh : tabstractrecorddef;
  2017. { shouldn't be used that often, so the extra overhead is ok to save
  2018. stack space }
  2019. dispatchstring : ansistring;
  2020. autoderef,
  2021. erroroutp1,
  2022. allowspecialize,
  2023. isspecialize,
  2024. found,
  2025. haderror,
  2026. nodechanged : boolean;
  2027. calltype: tdispcalltype;
  2028. valstr,expstr : string;
  2029. intval : qword;
  2030. code : integer;
  2031. strdef : tdef;
  2032. spezcontext : tspecializationcontext;
  2033. old_current_filepos : tfileposinfo;
  2034. label
  2035. skipreckklammercheck,
  2036. skippointdefcheck;
  2037. begin
  2038. result:=false;
  2039. again:=true;
  2040. while again do
  2041. begin
  2042. spezcontext:=nil;
  2043. { we need the resultdef }
  2044. do_typecheckpass_changed(p1,nodechanged);
  2045. result:=result or nodechanged;
  2046. if codegenerror then
  2047. begin
  2048. recoverconsume_postfixops;
  2049. exit;
  2050. end;
  2051. { handle token }
  2052. case token of
  2053. _CARET:
  2054. begin
  2055. consume(_CARET);
  2056. { support tp/mac procvar^ if the procvar returns a
  2057. pointer type }
  2058. if ((m_tp_procvar in current_settings.modeswitches) or
  2059. (m_mac_procvar in current_settings.modeswitches)) and
  2060. (p1.resultdef.typ=procvardef) and
  2061. (tprocvardef(p1.resultdef).returndef.typ=pointerdef) then
  2062. begin
  2063. p1:=ccallnode.create_procvar(nil,p1);
  2064. typecheckpass(p1);
  2065. end;
  2066. { iso file buf access? }
  2067. if (m_isolike_io in current_settings.modeswitches) and
  2068. (p1.resultdef.typ=filedef) then
  2069. begin
  2070. case tfiledef(p1.resultdef).filetyp of
  2071. ft_text:
  2072. begin
  2073. p1:=cderefnode.create(ccallnode.createintern('fpc_getbuf_text',ccallparanode.create(p1,nil)));
  2074. typecheckpass(p1);
  2075. end;
  2076. ft_typed:
  2077. begin
  2078. p1:=cderefnode.create(ctypeconvnode.create_internal(ccallnode.createintern('fpc_getbuf_typedfile',ccallparanode.create(p1,nil)),
  2079. cpointerdef.getreusable(tfiledef(p1.resultdef).typedfiledef)));
  2080. typecheckpass(p1);
  2081. end;
  2082. else
  2083. internalerror(2019050530);
  2084. end;
  2085. end
  2086. else if not(p1.resultdef.typ in [pointerdef,undefineddef]) then
  2087. begin
  2088. { ^ as binary operator is a problem!!!! (FK) }
  2089. again:=false;
  2090. Message(parser_e_invalid_qualifier);
  2091. recoverconsume_postfixops;
  2092. p1.destroy;
  2093. p1:=cerrornode.create;
  2094. end
  2095. else
  2096. p1:=cderefnode.create(p1);
  2097. end;
  2098. _LECKKLAMMER:
  2099. begin
  2100. if is_class_or_interface_or_object(p1.resultdef) or
  2101. is_dispinterface(p1.resultdef) or
  2102. is_record(p1.resultdef) or
  2103. is_javaclass(p1.resultdef) then
  2104. begin
  2105. { default property }
  2106. protsym:=search_default_property(tabstractrecorddef(p1.resultdef));
  2107. if not(assigned(protsym)) then
  2108. begin
  2109. p1.destroy;
  2110. p1:=cerrornode.create;
  2111. again:=false;
  2112. message(parser_e_no_default_property_available);
  2113. end
  2114. else
  2115. begin
  2116. { The property symbol is referenced indirect }
  2117. protsym.IncRefCount;
  2118. handle_propertysym(protsym,protsym.owner,p1);
  2119. end;
  2120. end
  2121. else
  2122. begin
  2123. consume(_LECKKLAMMER);
  2124. repeat
  2125. { in all of the cases below, p1 is changed }
  2126. case p1.resultdef.typ of
  2127. pointerdef:
  2128. begin
  2129. { support delphi autoderef }
  2130. if (tpointerdef(p1.resultdef).pointeddef.typ=arraydef) and
  2131. (m_autoderef in current_settings.modeswitches) then
  2132. p1:=cderefnode.create(p1);
  2133. p2:=comp_expr([ef_accept_equal]);
  2134. { Support Pbytevar[0..9] which returns array [0..9].}
  2135. if try_to_consume(_POINTPOINT) then
  2136. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2137. p1:=cvecnode.create(p1,p2);
  2138. end;
  2139. variantdef:
  2140. begin
  2141. handle_variantarray;
  2142. { the RECKKLAMMER is already read }
  2143. goto skipreckklammercheck;
  2144. end;
  2145. stringdef :
  2146. begin
  2147. p2:=comp_expr([ef_accept_equal]);
  2148. { Support string[0..9] which returns array [0..9] of char.}
  2149. if try_to_consume(_POINTPOINT) then
  2150. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2151. p1:=cvecnode.create(p1,p2);
  2152. end;
  2153. arraydef:
  2154. begin
  2155. p2:=comp_expr([ef_accept_equal]);
  2156. { support SEG:OFS for go32v2/msdos Mem[] }
  2157. if (target_info.system in [system_i386_go32v2,system_i386_watcom,system_i8086_msdos,system_i8086_win16,system_i8086_embedded]) and
  2158. (p1.nodetype=loadn) and
  2159. assigned(tloadnode(p1).symtableentry) and
  2160. assigned(tloadnode(p1).symtableentry.owner.name) and
  2161. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  2162. ((tloadnode(p1).symtableentry.name='MEM') or
  2163. (tloadnode(p1).symtableentry.name='MEMW') or
  2164. (tloadnode(p1).symtableentry.name='MEML')) then
  2165. begin
  2166. {$if defined(i8086)}
  2167. consume(_COLON);
  2168. inserttypeconv(p2,u16inttype);
  2169. inserttypeconv_internal(p2,u32inttype);
  2170. p3:=cshlshrnode.create(shln,p2,cordconstnode.create($10,s16inttype,false));
  2171. p2:=comp_expr([ef_accept_equal]);
  2172. inserttypeconv(p2,u16inttype);
  2173. inserttypeconv_internal(p2,u32inttype);
  2174. p2:=caddnode.create(addn,p2,p3);
  2175. case tloadnode(p1).symtableentry.name of
  2176. 'MEM': p2:=ctypeconvnode.create_internal(p2,bytefarpointertype);
  2177. 'MEMW': p2:=ctypeconvnode.create_internal(p2,wordfarpointertype);
  2178. 'MEML': p2:=ctypeconvnode.create_internal(p2,longintfarpointertype);
  2179. else
  2180. internalerror(2013053102);
  2181. end;
  2182. p1:=cderefnode.create(p2);
  2183. {$elseif defined(i386)}
  2184. if try_to_consume(_COLON) then
  2185. begin
  2186. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  2187. p2:=comp_expr([ef_accept_equal]);
  2188. p2:=caddnode.create(addn,p2,p3);
  2189. if try_to_consume(_POINTPOINT) then
  2190. { Support mem[$a000:$0000..$07ff] which returns array [0..$7ff] of memtype.}
  2191. p2:=crangenode.create(p2,caddnode.create(addn,comp_expr([ef_accept_equal]),p3.getcopy));
  2192. p1:=cvecnode.create(p1,p2);
  2193. include(tvecnode(p1).flags,nf_memseg);
  2194. include(tvecnode(p1).flags,nf_memindex);
  2195. end
  2196. else
  2197. begin
  2198. if try_to_consume(_POINTPOINT) then
  2199. { Support mem[$80000000..$80000002] which returns array [0..2] of memtype.}
  2200. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2201. p1:=cvecnode.create(p1,p2);
  2202. include(tvecnode(p1).flags,nf_memindex);
  2203. end;
  2204. {$else}
  2205. internalerror(2013053105);
  2206. {$endif}
  2207. end
  2208. else
  2209. begin
  2210. if try_to_consume(_POINTPOINT) then
  2211. { Support arrayvar[0..9] which returns array [0..9] of arraytype.}
  2212. p2:=crangenode.create(p2,comp_expr([ef_accept_equal]));
  2213. p1:=cvecnode.create(p1,p2);
  2214. end;
  2215. end;
  2216. else
  2217. begin
  2218. if p1.resultdef.typ<>undefineddef then
  2219. Message(parser_e_invalid_qualifier);
  2220. p1.destroy;
  2221. p1:=cerrornode.create;
  2222. comp_expr([ef_accept_equal]);
  2223. again:=false;
  2224. end;
  2225. end;
  2226. do_typecheckpass(p1);
  2227. until not try_to_consume(_COMMA);
  2228. consume(_RECKKLAMMER);
  2229. { handle_variantarray eats the RECKKLAMMER and jumps here }
  2230. skipreckklammercheck:
  2231. end;
  2232. end;
  2233. _POINT :
  2234. begin
  2235. consume(_POINT);
  2236. allowspecialize:=not (m_delphi in current_settings.modeswitches) and (block_type in inline_specialization_block_types);
  2237. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  2238. begin
  2239. //consume(_ID);
  2240. isspecialize:=true;
  2241. end
  2242. else
  2243. isspecialize:=false;
  2244. autoderef:=false;
  2245. if (p1.resultdef.typ=pointerdef) and
  2246. (m_autoderef in current_settings.modeswitches) and
  2247. { don't auto-deref objc.id, because then the code
  2248. below for supporting id.anyobjcmethod isn't triggered }
  2249. (p1.resultdef<>objc_idtype) then
  2250. begin
  2251. p1:=cderefnode.create(p1);
  2252. do_typecheckpass(p1);
  2253. autoderef:=true;
  2254. end;
  2255. { procvar.<something> can never mean anything so always
  2256. try to call it in case it returns a record/object/... }
  2257. maybe_call_procvar(p1,is_invokable(p1.resultdef) and not is_funcref(p1.resultdef));
  2258. if (p1.nodetype=ordconstn) and
  2259. not is_boolean(p1.resultdef) and
  2260. not is_enum(p1.resultdef) then
  2261. begin
  2262. { type helpers are checked first }
  2263. if (token=_ID) and try_type_helper(p1,nil) then
  2264. goto skippointdefcheck;
  2265. { only an "e" or "E" can follow an intconst with a ".", the
  2266. other case (another intconst) is handled by the scanner }
  2267. if (token=_ID) and (pattern[1]='E') then
  2268. begin
  2269. haderror:=false;
  2270. if length(pattern)>1 then
  2271. begin
  2272. expstr:=copy(pattern,2,length(pattern)-1);
  2273. val(expstr,intval,code);
  2274. if code<>0 then
  2275. begin
  2276. haderror:=true;
  2277. intval:=intval; // Hackfix the "var assigned but never used" note.
  2278. end;
  2279. end
  2280. else
  2281. expstr:='';
  2282. consume(token);
  2283. if tordconstnode(p1).value.signed then
  2284. str(tordconstnode(p1).value.svalue,valstr)
  2285. else
  2286. str(tordconstnode(p1).value.uvalue,valstr);
  2287. valstr:=valstr+'.0E';
  2288. if expstr='' then
  2289. case token of
  2290. _MINUS:
  2291. begin
  2292. consume(token);
  2293. if token=_INTCONST then
  2294. begin
  2295. valstr:=valstr+'-'+pattern;
  2296. consume(token);
  2297. end
  2298. else
  2299. haderror:=true;
  2300. end;
  2301. _PLUS:
  2302. begin
  2303. consume(token);
  2304. if token=_INTCONST then
  2305. begin
  2306. valstr:=valstr+pattern;
  2307. consume(token);
  2308. end
  2309. else
  2310. haderror:=true;
  2311. end;
  2312. _INTCONST:
  2313. begin
  2314. valstr:=valstr+pattern;
  2315. consume(_INTCONST);
  2316. end;
  2317. else
  2318. haderror:=true;
  2319. end
  2320. else
  2321. valstr:=valstr+expstr;
  2322. if haderror then
  2323. begin
  2324. Message(parser_e_error_in_real);
  2325. p2:=cerrornode.create;
  2326. end
  2327. else
  2328. p2:=real_const_node_from_pattern(valstr);
  2329. p1.free;
  2330. p1:=p2;
  2331. again:=false;
  2332. goto skippointdefcheck;
  2333. end
  2334. else
  2335. begin
  2336. { just convert the ordconst to a realconst }
  2337. p2:=crealconstnode.create(tordconstnode(p1).value,pbestrealtype^);
  2338. p1.free;
  2339. p1:=p2;
  2340. again:=false;
  2341. goto skippointdefcheck;
  2342. end;
  2343. end;
  2344. if (p1.nodetype=stringconstn) and (token=_ID) then
  2345. begin
  2346. strdef:=nil;
  2347. { the def of a string const is an array }
  2348. case tstringconstnode(p1).cst_type of
  2349. cst_conststring:
  2350. if cs_refcountedstrings in current_settings.localswitches then
  2351. if m_default_unicodestring in current_settings.modeswitches then
  2352. strdef:=cunicodestringtype
  2353. else
  2354. strdef:=cansistringtype
  2355. else
  2356. strdef:=cshortstringtype;
  2357. cst_shortstring:
  2358. strdef:=cshortstringtype;
  2359. cst_ansistring:
  2360. { use getansistringdef? }
  2361. strdef:=cansistringtype;
  2362. cst_widestring:
  2363. strdef:=cwidestringtype;
  2364. cst_unicodestring:
  2365. strdef:=cunicodestringtype;
  2366. cst_longstring:
  2367. { let's see when someone stumbles upon this...}
  2368. internalerror(201301111);
  2369. end;
  2370. if try_type_helper(p1,strdef) then
  2371. goto skippointdefcheck;
  2372. end;
  2373. { this is skipped if label skippointdefcheck is used }
  2374. case p1.resultdef.typ of
  2375. recorddef:
  2376. begin
  2377. if isspecialize or (token=_ID) then
  2378. begin
  2379. erroroutp1:=true;
  2380. srsym:=nil;
  2381. structh:=tabstractrecorddef(p1.resultdef);
  2382. if isspecialize then
  2383. begin
  2384. { consume the specialize }
  2385. consume(_ID);
  2386. if token<>_ID then
  2387. consume(_ID)
  2388. else
  2389. begin
  2390. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2391. consume(_ID);
  2392. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  2393. erroroutp1:=false;
  2394. end;
  2395. end
  2396. else
  2397. begin
  2398. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2399. if assigned(srsym) then
  2400. begin
  2401. old_current_filepos:=current_filepos;
  2402. consume(_ID);
  2403. if not (sp_generic_dummy in srsym.symoptions) or
  2404. not (token in [_LT,_LSHARPBRACKET]) then
  2405. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2406. else
  2407. p1:=cspecializenode.create(p1,getaddr,srsym);
  2408. erroroutp1:=false;
  2409. end
  2410. else
  2411. begin
  2412. Message1(sym_e_id_no_member,orgpattern);
  2413. { try to clean up }
  2414. consume(_ID);
  2415. end;
  2416. end;
  2417. if erroroutp1 then
  2418. begin
  2419. p1.free;
  2420. p1:=cerrornode.create;
  2421. end
  2422. else
  2423. if p1.nodetype<>specializen then
  2424. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2425. end
  2426. else
  2427. consume(_ID);
  2428. end;
  2429. enumdef:
  2430. begin
  2431. if token=_ID then
  2432. begin
  2433. srsym:=tsym(tenumdef(p1.resultdef).symtable.Find(pattern));
  2434. if assigned(srsym) and (srsym.typ=enumsym) and (p1.nodetype=typen) then
  2435. begin
  2436. p1.destroy;
  2437. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2438. p1:=genenumnode(tenumsym(srsym));
  2439. consume(_ID);
  2440. end
  2441. else
  2442. if not try_type_helper(p1,nil) then
  2443. begin
  2444. p1.destroy;
  2445. Message1(sym_e_id_no_member,orgpattern);
  2446. p1:=cerrornode.create;
  2447. consume(_ID);
  2448. end;
  2449. end;
  2450. end;
  2451. arraydef:
  2452. begin
  2453. if is_dynamic_array(p1.resultdef) then
  2454. begin
  2455. if token=_ID then
  2456. begin
  2457. if not try_type_helper(p1,nil) then
  2458. begin
  2459. if p1.nodetype=typen then
  2460. begin
  2461. if pattern='CREATE' then
  2462. begin
  2463. consume(_ID);
  2464. p2:=parse_array_constructor(tarraydef(p1.resultdef));
  2465. p1.destroy;
  2466. p1:=p2;
  2467. end
  2468. else
  2469. begin
  2470. Message2(scan_f_syn_expected,'CREATE',pattern);
  2471. p1.destroy;
  2472. p1:=cerrornode.create;
  2473. consume(_ID);
  2474. end;
  2475. end
  2476. else
  2477. begin
  2478. Message(parser_e_invalid_qualifier);
  2479. p1.destroy;
  2480. p1:=cerrornode.create;
  2481. consume(_ID);
  2482. end;
  2483. end;
  2484. end
  2485. else
  2486. begin
  2487. Message(parser_e_invalid_qualifier);
  2488. p1.destroy;
  2489. p1:=cerrornode.create;
  2490. consume(_ID);
  2491. end;
  2492. end
  2493. else
  2494. if (token<>_ID) or not try_type_helper(p1,nil) then
  2495. begin
  2496. Message(parser_e_invalid_qualifier);
  2497. p1.destroy;
  2498. p1:=cerrornode.create;
  2499. consume(_ID);
  2500. end;
  2501. end;
  2502. variantdef:
  2503. begin
  2504. { dispatch call? }
  2505. { lhs := v.ident[parameters] -> property get
  2506. lhs := v.ident(parameters) -> method call
  2507. v.ident[parameters] := rhs -> property put
  2508. v.ident(parameters) := rhs -> also property put }
  2509. if token=_ID then
  2510. begin
  2511. if not try_type_helper(p1,nil) then
  2512. begin
  2513. dispatchstring:=orgpattern;
  2514. consume(_ID);
  2515. calltype:=dct_method;
  2516. if try_to_consume(_LKLAMMER) then
  2517. begin
  2518. p2:=parse_paras(false,true,_RKLAMMER);
  2519. consume(_RKLAMMER);
  2520. end
  2521. else if try_to_consume(_LECKKLAMMER) then
  2522. begin
  2523. p2:=parse_paras(false,true,_RECKKLAMMER);
  2524. consume(_RECKKLAMMER);
  2525. calltype:=dct_propget;
  2526. end
  2527. else
  2528. p2:=nil;
  2529. { property setter? }
  2530. if (token=_ASSIGNMENT) and not(afterassignment) then
  2531. begin
  2532. consume(_ASSIGNMENT);
  2533. { read the expression }
  2534. p3:=comp_expr([ef_accept_equal]);
  2535. { concat value parameter too }
  2536. p2:=ccallparanode.create(p3,p2);
  2537. p1:=translate_disp_call(p1,p2,dct_propput,dispatchstring,0,voidtype);
  2538. end
  2539. else
  2540. { this is only an approximation
  2541. setting useresult if not necessary is only a waste of time, no more, no less (FK) }
  2542. if afterassignment or in_args or (token<>_SEMICOLON) then
  2543. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,cvarianttype)
  2544. else
  2545. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,voidtype);
  2546. end;
  2547. end
  2548. else { Error }
  2549. Consume(_ID);
  2550. end;
  2551. classrefdef:
  2552. begin
  2553. erroroutp1:=true;
  2554. if token=_ID then
  2555. begin
  2556. srsym:=nil;
  2557. structh:=tobjectdef(tclassrefdef(p1.resultdef).pointeddef);
  2558. if isspecialize then
  2559. begin
  2560. { consume the specialize }
  2561. consume(_ID);
  2562. if token<>_ID then
  2563. consume(_ID)
  2564. else
  2565. begin
  2566. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2567. consume(_ID);
  2568. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  2569. erroroutp1:=false;
  2570. end;
  2571. end
  2572. else
  2573. begin
  2574. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2575. if assigned(srsym) then
  2576. begin
  2577. old_current_filepos:=current_filepos;
  2578. consume(_ID);
  2579. if not (sp_generic_dummy in srsym.symoptions) or
  2580. not (token in [_LT,_LSHARPBRACKET]) then
  2581. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2582. else
  2583. p1:=cspecializenode.create(p1,getaddr,srsym);
  2584. erroroutp1:=false;
  2585. end
  2586. else
  2587. begin
  2588. Message1(sym_e_id_no_member,orgpattern);
  2589. { try to clean up }
  2590. consume(_ID);
  2591. end;
  2592. end;
  2593. if erroroutp1 then
  2594. begin
  2595. p1.free;
  2596. p1:=cerrornode.create;
  2597. end
  2598. else
  2599. if p1.nodetype<>specializen then
  2600. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2601. end
  2602. else { Error }
  2603. Consume(_ID);
  2604. end;
  2605. objectdef:
  2606. begin
  2607. if isspecialize or (token=_ID) then
  2608. begin
  2609. erroroutp1:=true;
  2610. srsym:=nil;
  2611. structh:=tobjectdef(p1.resultdef);
  2612. if isspecialize then
  2613. begin
  2614. { consume the "specialize" }
  2615. consume(_ID);
  2616. if token<>_ID then
  2617. consume(_ID)
  2618. else
  2619. begin
  2620. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2621. consume(_ID);
  2622. if handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  2623. erroroutp1:=false;
  2624. end;
  2625. end
  2626. else
  2627. begin
  2628. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2629. if assigned(srsym) then
  2630. begin
  2631. old_current_filepos:=current_filepos;
  2632. consume(_ID);
  2633. if not (sp_generic_dummy in srsym.symoptions) or
  2634. not (token in [_LT,_LSHARPBRACKET]) then
  2635. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg,old_current_filepos)
  2636. else
  2637. p1:=cspecializenode.create(p1,getaddr,srsym);
  2638. erroroutp1:=false;
  2639. end
  2640. else
  2641. begin
  2642. Message1(sym_e_id_no_member,orgpattern);
  2643. { try to clean up }
  2644. consume(_ID);
  2645. end;
  2646. end;
  2647. if erroroutp1 then
  2648. begin
  2649. p1.free;
  2650. p1:=cerrornode.create;
  2651. end
  2652. else
  2653. if p1.nodetype<>specializen then
  2654. do_member_read(structh,getaddr,srsym,p1,again,[],spezcontext);
  2655. end
  2656. else { Error }
  2657. Consume(_ID);
  2658. end;
  2659. pointerdef:
  2660. begin
  2661. if (p1.resultdef=objc_idtype) then
  2662. begin
  2663. { objc's id type can be used to call any
  2664. Objective-C method of any Objective-C class
  2665. type that's currently in scope }
  2666. if search_objc_method(pattern,srsym,srsymtable) then
  2667. begin
  2668. consume(_ID);
  2669. do_proc_call(srsym,srsymtable,nil,
  2670. (getaddr and not(token in [_CARET,_POINT])),
  2671. again,p1,[cnf_objc_id_call],nil);
  2672. { we need to know which procedure is called }
  2673. do_typecheckpass(p1);
  2674. end
  2675. else
  2676. begin
  2677. consume(_ID);
  2678. Message(parser_e_methode_id_expected);
  2679. end;
  2680. end
  2681. else
  2682. begin
  2683. if not try_type_helper(p1,nil) then
  2684. begin
  2685. Message(parser_e_invalid_qualifier);
  2686. if tpointerdef(p1.resultdef).pointeddef.typ in [recorddef,objectdef,classrefdef] then
  2687. Message(parser_h_maybe_deref_caret_missing);
  2688. end;
  2689. end
  2690. end;
  2691. else
  2692. begin
  2693. if autoderef then
  2694. begin
  2695. { always try with the not dereferenced node }
  2696. p2:=tderefnode(p1).left;
  2697. found:=try_type_helper(p2,nil);
  2698. if found then
  2699. begin
  2700. tderefnode(p1).left:=nil;
  2701. p1.destroy;
  2702. p1:=p2;
  2703. end;
  2704. end
  2705. else
  2706. found:=try_type_helper(p1,nil);
  2707. if not found then
  2708. begin
  2709. if p1.resultdef.typ<>undefineddef then
  2710. Message(parser_e_invalid_qualifier);
  2711. p1.destroy;
  2712. p1:=cerrornode.create;
  2713. { Error }
  2714. consume(_ID);
  2715. end;
  2716. end;
  2717. end;
  2718. { processing an ordconstnode avoids the resultdef check }
  2719. skippointdefcheck:
  2720. end;
  2721. else
  2722. begin
  2723. { is this a procedure variable ? }
  2724. if is_invokable(p1.resultdef) and
  2725. (token=_LKLAMMER) then
  2726. begin
  2727. if not searchsym_in_class(tobjectdef(p1.resultdef),tobjectdef(p1.resultdef),method_name_funcref_invoke_find,srsym,srsymtable,[]) then
  2728. internalerror(2021040202);
  2729. include(p1.flags,nf_load_procvar);
  2730. do_proc_call(srsym,srsymtable,tabstractrecorddef(p1.resultdef),false,again,p1,[],nil);
  2731. end
  2732. else if assigned(p1.resultdef) and
  2733. (p1.resultdef.typ=procvardef) then
  2734. begin
  2735. { Typenode for typecasting or expecting a procvar }
  2736. if (p1.nodetype=typen) or
  2737. (
  2738. assigned(getprocvardef) and
  2739. equal_defs(p1.resultdef,getprocvardef)
  2740. ) or
  2741. (
  2742. assigned(getfuncrefdef) and
  2743. equal_defs(p1.resultdef,getfuncrefdef)
  2744. ) then
  2745. begin
  2746. if try_to_consume(_LKLAMMER) then
  2747. begin
  2748. p1:=comp_expr([ef_accept_equal]);
  2749. consume(_RKLAMMER);
  2750. p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
  2751. end
  2752. else
  2753. again:=false
  2754. end
  2755. else
  2756. begin
  2757. if try_to_consume(_LKLAMMER) then
  2758. begin
  2759. p2:=parse_paras(false,false,_RKLAMMER);
  2760. consume(_RKLAMMER);
  2761. p1:=ccallnode.create_procvar(p2,p1);
  2762. { proc():= is never possible }
  2763. if token=_ASSIGNMENT then
  2764. begin
  2765. Message(parser_e_illegal_expression);
  2766. p1.free;
  2767. p1:=cerrornode.create;
  2768. again:=false;
  2769. end;
  2770. end
  2771. else
  2772. again:=false;
  2773. end;
  2774. end
  2775. else
  2776. again:=false;
  2777. end;
  2778. end;
  2779. { we only try again if p1 was changed }
  2780. if again or
  2781. (p1.nodetype=errorn) then
  2782. result:=true;
  2783. end; { while again }
  2784. end;
  2785. function is_member_read(sym: tsym; st: tsymtable; var p1: tnode;
  2786. out memberparentdef: tdef): boolean;
  2787. var
  2788. hdef : tdef;
  2789. begin
  2790. result:=true;
  2791. memberparentdef:=nil;
  2792. case st.symtabletype of
  2793. ObjectSymtable,
  2794. recordsymtable:
  2795. begin
  2796. memberparentdef:=tdef(st.defowner);
  2797. exit;
  2798. end;
  2799. WithSymtable:
  2800. begin
  2801. if assigned(p1) then
  2802. internalerror(2007012002);
  2803. hdef:=tnode(twithsymtable(st).withrefnode).resultdef;
  2804. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  2805. if not(hdef.typ in [objectdef,classrefdef]) then
  2806. exit;
  2807. if (hdef.typ=classrefdef) then
  2808. hdef:=tclassrefdef(hdef).pointeddef;
  2809. memberparentdef:=hdef;
  2810. end;
  2811. else
  2812. result:=false;
  2813. end;
  2814. end;
  2815. {$maxfpuregisters 0}
  2816. function factor_handle_sym(srsym:tsym;srsymtable:tsymtable;var again:boolean;getaddr:boolean;unit_found:boolean;flags:texprflags;var spezcontext:tspecializationcontext):tnode;
  2817. var
  2818. hdef : tdef;
  2819. pd : tprocdef;
  2820. callflags : tcallnodeflags;
  2821. tmpgetaddr : boolean;
  2822. begin
  2823. hdef:=nil;
  2824. result:=nil;
  2825. case srsym.typ of
  2826. absolutevarsym :
  2827. begin
  2828. if (tabsolutevarsym(srsym).abstyp=tovar) then
  2829. begin
  2830. result:=nil;
  2831. propaccesslist_to_node(result,nil,tabsolutevarsym(srsym).ref);
  2832. result:=ctypeconvnode.create(result,tabsolutevarsym(srsym).vardef);
  2833. include(result.flags,nf_absolute);
  2834. end
  2835. else
  2836. result:=cloadnode.create(srsym,srsymtable);
  2837. end;
  2838. staticvarsym,
  2839. localvarsym,
  2840. paravarsym,
  2841. fieldvarsym :
  2842. begin
  2843. { check if we are reading a field of an object/class/ }
  2844. { record. is_member_read() will deal with withsymtables }
  2845. { if needed. }
  2846. result:=nil;
  2847. if is_member_read(srsym,srsymtable,result,hdef) then
  2848. begin
  2849. { if the field was originally found in an }
  2850. { objectsymtable, it means it's part of self }
  2851. { if only method from which it was called is }
  2852. { not class static }
  2853. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2854. { if we are accessing a owner procsym from the nested }
  2855. { class we need to call it as a class member }
  2856. if assigned(current_structdef) and
  2857. (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  2858. (sp_static in srsym.symoptions)) then
  2859. if srsymtable.symtabletype=recordsymtable then
  2860. result:=ctypenode.create(hdef)
  2861. else
  2862. result:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2863. else
  2864. begin
  2865. if assigned(current_procinfo) then
  2866. begin
  2867. pd:=current_procinfo.get_normal_proc.procdef;
  2868. if assigned(pd) and pd.no_self_node then
  2869. result:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  2870. else
  2871. result:=load_self_node;
  2872. end
  2873. else
  2874. result:=load_self_node;
  2875. end;
  2876. { now, if the field itself is part of an objectsymtab }
  2877. { (it can be even if it was found in a withsymtable, }
  2878. { e.g., "with classinstance do field := 5"), then }
  2879. { let do_member_read handle it }
  2880. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2881. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil)
  2882. else
  2883. { otherwise it's a regular record subscript }
  2884. result:=csubscriptnode.create(srsym,result);
  2885. end
  2886. else
  2887. { regular non-field load }
  2888. result:=cloadnode.create(srsym,srsymtable);
  2889. end;
  2890. syssym :
  2891. begin
  2892. result:=statement_syssym(tsyssym(srsym).number);
  2893. end;
  2894. typesym :
  2895. begin
  2896. hdef:=ttypesym(srsym).typedef;
  2897. if not assigned(hdef) then
  2898. begin
  2899. again:=false;
  2900. end
  2901. else
  2902. begin
  2903. if (m_delphi in current_settings.modeswitches) and
  2904. (sp_generic_dummy in srsym.symoptions) and
  2905. (token in [_LT,_LSHARPBRACKET]) then
  2906. begin
  2907. if block_type in [bt_type,bt_const_type,bt_var_type] then
  2908. begin
  2909. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) or (srsym.typ=procsym) then
  2910. begin
  2911. spezcontext.free;
  2912. result:=cerrornode.create;
  2913. if try_to_consume(_LKLAMMER) then
  2914. begin
  2915. parse_paras(false,false,_RKLAMMER);
  2916. consume(_RKLAMMER);
  2917. end;
  2918. end
  2919. else
  2920. begin
  2921. if srsym.typ<>typesym then
  2922. internalerror(2015071705);
  2923. hdef:=ttypesym(srsym).typedef;
  2924. result:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  2925. end;
  2926. end
  2927. else
  2928. result:=cspecializenode.create(nil,getaddr,srsym)
  2929. end
  2930. else
  2931. begin
  2932. { We need to know if this unit uses Variants }
  2933. if ((hdef=cvarianttype) or (hdef=colevarianttype)) and
  2934. not(cs_compilesystem in current_settings.moduleswitches) then
  2935. include(current_module.moduleflags,mf_uses_variants);
  2936. result:=handle_factor_typenode(hdef,getaddr,again,srsym,ef_type_only in flags);
  2937. end;
  2938. end;
  2939. end;
  2940. enumsym :
  2941. begin
  2942. result:=genenumnode(tenumsym(srsym));
  2943. end;
  2944. constsym :
  2945. begin
  2946. if tconstsym(srsym).consttyp=constresourcestring then
  2947. begin
  2948. result:=cloadnode.create(srsym,srsymtable);
  2949. do_typecheckpass(result);
  2950. result.resultdef:=getansistringdef;
  2951. end
  2952. else
  2953. result:=genconstsymtree(tconstsym(srsym));
  2954. end;
  2955. procsym :
  2956. begin
  2957. result:=nil;
  2958. if (m_delphi in current_settings.modeswitches) and
  2959. (sp_generic_dummy in srsym.symoptions) and
  2960. (token in [_LT,_LSHARPBRACKET]) then
  2961. begin
  2962. result:=cspecializenode.create(nil,getaddr,srsym)
  2963. end
  2964. { check if it's a method/class method }
  2965. else if is_member_read(srsym,srsymtable,result,hdef) then
  2966. begin
  2967. { if we are accessing a owner procsym from the nested }
  2968. { class we need to call it as a class member }
  2969. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  2970. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2971. result:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  2972. { not srsymtable.symtabletype since that can be }
  2973. { withsymtable as well }
  2974. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2975. begin
  2976. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],spezcontext);
  2977. spezcontext:=nil;
  2978. end
  2979. else
  2980. { no procsyms in records (yet) }
  2981. internalerror(2007012006);
  2982. end
  2983. else
  2984. begin
  2985. { regular procedure/function call }
  2986. if not unit_found then
  2987. callflags:=[]
  2988. else
  2989. callflags:=[cnf_unit_specified];
  2990. { TP7 uglyness: @proc^ is parsed as (@proc)^,
  2991. but @notproc^ is parsed as @(notproc^) }
  2992. if m_tp_procvar in current_settings.modeswitches then
  2993. tmpgetaddr:=getaddr and not(token in [_POINT,_LECKKLAMMER])
  2994. else
  2995. tmpgetaddr:=getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER]);
  2996. do_proc_call(srsym,srsymtable,nil,tmpgetaddr,
  2997. again,result,callflags,spezcontext);
  2998. spezcontext:=nil;
  2999. end;
  3000. end;
  3001. propertysym :
  3002. begin
  3003. result:=nil;
  3004. { property of a class/object? }
  3005. if is_member_read(srsym,srsymtable,result,hdef) then
  3006. begin
  3007. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  3008. { if we are accessing a owner procsym from the nested }
  3009. { class or from a static class method we need to call }
  3010. { it as a class member }
  3011. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  3012. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  3013. begin
  3014. result:=ctypenode.create(hdef);
  3015. if not is_record(hdef) then
  3016. result:=cloadvmtaddrnode.create(result);
  3017. end
  3018. else
  3019. result:=load_self_node;
  3020. { not srsymtable.symtabletype since that can be }
  3021. { withsymtable as well }
  3022. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  3023. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[],nil)
  3024. else
  3025. { no propertysyms in records (yet) }
  3026. internalerror(2009111510);
  3027. end
  3028. else
  3029. { no method pointer }
  3030. begin
  3031. handle_propertysym(tpropertysym(srsym),srsymtable,result);
  3032. end;
  3033. end;
  3034. labelsym :
  3035. begin
  3036. { Support @label }
  3037. if getaddr then
  3038. begin
  3039. if srsym.owner<>current_procinfo.procdef.localst then
  3040. CGMessage(parser_e_label_outside_proc);
  3041. result:=cloadnode.create(srsym,srsym.owner)
  3042. end
  3043. else
  3044. begin
  3045. consume(_COLON);
  3046. if tlabelsym(srsym).defined then
  3047. Message(sym_e_label_already_defined);
  3048. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  3049. begin
  3050. include(current_procinfo.flags,pi_has_interproclabel);
  3051. if (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  3052. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  3053. end;
  3054. tlabelsym(srsym).defined:=true;
  3055. result:=clabelnode.create(nil,tlabelsym(srsym));
  3056. tlabelsym(srsym).code:=result;
  3057. end;
  3058. end;
  3059. undefinedsym :
  3060. begin
  3061. result:=cnothingnode.Create;
  3062. result.resultdef:=cundefineddef.create(true);
  3063. { clean up previously created dummy symbol }
  3064. srsym.free;
  3065. end;
  3066. errorsym :
  3067. begin
  3068. result:=cerrornode.create;
  3069. if try_to_consume(_LKLAMMER) then
  3070. begin
  3071. parse_paras(false,false,_RKLAMMER);
  3072. consume(_RKLAMMER);
  3073. end;
  3074. end;
  3075. else
  3076. begin
  3077. result:=cerrornode.create;
  3078. Message(parser_e_illegal_expression);
  3079. end;
  3080. end; { end case }
  3081. end;
  3082. function factor(getaddr:boolean;flags:texprflags) : tnode;
  3083. {---------------------------------------------
  3084. Factor_read_id
  3085. ---------------------------------------------}
  3086. procedure factor_read_id(out p1:tnode;out again:boolean);
  3087. function findwithsymtable : boolean;
  3088. var
  3089. hp : psymtablestackitem;
  3090. begin
  3091. result:=true;
  3092. hp:=symtablestack.stack;
  3093. while assigned(hp) do
  3094. begin
  3095. if hp^.symtable.symtabletype=withsymtable then
  3096. exit;
  3097. hp:=hp^.next;
  3098. end;
  3099. result:=false;
  3100. end;
  3101. var
  3102. srsym: tsym;
  3103. srsymtable: TSymtable;
  3104. hdef: tdef;
  3105. orgstoredpattern,
  3106. storedpattern: string;
  3107. t : ttoken;
  3108. consumeid,
  3109. wasgenericdummy,
  3110. allowspecialize,
  3111. isspecialize,
  3112. unit_found : boolean;
  3113. dummypos,
  3114. tokenpos: tfileposinfo;
  3115. spezcontext : tspecializationcontext;
  3116. cufflags : tconsume_unitsym_flags;
  3117. begin
  3118. { allow post fix operators }
  3119. again:=true;
  3120. { preinitalize tokenpos }
  3121. tokenpos:=current_filepos;
  3122. p1:=nil;
  3123. spezcontext:=nil;
  3124. { avoid warning }
  3125. fillchar(dummypos,sizeof(dummypos),0);
  3126. allowspecialize:=not (m_delphi in current_settings.modeswitches) and
  3127. not (ef_had_specialize in flags) and
  3128. (block_type in inline_specialization_block_types);
  3129. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  3130. begin
  3131. consume(_ID);
  3132. isspecialize:=true;
  3133. end
  3134. else
  3135. isspecialize:=ef_had_specialize in flags;
  3136. { first check for identifier }
  3137. if token<>_ID then
  3138. begin
  3139. srsym:=generrorsym;
  3140. srsymtable:=nil;
  3141. consume(_ID);
  3142. unit_found:=false;
  3143. end
  3144. else
  3145. begin
  3146. storedpattern:=pattern;
  3147. orgstoredpattern:=orgpattern;
  3148. { store the position of the token before consuming it }
  3149. tokenpos:=current_filepos;
  3150. consumeid:=true;
  3151. srsym:=nil;
  3152. if ef_check_attr_suffix in flags then
  3153. begin
  3154. if not (ef_type_only in flags) then
  3155. internalerror(2019063001);
  3156. consume(_ID);
  3157. consumeid:=false;
  3158. if token<>_POINT then
  3159. searchsym_type(storedpattern+custom_attribute_suffix,srsym,srsymtable);
  3160. end;
  3161. if not assigned(srsym) then
  3162. begin
  3163. if ef_type_only in flags then
  3164. searchsym_type(storedpattern,srsym,srsymtable)
  3165. else
  3166. searchsym(storedpattern,srsym,srsymtable);
  3167. end;
  3168. { handle unit specification like System.Writeln }
  3169. if not isspecialize then
  3170. begin
  3171. cufflags:=[];
  3172. if consumeid then
  3173. include(cufflags,cuf_consume_id);
  3174. if allowspecialize then
  3175. include(cufflags,cuf_allow_specialize);
  3176. if ef_check_attr_suffix in flags then
  3177. include(cufflags,cuf_check_attr_suffix);
  3178. unit_found:=try_consume_unitsym(srsym,srsymtable,t,cufflags,isspecialize,pattern);
  3179. if unit_found then
  3180. consumeid:=true;
  3181. end
  3182. else
  3183. begin
  3184. unit_found:=false;
  3185. t:=_ID;
  3186. end;
  3187. if consumeid then
  3188. begin
  3189. storedpattern:=pattern;
  3190. orgstoredpattern:=orgpattern;
  3191. { store the position of the token before consuming it }
  3192. tokenpos:=current_filepos;
  3193. consume(t);
  3194. end;
  3195. { named parameter support }
  3196. found_arg_name:=false;
  3197. if not(unit_found) and
  3198. not isspecialize and
  3199. named_args_allowed and
  3200. (token=_ASSIGNMENT) then
  3201. begin
  3202. found_arg_name:=true;
  3203. p1:=cstringconstnode.createstr(orgstoredpattern);
  3204. consume(_ASSIGNMENT);
  3205. exit;
  3206. end;
  3207. if isspecialize then
  3208. begin
  3209. if not assigned(srsym) then
  3210. begin
  3211. identifier_not_found(orgstoredpattern,tokenpos);
  3212. srsym:=generrorsym;
  3213. srsymtable:=nil;
  3214. end
  3215. else
  3216. begin
  3217. {$push}
  3218. {$warn 5036 off}
  3219. hdef:=generate_specialization_phase1(spezcontext,nil,nil,orgstoredpattern,nil,dummypos);
  3220. {$pop}
  3221. if hdef=generrordef then
  3222. begin
  3223. spezcontext.free;
  3224. spezcontext:=nil;
  3225. srsym:=generrorsym;
  3226. srsymtable:=nil;
  3227. end
  3228. else
  3229. begin
  3230. if hdef.typ in [objectdef,recorddef,procvardef,arraydef] then
  3231. begin
  3232. hdef:=generate_specialization_phase2(spezcontext,tstoreddef(hdef),false,'');
  3233. spezcontext.free;
  3234. spezcontext:=nil;
  3235. if hdef<>generrordef then
  3236. begin
  3237. srsym:=hdef.typesym;
  3238. srsymtable:=srsym.owner;
  3239. end
  3240. else
  3241. begin
  3242. srsym:=generrorsym;
  3243. srsymtable:=nil;
  3244. end;
  3245. end
  3246. else
  3247. if hdef.typ=procdef then
  3248. begin
  3249. if block_type<>bt_body then
  3250. message(parser_e_illegal_expression);
  3251. srsym:=tprocdef(hdef).procsym;
  3252. if assigned(spezcontext.symtable) then
  3253. srsymtable:=spezcontext.symtable
  3254. else
  3255. srsymtable:=srsym.owner;
  3256. end
  3257. else
  3258. internalerror(2015061204);
  3259. end;
  3260. end;
  3261. end;
  3262. wasgenericdummy:=false;
  3263. if assigned(srsym) and
  3264. (sp_generic_dummy in srsym.symoptions) and
  3265. (srsym.typ in [procsym,typesym]) and
  3266. (
  3267. (
  3268. (m_delphi in current_settings.modeswitches) and
  3269. not (token in [_LT, _LSHARPBRACKET]) and
  3270. (
  3271. (
  3272. (srsym.typ=typesym) and
  3273. (ttypesym(srsym).typedef.typ=undefineddef)
  3274. ) or (
  3275. (srsym.typ=procsym) and
  3276. (tprocsym(srsym).procdeflist.count=0)
  3277. )
  3278. )
  3279. )
  3280. or
  3281. (
  3282. not (m_delphi in current_settings.modeswitches) and
  3283. not isspecialize and
  3284. (
  3285. not parse_generic or
  3286. not (
  3287. assigned(current_structdef) and
  3288. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  3289. )
  3290. )
  3291. )
  3292. ) then
  3293. begin
  3294. srsym:=resolve_generic_dummysym(srsym.name);
  3295. if assigned(srsym) then
  3296. srsymtable:=srsym.owner
  3297. else
  3298. begin
  3299. srsymtable:=nil;
  3300. wasgenericdummy:=true;
  3301. end;
  3302. end;
  3303. { check hints, but only if it isn't a potential generic symbol;
  3304. that is checked in sub_expr if it isn't a generic }
  3305. if assigned(srsym) and
  3306. not (
  3307. (srsym.typ=typesym) and
  3308. (
  3309. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) or
  3310. (
  3311. (ttypesym(srsym).typedef.typ=errordef) and
  3312. (sp_generic_dummy in srsym.symoptions)
  3313. )
  3314. ) and
  3315. not (sp_generic_para in srsym.symoptions) and
  3316. (token in [_LT, _LSHARPBRACKET])
  3317. ) then
  3318. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3319. { if nothing found give error and return errorsym }
  3320. if not assigned(srsym) or
  3321. { is this a generic dummy symbol? }
  3322. ((srsym.typ=typesym) and
  3323. assigned(ttypesym(srsym).typedef) and
  3324. (ttypesym(srsym).typedef.typ=undefineddef) and
  3325. not (sp_generic_para in srsym.symoptions) and
  3326. not (token in [_LT, _LSHARPBRACKET]) and
  3327. not (
  3328. { in non-Delphi modes the generic class' name without a
  3329. "specialization" or "<T>" may be used to identify the
  3330. current class }
  3331. (sp_generic_dummy in srsym.symoptions) and
  3332. assigned(current_structdef) and
  3333. (df_generic in current_structdef.defoptions) and
  3334. not (m_delphi in current_settings.modeswitches) and
  3335. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  3336. )) and
  3337. { it could be a rename of a generic para }
  3338. { Note: if this generates false positives we'll need to
  3339. include a "basesym" to tsym to track the original
  3340. symbol }
  3341. not (sp_explicitrename in srsym.symoptions) then
  3342. begin
  3343. { if a generic is parsed and when we are inside an with block,
  3344. a symbol might not be defined }
  3345. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  3346. findwithsymtable then
  3347. begin
  3348. { create dummy symbol, it will be freed later on }
  3349. srsym:=tstoredsym.create(undefinedsym,'$undefinedsym');
  3350. srsymtable:=nil;
  3351. end
  3352. else
  3353. begin
  3354. if wasgenericdummy then
  3355. messagepos(tokenpos,parser_e_no_generics_as_types)
  3356. else
  3357. identifier_not_found(orgstoredpattern,tokenpos);
  3358. srsym:=generrorsym;
  3359. srsymtable:=nil;
  3360. end;
  3361. end;
  3362. end;
  3363. { Access to funcret or need to call the function? }
  3364. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  3365. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  3366. { result(x) is not allowed }
  3367. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  3368. (
  3369. (token=_LKLAMMER) or
  3370. (
  3371. (([m_tp7,m_delphi,m_mac,m_iso,m_extpas] * current_settings.modeswitches) <> []) and
  3372. (afterassignment or in_args)
  3373. )
  3374. ) then
  3375. begin
  3376. hdef:=tdef(srsym.owner.defowner);
  3377. if assigned(hdef) and
  3378. (hdef.typ=procdef) then
  3379. srsym:=tprocdef(hdef).procsym
  3380. else
  3381. begin
  3382. Message(parser_e_illegal_expression);
  3383. srsym:=generrorsym;
  3384. end;
  3385. srsymtable:=srsym.owner;
  3386. end;
  3387. begin
  3388. p1:=factor_handle_sym(srsym,srsymtable,again,getaddr,unit_found,flags,spezcontext);
  3389. if assigned(spezcontext) then
  3390. internalerror(2015061207);
  3391. if assigned(p1) and (p1.nodetype<>errorn) then
  3392. p1.fileinfo:=tokenpos;
  3393. end;
  3394. end;
  3395. {---------------------------------------------
  3396. Factor_Read_Set
  3397. ---------------------------------------------}
  3398. { Read a set between [] }
  3399. function factor_read_set:tnode;
  3400. var
  3401. p1,p2 : tnode;
  3402. lastp,
  3403. buildp : tarrayconstructornode;
  3404. begin
  3405. buildp:=nil;
  3406. lastp:=nil;
  3407. { be sure that a least one arrayconstructn is used, also for an
  3408. empty [] }
  3409. if token=_RECKKLAMMER then
  3410. buildp:=carrayconstructornode.create(nil,buildp)
  3411. else
  3412. repeat
  3413. p1:=comp_expr([ef_accept_equal]);
  3414. if try_to_consume(_POINTPOINT) then
  3415. begin
  3416. p2:=comp_expr([ef_accept_equal]);
  3417. p1:=carrayconstructorrangenode.create(p1,p2);
  3418. end;
  3419. { insert at the end of the tree, to get the correct order }
  3420. if not assigned(buildp) then
  3421. begin
  3422. buildp:=carrayconstructornode.create(p1,nil);
  3423. lastp:=buildp;
  3424. end
  3425. else
  3426. begin
  3427. lastp.right:=carrayconstructornode.create(p1,nil);
  3428. lastp:=tarrayconstructornode(lastp.right);
  3429. end;
  3430. { there could be more elements }
  3431. until not try_to_consume(_COMMA);
  3432. buildp.allow_array_constructor:=block_type in [bt_body,bt_except];
  3433. factor_read_set:=buildp;
  3434. end;
  3435. function can_load_self_node: boolean;
  3436. begin
  3437. result:=false;
  3438. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  3439. not assigned(current_structdef) or
  3440. not assigned(current_procinfo) then
  3441. exit;
  3442. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  3443. end;
  3444. {---------------------------------------------
  3445. Factor (Main)
  3446. ---------------------------------------------}
  3447. var
  3448. l : longint;
  3449. ic : int64;
  3450. qc : qword;
  3451. p1 : tnode;
  3452. code : integer;
  3453. srsym : tsym;
  3454. srsymtable : TSymtable;
  3455. pd : tprocdef;
  3456. hclassdef : tobjectdef;
  3457. d : bestreal;
  3458. hs,hsorg : string;
  3459. hdef : tdef;
  3460. filepos : tfileposinfo;
  3461. callflags : tcallnodeflags;
  3462. idstr : tidstring;
  3463. spezcontext : tspecializationcontext;
  3464. isspecialize,
  3465. mightbegeneric,
  3466. useself,
  3467. dopostfix,
  3468. again,
  3469. updatefpos,
  3470. nodechanged : boolean;
  3471. oldprocvardef : tprocvardef;
  3472. oldfuncrefdef : tobjectdef;
  3473. begin
  3474. { can't keep a copy of p1 and compare pointers afterwards, because
  3475. p1 may be freed and reallocated in the same place! }
  3476. dopostfix:=true;
  3477. updatefpos:=false;
  3478. p1:=nil;
  3479. filepos:=current_tokenpos;
  3480. again:=false;
  3481. pd:=nil;
  3482. isspecialize:=false;
  3483. if token=_ID then
  3484. begin
  3485. again:=true;
  3486. { Handle references to self }
  3487. if (idtoken=_SELF) and can_load_self_node then
  3488. begin
  3489. p1:=load_self_node;
  3490. consume(_ID);
  3491. again:=true;
  3492. end
  3493. else
  3494. factor_read_id(p1,again);
  3495. if assigned(p1) then
  3496. begin
  3497. { factor_read_id will set the filepos to after the id,
  3498. and in case of _SELF the filepos will already be the
  3499. same as filepos (so setting it again doesn't hurt). }
  3500. p1.fileinfo:=filepos;
  3501. filepos:=current_tokenpos;
  3502. end;
  3503. { handle post fix operators }
  3504. if (p1.nodetype=specializen) then
  3505. { post fix operators are handled after specialization }
  3506. dopostfix:=false
  3507. else
  3508. if (m_delphi in current_settings.modeswitches) and
  3509. (block_type=bt_body) and
  3510. (token in [_LT,_LSHARPBRACKET]) then
  3511. begin
  3512. idstr:='';
  3513. case p1.nodetype of
  3514. typen:
  3515. idstr:=ttypenode(p1).typesym.name;
  3516. loadvmtaddrn:
  3517. if tloadvmtaddrnode(p1).left.nodetype=typen then
  3518. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name;
  3519. loadn:
  3520. idstr:=tloadnode(p1).symtableentry.name;
  3521. calln:
  3522. idstr:=tcallnode(p1).symtableprocentry.name;
  3523. else
  3524. ;
  3525. end;
  3526. { if this is the case then the postfix handling is done in
  3527. sub_expr if necessary }
  3528. dopostfix:=not could_be_generic(idstr);
  3529. end;
  3530. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^ is parsed
  3531. as @(notproc^) }
  3532. if (m_tp_procvar in current_settings.modeswitches) and (token=_CARET) and
  3533. getaddr and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym) then
  3534. dopostfix:=false;
  3535. { maybe an additional parameter instead of misusing hadspezialize? }
  3536. if dopostfix and not (ef_had_specialize in flags) then
  3537. updatefpos:=postfixoperators(p1,again,getaddr);
  3538. end
  3539. else
  3540. begin
  3541. updatefpos:=true;
  3542. case token of
  3543. _RETURN :
  3544. begin
  3545. consume(_RETURN);
  3546. p1:=nil;
  3547. if not(token in [_SEMICOLON,_ELSE,_END]) then
  3548. begin
  3549. p1:=comp_expr([ef_accept_equal]);
  3550. if not assigned(current_procinfo) or
  3551. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  3552. is_void(current_procinfo.procdef.returndef) then
  3553. begin
  3554. Message(parser_e_void_function);
  3555. { recovery }
  3556. p1.free;
  3557. p1:=nil;
  3558. end;
  3559. end;
  3560. p1 := cexitnode.create(p1);
  3561. end;
  3562. _INHERITED :
  3563. begin
  3564. again:=true;
  3565. consume(_INHERITED);
  3566. if assigned(current_procinfo) and
  3567. assigned(current_structdef) and
  3568. ((current_structdef.typ=objectdef) or
  3569. ((target_info.system in systems_jvm) and
  3570. (current_structdef.typ=recorddef)))then
  3571. begin
  3572. { for record helpers in mode Delphi "inherited" is not
  3573. allowed }
  3574. if is_objectpascal_helper(current_structdef) and
  3575. (m_delphi in current_settings.modeswitches) and
  3576. (tobjectdef(current_structdef).helpertype=ht_record) then
  3577. Message(parser_e_inherited_not_in_record);
  3578. if (current_structdef.typ=objectdef) then
  3579. begin
  3580. hclassdef:=tobjectdef(current_structdef).childof;
  3581. { Objective-C categories *replace* methods in the class
  3582. they extend, or add methods to it. So calling an
  3583. inherited method always calls the method inherited from
  3584. the parent of the extended class }
  3585. if is_objccategory(current_structdef) then
  3586. hclassdef:=hclassdef.childof;
  3587. end
  3588. else if target_info.system in systems_jvm then
  3589. hclassdef:=java_fpcbaserecordtype
  3590. else
  3591. internalerror(2012012401);
  3592. spezcontext:=nil;
  3593. { if inherited; only then we need the method with
  3594. the same name }
  3595. if token <> _ID then
  3596. begin
  3597. hs:=current_procinfo.procdef.procsym.name;
  3598. hsorg:=current_procinfo.procdef.procsym.realname;
  3599. anon_inherited:=true;
  3600. { For message methods we need to search using the message
  3601. number or string }
  3602. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  3603. srdef:=nil;
  3604. if (po_msgint in pd.procoptions) then
  3605. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  3606. else
  3607. if (po_msgstr in pd.procoptions) then
  3608. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  3609. else
  3610. { helpers have their own ways of dealing with inherited }
  3611. if is_objectpascal_helper(current_structdef) then
  3612. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3613. else
  3614. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3615. end
  3616. else
  3617. begin
  3618. if not (m_delphi in current_settings.modeswitches) and
  3619. (block_type in inline_specialization_block_types) and
  3620. (token=_ID) and
  3621. (idtoken=_SPECIALIZE) then
  3622. begin
  3623. consume(_ID);
  3624. if token<>_ID then
  3625. message(parser_e_methode_id_expected);
  3626. isspecialize:=true;
  3627. end
  3628. else
  3629. isspecialize:=false;
  3630. hs:=pattern;
  3631. hsorg:=orgpattern;
  3632. consume(_ID);
  3633. anon_inherited:=false;
  3634. { helpers have their own ways of dealing with inherited }
  3635. if is_objectpascal_helper(current_structdef) then
  3636. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3637. else
  3638. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3639. if isspecialize and assigned(srsym) then
  3640. begin
  3641. if not handle_specialize_inline_specialization(srsym,srsymtable,spezcontext) then
  3642. srsym:=nil;
  3643. end;
  3644. end;
  3645. if assigned(srsym) then
  3646. begin
  3647. mightbegeneric:=(m_delphi in current_settings.modeswitches) and
  3648. (token in [_LT,_LSHARPBRACKET]) and
  3649. (sp_generic_dummy in srsym.symoptions);
  3650. { load the procdef from the inherited class and
  3651. not from self }
  3652. case srsym.typ of
  3653. typesym,
  3654. procsym:
  3655. begin
  3656. { typesym is only a valid choice if we're dealing
  3657. with a potential generic }
  3658. if (srsym.typ=typesym) and not mightbegeneric then
  3659. begin
  3660. Message(parser_e_methode_id_expected);
  3661. p1:=cerrornode.create;
  3662. end
  3663. else
  3664. begin
  3665. useself:=false;
  3666. if is_objectpascal_helper(current_structdef) then
  3667. begin
  3668. { for a helper load the procdef either from the
  3669. extended type, from the parent helper or from
  3670. the extended type of the parent helper
  3671. depending on the def the found symbol belongs
  3672. to }
  3673. if (srsym.Owner.defowner.typ=objectdef) and
  3674. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  3675. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  3676. assigned(tobjectdef(current_structdef).childof) then
  3677. hdef:=tobjectdef(current_structdef).childof
  3678. else
  3679. begin
  3680. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef;
  3681. useself:=true;
  3682. end
  3683. else
  3684. begin
  3685. hdef:=tdef(srsym.Owner.defowner);
  3686. useself:=true;
  3687. end;
  3688. end
  3689. else
  3690. hdef:=hclassdef;
  3691. if (po_classmethod in current_procinfo.procdef.procoptions) or
  3692. (po_staticmethod in current_procinfo.procdef.procoptions) then
  3693. hdef:=cclassrefdef.create(hdef);
  3694. if useself then
  3695. begin
  3696. p1:=ctypeconvnode.create_internal(load_self_node,hdef);
  3697. end
  3698. else
  3699. begin
  3700. p1:=ctypenode.create(hdef);
  3701. { we need to allow helpers here }
  3702. ttypenode(p1).helperallowed:=true;
  3703. end;
  3704. end;
  3705. end;
  3706. propertysym:
  3707. ;
  3708. else
  3709. begin
  3710. Message(parser_e_methode_id_expected);
  3711. p1:=cerrornode.create;
  3712. end;
  3713. end;
  3714. if mightbegeneric then
  3715. begin
  3716. p1:=cspecializenode.create_inherited(p1,getaddr,srsym,hclassdef);
  3717. end
  3718. else
  3719. begin
  3720. if not isspecialize then
  3721. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3722. callflags:=[cnf_inherited];
  3723. include(current_procinfo.flags,pi_has_inherited);
  3724. if anon_inherited then
  3725. include(callflags,cnf_anon_inherited);
  3726. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags,spezcontext);
  3727. end;
  3728. if p1.nodetype=errorn then
  3729. spezcontext.free;
  3730. end
  3731. else
  3732. begin
  3733. if anon_inherited then
  3734. begin
  3735. { For message methods we need to call DefaultHandler }
  3736. if (po_msgint in pd.procoptions) or
  3737. (po_msgstr in pd.procoptions) then
  3738. begin
  3739. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  3740. if not assigned(srsym) or
  3741. (srsym.typ<>procsym) then
  3742. internalerror(200303171);
  3743. p1:=nil;
  3744. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[],nil);
  3745. end
  3746. else
  3747. begin
  3748. { we need to ignore the inherited; }
  3749. p1:=cnothingnode.create;
  3750. end;
  3751. end
  3752. else
  3753. begin
  3754. Message1(sym_e_id_no_member,hsorg);
  3755. p1:=cerrornode.create;
  3756. end;
  3757. again:=false;
  3758. end;
  3759. { turn auto inheriting off }
  3760. anon_inherited:=false;
  3761. end
  3762. else
  3763. begin
  3764. { in case of records we use a more clear error message }
  3765. if assigned(current_structdef) and
  3766. (current_structdef.typ=recorddef) then
  3767. Message(parser_e_inherited_not_in_record)
  3768. else
  3769. Message(parser_e_generic_methods_only_in_methods);
  3770. again:=false;
  3771. p1:=cerrornode.create;
  3772. end;
  3773. if p1.nodetype<>specializen then
  3774. postfixoperators(p1,again,getaddr);
  3775. end;
  3776. _INTCONST :
  3777. begin
  3778. {Try first wether the value fits in an int64.}
  3779. val(pattern,ic,code);
  3780. if code=0 then
  3781. begin
  3782. consume(_INTCONST);
  3783. int_to_type(ic,hdef);
  3784. p1:=cordconstnode.create(ic,hdef,true);
  3785. end
  3786. else
  3787. begin
  3788. { try qword next }
  3789. val(pattern,qc,code);
  3790. if code=0 then
  3791. begin
  3792. consume(_INTCONST);
  3793. int_to_type(qc,hdef);
  3794. p1:=cordconstnode.create(qc,hdef,true);
  3795. end;
  3796. end;
  3797. if code<>0 then
  3798. begin
  3799. { finally float }
  3800. val(pattern,d,code);
  3801. if code<>0 then
  3802. begin
  3803. Message(parser_e_invalid_integer);
  3804. consume(_INTCONST);
  3805. l:=1;
  3806. p1:=cordconstnode.create(l,sinttype,true);
  3807. end
  3808. else
  3809. begin
  3810. consume(_INTCONST);
  3811. p1:=crealconstnode.create(d,pbestrealtype^);
  3812. end;
  3813. end
  3814. else
  3815. { the necessary range checking has already been done by val }
  3816. tordconstnode(p1).rangecheck:=false;
  3817. if token=_POINT then
  3818. begin
  3819. again:=true;
  3820. postfixoperators(p1,again,getaddr);
  3821. end;
  3822. end;
  3823. _REALNUMBER :
  3824. begin
  3825. p1:=real_const_node_from_pattern(pattern);
  3826. consume(_REALNUMBER);
  3827. if token=_POINT then
  3828. begin
  3829. again:=true;
  3830. postfixoperators(p1,again,getaddr);
  3831. end;
  3832. end;
  3833. _STRING :
  3834. begin
  3835. string_dec(hdef,true);
  3836. { STRING can be also a type cast }
  3837. if try_to_consume(_LKLAMMER) then
  3838. begin
  3839. p1:=comp_expr([ef_accept_equal]);
  3840. consume(_RKLAMMER);
  3841. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3842. { handle postfix operators here e.g. string(a)[10] }
  3843. again:=true;
  3844. postfixoperators(p1,again,getaddr);
  3845. end
  3846. else
  3847. begin
  3848. p1:=ctypenode.create(hdef);
  3849. if token=_POINT then
  3850. begin
  3851. again:=true;
  3852. { handle type helpers here }
  3853. postfixoperators(p1,again,getaddr);
  3854. end;
  3855. end;
  3856. end;
  3857. _FILE :
  3858. begin
  3859. hdef:=cfiletype;
  3860. consume(_FILE);
  3861. { FILE can be also a type cast }
  3862. if try_to_consume(_LKLAMMER) then
  3863. begin
  3864. p1:=comp_expr([ef_accept_equal]);
  3865. consume(_RKLAMMER);
  3866. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3867. { handle postfix operators here e.g. string(a)[10] }
  3868. again:=true;
  3869. postfixoperators(p1,again,getaddr);
  3870. end
  3871. else
  3872. begin
  3873. p1:=ctypenode.create(hdef);
  3874. end;
  3875. end;
  3876. _CSTRING :
  3877. begin
  3878. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3879. consume(_CSTRING);
  3880. if token in postfixoperator_tokens then
  3881. begin
  3882. again:=true;
  3883. postfixoperators(p1,again,getaddr);
  3884. end;
  3885. end;
  3886. _CCHAR :
  3887. begin
  3888. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3889. consume(_CCHAR);
  3890. if token=_POINT then
  3891. begin
  3892. again:=true;
  3893. postfixoperators(p1,again,getaddr);
  3894. end;
  3895. end;
  3896. _CWSTRING:
  3897. begin
  3898. if getlengthwidestring(patternw)=1 then
  3899. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true)
  3900. else
  3901. p1:=cstringconstnode.createunistr(patternw);
  3902. consume(_CWSTRING);
  3903. if token in postfixoperator_tokens then
  3904. begin
  3905. again:=true;
  3906. postfixoperators(p1,again,getaddr);
  3907. end;
  3908. end;
  3909. _CWCHAR:
  3910. begin
  3911. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3912. consume(_CWCHAR);
  3913. if token=_POINT then
  3914. begin
  3915. again:=true;
  3916. postfixoperators(p1,again,getaddr);
  3917. end;
  3918. end;
  3919. _KLAMMERAFFE :
  3920. begin
  3921. consume(_KLAMMERAFFE);
  3922. got_addrn:=true;
  3923. { support both @<x> and @(<x>) }
  3924. if try_to_consume(_LKLAMMER) then
  3925. begin
  3926. p1:=factor(true,[]);
  3927. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  3928. if token<>_RKLAMMER then
  3929. p1:=sub_expr(opcompare,[ef_accept_equal],p1);
  3930. consume(_RKLAMMER);
  3931. end
  3932. else
  3933. p1:=factor(true,[]);
  3934. if (token in postfixoperator_tokens) and
  3935. { TP7 uglyness: @proc^ is parsed as (@proc)^, but @notproc^
  3936. is parsed as @(notproc^) }
  3937. not
  3938. (
  3939. (m_tp_procvar in current_settings.modeswitches) and
  3940. (token=_CARET) and (p1.nodetype=loadn) and (tloadnode(p1).symtableentry.typ=procsym)
  3941. )
  3942. then
  3943. begin
  3944. again:=true;
  3945. postfixoperators(p1,again,getaddr);
  3946. end;
  3947. got_addrn:=false;
  3948. p1:=caddrnode.create(p1);
  3949. p1.fileinfo:=filepos;
  3950. if cs_typed_addresses in current_settings.localswitches then
  3951. include(taddrnode(p1).addrnodeflags,anf_typedaddr);
  3952. { Store the procvar that we are expecting, the
  3953. addrn will use the information to find the correct
  3954. procdef or it will return an error }
  3955. if assigned(getprocvardef) and
  3956. (taddrnode(p1).left.nodetype = loadn) then
  3957. taddrnode(p1).getprocvardef:=getprocvardef;
  3958. if (token in postfixoperator_tokens) then
  3959. begin
  3960. again:=true;
  3961. postfixoperators(p1,again,getaddr);
  3962. end;
  3963. end;
  3964. _LKLAMMER :
  3965. begin
  3966. consume(_LKLAMMER);
  3967. p1:=comp_expr([ef_accept_equal]);
  3968. consume(_RKLAMMER);
  3969. { it's not a good solution
  3970. but (a+b)^ makes some problems }
  3971. if token in postfixoperator_tokens then
  3972. begin
  3973. again:=true;
  3974. postfixoperators(p1,again,getaddr);
  3975. end;
  3976. end;
  3977. _LECKKLAMMER :
  3978. begin
  3979. consume(_LECKKLAMMER);
  3980. p1:=factor_read_set;
  3981. consume(_RECKKLAMMER);
  3982. end;
  3983. _PLUS :
  3984. begin
  3985. consume(_PLUS);
  3986. p1:=factor(false,[]);
  3987. p1:=cunaryplusnode.create(p1);
  3988. end;
  3989. _MINUS :
  3990. begin
  3991. consume(_MINUS);
  3992. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  3993. begin
  3994. { ugly hack, but necessary to be able to parse }
  3995. { -9223372036854775808 as int64 (JM) }
  3996. pattern := '-'+pattern;
  3997. p1:=sub_expr(oppower,[],nil);
  3998. { -1 ** 4 should be - (1 ** 4) and not
  3999. (-1) ** 4
  4000. This was the reason of tw0869.pp test failure PM }
  4001. if p1.nodetype=starstarn then
  4002. begin
  4003. if tbinarynode(p1).left.nodetype=ordconstn then
  4004. begin
  4005. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  4006. p1:=cunaryminusnode.create(p1);
  4007. end
  4008. else if tbinarynode(p1).left.nodetype=realconstn then
  4009. begin
  4010. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  4011. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  4012. p1:=cunaryminusnode.create(p1);
  4013. end
  4014. else
  4015. internalerror(20021029);
  4016. end;
  4017. end
  4018. else
  4019. begin
  4020. if m_isolike_unary_minus in current_settings.modeswitches then
  4021. p1:=sub_expr(opmultiply,[],nil)
  4022. else
  4023. p1:=sub_expr(oppower,[],nil);
  4024. p1:=cunaryminusnode.create(p1);
  4025. end;
  4026. end;
  4027. _OP_NOT :
  4028. begin
  4029. consume(_OP_NOT);
  4030. p1:=factor(false,[]);
  4031. p1:=cnotnode.create(p1);
  4032. end;
  4033. _NIL :
  4034. begin
  4035. consume(_NIL);
  4036. p1:=cnilnode.create;
  4037. { It's really ugly code nil^, but delphi allows it }
  4038. if token in [_CARET,_POINT] then
  4039. begin
  4040. again:=true;
  4041. postfixoperators(p1,again,getaddr);
  4042. end;
  4043. end;
  4044. _OBJCPROTOCOL:
  4045. begin
  4046. { The @protocol keyword is used in two ways in Objective-C:
  4047. 1) to declare protocols (~ Object Pascal interfaces)
  4048. 2) to obtain the metaclass (~ Object Pascal) "class of")
  4049. of a declared protocol
  4050. This code is for handling the second case. Because of 1),
  4051. we cannot simply use a system unit symbol.
  4052. }
  4053. consume(_OBJCPROTOCOL);
  4054. consume(_LKLAMMER);
  4055. p1:=factor(false,[]);
  4056. consume(_RKLAMMER);
  4057. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  4058. end;
  4059. _PROCEDURE,
  4060. _FUNCTION:
  4061. begin
  4062. if (block_type=bt_body) and
  4063. (m_anonymous_functions in current_settings.modeswitches) then
  4064. begin
  4065. oldprocvardef:=getprocvardef;
  4066. oldfuncrefdef:=getfuncrefdef;
  4067. getprocvardef:=nil;
  4068. getfuncrefdef:=nil;
  4069. pd:=read_proc([rpf_anonymous],nil);
  4070. getprocvardef:=oldprocvardef;
  4071. getfuncrefdef:=oldfuncrefdef;
  4072. { assume that we try to get the address except if certain
  4073. tokens follow that indicate a call }
  4074. do_proc_call(pd.procsym,pd.owner,nil,not (token in [_POINT,_CARET,_LECKKLAMMER]),
  4075. again,p1,[],nil);
  4076. end
  4077. else
  4078. begin
  4079. Message(parser_e_illegal_expression);
  4080. p1:=cerrornode.create;
  4081. { recover }
  4082. consume(token);
  4083. end;
  4084. end
  4085. else
  4086. begin
  4087. Message(parser_e_illegal_expression);
  4088. p1:=cerrornode.create;
  4089. { recover }
  4090. consume(token);
  4091. end;
  4092. end;
  4093. end;
  4094. { generate error node if no node is created }
  4095. if not assigned(p1) then
  4096. begin
  4097. {$ifdef EXTDEBUG}
  4098. Comment(V_Warning,'factor: p1=nil');
  4099. {$endif}
  4100. p1:=cerrornode.create;
  4101. updatefpos:=true;
  4102. end;
  4103. { get the resultdef for the node if nothing stops us }
  4104. if (not assigned(p1.resultdef)) and dopostfix then
  4105. begin
  4106. do_typecheckpass_changed(p1,nodechanged);
  4107. updatefpos:=updatefpos or nodechanged;
  4108. end;
  4109. if assigned(p1) and
  4110. updatefpos then
  4111. p1.fileinfo:=filepos;
  4112. factor:=p1;
  4113. end;
  4114. {$maxfpuregisters default}
  4115. procedure post_comp_expr_gendef(var def: tdef);
  4116. var
  4117. p1 : tnode;
  4118. again : boolean;
  4119. begin
  4120. if not assigned(def) then
  4121. internalerror(2011053001);
  4122. again:=false;
  4123. { handle potential typecasts, etc }
  4124. p1:=handle_factor_typenode(def,false,again,nil,false);
  4125. { parse postfix operators }
  4126. postfixoperators(p1,again,false);
  4127. if assigned(p1) and (p1.nodetype=typen) then
  4128. def:=ttypenode(p1).typedef
  4129. else
  4130. def:=generrordef;
  4131. end;
  4132. {****************************************************************************
  4133. Sub_Expr
  4134. ****************************************************************************}
  4135. function sub_expr(pred_level:Toperator_precedence;flags:texprflags;factornode:tnode):tnode;
  4136. {Reads a subexpression while the operators are of the current precedence
  4137. level, or any higher level. Replaces the old term, simpl_expr and
  4138. simpl2_expr.}
  4139. function istypenode(n:tnode):boolean;inline;
  4140. { Checks whether the given node is a type node or a VMT node containing a
  4141. typenode. This is used in the code for inline specializations in the
  4142. _LT branch below }
  4143. begin
  4144. result:=assigned(n) and
  4145. (
  4146. (n.nodetype=typen) or
  4147. (
  4148. (n.nodetype=loadvmtaddrn) and
  4149. (tloadvmtaddrnode(n).left.nodetype=typen)
  4150. )
  4151. );
  4152. end;
  4153. function gettypedef(n:tnode):tdef;inline;
  4154. { This returns the typedef that belongs to the given typenode or
  4155. loadvmtaddrnode. n must not be Nil! }
  4156. begin
  4157. if n.nodetype=typen then
  4158. result:=ttypenode(n).typedef
  4159. else
  4160. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  4161. end;
  4162. function gettypedef(sym:tsym):tdef;inline;
  4163. begin
  4164. result:=nil;
  4165. case sym.typ of
  4166. typesym:
  4167. result:=ttypesym(sym).typedef;
  4168. procsym:
  4169. if not (sp_generic_dummy in sym.symoptions) or (tprocsym(sym).procdeflist.count>0) then
  4170. result:=tdef(tprocsym(sym).procdeflist[0]);
  4171. else
  4172. internalerror(2015092701);
  4173. end;
  4174. end;
  4175. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  4176. var
  4177. srsymtable : tsymtable;
  4178. begin
  4179. srsym:=nil;
  4180. case n.nodetype of
  4181. typen:
  4182. srsym:=ttypenode(n).typedef.typesym;
  4183. loadvmtaddrn:
  4184. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  4185. loadn:
  4186. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  4187. srsym:=nil;
  4188. calln:
  4189. srsym:=tcallnode(n).symtableprocentry;
  4190. specializen:
  4191. srsym:=tspecializenode(n).sym;
  4192. { TODO : handle const nodes }
  4193. else
  4194. ;
  4195. end;
  4196. result:=assigned(srsym);
  4197. end;
  4198. function generate_inline_specialization(gendef:tdef;n:tnode;filepos:tfileposinfo;parseddef:tdef;gensym:tsym;p2:tnode):tnode;
  4199. var
  4200. again,
  4201. getaddr : boolean;
  4202. pload : tnode;
  4203. spezcontext : tspecializationcontext;
  4204. structdef,
  4205. inheriteddef : tabstractrecorddef;
  4206. callflags : tcallnodeflags;
  4207. begin
  4208. if n.nodetype=specializen then
  4209. begin
  4210. getaddr:=tspecializenode(n).getaddr;
  4211. pload:=tspecializenode(n).left;
  4212. inheriteddef:=tabstractrecorddef(tspecializenode(n).inheriteddef);
  4213. tspecializenode(n).left:=nil;
  4214. end
  4215. else
  4216. begin
  4217. getaddr:=false;
  4218. pload:=nil;
  4219. inheriteddef:=nil;
  4220. end;
  4221. if assigned(parseddef) and assigned(gensym) and assigned(p2) then
  4222. gendef:=generate_specialization_phase1(spezcontext,gendef,parseddef,gensym.realname,gensym.owner,p2.fileinfo)
  4223. else
  4224. gendef:=generate_specialization_phase1(spezcontext,gendef);
  4225. case gendef.typ of
  4226. errordef:
  4227. begin
  4228. spezcontext.free;
  4229. spezcontext:=nil;
  4230. gensym:=generrorsym;
  4231. end;
  4232. objectdef,
  4233. recorddef,
  4234. procvardef,
  4235. arraydef:
  4236. begin
  4237. gendef:=generate_specialization_phase2(spezcontext,tstoreddef(gendef),false,'');
  4238. spezcontext.free;
  4239. spezcontext:=nil;
  4240. if gendef.typ=errordef then
  4241. gensym:=generrorsym
  4242. else
  4243. gensym:=gendef.typesym;
  4244. end;
  4245. procdef:
  4246. begin
  4247. if block_type<>bt_body then
  4248. begin
  4249. message(parser_e_illegal_expression);
  4250. gensym:=generrorsym;
  4251. end
  4252. else
  4253. begin
  4254. gensym:=tprocdef(gendef).procsym;
  4255. end;
  4256. end;
  4257. else
  4258. internalerror(2015092702);
  4259. end;
  4260. { in case of a class or a record the specialized generic
  4261. is always a classrefdef }
  4262. again:=false;
  4263. if assigned(pload) then
  4264. begin
  4265. result:=pload;
  4266. typecheckpass(result);
  4267. structdef:=inheriteddef;
  4268. if not assigned(structdef) then
  4269. case result.resultdef.typ of
  4270. objectdef,
  4271. recorddef:
  4272. begin
  4273. structdef:=tabstractrecorddef(result.resultdef);
  4274. end;
  4275. classrefdef:
  4276. begin
  4277. structdef:=tabstractrecorddef(tclassrefdef(result.resultdef).pointeddef);
  4278. end;
  4279. else
  4280. internalerror(2015092703);
  4281. end;
  4282. if not (structdef.typ in [recorddef,objectdef]) then
  4283. internalerror(2018092101);
  4284. if assigned(inheriteddef) then
  4285. begin
  4286. callflags:=[cnf_inherited];
  4287. include(current_procinfo.flags,pi_has_inherited);
  4288. end
  4289. else
  4290. callflags:=[];
  4291. do_member_read(structdef,getaddr,gensym,result,again,callflags,spezcontext);
  4292. spezcontext:=nil;
  4293. end
  4294. else
  4295. begin
  4296. if gensym.typ=procsym then
  4297. begin
  4298. result:=nil;
  4299. { check if it's a method/class method }
  4300. if is_member_read(gensym,gensym.owner,result,parseddef) then
  4301. begin
  4302. { if we are accessing a owner procsym from the nested }
  4303. { class we need to call it as a class member }
  4304. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) and
  4305. assigned(current_structdef) and (current_structdef<>parseddef) and is_owned_by(current_structdef,parseddef) then
  4306. result:=cloadvmtaddrnode.create(ctypenode.create(parseddef));
  4307. { not srsymtable.symtabletype since that can be }
  4308. { withsymtable as well }
  4309. if (gensym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  4310. begin
  4311. do_member_read(tabstractrecorddef(parseddef),getaddr,gensym,result,again,[],spezcontext);
  4312. spezcontext:=nil;
  4313. end
  4314. else
  4315. { no procsyms in records (yet) }
  4316. internalerror(2015092704);
  4317. end
  4318. else
  4319. begin
  4320. { regular procedure/function call }
  4321. do_proc_call(gensym,gensym.owner,nil,
  4322. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  4323. again,result,[],spezcontext);
  4324. spezcontext:=nil;
  4325. end;
  4326. end
  4327. else
  4328. { handle potential typecasts, etc }
  4329. result:=handle_factor_typenode(gendef,false,again,nil,false);
  4330. end;
  4331. { parse postfix operators }
  4332. if postfixoperators(result,again,false) then
  4333. if assigned(result) then
  4334. result.fileinfo:=filepos
  4335. else
  4336. result:=cerrornode.create;
  4337. spezcontext.free;
  4338. end;
  4339. function maybe_handle_specialization(var p1,p2:tnode;filepos:tfileposinfo):boolean;
  4340. var
  4341. gensym : tsym;
  4342. parseddef,
  4343. gendef : tdef;
  4344. ptmp : tnode;
  4345. begin
  4346. result:=false;
  4347. { we need to decide whether we have an inline specialization
  4348. (type nodes to the left and right of "<", mode Delphi and
  4349. ">" or "," following) or a normal "<" comparison }
  4350. { TODO : p1 could be a non type if e.g. a variable with the
  4351. same name is defined in the same unit where the
  4352. generic is defined (though "same unit" is not
  4353. necessarily needed) }
  4354. if getgenericsym(p1,gensym) and
  4355. { Attention: when nested specializations are supported
  4356. p2 could be a loadn if a "<" follows }
  4357. istypenode(p2) and
  4358. (m_delphi in current_settings.modeswitches) and
  4359. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  4360. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  4361. begin
  4362. { this is an inline specialization }
  4363. { retrieve the defs of two nodes }
  4364. if p1.nodetype=specializen then
  4365. gendef:=gettypedef(tspecializenode(p1).sym)
  4366. else
  4367. gendef:=nil;
  4368. parseddef:=gettypedef(p2);
  4369. { check the hints for parseddef }
  4370. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg,p1.fileinfo);
  4371. ptmp:=generate_inline_specialization(gendef,p1,filepos,parseddef,gensym,p2);
  4372. { we don't need these nodes anymore }
  4373. p1.free;
  4374. p2.free;
  4375. p1:=ptmp;
  4376. result:=true;
  4377. end;
  4378. end;
  4379. label
  4380. SubExprStart;
  4381. var
  4382. p1,p2,ptmp : tnode;
  4383. oldt : Ttoken;
  4384. filepos : tfileposinfo;
  4385. gendef,parseddef : tdef;
  4386. gensym : tsym;
  4387. genlist : tfpobjectlist;
  4388. dummyagain : boolean;
  4389. dummyspezctxt : tspecializationcontext;
  4390. begin
  4391. SubExprStart:
  4392. if pred_level=highest_precedence then
  4393. begin
  4394. if factornode=nil then
  4395. p1:=factor(false,flags)
  4396. else
  4397. p1:=factornode;
  4398. end
  4399. else
  4400. p1:=sub_expr(succ(pred_level),flags+[ef_accept_equal],factornode);
  4401. repeat
  4402. if (token in [NOTOKEN..last_operator]) and
  4403. (token in operator_levels[pred_level]) and
  4404. ((token<>_EQ) or (ef_accept_equal in flags)) then
  4405. begin
  4406. oldt:=token;
  4407. filepos:=current_tokenpos;
  4408. consume(token);
  4409. if pred_level=highest_precedence then
  4410. p2:=factor(false,[])
  4411. else
  4412. p2:=sub_expr(succ(pred_level),flags+[ef_accept_equal],nil);
  4413. case oldt of
  4414. _PLUS :
  4415. p1:=caddnode.create(addn,p1,p2);
  4416. _MINUS :
  4417. p1:=caddnode.create(subn,p1,p2);
  4418. _STAR :
  4419. p1:=caddnode.create(muln,p1,p2);
  4420. _SLASH :
  4421. p1:=caddnode.create(slashn,p1,p2);
  4422. _EQ:
  4423. p1:=caddnode.create(equaln,p1,p2);
  4424. _GT :
  4425. p1:=caddnode.create(gtn,p1,p2);
  4426. _LT :
  4427. begin
  4428. if maybe_handle_specialization(p1,p2,filepos) then
  4429. begin
  4430. { with p1 now set we are in reality directly behind the
  4431. call to "factor" thus we need to call down to that
  4432. again }
  4433. { This is disabled until specializations on the right
  4434. hand side work as well, because
  4435. "not working expressions" is better than "half working
  4436. expressions" }
  4437. {factornode:=p1;
  4438. goto SubExprStart;}
  4439. end
  4440. else
  4441. begin
  4442. { this is a normal "<" comparison }
  4443. { potential generic types that are followed by a "<": }
  4444. if p1.nodetype=specializen then
  4445. begin
  4446. genlist:=tfpobjectlist(current_module.genericdummysyms.find(tspecializenode(p1).sym.name));
  4447. if assigned(genlist) and (genlist.count>0) then
  4448. begin
  4449. gensym:=tgenericdummyentry(genlist.last).resolvedsym;
  4450. check_hints(gensym,gensym.symoptions,gensym.deprecatedmsg,p1.fileinfo);
  4451. dummyagain:=false;
  4452. dummyspezctxt:=nil;
  4453. ptmp:=factor_handle_sym(gensym,
  4454. gensym.owner,
  4455. dummyagain,
  4456. tspecializenode(p1).getaddr,
  4457. false,
  4458. flags,
  4459. dummyspezctxt);
  4460. if dummyagain then
  4461. internalerror(2022012201);
  4462. p1.free;
  4463. p1:=ptmp;
  4464. end
  4465. else
  4466. begin
  4467. identifier_not_found(tspecializenode(p1).sym.realname);
  4468. p1.free;
  4469. p1:=cerrornode.create;
  4470. end;
  4471. end;
  4472. { a) might not have their resultdef set }
  4473. if not assigned(p1.resultdef) then
  4474. do_typecheckpass(p1);
  4475. { b) are not checked whether they are an undefined def,
  4476. but not a generic parameter }
  4477. if (p1.nodetype=typen) and
  4478. (ttypenode(p1).typedef.typ=undefineddef) and
  4479. assigned(ttypenode(p1).typedef.typesym) and
  4480. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  4481. begin
  4482. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  4483. p1.Free;
  4484. p1:=cerrornode.create;
  4485. end;
  4486. { c) don't have their hints checked }
  4487. if istypenode(p1) then
  4488. begin
  4489. gendef:=gettypedef(p1);
  4490. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4491. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4492. end;
  4493. { Note: the second part of the expression will be needed
  4494. for nested specializations }
  4495. if istypenode(p2) {and
  4496. not (token in [_LT, _LSHARPBRACKET])} then
  4497. begin
  4498. gendef:=gettypedef(p2);
  4499. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  4500. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  4501. end;
  4502. { create the comparison node for "<" }
  4503. p1:=caddnode.create(ltn,p1,p2)
  4504. end;
  4505. end;
  4506. _GTE :
  4507. p1:=caddnode.create(gten,p1,p2);
  4508. _LTE :
  4509. p1:=caddnode.create(lten,p1,p2);
  4510. _SYMDIF :
  4511. p1:=caddnode.create(symdifn,p1,p2);
  4512. _STARSTAR :
  4513. p1:=caddnode.create(starstarn,p1,p2);
  4514. _OP_AS,
  4515. _OP_IS :
  4516. begin
  4517. if (m_delphi in current_settings.modeswitches) and
  4518. (token in [_LT, _LSHARPBRACKET]) and
  4519. getgenericsym(p2,gensym) then
  4520. begin
  4521. { for now we're handling this as a generic declaration;
  4522. there could be cases though (because of operator
  4523. overloading) where this is the wrong decision... }
  4524. if gensym.typ=typesym then
  4525. gendef:=ttypesym(gensym).typedef
  4526. else
  4527. if gensym.typ=procsym then
  4528. gendef:=tdef(tprocsym(gensym).procdeflist[0])
  4529. else
  4530. internalerror(2015072401);
  4531. ptmp:=generate_inline_specialization(gendef,p2,filepos,nil,nil,nil);
  4532. { we don't need the old p2 anymore }
  4533. p2.Free;
  4534. p2:=ptmp;
  4535. { here we don't need to call back down to "factor", thus
  4536. no "goto" }
  4537. end;
  4538. { now generate the "is" or "as" node }
  4539. case oldt of
  4540. _OP_AS:
  4541. p1:=casnode.create(p1,p2);
  4542. _OP_IS:
  4543. p1:=cisnode.create(p1,p2);
  4544. else
  4545. internalerror(2019050528);
  4546. end;
  4547. end;
  4548. _OP_IN :
  4549. p1:=cinnode.create(p1,p2);
  4550. _OP_OR,
  4551. _PIPE {macpas only} :
  4552. begin
  4553. p1:=caddnode.create(orn,p1,p2);
  4554. if (oldt = _PIPE) then
  4555. include(p1.flags,nf_short_bool);
  4556. end;
  4557. _OP_AND,
  4558. _AMPERSAND {macpas only} :
  4559. begin
  4560. p1:=caddnode.create(andn,p1,p2);
  4561. if (oldt = _AMPERSAND) then
  4562. include(p1.flags,nf_short_bool);
  4563. end;
  4564. _OP_DIV :
  4565. p1:=cmoddivnode.create(divn,p1,p2);
  4566. _OP_NOT :
  4567. p1:=cnotnode.create(p1);
  4568. _OP_MOD :
  4569. begin
  4570. p1:=cmoddivnode.create(modn,p1,p2);
  4571. if m_isolike_mod in current_settings.modeswitches then
  4572. include(p1.flags,nf_isomod);
  4573. end;
  4574. _OP_SHL :
  4575. p1:=cshlshrnode.create(shln,p1,p2);
  4576. _OP_SHR :
  4577. p1:=cshlshrnode.create(shrn,p1,p2);
  4578. _OP_XOR :
  4579. p1:=caddnode.create(xorn,p1,p2);
  4580. _ASSIGNMENT :
  4581. p1:=cassignmentnode.create(p1,p2);
  4582. _NE :
  4583. p1:=caddnode.create(unequaln,p1,p2);
  4584. else
  4585. internalerror(2019050529);
  4586. end;
  4587. p1.fileinfo:=filepos;
  4588. end
  4589. else
  4590. break;
  4591. until false;
  4592. if (p1.nodetype=specializen) and
  4593. (token=_LSHARPBRACKET) and
  4594. (m_delphi in current_settings.modeswitches) then
  4595. begin
  4596. filepos:=current_tokenpos;
  4597. consume(token);
  4598. p2:=factor(false,[]);
  4599. if maybe_handle_specialization(p1,p2,filepos) then
  4600. begin
  4601. { with p1 now set we are in reality directly behind the
  4602. call to "factor" thus we need to call down to that
  4603. again }
  4604. { This is disabled until specializations on the right
  4605. hand side work as well, because
  4606. "not working expressions" is better than "half working
  4607. expressions" }
  4608. {factornode:=p1;
  4609. goto SubExprStart;}
  4610. end else
  4611. message(parser_e_illegal_expression);
  4612. end;
  4613. sub_expr:=p1;
  4614. end;
  4615. function comp_expr(flags:texprflags):tnode;
  4616. var
  4617. oldafterassignment : boolean;
  4618. p1 : tnode;
  4619. begin
  4620. oldafterassignment:=afterassignment;
  4621. afterassignment:=true;
  4622. p1:=sub_expr(opcompare,flags,nil);
  4623. { get the resultdef for this expression }
  4624. if not assigned(p1.resultdef) then
  4625. do_typecheckpass(p1);
  4626. afterassignment:=oldafterassignment;
  4627. comp_expr:=p1;
  4628. end;
  4629. function expr(dotypecheck : boolean) : tnode;
  4630. var
  4631. p1,p2 : tnode;
  4632. filepos : tfileposinfo;
  4633. oldafterassignment,
  4634. updatefpos : boolean;
  4635. oldflags : tnodeflags;
  4636. begin
  4637. oldafterassignment:=afterassignment;
  4638. p1:=sub_expr(opcompare,[ef_accept_equal],nil);
  4639. { get the resultdef for this expression }
  4640. if not assigned(p1.resultdef) and
  4641. dotypecheck then
  4642. do_typecheckpass(p1);
  4643. filepos:=current_tokenpos;
  4644. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  4645. afterassignment:=true;
  4646. updatefpos:=true;
  4647. case token of
  4648. _POINTPOINT :
  4649. begin
  4650. consume(_POINTPOINT);
  4651. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4652. p1:=crangenode.create(p1,p2);
  4653. end;
  4654. _ASSIGNMENT :
  4655. begin
  4656. consume(_ASSIGNMENT);
  4657. if assigned(p1.resultdef) then
  4658. if (p1.resultdef.typ=procvardef) then
  4659. getprocvardef:=tprocvardef(p1.resultdef)
  4660. else if is_invokable(p1.resultdef) then
  4661. getfuncrefdef:=tobjectdef(p1.resultdef);
  4662. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4663. if assigned(getprocvardef) then
  4664. handle_procvar(getprocvardef,p2)
  4665. else if assigned(getfuncrefdef) then
  4666. handle_funcref(getfuncrefdef,p2);
  4667. getprocvardef:=nil;
  4668. getfuncrefdef:=nil;
  4669. p1:=cassignmentnode.create(p1,p2);
  4670. end;
  4671. _PLUSASN :
  4672. begin
  4673. consume(_PLUSASN);
  4674. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4675. p1:=gen_c_style_operator(addn,p1,p2);
  4676. end;
  4677. _MINUSASN :
  4678. begin
  4679. consume(_MINUSASN);
  4680. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4681. p1:=gen_c_style_operator(subn,p1,p2);
  4682. end;
  4683. _STARASN :
  4684. begin
  4685. consume(_STARASN );
  4686. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4687. p1:=gen_c_style_operator(muln,p1,p2);
  4688. end;
  4689. _SLASHASN :
  4690. begin
  4691. consume(_SLASHASN );
  4692. p2:=sub_expr(opcompare,[ef_accept_equal],nil);
  4693. p1:=gen_c_style_operator(slashn,p1,p2);
  4694. end;
  4695. else
  4696. updatefpos:=false;
  4697. end;
  4698. oldflags:=p1.flags;
  4699. { get the resultdef for this expression }
  4700. if not assigned(p1.resultdef) and
  4701. dotypecheck then
  4702. do_typecheckpass(p1);
  4703. { transfer generic parameter flag }
  4704. if nf_generic_para in oldflags then
  4705. include(p1.flags,nf_generic_para);
  4706. afterassignment:=oldafterassignment;
  4707. if updatefpos then
  4708. p1.fileinfo:=filepos;
  4709. expr:=p1;
  4710. end;
  4711. function get_intconst:TConstExprInt;
  4712. {Reads an expression, tries to evalute it and check if it is an integer
  4713. constant. Then the constant is returned.}
  4714. var
  4715. p:tnode;
  4716. begin
  4717. result:=0;
  4718. p:=comp_expr([ef_accept_equal]);
  4719. if not codegenerror then
  4720. begin
  4721. if (p.nodetype<>ordconstn) or
  4722. not(is_integer(p.resultdef)) then
  4723. Message(parser_e_illegal_expression)
  4724. else
  4725. result:=tordconstnode(p).value;
  4726. end;
  4727. p.free;
  4728. end;
  4729. function get_stringconst:string;
  4730. {Reads an expression, tries to evaluate it and checks if it is a string
  4731. constant. Then the constant is returned.}
  4732. var
  4733. p:tnode;
  4734. begin
  4735. get_stringconst:='';
  4736. p:=comp_expr([ef_accept_equal]);
  4737. if p.nodetype<>stringconstn then
  4738. begin
  4739. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  4740. get_stringconst:=char(int64(tordconstnode(p).value))
  4741. else
  4742. Message(parser_e_illegal_expression);
  4743. end
  4744. else
  4745. get_stringconst:=strpas(tstringconstnode(p).value_str);
  4746. p.free;
  4747. end;
  4748. end.