pexpr.pas 180 KB

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