2
0

pexpr.pas 205 KB

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