pexpr.pas 187 KB

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