pexpr.pas 188 KB

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