pexpr.pas 161 KB

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