pexpr.pas 195 KB

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