pexpr.pas 202 KB

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