pexpr.pas 150 KB

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