pexpr.pas 191 KB

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