pexpr.pas 185 KB

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