pexpr.pas 182 KB

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