pexpr.pas 179 KB

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