pexpr.pas 202 KB

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