pexpr.pas 188 KB

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