pexpr.pas 187 KB

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