pexpr.pas 152 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842
  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. else
  826. internalerror(15);
  827. end;
  828. in_args:=prev_in_args;
  829. end;
  830. function maybe_load_methodpointer(st:TSymtable;var p1:tnode):boolean;
  831. var
  832. pd: tprocdef;
  833. begin
  834. maybe_load_methodpointer:=false;
  835. if not assigned(p1) then
  836. begin
  837. case st.symtabletype of
  838. withsymtable :
  839. begin
  840. if (st.defowner.typ=objectdef) then
  841. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  842. end;
  843. ObjectSymtable,
  844. recordsymtable:
  845. begin
  846. { Escape nested procedures }
  847. if assigned(current_procinfo) then
  848. begin
  849. pd:=current_procinfo.get_normal_proc.procdef;
  850. { We are calling from the static class method which has no self node }
  851. if assigned(pd) and pd.no_self_node then
  852. if st.symtabletype=recordsymtable then
  853. p1:=ctypenode.create(pd.struct)
  854. else
  855. p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  856. else
  857. p1:=load_self_node;
  858. end
  859. else
  860. p1:=load_self_node;
  861. { We are calling a member }
  862. maybe_load_methodpointer:=true;
  863. end;
  864. end;
  865. end;
  866. end;
  867. { reads the parameter for a subroutine call }
  868. procedure do_proc_call(sym:tsym;st:TSymtable;obj:tabstractrecorddef;getaddr:boolean;var again : boolean;var p1:tnode;callflags:tcallnodeflags);
  869. var
  870. membercall,
  871. prevafterassn : boolean;
  872. i : integer;
  873. para,p2 : tnode;
  874. currpara : tparavarsym;
  875. aprocdef : tprocdef;
  876. begin
  877. prevafterassn:=afterassignment;
  878. afterassignment:=false;
  879. membercall:=false;
  880. aprocdef:=nil;
  881. { when it is a call to a member we need to load the
  882. methodpointer first
  883. }
  884. membercall:=maybe_load_methodpointer(st,p1);
  885. { When we are expecting a procvar we also need
  886. to get the address in some cases }
  887. if assigned(getprocvardef) then
  888. begin
  889. if (block_type=bt_const) or
  890. getaddr then
  891. begin
  892. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  893. getaddr:=true;
  894. end
  895. else
  896. if ((m_tp_procvar in current_settings.modeswitches) or
  897. (m_mac_procvar in current_settings.modeswitches)) and
  898. not(token in [_CARET,_POINT,_LKLAMMER]) then
  899. begin
  900. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  901. if assigned(aprocdef) then
  902. getaddr:=true;
  903. end;
  904. end;
  905. { only need to get the address of the procedure? }
  906. if getaddr then
  907. begin
  908. { Retrieve info which procvar to call. For tp_procvar the
  909. aprocdef is already loaded above so we can reuse it }
  910. if not assigned(aprocdef) and
  911. assigned(getprocvardef) then
  912. aprocdef:=Tprocsym(sym).Find_procdef_byprocvardef(getprocvardef);
  913. { generate a methodcallnode or proccallnode }
  914. { we shouldn't convert things like @tcollection.load }
  915. p2:=cloadnode.create_procvar(sym,aprocdef,st);
  916. if assigned(p1) then
  917. begin
  918. { for loading methodpointer of an inherited function
  919. we use self as instance and load the address of
  920. the function directly and not through the vmt (PFV) }
  921. if (cnf_inherited in callflags) then
  922. begin
  923. include(tloadnode(p2).loadnodeflags,loadnf_inherited);
  924. p1.free;
  925. p1:=load_self_node;
  926. end;
  927. if (p1.nodetype<>typen) then
  928. tloadnode(p2).set_mp(p1)
  929. else
  930. p1.free;
  931. end;
  932. p1:=p2;
  933. { no postfix operators }
  934. again:=false;
  935. end
  936. else
  937. begin
  938. para:=nil;
  939. if anon_inherited then
  940. begin
  941. if not assigned(current_procinfo) then
  942. internalerror(200305054);
  943. for i:=0 to current_procinfo.procdef.paras.count-1 do
  944. begin
  945. currpara:=tparavarsym(current_procinfo.procdef.paras[i]);
  946. if not(vo_is_hidden_para in currpara.varoptions) then
  947. begin
  948. { inheritance by msgint? }
  949. if assigned(srdef) then
  950. { anonymous inherited via msgid calls only require a var parameter for
  951. both methods, so we need some type casting here }
  952. para:=ccallparanode.create(ctypeconvnode.create_internal(ctypeconvnode.create_internal(
  953. cloadnode.create(currpara,currpara.owner),cformaltype),tparavarsym(tprocdef(srdef).paras[i]).vardef),
  954. para)
  955. else
  956. para:=ccallparanode.create(cloadnode.create(currpara,currpara.owner),para);
  957. end;
  958. end;
  959. end
  960. else
  961. begin
  962. if try_to_consume(_LKLAMMER) then
  963. begin
  964. para:=parse_paras(false,false,_RKLAMMER);
  965. consume(_RKLAMMER);
  966. end;
  967. end;
  968. { indicate if this call was generated by a member and
  969. no explicit self is used, this is needed to determine
  970. how to handle a destructor call (PFV) }
  971. if membercall then
  972. include(callflags,cnf_member_call);
  973. if assigned(obj) then
  974. begin
  975. if not (st.symtabletype in [ObjectSymtable,recordsymtable]) then
  976. internalerror(200310031);
  977. p1:=ccallnode.create(para,tprocsym(sym),obj.symtable,p1,callflags);
  978. end
  979. else
  980. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags);
  981. end;
  982. afterassignment:=prevafterassn;
  983. end;
  984. procedure handle_procvar(pv : tprocvardef;var p2 : tnode);
  985. var
  986. hp,hp2 : tnode;
  987. hpp : ^tnode;
  988. currprocdef : tprocdef;
  989. begin
  990. if not assigned(pv) then
  991. internalerror(200301121);
  992. if (m_tp_procvar in current_settings.modeswitches) or
  993. (m_mac_procvar in current_settings.modeswitches) then
  994. begin
  995. hp:=p2;
  996. hpp:=@p2;
  997. while assigned(hp) and
  998. (hp.nodetype=typeconvn) do
  999. begin
  1000. hp:=ttypeconvnode(hp).left;
  1001. { save orignal address of the old tree so we can replace the node }
  1002. hpp:=@hp;
  1003. end;
  1004. if (hp.nodetype=calln) and
  1005. { a procvar can't have parameters! }
  1006. not assigned(tcallnode(hp).left) then
  1007. begin
  1008. currprocdef:=tcallnode(hp).symtableprocentry.Find_procdef_byprocvardef(pv);
  1009. if assigned(currprocdef) then
  1010. begin
  1011. hp2:=cloadnode.create_procvar(tprocsym(tcallnode(hp).symtableprocentry),currprocdef,tcallnode(hp).symtableproc);
  1012. if (po_methodpointer in pv.procoptions) then
  1013. tloadnode(hp2).set_mp(tcallnode(hp).methodpointer.getcopy);
  1014. hp.destroy;
  1015. { replace the old callnode with the new loadnode }
  1016. hpp^:=hp2;
  1017. end;
  1018. end;
  1019. end;
  1020. end;
  1021. { the following procedure handles the access to a property symbol }
  1022. procedure handle_propertysym(propsym : tpropertysym;st : TSymtable;var p1 : tnode);
  1023. var
  1024. paras : tnode;
  1025. p2 : tnode;
  1026. membercall : boolean;
  1027. callflags : tcallnodeflags;
  1028. propaccesslist : tpropaccesslist;
  1029. sym: tsym;
  1030. begin
  1031. { property parameters? read them only if the property really }
  1032. { has parameters }
  1033. paras:=nil;
  1034. if (ppo_hasparameters in propsym.propoptions) then
  1035. begin
  1036. if try_to_consume(_LECKKLAMMER) then
  1037. begin
  1038. paras:=parse_paras(false,false,_RECKKLAMMER);
  1039. consume(_RECKKLAMMER);
  1040. end;
  1041. end;
  1042. { indexed property }
  1043. if (ppo_indexed in propsym.propoptions) then
  1044. begin
  1045. p2:=cordconstnode.create(propsym.index,propsym.indexdef,true);
  1046. paras:=ccallparanode.create(p2,paras);
  1047. end;
  1048. { we need only a write property if a := follows }
  1049. { if not(afterassignment) and not(in_args) then }
  1050. if token=_ASSIGNMENT then
  1051. begin
  1052. if propsym.getpropaccesslist(palt_write,propaccesslist) then
  1053. begin
  1054. sym:=propaccesslist.firstsym^.sym;
  1055. case sym.typ of
  1056. procsym :
  1057. begin
  1058. callflags:=[];
  1059. { generate the method call }
  1060. membercall:=maybe_load_methodpointer(st,p1);
  1061. if membercall then
  1062. include(callflags,cnf_member_call);
  1063. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags);
  1064. addsymref(sym);
  1065. paras:=nil;
  1066. consume(_ASSIGNMENT);
  1067. { read the expression }
  1068. if propsym.propdef.typ=procvardef then
  1069. getprocvardef:=tprocvardef(propsym.propdef);
  1070. p2:=comp_expr(true,false);
  1071. if assigned(getprocvardef) then
  1072. handle_procvar(getprocvardef,p2);
  1073. tcallnode(p1).left:=ccallparanode.create(p2,tcallnode(p1).left);
  1074. { mark as property, both the tcallnode and the real call block }
  1075. include(p1.flags,nf_isproperty);
  1076. getprocvardef:=nil;
  1077. end;
  1078. fieldvarsym :
  1079. begin
  1080. { generate access code }
  1081. if not handle_staticfield_access(sym,false,p1) then
  1082. propaccesslist_to_node(p1,st,propaccesslist);
  1083. include(p1.flags,nf_isproperty);
  1084. consume(_ASSIGNMENT);
  1085. { read the expression }
  1086. p2:=comp_expr(true,false);
  1087. p1:=cassignmentnode.create(p1,p2);
  1088. end
  1089. else
  1090. begin
  1091. p1:=cerrornode.create;
  1092. Message(parser_e_no_procedure_to_access_property);
  1093. end;
  1094. end;
  1095. end
  1096. else
  1097. begin
  1098. p1:=cerrornode.create;
  1099. Message(parser_e_no_procedure_to_access_property);
  1100. end;
  1101. end
  1102. else
  1103. begin
  1104. if propsym.getpropaccesslist(palt_read,propaccesslist) then
  1105. begin
  1106. sym := propaccesslist.firstsym^.sym;
  1107. case sym.typ of
  1108. fieldvarsym :
  1109. begin
  1110. { generate access code }
  1111. if not handle_staticfield_access(sym,false,p1) then
  1112. propaccesslist_to_node(p1,st,propaccesslist);
  1113. include(p1.flags,nf_isproperty);
  1114. { catch expressions like "(propx):=1;" }
  1115. include(p1.flags,nf_no_lvalue);
  1116. end;
  1117. procsym :
  1118. begin
  1119. callflags:=[];
  1120. { generate the method call }
  1121. membercall:=maybe_load_methodpointer(st,p1);
  1122. if membercall then
  1123. include(callflags,cnf_member_call);
  1124. p1:=ccallnode.create(paras,tprocsym(sym),st,p1,callflags);
  1125. paras:=nil;
  1126. include(p1.flags,nf_isproperty);
  1127. include(p1.flags,nf_no_lvalue);
  1128. end
  1129. else
  1130. begin
  1131. p1:=cerrornode.create;
  1132. Message(type_e_mismatch);
  1133. end;
  1134. end;
  1135. end
  1136. else
  1137. begin
  1138. { error, no function to read property }
  1139. p1:=cerrornode.create;
  1140. Message(parser_e_no_procedure_to_access_property);
  1141. end;
  1142. end;
  1143. { release paras if not used }
  1144. if assigned(paras) then
  1145. paras.free;
  1146. end;
  1147. { the ID token has to be consumed before calling this function }
  1148. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags);
  1149. var
  1150. isclassref:boolean;
  1151. begin
  1152. if sym=nil then
  1153. begin
  1154. { pattern is still valid unless
  1155. there is another ID just after the ID of sym }
  1156. Message1(sym_e_id_no_member,orgpattern);
  1157. p1.free;
  1158. p1:=cerrornode.create;
  1159. { try to clean up }
  1160. again:=false;
  1161. end
  1162. else
  1163. begin
  1164. if assigned(p1) then
  1165. begin
  1166. if not assigned(p1.resultdef) then
  1167. do_typecheckpass(p1);
  1168. isclassref:=(p1.resultdef.typ=classrefdef);
  1169. end
  1170. else
  1171. isclassref:=false;
  1172. { we assume, that only procsyms and varsyms are in an object }
  1173. { symbol table, for classes, properties are allowed }
  1174. case sym.typ of
  1175. procsym:
  1176. begin
  1177. do_proc_call(sym,sym.owner,structh,
  1178. (getaddr and not(token in [_CARET,_POINT])),
  1179. again,p1,callflags);
  1180. { we need to know which procedure is called }
  1181. do_typecheckpass(p1);
  1182. { calling using classref? }
  1183. if isclassref and
  1184. (p1.nodetype=calln) and
  1185. assigned(tcallnode(p1).procdefinition) then
  1186. begin
  1187. if not(po_classmethod in tcallnode(p1).procdefinition.procoptions) and
  1188. not(tcallnode(p1).procdefinition.proctypeoption=potype_constructor) then
  1189. Message(parser_e_only_class_members_via_class_ref);
  1190. { in Java, constructors are not automatically inherited
  1191. -> calling a constructor from a parent type will create
  1192. an instance of that parent type! }
  1193. if is_javaclass(structh) and
  1194. (tcallnode(p1).procdefinition.proctypeoption=potype_constructor) and
  1195. (tcallnode(p1).procdefinition.owner.defowner<>find_real_class_definition(tobjectdef(structh),false)) then
  1196. Message(parser_e_java_no_inherited_constructor);
  1197. end;
  1198. end;
  1199. fieldvarsym:
  1200. begin
  1201. if not handle_staticfield_access(sym,true,p1) then
  1202. begin
  1203. if isclassref then
  1204. if assigned(p1) and
  1205. (
  1206. is_self_node(p1) or
  1207. (assigned(current_procinfo) and (current_procinfo.get_normal_proc.procdef.no_self_node) and
  1208. (current_procinfo.procdef.struct=structh))) then
  1209. Message(parser_e_only_class_members)
  1210. else
  1211. Message(parser_e_only_class_members_via_class_ref);
  1212. p1:=csubscriptnode.create(sym,p1);
  1213. end;
  1214. end;
  1215. propertysym:
  1216. begin
  1217. if isclassref and not (sp_static in sym.symoptions) then
  1218. Message(parser_e_only_class_members_via_class_ref);
  1219. handle_propertysym(tpropertysym(sym),sym.owner,p1);
  1220. end;
  1221. typesym:
  1222. begin
  1223. p1.free;
  1224. if try_to_consume(_LKLAMMER) then
  1225. begin
  1226. p1:=comp_expr(true,false);
  1227. consume(_RKLAMMER);
  1228. p1:=ctypeconvnode.create_explicit(p1,ttypesym(sym).typedef);
  1229. end
  1230. else
  1231. begin
  1232. p1:=ctypenode.create(ttypesym(sym).typedef);
  1233. if (is_class(ttypesym(sym).typedef) or
  1234. is_objcclass(ttypesym(sym).typedef) or
  1235. is_javaclass(ttypesym(sym).typedef)) and
  1236. not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1237. p1:=cloadvmtaddrnode.create(p1);
  1238. end;
  1239. end;
  1240. constsym:
  1241. begin
  1242. p1.free;
  1243. p1:=genconstsymtree(tconstsym(sym));
  1244. end;
  1245. staticvarsym:
  1246. begin
  1247. { typed constant is a staticvarsym
  1248. now they are absolutevarsym }
  1249. p1.free;
  1250. p1:=cloadnode.create(sym,sym.Owner);
  1251. end;
  1252. absolutevarsym:
  1253. begin
  1254. p1.free;
  1255. p1:=nil;
  1256. { typed constants are absolutebarsyms now to handle storage properly }
  1257. propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref);
  1258. end
  1259. else
  1260. internalerror(16);
  1261. end;
  1262. end;
  1263. end;
  1264. function handle_factor_typenode(hdef:tdef;getaddr:boolean;var again:boolean;sym:tsym;typeonly:boolean):tnode;
  1265. var
  1266. srsym : tsym;
  1267. srsymtable : tsymtable;
  1268. begin
  1269. if sym=nil then
  1270. sym:=hdef.typesym;
  1271. { allow Ordinal(Value) for type declarations since it
  1272. can be an enummeration declaration or a set lke:
  1273. (OrdinalType(const1)..OrdinalType(const2) }
  1274. if (not typeonly or is_ordinal(hdef)) and
  1275. try_to_consume(_LKLAMMER) then
  1276. begin
  1277. result:=comp_expr(true,false);
  1278. consume(_RKLAMMER);
  1279. { type casts to class helpers aren't allowed }
  1280. if is_objectpascal_helper(hdef) then
  1281. Message(parser_e_no_category_as_types)
  1282. { recovery by not creating a conversion node }
  1283. else
  1284. result:=ctypeconvnode.create_explicit(result,hdef);
  1285. end
  1286. { not LKLAMMER }
  1287. else if (token=_POINT) and
  1288. (is_object(hdef) or is_record(hdef)) then
  1289. begin
  1290. consume(_POINT);
  1291. { handles calling methods declared in parent objects
  1292. using "parentobject.methodname()" }
  1293. if assigned(current_structdef) and
  1294. not(getaddr) and
  1295. def_is_related(current_structdef,hdef) then
  1296. begin
  1297. result:=ctypenode.create(hdef);
  1298. ttypenode(result).typesym:=sym;
  1299. { search also in inherited methods }
  1300. searchsym_in_class(tobjectdef(hdef),tobjectdef(current_structdef),pattern,srsym,srsymtable,[ssf_search_helper]);
  1301. if assigned(srsym) then
  1302. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1303. consume(_ID);
  1304. do_member_read(tabstractrecorddef(hdef),false,srsym,result,again,[]);
  1305. end
  1306. else
  1307. begin
  1308. { handles:
  1309. * @TObject.Load
  1310. * static methods and variables }
  1311. result:=ctypenode.create(hdef);
  1312. ttypenode(result).typesym:=sym;
  1313. { TP allows also @TMenu.Load if Load is only }
  1314. { defined in an anchestor class }
  1315. srsym:=search_struct_member(tabstractrecorddef(hdef),pattern);
  1316. if assigned(srsym) then
  1317. begin
  1318. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1319. consume(_ID);
  1320. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[]);
  1321. end
  1322. else
  1323. Message1(sym_e_id_no_member,orgpattern);
  1324. end;
  1325. end
  1326. else
  1327. begin
  1328. { Normally here would be the check against the usage
  1329. of "TClassHelper.Something", but as that might be
  1330. used inside of system symbols like sizeof and
  1331. typeinfo this check is put into ttypenode.pass_1
  1332. (for "TClassHelper" alone) and tcallnode.pass_1
  1333. (for "TClassHelper.Something") }
  1334. { class reference ? }
  1335. if is_class(hdef) or
  1336. is_objcclass(hdef) or
  1337. { Java interfaces also can have loadvmtaddrnodes,
  1338. e.g. for expressions such as JLClass(intftype) }
  1339. is_java_class_or_interface(hdef) then
  1340. begin
  1341. if getaddr and (token=_POINT) and
  1342. not is_javainterface(hdef) then
  1343. begin
  1344. consume(_POINT);
  1345. { allows @Object.Method }
  1346. { also allows static methods and variables }
  1347. result:=ctypenode.create(hdef);
  1348. ttypenode(result).typesym:=sym;
  1349. { TP allows also @TMenu.Load if Load is only }
  1350. { defined in an anchestor class }
  1351. srsym:=search_struct_member(tobjectdef(hdef),pattern);
  1352. if assigned(srsym) then
  1353. begin
  1354. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1355. consume(_ID);
  1356. { in case of @Object.Method1.Method2, we have to call
  1357. Method1 -> create a loadvmtaddr node as self instead of
  1358. a typen (the typenode would be changed to self of the
  1359. current method in case Method1 is a constructor, see
  1360. mantis #24844) }
  1361. if not(block_type in [bt_type,bt_const_type,bt_var_type]) and
  1362. (srsym.typ=procsym) and
  1363. (token in [_CARET,_POINT]) then
  1364. result:=cloadvmtaddrnode.create(result);
  1365. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[]);
  1366. end
  1367. else
  1368. begin
  1369. Message1(sym_e_id_no_member,orgpattern);
  1370. consume(_ID);
  1371. end;
  1372. end
  1373. else
  1374. begin
  1375. result:=ctypenode.create(hdef);
  1376. ttypenode(result).typesym:=sym;
  1377. { For a type block we simply return only
  1378. the type. For all other blocks we return
  1379. a loadvmt node }
  1380. if not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1381. result:=cloadvmtaddrnode.create(result);
  1382. end;
  1383. end
  1384. else
  1385. begin
  1386. result:=ctypenode.create(hdef);
  1387. ttypenode(result).typesym:=sym;
  1388. end;
  1389. end;
  1390. end;
  1391. {****************************************************************************
  1392. Factor
  1393. ****************************************************************************}
  1394. function real_const_node_from_pattern(s:string):tnode;
  1395. var
  1396. d : bestreal;
  1397. code : integer;
  1398. cur : currency;
  1399. begin
  1400. val(s,d,code);
  1401. if code<>0 then
  1402. begin
  1403. Message(parser_e_error_in_real);
  1404. d:=1.0;
  1405. end;
  1406. {$ifdef FPC_REAL2REAL_FIXED}
  1407. if current_settings.fputype=fpu_none then
  1408. Message(parser_e_unsupported_real);
  1409. if (current_settings.minfpconstprec=s32real) and
  1410. (d = single(d)) then
  1411. result:=crealconstnode.create(d,s32floattype)
  1412. else if (current_settings.minfpconstprec=s64real) and
  1413. (d = double(d)) then
  1414. result:=crealconstnode.create(d,s64floattype)
  1415. else
  1416. {$endif FPC_REAL2REAL_FIXED}
  1417. result:=crealconstnode.create(d,pbestrealtype^);
  1418. {$ifdef FPC_HAS_STR_CURRENCY}
  1419. val(pattern,cur,code);
  1420. if code=0 then
  1421. trealconstnode(result).value_currency:=cur;
  1422. {$endif FPC_HAS_STR_CURRENCY}
  1423. end;
  1424. {---------------------------------------------
  1425. PostFixOperators
  1426. ---------------------------------------------}
  1427. { returns whether or not p1 has been changed }
  1428. function postfixoperators(var p1:tnode;var again:boolean;getaddr:boolean): boolean;
  1429. { tries to avoid syntax errors after invalid qualifiers }
  1430. procedure recoverconsume_postfixops;
  1431. begin
  1432. repeat
  1433. if not try_to_consume(_CARET) then
  1434. if try_to_consume(_POINT) then
  1435. try_to_consume(_ID)
  1436. else if try_to_consume(_LECKKLAMMER) then
  1437. begin
  1438. repeat
  1439. comp_expr(true,false);
  1440. until not try_to_consume(_COMMA);
  1441. consume(_RECKKLAMMER);
  1442. end
  1443. else if try_to_consume(_LKLAMMER) then
  1444. begin
  1445. repeat
  1446. comp_expr(true,false);
  1447. until not try_to_consume(_COMMA);
  1448. consume(_RKLAMMER);
  1449. end
  1450. else
  1451. break;
  1452. until false;
  1453. end;
  1454. procedure handle_variantarray;
  1455. var
  1456. p4 : tnode;
  1457. newstatement : tstatementnode;
  1458. tempresultvariant,
  1459. temp : ttempcreatenode;
  1460. paras : tcallparanode;
  1461. newblock : tnode;
  1462. countindices : aint;
  1463. begin
  1464. { create statements with call initialize the arguments and
  1465. call fpc_dynarr_setlength }
  1466. newblock:=internalstatements(newstatement);
  1467. { get temp for array of indicies,
  1468. we set the real size later }
  1469. temp:=ctempcreatenode.create(s32inttype,4,tt_persistent,false);
  1470. addstatement(newstatement,temp);
  1471. countindices:=0;
  1472. repeat
  1473. p4:=comp_expr(true,false);
  1474. addstatement(newstatement,cassignmentnode.create(
  1475. ctemprefnode.create_offset(temp,countindices*s32inttype.size),p4));
  1476. inc(countindices);
  1477. until not try_to_consume(_COMMA);
  1478. { set real size }
  1479. temp.size:=countindices*s32inttype.size;
  1480. consume(_RECKKLAMMER);
  1481. { we need only a write access if a := follows }
  1482. if token=_ASSIGNMENT then
  1483. begin
  1484. consume(_ASSIGNMENT);
  1485. p4:=comp_expr(true,false);
  1486. { create call to fpc_vararray_put }
  1487. paras:=ccallparanode.create(cordconstnode.create
  1488. (countindices,s32inttype,true),
  1489. ccallparanode.create(caddrnode.create_internal
  1490. (ctemprefnode.create(temp)),
  1491. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1492. ccallparanode.create(ctypeconvnode.create_internal(p1,cvarianttype)
  1493. ,nil))));
  1494. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1495. addstatement(newstatement,ctempdeletenode.create(temp));
  1496. end
  1497. else
  1498. begin
  1499. { create temp for result }
  1500. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.size,tt_persistent,true);
  1501. addstatement(newstatement,tempresultvariant);
  1502. { create call to fpc_vararray_get }
  1503. paras:=ccallparanode.create(cordconstnode.create
  1504. (countindices,s32inttype,true),
  1505. ccallparanode.create(caddrnode.create_internal
  1506. (ctemprefnode.create(temp)),
  1507. ccallparanode.create(p1,
  1508. ccallparanode.create(
  1509. ctemprefnode.create(tempresultvariant)
  1510. ,nil))));
  1511. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1512. addstatement(newstatement,ctempdeletenode.create(temp));
  1513. { the last statement should return the value as
  1514. location and type, this is done be referencing the
  1515. temp and converting it first from a persistent temp to
  1516. normal temp }
  1517. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1518. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1519. end;
  1520. p1:=newblock;
  1521. end;
  1522. function parse_array_constructor(arrdef:tarraydef): tnode;
  1523. var
  1524. newstatement,assstatement:tstatementnode;
  1525. arrnode:ttempcreatenode;
  1526. temp2:ttempcreatenode;
  1527. assnode:tnode;
  1528. paracount:integer;
  1529. begin
  1530. result:=internalstatements(newstatement);
  1531. { create temp for result }
  1532. arrnode:=ctempcreatenode.create(arrdef,arrdef.size,tt_persistent,true);
  1533. addstatement(newstatement,arrnode);
  1534. paracount:=0;
  1535. { check arguments and create an assignment calls }
  1536. if try_to_consume(_LKLAMMER) then
  1537. begin
  1538. assnode:=internalstatements(assstatement);
  1539. repeat
  1540. { arr[i] := param_i }
  1541. addstatement(assstatement,
  1542. cassignmentnode.create(
  1543. cvecnode.create(
  1544. ctemprefnode.create(arrnode),
  1545. cordconstnode.create(paracount,arrdef.rangedef,false)),
  1546. comp_expr(true,false)));
  1547. inc(paracount);
  1548. until not try_to_consume(_COMMA);
  1549. consume(_RKLAMMER);
  1550. end
  1551. else
  1552. assnode:=nil;
  1553. { get temp for array of lengths }
  1554. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1555. addstatement(newstatement,temp2);
  1556. { one dimensional }
  1557. addstatement(newstatement,cassignmentnode.create(
  1558. ctemprefnode.create_offset(temp2,0),
  1559. cordconstnode.create
  1560. (paracount,s32inttype,true)));
  1561. { create call to fpc_dynarr_setlength }
  1562. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1563. ccallparanode.create(caddrnode.create_internal
  1564. (ctemprefnode.create(temp2)),
  1565. ccallparanode.create(cordconstnode.create
  1566. (1,s32inttype,true),
  1567. ccallparanode.create(caddrnode.create_internal
  1568. (crttinode.create(tstoreddef(arrdef),initrtti,rdt_normal)),
  1569. ccallparanode.create(
  1570. ctypeconvnode.create_internal(
  1571. ctemprefnode.create(arrnode),voidpointertype),
  1572. nil))))
  1573. ));
  1574. { add assignment statememnts }
  1575. addstatement(newstatement,ctempdeletenode.create(temp2));
  1576. if assigned(assnode) then
  1577. addstatement(newstatement,assnode);
  1578. { the last statement should return the value as
  1579. location and type, this is done be referencing the
  1580. temp and converting it first from a persistent temp to
  1581. normal temp }
  1582. addstatement(newstatement,ctempdeletenode.create_normal_temp(arrnode));
  1583. addstatement(newstatement,ctemprefnode.create(arrnode));
  1584. end;
  1585. function try_type_helper(var node:tnode;def:tdef):boolean;
  1586. var
  1587. srsym : tsym;
  1588. srsymtable : tsymtable;
  1589. n : tnode;
  1590. newstatement : tstatementnode;
  1591. temp : ttempcreatenode;
  1592. extdef : tdef;
  1593. begin
  1594. result:=false;
  1595. if (token=_ID) and (block_type in [bt_body,bt_general,bt_except]) then
  1596. begin
  1597. if not assigned(def) then
  1598. if node.nodetype=addrn then
  1599. { always use the pointer type for addr nodes as otherwise
  1600. we'll have an anonymous pointertype with no name }
  1601. def:=voidpointertype
  1602. else
  1603. def:=node.resultdef;
  1604. result:=search_objectpascal_helper(def,nil,pattern,srsym,srsymtable);
  1605. if result then
  1606. begin
  1607. if not (srsymtable.symtabletype=objectsymtable) or
  1608. not is_objectpascal_helper(tdef(srsymtable.defowner)) then
  1609. internalerror(2013011401);
  1610. { convert const node to temp node of the extended type }
  1611. if node.nodetype in (nodetype_const+[niln,addrn]) then
  1612. begin
  1613. extdef:=tobjectdef(srsymtable.defowner).extendeddef;
  1614. newstatement:=nil;
  1615. n:=internalstatements(newstatement);
  1616. temp:=ctempcreatenode.create(extdef,extdef.size,tt_persistent,false);
  1617. addstatement(newstatement,temp);
  1618. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),node));
  1619. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1620. addstatement(newstatement,ctemprefnode.create(temp));
  1621. node:=n;
  1622. do_typecheckpass(node)
  1623. end;
  1624. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1625. consume(_ID);
  1626. do_member_read(nil,getaddr,srsym,node,again,[]);
  1627. end;
  1628. end;
  1629. end;
  1630. var
  1631. protsym : tpropertysym;
  1632. p2,p3 : tnode;
  1633. srsym : tsym;
  1634. srsymtable : TSymtable;
  1635. structh : tabstractrecorddef;
  1636. { shouldn't be used that often, so the extra overhead is ok to save
  1637. stack space }
  1638. dispatchstring : ansistring;
  1639. found,
  1640. haderror,
  1641. nodechanged : boolean;
  1642. calltype: tdispcalltype;
  1643. valstr,expstr : string;
  1644. intval : qword;
  1645. code : integer;
  1646. strdef : tdef;
  1647. label
  1648. skipreckklammercheck,
  1649. skippointdefcheck;
  1650. begin
  1651. result:=false;
  1652. again:=true;
  1653. while again do
  1654. begin
  1655. { we need the resultdef }
  1656. do_typecheckpass_changed(p1,nodechanged);
  1657. result:=result or nodechanged;
  1658. if codegenerror then
  1659. begin
  1660. recoverconsume_postfixops;
  1661. exit;
  1662. end;
  1663. { handle token }
  1664. case token of
  1665. _CARET:
  1666. begin
  1667. consume(_CARET);
  1668. { support tp/mac procvar^ if the procvar returns a
  1669. pointer type }
  1670. if ((m_tp_procvar in current_settings.modeswitches) or
  1671. (m_mac_procvar in current_settings.modeswitches)) and
  1672. (p1.resultdef.typ=procvardef) and
  1673. (tprocvardef(p1.resultdef).returndef.typ=pointerdef) then
  1674. begin
  1675. p1:=ccallnode.create_procvar(nil,p1);
  1676. typecheckpass(p1);
  1677. end;
  1678. { iso file buf access? }
  1679. if (m_iso in current_settings.modeswitches) and
  1680. (p1.resultdef.typ=filedef) then
  1681. begin
  1682. case tfiledef(p1.resultdef).filetyp of
  1683. ft_text:
  1684. begin
  1685. p1:=cderefnode.create(ccallnode.createintern('fpc_getbuf_text',ccallparanode.create(p1,nil)));
  1686. typecheckpass(p1);
  1687. end;
  1688. ft_typed:
  1689. begin
  1690. p1:=cderefnode.create(ctypeconvnode.create_internal(ccallnode.createintern('fpc_getbuf_typedfile',ccallparanode.create(p1,nil)),
  1691. getpointerdef(tfiledef(p1.resultdef).typedfiledef)));
  1692. typecheckpass(p1);
  1693. end;
  1694. end;
  1695. end
  1696. else if (p1.resultdef.typ<>pointerdef) then
  1697. begin
  1698. { ^ as binary operator is a problem!!!! (FK) }
  1699. again:=false;
  1700. Message(parser_e_invalid_qualifier);
  1701. recoverconsume_postfixops;
  1702. p1.destroy;
  1703. p1:=cerrornode.create;
  1704. end
  1705. else
  1706. p1:=cderefnode.create(p1);
  1707. end;
  1708. _LECKKLAMMER:
  1709. begin
  1710. if is_class_or_interface_or_object(p1.resultdef) or
  1711. is_dispinterface(p1.resultdef) or
  1712. is_record(p1.resultdef) or
  1713. is_javaclass(p1.resultdef) then
  1714. begin
  1715. { default property }
  1716. protsym:=search_default_property(tabstractrecorddef(p1.resultdef));
  1717. if not(assigned(protsym)) then
  1718. begin
  1719. p1.destroy;
  1720. p1:=cerrornode.create;
  1721. again:=false;
  1722. message(parser_e_no_default_property_available);
  1723. end
  1724. else
  1725. begin
  1726. { The property symbol is referenced indirect }
  1727. protsym.IncRefCount;
  1728. handle_propertysym(protsym,protsym.owner,p1);
  1729. end;
  1730. end
  1731. else
  1732. begin
  1733. consume(_LECKKLAMMER);
  1734. repeat
  1735. { in all of the cases below, p1 is changed }
  1736. case p1.resultdef.typ of
  1737. pointerdef:
  1738. begin
  1739. { support delphi autoderef }
  1740. if (tpointerdef(p1.resultdef).pointeddef.typ=arraydef) and
  1741. (m_autoderef in current_settings.modeswitches) then
  1742. p1:=cderefnode.create(p1);
  1743. p2:=comp_expr(true,false);
  1744. { Support Pbytevar[0..9] which returns array [0..9].}
  1745. if try_to_consume(_POINTPOINT) then
  1746. p2:=crangenode.create(p2,comp_expr(true,false));
  1747. p1:=cvecnode.create(p1,p2);
  1748. end;
  1749. variantdef:
  1750. begin
  1751. handle_variantarray;
  1752. { the RECKKLAMMER is already read }
  1753. goto skipreckklammercheck;
  1754. end;
  1755. stringdef :
  1756. begin
  1757. p2:=comp_expr(true,false);
  1758. { Support string[0..9] which returns array [0..9] of char.}
  1759. if try_to_consume(_POINTPOINT) then
  1760. p2:=crangenode.create(p2,comp_expr(true,false));
  1761. p1:=cvecnode.create(p1,p2);
  1762. end;
  1763. arraydef:
  1764. begin
  1765. p2:=comp_expr(true,false);
  1766. { support SEG:OFS for go32v2/msdos Mem[] }
  1767. if (target_info.system in [system_i386_go32v2,system_i386_watcom,system_i8086_msdos]) and
  1768. (p1.nodetype=loadn) and
  1769. assigned(tloadnode(p1).symtableentry) and
  1770. assigned(tloadnode(p1).symtableentry.owner.name) and
  1771. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1772. ((tloadnode(p1).symtableentry.name='MEM') or
  1773. (tloadnode(p1).symtableentry.name='MEMW') or
  1774. (tloadnode(p1).symtableentry.name='MEML')) then
  1775. begin
  1776. {$if defined(i8086)}
  1777. consume(_COLON);
  1778. inserttypeconv(p2,u16inttype);
  1779. inserttypeconv_internal(p2,u32inttype);
  1780. p3:=cshlshrnode.create(shln,p2,cordconstnode.create($10,s16inttype,false));
  1781. p2:=comp_expr(true,false);
  1782. inserttypeconv(p2,u16inttype);
  1783. inserttypeconv_internal(p2,u32inttype);
  1784. p2:=caddnode.create(addn,p2,p3);
  1785. case tloadnode(p1).symtableentry.name of
  1786. 'MEM': p2:=ctypeconvnode.create_internal(p2,bytefarpointertype);
  1787. 'MEMW': p2:=ctypeconvnode.create_internal(p2,wordfarpointertype);
  1788. 'MEML': p2:=ctypeconvnode.create_internal(p2,longintfarpointertype);
  1789. else
  1790. internalerror(2013053102);
  1791. end;
  1792. p1:=cderefnode.create(p2);
  1793. {$elseif defined(i386)}
  1794. if try_to_consume(_COLON) then
  1795. begin
  1796. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1797. p2:=comp_expr(true,false);
  1798. p2:=caddnode.create(addn,p2,p3);
  1799. if try_to_consume(_POINTPOINT) then
  1800. { Support mem[$a000:$0000..$07ff] which returns array [0..$7ff] of memtype.}
  1801. p2:=crangenode.create(p2,caddnode.create(addn,comp_expr(true,false),p3.getcopy));
  1802. p1:=cvecnode.create(p1,p2);
  1803. include(tvecnode(p1).flags,nf_memseg);
  1804. include(tvecnode(p1).flags,nf_memindex);
  1805. end
  1806. else
  1807. begin
  1808. if try_to_consume(_POINTPOINT) then
  1809. { Support mem[$80000000..$80000002] which returns array [0..2] of memtype.}
  1810. p2:=crangenode.create(p2,comp_expr(true,false));
  1811. p1:=cvecnode.create(p1,p2);
  1812. include(tvecnode(p1).flags,nf_memindex);
  1813. end;
  1814. {$else}
  1815. internalerror(2013053101);
  1816. {$endif}
  1817. end
  1818. else
  1819. begin
  1820. if try_to_consume(_POINTPOINT) then
  1821. { Support arrayvar[0..9] which returns array [0..9] of arraytype.}
  1822. p2:=crangenode.create(p2,comp_expr(true,false));
  1823. p1:=cvecnode.create(p1,p2);
  1824. end;
  1825. end;
  1826. else
  1827. begin
  1828. if p1.resultdef.typ<>undefineddef then
  1829. Message(parser_e_invalid_qualifier);
  1830. p1.destroy;
  1831. p1:=cerrornode.create;
  1832. comp_expr(true,false);
  1833. again:=false;
  1834. end;
  1835. end;
  1836. do_typecheckpass(p1);
  1837. until not try_to_consume(_COMMA);
  1838. consume(_RECKKLAMMER);
  1839. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1840. skipreckklammercheck:
  1841. end;
  1842. end;
  1843. _POINT :
  1844. begin
  1845. consume(_POINT);
  1846. if (p1.resultdef.typ=pointerdef) and
  1847. (m_autoderef in current_settings.modeswitches) and
  1848. { don't auto-deref objc.id, because then the code
  1849. below for supporting id.anyobjcmethod isn't triggered }
  1850. (p1.resultdef<>objc_idtype) then
  1851. begin
  1852. p1:=cderefnode.create(p1);
  1853. do_typecheckpass(p1);
  1854. end;
  1855. { procvar.<something> can never mean anything so always
  1856. try to call it in case it returns a record/object/... }
  1857. maybe_call_procvar(p1,false);
  1858. if (p1.nodetype=ordconstn) and
  1859. not is_boolean(p1.resultdef) and
  1860. not is_enum(p1.resultdef) then
  1861. begin
  1862. { type helpers are checked first }
  1863. if (token=_ID) and try_type_helper(p1,nil) then
  1864. goto skippointdefcheck;
  1865. { only an "e" or "E" can follow an intconst with a ".", the
  1866. other case (another intconst) is handled by the scanner }
  1867. if (token=_ID) and (pattern[1]='E') then
  1868. begin
  1869. haderror:=false;
  1870. if length(pattern)>1 then
  1871. begin
  1872. expstr:=copy(pattern,2,length(pattern)-1);
  1873. val(expstr,intval,code);
  1874. if code<>0 then
  1875. haderror:=true;
  1876. end
  1877. else
  1878. expstr:='';
  1879. consume(token);
  1880. if tordconstnode(p1).value.signed then
  1881. str(tordconstnode(p1).value.svalue,valstr)
  1882. else
  1883. str(tordconstnode(p1).value.uvalue,valstr);
  1884. valstr:=valstr+'.0E';
  1885. if expstr='' then
  1886. case token of
  1887. _MINUS:
  1888. begin
  1889. consume(token);
  1890. if token=_INTCONST then
  1891. begin
  1892. valstr:=valstr+'-'+pattern;
  1893. consume(token);
  1894. end
  1895. else
  1896. haderror:=true;
  1897. end;
  1898. _PLUS:
  1899. begin
  1900. consume(token);
  1901. if token=_INTCONST then
  1902. begin
  1903. valstr:=valstr+pattern;
  1904. consume(token);
  1905. end
  1906. else
  1907. haderror:=true;
  1908. end;
  1909. _INTCONST:
  1910. begin
  1911. valstr:=valstr+pattern;
  1912. consume(_INTCONST);
  1913. end;
  1914. else
  1915. haderror:=true;
  1916. end
  1917. else
  1918. valstr:=valstr+expstr;
  1919. if haderror then
  1920. begin
  1921. Message(parser_e_error_in_real);
  1922. p2:=cerrornode.create;
  1923. end
  1924. else
  1925. p2:=real_const_node_from_pattern(valstr);
  1926. p1.free;
  1927. p1:=p2;
  1928. again:=false;
  1929. goto skippointdefcheck;
  1930. end
  1931. else
  1932. begin
  1933. { just convert the ordconst to a realconst }
  1934. p2:=crealconstnode.create(tordconstnode(p1).value,pbestrealtype^);
  1935. p1.free;
  1936. p1:=p2;
  1937. again:=false;
  1938. goto skippointdefcheck;
  1939. end;
  1940. end;
  1941. if (p1.nodetype=stringconstn) and (token=_ID) then
  1942. begin
  1943. { the def of a string const is an array }
  1944. case tstringconstnode(p1).cst_type of
  1945. cst_conststring:
  1946. if cs_refcountedstrings in current_settings.localswitches then
  1947. if m_default_unicodestring in current_settings.modeswitches then
  1948. strdef:=cunicodestringtype
  1949. else
  1950. strdef:=cansistringtype
  1951. else
  1952. strdef:=cshortstringtype;
  1953. cst_shortstring:
  1954. strdef:=cshortstringtype;
  1955. cst_ansistring:
  1956. { use getansistringdef? }
  1957. strdef:=cansistringtype;
  1958. cst_widestring:
  1959. strdef:=cwidestringtype;
  1960. cst_unicodestring:
  1961. strdef:=cunicodestringtype;
  1962. cst_longstring:
  1963. { let's see when someone stumbles upon this...}
  1964. internalerror(201301111);
  1965. else
  1966. internalerror(2013112903);
  1967. end;
  1968. if try_type_helper(p1,strdef) then
  1969. goto skippointdefcheck;
  1970. end;
  1971. { this is skipped if label skippointdefcheck is used }
  1972. case p1.resultdef.typ of
  1973. recorddef:
  1974. begin
  1975. if token=_ID then
  1976. begin
  1977. structh:=tabstractrecorddef(p1.resultdef);
  1978. searchsym_in_record(structh,pattern,srsym,srsymtable);
  1979. if assigned(srsym) then
  1980. begin
  1981. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1982. consume(_ID);
  1983. do_member_read(structh,getaddr,srsym,p1,again,[]);
  1984. end
  1985. else
  1986. begin
  1987. Message1(sym_e_id_no_member,orgpattern);
  1988. p1.destroy;
  1989. p1:=cerrornode.create;
  1990. { try to clean up }
  1991. consume(_ID);
  1992. end;
  1993. end
  1994. else
  1995. consume(_ID);
  1996. end;
  1997. enumdef:
  1998. begin
  1999. if token=_ID then
  2000. begin
  2001. srsym:=tsym(tenumdef(p1.resultdef).symtable.Find(pattern));
  2002. if assigned(srsym) and (srsym.typ=enumsym) and (p1.nodetype=typen) then
  2003. begin
  2004. p1.destroy;
  2005. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2006. p1:=genenumnode(tenumsym(srsym));
  2007. consume(_ID);
  2008. end
  2009. else
  2010. if not try_type_helper(p1,nil) then
  2011. begin
  2012. p1.destroy;
  2013. Message1(sym_e_id_no_member,orgpattern);
  2014. p1:=cerrornode.create;
  2015. consume(_ID);
  2016. end;
  2017. end;
  2018. end;
  2019. arraydef:
  2020. begin
  2021. if is_dynamic_array(p1.resultdef) then
  2022. begin
  2023. if (token=_ID) and not try_type_helper(p1,nil) then
  2024. begin
  2025. if pattern='CREATE' then
  2026. begin
  2027. consume(_ID);
  2028. p2:=parse_array_constructor(tarraydef(p1.resultdef));
  2029. p1.destroy;
  2030. p1:=p2;
  2031. end
  2032. else
  2033. begin
  2034. Message2(scan_f_syn_expected,'CREATE',pattern);
  2035. p1.destroy;
  2036. p1:=cerrornode.create;
  2037. consume(_ID);
  2038. end;
  2039. end;
  2040. end
  2041. else
  2042. begin
  2043. Message(parser_e_invalid_qualifier);
  2044. p1.destroy;
  2045. p1:=cerrornode.create;
  2046. consume(_ID);
  2047. end;
  2048. end;
  2049. variantdef:
  2050. begin
  2051. { dispatch call? }
  2052. { lhs := v.ident[parameters] -> property get
  2053. lhs := v.ident(parameters) -> method call
  2054. v.ident[parameters] := rhs -> property put
  2055. v.ident(parameters) := rhs -> also property put }
  2056. if token=_ID then
  2057. begin
  2058. if not try_type_helper(p1,nil) then
  2059. begin
  2060. dispatchstring:=orgpattern;
  2061. consume(_ID);
  2062. calltype:=dct_method;
  2063. if try_to_consume(_LKLAMMER) then
  2064. begin
  2065. p2:=parse_paras(false,true,_RKLAMMER);
  2066. consume(_RKLAMMER);
  2067. end
  2068. else if try_to_consume(_LECKKLAMMER) then
  2069. begin
  2070. p2:=parse_paras(false,true,_RECKKLAMMER);
  2071. consume(_RECKKLAMMER);
  2072. calltype:=dct_propget;
  2073. end
  2074. else
  2075. p2:=nil;
  2076. { property setter? }
  2077. if (token=_ASSIGNMENT) and not(afterassignment) then
  2078. begin
  2079. consume(_ASSIGNMENT);
  2080. { read the expression }
  2081. p3:=comp_expr(true,false);
  2082. { concat value parameter too }
  2083. p2:=ccallparanode.create(p3,p2);
  2084. p1:=translate_disp_call(p1,p2,dct_propput,dispatchstring,0,voidtype);
  2085. end
  2086. else
  2087. { this is only an approximation
  2088. setting useresult if not necessary is only a waste of time, no more, no less (FK) }
  2089. if afterassignment or in_args or (token<>_SEMICOLON) then
  2090. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,cvarianttype)
  2091. else
  2092. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,voidtype);
  2093. end;
  2094. end
  2095. else { Error }
  2096. Consume(_ID);
  2097. end;
  2098. classrefdef:
  2099. begin
  2100. if token=_ID then
  2101. begin
  2102. structh:=tobjectdef(tclassrefdef(p1.resultdef).pointeddef);
  2103. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2104. if assigned(srsym) then
  2105. begin
  2106. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2107. consume(_ID);
  2108. do_member_read(structh,getaddr,srsym,p1,again,[]);
  2109. end
  2110. else
  2111. begin
  2112. Message1(sym_e_id_no_member,orgpattern);
  2113. p1.destroy;
  2114. p1:=cerrornode.create;
  2115. { try to clean up }
  2116. consume(_ID);
  2117. end;
  2118. end
  2119. else { Error }
  2120. Consume(_ID);
  2121. end;
  2122. objectdef:
  2123. begin
  2124. if token=_ID then
  2125. begin
  2126. structh:=tobjectdef(p1.resultdef);
  2127. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2128. if assigned(srsym) then
  2129. begin
  2130. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2131. consume(_ID);
  2132. do_member_read(structh,getaddr,srsym,p1,again,[]);
  2133. end
  2134. else
  2135. begin
  2136. Message1(sym_e_id_no_member,orgpattern);
  2137. p1.destroy;
  2138. p1:=cerrornode.create;
  2139. { try to clean up }
  2140. consume(_ID);
  2141. end;
  2142. end
  2143. else { Error }
  2144. Consume(_ID);
  2145. end;
  2146. pointerdef:
  2147. begin
  2148. if (p1.resultdef=objc_idtype) then
  2149. begin
  2150. { objc's id type can be used to call any
  2151. Objective-C method of any Objective-C class
  2152. type that's currently in scope }
  2153. if search_objc_method(pattern,srsym,srsymtable) then
  2154. begin
  2155. consume(_ID);
  2156. do_proc_call(srsym,srsymtable,nil,
  2157. (getaddr and not(token in [_CARET,_POINT])),
  2158. again,p1,[cnf_objc_id_call]);
  2159. { we need to know which procedure is called }
  2160. do_typecheckpass(p1);
  2161. end
  2162. else
  2163. begin
  2164. consume(_ID);
  2165. Message(parser_e_methode_id_expected);
  2166. end;
  2167. end
  2168. else
  2169. begin
  2170. if not try_type_helper(p1,nil) then
  2171. begin
  2172. Message(parser_e_invalid_qualifier);
  2173. if tpointerdef(p1.resultdef).pointeddef.typ in [recorddef,objectdef,classrefdef] then
  2174. Message(parser_h_maybe_deref_caret_missing);
  2175. end;
  2176. end
  2177. end;
  2178. else
  2179. begin
  2180. found:=try_type_helper(p1,nil);
  2181. if not found then
  2182. begin
  2183. if p1.resultdef.typ<>undefineddef then
  2184. Message(parser_e_invalid_qualifier);
  2185. p1.destroy;
  2186. p1:=cerrornode.create;
  2187. { Error }
  2188. consume(_ID);
  2189. end;
  2190. end;
  2191. end;
  2192. { processing an ordconstnode avoids the resultdef check }
  2193. skippointdefcheck:
  2194. end;
  2195. else
  2196. begin
  2197. { is this a procedure variable ? }
  2198. if assigned(p1.resultdef) and
  2199. (p1.resultdef.typ=procvardef) then
  2200. begin
  2201. { Typenode for typecasting or expecting a procvar }
  2202. if (p1.nodetype=typen) or
  2203. (
  2204. assigned(getprocvardef) and
  2205. equal_defs(p1.resultdef,getprocvardef)
  2206. ) then
  2207. begin
  2208. if try_to_consume(_LKLAMMER) then
  2209. begin
  2210. p1:=comp_expr(true,false);
  2211. consume(_RKLAMMER);
  2212. p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
  2213. end
  2214. else
  2215. again:=false
  2216. end
  2217. else
  2218. begin
  2219. if try_to_consume(_LKLAMMER) then
  2220. begin
  2221. p2:=parse_paras(false,false,_RKLAMMER);
  2222. consume(_RKLAMMER);
  2223. p1:=ccallnode.create_procvar(p2,p1);
  2224. { proc():= is never possible }
  2225. if token=_ASSIGNMENT then
  2226. begin
  2227. Message(parser_e_illegal_expression);
  2228. p1.free;
  2229. p1:=cerrornode.create;
  2230. again:=false;
  2231. end;
  2232. end
  2233. else
  2234. again:=false;
  2235. end;
  2236. end
  2237. else
  2238. again:=false;
  2239. end;
  2240. end;
  2241. { we only try again if p1 was changed }
  2242. if again or
  2243. (p1.nodetype=errorn) then
  2244. result:=true;
  2245. end; { while again }
  2246. end;
  2247. function is_member_read(sym: tsym; st: tsymtable; var p1: tnode;
  2248. out memberparentdef: tdef): boolean;
  2249. var
  2250. hdef : tdef;
  2251. begin
  2252. result:=true;
  2253. memberparentdef:=nil;
  2254. case st.symtabletype of
  2255. ObjectSymtable,
  2256. recordsymtable:
  2257. begin
  2258. memberparentdef:=tdef(st.defowner);
  2259. exit;
  2260. end;
  2261. WithSymtable:
  2262. begin
  2263. if assigned(p1) then
  2264. internalerror(2007012002);
  2265. hdef:=tnode(twithsymtable(st).withrefnode).resultdef;
  2266. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  2267. if not(hdef.typ in [objectdef,classrefdef]) then
  2268. exit;
  2269. if (hdef.typ=classrefdef) then
  2270. hdef:=tclassrefdef(hdef).pointeddef;
  2271. memberparentdef:=hdef;
  2272. end;
  2273. else
  2274. result:=false;
  2275. end;
  2276. end;
  2277. {$maxfpuregisters 0}
  2278. function factor(getaddr,typeonly:boolean) : tnode;
  2279. {---------------------------------------------
  2280. Factor_read_id
  2281. ---------------------------------------------}
  2282. procedure factor_read_id(out p1:tnode;var again:boolean);
  2283. function findwithsymtable : boolean;
  2284. var
  2285. hp : psymtablestackitem;
  2286. begin
  2287. result:=true;
  2288. hp:=symtablestack.stack;
  2289. while assigned(hp) do
  2290. begin
  2291. if hp^.symtable.symtabletype=withsymtable then
  2292. exit;
  2293. hp:=hp^.next;
  2294. end;
  2295. result:=false;
  2296. end;
  2297. var
  2298. srsym: tsym;
  2299. srsymtable: TSymtable;
  2300. hdef: tdef;
  2301. pd: tprocdef;
  2302. orgstoredpattern,
  2303. storedpattern: string;
  2304. callflags: tcallnodeflags;
  2305. t : ttoken;
  2306. unit_found : boolean;
  2307. tokenpos: tfileposinfo;
  2308. begin
  2309. { allow post fix operators }
  2310. again:=true;
  2311. { preinitalize tokenpos }
  2312. tokenpos:=current_filepos;
  2313. { first check for identifier }
  2314. if token<>_ID then
  2315. begin
  2316. srsym:=generrorsym;
  2317. srsymtable:=nil;
  2318. consume(_ID);
  2319. unit_found:=false;
  2320. end
  2321. else
  2322. begin
  2323. if typeonly then
  2324. searchsym_type(pattern,srsym,srsymtable)
  2325. else
  2326. searchsym(pattern,srsym,srsymtable);
  2327. { handle unit specification like System.Writeln }
  2328. unit_found:=try_consume_unitsym(srsym,srsymtable,t,true);
  2329. storedpattern:=pattern;
  2330. orgstoredpattern:=orgpattern;
  2331. { store the position of the token before consuming it }
  2332. tokenpos:=current_filepos;
  2333. consume(t);
  2334. { named parameter support }
  2335. found_arg_name:=false;
  2336. if not(unit_found) and
  2337. named_args_allowed and
  2338. (token=_ASSIGNMENT) then
  2339. begin
  2340. found_arg_name:=true;
  2341. p1:=cstringconstnode.createstr(storedpattern);
  2342. consume(_ASSIGNMENT);
  2343. exit;
  2344. end;
  2345. { check hints, but only if it isn't a potential generic symbol;
  2346. that is checked in sub_expr if it isn't a generic }
  2347. if assigned(srsym) and
  2348. not (
  2349. (srsym.typ=typesym) and
  2350. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) and
  2351. not (sp_generic_para in srsym.symoptions) and
  2352. (token in [_LT, _LSHARPBRACKET])
  2353. ) then
  2354. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2355. { if nothing found give error and return errorsym }
  2356. if not assigned(srsym) or
  2357. { is this a generic dummy symbol? }
  2358. ((srsym.typ=typesym) and
  2359. assigned(ttypesym(srsym).typedef) and
  2360. (ttypesym(srsym).typedef.typ=undefineddef) and
  2361. not (sp_generic_para in srsym.symoptions) and
  2362. not (token in [_LT, _LSHARPBRACKET]) and
  2363. not (
  2364. { in non-Delphi modes the generic class' name without a
  2365. "specialization" or "<T>" may be used to identify the
  2366. current class }
  2367. (sp_generic_dummy in srsym.symoptions) and
  2368. assigned(current_structdef) and
  2369. (df_generic in current_structdef.defoptions) and
  2370. not (m_delphi in current_settings.modeswitches) and
  2371. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  2372. )) and
  2373. { it could be a rename of a generic para }
  2374. { Note: if this generates false positives we'll need to
  2375. include a "basesym" to tsym to track the original
  2376. symbol }
  2377. not (sp_explicitrename in srsym.symoptions) then
  2378. begin
  2379. { if a generic is parsed and when we are inside an with block,
  2380. a symbol might not be defined }
  2381. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  2382. findwithsymtable then
  2383. begin
  2384. { create dummy symbol, it will be freed later on }
  2385. srsym:=tsym.create(undefinedsym,'$undefinedsym');
  2386. srsymtable:=nil;
  2387. end
  2388. else
  2389. begin
  2390. identifier_not_found(orgstoredpattern,tokenpos);
  2391. srsym:=generrorsym;
  2392. srsymtable:=nil;
  2393. end;
  2394. end;
  2395. end;
  2396. { Access to funcret or need to call the function? }
  2397. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  2398. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  2399. { result(x) is not allowed }
  2400. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  2401. (
  2402. (token=_LKLAMMER) or
  2403. (
  2404. (([m_tp7,m_delphi,m_mac,m_iso] * current_settings.modeswitches) <> []) and
  2405. (afterassignment or in_args)
  2406. )
  2407. ) then
  2408. begin
  2409. hdef:=tdef(srsym.owner.defowner);
  2410. if assigned(hdef) and
  2411. (hdef.typ=procdef) then
  2412. srsym:=tprocdef(hdef).procsym
  2413. else
  2414. begin
  2415. Message(parser_e_illegal_expression);
  2416. srsym:=generrorsym;
  2417. end;
  2418. srsymtable:=srsym.owner;
  2419. end;
  2420. begin
  2421. case srsym.typ of
  2422. absolutevarsym :
  2423. begin
  2424. if (tabsolutevarsym(srsym).abstyp=tovar) then
  2425. begin
  2426. p1:=nil;
  2427. propaccesslist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  2428. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vardef);
  2429. include(p1.flags,nf_absolute);
  2430. end
  2431. else
  2432. p1:=cloadnode.create(srsym,srsymtable);
  2433. end;
  2434. staticvarsym,
  2435. localvarsym,
  2436. paravarsym,
  2437. fieldvarsym :
  2438. begin
  2439. { check if we are reading a field of an object/class/ }
  2440. { record. is_member_read() will deal with withsymtables }
  2441. { if needed. }
  2442. p1:=nil;
  2443. if is_member_read(srsym,srsymtable,p1,hdef) then
  2444. begin
  2445. { if the field was originally found in an }
  2446. { objectsymtable, it means it's part of self }
  2447. { if only method from which it was called is }
  2448. { not class static }
  2449. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2450. { if we are accessing a owner procsym from the nested }
  2451. { class we need to call it as a class member }
  2452. if assigned(current_structdef) and
  2453. (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  2454. (sp_static in srsym.symoptions)) then
  2455. if srsymtable.symtabletype=recordsymtable then
  2456. p1:=ctypenode.create(hdef)
  2457. else
  2458. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2459. else
  2460. begin
  2461. if assigned(current_procinfo) then
  2462. begin
  2463. pd:=current_procinfo.get_normal_proc.procdef;
  2464. if assigned(pd) and pd.no_self_node then
  2465. p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  2466. else
  2467. p1:=load_self_node;
  2468. end
  2469. else
  2470. p1:=load_self_node;
  2471. end;
  2472. { now, if the field itself is part of an objectsymtab }
  2473. { (it can be even if it was found in a withsymtable, }
  2474. { e.g., "with classinstance do field := 5"), then }
  2475. { let do_member_read handle it }
  2476. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2477. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2478. else
  2479. { otherwise it's a regular record subscript }
  2480. p1:=csubscriptnode.create(srsym,p1);
  2481. end
  2482. else
  2483. { regular non-field load }
  2484. p1:=cloadnode.create(srsym,srsymtable);
  2485. end;
  2486. syssym :
  2487. begin
  2488. p1:=statement_syssym(tsyssym(srsym).number);
  2489. end;
  2490. typesym :
  2491. begin
  2492. hdef:=ttypesym(srsym).typedef;
  2493. if not assigned(hdef) then
  2494. begin
  2495. again:=false;
  2496. end
  2497. else
  2498. begin
  2499. { We need to know if this unit uses Variants }
  2500. if ((hdef=cvarianttype) or (hdef=colevarianttype)) and
  2501. not(cs_compilesystem in current_settings.moduleswitches) then
  2502. current_module.flags:=current_module.flags or uf_uses_variants;
  2503. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,typeonly);
  2504. end;
  2505. end;
  2506. enumsym :
  2507. begin
  2508. p1:=genenumnode(tenumsym(srsym));
  2509. end;
  2510. constsym :
  2511. begin
  2512. if tconstsym(srsym).consttyp=constresourcestring then
  2513. begin
  2514. p1:=cloadnode.create(srsym,srsymtable);
  2515. do_typecheckpass(p1);
  2516. p1.resultdef:=getansistringdef;
  2517. end
  2518. else
  2519. p1:=genconstsymtree(tconstsym(srsym));
  2520. end;
  2521. procsym :
  2522. begin
  2523. p1:=nil;
  2524. { check if it's a method/class method }
  2525. if is_member_read(srsym,srsymtable,p1,hdef) then
  2526. begin
  2527. { if we are accessing a owner procsym from the nested }
  2528. { class we need to call it as a class member }
  2529. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  2530. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2531. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  2532. { not srsymtable.symtabletype since that can be }
  2533. { withsymtable as well }
  2534. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2535. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2536. else
  2537. { no procsyms in records (yet) }
  2538. internalerror(2007012006);
  2539. end
  2540. else
  2541. begin
  2542. { regular procedure/function call }
  2543. if not unit_found then
  2544. callflags:=[]
  2545. else
  2546. callflags:=[cnf_unit_specified];
  2547. do_proc_call(srsym,srsymtable,nil,
  2548. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  2549. again,p1,callflags);
  2550. end;
  2551. end;
  2552. propertysym :
  2553. begin
  2554. p1:=nil;
  2555. { property of a class/object? }
  2556. if is_member_read(srsym,srsymtable,p1,hdef) then
  2557. begin
  2558. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2559. { if we are accessing a owner procsym from the nested }
  2560. { class or from a static class method we need to call }
  2561. { it as a class member }
  2562. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  2563. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  2564. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2565. else
  2566. p1:=load_self_node;
  2567. { not srsymtable.symtabletype since that can be }
  2568. { withsymtable as well }
  2569. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2570. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2571. else
  2572. { no propertysyms in records (yet) }
  2573. internalerror(2009111510);
  2574. end
  2575. else
  2576. { no method pointer }
  2577. begin
  2578. handle_propertysym(tpropertysym(srsym),srsymtable,p1);
  2579. end;
  2580. end;
  2581. labelsym :
  2582. begin
  2583. { Support @label }
  2584. if getaddr then
  2585. begin
  2586. if srsym.owner<>current_procinfo.procdef.localst then
  2587. CGMessage(parser_e_label_outside_proc);
  2588. p1:=cloadnode.create(srsym,srsym.owner)
  2589. end
  2590. else
  2591. begin
  2592. consume(_COLON);
  2593. if tlabelsym(srsym).defined then
  2594. Message(sym_e_label_already_defined);
  2595. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  2596. begin
  2597. tlabelsym(srsym).nonlocal:=true;
  2598. exclude(current_procinfo.procdef.procoptions,po_inline);
  2599. end;
  2600. if tlabelsym(srsym).nonlocal and
  2601. (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  2602. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  2603. tlabelsym(srsym).defined:=true;
  2604. p1:=clabelnode.create(nil,tlabelsym(srsym));
  2605. tlabelsym(srsym).code:=p1;
  2606. end;
  2607. end;
  2608. undefinedsym :
  2609. begin
  2610. p1:=cnothingnode.Create;
  2611. p1.resultdef:=cundefineddef.create;
  2612. { clean up previously created dummy symbol }
  2613. srsym.free;
  2614. end;
  2615. errorsym :
  2616. begin
  2617. p1:=cerrornode.create;
  2618. if try_to_consume(_LKLAMMER) then
  2619. begin
  2620. parse_paras(false,false,_RKLAMMER);
  2621. consume(_RKLAMMER);
  2622. end;
  2623. end;
  2624. else
  2625. begin
  2626. p1:=cerrornode.create;
  2627. Message(parser_e_illegal_expression);
  2628. end;
  2629. end; { end case }
  2630. if assigned(p1) and (p1.nodetype<>errorn) then
  2631. p1.fileinfo:=tokenpos;
  2632. end;
  2633. end;
  2634. {---------------------------------------------
  2635. Factor_Read_Set
  2636. ---------------------------------------------}
  2637. { Read a set between [] }
  2638. function factor_read_set:tnode;
  2639. var
  2640. p1,p2 : tnode;
  2641. lastp,
  2642. buildp : tarrayconstructornode;
  2643. old_allow_array_constructor : boolean;
  2644. begin
  2645. buildp:=nil;
  2646. lastp:=nil;
  2647. { be sure that a least one arrayconstructn is used, also for an
  2648. empty [] }
  2649. if token=_RECKKLAMMER then
  2650. buildp:=carrayconstructornode.create(nil,buildp)
  2651. else
  2652. repeat
  2653. { nested array constructors are not allowed, see also tests/webtbs/tw17213.pp }
  2654. old_allow_array_constructor:=allow_array_constructor;
  2655. allow_array_constructor:=false;
  2656. p1:=comp_expr(true,false);
  2657. if try_to_consume(_POINTPOINT) then
  2658. begin
  2659. p2:=comp_expr(true,false);
  2660. p1:=carrayconstructorrangenode.create(p1,p2);
  2661. end;
  2662. { insert at the end of the tree, to get the correct order }
  2663. if not assigned(buildp) then
  2664. begin
  2665. buildp:=carrayconstructornode.create(p1,nil);
  2666. lastp:=buildp;
  2667. end
  2668. else
  2669. begin
  2670. lastp.right:=carrayconstructornode.create(p1,nil);
  2671. lastp:=tarrayconstructornode(lastp.right);
  2672. end;
  2673. allow_array_constructor:=old_allow_array_constructor;
  2674. { there could be more elements }
  2675. until not try_to_consume(_COMMA);
  2676. factor_read_set:=buildp;
  2677. end;
  2678. function can_load_self_node: boolean;
  2679. begin
  2680. result:=false;
  2681. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  2682. not assigned(current_structdef) or
  2683. not assigned(current_procinfo) then
  2684. exit;
  2685. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  2686. end;
  2687. {---------------------------------------------
  2688. Factor (Main)
  2689. ---------------------------------------------}
  2690. var
  2691. l : longint;
  2692. ic : int64;
  2693. qc : qword;
  2694. p1 : tnode;
  2695. code : integer;
  2696. srsym : tsym;
  2697. srsymtable : TSymtable;
  2698. pd : tprocdef;
  2699. hclassdef : tobjectdef;
  2700. d : bestreal;
  2701. hs,hsorg : string;
  2702. hdef : tdef;
  2703. filepos : tfileposinfo;
  2704. callflags : tcallnodeflags;
  2705. idstr : tidstring;
  2706. dopostfix,
  2707. again,
  2708. updatefpos,
  2709. nodechanged : boolean;
  2710. begin
  2711. { can't keep a copy of p1 and compare pointers afterwards, because
  2712. p1 may be freed and reallocated in the same place! }
  2713. dopostfix:=true;
  2714. updatefpos:=false;
  2715. p1:=nil;
  2716. filepos:=current_tokenpos;
  2717. again:=false;
  2718. pd:=nil;
  2719. if token=_ID then
  2720. begin
  2721. again:=true;
  2722. { Handle references to self }
  2723. if (idtoken=_SELF) and can_load_self_node then
  2724. begin
  2725. p1:=load_self_node;
  2726. consume(_ID);
  2727. again:=true;
  2728. end
  2729. else
  2730. factor_read_id(p1,again);
  2731. if assigned(p1) then
  2732. begin
  2733. { factor_read_id will set the filepos to after the id,
  2734. and in case of _SELF the filepos will already be the
  2735. same as filepos (so setting it again doesn't hurt). }
  2736. p1.fileinfo:=filepos;
  2737. filepos:=current_tokenpos;
  2738. end;
  2739. { handle post fix operators }
  2740. if (m_delphi in current_settings.modeswitches) and
  2741. (block_type=bt_body) and
  2742. (token in [_LT,_LSHARPBRACKET]) then
  2743. begin
  2744. if p1.nodetype=typen then
  2745. idstr:=ttypenode(p1).typesym.name
  2746. else
  2747. if (p1.nodetype=loadvmtaddrn) and
  2748. (tloadvmtaddrnode(p1).left.nodetype=typen) then
  2749. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name
  2750. else
  2751. if (p1.nodetype=loadn) then
  2752. idstr:=tloadnode(p1).symtableentry.name
  2753. else
  2754. idstr:='';
  2755. { if this is the case then the postfix handling is done in
  2756. sub_expr if necessary }
  2757. dopostfix:=not could_be_generic(idstr);
  2758. end;
  2759. if dopostfix then
  2760. updatefpos:=postfixoperators(p1,again,getaddr);
  2761. end
  2762. else
  2763. begin
  2764. updatefpos:=true;
  2765. case token of
  2766. _RETURN :
  2767. begin
  2768. consume(_RETURN);
  2769. if not(token in [_SEMICOLON,_ELSE,_END]) then
  2770. p1 := cexitnode.create(comp_expr(true,false))
  2771. else
  2772. p1 := cexitnode.create(nil);
  2773. end;
  2774. _INHERITED :
  2775. begin
  2776. again:=true;
  2777. consume(_INHERITED);
  2778. if assigned(current_procinfo) and
  2779. assigned(current_structdef) and
  2780. ((current_structdef.typ=objectdef) or
  2781. ((target_info.system in systems_jvm) and
  2782. (current_structdef.typ=recorddef)))then
  2783. begin
  2784. { for record helpers in mode Delphi "inherited" is not
  2785. allowed }
  2786. if is_objectpascal_helper(current_structdef) and
  2787. (m_delphi in current_settings.modeswitches) and
  2788. is_record(tobjectdef(current_structdef).extendeddef) then
  2789. Message(parser_e_inherited_not_in_record);
  2790. if (current_structdef.typ=objectdef) then
  2791. begin
  2792. hclassdef:=tobjectdef(current_structdef).childof;
  2793. { Objective-C categories *replace* methods in the class
  2794. they extend, or add methods to it. So calling an
  2795. inherited method always calls the method inherited from
  2796. the parent of the extended class }
  2797. if is_objccategory(current_structdef) then
  2798. hclassdef:=hclassdef.childof;
  2799. end
  2800. else if target_info.system in systems_jvm then
  2801. hclassdef:=java_fpcbaserecordtype
  2802. else
  2803. internalerror(2012012401);
  2804. { if inherited; only then we need the method with
  2805. the same name }
  2806. if token <> _ID then
  2807. begin
  2808. hs:=current_procinfo.procdef.procsym.name;
  2809. hsorg:=current_procinfo.procdef.procsym.realname;
  2810. anon_inherited:=true;
  2811. { For message methods we need to search using the message
  2812. number or string }
  2813. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  2814. srdef:=nil;
  2815. if (po_msgint in pd.procoptions) then
  2816. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  2817. else
  2818. if (po_msgstr in pd.procoptions) then
  2819. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  2820. else
  2821. { helpers have their own ways of dealing with inherited }
  2822. if is_objectpascal_helper(current_structdef) then
  2823. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  2824. else
  2825. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  2826. end
  2827. else
  2828. begin
  2829. hs:=pattern;
  2830. hsorg:=orgpattern;
  2831. consume(_ID);
  2832. anon_inherited:=false;
  2833. { helpers have their own ways of dealing with inherited }
  2834. if is_objectpascal_helper(current_structdef) then
  2835. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  2836. else
  2837. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  2838. end;
  2839. if assigned(srsym) then
  2840. begin
  2841. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2842. { load the procdef from the inherited class and
  2843. not from self }
  2844. case srsym.typ of
  2845. procsym:
  2846. begin
  2847. if is_objectpascal_helper(current_structdef) then
  2848. begin
  2849. { for a helper load the procdef either from the
  2850. extended type, from the parent helper or from
  2851. the extended type of the parent helper
  2852. depending on the def the found symbol belongs
  2853. to }
  2854. if (srsym.Owner.defowner.typ=objectdef) and
  2855. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  2856. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  2857. assigned(tobjectdef(current_structdef).childof) then
  2858. hdef:=tobjectdef(current_structdef).childof
  2859. else
  2860. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef
  2861. else
  2862. hdef:=tdef(srsym.Owner.defowner);
  2863. end
  2864. else
  2865. hdef:=hclassdef;
  2866. if (po_classmethod in current_procinfo.procdef.procoptions) or
  2867. (po_staticmethod in current_procinfo.procdef.procoptions) then
  2868. hdef:=cclassrefdef.create(hdef);
  2869. p1:=ctypenode.create(hdef);
  2870. { we need to allow helpers here }
  2871. ttypenode(p1).helperallowed:=true;
  2872. end;
  2873. propertysym:
  2874. ;
  2875. else
  2876. begin
  2877. Message(parser_e_methode_id_expected);
  2878. p1:=cerrornode.create;
  2879. end;
  2880. end;
  2881. callflags:=[cnf_inherited];
  2882. include(current_procinfo.flags,pi_has_inherited);
  2883. if anon_inherited then
  2884. include(callflags,cnf_anon_inherited);
  2885. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags);
  2886. end
  2887. else
  2888. begin
  2889. if anon_inherited then
  2890. begin
  2891. { For message methods we need to call DefaultHandler }
  2892. if (po_msgint in pd.procoptions) or
  2893. (po_msgstr in pd.procoptions) then
  2894. begin
  2895. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  2896. if not assigned(srsym) or
  2897. (srsym.typ<>procsym) then
  2898. internalerror(200303171);
  2899. p1:=nil;
  2900. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[]);
  2901. end
  2902. else
  2903. begin
  2904. { we need to ignore the inherited; }
  2905. p1:=cnothingnode.create;
  2906. end;
  2907. end
  2908. else
  2909. begin
  2910. Message1(sym_e_id_no_member,hsorg);
  2911. p1:=cerrornode.create;
  2912. end;
  2913. again:=false;
  2914. end;
  2915. { turn auto inheriting off }
  2916. anon_inherited:=false;
  2917. end
  2918. else
  2919. begin
  2920. { in case of records we use a more clear error message }
  2921. if assigned(current_structdef) and
  2922. (current_structdef.typ=recorddef) then
  2923. Message(parser_e_inherited_not_in_record)
  2924. else
  2925. Message(parser_e_generic_methods_only_in_methods);
  2926. again:=false;
  2927. p1:=cerrornode.create;
  2928. end;
  2929. postfixoperators(p1,again,getaddr);
  2930. end;
  2931. _INTCONST :
  2932. begin
  2933. {Try first wether the value fits in an int64.}
  2934. val(pattern,ic,code);
  2935. if code=0 then
  2936. begin
  2937. consume(_INTCONST);
  2938. int_to_type(ic,hdef);
  2939. p1:=cordconstnode.create(ic,hdef,true);
  2940. end
  2941. else
  2942. begin
  2943. { try qword next }
  2944. val(pattern,qc,code);
  2945. if code=0 then
  2946. begin
  2947. consume(_INTCONST);
  2948. int_to_type(qc,hdef);
  2949. p1:=cordconstnode.create(qc,hdef,true);
  2950. end;
  2951. end;
  2952. if code<>0 then
  2953. begin
  2954. { finally float }
  2955. val(pattern,d,code);
  2956. if code<>0 then
  2957. begin
  2958. Message(parser_e_invalid_integer);
  2959. consume(_INTCONST);
  2960. l:=1;
  2961. p1:=cordconstnode.create(l,sinttype,true);
  2962. end
  2963. else
  2964. begin
  2965. consume(_INTCONST);
  2966. p1:=crealconstnode.create(d,pbestrealtype^);
  2967. end;
  2968. end
  2969. else
  2970. { the necessary range checking has already been done by val }
  2971. tordconstnode(p1).rangecheck:=false;
  2972. if token=_POINT then
  2973. begin
  2974. again:=true;
  2975. postfixoperators(p1,again,getaddr);
  2976. end;
  2977. end;
  2978. _REALNUMBER :
  2979. begin
  2980. p1:=real_const_node_from_pattern(pattern);
  2981. consume(_REALNUMBER);
  2982. if token=_POINT then
  2983. begin
  2984. again:=true;
  2985. postfixoperators(p1,again,getaddr);
  2986. end;
  2987. end;
  2988. _STRING :
  2989. begin
  2990. string_dec(hdef,true);
  2991. { STRING can be also a type cast }
  2992. if try_to_consume(_LKLAMMER) then
  2993. begin
  2994. p1:=comp_expr(true,false);
  2995. consume(_RKLAMMER);
  2996. p1:=ctypeconvnode.create_explicit(p1,hdef);
  2997. { handle postfix operators here e.g. string(a)[10] }
  2998. again:=true;
  2999. postfixoperators(p1,again,getaddr);
  3000. end
  3001. else
  3002. p1:=ctypenode.create(hdef);
  3003. end;
  3004. _FILE :
  3005. begin
  3006. hdef:=cfiletype;
  3007. consume(_FILE);
  3008. { FILE can be also a type cast }
  3009. if try_to_consume(_LKLAMMER) then
  3010. begin
  3011. p1:=comp_expr(true,false);
  3012. consume(_RKLAMMER);
  3013. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3014. { handle postfix operators here e.g. string(a)[10] }
  3015. again:=true;
  3016. postfixoperators(p1,again,getaddr);
  3017. end
  3018. else
  3019. begin
  3020. p1:=ctypenode.create(hdef);
  3021. end;
  3022. end;
  3023. _CSTRING :
  3024. begin
  3025. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3026. consume(_CSTRING);
  3027. if token in postfixoperator_tokens then
  3028. begin
  3029. again:=true;
  3030. postfixoperators(p1,again,getaddr);
  3031. end;
  3032. end;
  3033. _CCHAR :
  3034. begin
  3035. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3036. consume(_CCHAR);
  3037. if token=_POINT then
  3038. begin
  3039. again:=true;
  3040. postfixoperators(p1,again,getaddr);
  3041. end;
  3042. end;
  3043. _CWSTRING:
  3044. begin
  3045. p1:=cstringconstnode.createunistr(patternw);
  3046. consume(_CWSTRING);
  3047. if token in postfixoperator_tokens then
  3048. begin
  3049. again:=true;
  3050. postfixoperators(p1,again,getaddr);
  3051. end;
  3052. end;
  3053. _CWCHAR:
  3054. begin
  3055. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3056. consume(_CWCHAR);
  3057. if token=_POINT then
  3058. begin
  3059. again:=true;
  3060. postfixoperators(p1,again,getaddr);
  3061. end;
  3062. end;
  3063. _KLAMMERAFFE :
  3064. begin
  3065. consume(_KLAMMERAFFE);
  3066. got_addrn:=true;
  3067. { support both @<x> and @(<x>) }
  3068. if try_to_consume(_LKLAMMER) then
  3069. begin
  3070. p1:=factor(true,false);
  3071. if token in postfixoperator_tokens then
  3072. begin
  3073. again:=true;
  3074. postfixoperators(p1,again,getaddr);
  3075. end
  3076. else
  3077. consume(_RKLAMMER);
  3078. end
  3079. else
  3080. p1:=factor(true,false);
  3081. if token in postfixoperator_tokens then
  3082. begin
  3083. again:=true;
  3084. postfixoperators(p1,again,getaddr);
  3085. end;
  3086. got_addrn:=false;
  3087. p1:=caddrnode.create(p1);
  3088. p1.fileinfo:=filepos;
  3089. if cs_typed_addresses in current_settings.localswitches then
  3090. include(p1.flags,nf_typedaddr);
  3091. { Store the procvar that we are expecting, the
  3092. addrn will use the information to find the correct
  3093. procdef or it will return an error }
  3094. if assigned(getprocvardef) and
  3095. (taddrnode(p1).left.nodetype = loadn) then
  3096. taddrnode(p1).getprocvardef:=getprocvardef;
  3097. end;
  3098. _LKLAMMER :
  3099. begin
  3100. consume(_LKLAMMER);
  3101. p1:=comp_expr(true,false);
  3102. consume(_RKLAMMER);
  3103. { it's not a good solution
  3104. but (a+b)^ makes some problems }
  3105. if token in postfixoperator_tokens then
  3106. begin
  3107. again:=true;
  3108. postfixoperators(p1,again,getaddr);
  3109. end;
  3110. end;
  3111. _LECKKLAMMER :
  3112. begin
  3113. consume(_LECKKLAMMER);
  3114. p1:=factor_read_set;
  3115. consume(_RECKKLAMMER);
  3116. end;
  3117. _PLUS :
  3118. begin
  3119. consume(_PLUS);
  3120. p1:=factor(false,false);
  3121. p1:=cunaryplusnode.create(p1);
  3122. end;
  3123. _MINUS :
  3124. begin
  3125. consume(_MINUS);
  3126. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  3127. begin
  3128. { ugly hack, but necessary to be able to parse }
  3129. { -9223372036854775808 as int64 (JM) }
  3130. pattern := '-'+pattern;
  3131. p1:=sub_expr(oppower,false,false,nil);
  3132. { -1 ** 4 should be - (1 ** 4) and not
  3133. (-1) ** 4
  3134. This was the reason of tw0869.pp test failure PM }
  3135. if p1.nodetype=starstarn then
  3136. begin
  3137. if tbinarynode(p1).left.nodetype=ordconstn then
  3138. begin
  3139. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  3140. p1:=cunaryminusnode.create(p1);
  3141. end
  3142. else if tbinarynode(p1).left.nodetype=realconstn then
  3143. begin
  3144. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  3145. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  3146. p1:=cunaryminusnode.create(p1);
  3147. end
  3148. else
  3149. internalerror(20021029);
  3150. end;
  3151. end
  3152. else
  3153. begin
  3154. if m_isolike_unary_minus in current_settings.modeswitches then
  3155. p1:=sub_expr(opmultiply,false,false,nil)
  3156. else
  3157. p1:=sub_expr(oppower,false,false,nil);
  3158. p1:=cunaryminusnode.create(p1);
  3159. end;
  3160. end;
  3161. _OP_NOT :
  3162. begin
  3163. consume(_OP_NOT);
  3164. p1:=factor(false,false);
  3165. p1:=cnotnode.create(p1);
  3166. end;
  3167. _NIL :
  3168. begin
  3169. consume(_NIL);
  3170. p1:=cnilnode.create;
  3171. { It's really ugly code nil^, but delphi allows it }
  3172. if token in [_CARET,_POINT] then
  3173. begin
  3174. again:=true;
  3175. postfixoperators(p1,again,getaddr);
  3176. end;
  3177. end;
  3178. _OBJCPROTOCOL:
  3179. begin
  3180. { The @protocol keyword is used in two ways in Objective-C:
  3181. 1) to declare protocols (~ Object Pascal interfaces)
  3182. 2) to obtain the metaclass (~ Object Pascal) "class of")
  3183. of a declared protocol
  3184. This code is for handling the second case. Because of 1),
  3185. we cannot simply use a system unit symbol.
  3186. }
  3187. consume(_OBJCPROTOCOL);
  3188. consume(_LKLAMMER);
  3189. p1:=factor(false,false);
  3190. consume(_RKLAMMER);
  3191. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  3192. end;
  3193. else
  3194. begin
  3195. Message(parser_e_illegal_expression);
  3196. p1:=cerrornode.create;
  3197. { recover }
  3198. consume(token);
  3199. end;
  3200. end;
  3201. end;
  3202. { generate error node if no node is created }
  3203. if not assigned(p1) then
  3204. begin
  3205. {$ifdef EXTDEBUG}
  3206. Comment(V_Warning,'factor: p1=nil');
  3207. {$endif}
  3208. p1:=cerrornode.create;
  3209. updatefpos:=true;
  3210. end;
  3211. { get the resultdef for the node if nothing stops us }
  3212. if (not assigned(p1.resultdef)) and dopostfix then
  3213. begin
  3214. do_typecheckpass_changed(p1,nodechanged);
  3215. updatefpos:=updatefpos or nodechanged;
  3216. end;
  3217. if assigned(p1) and
  3218. updatefpos then
  3219. p1.fileinfo:=filepos;
  3220. factor:=p1;
  3221. end;
  3222. {$maxfpuregisters default}
  3223. procedure post_comp_expr_gendef(var def: tdef);
  3224. var
  3225. p1 : tnode;
  3226. again : boolean;
  3227. begin
  3228. if not assigned(def) then
  3229. internalerror(2011053001);
  3230. again:=false;
  3231. { handle potential typecasts, etc }
  3232. p1:=handle_factor_typenode(def,false,again,nil,false);
  3233. { parse postfix operators }
  3234. postfixoperators(p1,again,false);
  3235. if assigned(p1) and (p1.nodetype=typen) then
  3236. def:=ttypenode(p1).typedef
  3237. else
  3238. def:=generrordef;
  3239. end;
  3240. {****************************************************************************
  3241. Sub_Expr
  3242. ****************************************************************************}
  3243. function sub_expr(pred_level:Toperator_precedence;accept_equal,typeonly:boolean;factornode:tnode):tnode;
  3244. {Reads a subexpression while the operators are of the current precedence
  3245. level, or any higher level. Replaces the old term, simpl_expr and
  3246. simpl2_expr.}
  3247. function istypenode(n:tnode):boolean;inline;
  3248. { Checks whether the given node is a type node or a VMT node containing a
  3249. typenode. This is used in the code for inline specializations in the
  3250. _LT branch below }
  3251. begin
  3252. result:=assigned(n) and
  3253. (
  3254. (n.nodetype=typen) or
  3255. (
  3256. (n.nodetype=loadvmtaddrn) and
  3257. (tloadvmtaddrnode(n).left.nodetype=typen)
  3258. )
  3259. );
  3260. end;
  3261. function gettypedef(n:tnode):tdef;inline;
  3262. { This returns the typedef that belongs to the given typenode or
  3263. loadvmtaddrnode. n must not be Nil! }
  3264. begin
  3265. if n.nodetype=typen then
  3266. result:=ttypenode(n).typedef
  3267. else
  3268. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  3269. end;
  3270. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  3271. var
  3272. srsymtable : tsymtable;
  3273. begin
  3274. srsym:=nil;
  3275. case n.nodetype of
  3276. typen:
  3277. srsym:=ttypenode(n).typedef.typesym;
  3278. loadvmtaddrn:
  3279. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  3280. loadn:
  3281. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  3282. srsym:=nil;
  3283. { TODO : handle const nodes }
  3284. end;
  3285. result:=assigned(srsym);
  3286. end;
  3287. label
  3288. SubExprStart;
  3289. var
  3290. p1,p2 : tnode;
  3291. oldt : Ttoken;
  3292. filepos : tfileposinfo;
  3293. again : boolean;
  3294. gendef,parseddef : tdef;
  3295. gensym : tsym;
  3296. begin
  3297. SubExprStart:
  3298. if pred_level=highest_precedence then
  3299. begin
  3300. if factornode=nil then
  3301. p1:=factor(false,typeonly)
  3302. else
  3303. p1:=factornode;
  3304. end
  3305. else
  3306. p1:=sub_expr(succ(pred_level),true,typeonly,factornode);
  3307. repeat
  3308. if (token in [NOTOKEN..last_operator]) and
  3309. (token in operator_levels[pred_level]) and
  3310. ((token<>_EQ) or accept_equal) then
  3311. begin
  3312. oldt:=token;
  3313. filepos:=current_tokenpos;
  3314. consume(token);
  3315. if pred_level=highest_precedence then
  3316. p2:=factor(false,false)
  3317. else
  3318. p2:=sub_expr(succ(pred_level),true,typeonly,nil);
  3319. case oldt of
  3320. _PLUS :
  3321. p1:=caddnode.create(addn,p1,p2);
  3322. _MINUS :
  3323. p1:=caddnode.create(subn,p1,p2);
  3324. _STAR :
  3325. p1:=caddnode.create(muln,p1,p2);
  3326. _SLASH :
  3327. p1:=caddnode.create(slashn,p1,p2);
  3328. _EQ:
  3329. p1:=caddnode.create(equaln,p1,p2);
  3330. _GT :
  3331. p1:=caddnode.create(gtn,p1,p2);
  3332. _LT :
  3333. begin
  3334. { we need to decice whether we have an inline specialization
  3335. (type nodes to the left and right of "<", mode Delphi and
  3336. ">" or "," following) or a normal "<" comparison }
  3337. { TODO : p1 could be a non type if e.g. a variable with the
  3338. same name is defined in the same unit where the
  3339. generic is defined (though "same unit" is not
  3340. necessarily needed) }
  3341. if getgenericsym(p1,gensym) and
  3342. { Attention: when nested specializations are supported
  3343. p2 could be a loadn if a "<" follows }
  3344. istypenode(p2) and
  3345. (m_delphi in current_settings.modeswitches) and
  3346. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  3347. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  3348. begin
  3349. { this is an inline specialization }
  3350. { retrieve the defs of two nodes }
  3351. gendef:=nil;
  3352. parseddef:=gettypedef(p2);
  3353. if parseddef.typesym.typ<>typesym then
  3354. Internalerror(2011051001);
  3355. { check the hints for parseddef }
  3356. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg);
  3357. { generate the specialization }
  3358. generate_specialization(gendef,false,'',parseddef,gensym.RealName,p2.fileinfo);
  3359. { we don't need the old left and right nodes anymore }
  3360. p1.Free;
  3361. p2.Free;
  3362. { in case of a class or a record the specialized generic
  3363. is always a classrefdef }
  3364. again:=false;
  3365. { handle potential typecasts, etc }
  3366. p1:=handle_factor_typenode(gendef,false,again,nil,false);
  3367. { parse postfix operators }
  3368. if postfixoperators(p1,again,false) then
  3369. if assigned(p1) then
  3370. p1.fileinfo:=filepos
  3371. else
  3372. p1:=cerrornode.create;
  3373. { with p1 now set we are in reality directly behind the
  3374. call to "factor" thus we need to call down to that
  3375. again }
  3376. { This is disabled until specializations on the right
  3377. hand side work as well, because
  3378. "not working expressions" is better than "half working
  3379. expressions" }
  3380. {factornode:=p1;
  3381. goto SubExprStart;}
  3382. end
  3383. else
  3384. begin
  3385. { this is a normal "<" comparison }
  3386. { potential generic types that are followed by a "<": }
  3387. { a) might not have their resultdef set }
  3388. if not assigned(p1.resultdef) then
  3389. do_typecheckpass(p1);
  3390. { b) are not checked whether they are an undefined def,
  3391. but not a generic parameter }
  3392. if (p1.nodetype=typen) and
  3393. (ttypenode(p1).typedef.typ=undefineddef) and
  3394. assigned(ttypenode(p1).typedef.typesym) and
  3395. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  3396. begin
  3397. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  3398. p1.Free;
  3399. p1:=cerrornode.create;
  3400. end;
  3401. { c) don't have their hints checked }
  3402. if istypenode(p1) then
  3403. begin
  3404. gendef:=gettypedef(p1);
  3405. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  3406. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  3407. end;
  3408. { Note: the second part of the expression will be needed
  3409. for nested specializations }
  3410. if istypenode(p2) {and
  3411. not (token in [_LT, _LSHARPBRACKET])} then
  3412. begin
  3413. gendef:=gettypedef(p2);
  3414. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  3415. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  3416. end;
  3417. { create the comparison node for "<" }
  3418. p1:=caddnode.create(ltn,p1,p2)
  3419. end;
  3420. end;
  3421. _GTE :
  3422. p1:=caddnode.create(gten,p1,p2);
  3423. _LTE :
  3424. p1:=caddnode.create(lten,p1,p2);
  3425. _SYMDIF :
  3426. p1:=caddnode.create(symdifn,p1,p2);
  3427. _STARSTAR :
  3428. p1:=caddnode.create(starstarn,p1,p2);
  3429. _OP_AS,
  3430. _OP_IS :
  3431. begin
  3432. if token in [_LT, _LSHARPBRACKET] then
  3433. begin
  3434. { for now we're handling this as a generic declaration;
  3435. there could be cases though (because of operator
  3436. overloading) where this is the wrong decision... }
  3437. { TODO : here the same note as in _LT applies as p2 could
  3438. point to a variable, etc }
  3439. gendef:=gettypedef(p2);
  3440. if gendef.typesym.typ<>typesym then
  3441. Internalerror(2011071401);
  3442. { generate the specialization }
  3443. generate_specialization(gendef,false,'');
  3444. { we don't need the old p2 anymore }
  3445. p2.Free;
  3446. again:=false;
  3447. { handle potential typecasts, etc }
  3448. p2:=handle_factor_typenode(gendef,false,again,nil,false);
  3449. { parse postfix operators }
  3450. if postfixoperators(p2,again,false) then
  3451. if assigned(p2) then
  3452. p2.fileinfo:=filepos
  3453. else
  3454. p2:=cerrornode.create;
  3455. { here we don't need to call back down to "factor", thus
  3456. no "goto" }
  3457. end;
  3458. { now generate the "is" or "as" node }
  3459. case oldt of
  3460. _OP_AS:
  3461. p1:=casnode.create(p1,p2);
  3462. _OP_IS:
  3463. p1:=cisnode.create(p1,p2);
  3464. end;
  3465. end;
  3466. _OP_IN :
  3467. p1:=cinnode.create(p1,p2);
  3468. _OP_OR,
  3469. _PIPE {macpas only} :
  3470. begin
  3471. p1:=caddnode.create(orn,p1,p2);
  3472. if (oldt = _PIPE) then
  3473. include(p1.flags,nf_short_bool);
  3474. end;
  3475. _OP_AND,
  3476. _AMPERSAND {macpas only} :
  3477. begin
  3478. p1:=caddnode.create(andn,p1,p2);
  3479. if (oldt = _AMPERSAND) then
  3480. include(p1.flags,nf_short_bool);
  3481. end;
  3482. _OP_DIV :
  3483. p1:=cmoddivnode.create(divn,p1,p2);
  3484. _OP_NOT :
  3485. p1:=cnotnode.create(p1);
  3486. _OP_MOD :
  3487. begin
  3488. p1:=cmoddivnode.create(modn,p1,p2);
  3489. if m_iso in current_settings.modeswitches then
  3490. include(p1.flags,nf_isomod);
  3491. end;
  3492. _OP_SHL :
  3493. p1:=cshlshrnode.create(shln,p1,p2);
  3494. _OP_SHR :
  3495. p1:=cshlshrnode.create(shrn,p1,p2);
  3496. _OP_XOR :
  3497. p1:=caddnode.create(xorn,p1,p2);
  3498. _ASSIGNMENT :
  3499. p1:=cassignmentnode.create(p1,p2);
  3500. _NE :
  3501. p1:=caddnode.create(unequaln,p1,p2);
  3502. end;
  3503. p1.fileinfo:=filepos;
  3504. end
  3505. else
  3506. break;
  3507. until false;
  3508. sub_expr:=p1;
  3509. end;
  3510. function comp_expr(accept_equal,typeonly:boolean):tnode;
  3511. var
  3512. oldafterassignment : boolean;
  3513. p1 : tnode;
  3514. begin
  3515. oldafterassignment:=afterassignment;
  3516. afterassignment:=true;
  3517. p1:=sub_expr(opcompare,accept_equal,typeonly,nil);
  3518. { get the resultdef for this expression }
  3519. if not assigned(p1.resultdef) then
  3520. do_typecheckpass(p1);
  3521. afterassignment:=oldafterassignment;
  3522. comp_expr:=p1;
  3523. end;
  3524. function expr(dotypecheck : boolean) : tnode;
  3525. var
  3526. p1,p2 : tnode;
  3527. filepos : tfileposinfo;
  3528. oldafterassignment,
  3529. updatefpos : boolean;
  3530. begin
  3531. oldafterassignment:=afterassignment;
  3532. p1:=sub_expr(opcompare,true,false,nil);
  3533. { get the resultdef for this expression }
  3534. if not assigned(p1.resultdef) and
  3535. dotypecheck then
  3536. do_typecheckpass(p1);
  3537. filepos:=current_tokenpos;
  3538. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  3539. afterassignment:=true;
  3540. updatefpos:=true;
  3541. case token of
  3542. _POINTPOINT :
  3543. begin
  3544. consume(_POINTPOINT);
  3545. p2:=sub_expr(opcompare,true,false,nil);
  3546. p1:=crangenode.create(p1,p2);
  3547. end;
  3548. _ASSIGNMENT :
  3549. begin
  3550. consume(_ASSIGNMENT);
  3551. if assigned(p1.resultdef) and (p1.resultdef.typ=procvardef) then
  3552. getprocvardef:=tprocvardef(p1.resultdef);
  3553. p2:=sub_expr(opcompare,true,false,nil);
  3554. if assigned(getprocvardef) then
  3555. handle_procvar(getprocvardef,p2);
  3556. getprocvardef:=nil;
  3557. p1:=cassignmentnode.create(p1,p2);
  3558. end;
  3559. _PLUSASN :
  3560. begin
  3561. consume(_PLUSASN);
  3562. p2:=sub_expr(opcompare,true,false,nil);
  3563. p1:=gen_c_style_operator(addn,p1,p2);
  3564. end;
  3565. _MINUSASN :
  3566. begin
  3567. consume(_MINUSASN);
  3568. p2:=sub_expr(opcompare,true,false,nil);
  3569. p1:=gen_c_style_operator(subn,p1,p2);
  3570. end;
  3571. _STARASN :
  3572. begin
  3573. consume(_STARASN );
  3574. p2:=sub_expr(opcompare,true,false,nil);
  3575. p1:=gen_c_style_operator(muln,p1,p2);
  3576. end;
  3577. _SLASHASN :
  3578. begin
  3579. consume(_SLASHASN );
  3580. p2:=sub_expr(opcompare,true,false,nil);
  3581. p1:=gen_c_style_operator(slashn,p1,p2);
  3582. end;
  3583. else
  3584. updatefpos:=false;
  3585. end;
  3586. { get the resultdef for this expression }
  3587. if not assigned(p1.resultdef) and
  3588. dotypecheck then
  3589. do_typecheckpass(p1);
  3590. afterassignment:=oldafterassignment;
  3591. if updatefpos then
  3592. p1.fileinfo:=filepos;
  3593. expr:=p1;
  3594. end;
  3595. function get_intconst:TConstExprInt;
  3596. {Reads an expression, tries to evalute it and check if it is an integer
  3597. constant. Then the constant is returned.}
  3598. var
  3599. p:tnode;
  3600. begin
  3601. result:=0;
  3602. p:=comp_expr(true,false);
  3603. if not codegenerror then
  3604. begin
  3605. if (p.nodetype<>ordconstn) or
  3606. not(is_integer(p.resultdef)) then
  3607. Message(parser_e_illegal_expression)
  3608. else
  3609. result:=tordconstnode(p).value;
  3610. end;
  3611. p.free;
  3612. end;
  3613. function get_stringconst:string;
  3614. {Reads an expression, tries to evaluate it and checks if it is a string
  3615. constant. Then the constant is returned.}
  3616. var
  3617. p:tnode;
  3618. begin
  3619. get_stringconst:='';
  3620. p:=comp_expr(true,false);
  3621. if p.nodetype<>stringconstn then
  3622. begin
  3623. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  3624. get_stringconst:=char(int64(tordconstnode(p).value))
  3625. else
  3626. Message(parser_e_illegal_expression);
  3627. end
  3628. else
  3629. get_stringconst:=strpas(tstringconstnode(p).value_str);
  3630. p.free;
  3631. end;
  3632. end.