pexpr.pas 178 KB

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