pexpr.pas 177 KB

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