pexpr.pas 189 KB

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