pexpr.pas 177 KB

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