pexpr.pas 179 KB

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