2
0

pexpr.pas 189 KB

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