pexpr.pas 177 KB

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