pexpr.pas 190 KB

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