pexpr.pas 203 KB

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