pexpr.pas 154 KB

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