pexpr.pas 197 KB

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