pexpr.pas 192 KB

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