pexpr.pas 151 KB

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