pexpr.pas 153 KB

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