pexpr.pas 161 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does parsing of expression for Free Pascal
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pexpr;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symtype,symdef,symbase,
  22. node,ncal,
  23. tokens,globtype,globals,constexp;
  24. { reads a whole expression }
  25. function expr(dotypecheck:boolean) : tnode;
  26. { reads an expression without assignements and .. }
  27. function comp_expr(accept_equal,typeonly:boolean):tnode;
  28. { reads a single factor }
  29. function factor(getaddr,typeonly:boolean) : tnode;
  30. procedure string_dec(var def: tdef; allowtypedef: boolean);
  31. function parse_paras(__colon,__namedpara : boolean;end_of_paras : ttoken) : tnode;
  32. { the ID token has to be consumed before calling this function }
  33. procedure do_member_read(structh:tabstractrecorddef;getaddr:boolean;sym:tsym;var p1:tnode;var again:boolean;callflags:tcallnodeflags);
  34. function get_intconst:TConstExprInt;
  35. function get_stringconst:string;
  36. { Does some postprocessing for a generic type (especially when nested types
  37. of the specialization are used) }
  38. procedure post_comp_expr_gendef(var def: tdef);
  39. implementation
  40. uses
  41. { common }
  42. cutils,
  43. { global }
  44. verbose,
  45. systems,widestr,
  46. { symtable }
  47. symconst,symtable,symsym,symcpu,defutil,defcmp,
  48. { module }
  49. fmodule,ppu,
  50. { pass 1 }
  51. pass_1,htypechk,
  52. nmat,nadd,nmem,nset,ncnv,ninl,ncon,nld,nflw,nbas,nutils,
  53. { parser }
  54. scanner,
  55. pbase,pinline,ptype,pgenutil,procinfo,cpuinfo
  56. ;
  57. function sub_expr(pred_level:Toperator_precedence;accept_equal,typeonly:boolean;factornode:tnode):tnode;forward;
  58. const
  59. { true, if the inherited call is anonymous }
  60. anon_inherited : boolean = false;
  61. { last def found, only used by anon. inherited calls to insert proper type casts }
  62. srdef : tdef = nil;
  63. procedure string_dec(var def:tdef; allowtypedef: boolean);
  64. { reads a string type with optional length }
  65. { and returns a pointer to the string }
  66. { definition }
  67. var
  68. p : tnode;
  69. begin
  70. def:=cshortstringtype;
  71. consume(_STRING);
  72. if token=_LECKKLAMMER then
  73. begin
  74. if not(allowtypedef) then
  75. Message(parser_e_no_local_para_def);
  76. consume(_LECKKLAMMER);
  77. p:=comp_expr(true,false);
  78. if not is_constintnode(p) then
  79. begin
  80. Message(parser_e_illegal_expression);
  81. { error recovery }
  82. consume(_RECKKLAMMER);
  83. end
  84. else
  85. begin
  86. if (tordconstnode(p).value<=0) then
  87. begin
  88. Message(parser_e_invalid_string_size);
  89. tordconstnode(p).value:=255;
  90. end;
  91. if tordconstnode(p).value>255 then
  92. begin
  93. { longstring is currently unsupported (CEC)! }
  94. { t:=cstringdef.createlong(tordconstnode(p).value))}
  95. Message(parser_e_invalid_string_size);
  96. tordconstnode(p).value:=255;
  97. def:=cstringdef.createshort(int64(tordconstnode(p).value));
  98. end
  99. else
  100. if tordconstnode(p).value<>255 then
  101. def:=cstringdef.createshort(int64(tordconstnode(p).value));
  102. consume(_RECKKLAMMER);
  103. end;
  104. p.free;
  105. end
  106. else
  107. begin
  108. if cs_refcountedstrings in current_settings.localswitches then
  109. begin
  110. if m_default_unicodestring in current_settings.modeswitches then
  111. def:=cunicodestringtype
  112. else
  113. def:=getansistringdef
  114. end
  115. else
  116. def:=cshortstringtype;
  117. end;
  118. end;
  119. function parse_paras(__colon,__namedpara : boolean;end_of_paras : ttoken) : tnode;
  120. var
  121. p1,p2,argname : tnode;
  122. prev_in_args,
  123. old_named_args_allowed,
  124. old_allow_array_constructor : boolean;
  125. begin
  126. if token=end_of_paras then
  127. begin
  128. parse_paras:=nil;
  129. exit;
  130. end;
  131. { save old values }
  132. prev_in_args:=in_args;
  133. old_allow_array_constructor:=allow_array_constructor;
  134. old_named_args_allowed:=named_args_allowed;
  135. { set para parsing values }
  136. in_args:=true;
  137. named_args_allowed:=false;
  138. allow_array_constructor:=true;
  139. p2:=nil;
  140. repeat
  141. if __namedpara then
  142. begin
  143. if token=_COMMA then
  144. begin
  145. { empty parameter }
  146. p2:=ccallparanode.create(cnothingnode.create,p2);
  147. end
  148. else
  149. begin
  150. named_args_allowed:=true;
  151. p1:=comp_expr(true,false);
  152. named_args_allowed:=false;
  153. if found_arg_name then
  154. begin
  155. argname:=p1;
  156. p1:=comp_expr(true,false);
  157. p2:=ccallparanode.create(p1,p2);
  158. tcallparanode(p2).parametername:=argname;
  159. end
  160. else
  161. p2:=ccallparanode.create(p1,p2);
  162. found_arg_name:=false;
  163. end;
  164. end
  165. else
  166. begin
  167. p1:=comp_expr(true,false);
  168. p2:=ccallparanode.create(p1,p2);
  169. end;
  170. { it's for the str(l:5,s); }
  171. if __colon and (token=_COLON) then
  172. begin
  173. consume(_COLON);
  174. p1:=comp_expr(true,false);
  175. p2:=ccallparanode.create(p1,p2);
  176. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  177. if try_to_consume(_COLON) then
  178. begin
  179. p1:=comp_expr(true,false);
  180. p2:=ccallparanode.create(p1,p2);
  181. include(tcallparanode(p2).callparaflags,cpf_is_colon_para);
  182. end
  183. end;
  184. until not try_to_consume(_COMMA);
  185. allow_array_constructor:=old_allow_array_constructor;
  186. in_args:=prev_in_args;
  187. named_args_allowed:=old_named_args_allowed;
  188. parse_paras:=p2;
  189. end;
  190. function gen_c_style_operator(ntyp:tnodetype;p1,p2:tnode) : tnode;
  191. var
  192. hp : tnode;
  193. hdef : tdef;
  194. temp : ttempcreatenode;
  195. newstatement : tstatementnode;
  196. begin
  197. { Properties are not allowed, because the write can
  198. be different from the read }
  199. if (nf_isproperty in p1.flags) then
  200. begin
  201. Message(type_e_variable_id_expected);
  202. { We can continue with the loading,
  203. it'll not create errors. Only the expected
  204. result can be wrong }
  205. end;
  206. hp:=p1;
  207. while assigned(hp) and
  208. (hp.nodetype in [derefn,subscriptn,vecn,typeconvn]) do
  209. hp:=tunarynode(hp).left;
  210. if not assigned(hp) then
  211. internalerror(200410121);
  212. if (hp.nodetype=calln) then
  213. begin
  214. typecheckpass(p1);
  215. result:=internalstatements(newstatement);
  216. hdef:=cpointerdef.getreusable(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,nil);
  982. end
  983. else
  984. p1:=ccallnode.create(para,tprocsym(sym),st,p1,callflags,nil);
  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,nil);
  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,false,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,false,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,nil);
  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,true,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_specialize_inline_specialization(var srsym:tsym;out srsymtable:tsymtable):boolean;
  1279. var
  1280. spezdef : tdef;
  1281. begin
  1282. result:=false;
  1283. if not assigned(srsym) then
  1284. message1(sym_e_id_no_member,orgpattern)
  1285. else
  1286. if srsym.typ<>typesym then
  1287. message(type_e_type_id_expected)
  1288. else
  1289. begin
  1290. spezdef:=ttypesym(srsym).typedef;
  1291. generate_specialization(spezdef,false,'');
  1292. if spezdef<>generrordef then
  1293. begin
  1294. srsym:=spezdef.typesym;
  1295. srsymtable:=srsym.owner;
  1296. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1297. result:=true;
  1298. end
  1299. end;
  1300. end;
  1301. function handle_factor_typenode(hdef:tdef;getaddr:boolean;var again:boolean;sym:tsym;typeonly:boolean):tnode;
  1302. var
  1303. srsym : tsym;
  1304. srsymtable : tsymtable;
  1305. isspecialize : boolean;
  1306. begin
  1307. if sym=nil then
  1308. sym:=hdef.typesym;
  1309. { allow Ordinal(Value) for type declarations since it
  1310. can be an enummeration declaration or a set lke:
  1311. (OrdinalType(const1)..OrdinalType(const2) }
  1312. if (not typeonly or is_ordinal(hdef)) and
  1313. try_to_consume(_LKLAMMER) then
  1314. begin
  1315. result:=comp_expr(true,false);
  1316. consume(_RKLAMMER);
  1317. { type casts to class helpers aren't allowed }
  1318. if is_objectpascal_helper(hdef) then
  1319. Message(parser_e_no_category_as_types)
  1320. { recovery by not creating a conversion node }
  1321. else
  1322. result:=ctypeconvnode.create_explicit(result,hdef);
  1323. end
  1324. { not LKLAMMER }
  1325. else if (token=_POINT) and
  1326. (is_object(hdef) or is_record(hdef)) then
  1327. begin
  1328. consume(_POINT);
  1329. { handles calling methods declared in parent objects
  1330. using "parentobject.methodname()" }
  1331. if assigned(current_structdef) and
  1332. not(getaddr) and
  1333. def_is_related(current_structdef,hdef) then
  1334. begin
  1335. result:=ctypenode.create(hdef);
  1336. ttypenode(result).typesym:=sym;
  1337. if not (m_delphi in current_settings.modeswitches) and
  1338. (block_type in [bt_type,bt_var_type,bt_const_type]) and
  1339. (token=_ID) and
  1340. (idtoken=_SPECIALIZE) then
  1341. begin
  1342. consume(_ID);
  1343. if token<>_ID then
  1344. message(type_e_type_id_expected);
  1345. isspecialize:=true;
  1346. end
  1347. else
  1348. isspecialize:=false;
  1349. { search also in inherited methods }
  1350. searchsym_in_class(tobjectdef(hdef),tobjectdef(current_structdef),pattern,srsym,srsymtable,[ssf_search_helper]);
  1351. if isspecialize then
  1352. begin
  1353. consume(_ID);
  1354. if not handle_specialize_inline_specialization(srsym,srsymtable) then
  1355. begin
  1356. result.free;
  1357. result:=cerrornode.create;
  1358. end;
  1359. end
  1360. else
  1361. begin
  1362. if assigned(srsym) then
  1363. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1364. consume(_ID);
  1365. end;
  1366. if result.nodetype<>errorn then
  1367. do_member_read(tabstractrecorddef(hdef),false,srsym,result,again,[]);
  1368. end
  1369. else
  1370. begin
  1371. { handles:
  1372. * @TObject.Load
  1373. * static methods and variables }
  1374. result:=ctypenode.create(hdef);
  1375. ttypenode(result).typesym:=sym;
  1376. if not (m_delphi in current_settings.modeswitches) and
  1377. (block_type in [bt_type,bt_var_type,bt_const_type]) and
  1378. (token=_ID) and
  1379. (idtoken=_SPECIALIZE) then
  1380. begin
  1381. consume(_ID);
  1382. if token<>_ID then
  1383. message(type_e_type_id_expected);
  1384. isspecialize:=true;
  1385. end
  1386. else
  1387. isspecialize:=false;
  1388. { TP allows also @TMenu.Load if Load is only }
  1389. { defined in an anchestor class }
  1390. srsym:=search_struct_member(tabstractrecorddef(hdef),pattern);
  1391. if isspecialize then
  1392. begin
  1393. consume(_ID);
  1394. if not handle_specialize_inline_specialization(srsym,srsymtable) then
  1395. begin
  1396. result.free;
  1397. result:=cerrornode.create;
  1398. end;
  1399. end
  1400. else
  1401. begin
  1402. if assigned(srsym) then
  1403. begin
  1404. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1405. consume(_ID);
  1406. end
  1407. else
  1408. Message1(sym_e_id_no_member,orgpattern);
  1409. end;
  1410. if (result.nodetype<>errorn) and assigned(srsym) then
  1411. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[]);
  1412. end;
  1413. end
  1414. else
  1415. begin
  1416. { Normally here would be the check against the usage
  1417. of "TClassHelper.Something", but as that might be
  1418. used inside of system symbols like sizeof and
  1419. typeinfo this check is put into ttypenode.pass_1
  1420. (for "TClassHelper" alone) and tcallnode.pass_1
  1421. (for "TClassHelper.Something") }
  1422. { class reference ? }
  1423. if is_class(hdef) or
  1424. is_objcclass(hdef) or
  1425. { Java interfaces also can have loadvmtaddrnodes,
  1426. e.g. for expressions such as JLClass(intftype) }
  1427. is_java_class_or_interface(hdef) then
  1428. begin
  1429. if getaddr and (token=_POINT) and
  1430. not is_javainterface(hdef) then
  1431. begin
  1432. consume(_POINT);
  1433. { allows @Object.Method }
  1434. { also allows static methods and variables }
  1435. result:=ctypenode.create(hdef);
  1436. ttypenode(result).typesym:=sym;
  1437. { TP allows also @TMenu.Load if Load is only }
  1438. { defined in an anchestor class }
  1439. srsym:=search_struct_member(tobjectdef(hdef),pattern);
  1440. if assigned(srsym) then
  1441. begin
  1442. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1443. consume(_ID);
  1444. { in case of @Object.Method1.Method2, we have to call
  1445. Method1 -> create a loadvmtaddr node as self instead of
  1446. a typen (the typenode would be changed to self of the
  1447. current method in case Method1 is a constructor, see
  1448. mantis #24844) }
  1449. if not(block_type in [bt_type,bt_const_type,bt_var_type]) and
  1450. (srsym.typ=procsym) and
  1451. (token in [_CARET,_POINT]) then
  1452. result:=cloadvmtaddrnode.create(result);
  1453. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,result,again,[]);
  1454. end
  1455. else
  1456. begin
  1457. Message1(sym_e_id_no_member,orgpattern);
  1458. consume(_ID);
  1459. end;
  1460. end
  1461. else
  1462. begin
  1463. result:=ctypenode.create(hdef);
  1464. ttypenode(result).typesym:=sym;
  1465. { For a type block we simply return only
  1466. the type. For all other blocks we return
  1467. a loadvmt node }
  1468. if not(block_type in [bt_type,bt_const_type,bt_var_type]) then
  1469. result:=cloadvmtaddrnode.create(result);
  1470. end;
  1471. end
  1472. else
  1473. begin
  1474. result:=ctypenode.create(hdef);
  1475. ttypenode(result).typesym:=sym;
  1476. end;
  1477. end;
  1478. end;
  1479. {****************************************************************************
  1480. Factor
  1481. ****************************************************************************}
  1482. function real_const_node_from_pattern(s:string):tnode;
  1483. var
  1484. d : bestreal;
  1485. code : integer;
  1486. cur : currency;
  1487. begin
  1488. val(s,d,code);
  1489. if code<>0 then
  1490. begin
  1491. Message(parser_e_error_in_real);
  1492. d:=1.0;
  1493. end;
  1494. if current_settings.fputype=fpu_none then
  1495. Message(parser_e_unsupported_real);
  1496. if (current_settings.minfpconstprec=s32real) and
  1497. (d = single(d)) then
  1498. result:=crealconstnode.create(d,s32floattype)
  1499. else if (current_settings.minfpconstprec=s64real) and
  1500. (d = double(d)) then
  1501. result:=crealconstnode.create(d,s64floattype)
  1502. else
  1503. result:=crealconstnode.create(d,pbestrealtype^);
  1504. val(pattern,cur,code);
  1505. if code=0 then
  1506. trealconstnode(result).value_currency:=cur;
  1507. end;
  1508. {---------------------------------------------
  1509. PostFixOperators
  1510. ---------------------------------------------}
  1511. { returns whether or not p1 has been changed }
  1512. function postfixoperators(var p1:tnode;var again:boolean;getaddr:boolean): boolean;
  1513. { tries to avoid syntax errors after invalid qualifiers }
  1514. procedure recoverconsume_postfixops;
  1515. begin
  1516. repeat
  1517. if not try_to_consume(_CARET) then
  1518. if try_to_consume(_POINT) then
  1519. try_to_consume(_ID)
  1520. else if try_to_consume(_LECKKLAMMER) then
  1521. begin
  1522. repeat
  1523. comp_expr(true,false);
  1524. until not try_to_consume(_COMMA);
  1525. consume(_RECKKLAMMER);
  1526. end
  1527. else if try_to_consume(_LKLAMMER) then
  1528. begin
  1529. repeat
  1530. comp_expr(true,false);
  1531. until not try_to_consume(_COMMA);
  1532. consume(_RKLAMMER);
  1533. end
  1534. else
  1535. break;
  1536. until false;
  1537. end;
  1538. procedure handle_variantarray;
  1539. var
  1540. p4 : tnode;
  1541. newstatement : tstatementnode;
  1542. tempresultvariant,
  1543. temp : ttempcreatenode;
  1544. paras : tcallparanode;
  1545. newblock : tnode;
  1546. countindices : aint;
  1547. begin
  1548. { create statements with call initialize the arguments and
  1549. call fpc_dynarr_setlength }
  1550. newblock:=internalstatements(newstatement);
  1551. { get temp for array of indicies,
  1552. we set the real size later }
  1553. temp:=ctempcreatenode.create(s32inttype,4,tt_persistent,false);
  1554. addstatement(newstatement,temp);
  1555. countindices:=0;
  1556. repeat
  1557. p4:=comp_expr(true,false);
  1558. addstatement(newstatement,cassignmentnode.create(
  1559. ctemprefnode.create_offset(temp,countindices*s32inttype.size),p4));
  1560. inc(countindices);
  1561. until not try_to_consume(_COMMA);
  1562. { set real size }
  1563. temp.size:=countindices*s32inttype.size;
  1564. consume(_RECKKLAMMER);
  1565. { we need only a write access if a := follows }
  1566. if token=_ASSIGNMENT then
  1567. begin
  1568. consume(_ASSIGNMENT);
  1569. p4:=comp_expr(true,false);
  1570. { create call to fpc_vararray_put }
  1571. paras:=ccallparanode.create(cordconstnode.create
  1572. (countindices,s32inttype,true),
  1573. ccallparanode.create(caddrnode.create_internal
  1574. (ctemprefnode.create(temp)),
  1575. ccallparanode.create(ctypeconvnode.create_internal(p4,cvarianttype),
  1576. ccallparanode.create(ctypeconvnode.create_internal(p1,cvarianttype)
  1577. ,nil))));
  1578. addstatement(newstatement,ccallnode.createintern('fpc_vararray_put',paras));
  1579. addstatement(newstatement,ctempdeletenode.create(temp));
  1580. end
  1581. else
  1582. begin
  1583. { create temp for result }
  1584. tempresultvariant:=ctempcreatenode.create(cvarianttype,cvarianttype.size,tt_persistent,true);
  1585. addstatement(newstatement,tempresultvariant);
  1586. { create call to fpc_vararray_get }
  1587. paras:=ccallparanode.create(cordconstnode.create
  1588. (countindices,s32inttype,true),
  1589. ccallparanode.create(caddrnode.create_internal
  1590. (ctemprefnode.create(temp)),
  1591. ccallparanode.create(p1,
  1592. ccallparanode.create(
  1593. ctemprefnode.create(tempresultvariant)
  1594. ,nil))));
  1595. addstatement(newstatement,ccallnode.createintern('fpc_vararray_get',paras));
  1596. addstatement(newstatement,ctempdeletenode.create(temp));
  1597. { the last statement should return the value as
  1598. location and type, this is done be referencing the
  1599. temp and converting it first from a persistent temp to
  1600. normal temp }
  1601. addstatement(newstatement,ctempdeletenode.create_normal_temp(tempresultvariant));
  1602. addstatement(newstatement,ctemprefnode.create(tempresultvariant));
  1603. end;
  1604. p1:=newblock;
  1605. end;
  1606. function parse_array_constructor(arrdef:tarraydef): tnode;
  1607. var
  1608. newstatement,assstatement:tstatementnode;
  1609. arrnode:ttempcreatenode;
  1610. temp2:ttempcreatenode;
  1611. assnode:tnode;
  1612. paracount:integer;
  1613. begin
  1614. result:=internalstatements(newstatement);
  1615. { create temp for result }
  1616. arrnode:=ctempcreatenode.create(arrdef,arrdef.size,tt_persistent,true);
  1617. addstatement(newstatement,arrnode);
  1618. paracount:=0;
  1619. { check arguments and create an assignment calls }
  1620. if try_to_consume(_LKLAMMER) then
  1621. begin
  1622. assnode:=internalstatements(assstatement);
  1623. repeat
  1624. { arr[i] := param_i }
  1625. addstatement(assstatement,
  1626. cassignmentnode.create(
  1627. cvecnode.create(
  1628. ctemprefnode.create(arrnode),
  1629. cordconstnode.create(paracount,arrdef.rangedef,false)),
  1630. comp_expr(true,false)));
  1631. inc(paracount);
  1632. until not try_to_consume(_COMMA);
  1633. consume(_RKLAMMER);
  1634. end
  1635. else
  1636. assnode:=nil;
  1637. { get temp for array of lengths }
  1638. temp2:=ctempcreatenode.create(sinttype,sinttype.size,tt_persistent,false);
  1639. addstatement(newstatement,temp2);
  1640. { one dimensional }
  1641. addstatement(newstatement,cassignmentnode.create(
  1642. ctemprefnode.create_offset(temp2,0),
  1643. cordconstnode.create
  1644. (paracount,s32inttype,true)));
  1645. { create call to fpc_dynarr_setlength }
  1646. addstatement(newstatement,ccallnode.createintern('fpc_dynarray_setlength',
  1647. ccallparanode.create(caddrnode.create_internal
  1648. (ctemprefnode.create(temp2)),
  1649. ccallparanode.create(cordconstnode.create
  1650. (1,s32inttype,true),
  1651. ccallparanode.create(caddrnode.create_internal
  1652. (crttinode.create(tstoreddef(arrdef),initrtti,rdt_normal)),
  1653. ccallparanode.create(
  1654. ctypeconvnode.create_internal(
  1655. ctemprefnode.create(arrnode),voidpointertype),
  1656. nil))))
  1657. ));
  1658. { add assignment statememnts }
  1659. addstatement(newstatement,ctempdeletenode.create(temp2));
  1660. if assigned(assnode) then
  1661. addstatement(newstatement,assnode);
  1662. { the last statement should return the value as
  1663. location and type, this is done be referencing the
  1664. temp and converting it first from a persistent temp to
  1665. normal temp }
  1666. addstatement(newstatement,ctempdeletenode.create_normal_temp(arrnode));
  1667. addstatement(newstatement,ctemprefnode.create(arrnode));
  1668. end;
  1669. function try_type_helper(var node:tnode;def:tdef):boolean;
  1670. var
  1671. srsym : tsym;
  1672. srsymtable : tsymtable;
  1673. n : tnode;
  1674. newstatement : tstatementnode;
  1675. temp : ttempcreatenode;
  1676. extdef : tdef;
  1677. begin
  1678. result:=false;
  1679. if (token=_ID) and (block_type in [bt_body,bt_general,bt_except,bt_const]) then
  1680. begin
  1681. if not assigned(def) then
  1682. if node.nodetype=addrn then
  1683. { always use the pointer type for addr nodes as otherwise
  1684. we'll have an anonymous pointertype with no name }
  1685. def:=voidpointertype
  1686. else
  1687. def:=node.resultdef;
  1688. result:=search_objectpascal_helper(def,nil,pattern,srsym,srsymtable);
  1689. if result then
  1690. begin
  1691. if not (srsymtable.symtabletype=objectsymtable) or
  1692. not is_objectpascal_helper(tdef(srsymtable.defowner)) then
  1693. internalerror(2013011401);
  1694. { convert const node to temp node of the extended type }
  1695. if node.nodetype in (nodetype_const+[niln,addrn]) then
  1696. begin
  1697. extdef:=tobjectdef(srsymtable.defowner).extendeddef;
  1698. newstatement:=nil;
  1699. n:=internalstatements(newstatement);
  1700. temp:=ctempcreatenode.create(extdef,extdef.size,tt_persistent,false);
  1701. addstatement(newstatement,temp);
  1702. addstatement(newstatement,cassignmentnode.create(ctemprefnode.create(temp),node));
  1703. addstatement(newstatement,ctempdeletenode.create_normal_temp(temp));
  1704. addstatement(newstatement,ctemprefnode.create(temp));
  1705. node:=n;
  1706. do_typecheckpass(node)
  1707. end;
  1708. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  1709. consume(_ID);
  1710. do_member_read(nil,getaddr,srsym,node,again,[]);
  1711. end;
  1712. end;
  1713. end;
  1714. var
  1715. protsym : tpropertysym;
  1716. p2,p3 : tnode;
  1717. srsym : tsym;
  1718. srsymtable : TSymtable;
  1719. structh : tabstractrecorddef;
  1720. { shouldn't be used that often, so the extra overhead is ok to save
  1721. stack space }
  1722. dispatchstring : ansistring;
  1723. erroroutp1,
  1724. allowspecialize,
  1725. isspecialize,
  1726. found,
  1727. haderror,
  1728. nodechanged : boolean;
  1729. calltype: tdispcalltype;
  1730. valstr,expstr : string;
  1731. intval : qword;
  1732. code : integer;
  1733. strdef : tdef;
  1734. label
  1735. skipreckklammercheck,
  1736. skippointdefcheck;
  1737. begin
  1738. result:=false;
  1739. again:=true;
  1740. while again do
  1741. begin
  1742. { we need the resultdef }
  1743. do_typecheckpass_changed(p1,nodechanged);
  1744. result:=result or nodechanged;
  1745. if codegenerror then
  1746. begin
  1747. recoverconsume_postfixops;
  1748. exit;
  1749. end;
  1750. { handle token }
  1751. case token of
  1752. _CARET:
  1753. begin
  1754. consume(_CARET);
  1755. { support tp/mac procvar^ if the procvar returns a
  1756. pointer type }
  1757. if ((m_tp_procvar in current_settings.modeswitches) or
  1758. (m_mac_procvar in current_settings.modeswitches)) and
  1759. (p1.resultdef.typ=procvardef) and
  1760. (tprocvardef(p1.resultdef).returndef.typ=pointerdef) then
  1761. begin
  1762. p1:=ccallnode.create_procvar(nil,p1);
  1763. typecheckpass(p1);
  1764. end;
  1765. { iso file buf access? }
  1766. if (m_iso in current_settings.modeswitches) and
  1767. (p1.resultdef.typ=filedef) then
  1768. begin
  1769. case tfiledef(p1.resultdef).filetyp of
  1770. ft_text:
  1771. begin
  1772. p1:=cderefnode.create(ccallnode.createintern('fpc_getbuf_text',ccallparanode.create(p1,nil)));
  1773. typecheckpass(p1);
  1774. end;
  1775. ft_typed:
  1776. begin
  1777. p1:=cderefnode.create(ctypeconvnode.create_internal(ccallnode.createintern('fpc_getbuf_typedfile',ccallparanode.create(p1,nil)),
  1778. cpointerdef.getreusable(tfiledef(p1.resultdef).typedfiledef)));
  1779. typecheckpass(p1);
  1780. end;
  1781. end;
  1782. end
  1783. else if (p1.resultdef.typ<>pointerdef) then
  1784. begin
  1785. { ^ as binary operator is a problem!!!! (FK) }
  1786. again:=false;
  1787. Message(parser_e_invalid_qualifier);
  1788. recoverconsume_postfixops;
  1789. p1.destroy;
  1790. p1:=cerrornode.create;
  1791. end
  1792. else
  1793. p1:=cderefnode.create(p1);
  1794. end;
  1795. _LECKKLAMMER:
  1796. begin
  1797. if is_class_or_interface_or_object(p1.resultdef) or
  1798. is_dispinterface(p1.resultdef) or
  1799. is_record(p1.resultdef) or
  1800. is_javaclass(p1.resultdef) then
  1801. begin
  1802. { default property }
  1803. protsym:=search_default_property(tabstractrecorddef(p1.resultdef));
  1804. if not(assigned(protsym)) then
  1805. begin
  1806. p1.destroy;
  1807. p1:=cerrornode.create;
  1808. again:=false;
  1809. message(parser_e_no_default_property_available);
  1810. end
  1811. else
  1812. begin
  1813. { The property symbol is referenced indirect }
  1814. protsym.IncRefCount;
  1815. handle_propertysym(protsym,protsym.owner,p1);
  1816. end;
  1817. end
  1818. else
  1819. begin
  1820. consume(_LECKKLAMMER);
  1821. repeat
  1822. { in all of the cases below, p1 is changed }
  1823. case p1.resultdef.typ of
  1824. pointerdef:
  1825. begin
  1826. { support delphi autoderef }
  1827. if (tpointerdef(p1.resultdef).pointeddef.typ=arraydef) and
  1828. (m_autoderef in current_settings.modeswitches) then
  1829. p1:=cderefnode.create(p1);
  1830. p2:=comp_expr(true,false);
  1831. { Support Pbytevar[0..9] which returns array [0..9].}
  1832. if try_to_consume(_POINTPOINT) then
  1833. p2:=crangenode.create(p2,comp_expr(true,false));
  1834. p1:=cvecnode.create(p1,p2);
  1835. end;
  1836. variantdef:
  1837. begin
  1838. handle_variantarray;
  1839. { the RECKKLAMMER is already read }
  1840. goto skipreckklammercheck;
  1841. end;
  1842. stringdef :
  1843. begin
  1844. p2:=comp_expr(true,false);
  1845. { Support string[0..9] which returns array [0..9] of char.}
  1846. if try_to_consume(_POINTPOINT) then
  1847. p2:=crangenode.create(p2,comp_expr(true,false));
  1848. p1:=cvecnode.create(p1,p2);
  1849. end;
  1850. arraydef:
  1851. begin
  1852. p2:=comp_expr(true,false);
  1853. { support SEG:OFS for go32v2/msdos Mem[] }
  1854. if (target_info.system in [system_i386_go32v2,system_i386_watcom,system_i8086_msdos,system_i8086_win16]) and
  1855. (p1.nodetype=loadn) and
  1856. assigned(tloadnode(p1).symtableentry) and
  1857. assigned(tloadnode(p1).symtableentry.owner.name) and
  1858. (tloadnode(p1).symtableentry.owner.name^='SYSTEM') and
  1859. ((tloadnode(p1).symtableentry.name='MEM') or
  1860. (tloadnode(p1).symtableentry.name='MEMW') or
  1861. (tloadnode(p1).symtableentry.name='MEML')) then
  1862. begin
  1863. {$if defined(i8086)}
  1864. consume(_COLON);
  1865. inserttypeconv(p2,u16inttype);
  1866. inserttypeconv_internal(p2,u32inttype);
  1867. p3:=cshlshrnode.create(shln,p2,cordconstnode.create($10,s16inttype,false));
  1868. p2:=comp_expr(true,false);
  1869. inserttypeconv(p2,u16inttype);
  1870. inserttypeconv_internal(p2,u32inttype);
  1871. p2:=caddnode.create(addn,p2,p3);
  1872. case tloadnode(p1).symtableentry.name of
  1873. 'MEM': p2:=ctypeconvnode.create_internal(p2,bytefarpointertype);
  1874. 'MEMW': p2:=ctypeconvnode.create_internal(p2,wordfarpointertype);
  1875. 'MEML': p2:=ctypeconvnode.create_internal(p2,longintfarpointertype);
  1876. else
  1877. internalerror(2013053102);
  1878. end;
  1879. p1:=cderefnode.create(p2);
  1880. {$elseif defined(i386)}
  1881. if try_to_consume(_COLON) then
  1882. begin
  1883. p3:=caddnode.create(muln,cordconstnode.create($10,s32inttype,false),p2);
  1884. p2:=comp_expr(true,false);
  1885. p2:=caddnode.create(addn,p2,p3);
  1886. if try_to_consume(_POINTPOINT) then
  1887. { Support mem[$a000:$0000..$07ff] which returns array [0..$7ff] of memtype.}
  1888. p2:=crangenode.create(p2,caddnode.create(addn,comp_expr(true,false),p3.getcopy));
  1889. p1:=cvecnode.create(p1,p2);
  1890. include(tvecnode(p1).flags,nf_memseg);
  1891. include(tvecnode(p1).flags,nf_memindex);
  1892. end
  1893. else
  1894. begin
  1895. if try_to_consume(_POINTPOINT) then
  1896. { Support mem[$80000000..$80000002] which returns array [0..2] of memtype.}
  1897. p2:=crangenode.create(p2,comp_expr(true,false));
  1898. p1:=cvecnode.create(p1,p2);
  1899. include(tvecnode(p1).flags,nf_memindex);
  1900. end;
  1901. {$else}
  1902. internalerror(2013053101);
  1903. {$endif}
  1904. end
  1905. else
  1906. begin
  1907. if try_to_consume(_POINTPOINT) then
  1908. { Support arrayvar[0..9] which returns array [0..9] of arraytype.}
  1909. p2:=crangenode.create(p2,comp_expr(true,false));
  1910. p1:=cvecnode.create(p1,p2);
  1911. end;
  1912. end;
  1913. else
  1914. begin
  1915. if p1.resultdef.typ<>undefineddef then
  1916. Message(parser_e_invalid_qualifier);
  1917. p1.destroy;
  1918. p1:=cerrornode.create;
  1919. comp_expr(true,false);
  1920. again:=false;
  1921. end;
  1922. end;
  1923. do_typecheckpass(p1);
  1924. until not try_to_consume(_COMMA);
  1925. consume(_RECKKLAMMER);
  1926. { handle_variantarray eats the RECKKLAMMER and jumps here }
  1927. skipreckklammercheck:
  1928. end;
  1929. end;
  1930. _POINT :
  1931. begin
  1932. consume(_POINT);
  1933. allowspecialize:=not (m_delphi in current_settings.modeswitches) and (block_type in [bt_type,bt_var_type,bt_const_type]);
  1934. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  1935. begin
  1936. //consume(_ID);
  1937. isspecialize:=true;
  1938. end
  1939. else
  1940. isspecialize:=false;
  1941. if (p1.resultdef.typ=pointerdef) and
  1942. (m_autoderef in current_settings.modeswitches) and
  1943. { don't auto-deref objc.id, because then the code
  1944. below for supporting id.anyobjcmethod isn't triggered }
  1945. (p1.resultdef<>objc_idtype) then
  1946. begin
  1947. p1:=cderefnode.create(p1);
  1948. do_typecheckpass(p1);
  1949. end;
  1950. { procvar.<something> can never mean anything so always
  1951. try to call it in case it returns a record/object/... }
  1952. maybe_call_procvar(p1,false);
  1953. if (p1.nodetype=ordconstn) and
  1954. not is_boolean(p1.resultdef) and
  1955. not is_enum(p1.resultdef) then
  1956. begin
  1957. { type helpers are checked first }
  1958. if (token=_ID) and try_type_helper(p1,nil) then
  1959. goto skippointdefcheck;
  1960. { only an "e" or "E" can follow an intconst with a ".", the
  1961. other case (another intconst) is handled by the scanner }
  1962. if (token=_ID) and (pattern[1]='E') then
  1963. begin
  1964. haderror:=false;
  1965. if length(pattern)>1 then
  1966. begin
  1967. expstr:=copy(pattern,2,length(pattern)-1);
  1968. val(expstr,intval,code);
  1969. if code<>0 then
  1970. begin
  1971. haderror:=true;
  1972. intval:=intval; // Hackfix the "var assigned but never used" note.
  1973. end;
  1974. end
  1975. else
  1976. expstr:='';
  1977. consume(token);
  1978. if tordconstnode(p1).value.signed then
  1979. str(tordconstnode(p1).value.svalue,valstr)
  1980. else
  1981. str(tordconstnode(p1).value.uvalue,valstr);
  1982. valstr:=valstr+'.0E';
  1983. if expstr='' then
  1984. case token of
  1985. _MINUS:
  1986. begin
  1987. consume(token);
  1988. if token=_INTCONST then
  1989. begin
  1990. valstr:=valstr+'-'+pattern;
  1991. consume(token);
  1992. end
  1993. else
  1994. haderror:=true;
  1995. end;
  1996. _PLUS:
  1997. begin
  1998. consume(token);
  1999. if token=_INTCONST then
  2000. begin
  2001. valstr:=valstr+pattern;
  2002. consume(token);
  2003. end
  2004. else
  2005. haderror:=true;
  2006. end;
  2007. _INTCONST:
  2008. begin
  2009. valstr:=valstr+pattern;
  2010. consume(_INTCONST);
  2011. end;
  2012. else
  2013. haderror:=true;
  2014. end
  2015. else
  2016. valstr:=valstr+expstr;
  2017. if haderror then
  2018. begin
  2019. Message(parser_e_error_in_real);
  2020. p2:=cerrornode.create;
  2021. end
  2022. else
  2023. p2:=real_const_node_from_pattern(valstr);
  2024. p1.free;
  2025. p1:=p2;
  2026. again:=false;
  2027. goto skippointdefcheck;
  2028. end
  2029. else
  2030. begin
  2031. { just convert the ordconst to a realconst }
  2032. p2:=crealconstnode.create(tordconstnode(p1).value,pbestrealtype^);
  2033. p1.free;
  2034. p1:=p2;
  2035. again:=false;
  2036. goto skippointdefcheck;
  2037. end;
  2038. end;
  2039. if (p1.nodetype=stringconstn) and (token=_ID) then
  2040. begin
  2041. { the def of a string const is an array }
  2042. case tstringconstnode(p1).cst_type of
  2043. cst_conststring:
  2044. if cs_refcountedstrings in current_settings.localswitches then
  2045. if m_default_unicodestring in current_settings.modeswitches then
  2046. strdef:=cunicodestringtype
  2047. else
  2048. strdef:=cansistringtype
  2049. else
  2050. strdef:=cshortstringtype;
  2051. cst_shortstring:
  2052. strdef:=cshortstringtype;
  2053. cst_ansistring:
  2054. { use getansistringdef? }
  2055. strdef:=cansistringtype;
  2056. cst_widestring:
  2057. strdef:=cwidestringtype;
  2058. cst_unicodestring:
  2059. strdef:=cunicodestringtype;
  2060. cst_longstring:
  2061. { let's see when someone stumbles upon this...}
  2062. internalerror(201301111);
  2063. else
  2064. internalerror(2013112903);
  2065. end;
  2066. if try_type_helper(p1,strdef) then
  2067. goto skippointdefcheck;
  2068. end;
  2069. { this is skipped if label skippointdefcheck is used }
  2070. case p1.resultdef.typ of
  2071. recorddef:
  2072. begin
  2073. if isspecialize or (token=_ID) then
  2074. begin
  2075. erroroutp1:=true;
  2076. srsym:=nil;
  2077. structh:=tabstractrecorddef(p1.resultdef);
  2078. if isspecialize then
  2079. begin
  2080. { consume the specialize }
  2081. consume(_ID);
  2082. if token<>_ID then
  2083. consume(_ID)
  2084. else
  2085. begin
  2086. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2087. consume(_ID);
  2088. if handle_specialize_inline_specialization(srsym,srsymtable) then
  2089. erroroutp1:=false;
  2090. end;
  2091. end
  2092. else
  2093. begin
  2094. searchsym_in_record(structh,pattern,srsym,srsymtable);
  2095. if assigned(srsym) then
  2096. begin
  2097. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2098. consume(_ID);
  2099. erroroutp1:=false;
  2100. end
  2101. else
  2102. begin
  2103. Message1(sym_e_id_no_member,orgpattern);
  2104. { try to clean up }
  2105. consume(_ID);
  2106. end;
  2107. end;
  2108. if erroroutp1 then
  2109. begin
  2110. p1.free;
  2111. p1:=cerrornode.create;
  2112. end
  2113. else
  2114. do_member_read(structh,getaddr,srsym,p1,again,[]);
  2115. end
  2116. else
  2117. consume(_ID);
  2118. end;
  2119. enumdef:
  2120. begin
  2121. if token=_ID then
  2122. begin
  2123. srsym:=tsym(tenumdef(p1.resultdef).symtable.Find(pattern));
  2124. if assigned(srsym) and (srsym.typ=enumsym) and (p1.nodetype=typen) then
  2125. begin
  2126. p1.destroy;
  2127. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2128. p1:=genenumnode(tenumsym(srsym));
  2129. consume(_ID);
  2130. end
  2131. else
  2132. if not try_type_helper(p1,nil) then
  2133. begin
  2134. p1.destroy;
  2135. Message1(sym_e_id_no_member,orgpattern);
  2136. p1:=cerrornode.create;
  2137. consume(_ID);
  2138. end;
  2139. end;
  2140. end;
  2141. arraydef:
  2142. begin
  2143. if is_dynamic_array(p1.resultdef) then
  2144. begin
  2145. if (token=_ID) and not try_type_helper(p1,nil) then
  2146. begin
  2147. if pattern='CREATE' then
  2148. begin
  2149. consume(_ID);
  2150. p2:=parse_array_constructor(tarraydef(p1.resultdef));
  2151. p1.destroy;
  2152. p1:=p2;
  2153. end
  2154. else
  2155. begin
  2156. Message2(scan_f_syn_expected,'CREATE',pattern);
  2157. p1.destroy;
  2158. p1:=cerrornode.create;
  2159. consume(_ID);
  2160. end;
  2161. end;
  2162. end
  2163. else
  2164. begin
  2165. Message(parser_e_invalid_qualifier);
  2166. p1.destroy;
  2167. p1:=cerrornode.create;
  2168. consume(_ID);
  2169. end;
  2170. end;
  2171. variantdef:
  2172. begin
  2173. { dispatch call? }
  2174. { lhs := v.ident[parameters] -> property get
  2175. lhs := v.ident(parameters) -> method call
  2176. v.ident[parameters] := rhs -> property put
  2177. v.ident(parameters) := rhs -> also property put }
  2178. if token=_ID then
  2179. begin
  2180. if not try_type_helper(p1,nil) then
  2181. begin
  2182. dispatchstring:=orgpattern;
  2183. consume(_ID);
  2184. calltype:=dct_method;
  2185. if try_to_consume(_LKLAMMER) then
  2186. begin
  2187. p2:=parse_paras(false,true,_RKLAMMER);
  2188. consume(_RKLAMMER);
  2189. end
  2190. else if try_to_consume(_LECKKLAMMER) then
  2191. begin
  2192. p2:=parse_paras(false,true,_RECKKLAMMER);
  2193. consume(_RECKKLAMMER);
  2194. calltype:=dct_propget;
  2195. end
  2196. else
  2197. p2:=nil;
  2198. { property setter? }
  2199. if (token=_ASSIGNMENT) and not(afterassignment) then
  2200. begin
  2201. consume(_ASSIGNMENT);
  2202. { read the expression }
  2203. p3:=comp_expr(true,false);
  2204. { concat value parameter too }
  2205. p2:=ccallparanode.create(p3,p2);
  2206. p1:=translate_disp_call(p1,p2,dct_propput,dispatchstring,0,voidtype);
  2207. end
  2208. else
  2209. { this is only an approximation
  2210. setting useresult if not necessary is only a waste of time, no more, no less (FK) }
  2211. if afterassignment or in_args or (token<>_SEMICOLON) then
  2212. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,cvarianttype)
  2213. else
  2214. p1:=translate_disp_call(p1,p2,calltype,dispatchstring,0,voidtype);
  2215. end;
  2216. end
  2217. else { Error }
  2218. Consume(_ID);
  2219. end;
  2220. classrefdef:
  2221. begin
  2222. if token=_ID then
  2223. begin
  2224. structh:=tobjectdef(tclassrefdef(p1.resultdef).pointeddef);
  2225. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2226. if assigned(srsym) then
  2227. begin
  2228. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2229. consume(_ID);
  2230. do_member_read(structh,getaddr,srsym,p1,again,[]);
  2231. end
  2232. else
  2233. begin
  2234. Message1(sym_e_id_no_member,orgpattern);
  2235. p1.destroy;
  2236. p1:=cerrornode.create;
  2237. { try to clean up }
  2238. consume(_ID);
  2239. end;
  2240. end
  2241. else { Error }
  2242. Consume(_ID);
  2243. end;
  2244. objectdef:
  2245. begin
  2246. if isspecialize or (token=_ID) then
  2247. begin
  2248. erroroutp1:=true;
  2249. srsym:=nil;
  2250. structh:=tobjectdef(p1.resultdef);
  2251. if isspecialize then
  2252. begin
  2253. { consume the "specialize" }
  2254. consume(_ID);
  2255. if token<>_ID then
  2256. consume(_ID)
  2257. else
  2258. begin
  2259. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2260. consume(_ID);
  2261. if handle_specialize_inline_specialization(srsym,srsymtable) then
  2262. erroroutp1:=false;
  2263. end;
  2264. end
  2265. else
  2266. begin
  2267. searchsym_in_class(tobjectdef(structh),tobjectdef(structh),pattern,srsym,srsymtable,[ssf_search_helper]);
  2268. if assigned(srsym) then
  2269. begin
  2270. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2271. consume(_ID);
  2272. erroroutp1:=false;
  2273. end
  2274. else
  2275. begin
  2276. Message1(sym_e_id_no_member,orgpattern);
  2277. { try to clean up }
  2278. consume(_ID);
  2279. end;
  2280. end;
  2281. if erroroutp1 then
  2282. begin
  2283. p1.free;
  2284. p1:=cerrornode.create;
  2285. end
  2286. else
  2287. do_member_read(structh,getaddr,srsym,p1,again,[]);
  2288. end
  2289. else { Error }
  2290. Consume(_ID);
  2291. end;
  2292. pointerdef:
  2293. begin
  2294. if (p1.resultdef=objc_idtype) then
  2295. begin
  2296. { objc's id type can be used to call any
  2297. Objective-C method of any Objective-C class
  2298. type that's currently in scope }
  2299. if search_objc_method(pattern,srsym,srsymtable) then
  2300. begin
  2301. consume(_ID);
  2302. do_proc_call(srsym,srsymtable,nil,
  2303. (getaddr and not(token in [_CARET,_POINT])),
  2304. again,p1,[cnf_objc_id_call]);
  2305. { we need to know which procedure is called }
  2306. do_typecheckpass(p1);
  2307. end
  2308. else
  2309. begin
  2310. consume(_ID);
  2311. Message(parser_e_methode_id_expected);
  2312. end;
  2313. end
  2314. else
  2315. begin
  2316. if not try_type_helper(p1,nil) then
  2317. begin
  2318. Message(parser_e_invalid_qualifier);
  2319. if tpointerdef(p1.resultdef).pointeddef.typ in [recorddef,objectdef,classrefdef] then
  2320. Message(parser_h_maybe_deref_caret_missing);
  2321. end;
  2322. end
  2323. end;
  2324. else
  2325. begin
  2326. found:=try_type_helper(p1,nil);
  2327. if not found then
  2328. begin
  2329. if p1.resultdef.typ<>undefineddef then
  2330. Message(parser_e_invalid_qualifier);
  2331. p1.destroy;
  2332. p1:=cerrornode.create;
  2333. { Error }
  2334. consume(_ID);
  2335. end;
  2336. end;
  2337. end;
  2338. { processing an ordconstnode avoids the resultdef check }
  2339. skippointdefcheck:
  2340. end;
  2341. else
  2342. begin
  2343. { is this a procedure variable ? }
  2344. if assigned(p1.resultdef) and
  2345. (p1.resultdef.typ=procvardef) then
  2346. begin
  2347. { Typenode for typecasting or expecting a procvar }
  2348. if (p1.nodetype=typen) or
  2349. (
  2350. assigned(getprocvardef) and
  2351. equal_defs(p1.resultdef,getprocvardef)
  2352. ) then
  2353. begin
  2354. if try_to_consume(_LKLAMMER) then
  2355. begin
  2356. p1:=comp_expr(true,false);
  2357. consume(_RKLAMMER);
  2358. p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
  2359. end
  2360. else
  2361. again:=false
  2362. end
  2363. else
  2364. begin
  2365. if try_to_consume(_LKLAMMER) then
  2366. begin
  2367. p2:=parse_paras(false,false,_RKLAMMER);
  2368. consume(_RKLAMMER);
  2369. p1:=ccallnode.create_procvar(p2,p1);
  2370. { proc():= is never possible }
  2371. if token=_ASSIGNMENT then
  2372. begin
  2373. Message(parser_e_illegal_expression);
  2374. p1.free;
  2375. p1:=cerrornode.create;
  2376. again:=false;
  2377. end;
  2378. end
  2379. else
  2380. again:=false;
  2381. end;
  2382. end
  2383. else
  2384. again:=false;
  2385. end;
  2386. end;
  2387. { we only try again if p1 was changed }
  2388. if again or
  2389. (p1.nodetype=errorn) then
  2390. result:=true;
  2391. end; { while again }
  2392. end;
  2393. function is_member_read(sym: tsym; st: tsymtable; var p1: tnode;
  2394. out memberparentdef: tdef): boolean;
  2395. var
  2396. hdef : tdef;
  2397. begin
  2398. result:=true;
  2399. memberparentdef:=nil;
  2400. case st.symtabletype of
  2401. ObjectSymtable,
  2402. recordsymtable:
  2403. begin
  2404. memberparentdef:=tdef(st.defowner);
  2405. exit;
  2406. end;
  2407. WithSymtable:
  2408. begin
  2409. if assigned(p1) then
  2410. internalerror(2007012002);
  2411. hdef:=tnode(twithsymtable(st).withrefnode).resultdef;
  2412. p1:=tnode(twithsymtable(st).withrefnode).getcopy;
  2413. if not(hdef.typ in [objectdef,classrefdef]) then
  2414. exit;
  2415. if (hdef.typ=classrefdef) then
  2416. hdef:=tclassrefdef(hdef).pointeddef;
  2417. memberparentdef:=hdef;
  2418. end;
  2419. else
  2420. result:=false;
  2421. end;
  2422. end;
  2423. {$maxfpuregisters 0}
  2424. function factor(getaddr,typeonly:boolean) : tnode;
  2425. {---------------------------------------------
  2426. Factor_read_id
  2427. ---------------------------------------------}
  2428. procedure factor_read_id(out p1:tnode;var again:boolean);
  2429. function findwithsymtable : boolean;
  2430. var
  2431. hp : psymtablestackitem;
  2432. begin
  2433. result:=true;
  2434. hp:=symtablestack.stack;
  2435. while assigned(hp) do
  2436. begin
  2437. if hp^.symtable.symtabletype=withsymtable then
  2438. exit;
  2439. hp:=hp^.next;
  2440. end;
  2441. result:=false;
  2442. end;
  2443. var
  2444. srsym: tsym;
  2445. srsymtable: TSymtable;
  2446. hdef: tdef;
  2447. pd: tprocdef;
  2448. orgstoredpattern,
  2449. storedpattern: string;
  2450. callflags: tcallnodeflags;
  2451. t : ttoken;
  2452. allowspecialize,
  2453. isspecialize,
  2454. unit_found : boolean;
  2455. tokenpos: tfileposinfo;
  2456. begin
  2457. { allow post fix operators }
  2458. again:=true;
  2459. { preinitalize tokenpos }
  2460. tokenpos:=current_filepos;
  2461. p1:=nil;
  2462. allowspecialize:=not (m_delphi in current_settings.modeswitches) and (block_type in [bt_type,bt_var_type,bt_const_type]);
  2463. if allowspecialize and (token=_ID) and (idtoken=_SPECIALIZE) then
  2464. begin
  2465. consume(_ID);
  2466. isspecialize:=true;
  2467. end
  2468. else
  2469. isspecialize:=false;
  2470. { first check for identifier }
  2471. if token<>_ID then
  2472. begin
  2473. srsym:=generrorsym;
  2474. srsymtable:=nil;
  2475. consume(_ID);
  2476. unit_found:=false;
  2477. end
  2478. else
  2479. begin
  2480. if typeonly then
  2481. searchsym_type(pattern,srsym,srsymtable)
  2482. else
  2483. searchsym(pattern,srsym,srsymtable);
  2484. { handle unit specification like System.Writeln }
  2485. if not isspecialize then
  2486. unit_found:=try_consume_unitsym(srsym,srsymtable,t,true,allowspecialize,isspecialize)
  2487. else
  2488. begin
  2489. unit_found:=false;
  2490. t:=_ID;
  2491. end;
  2492. storedpattern:=pattern;
  2493. orgstoredpattern:=orgpattern;
  2494. { store the position of the token before consuming it }
  2495. tokenpos:=current_filepos;
  2496. consume(t);
  2497. { named parameter support }
  2498. found_arg_name:=false;
  2499. if not(unit_found) and
  2500. not isspecialize and
  2501. named_args_allowed and
  2502. (token=_ASSIGNMENT) then
  2503. begin
  2504. found_arg_name:=true;
  2505. p1:=cstringconstnode.createstr(storedpattern);
  2506. consume(_ASSIGNMENT);
  2507. exit;
  2508. end;
  2509. if isspecialize then
  2510. begin
  2511. if not assigned(srsym) or
  2512. (srsym.typ<>typesym) then
  2513. begin
  2514. identifier_not_found(orgstoredpattern,tokenpos);
  2515. srsym:=generrorsym;
  2516. srsymtable:=nil;
  2517. end
  2518. else
  2519. begin
  2520. hdef:=ttypesym(srsym).typedef;
  2521. generate_specialization(hdef,false,'');
  2522. if hdef=generrordef then
  2523. begin
  2524. srsym:=generrorsym;
  2525. srsymtable:=nil;
  2526. end
  2527. else
  2528. begin
  2529. srsym:=hdef.typesym;
  2530. srsymtable:=srsym.owner;
  2531. end;
  2532. end;
  2533. end;
  2534. { check hints, but only if it isn't a potential generic symbol;
  2535. that is checked in sub_expr if it isn't a generic }
  2536. if assigned(srsym) and
  2537. not (
  2538. (srsym.typ=typesym) and
  2539. (ttypesym(srsym).typedef.typ in [recorddef,objectdef,arraydef,procvardef,undefineddef]) and
  2540. not (sp_generic_para in srsym.symoptions) and
  2541. (token in [_LT, _LSHARPBRACKET])
  2542. ) then
  2543. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  2544. { if nothing found give error and return errorsym }
  2545. if not assigned(srsym) or
  2546. { is this a generic dummy symbol? }
  2547. ((srsym.typ=typesym) and
  2548. assigned(ttypesym(srsym).typedef) and
  2549. (ttypesym(srsym).typedef.typ=undefineddef) and
  2550. not (sp_generic_para in srsym.symoptions) and
  2551. not (token in [_LT, _LSHARPBRACKET]) and
  2552. not (
  2553. { in non-Delphi modes the generic class' name without a
  2554. "specialization" or "<T>" may be used to identify the
  2555. current class }
  2556. (sp_generic_dummy in srsym.symoptions) and
  2557. assigned(current_structdef) and
  2558. (df_generic in current_structdef.defoptions) and
  2559. not (m_delphi in current_settings.modeswitches) and
  2560. assigned(get_generic_in_hierarchy_by_name(srsym,current_structdef))
  2561. )) and
  2562. { it could be a rename of a generic para }
  2563. { Note: if this generates false positives we'll need to
  2564. include a "basesym" to tsym to track the original
  2565. symbol }
  2566. not (sp_explicitrename in srsym.symoptions) then
  2567. begin
  2568. { if a generic is parsed and when we are inside an with block,
  2569. a symbol might not be defined }
  2570. if assigned(current_procinfo) and (df_generic in current_procinfo.procdef.defoptions) and
  2571. findwithsymtable then
  2572. begin
  2573. { create dummy symbol, it will be freed later on }
  2574. srsym:=tsym.create(undefinedsym,'$undefinedsym');
  2575. srsymtable:=nil;
  2576. end
  2577. else
  2578. begin
  2579. identifier_not_found(orgstoredpattern,tokenpos);
  2580. srsym:=generrorsym;
  2581. srsymtable:=nil;
  2582. end;
  2583. end;
  2584. end;
  2585. { Access to funcret or need to call the function? }
  2586. if (srsym.typ in [absolutevarsym,localvarsym,paravarsym]) and
  2587. (vo_is_funcret in tabstractvarsym(srsym).varoptions) and
  2588. { result(x) is not allowed }
  2589. not(vo_is_result in tabstractvarsym(srsym).varoptions) and
  2590. (
  2591. (token=_LKLAMMER) or
  2592. (
  2593. (([m_tp7,m_delphi,m_mac,m_iso] * current_settings.modeswitches) <> []) and
  2594. (afterassignment or in_args)
  2595. )
  2596. ) then
  2597. begin
  2598. hdef:=tdef(srsym.owner.defowner);
  2599. if assigned(hdef) and
  2600. (hdef.typ=procdef) then
  2601. srsym:=tprocdef(hdef).procsym
  2602. else
  2603. begin
  2604. Message(parser_e_illegal_expression);
  2605. srsym:=generrorsym;
  2606. end;
  2607. srsymtable:=srsym.owner;
  2608. end;
  2609. begin
  2610. case srsym.typ of
  2611. absolutevarsym :
  2612. begin
  2613. if (tabsolutevarsym(srsym).abstyp=tovar) then
  2614. begin
  2615. p1:=nil;
  2616. propaccesslist_to_node(p1,nil,tabsolutevarsym(srsym).ref);
  2617. p1:=ctypeconvnode.create(p1,tabsolutevarsym(srsym).vardef);
  2618. include(p1.flags,nf_absolute);
  2619. end
  2620. else
  2621. p1:=cloadnode.create(srsym,srsymtable);
  2622. end;
  2623. staticvarsym,
  2624. localvarsym,
  2625. paravarsym,
  2626. fieldvarsym :
  2627. begin
  2628. { check if we are reading a field of an object/class/ }
  2629. { record. is_member_read() will deal with withsymtables }
  2630. { if needed. }
  2631. p1:=nil;
  2632. if is_member_read(srsym,srsymtable,p1,hdef) then
  2633. begin
  2634. { if the field was originally found in an }
  2635. { objectsymtable, it means it's part of self }
  2636. { if only method from which it was called is }
  2637. { not class static }
  2638. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2639. { if we are accessing a owner procsym from the nested }
  2640. { class we need to call it as a class member }
  2641. if assigned(current_structdef) and
  2642. (((current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  2643. (sp_static in srsym.symoptions)) then
  2644. if srsymtable.symtabletype=recordsymtable then
  2645. p1:=ctypenode.create(hdef)
  2646. else
  2647. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2648. else
  2649. begin
  2650. if assigned(current_procinfo) then
  2651. begin
  2652. pd:=current_procinfo.get_normal_proc.procdef;
  2653. if assigned(pd) and pd.no_self_node then
  2654. p1:=cloadvmtaddrnode.create(ctypenode.create(pd.struct))
  2655. else
  2656. p1:=load_self_node;
  2657. end
  2658. else
  2659. p1:=load_self_node;
  2660. end;
  2661. { now, if the field itself is part of an objectsymtab }
  2662. { (it can be even if it was found in a withsymtable, }
  2663. { e.g., "with classinstance do field := 5"), then }
  2664. { let do_member_read handle it }
  2665. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2666. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2667. else
  2668. { otherwise it's a regular record subscript }
  2669. p1:=csubscriptnode.create(srsym,p1);
  2670. end
  2671. else
  2672. { regular non-field load }
  2673. p1:=cloadnode.create(srsym,srsymtable);
  2674. end;
  2675. syssym :
  2676. begin
  2677. p1:=statement_syssym(tsyssym(srsym).number);
  2678. end;
  2679. typesym :
  2680. begin
  2681. hdef:=ttypesym(srsym).typedef;
  2682. if not assigned(hdef) then
  2683. begin
  2684. again:=false;
  2685. end
  2686. else
  2687. begin
  2688. { We need to know if this unit uses Variants }
  2689. if ((hdef=cvarianttype) or (hdef=colevarianttype)) and
  2690. not(cs_compilesystem in current_settings.moduleswitches) then
  2691. current_module.flags:=current_module.flags or uf_uses_variants;
  2692. p1:=handle_factor_typenode(hdef,getaddr,again,srsym,typeonly);
  2693. end;
  2694. end;
  2695. enumsym :
  2696. begin
  2697. p1:=genenumnode(tenumsym(srsym));
  2698. end;
  2699. constsym :
  2700. begin
  2701. if tconstsym(srsym).consttyp=constresourcestring then
  2702. begin
  2703. p1:=cloadnode.create(srsym,srsymtable);
  2704. do_typecheckpass(p1);
  2705. p1.resultdef:=getansistringdef;
  2706. end
  2707. else
  2708. p1:=genconstsymtree(tconstsym(srsym));
  2709. end;
  2710. procsym :
  2711. begin
  2712. p1:=nil;
  2713. { check if it's a method/class method }
  2714. if is_member_read(srsym,srsymtable,p1,hdef) then
  2715. begin
  2716. { if we are accessing a owner procsym from the nested }
  2717. { class we need to call it as a class member }
  2718. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) and
  2719. assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef) then
  2720. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef));
  2721. { not srsymtable.symtabletype since that can be }
  2722. { withsymtable as well }
  2723. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2724. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2725. else
  2726. { no procsyms in records (yet) }
  2727. internalerror(2007012006);
  2728. end
  2729. else
  2730. begin
  2731. { regular procedure/function call }
  2732. if not unit_found then
  2733. callflags:=[]
  2734. else
  2735. callflags:=[cnf_unit_specified];
  2736. do_proc_call(srsym,srsymtable,nil,
  2737. (getaddr and not(token in [_CARET,_POINT,_LECKKLAMMER])),
  2738. again,p1,callflags);
  2739. end;
  2740. end;
  2741. propertysym :
  2742. begin
  2743. p1:=nil;
  2744. { property of a class/object? }
  2745. if is_member_read(srsym,srsymtable,p1,hdef) then
  2746. begin
  2747. if (srsymtable.symtabletype in [ObjectSymtable,recordsymtable]) then
  2748. { if we are accessing a owner procsym from the nested }
  2749. { class or from a static class method we need to call }
  2750. { it as a class member }
  2751. if (assigned(current_structdef) and (current_structdef<>hdef) and is_owned_by(current_structdef,hdef)) or
  2752. (assigned(current_procinfo) and current_procinfo.get_normal_proc.procdef.no_self_node) then
  2753. p1:=cloadvmtaddrnode.create(ctypenode.create(hdef))
  2754. else
  2755. p1:=load_self_node;
  2756. { not srsymtable.symtabletype since that can be }
  2757. { withsymtable as well }
  2758. if (srsym.owner.symtabletype in [ObjectSymtable,recordsymtable]) then
  2759. do_member_read(tabstractrecorddef(hdef),getaddr,srsym,p1,again,[])
  2760. else
  2761. { no propertysyms in records (yet) }
  2762. internalerror(2009111510);
  2763. end
  2764. else
  2765. { no method pointer }
  2766. begin
  2767. handle_propertysym(tpropertysym(srsym),srsymtable,p1);
  2768. end;
  2769. end;
  2770. labelsym :
  2771. begin
  2772. { Support @label }
  2773. if getaddr then
  2774. begin
  2775. if srsym.owner<>current_procinfo.procdef.localst then
  2776. CGMessage(parser_e_label_outside_proc);
  2777. p1:=cloadnode.create(srsym,srsym.owner)
  2778. end
  2779. else
  2780. begin
  2781. consume(_COLON);
  2782. if tlabelsym(srsym).defined then
  2783. Message(sym_e_label_already_defined);
  2784. if symtablestack.top.symtablelevel<>srsymtable.symtablelevel then
  2785. begin
  2786. tlabelsym(srsym).nonlocal:=true;
  2787. exclude(current_procinfo.procdef.procoptions,po_inline);
  2788. end;
  2789. if tlabelsym(srsym).nonlocal and
  2790. (current_procinfo.procdef.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  2791. Message(sym_e_interprocgoto_into_init_final_code_not_allowed);
  2792. tlabelsym(srsym).defined:=true;
  2793. p1:=clabelnode.create(nil,tlabelsym(srsym));
  2794. tlabelsym(srsym).code:=p1;
  2795. end;
  2796. end;
  2797. undefinedsym :
  2798. begin
  2799. p1:=cnothingnode.Create;
  2800. p1.resultdef:=cundefineddef.create(true);
  2801. { clean up previously created dummy symbol }
  2802. srsym.free;
  2803. end;
  2804. errorsym :
  2805. begin
  2806. p1:=cerrornode.create;
  2807. if try_to_consume(_LKLAMMER) then
  2808. begin
  2809. parse_paras(false,false,_RKLAMMER);
  2810. consume(_RKLAMMER);
  2811. end;
  2812. end;
  2813. else
  2814. begin
  2815. p1:=cerrornode.create;
  2816. Message(parser_e_illegal_expression);
  2817. end;
  2818. end; { end case }
  2819. if assigned(p1) and (p1.nodetype<>errorn) then
  2820. p1.fileinfo:=tokenpos;
  2821. end;
  2822. end;
  2823. {---------------------------------------------
  2824. Factor_Read_Set
  2825. ---------------------------------------------}
  2826. { Read a set between [] }
  2827. function factor_read_set:tnode;
  2828. var
  2829. p1,p2 : tnode;
  2830. lastp,
  2831. buildp : tarrayconstructornode;
  2832. old_allow_array_constructor : boolean;
  2833. begin
  2834. buildp:=nil;
  2835. lastp:=nil;
  2836. { be sure that a least one arrayconstructn is used, also for an
  2837. empty [] }
  2838. if token=_RECKKLAMMER then
  2839. buildp:=carrayconstructornode.create(nil,buildp)
  2840. else
  2841. repeat
  2842. { nested array constructors are not allowed, see also tests/webtbs/tw17213.pp }
  2843. old_allow_array_constructor:=allow_array_constructor;
  2844. allow_array_constructor:=false;
  2845. p1:=comp_expr(true,false);
  2846. if try_to_consume(_POINTPOINT) then
  2847. begin
  2848. p2:=comp_expr(true,false);
  2849. p1:=carrayconstructorrangenode.create(p1,p2);
  2850. end;
  2851. { insert at the end of the tree, to get the correct order }
  2852. if not assigned(buildp) then
  2853. begin
  2854. buildp:=carrayconstructornode.create(p1,nil);
  2855. lastp:=buildp;
  2856. end
  2857. else
  2858. begin
  2859. lastp.right:=carrayconstructornode.create(p1,nil);
  2860. lastp:=tarrayconstructornode(lastp.right);
  2861. end;
  2862. allow_array_constructor:=old_allow_array_constructor;
  2863. { there could be more elements }
  2864. until not try_to_consume(_COMMA);
  2865. factor_read_set:=buildp;
  2866. end;
  2867. function can_load_self_node: boolean;
  2868. begin
  2869. result:=false;
  2870. if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or
  2871. not assigned(current_structdef) or
  2872. not assigned(current_procinfo) then
  2873. exit;
  2874. result:=not current_procinfo.get_normal_proc.procdef.no_self_node;
  2875. end;
  2876. {---------------------------------------------
  2877. Factor (Main)
  2878. ---------------------------------------------}
  2879. var
  2880. l : longint;
  2881. ic : int64;
  2882. qc : qword;
  2883. p1 : tnode;
  2884. code : integer;
  2885. srsym : tsym;
  2886. srsymtable : TSymtable;
  2887. pd : tprocdef;
  2888. hclassdef : tobjectdef;
  2889. d : bestreal;
  2890. hs,hsorg : string;
  2891. hdef : tdef;
  2892. filepos : tfileposinfo;
  2893. callflags : tcallnodeflags;
  2894. idstr : tidstring;
  2895. dopostfix,
  2896. again,
  2897. updatefpos,
  2898. nodechanged : boolean;
  2899. begin
  2900. { can't keep a copy of p1 and compare pointers afterwards, because
  2901. p1 may be freed and reallocated in the same place! }
  2902. dopostfix:=true;
  2903. updatefpos:=false;
  2904. p1:=nil;
  2905. filepos:=current_tokenpos;
  2906. again:=false;
  2907. pd:=nil;
  2908. if token=_ID then
  2909. begin
  2910. again:=true;
  2911. { Handle references to self }
  2912. if (idtoken=_SELF) and can_load_self_node then
  2913. begin
  2914. p1:=load_self_node;
  2915. consume(_ID);
  2916. again:=true;
  2917. end
  2918. else
  2919. factor_read_id(p1,again);
  2920. if assigned(p1) then
  2921. begin
  2922. { factor_read_id will set the filepos to after the id,
  2923. and in case of _SELF the filepos will already be the
  2924. same as filepos (so setting it again doesn't hurt). }
  2925. p1.fileinfo:=filepos;
  2926. filepos:=current_tokenpos;
  2927. end;
  2928. { handle post fix operators }
  2929. if (m_delphi in current_settings.modeswitches) and
  2930. (block_type=bt_body) and
  2931. (token in [_LT,_LSHARPBRACKET]) then
  2932. begin
  2933. if p1.nodetype=typen then
  2934. idstr:=ttypenode(p1).typesym.name
  2935. else
  2936. if (p1.nodetype=loadvmtaddrn) and
  2937. (tloadvmtaddrnode(p1).left.nodetype=typen) then
  2938. idstr:=ttypenode(tloadvmtaddrnode(p1).left).typesym.name
  2939. else
  2940. if (p1.nodetype=loadn) then
  2941. idstr:=tloadnode(p1).symtableentry.name
  2942. else
  2943. idstr:='';
  2944. { if this is the case then the postfix handling is done in
  2945. sub_expr if necessary }
  2946. dopostfix:=not could_be_generic(idstr);
  2947. end;
  2948. if dopostfix then
  2949. updatefpos:=postfixoperators(p1,again,getaddr);
  2950. end
  2951. else
  2952. begin
  2953. updatefpos:=true;
  2954. case token of
  2955. _RETURN :
  2956. begin
  2957. consume(_RETURN);
  2958. p1:=nil;
  2959. if not(token in [_SEMICOLON,_ELSE,_END]) then
  2960. begin
  2961. p1:=comp_expr(true,false);
  2962. if not assigned(current_procinfo) or
  2963. (current_procinfo.procdef.proctypeoption in [potype_constructor,potype_destructor]) or
  2964. is_void(current_procinfo.procdef.returndef) then
  2965. begin
  2966. Message(parser_e_void_function);
  2967. { recovery }
  2968. p1.free;
  2969. p1:=nil;
  2970. end;
  2971. end;
  2972. p1 := cexitnode.create(p1);
  2973. end;
  2974. _INHERITED :
  2975. begin
  2976. again:=true;
  2977. consume(_INHERITED);
  2978. if assigned(current_procinfo) and
  2979. assigned(current_structdef) and
  2980. ((current_structdef.typ=objectdef) or
  2981. ((target_info.system in systems_jvm) and
  2982. (current_structdef.typ=recorddef)))then
  2983. begin
  2984. { for record helpers in mode Delphi "inherited" is not
  2985. allowed }
  2986. if is_objectpascal_helper(current_structdef) and
  2987. (m_delphi in current_settings.modeswitches) and
  2988. is_record(tobjectdef(current_structdef).extendeddef) then
  2989. Message(parser_e_inherited_not_in_record);
  2990. if (current_structdef.typ=objectdef) then
  2991. begin
  2992. hclassdef:=tobjectdef(current_structdef).childof;
  2993. { Objective-C categories *replace* methods in the class
  2994. they extend, or add methods to it. So calling an
  2995. inherited method always calls the method inherited from
  2996. the parent of the extended class }
  2997. if is_objccategory(current_structdef) then
  2998. hclassdef:=hclassdef.childof;
  2999. end
  3000. else if target_info.system in systems_jvm then
  3001. hclassdef:=java_fpcbaserecordtype
  3002. else
  3003. internalerror(2012012401);
  3004. { if inherited; only then we need the method with
  3005. the same name }
  3006. if token <> _ID then
  3007. begin
  3008. hs:=current_procinfo.procdef.procsym.name;
  3009. hsorg:=current_procinfo.procdef.procsym.realname;
  3010. anon_inherited:=true;
  3011. { For message methods we need to search using the message
  3012. number or string }
  3013. pd:=tprocdef(tprocsym(current_procinfo.procdef.procsym).ProcdefList[0]);
  3014. srdef:=nil;
  3015. if (po_msgint in pd.procoptions) then
  3016. searchsym_in_class_by_msgint(hclassdef,pd.messageinf.i,srdef,srsym,srsymtable)
  3017. else
  3018. if (po_msgstr in pd.procoptions) then
  3019. searchsym_in_class_by_msgstr(hclassdef,pd.messageinf.str^,srsym,srsymtable)
  3020. else
  3021. { helpers have their own ways of dealing with inherited }
  3022. if is_objectpascal_helper(current_structdef) then
  3023. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3024. else
  3025. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3026. end
  3027. else
  3028. begin
  3029. hs:=pattern;
  3030. hsorg:=orgpattern;
  3031. consume(_ID);
  3032. anon_inherited:=false;
  3033. { helpers have their own ways of dealing with inherited }
  3034. if is_objectpascal_helper(current_structdef) then
  3035. searchsym_in_helper(tobjectdef(current_structdef),tobjectdef(current_structdef),hs,srsym,srsymtable,[ssf_has_inherited])
  3036. else
  3037. searchsym_in_class(hclassdef,current_structdef,hs,srsym,srsymtable,[ssf_search_helper]);
  3038. end;
  3039. if assigned(srsym) then
  3040. begin
  3041. check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
  3042. { load the procdef from the inherited class and
  3043. not from self }
  3044. case srsym.typ of
  3045. procsym:
  3046. begin
  3047. if is_objectpascal_helper(current_structdef) then
  3048. begin
  3049. { for a helper load the procdef either from the
  3050. extended type, from the parent helper or from
  3051. the extended type of the parent helper
  3052. depending on the def the found symbol belongs
  3053. to }
  3054. if (srsym.Owner.defowner.typ=objectdef) and
  3055. is_objectpascal_helper(tobjectdef(srsym.Owner.defowner)) then
  3056. if def_is_related(current_structdef,tdef(srsym.Owner.defowner)) and
  3057. assigned(tobjectdef(current_structdef).childof) then
  3058. hdef:=tobjectdef(current_structdef).childof
  3059. else
  3060. hdef:=tobjectdef(srsym.Owner.defowner).extendeddef
  3061. else
  3062. hdef:=tdef(srsym.Owner.defowner);
  3063. end
  3064. else
  3065. hdef:=hclassdef;
  3066. if (po_classmethod in current_procinfo.procdef.procoptions) or
  3067. (po_staticmethod in current_procinfo.procdef.procoptions) then
  3068. hdef:=cclassrefdef.create(hdef);
  3069. p1:=ctypenode.create(hdef);
  3070. { we need to allow helpers here }
  3071. ttypenode(p1).helperallowed:=true;
  3072. end;
  3073. propertysym:
  3074. ;
  3075. else
  3076. begin
  3077. Message(parser_e_methode_id_expected);
  3078. p1:=cerrornode.create;
  3079. end;
  3080. end;
  3081. callflags:=[cnf_inherited];
  3082. include(current_procinfo.flags,pi_has_inherited);
  3083. if anon_inherited then
  3084. include(callflags,cnf_anon_inherited);
  3085. do_member_read(hclassdef,getaddr,srsym,p1,again,callflags);
  3086. end
  3087. else
  3088. begin
  3089. if anon_inherited then
  3090. begin
  3091. { For message methods we need to call DefaultHandler }
  3092. if (po_msgint in pd.procoptions) or
  3093. (po_msgstr in pd.procoptions) then
  3094. begin
  3095. searchsym_in_class(hclassdef,hclassdef,'DEFAULTHANDLER',srsym,srsymtable,[ssf_search_helper]);
  3096. if not assigned(srsym) or
  3097. (srsym.typ<>procsym) then
  3098. internalerror(200303171);
  3099. p1:=nil;
  3100. do_proc_call(srsym,srsym.owner,hclassdef,false,again,p1,[]);
  3101. end
  3102. else
  3103. begin
  3104. { we need to ignore the inherited; }
  3105. p1:=cnothingnode.create;
  3106. end;
  3107. end
  3108. else
  3109. begin
  3110. Message1(sym_e_id_no_member,hsorg);
  3111. p1:=cerrornode.create;
  3112. end;
  3113. again:=false;
  3114. end;
  3115. { turn auto inheriting off }
  3116. anon_inherited:=false;
  3117. end
  3118. else
  3119. begin
  3120. { in case of records we use a more clear error message }
  3121. if assigned(current_structdef) and
  3122. (current_structdef.typ=recorddef) then
  3123. Message(parser_e_inherited_not_in_record)
  3124. else
  3125. Message(parser_e_generic_methods_only_in_methods);
  3126. again:=false;
  3127. p1:=cerrornode.create;
  3128. end;
  3129. postfixoperators(p1,again,getaddr);
  3130. end;
  3131. _INTCONST :
  3132. begin
  3133. {Try first wether the value fits in an int64.}
  3134. val(pattern,ic,code);
  3135. if code=0 then
  3136. begin
  3137. consume(_INTCONST);
  3138. int_to_type(ic,hdef);
  3139. p1:=cordconstnode.create(ic,hdef,true);
  3140. end
  3141. else
  3142. begin
  3143. { try qword next }
  3144. val(pattern,qc,code);
  3145. if code=0 then
  3146. begin
  3147. consume(_INTCONST);
  3148. int_to_type(qc,hdef);
  3149. p1:=cordconstnode.create(qc,hdef,true);
  3150. end;
  3151. end;
  3152. if code<>0 then
  3153. begin
  3154. { finally float }
  3155. val(pattern,d,code);
  3156. if code<>0 then
  3157. begin
  3158. Message(parser_e_invalid_integer);
  3159. consume(_INTCONST);
  3160. l:=1;
  3161. p1:=cordconstnode.create(l,sinttype,true);
  3162. end
  3163. else
  3164. begin
  3165. consume(_INTCONST);
  3166. p1:=crealconstnode.create(d,pbestrealtype^);
  3167. end;
  3168. end
  3169. else
  3170. { the necessary range checking has already been done by val }
  3171. tordconstnode(p1).rangecheck:=false;
  3172. if token=_POINT then
  3173. begin
  3174. again:=true;
  3175. postfixoperators(p1,again,getaddr);
  3176. end;
  3177. end;
  3178. _REALNUMBER :
  3179. begin
  3180. p1:=real_const_node_from_pattern(pattern);
  3181. consume(_REALNUMBER);
  3182. if token=_POINT then
  3183. begin
  3184. again:=true;
  3185. postfixoperators(p1,again,getaddr);
  3186. end;
  3187. end;
  3188. _STRING :
  3189. begin
  3190. string_dec(hdef,true);
  3191. { STRING can be also a type cast }
  3192. if try_to_consume(_LKLAMMER) then
  3193. begin
  3194. p1:=comp_expr(true,false);
  3195. consume(_RKLAMMER);
  3196. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3197. { handle postfix operators here e.g. string(a)[10] }
  3198. again:=true;
  3199. postfixoperators(p1,again,getaddr);
  3200. end
  3201. else
  3202. p1:=ctypenode.create(hdef);
  3203. end;
  3204. _FILE :
  3205. begin
  3206. hdef:=cfiletype;
  3207. consume(_FILE);
  3208. { FILE can be also a type cast }
  3209. if try_to_consume(_LKLAMMER) then
  3210. begin
  3211. p1:=comp_expr(true,false);
  3212. consume(_RKLAMMER);
  3213. p1:=ctypeconvnode.create_explicit(p1,hdef);
  3214. { handle postfix operators here e.g. string(a)[10] }
  3215. again:=true;
  3216. postfixoperators(p1,again,getaddr);
  3217. end
  3218. else
  3219. begin
  3220. p1:=ctypenode.create(hdef);
  3221. end;
  3222. end;
  3223. _CSTRING :
  3224. begin
  3225. p1:=cstringconstnode.createpchar(ansistring2pchar(cstringpattern),length(cstringpattern),nil);
  3226. consume(_CSTRING);
  3227. if token in postfixoperator_tokens then
  3228. begin
  3229. again:=true;
  3230. postfixoperators(p1,again,getaddr);
  3231. end;
  3232. end;
  3233. _CCHAR :
  3234. begin
  3235. p1:=cordconstnode.create(ord(pattern[1]),cansichartype,true);
  3236. consume(_CCHAR);
  3237. if token=_POINT then
  3238. begin
  3239. again:=true;
  3240. postfixoperators(p1,again,getaddr);
  3241. end;
  3242. end;
  3243. _CWSTRING:
  3244. begin
  3245. p1:=cstringconstnode.createunistr(patternw);
  3246. consume(_CWSTRING);
  3247. if token in postfixoperator_tokens then
  3248. begin
  3249. again:=true;
  3250. postfixoperators(p1,again,getaddr);
  3251. end;
  3252. end;
  3253. _CWCHAR:
  3254. begin
  3255. p1:=cordconstnode.create(ord(getcharwidestring(patternw,0)),cwidechartype,true);
  3256. consume(_CWCHAR);
  3257. if token=_POINT then
  3258. begin
  3259. again:=true;
  3260. postfixoperators(p1,again,getaddr);
  3261. end;
  3262. end;
  3263. _KLAMMERAFFE :
  3264. begin
  3265. consume(_KLAMMERAFFE);
  3266. got_addrn:=true;
  3267. { support both @<x> and @(<x>) }
  3268. if try_to_consume(_LKLAMMER) then
  3269. begin
  3270. p1:=factor(true,false);
  3271. { inside parentheses a full expression is allowed, see also tests\webtbs\tb27517.pp }
  3272. if token<>_RKLAMMER then
  3273. p1:=sub_expr(opcompare,true,false,p1);
  3274. consume(_RKLAMMER);
  3275. end
  3276. else
  3277. p1:=factor(true,false);
  3278. if token in postfixoperator_tokens then
  3279. begin
  3280. again:=true;
  3281. postfixoperators(p1,again,getaddr);
  3282. end;
  3283. got_addrn:=false;
  3284. p1:=caddrnode.create(p1);
  3285. p1.fileinfo:=filepos;
  3286. if cs_typed_addresses in current_settings.localswitches then
  3287. include(p1.flags,nf_typedaddr);
  3288. { Store the procvar that we are expecting, the
  3289. addrn will use the information to find the correct
  3290. procdef or it will return an error }
  3291. if assigned(getprocvardef) and
  3292. (taddrnode(p1).left.nodetype = loadn) then
  3293. taddrnode(p1).getprocvardef:=getprocvardef;
  3294. end;
  3295. _LKLAMMER :
  3296. begin
  3297. consume(_LKLAMMER);
  3298. p1:=comp_expr(true,false);
  3299. consume(_RKLAMMER);
  3300. { it's not a good solution
  3301. but (a+b)^ makes some problems }
  3302. if token in postfixoperator_tokens then
  3303. begin
  3304. again:=true;
  3305. postfixoperators(p1,again,getaddr);
  3306. end;
  3307. end;
  3308. _LECKKLAMMER :
  3309. begin
  3310. consume(_LECKKLAMMER);
  3311. p1:=factor_read_set;
  3312. consume(_RECKKLAMMER);
  3313. end;
  3314. _PLUS :
  3315. begin
  3316. consume(_PLUS);
  3317. p1:=factor(false,false);
  3318. p1:=cunaryplusnode.create(p1);
  3319. end;
  3320. _MINUS :
  3321. begin
  3322. consume(_MINUS);
  3323. if (token = _INTCONST) and not(m_isolike_unary_minus in current_settings.modeswitches) then
  3324. begin
  3325. { ugly hack, but necessary to be able to parse }
  3326. { -9223372036854775808 as int64 (JM) }
  3327. pattern := '-'+pattern;
  3328. p1:=sub_expr(oppower,false,false,nil);
  3329. { -1 ** 4 should be - (1 ** 4) and not
  3330. (-1) ** 4
  3331. This was the reason of tw0869.pp test failure PM }
  3332. if p1.nodetype=starstarn then
  3333. begin
  3334. if tbinarynode(p1).left.nodetype=ordconstn then
  3335. begin
  3336. tordconstnode(tbinarynode(p1).left).value:=-tordconstnode(tbinarynode(p1).left).value;
  3337. p1:=cunaryminusnode.create(p1);
  3338. end
  3339. else if tbinarynode(p1).left.nodetype=realconstn then
  3340. begin
  3341. trealconstnode(tbinarynode(p1).left).value_real:=-trealconstnode(tbinarynode(p1).left).value_real;
  3342. trealconstnode(tbinarynode(p1).left).value_currency:=-trealconstnode(tbinarynode(p1).left).value_currency;
  3343. p1:=cunaryminusnode.create(p1);
  3344. end
  3345. else
  3346. internalerror(20021029);
  3347. end;
  3348. end
  3349. else
  3350. begin
  3351. if m_isolike_unary_minus in current_settings.modeswitches then
  3352. p1:=sub_expr(opmultiply,false,false,nil)
  3353. else
  3354. p1:=sub_expr(oppower,false,false,nil);
  3355. p1:=cunaryminusnode.create(p1);
  3356. end;
  3357. end;
  3358. _OP_NOT :
  3359. begin
  3360. consume(_OP_NOT);
  3361. p1:=factor(false,false);
  3362. p1:=cnotnode.create(p1);
  3363. end;
  3364. _NIL :
  3365. begin
  3366. consume(_NIL);
  3367. p1:=cnilnode.create;
  3368. { It's really ugly code nil^, but delphi allows it }
  3369. if token in [_CARET,_POINT] then
  3370. begin
  3371. again:=true;
  3372. postfixoperators(p1,again,getaddr);
  3373. end;
  3374. end;
  3375. _OBJCPROTOCOL:
  3376. begin
  3377. { The @protocol keyword is used in two ways in Objective-C:
  3378. 1) to declare protocols (~ Object Pascal interfaces)
  3379. 2) to obtain the metaclass (~ Object Pascal) "class of")
  3380. of a declared protocol
  3381. This code is for handling the second case. Because of 1),
  3382. we cannot simply use a system unit symbol.
  3383. }
  3384. consume(_OBJCPROTOCOL);
  3385. consume(_LKLAMMER);
  3386. p1:=factor(false,false);
  3387. consume(_RKLAMMER);
  3388. p1:=cinlinenode.create(in_objc_protocol_x,false,p1);
  3389. end;
  3390. else
  3391. begin
  3392. Message(parser_e_illegal_expression);
  3393. p1:=cerrornode.create;
  3394. { recover }
  3395. consume(token);
  3396. end;
  3397. end;
  3398. end;
  3399. { generate error node if no node is created }
  3400. if not assigned(p1) then
  3401. begin
  3402. {$ifdef EXTDEBUG}
  3403. Comment(V_Warning,'factor: p1=nil');
  3404. {$endif}
  3405. p1:=cerrornode.create;
  3406. updatefpos:=true;
  3407. end;
  3408. { get the resultdef for the node if nothing stops us }
  3409. if (not assigned(p1.resultdef)) and dopostfix then
  3410. begin
  3411. do_typecheckpass_changed(p1,nodechanged);
  3412. updatefpos:=updatefpos or nodechanged;
  3413. end;
  3414. if assigned(p1) and
  3415. updatefpos then
  3416. p1.fileinfo:=filepos;
  3417. factor:=p1;
  3418. end;
  3419. {$maxfpuregisters default}
  3420. procedure post_comp_expr_gendef(var def: tdef);
  3421. var
  3422. p1 : tnode;
  3423. again : boolean;
  3424. begin
  3425. if not assigned(def) then
  3426. internalerror(2011053001);
  3427. again:=false;
  3428. { handle potential typecasts, etc }
  3429. p1:=handle_factor_typenode(def,false,again,nil,false);
  3430. { parse postfix operators }
  3431. postfixoperators(p1,again,false);
  3432. if assigned(p1) and (p1.nodetype=typen) then
  3433. def:=ttypenode(p1).typedef
  3434. else
  3435. def:=generrordef;
  3436. end;
  3437. {****************************************************************************
  3438. Sub_Expr
  3439. ****************************************************************************}
  3440. function sub_expr(pred_level:Toperator_precedence;accept_equal,typeonly:boolean;factornode:tnode):tnode;
  3441. {Reads a subexpression while the operators are of the current precedence
  3442. level, or any higher level. Replaces the old term, simpl_expr and
  3443. simpl2_expr.}
  3444. function istypenode(n:tnode):boolean;inline;
  3445. { Checks whether the given node is a type node or a VMT node containing a
  3446. typenode. This is used in the code for inline specializations in the
  3447. _LT branch below }
  3448. begin
  3449. result:=assigned(n) and
  3450. (
  3451. (n.nodetype=typen) or
  3452. (
  3453. (n.nodetype=loadvmtaddrn) and
  3454. (tloadvmtaddrnode(n).left.nodetype=typen)
  3455. )
  3456. );
  3457. end;
  3458. function gettypedef(n:tnode):tdef;inline;
  3459. { This returns the typedef that belongs to the given typenode or
  3460. loadvmtaddrnode. n must not be Nil! }
  3461. begin
  3462. if n.nodetype=typen then
  3463. result:=ttypenode(n).typedef
  3464. else
  3465. result:=ttypenode(tloadvmtaddrnode(n).left).typedef;
  3466. end;
  3467. function getgenericsym(n:tnode;out srsym:tsym):boolean;
  3468. var
  3469. srsymtable : tsymtable;
  3470. begin
  3471. srsym:=nil;
  3472. case n.nodetype of
  3473. typen:
  3474. srsym:=ttypenode(n).typedef.typesym;
  3475. loadvmtaddrn:
  3476. srsym:=ttypenode(tloadvmtaddrnode(n).left).typedef.typesym;
  3477. loadn:
  3478. if not searchsym_with_symoption(tloadnode(n).symtableentry.Name,srsym,srsymtable,sp_generic_dummy) then
  3479. srsym:=nil;
  3480. { TODO : handle const nodes }
  3481. end;
  3482. result:=assigned(srsym);
  3483. end;
  3484. label
  3485. SubExprStart;
  3486. var
  3487. p1,p2 : tnode;
  3488. oldt : Ttoken;
  3489. filepos : tfileposinfo;
  3490. again : boolean;
  3491. gendef,parseddef : tdef;
  3492. gensym : tsym;
  3493. begin
  3494. SubExprStart:
  3495. if pred_level=highest_precedence then
  3496. begin
  3497. if factornode=nil then
  3498. p1:=factor(false,typeonly)
  3499. else
  3500. p1:=factornode;
  3501. end
  3502. else
  3503. p1:=sub_expr(succ(pred_level),true,typeonly,factornode);
  3504. repeat
  3505. if (token in [NOTOKEN..last_operator]) and
  3506. (token in operator_levels[pred_level]) and
  3507. ((token<>_EQ) or accept_equal) then
  3508. begin
  3509. oldt:=token;
  3510. filepos:=current_tokenpos;
  3511. consume(token);
  3512. if pred_level=highest_precedence then
  3513. p2:=factor(false,false)
  3514. else
  3515. p2:=sub_expr(succ(pred_level),true,typeonly,nil);
  3516. case oldt of
  3517. _PLUS :
  3518. p1:=caddnode.create(addn,p1,p2);
  3519. _MINUS :
  3520. p1:=caddnode.create(subn,p1,p2);
  3521. _STAR :
  3522. p1:=caddnode.create(muln,p1,p2);
  3523. _SLASH :
  3524. p1:=caddnode.create(slashn,p1,p2);
  3525. _EQ:
  3526. p1:=caddnode.create(equaln,p1,p2);
  3527. _GT :
  3528. p1:=caddnode.create(gtn,p1,p2);
  3529. _LT :
  3530. begin
  3531. { we need to decice whether we have an inline specialization
  3532. (type nodes to the left and right of "<", mode Delphi and
  3533. ">" or "," following) or a normal "<" comparison }
  3534. { TODO : p1 could be a non type if e.g. a variable with the
  3535. same name is defined in the same unit where the
  3536. generic is defined (though "same unit" is not
  3537. necessarily needed) }
  3538. if getgenericsym(p1,gensym) and
  3539. { Attention: when nested specializations are supported
  3540. p2 could be a loadn if a "<" follows }
  3541. istypenode(p2) and
  3542. (m_delphi in current_settings.modeswitches) and
  3543. { TODO : add _LT, _LSHARPBRACKET for nested specializations }
  3544. (token in [_GT,_RSHARPBRACKET,_COMMA]) then
  3545. begin
  3546. { this is an inline specialization }
  3547. { retrieve the defs of two nodes }
  3548. gendef:=nil;
  3549. parseddef:=gettypedef(p2);
  3550. if parseddef.typesym.typ<>typesym then
  3551. Internalerror(2011051001);
  3552. { check the hints for parseddef }
  3553. check_hints(parseddef.typesym,parseddef.typesym.symoptions,parseddef.typesym.deprecatedmsg);
  3554. { generate the specialization }
  3555. generate_specialization(gendef,false,'',parseddef,gensym.RealName,p2.fileinfo);
  3556. { we don't need the old left and right nodes anymore }
  3557. p1.Free;
  3558. p2.Free;
  3559. { in case of a class or a record the specialized generic
  3560. is always a classrefdef }
  3561. again:=false;
  3562. { handle potential typecasts, etc }
  3563. p1:=handle_factor_typenode(gendef,false,again,nil,false);
  3564. { parse postfix operators }
  3565. if postfixoperators(p1,again,false) then
  3566. if assigned(p1) then
  3567. p1.fileinfo:=filepos
  3568. else
  3569. p1:=cerrornode.create;
  3570. { with p1 now set we are in reality directly behind the
  3571. call to "factor" thus we need to call down to that
  3572. again }
  3573. { This is disabled until specializations on the right
  3574. hand side work as well, because
  3575. "not working expressions" is better than "half working
  3576. expressions" }
  3577. {factornode:=p1;
  3578. goto SubExprStart;}
  3579. end
  3580. else
  3581. begin
  3582. { this is a normal "<" comparison }
  3583. { potential generic types that are followed by a "<": }
  3584. { a) might not have their resultdef set }
  3585. if not assigned(p1.resultdef) then
  3586. do_typecheckpass(p1);
  3587. { b) are not checked whether they are an undefined def,
  3588. but not a generic parameter }
  3589. if (p1.nodetype=typen) and
  3590. (ttypenode(p1).typedef.typ=undefineddef) and
  3591. assigned(ttypenode(p1).typedef.typesym) and
  3592. not (sp_generic_para in ttypenode(p1).typedef.typesym.symoptions) then
  3593. begin
  3594. identifier_not_found(ttypenode(p1).typedef.typesym.RealName);
  3595. p1.Free;
  3596. p1:=cerrornode.create;
  3597. end;
  3598. { c) don't have their hints checked }
  3599. if istypenode(p1) then
  3600. begin
  3601. gendef:=gettypedef(p1);
  3602. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  3603. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  3604. end;
  3605. { Note: the second part of the expression will be needed
  3606. for nested specializations }
  3607. if istypenode(p2) {and
  3608. not (token in [_LT, _LSHARPBRACKET])} then
  3609. begin
  3610. gendef:=gettypedef(p2);
  3611. if gendef.typ in [objectdef,recorddef,arraydef,procvardef] then
  3612. check_hints(gendef.typesym,gendef.typesym.symoptions,gendef.typesym.deprecatedmsg);
  3613. end;
  3614. { create the comparison node for "<" }
  3615. p1:=caddnode.create(ltn,p1,p2)
  3616. end;
  3617. end;
  3618. _GTE :
  3619. p1:=caddnode.create(gten,p1,p2);
  3620. _LTE :
  3621. p1:=caddnode.create(lten,p1,p2);
  3622. _SYMDIF :
  3623. p1:=caddnode.create(symdifn,p1,p2);
  3624. _STARSTAR :
  3625. p1:=caddnode.create(starstarn,p1,p2);
  3626. _OP_AS,
  3627. _OP_IS :
  3628. begin
  3629. if token in [_LT, _LSHARPBRACKET] then
  3630. begin
  3631. { for now we're handling this as a generic declaration;
  3632. there could be cases though (because of operator
  3633. overloading) where this is the wrong decision... }
  3634. { TODO : here the same note as in _LT applies as p2 could
  3635. point to a variable, etc }
  3636. gendef:=gettypedef(p2);
  3637. if gendef.typesym.typ<>typesym then
  3638. Internalerror(2011071401);
  3639. { generate the specialization }
  3640. generate_specialization(gendef,false,'');
  3641. { we don't need the old p2 anymore }
  3642. p2.Free;
  3643. again:=false;
  3644. { handle potential typecasts, etc }
  3645. p2:=handle_factor_typenode(gendef,false,again,nil,false);
  3646. { parse postfix operators }
  3647. if postfixoperators(p2,again,false) then
  3648. if assigned(p2) then
  3649. p2.fileinfo:=filepos
  3650. else
  3651. p2:=cerrornode.create;
  3652. { here we don't need to call back down to "factor", thus
  3653. no "goto" }
  3654. end;
  3655. { now generate the "is" or "as" node }
  3656. case oldt of
  3657. _OP_AS:
  3658. p1:=casnode.create(p1,p2);
  3659. _OP_IS:
  3660. p1:=cisnode.create(p1,p2);
  3661. end;
  3662. end;
  3663. _OP_IN :
  3664. p1:=cinnode.create(p1,p2);
  3665. _OP_OR,
  3666. _PIPE {macpas only} :
  3667. begin
  3668. p1:=caddnode.create(orn,p1,p2);
  3669. if (oldt = _PIPE) then
  3670. include(p1.flags,nf_short_bool);
  3671. end;
  3672. _OP_AND,
  3673. _AMPERSAND {macpas only} :
  3674. begin
  3675. p1:=caddnode.create(andn,p1,p2);
  3676. if (oldt = _AMPERSAND) then
  3677. include(p1.flags,nf_short_bool);
  3678. end;
  3679. _OP_DIV :
  3680. p1:=cmoddivnode.create(divn,p1,p2);
  3681. _OP_NOT :
  3682. p1:=cnotnode.create(p1);
  3683. _OP_MOD :
  3684. begin
  3685. p1:=cmoddivnode.create(modn,p1,p2);
  3686. if m_iso in current_settings.modeswitches then
  3687. include(p1.flags,nf_isomod);
  3688. end;
  3689. _OP_SHL :
  3690. p1:=cshlshrnode.create(shln,p1,p2);
  3691. _OP_SHR :
  3692. p1:=cshlshrnode.create(shrn,p1,p2);
  3693. _OP_XOR :
  3694. p1:=caddnode.create(xorn,p1,p2);
  3695. _ASSIGNMENT :
  3696. p1:=cassignmentnode.create(p1,p2);
  3697. _NE :
  3698. p1:=caddnode.create(unequaln,p1,p2);
  3699. end;
  3700. p1.fileinfo:=filepos;
  3701. end
  3702. else
  3703. break;
  3704. until false;
  3705. sub_expr:=p1;
  3706. end;
  3707. function comp_expr(accept_equal,typeonly:boolean):tnode;
  3708. var
  3709. oldafterassignment : boolean;
  3710. p1 : tnode;
  3711. begin
  3712. oldafterassignment:=afterassignment;
  3713. afterassignment:=true;
  3714. p1:=sub_expr(opcompare,accept_equal,typeonly,nil);
  3715. { get the resultdef for this expression }
  3716. if not assigned(p1.resultdef) then
  3717. do_typecheckpass(p1);
  3718. afterassignment:=oldafterassignment;
  3719. comp_expr:=p1;
  3720. end;
  3721. function expr(dotypecheck : boolean) : tnode;
  3722. var
  3723. p1,p2 : tnode;
  3724. filepos : tfileposinfo;
  3725. oldafterassignment,
  3726. updatefpos : boolean;
  3727. begin
  3728. oldafterassignment:=afterassignment;
  3729. p1:=sub_expr(opcompare,true,false,nil);
  3730. { get the resultdef for this expression }
  3731. if not assigned(p1.resultdef) and
  3732. dotypecheck then
  3733. do_typecheckpass(p1);
  3734. filepos:=current_tokenpos;
  3735. if token in [_ASSIGNMENT,_PLUSASN,_MINUSASN,_STARASN,_SLASHASN] then
  3736. afterassignment:=true;
  3737. updatefpos:=true;
  3738. case token of
  3739. _POINTPOINT :
  3740. begin
  3741. consume(_POINTPOINT);
  3742. p2:=sub_expr(opcompare,true,false,nil);
  3743. p1:=crangenode.create(p1,p2);
  3744. end;
  3745. _ASSIGNMENT :
  3746. begin
  3747. consume(_ASSIGNMENT);
  3748. if assigned(p1.resultdef) and (p1.resultdef.typ=procvardef) then
  3749. getprocvardef:=tprocvardef(p1.resultdef);
  3750. p2:=sub_expr(opcompare,true,false,nil);
  3751. if assigned(getprocvardef) then
  3752. handle_procvar(getprocvardef,p2);
  3753. getprocvardef:=nil;
  3754. p1:=cassignmentnode.create(p1,p2);
  3755. end;
  3756. _PLUSASN :
  3757. begin
  3758. consume(_PLUSASN);
  3759. p2:=sub_expr(opcompare,true,false,nil);
  3760. p1:=gen_c_style_operator(addn,p1,p2);
  3761. end;
  3762. _MINUSASN :
  3763. begin
  3764. consume(_MINUSASN);
  3765. p2:=sub_expr(opcompare,true,false,nil);
  3766. p1:=gen_c_style_operator(subn,p1,p2);
  3767. end;
  3768. _STARASN :
  3769. begin
  3770. consume(_STARASN );
  3771. p2:=sub_expr(opcompare,true,false,nil);
  3772. p1:=gen_c_style_operator(muln,p1,p2);
  3773. end;
  3774. _SLASHASN :
  3775. begin
  3776. consume(_SLASHASN );
  3777. p2:=sub_expr(opcompare,true,false,nil);
  3778. p1:=gen_c_style_operator(slashn,p1,p2);
  3779. end;
  3780. else
  3781. updatefpos:=false;
  3782. end;
  3783. { get the resultdef for this expression }
  3784. if not assigned(p1.resultdef) and
  3785. dotypecheck then
  3786. do_typecheckpass(p1);
  3787. afterassignment:=oldafterassignment;
  3788. if updatefpos then
  3789. p1.fileinfo:=filepos;
  3790. expr:=p1;
  3791. end;
  3792. function get_intconst:TConstExprInt;
  3793. {Reads an expression, tries to evalute it and check if it is an integer
  3794. constant. Then the constant is returned.}
  3795. var
  3796. p:tnode;
  3797. begin
  3798. result:=0;
  3799. p:=comp_expr(true,false);
  3800. if not codegenerror then
  3801. begin
  3802. if (p.nodetype<>ordconstn) or
  3803. not(is_integer(p.resultdef)) then
  3804. Message(parser_e_illegal_expression)
  3805. else
  3806. result:=tordconstnode(p).value;
  3807. end;
  3808. p.free;
  3809. end;
  3810. function get_stringconst:string;
  3811. {Reads an expression, tries to evaluate it and checks if it is a string
  3812. constant. Then the constant is returned.}
  3813. var
  3814. p:tnode;
  3815. begin
  3816. get_stringconst:='';
  3817. p:=comp_expr(true,false);
  3818. if p.nodetype<>stringconstn then
  3819. begin
  3820. if (p.nodetype=ordconstn) and is_char(p.resultdef) then
  3821. get_stringconst:=char(int64(tordconstnode(p).value))
  3822. else
  3823. Message(parser_e_illegal_expression);
  3824. end
  3825. else
  3826. get_stringconst:=strpas(tstringconstnode(p).value_str);
  3827. p.free;
  3828. end;
  3829. end.