2
0

pexpr.pas 187 KB

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