pexpr.pas 175 KB

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