pdecsub.pas 129 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  3. Does the parsing of the procedures/functions
  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 pdecsub;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { scanner }
  24. tokens,
  25. { symtable }
  26. symconst,symtype,symdef,symsym;
  27. type
  28. tpdflag=(
  29. pd_body, { directive needs a body }
  30. pd_implemen, { directive can be used in implementation section }
  31. pd_interface, { directive can be used in interface section }
  32. pd_object, { directive can be used with object declaration }
  33. pd_record, { directive can be used with record declaration }
  34. pd_procvar, { directive can be used with procvar declaration }
  35. pd_notobject, { directive can not be used with object declaration }
  36. pd_notrecord, { directive can not be used with record declaration }
  37. pd_notobjintf, { directive can not be used with interface declaration }
  38. pd_notprocvar, { directive can not be used with procvar declaration }
  39. pd_dispinterface,{ directive can be used with dispinterface methods }
  40. pd_cppobject, { directive can be used with cppclass }
  41. pd_objcclass, { directive can be used with objcclass }
  42. pd_objcprot, { directive can be used with objcprotocol }
  43. pd_nothelper, { directive can not be used with record/class helper declaration }
  44. pd_javaclass, { directive can be used with Java class }
  45. pd_intfjava { directive can be used with Java interface }
  46. );
  47. tpdflags=set of tpdflag;
  48. function check_proc_directive(isprocvar:boolean):boolean;
  49. function proc_get_importname(pd:tprocdef):string;
  50. procedure proc_set_mangledname(pd:tprocdef);
  51. procedure parse_parameter_dec(pd:tabstractprocdef);
  52. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  53. procedure parse_var_proc_directives(sym:tsym);
  54. procedure parse_object_proc_directives(pd:tabstractprocdef);
  55. procedure parse_record_proc_directives(pd:tabstractprocdef);
  56. function parse_proc_head(astruct:tabstractrecorddef;potype:tproctypeoption;isgeneric:boolean;genericdef:tdef;generictypelist:tfphashobjectlist;out pd:tprocdef):boolean;
  57. function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef;isgeneric:boolean):tprocdef;
  58. procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean;astruct:tabstractrecorddef);
  59. { parse a record method declaration (not a (class) constructor/destructor) }
  60. function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean;hadgeneric:boolean): tprocdef;
  61. { helper functions - they insert nested objects hierarchy to the symtablestack
  62. with object hierarchy
  63. }
  64. function push_child_hierarchy(obj:tabstractrecorddef):integer;
  65. function pop_child_hierarchy(obj:tabstractrecorddef):integer;
  66. function push_nested_hierarchy(obj:tabstractrecorddef):integer;
  67. function pop_nested_hierarchy(obj:tabstractrecorddef):integer;
  68. implementation
  69. uses
  70. SysUtils,
  71. { common }
  72. cutils,
  73. { global }
  74. globtype,globals,verbose,constexp,
  75. systems,
  76. cpuinfo,
  77. { assembler }
  78. aasmbase,
  79. { symtable }
  80. symbase,symcpu,symtable,symutil,defutil,defcmp,
  81. { parameter handling }
  82. paramgr,cpupara,
  83. { pass 1 }
  84. fmodule,node,htypechk,ncon,nld,
  85. objcutil,
  86. { parser }
  87. scanner,
  88. syscinfo,
  89. pbase,pexpr,ptype,pdecl,pparautl,pgenutil
  90. {$ifdef jvm}
  91. ,pjvm
  92. {$endif}
  93. ;
  94. const
  95. { Please leave this here, this module should NOT use
  96. these variables.
  97. Declaring it as string here results in an error when compiling (PFV) }
  98. current_procinfo = 'error';
  99. function push_child_hierarchy(obj:tabstractrecorddef):integer;
  100. var
  101. _class,hp : tobjectdef;
  102. begin
  103. if obj.typ=recorddef then
  104. begin
  105. symtablestack.push(obj.symtable);
  106. result:=1;
  107. exit;
  108. end;
  109. result:=0;
  110. { insert class hierarchy in the reverse order }
  111. hp:=nil;
  112. repeat
  113. _class:=tobjectdef(obj);
  114. while _class.childof<>hp do
  115. _class:=_class.childof;
  116. hp:=_class;
  117. symtablestack.push(_class.symtable);
  118. inc(result);
  119. until hp=obj;
  120. end;
  121. function push_nested_hierarchy(obj:tabstractrecorddef):integer;
  122. begin
  123. result:=0;
  124. if obj.owner.symtabletype in [ObjectSymtable,recordsymtable] then
  125. inc(result,push_nested_hierarchy(tabstractrecorddef(obj.owner.defowner)));
  126. inc(result,push_child_hierarchy(obj));
  127. end;
  128. function pop_child_hierarchy(obj:tabstractrecorddef):integer;
  129. var
  130. _class : tobjectdef;
  131. begin
  132. if obj.typ=recorddef then
  133. begin
  134. symtablestack.pop(obj.symtable);
  135. result:=1;
  136. exit;
  137. end;
  138. result:=0;
  139. _class:=tobjectdef(obj);
  140. while assigned(_class) do
  141. begin
  142. symtablestack.pop(_class.symtable);
  143. _class:=_class.childof;
  144. inc(result);
  145. end;
  146. end;
  147. function pop_nested_hierarchy(obj:tabstractrecorddef):integer;
  148. begin
  149. result:=pop_child_hierarchy(obj);
  150. if obj.owner.symtabletype in [ObjectSymtable,recordsymtable] then
  151. inc(result,pop_nested_hierarchy(tabstractrecorddef(obj.owner.defowner)));
  152. end;
  153. procedure check_msg_para(p:TObject;arg:pointer);
  154. begin
  155. if (tsym(p).typ<>paravarsym) then
  156. exit;
  157. with tparavarsym(p) do
  158. begin
  159. { Count parameters }
  160. if (paranr>=10) then
  161. inc(plongint(arg)^);
  162. { First parameter must be var }
  163. if (paranr=10) and
  164. (varspez<>vs_var) then
  165. MessagePos(fileinfo,parser_e_ill_msg_param);
  166. end;
  167. end;
  168. procedure parse_parameter_dec(pd:tabstractprocdef);
  169. {
  170. handle_procvar needs the same changes
  171. }
  172. type
  173. tppv = (pv_none,pv_proc,pv_func);
  174. var
  175. sc : TFPObjectList;
  176. hdef : tdef;
  177. arrayelementdef : tdef;
  178. vs : tparavarsym;
  179. i : longint;
  180. srsym : tsym;
  181. pv : tprocvardef;
  182. varspez : Tvarspez;
  183. defaultvalue : tconstsym;
  184. defaultrequired : boolean;
  185. old_block_type : tblock_type;
  186. currparast : tparasymtable;
  187. parseprocvar : tppv;
  188. locationstr : string;
  189. paranr : integer;
  190. dummytype : ttypesym;
  191. explicit_paraloc,
  192. need_array,
  193. is_univ: boolean;
  194. stoptions : TSingleTypeOptions;
  195. procedure handle_default_para_value;
  196. var
  197. convpd : tprocdef;
  198. doconv : tconverttype;
  199. nodetype : tnodetype;
  200. bt : tblock_type;
  201. begin
  202. { only allowed for types that can be represented by a
  203. constant expression }
  204. if try_to_consume(_EQ) then
  205. begin
  206. if (hdef.typ in [recorddef,variantdef,filedef,formaldef]) or
  207. is_object(hdef) or
  208. ((hdef.typ=arraydef) and
  209. not is_dynamic_array(hdef)) then
  210. Message1(type_e_invalid_default_value,FullTypeName(hdef,nil));
  211. vs:=tparavarsym(sc[0]);
  212. if sc.count>1 then
  213. Message(parser_e_default_value_only_one_para);
  214. if not(vs.varspez in [vs_value,vs_const,vs_constref]) then
  215. Message(parser_e_default_value_val_const);
  216. bt:=block_type;
  217. block_type:=bt_const;
  218. { prefix 'def' to the parameter name }
  219. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo,nodetype);
  220. block_type:=bt;
  221. if assigned(defaultvalue) then
  222. begin
  223. include(defaultvalue.symoptions,sp_internal);
  224. pd.parast.insert(defaultvalue);
  225. { check whether the default value is of the correct
  226. type }
  227. if compare_defs_ext(defaultvalue.constdef,hdef,nodetype,doconv,convpd,[])<=te_convert_operator then
  228. MessagePos2(defaultvalue.fileinfo,type_e_incompatible_types,FullTypeName(defaultvalue.constdef,hdef),FullTypeName(hdef,defaultvalue.constdef));
  229. end;
  230. defaultrequired:=true;
  231. end
  232. else
  233. begin
  234. if defaultrequired then
  235. Message1(parser_e_default_value_expected_for_para,vs.name);
  236. end;
  237. end;
  238. begin
  239. old_block_type:=block_type;
  240. explicit_paraloc:=false;
  241. consume(_LKLAMMER);
  242. { Delphi/Kylix supports nonsense like }
  243. { procedure p(); }
  244. if try_to_consume(_RKLAMMER) and
  245. not(m_tp7 in current_settings.modeswitches) then
  246. exit;
  247. { parsing a proc or procvar ? }
  248. currparast:=tparasymtable(pd.parast);
  249. { reset }
  250. sc:=TFPObjectList.create(false);
  251. defaultrequired:=false;
  252. paranr:=0;
  253. block_type:=bt_var;
  254. is_univ:=false;
  255. repeat
  256. parseprocvar:=pv_none;
  257. if try_to_consume(_VAR) then
  258. varspez:=vs_var
  259. else
  260. if try_to_consume(_CONST) then
  261. varspez:=vs_const
  262. else
  263. if (m_out in current_settings.modeswitches) and
  264. try_to_consume(_OUT) then
  265. varspez:=vs_out
  266. else
  267. if try_to_consume(_CONSTREF) then
  268. varspez:=vs_constref
  269. else
  270. if (m_mac in current_settings.modeswitches) and
  271. try_to_consume(_POINTPOINTPOINT) then
  272. begin
  273. include(pd.procoptions,po_varargs);
  274. break;
  275. end
  276. else
  277. if (m_nested_procvars in current_settings.modeswitches) and
  278. try_to_consume(_PROCEDURE) then
  279. begin
  280. parseprocvar:=pv_proc;
  281. varspez:=vs_const;
  282. end
  283. else
  284. if (m_nested_procvars in current_settings.modeswitches) and
  285. try_to_consume(_FUNCTION) then
  286. begin
  287. parseprocvar:=pv_func;
  288. varspez:=vs_const;
  289. end
  290. else
  291. varspez:=vs_value;
  292. defaultvalue:=nil;
  293. hdef:=nil;
  294. { read identifiers and insert with error type }
  295. sc.clear;
  296. repeat
  297. inc(paranr);
  298. vs:=cparavarsym.create(orgpattern,paranr*10,varspez,generrordef,[]);
  299. currparast.insert(vs);
  300. if assigned(vs.owner) then
  301. sc.add(vs)
  302. else
  303. vs.free;
  304. consume(_ID);
  305. until not try_to_consume(_COMMA);
  306. locationstr:='';
  307. { macpas anonymous procvar }
  308. if parseprocvar<>pv_none then
  309. begin
  310. { inline procvar definitions are always nested procvars }
  311. pv:=cprocvardef.create(normal_function_level+1);
  312. if token=_LKLAMMER then
  313. parse_parameter_dec(pv);
  314. if parseprocvar=pv_func then
  315. begin
  316. block_type:=bt_var_type;
  317. consume(_COLON);
  318. single_type(pv.returndef,[]);
  319. block_type:=bt_var;
  320. end;
  321. hdef:=pv;
  322. { possible proc directives }
  323. if check_proc_directive(true) then
  324. begin
  325. dummytype:=ctypesym.create('unnamed',hdef);
  326. parse_var_proc_directives(tsym(dummytype));
  327. dummytype.typedef:=nil;
  328. hdef.typesym:=nil;
  329. dummytype.free;
  330. end;
  331. { Add implicit hidden parameters and function result }
  332. handle_calling_convention(pv,hcc_default_actions_intf);
  333. {$ifdef jvm}
  334. { anonymous -> no name }
  335. jvm_create_procvar_class('',pv);
  336. {$endif}
  337. end
  338. else
  339. { read type declaration, force reading for value paras }
  340. if (token=_COLON) or (varspez=vs_value) then
  341. begin
  342. consume(_COLON);
  343. { check for an open array }
  344. need_array:=false;
  345. { bitpacked open array are not yet supported }
  346. if (token=_PACKED) and
  347. not(cs_bitpacking in current_settings.localswitches) then
  348. begin
  349. consume(_PACKED);
  350. need_array:=true;
  351. end;
  352. if (token=_ARRAY) or
  353. need_array then
  354. begin
  355. consume(_ARRAY);
  356. consume(_OF);
  357. { define range and type of range }
  358. hdef:=carraydef.create_openarray;
  359. { array of const ? }
  360. if (token=_CONST) and (m_objpas in current_settings.modeswitches) then
  361. begin
  362. consume(_CONST);
  363. srsym:=search_system_type('TVARREC');
  364. tarraydef(hdef).elementdef:=ttypesym(srsym).typedef;
  365. include(tarraydef(hdef).arrayoptions,ado_IsArrayOfConst);
  366. end
  367. else
  368. begin
  369. { define field type }
  370. if m_delphi in current_settings.modeswitches then
  371. stoptions:=[stoAllowSpecialization]
  372. else
  373. stoptions:=[];
  374. single_type(arrayelementdef,stoptions);
  375. tarraydef(hdef).elementdef:=arrayelementdef;
  376. end;
  377. end
  378. else
  379. begin
  380. if (m_mac in current_settings.modeswitches) then
  381. is_univ:=try_to_consume(_UNIV);
  382. if try_to_consume(_TYPE) then
  383. hdef:=ctypedformaltype
  384. else
  385. begin
  386. block_type:=bt_var_type;
  387. single_type(hdef,[stoAllowSpecialization]);
  388. block_type:=bt_var;
  389. end;
  390. { open string ? }
  391. if is_shortstring(hdef) then
  392. begin
  393. case varspez of
  394. vs_var,vs_out:
  395. begin
  396. { not 100% Delphi-compatible: type xstr=string[255] cannot
  397. become an openstring there, while here it can }
  398. if (cs_openstring in current_settings.moduleswitches) and
  399. (tstringdef(hdef).len=255) then
  400. hdef:=openshortstringtype
  401. end;
  402. vs_value:
  403. begin
  404. { value "openstring" parameters don't make sense (the
  405. original string can never be modified, so there's no
  406. use in passing its original length), so change these
  407. into regular shortstring parameters (seems to be what
  408. Delphi also does) }
  409. if is_open_string(hdef) then
  410. hdef:=cshortstringtype;
  411. end;
  412. else
  413. ;
  414. end;
  415. end;
  416. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  417. begin
  418. if (idtoken=_LOCATION) then
  419. begin
  420. consume(_LOCATION);
  421. locationstr:=cstringpattern;
  422. consume(_CSTRING);
  423. end
  424. else
  425. begin
  426. if explicit_paraloc then
  427. Message(parser_e_paraloc_all_paras);
  428. locationstr:='';
  429. end;
  430. end
  431. else
  432. locationstr:='';
  433. { default parameter }
  434. if (m_default_para in current_settings.modeswitches) then
  435. handle_default_para_value;
  436. end;
  437. end
  438. else
  439. hdef:=cformaltype;
  440. { File types are only allowed for var and out parameters }
  441. if (hdef.typ=filedef) and
  442. not(varspez in [vs_out,vs_var]) then
  443. CGMessage(cg_e_file_must_call_by_reference);
  444. { Dispinterfaces are restricted to using only automatable types }
  445. if (pd.typ=procdef) and is_dispinterface(tprocdef(pd).struct) and
  446. not is_automatable(hdef) then
  447. Message1(type_e_not_automatable,hdef.typename);
  448. { univ cannot be used with types whose size is not known at compile
  449. time }
  450. if is_univ and
  451. not is_valid_univ_para_type(hdef) then
  452. Message1(parser_e_invalid_univ_para,hdef.typename);
  453. for i:=0 to sc.count-1 do
  454. begin
  455. vs:=tparavarsym(sc[i]);
  456. vs.univpara:=is_univ;
  457. { update varsym }
  458. vs.vardef:=hdef;
  459. vs.defaultconstsym:=defaultvalue;
  460. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  461. begin
  462. if locationstr<>'' then
  463. begin
  464. if sc.count>1 then
  465. Message(parser_e_paraloc_only_one_para);
  466. if (paranr>1) and not(explicit_paraloc) then
  467. Message(parser_e_paraloc_all_paras);
  468. explicit_paraloc:=true;
  469. include(vs.varoptions,vo_has_explicit_paraloc);
  470. if not(paramanager.parseparaloc(vs,locationstr)) then
  471. message(parser_e_illegal_explicit_paraloc);
  472. end
  473. else
  474. if explicit_paraloc then
  475. Message(parser_e_paraloc_all_paras);
  476. end;
  477. end;
  478. until not try_to_consume(_SEMICOLON);
  479. if explicit_paraloc then
  480. include(pd.procoptions,po_explicitparaloc);
  481. { remove parasymtable from stack }
  482. sc.free;
  483. { reset object options }
  484. block_type:=old_block_type;
  485. consume(_RKLAMMER);
  486. end;
  487. function parse_proc_head(astruct:tabstractrecorddef;potype:tproctypeoption;isgeneric:boolean;genericdef:tdef;generictypelist:tfphashobjectlist;out pd:tprocdef):boolean;
  488. var
  489. hs : string;
  490. orgsp,sp,orgspnongen,spnongen : TIDString;
  491. dummysym,srsym : tsym;
  492. checkstack : psymtablestackitem;
  493. oldfilepos,
  494. classstartfilepos,
  495. procstartfilepos : tfileposinfo;
  496. i,
  497. index : longint;
  498. addgendummy,
  499. hadspecialize,
  500. firstpart,
  501. found,
  502. searchagain : boolean;
  503. st,
  504. genericst: TSymtable;
  505. aprocsym : tprocsym;
  506. popclass : integer;
  507. ImplIntf : TImplementedInterface;
  508. old_parse_generic : boolean;
  509. old_current_structdef: tabstractrecorddef;
  510. old_current_genericdef,
  511. old_current_specializedef: tstoreddef;
  512. lasttoken,lastidtoken: ttoken;
  513. genericparams : tfphashobjectlist;
  514. procedure parse_operator_name;
  515. begin
  516. if (lasttoken in [first_overloaded..last_overloaded]) then
  517. begin
  518. optoken:=token;
  519. end
  520. else
  521. begin
  522. case lasttoken of
  523. _CARET:
  524. Message1(parser_e_overload_operator_failed,'**');
  525. _ID:
  526. case lastidtoken of
  527. _ENUMERATOR:optoken:=_OP_ENUMERATOR;
  528. _EXPLICIT:optoken:=_OP_EXPLICIT;
  529. _INC:optoken:=_OP_INC;
  530. _DEC:optoken:=_OP_DEC;
  531. _INITIALIZE:optoken:=_OP_INITIALIZE;
  532. _FINALIZE:optoken:=_OP_FINALIZE;
  533. _ADDREF:optoken:=_OP_ADDREF;
  534. _COPY:optoken:=_OP_COPY;
  535. else
  536. if (m_delphi in current_settings.modeswitches) then
  537. case lastidtoken of
  538. _IMPLICIT:optoken:=_ASSIGNMENT;
  539. _NEGATIVE:optoken:=_MINUS;
  540. _POSITIVE:optoken:=_PLUS;
  541. _LOGICALNOT:optoken:=_OP_NOT;
  542. _IN:optoken:=_OP_IN;
  543. _EQUAL:optoken:=_EQ;
  544. _NOTEQUAL:optoken:=_NE;
  545. _GREATERTHAN:optoken:=_GT;
  546. _GREATERTHANOREQUAL:optoken:=_GTE;
  547. _LESSTHAN:optoken:=_LT;
  548. _LESSTHANOREQUAL:optoken:=_LTE;
  549. _ADD:optoken:=_PLUS;
  550. _SUBTRACT:optoken:=_MINUS;
  551. _MULTIPLY:optoken:=_STAR;
  552. _DIVIDE:optoken:=_SLASH;
  553. _INTDIVIDE:optoken:=_OP_DIV;
  554. _MODULUS:optoken:=_OP_MOD;
  555. _LEFTSHIFT:optoken:=_OP_SHL;
  556. _RIGHTSHIFT:optoken:=_OP_SHR;
  557. _LOGICALAND:optoken:=_OP_AND;
  558. _LOGICALOR:optoken:=_OP_OR;
  559. _LOGICALXOR:optoken:=_OP_XOR;
  560. _BITWISEAND:optoken:=_OP_AND;
  561. _BITWISEOR:optoken:=_OP_OR;
  562. _BITWISEXOR:optoken:=_OP_XOR;
  563. else
  564. Message1(parser_e_overload_operator_failed,'');
  565. end
  566. else
  567. Message1(parser_e_overload_operator_failed,'');
  568. end
  569. else
  570. Message1(parser_e_overload_operator_failed,'');
  571. end;
  572. end;
  573. sp:=overloaded_names[optoken];
  574. orgsp:=sp;
  575. spnongen:=sp;
  576. orgspnongen:=orgsp;
  577. end;
  578. procedure consume_proc_name;
  579. var
  580. s : string;
  581. i : longint;
  582. sym : ttypesym;
  583. begin
  584. lasttoken:=token;
  585. lastidtoken:=idtoken;
  586. if assigned(genericparams) then
  587. for i:=0 to genericparams.count-1 do
  588. begin
  589. sym:=ttypesym(genericparams[i]);
  590. if (sym.typ<>constsym) and tstoreddef(sym.typedef).is_registered then
  591. begin
  592. sym.typedef.free;
  593. sym.typedef:=nil;
  594. end;
  595. sym.free;
  596. end;
  597. genericparams.free;
  598. genericparams:=nil;
  599. hadspecialize:=false;
  600. if potype=potype_operator then
  601. optoken:=NOTOKEN;
  602. if (potype=potype_operator) and (token<>_ID) then
  603. begin
  604. parse_operator_name;
  605. consume(token);
  606. end
  607. else
  608. begin
  609. sp:=pattern;
  610. orgsp:=orgpattern;
  611. spnongen:=sp;
  612. orgspnongen:=orgsp;
  613. if firstpart and
  614. not (m_delphi in current_settings.modeswitches) and
  615. (idtoken=_SPECIALIZE) then
  616. hadspecialize:=true;
  617. consume(_ID);
  618. if (isgeneric or (m_delphi in current_settings.modeswitches)) and
  619. (token in [_LT,_LSHARPBRACKET]) then
  620. begin
  621. consume(token);
  622. if token in [_GT,_RSHARPBRACKET] then
  623. message(type_e_type_id_expected)
  624. else
  625. begin
  626. genericparams:=parse_generic_parameters(true);
  627. if not assigned(genericparams) then
  628. internalerror(2015061201);
  629. if genericparams.count=0 then
  630. internalerror(2015061202);
  631. s:='';
  632. str(genericparams.count,s);
  633. spnongen:=sp;
  634. orgspnongen:=orgsp;
  635. sp:=sp+'$'+s;
  636. orgsp:=orgsp+'$'+s;
  637. end;
  638. if not try_to_consume(_GT) then
  639. consume(_RSHARPBRACKET);
  640. end;
  641. end;
  642. firstpart:=false;
  643. end;
  644. function search_object_name(const sp:TIDString;gen_error:boolean):tsym;
  645. var
  646. storepos:tfileposinfo;
  647. srsymtable:TSymtable;
  648. begin
  649. storepos:=current_tokenpos;
  650. current_tokenpos:=procstartfilepos;
  651. searchsym(sp,result,srsymtable);
  652. if not assigned(result) then
  653. begin
  654. if gen_error then
  655. identifier_not_found(orgsp);
  656. result:=generrorsym;
  657. end;
  658. current_tokenpos:=storepos;
  659. end;
  660. procedure consume_generic_interface;
  661. var
  662. genparalist : tfpobjectlist;
  663. prettyname,
  664. specializename : ansistring;
  665. genname,
  666. ugenname : tidstring;
  667. gencount : string;
  668. begin
  669. consume(_LSHARPBRACKET);
  670. genparalist:=tfpobjectlist.create(false);
  671. if not parse_generic_specialization_types(genparalist,nil,prettyname,specializename) then
  672. srsym:=generrorsym
  673. else
  674. begin
  675. str(genparalist.count,gencount);
  676. genname:=sp+'$'+gencount;
  677. { ToDo: handle nested interfaces }
  678. genname:=generate_generic_name(genname,specializename,'');
  679. ugenname:=upper(genname);
  680. srsym:=search_object_name(ugenname,false);
  681. if not assigned(srsym) then
  682. begin
  683. Message1(type_e_generic_declaration_does_not_match,sp+'<'+prettyname+'>');
  684. srsym:=nil;
  685. exit;
  686. end;
  687. end;
  688. genparalist.free;
  689. consume(_RSHARPBRACKET);
  690. end;
  691. function handle_generic_interface:boolean;
  692. var
  693. i : longint;
  694. sym : ttypesym;
  695. typesrsym : tsym;
  696. typesrsymtable : tsymtable;
  697. specializename,
  698. prettyname: ansistring;
  699. error : boolean;
  700. genname,
  701. ugenname : tidstring;
  702. module : tmodule;
  703. begin
  704. result:=false;
  705. if not assigned(genericparams) then
  706. exit;
  707. specializename:='$';
  708. prettyname:='';
  709. error:=false;
  710. for i:=0 to genericparams.count-1 do
  711. begin
  712. sym:=ttypesym(genericparams[i]);
  713. { ToDo: position }
  714. if not searchsym(upper(sym.RealName),typesrsym,typesrsymtable) then
  715. begin
  716. message1(sym_e_id_not_found,sym.name);
  717. error:=true;
  718. continue;
  719. end;
  720. if typesrsym.typ<>typesym then
  721. begin
  722. message(type_e_type_id_expected);
  723. error:=true;
  724. continue;
  725. end;
  726. module:=find_module_from_symtable(ttypesym(typesrsym).typedef.owner);
  727. if not assigned(module) then
  728. internalerror(2016112803);
  729. specializename:=specializename+'_$'+hexstr(module.moduleid,8)+'$$'+ttypesym(typesrsym).typedef.unique_id_str;
  730. if i>0 then
  731. prettyname:=prettyname+',';
  732. prettyname:=prettyname+ttypesym(typesrsym).prettyname;
  733. end;
  734. result:=true;
  735. if error then
  736. begin
  737. srsym:=generrorsym;
  738. exit;
  739. end;
  740. { ToDo: handle nested interfaces }
  741. genname:=generate_generic_name(sp,specializename,'');
  742. ugenname:=upper(genname);
  743. srsym:=search_object_name(ugenname,false);
  744. if not assigned(srsym) then
  745. begin
  746. Message1(type_e_generic_declaration_does_not_match,sp+'<'+prettyname+'>');
  747. srsym:=generrorsym;
  748. end;
  749. end;
  750. procedure specialize_generic_interface;
  751. var
  752. node : tnode;
  753. begin
  754. node:=factor(false,[ef_type_only,ef_had_specialize]);
  755. if node.nodetype=typen then
  756. begin
  757. sp:=ttypenode(node).typedef.typesym.name;
  758. end
  759. else
  760. sp:='';
  761. end;
  762. function check_generic_parameters(def:tstoreddef):boolean;
  763. var
  764. i : longint;
  765. declsym,
  766. implsym : tsym;
  767. impltype : ttypesym absolute implsym;
  768. implname : tsymstr;
  769. fileinfo : tfileposinfo;
  770. begin
  771. result:=true;
  772. if not assigned(def.genericparas) then
  773. internalerror(2018090102);
  774. if not assigned(genericparams) then
  775. internalerror(2018090103);
  776. if def.genericparas.count<>genericparams.count then
  777. internalerror(2018090104);
  778. for i:=0 to def.genericparas.count-1 do
  779. begin
  780. declsym:=tsym(def.genericparas[i]);
  781. implsym:=tsym(genericparams[i]);
  782. implname:=upper(genericparams.nameofindex(i));
  783. if declsym.name<>implname then
  784. begin
  785. messagepos1(implsym.fileinfo,sym_e_generic_type_param_mismatch,implsym.realname);
  786. messagepos1(declsym.fileinfo,sym_e_generic_type_param_decl,declsym.realname);
  787. result:=false;
  788. end;
  789. if ((implsym.typ=typesym) and (df_genconstraint in impltype.typedef.defoptions)) or
  790. (implsym.typ=constsym) then
  791. begin
  792. if implsym.typ=constsym then
  793. fileinfo:=impltype.fileinfo
  794. else
  795. fileinfo:=tstoreddef(impltype.typedef).genconstraintdata.fileinfo;
  796. messagepos(fileinfo,parser_e_generic_constraints_not_allowed_here);
  797. result:=false;
  798. end;
  799. end;
  800. end;
  801. begin
  802. sp:='';
  803. orgsp:='';
  804. spnongen:='';
  805. orgspnongen:='';
  806. { Save the position where this procedure really starts }
  807. procstartfilepos:=current_tokenpos;
  808. old_parse_generic:=parse_generic;
  809. firstpart:=true;
  810. result:=false;
  811. pd:=nil;
  812. aprocsym:=nil;
  813. srsym:=nil;
  814. genericparams:=nil;
  815. hadspecialize:=false;
  816. addgendummy:=false;
  817. if not assigned(genericdef) then
  818. begin
  819. consume_proc_name;
  820. { examine interface map: function/procedure iname.functionname=locfuncname }
  821. if assigned(astruct) and
  822. (astruct.typ=objectdef) and
  823. assigned(tobjectdef(astruct).ImplementedInterfaces) and
  824. (tobjectdef(astruct).ImplementedInterfaces.count>0) and
  825. (
  826. (token=_POINT) or
  827. (
  828. hadspecialize and
  829. (token=_ID)
  830. )
  831. ) then
  832. begin
  833. if hadspecialize and (token=_ID) then
  834. specialize_generic_interface;
  835. consume(_POINT);
  836. if hadspecialize or not handle_generic_interface then
  837. srsym:=search_object_name(sp,true);
  838. { qualifier is interface? }
  839. ImplIntf:=nil;
  840. if assigned(srsym) and
  841. (srsym.typ=typesym) and
  842. (ttypesym(srsym).typedef.typ=objectdef) then
  843. ImplIntf:=find_implemented_interface(tobjectdef(astruct),tobjectdef(ttypesym(srsym).typedef));
  844. if ImplIntf=nil then
  845. begin
  846. Message(parser_e_interface_id_expected);
  847. { error recovery }
  848. consume(_ID);
  849. if try_to_consume(_EQ) then
  850. consume(_ID);
  851. exit;
  852. end
  853. else
  854. { in case of a generic or specialized interface we need to use the
  855. name of the def instead of the symbol, so that always the correct
  856. name is used }
  857. if [df_generic,df_specialization]*ttypesym(srsym).typedef.defoptions<>[] then
  858. sp:=tobjectdef(ttypesym(srsym).typedef).objname^;
  859. { must be a directly implemented interface }
  860. if Assigned(ImplIntf.ImplementsGetter) then
  861. Message2(parser_e_implements_no_mapping,ImplIntf.IntfDef.typename,astruct.objrealname^);
  862. consume(_ID);
  863. { Create unique name <interface>.<method> }
  864. hs:=sp+'.'+pattern;
  865. consume(_EQ);
  866. if assigned(ImplIntf) and
  867. (token=_ID) then
  868. ImplIntf.AddMapping(hs,pattern);
  869. consume(_ID);
  870. result:=true;
  871. exit;
  872. end;
  873. if assigned(genericparams) and assigned(current_genericdef) then
  874. Message(parser_f_no_generic_inside_generic);
  875. { method ? }
  876. srsym:=nil;
  877. if not assigned(astruct) and
  878. (symtablestack.top.symtablelevel=main_program_level) and
  879. try_to_consume(_POINT) then
  880. begin
  881. repeat
  882. classstartfilepos:=procstartfilepos;
  883. searchagain:=false;
  884. { throw the error at the right location }
  885. oldfilepos:=current_filepos;
  886. current_filepos:=procstartfilepos;
  887. if not assigned(astruct) and not assigned(srsym) then
  888. srsym:=search_object_name(sp,true);
  889. current_filepos:=oldfilepos;
  890. { we need to check whether the names of the generic parameter
  891. types match with the one in the declaration of a class/record,
  892. but we need to do this before consume_proc_name frees the
  893. type parameters of the class part }
  894. if (srsym.typ=typesym) and
  895. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) and
  896. tstoreddef(ttypesym(srsym).typedef).is_generic and
  897. assigned(genericparams) then
  898. { this is recoverable, so no further action necessary }
  899. check_generic_parameters(tstoreddef(ttypesym(srsym).typedef));
  900. { consume proc name }
  901. procstartfilepos:=current_tokenpos;
  902. consume_proc_name;
  903. { qualifier is class name ? }
  904. if (srsym.typ=typesym) and
  905. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) then
  906. begin
  907. astruct:=tabstractrecorddef(ttypesym(srsym).typedef);
  908. if (token<>_POINT) then
  909. if (potype in [potype_class_constructor,potype_class_destructor]) then
  910. sp:=lower(sp)
  911. else
  912. if (potype=potype_operator) and (optoken=NOTOKEN) then
  913. parse_operator_name;
  914. srsym:=tsym(astruct.symtable.Find(sp));
  915. if assigned(srsym) then
  916. begin
  917. if srsym.typ=procsym then
  918. aprocsym:=tprocsym(srsym)
  919. else
  920. if (srsym.typ=typesym) and
  921. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) then
  922. begin
  923. searchagain:=true;
  924. consume(_POINT);
  925. end
  926. else
  927. begin
  928. { we use a different error message for tp7 so it looks more compatible }
  929. if (m_fpc in current_settings.modeswitches) then
  930. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  931. else
  932. Message(parser_e_methode_id_expected);
  933. { rename the name to an unique name to avoid an
  934. error when inserting the symbol in the symtable }
  935. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  936. end;
  937. end
  938. else
  939. begin
  940. MessagePos(procstartfilepos,parser_e_methode_id_expected);
  941. { recover by making it a normal procedure instead of method }
  942. astruct:=nil;
  943. end;
  944. end
  945. else
  946. MessagePos(classstartfilepos,parser_e_class_id_expected);
  947. until not searchagain;
  948. end
  949. else
  950. begin
  951. { check for constructor/destructor/class operators which are not allowed here }
  952. if (not parse_only) and
  953. ((potype in [potype_constructor,potype_destructor,
  954. potype_class_constructor,potype_class_destructor]) or
  955. ((potype=potype_operator) and (m_delphi in current_settings.modeswitches))) then
  956. Message(parser_e_only_methods_allowed);
  957. repeat
  958. { only 1 class constructor and destructor is allowed in the class and
  959. the check was already done with oo_has_class_constructor or
  960. oo_has_class_destructor -> skip searching
  961. (bug #28801) }
  962. if (potype in [potype_class_constructor,potype_class_destructor]) then
  963. break;
  964. searchagain:=false;
  965. current_tokenpos:=procstartfilepos;
  966. if (potype=potype_operator)and(optoken=NOTOKEN) then
  967. parse_operator_name;
  968. srsym:=tsym(symtablestack.top.Find(sp));
  969. { Also look in the globalsymtable if we didn't found
  970. the symbol in the localsymtable }
  971. if not assigned(srsym) and
  972. not(parse_only) and
  973. (symtablestack.top=current_module.localsymtable) and
  974. assigned(current_module.globalsymtable) then
  975. srsym:=tsym(current_module.globalsymtable.Find(sp));
  976. { Check if overloaded is a procsym }
  977. if assigned(srsym) then
  978. begin
  979. if srsym.typ=procsym then
  980. aprocsym:=tprocsym(srsym)
  981. else
  982. begin
  983. { when the other symbol is a unit symbol then hide the unit
  984. symbol, this is not supported in tp7 }
  985. if not(m_tp7 in current_settings.modeswitches) and
  986. (srsym.typ=unitsym) then
  987. begin
  988. HideSym(srsym);
  989. searchagain:=true;
  990. end
  991. else
  992. if (m_delphi in current_settings.modeswitches) and
  993. (srsym.typ=absolutevarsym) and
  994. ([vo_is_funcret,vo_is_result]*tabstractvarsym(srsym).varoptions=[vo_is_funcret]) then
  995. begin
  996. HideSym(srsym);
  997. searchagain:=true;
  998. end
  999. else if (srsym.typ=typesym) and
  1000. (sp_generic_dummy in srsym.symoptions) and
  1001. (ttypesym(srsym).typedef.typ=undefineddef) and
  1002. not assigned(genericparams) then
  1003. begin
  1004. { this is a generic dummy symbol that has not yet
  1005. been used; so we rename the dummy symbol and continue
  1006. as if nothing happened }
  1007. hidesym(srsym);
  1008. searchagain:=true;
  1009. addgendummy:=true;
  1010. end
  1011. else
  1012. begin
  1013. { we use a different error message for tp7 so it looks more compatible }
  1014. if (m_fpc in current_settings.modeswitches) then
  1015. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  1016. else
  1017. Message1(sym_e_duplicate_id,srsym.realname);
  1018. { rename the name to an unique name to avoid an
  1019. error when inserting the symbol in the symtable }
  1020. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  1021. end;
  1022. end;
  1023. end;
  1024. until not searchagain;
  1025. end;
  1026. { test again if assigned, it can be reset to recover }
  1027. if not assigned(aprocsym) then
  1028. begin
  1029. { create a new procsym and set the real filepos }
  1030. current_tokenpos:=procstartfilepos;
  1031. { for operator we have only one procsym for each overloaded
  1032. operation }
  1033. if (potype=potype_operator) then
  1034. begin
  1035. aprocsym:=Tprocsym(symtablestack.top.Find(sp));
  1036. if aprocsym=nil then
  1037. aprocsym:=cprocsym.create('$'+sp);
  1038. end
  1039. else
  1040. if (potype in [potype_class_constructor,potype_class_destructor]) then
  1041. aprocsym:=cprocsym.create('$'+lower(sp))
  1042. else
  1043. aprocsym:=cprocsym.create(orgsp);
  1044. if addgendummy then
  1045. include(aprocsym.symoptions,sp_generic_dummy);
  1046. symtablestack.top.insert(aprocsym);
  1047. end;
  1048. end;
  1049. { to get the correct symtablelevel we must ignore ObjectSymtables }
  1050. st:=nil;
  1051. checkstack:=symtablestack.stack;
  1052. while assigned(checkstack) do
  1053. begin
  1054. st:=checkstack^.symtable;
  1055. if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
  1056. break;
  1057. checkstack:=checkstack^.next;
  1058. end;
  1059. pd:=cprocdef.create(st.symtablelevel+1,not assigned(genericdef));
  1060. pd.struct:=astruct;
  1061. pd.procsym:=aprocsym;
  1062. pd.proctypeoption:=potype;
  1063. if assigned(genericparams) then
  1064. begin
  1065. if potype=potype_constructor then
  1066. begin
  1067. Message(parser_e_constructurs_cannot_take_type_parameters);
  1068. genericparams.free;
  1069. genericparams:=nil;
  1070. end
  1071. else
  1072. begin
  1073. include(pd.defoptions,df_generic);
  1074. { push the parameter symtable so that constraint definitions are added
  1075. there and not in the owner symtable }
  1076. symtablestack.push(pd.parast);
  1077. { register the parameters }
  1078. for i:=0 to genericparams.count-1 do
  1079. begin
  1080. tsym(genericparams[i]).register_sym;
  1081. if tsym(genericparams[i]).typ=typesym then
  1082. tstoreddef(ttypesym(genericparams[i]).typedef).register_def;
  1083. end;
  1084. insert_generic_parameter_types(pd,nil,genericparams);
  1085. { the list is no longer required }
  1086. genericparams.free;
  1087. genericparams:=nil;
  1088. symtablestack.pop(pd.parast);
  1089. parse_generic:=true;
  1090. { also generate a dummy symbol if none exists already }
  1091. if assigned(astruct) then
  1092. dummysym:=tsym(astruct.symtable.find(spnongen))
  1093. else
  1094. begin
  1095. dummysym:=tsym(symtablestack.top.find(spnongen));
  1096. if not assigned(dummysym) and
  1097. (symtablestack.top=current_module.localsymtable) and
  1098. assigned(current_module.globalsymtable) then
  1099. dummysym:=tsym(current_module.globalsymtable.find(spnongen));
  1100. end;
  1101. if not assigned(dummysym) then
  1102. begin
  1103. { overloading generic routines with non-generic types is not
  1104. allowed, so we create a procsym as dummy }
  1105. dummysym:=cprocsym.create(orgspnongen);
  1106. if assigned(astruct) then
  1107. astruct.symtable.insert(dummysym)
  1108. else
  1109. symtablestack.top.insert(dummysym);
  1110. end
  1111. else if (dummysym.typ<>procsym) and
  1112. (
  1113. { show error only for the declaration, not also the implementation }
  1114. not assigned(astruct) or
  1115. (symtablestack.top.symtablelevel<>main_program_level)
  1116. ) then
  1117. Message1(sym_e_duplicate_id,dummysym.realname);
  1118. if not (sp_generic_dummy in dummysym.symoptions) then
  1119. begin
  1120. include(dummysym.symoptions,sp_generic_dummy);
  1121. add_generic_dummysym(dummysym);
  1122. end;
  1123. if dummysym.typ=procsym then
  1124. tprocsym(dummysym).add_generic_overload(aprocsym);
  1125. { start token recorder for the declaration }
  1126. pd.init_genericdecl;
  1127. current_scanner.startrecordtokens(pd.genericdecltokenbuf);
  1128. end;
  1129. end
  1130. else if assigned(genericdef) then
  1131. insert_generic_parameter_types(pd,tstoreddef(genericdef),generictypelist);
  1132. { methods inherit df_generic or df_specialization from the objectdef }
  1133. if assigned(pd.struct) and
  1134. (pd.parast.symtablelevel=normal_function_level) then
  1135. begin
  1136. if (df_generic in pd.struct.defoptions) then
  1137. begin
  1138. include(pd.defoptions,df_generic);
  1139. parse_generic:=true;
  1140. end;
  1141. if (df_specialization in pd.struct.defoptions) then
  1142. begin
  1143. if assigned(current_specializedef) then
  1144. begin
  1145. include(pd.defoptions,df_specialization);
  1146. { Find corresponding genericdef, we need it later to
  1147. replay the tokens to generate the body }
  1148. if not assigned(pd.struct.genericdef) then
  1149. internalerror(200512113);
  1150. genericst:=pd.struct.genericdef.GetSymtable(gs_record);
  1151. if not assigned(genericst) then
  1152. internalerror(200512114);
  1153. { when searching for the correct procdef to use as genericdef we need to ignore
  1154. everything except procdefs so that we can find the correct indices }
  1155. index:=0;
  1156. found:=false;
  1157. for i:=0 to pd.owner.deflist.count-1 do
  1158. begin
  1159. if tdef(pd.owner.deflist[i]).typ<>procdef then
  1160. continue;
  1161. if pd.owner.deflist[i]=pd then
  1162. begin
  1163. found:=true;
  1164. break;
  1165. end;
  1166. inc(index);
  1167. end;
  1168. if not found then
  1169. internalerror(2014052301);
  1170. for i:=0 to genericst.deflist.count-1 do
  1171. begin
  1172. if tdef(genericst.deflist[i]).typ<>procdef then
  1173. continue;
  1174. if index=0 then
  1175. pd.genericdef:=tstoreddef(genericst.deflist[i]);
  1176. dec(index);
  1177. end;
  1178. if not assigned(pd.genericdef) or
  1179. (pd.genericdef.typ<>procdef) then
  1180. internalerror(200512115);
  1181. end
  1182. else
  1183. Message(parser_e_explicit_method_implementation_for_specializations_not_allowed);
  1184. end;
  1185. end;
  1186. { methods need to be exported }
  1187. if assigned(astruct) and
  1188. (
  1189. (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) or
  1190. (symtablestack.top.symtablelevel=main_program_level)
  1191. ) then
  1192. include(pd.procoptions,po_global);
  1193. { symbol options that need to be kept per procdef }
  1194. pd.fileinfo:=procstartfilepos;
  1195. pd.visibility:=symtablestack.top.currentvisibility;
  1196. if symtablestack.top.currentlyoptional then
  1197. include(pd.procoptions,po_optional);
  1198. { parse parameters }
  1199. if token=_LKLAMMER then
  1200. begin
  1201. old_current_structdef:=nil;
  1202. old_current_genericdef:=current_genericdef;
  1203. old_current_specializedef:=nil;
  1204. { Add ObjectSymtable to be able to find nested type definitions }
  1205. popclass:=0;
  1206. if assigned(pd.struct) and
  1207. (pd.parast.symtablelevel>=normal_function_level) and
  1208. not(symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1209. begin
  1210. popclass:=push_nested_hierarchy(pd.struct);
  1211. old_current_structdef:=current_structdef;
  1212. old_current_specializedef:=current_specializedef;
  1213. current_structdef:=pd.struct;
  1214. if assigned(current_structdef) and (df_generic in current_structdef.defoptions) then
  1215. current_genericdef:=current_structdef;
  1216. if assigned(current_structdef) and (df_specialization in current_structdef.defoptions) then
  1217. current_specializedef:=current_structdef;
  1218. end;
  1219. if pd.is_generic then
  1220. current_genericdef:=pd;
  1221. { Add parameter symtable }
  1222. if pd.parast.symtabletype<>staticsymtable then
  1223. symtablestack.push(pd.parast);
  1224. parse_parameter_dec(pd);
  1225. if pd.parast.symtabletype<>staticsymtable then
  1226. symtablestack.pop(pd.parast);
  1227. current_genericdef:=old_current_genericdef;
  1228. if popclass>0 then
  1229. begin
  1230. current_structdef:=old_current_structdef;
  1231. current_specializedef:=old_current_specializedef;
  1232. dec(popclass,pop_nested_hierarchy(pd.struct));
  1233. if popclass<>0 then
  1234. internalerror(201011260); // 11 nov 2010 index 0
  1235. end;
  1236. end;
  1237. parse_generic:=old_parse_generic;
  1238. result:=true;
  1239. end;
  1240. procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean;astruct:tabstractrecorddef);
  1241. var
  1242. locationstr: string;
  1243. i: integer;
  1244. found: boolean;
  1245. procedure read_returndef(pd: tprocdef);
  1246. var
  1247. popclass: integer;
  1248. old_parse_generic: boolean;
  1249. old_current_structdef: tabstractrecorddef;
  1250. old_current_genericdef,
  1251. old_current_specializedef: tstoreddef;
  1252. begin
  1253. old_parse_generic:=parse_generic;
  1254. { Add ObjectSymtable to be able to find generic type definitions }
  1255. popclass:=0;
  1256. old_current_structdef:=nil;
  1257. old_current_genericdef:=current_genericdef;
  1258. old_current_specializedef:=current_specializedef;
  1259. current_genericdef:=nil;
  1260. current_specializedef:=nil;
  1261. if assigned(pd.struct) and
  1262. (pd.parast.symtablelevel>=normal_function_level) and
  1263. not (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1264. begin
  1265. popclass:=push_nested_hierarchy(pd.struct);
  1266. old_current_structdef:=current_structdef;
  1267. current_structdef:=pd.struct;
  1268. end;
  1269. if df_generic in pd.defoptions then
  1270. begin
  1271. if pd.is_generic then
  1272. current_genericdef:=pd
  1273. else if assigned(pd.struct) then
  1274. current_genericdef:=pd.struct
  1275. else
  1276. internalerror(2016090202);
  1277. end;
  1278. if df_specialization in pd.defoptions then
  1279. begin
  1280. if pd.is_specialization then
  1281. current_specializedef:=pd
  1282. else if assigned(pd.struct) then
  1283. current_specializedef:=pd.struct
  1284. else
  1285. internalerror(2016090203);
  1286. end;
  1287. parse_generic:=(df_generic in pd.defoptions);
  1288. if pd.is_generic or pd.is_specialization then
  1289. symtablestack.push(pd.parast);
  1290. pd.returndef:=result_type([stoAllowSpecialization]);
  1291. // Issue #24863, enabled only for the main progra commented out for now because it breaks building of RTL and needs extensive
  1292. // testing and/or RTL patching.
  1293. {
  1294. if ((pd.returndef=cvarianttype) or (pd.returndef=colevarianttype)) and
  1295. not(cs_compilesystem in current_settings.moduleswitches) then
  1296. include(current_module.moduleflags,mf_uses_variants);
  1297. }
  1298. if is_dispinterface(pd.struct) and not is_automatable(pd.returndef) then
  1299. Message1(type_e_not_automatable,pd.returndef.typename);
  1300. if pd.is_generic or pd.is_specialization then
  1301. symtablestack.pop(pd.parast);
  1302. if popclass>0 then
  1303. begin
  1304. current_structdef:=old_current_structdef;
  1305. dec(popclass,pop_nested_hierarchy(pd.struct));
  1306. if popclass<>0 then
  1307. internalerror(201012020);
  1308. end;
  1309. current_genericdef:=old_current_genericdef;
  1310. current_specializedef:=old_current_specializedef;
  1311. parse_generic:=old_parse_generic;
  1312. end;
  1313. begin
  1314. locationstr:='';
  1315. case pd.proctypeoption of
  1316. potype_procedure:
  1317. begin
  1318. pd.returndef:=voidtype;
  1319. if isclassmethod then
  1320. include(pd.procoptions,po_classmethod);
  1321. end;
  1322. potype_function:
  1323. begin
  1324. if try_to_consume(_COLON) then
  1325. begin
  1326. read_returndef(pd);
  1327. if (target_info.system in [system_m68k_amiga]) then
  1328. begin
  1329. if (idtoken=_LOCATION) then
  1330. begin
  1331. if po_explicitparaloc in pd.procoptions then
  1332. begin
  1333. consume(_LOCATION);
  1334. locationstr:=cstringpattern;
  1335. consume(_CSTRING);
  1336. end
  1337. else
  1338. { I guess this needs a new message... (KB) }
  1339. Message(parser_e_paraloc_all_paras);
  1340. end
  1341. else
  1342. begin
  1343. if po_explicitparaloc in pd.procoptions then
  1344. { assign default locationstr, if none specified }
  1345. { and we've arguments with explicit paraloc }
  1346. locationstr:='D0';
  1347. end;
  1348. end;
  1349. end
  1350. else
  1351. begin
  1352. if (
  1353. parse_only and
  1354. not(is_interface(pd.struct))
  1355. ) or
  1356. (m_repeat_forward in current_settings.modeswitches) then
  1357. begin
  1358. consume(_COLON);
  1359. consume_all_until(_SEMICOLON);
  1360. end;
  1361. end;
  1362. if isclassmethod then
  1363. include(pd.procoptions,po_classmethod);
  1364. end;
  1365. potype_constructor,
  1366. potype_class_constructor:
  1367. begin
  1368. if not isclassmethod and
  1369. assigned(pd) and
  1370. assigned(pd.struct) then
  1371. begin
  1372. { Set return type, class constructors return the
  1373. created instance, object constructors return boolean }
  1374. if is_class(pd.struct) or
  1375. is_record(pd.struct) or
  1376. is_javaclass(pd.struct) then
  1377. pd.returndef:=pd.struct
  1378. else
  1379. if is_objectpascal_helper(pd.struct) then
  1380. pd.returndef:=tobjectdef(pd.struct).extendeddef
  1381. else
  1382. {$ifdef CPU64bitaddr}
  1383. pd.returndef:=bool64type;
  1384. {$else CPU64bitaddr}
  1385. pd.returndef:=bool32type;
  1386. {$endif CPU64bitaddr}
  1387. end
  1388. else
  1389. pd.returndef:=voidtype;
  1390. end;
  1391. potype_class_destructor,
  1392. potype_destructor:
  1393. begin
  1394. if assigned(pd) then
  1395. pd.returndef:=voidtype;
  1396. end;
  1397. potype_operator:
  1398. begin
  1399. { operators always need to be searched in all units (that
  1400. contain operators) }
  1401. include(pd.procoptions,po_overload);
  1402. pd.procsym.owner.includeoption(sto_has_operator);
  1403. if pd.parast.symtablelevel>normal_function_level then
  1404. Message(parser_e_no_local_operator);
  1405. if isclassmethod then
  1406. begin
  1407. include(pd.procoptions,po_classmethod);
  1408. { any class operator is also static }
  1409. include(pd.procoptions,po_staticmethod);
  1410. end;
  1411. if token<>_ID then
  1412. begin
  1413. if not(m_result in current_settings.modeswitches) then
  1414. consume(_ID);
  1415. end
  1416. else
  1417. begin
  1418. pd.resultname:=stringdup(orgpattern);
  1419. consume(_ID);
  1420. end;
  1421. { operators without result (management operators) }
  1422. if optoken in [_OP_INITIALIZE, _OP_FINALIZE, _OP_ADDREF, _OP_COPY] then
  1423. begin
  1424. { single var parameter to point the record }
  1425. if (optoken in [_OP_INITIALIZE, _OP_FINALIZE, _OP_ADDREF]) and
  1426. (
  1427. (pd.parast.SymList.Count<>1) or
  1428. (tparavarsym(pd.parast.SymList[0]).vardef<>pd.struct) or
  1429. (tparavarsym(pd.parast.SymList[0]).varspez<>vs_var)
  1430. ) then
  1431. Message(parser_e_overload_impossible)
  1432. { constref (source) and var (dest) parameter to point the records }
  1433. else if (optoken=_OP_COPY) and
  1434. (
  1435. (pd.parast.SymList.Count<>2) or
  1436. (tparavarsym(pd.parast.SymList[0]).vardef<>pd.struct) or
  1437. (tparavarsym(pd.parast.SymList[0]).varspez<>vs_constref) or
  1438. (tparavarsym(pd.parast.SymList[1]).vardef<>pd.struct) or
  1439. (tparavarsym(pd.parast.SymList[1]).varspez<>vs_var)
  1440. ) then
  1441. Message(parser_e_overload_impossible);
  1442. trecordsymtable(pd.procsym.Owner).includemanagementoperator(
  1443. token2managementoperator(optoken));
  1444. pd.returndef:=voidtype
  1445. end
  1446. else
  1447. if not try_to_consume(_COLON) then
  1448. begin
  1449. consume(_COLON);
  1450. pd.returndef:=generrordef;
  1451. consume_all_until(_SEMICOLON);
  1452. end
  1453. else
  1454. begin
  1455. read_returndef(pd);
  1456. { check that class operators have either return type of structure or }
  1457. { at least one argument of that type }
  1458. if (po_classmethod in pd.procoptions) and
  1459. (pd.returndef <> pd.struct) then
  1460. begin
  1461. found:=false;
  1462. for i := 0 to pd.parast.SymList.Count - 1 do
  1463. if tparavarsym(pd.parast.SymList[i]).vardef=pd.struct then
  1464. begin
  1465. found:=true;
  1466. break;
  1467. end;
  1468. if not found then
  1469. if assigned(pd.struct) then
  1470. Message1(parser_e_at_least_one_argument_must_be_of_type,pd.struct.RttiName)
  1471. else
  1472. MessagePos(pd.fileinfo,type_e_type_id_expected);
  1473. end;
  1474. if not assigned(pd.struct) or assigned(astruct) then
  1475. begin
  1476. if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and
  1477. equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and
  1478. (pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then
  1479. message(parser_e_no_such_assignment)
  1480. else if not isoperatoracceptable(pd,optoken) then
  1481. Message(parser_e_overload_impossible);
  1482. end;
  1483. end;
  1484. end;
  1485. else
  1486. internalerror(2015052202);
  1487. end;
  1488. if (pd.proccalloption in cdecl_pocalls) and
  1489. (pd.paras.count>0) and
  1490. is_array_of_const(tparavarsym(pd.paras[pd.paras.count-1]).vardef) then
  1491. begin
  1492. include(pd.procoptions,po_variadic);
  1493. end;
  1494. { support procedure proc stdcall export; }
  1495. if not(check_proc_directive(false)) then
  1496. begin
  1497. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1498. begin
  1499. message(parser_e_field_not_allowed_here);
  1500. consume_all_until(_SEMICOLON);
  1501. end;
  1502. consume(_SEMICOLON);
  1503. end;
  1504. if locationstr<>'' then
  1505. begin
  1506. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1507. { I guess this needs a new message... (KB) }
  1508. message(parser_e_illegal_explicit_paraloc);
  1509. end;
  1510. end;
  1511. function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef;isgeneric:boolean):tprocdef;
  1512. var
  1513. pd : tprocdef;
  1514. old_block_type : tblock_type;
  1515. recover : boolean;
  1516. procedure finish_intf_mapping;
  1517. begin
  1518. if token=_COLON then
  1519. begin
  1520. message(parser_e_field_not_allowed_here);
  1521. consume_all_until(_SEMICOLON);
  1522. end;
  1523. consume(_SEMICOLON);
  1524. end;
  1525. begin
  1526. pd:=nil;
  1527. recover:=false;
  1528. case token of
  1529. _FUNCTION :
  1530. begin
  1531. consume(_FUNCTION);
  1532. if parse_proc_head(astruct,potype_function,isgeneric,nil,nil,pd) then
  1533. begin
  1534. { pd=nil when it is a interface mapping }
  1535. if assigned(pd) then
  1536. parse_proc_dec_finish(pd,isclassmethod,astruct)
  1537. else
  1538. finish_intf_mapping;
  1539. end
  1540. else
  1541. begin
  1542. { recover }
  1543. consume(_COLON);
  1544. consume_all_until(_SEMICOLON);
  1545. recover:=true;
  1546. end;
  1547. end;
  1548. _PROCEDURE :
  1549. begin
  1550. consume(_PROCEDURE);
  1551. if parse_proc_head(astruct,potype_procedure,isgeneric,nil,nil,pd) then
  1552. begin
  1553. { pd=nil when it is an interface mapping }
  1554. if assigned(pd) then
  1555. parse_proc_dec_finish(pd,isclassmethod,astruct)
  1556. else
  1557. finish_intf_mapping;
  1558. end
  1559. else
  1560. recover:=true;
  1561. end;
  1562. _CONSTRUCTOR :
  1563. begin
  1564. consume(_CONSTRUCTOR);
  1565. if isclassmethod then
  1566. recover:=not parse_proc_head(astruct,potype_class_constructor,false,nil,nil,pd)
  1567. else
  1568. recover:=not parse_proc_head(astruct,potype_constructor,false,nil,nil,pd);
  1569. if not recover then
  1570. parse_proc_dec_finish(pd,isclassmethod,astruct);
  1571. end;
  1572. _DESTRUCTOR :
  1573. begin
  1574. consume(_DESTRUCTOR);
  1575. if isclassmethod then
  1576. recover:=not parse_proc_head(astruct,potype_class_destructor,false,nil,nil,pd)
  1577. else
  1578. recover:=not parse_proc_head(astruct,potype_destructor,false,nil,nil,pd);
  1579. if not recover then
  1580. parse_proc_dec_finish(pd,isclassmethod,astruct);
  1581. end;
  1582. else
  1583. if (token=_OPERATOR) or
  1584. (isclassmethod and (idtoken=_OPERATOR)) then
  1585. begin
  1586. { we need to set the block type to bt_body, so that operator names
  1587. like ">", "=>" or "<>" are parsed correctly instead of e.g.
  1588. _LSHARPBRACKET and _RSHARPBRACKET for "<>" }
  1589. old_block_type:=block_type;
  1590. block_type:=bt_body;
  1591. consume(_OPERATOR);
  1592. parse_proc_head(astruct,potype_operator,false,nil,nil,pd);
  1593. block_type:=old_block_type;
  1594. if assigned(pd) then
  1595. parse_proc_dec_finish(pd,isclassmethod,astruct)
  1596. else
  1597. begin
  1598. { recover }
  1599. try_to_consume(_ID);
  1600. consume(_COLON);
  1601. consume_all_until(_SEMICOLON);
  1602. recover:=true;
  1603. end;
  1604. end;
  1605. end;
  1606. if recover and not(check_proc_directive(false)) then
  1607. begin
  1608. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1609. begin
  1610. message(parser_e_field_not_allowed_here);
  1611. consume_all_until(_SEMICOLON);
  1612. end;
  1613. consume(_SEMICOLON);
  1614. end;
  1615. { we've parsed the final semicolon, so stop recording tokens }
  1616. if assigned(pd) and
  1617. (df_generic in pd.defoptions) and
  1618. assigned(pd.genericdecltokenbuf) then
  1619. current_scanner.stoprecordtokens;
  1620. result:=pd;
  1621. end;
  1622. function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean;hadgeneric:boolean): tprocdef;
  1623. var
  1624. oldparse_only: boolean;
  1625. begin
  1626. oldparse_only:=parse_only;
  1627. parse_only:=true;
  1628. result:=parse_proc_dec(is_classdef,astruct,hadgeneric);
  1629. { this is for error recovery as well as forward }
  1630. { interface mappings, i.e. mapping to a method }
  1631. { which isn't declared yet }
  1632. if assigned(result) then
  1633. begin
  1634. parse_record_proc_directives(result);
  1635. { since records have no inheritance, don't allow non-static
  1636. class methods. Delphi does the same. }
  1637. if (result.proctypeoption<>potype_operator) and
  1638. is_classdef and
  1639. not (po_staticmethod in result.procoptions) then
  1640. MessagePos(result.fileinfo, parser_e_class_methods_only_static_in_records);
  1641. // we can't add hidden params here because record is not yet defined
  1642. // and therefore record size which has influence on paramter passing rules may change too
  1643. // look at record_dec to see where calling conventions are applied (issue #0021044)
  1644. handle_calling_convention(result,hcc_default_actions_intf_struct);
  1645. { add definition to procsym }
  1646. proc_add_definition(result);
  1647. if result.is_generic then
  1648. astruct.symtable.includeoption(sto_has_generic);
  1649. end;
  1650. maybe_parse_hint_directives(result);
  1651. parse_only:=oldparse_only;
  1652. end;
  1653. {****************************************************************************
  1654. Procedure directive handlers
  1655. ****************************************************************************}
  1656. procedure pd_compilerproc(pd:tabstractprocdef);
  1657. var
  1658. v : Tconstexprint;
  1659. begin
  1660. { check for optional syssym index }
  1661. if try_to_consume(_COLON) then
  1662. begin
  1663. v:=get_intconst;
  1664. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1665. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1666. else if not assigned(tsyssym.find_by_number(longint(v.svalue))) then
  1667. message1(parser_e_invalid_internal_function_index,tostr(v))
  1668. else
  1669. tprocdef(pd).extnumber:=longint(v.svalue);
  1670. end;
  1671. end;
  1672. procedure pd_far(pd:tabstractprocdef);
  1673. begin
  1674. pd.declared_far;
  1675. end;
  1676. procedure pd_near(pd:tabstractprocdef);
  1677. begin
  1678. pd.declared_near;
  1679. end;
  1680. procedure pd_export(pd:tabstractprocdef);
  1681. begin
  1682. if pd.typ<>procdef then
  1683. internalerror(200304264);
  1684. if assigned(tprocdef(pd).struct) then
  1685. Message(parser_e_methods_dont_be_export);
  1686. if pd.parast.symtablelevel>normal_function_level then
  1687. Message(parser_e_dont_nest_export);
  1688. end;
  1689. procedure pd_forward(pd:tabstractprocdef);
  1690. begin
  1691. if pd.typ<>procdef then
  1692. internalerror(200304265);
  1693. tprocdef(pd).forwarddef:=true;
  1694. end;
  1695. procedure pd_alias(pd:tabstractprocdef);
  1696. begin
  1697. if pd.typ<>procdef then
  1698. internalerror(200304266);
  1699. consume(_COLON);
  1700. tprocdef(pd).aliasnames.insert(get_stringconst);
  1701. include(pd.procoptions,po_has_public_name);
  1702. end;
  1703. procedure pd_public(pd:tabstractprocdef);
  1704. begin
  1705. if pd.typ<>procdef then
  1706. internalerror(2003042601);
  1707. if try_to_consume(_NAME) then
  1708. begin
  1709. tprocdef(pd).aliasnames.insert(get_stringconst);
  1710. include(pd.procoptions,po_has_public_name);
  1711. end;
  1712. end;
  1713. procedure pd_asmname(pd:tabstractprocdef);
  1714. begin
  1715. if pd.typ<>procdef then
  1716. internalerror(200304267);
  1717. if token=_CCHAR then
  1718. begin
  1719. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1720. consume(_CCHAR)
  1721. end
  1722. else
  1723. begin
  1724. tprocdef(pd).aliasnames.insert(target_info.Cprefix+cstringpattern);
  1725. consume(_CSTRING);
  1726. end;
  1727. { we don't need anything else }
  1728. tprocdef(pd).forwarddef:=false;
  1729. end;
  1730. procedure pd_internconst(pd:tabstractprocdef);
  1731. var v:Tconstexprint;
  1732. begin
  1733. if pd.typ<>procdef then
  1734. internalerror(200304268);
  1735. consume(_COLON);
  1736. v:=get_intconst;
  1737. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1738. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1739. else
  1740. Tprocdef(pd).extnumber:=longint(v.svalue);
  1741. end;
  1742. procedure pd_internproc(pd:tabstractprocdef);
  1743. var v:Tconstexprint;
  1744. begin
  1745. if pd.typ<>procdef then
  1746. internalerror(2003042602);
  1747. consume(_COLON);
  1748. v:=get_intconst;
  1749. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1750. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1751. else
  1752. Tprocdef(pd).extnumber:=longint(v.svalue);
  1753. { the proc is defined }
  1754. tprocdef(pd).forwarddef:=false;
  1755. end;
  1756. procedure pd_interrupt(pd:tabstractprocdef);
  1757. begin
  1758. if pd.parast.symtablelevel>normal_function_level then
  1759. Message(parser_e_dont_nest_interrupt);
  1760. end;
  1761. procedure pd_abstract(pd:tabstractprocdef);
  1762. begin
  1763. if pd.typ<>procdef then
  1764. internalerror(200304269);
  1765. if is_objectpascal_helper(tprocdef(pd).struct) then
  1766. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_ABSTRACT].str);
  1767. if assigned(tprocdef(pd).struct) and
  1768. (oo_is_sealed in tprocdef(pd).struct.objectoptions) then
  1769. Message(parser_e_sealed_class_cannot_have_abstract_methods)
  1770. else if (po_virtualmethod in pd.procoptions) then
  1771. begin
  1772. include(pd.procoptions,po_abstractmethod);
  1773. { one more abstract method }
  1774. inc(tobjectdef(pd.owner.defowner).abstractcnt);
  1775. end
  1776. else
  1777. Message(parser_e_only_virtual_methods_abstract);
  1778. { the method is defined }
  1779. tprocdef(pd).forwarddef:=false;
  1780. end;
  1781. procedure pd_final(pd:tabstractprocdef);
  1782. begin
  1783. if pd.typ<>procdef then
  1784. internalerror(200910170);
  1785. if is_objectpascal_helper(tprocdef(pd).struct) and
  1786. (m_objfpc in current_settings.modeswitches) then
  1787. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_FINAL].str);
  1788. if (po_virtualmethod in pd.procoptions) or
  1789. (is_javaclass(tprocdef(pd).struct) and
  1790. (po_classmethod in pd.procoptions)) then
  1791. include(pd.procoptions,po_finalmethod)
  1792. else
  1793. Message(parser_e_only_virtual_methods_final);
  1794. end;
  1795. procedure pd_enumerator(pd:tabstractprocdef);
  1796. begin
  1797. if pd.typ<>procdef then
  1798. internalerror(200910250);
  1799. if (token = _ID) then
  1800. begin
  1801. if pattern='MOVENEXT' then
  1802. begin
  1803. if oo_has_enumerator_movenext in tprocdef(pd).struct.objectoptions then
  1804. message(parser_e_only_one_enumerator_movenext);
  1805. pd.calcparas;
  1806. if (pd.proctypeoption = potype_function) and is_boolean(pd.returndef) and
  1807. (pd.minparacount = 0) then
  1808. begin
  1809. include(tprocdef(pd).struct.objectoptions, oo_has_enumerator_movenext);
  1810. include(pd.procoptions,po_enumerator_movenext);
  1811. end
  1812. else
  1813. Message(parser_e_enumerator_movenext_is_not_valid)
  1814. end
  1815. else
  1816. Message1(parser_e_invalid_enumerator_identifier, pattern);
  1817. consume(token);
  1818. end
  1819. else
  1820. Message(parser_e_enumerator_identifier_required);
  1821. end;
  1822. procedure pd_virtual(pd:tabstractprocdef);
  1823. {$ifdef WITHDMT}
  1824. var
  1825. pt : tnode;
  1826. {$endif WITHDMT}
  1827. begin
  1828. if assigned(pd.owner) and
  1829. (not assigned(pd.owner.defowner) or
  1830. not is_java_class_or_interface(tdef(pd.owner.defowner))) and
  1831. (po_external in pd.procoptions) then
  1832. Message2(parser_e_proc_dir_conflict,'EXTERNAL','"VIRTUAL"');
  1833. if pd.typ<>procdef then
  1834. internalerror(2003042610);
  1835. if (pd.proctypeoption=potype_constructor) and
  1836. is_object(tprocdef(pd).struct) then
  1837. Message(parser_e_constructor_cannot_be_not_virtual);
  1838. if pd.is_generic then
  1839. message(parser_e_genfuncs_cannot_be_virtual);
  1840. if is_objectpascal_helper(tprocdef(pd).struct) and
  1841. (m_objfpc in current_settings.modeswitches) then
  1842. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_VIRTUAL].str);
  1843. {$ifdef WITHDMT}
  1844. if is_object(tprocdef(pd).struct) and
  1845. (token<>_SEMICOLON) then
  1846. begin
  1847. { any type of parameter is allowed here! }
  1848. pt:=comp_expr(true);
  1849. if is_constintnode(pt) then
  1850. begin
  1851. include(pd.procoptions,po_msgint);
  1852. pd.messageinf.i:=pt.value;
  1853. end
  1854. else
  1855. Message(parser_e_ill_msg_expr);
  1856. disposetree(pt);
  1857. end;
  1858. {$endif WITHDMT}
  1859. end;
  1860. procedure pd_dispid(pd:tabstractprocdef);
  1861. var pt:Tnode;
  1862. begin
  1863. if pd.typ<>procdef then
  1864. internalerror(200604301);
  1865. pt:=comp_expr([ef_accept_equal]);
  1866. if is_constintnode(pt) then
  1867. if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
  1868. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
  1869. else
  1870. Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
  1871. else
  1872. message(parser_e_dispid_must_be_ord_const);
  1873. pt.free;
  1874. end;
  1875. procedure pd_static(pd:tabstractprocdef);
  1876. begin
  1877. if pd.typ<>procdef then
  1878. internalerror(2013032001);
  1879. if not assigned(tprocdef(pd).struct) then
  1880. internalerror(2013032002);
  1881. include(tprocdef(pd).procsym.symoptions,sp_static);
  1882. { "static" is not allowed for operators or normal methods (except in objects) }
  1883. if (pd.proctypeoption=potype_operator) or
  1884. (
  1885. not (po_classmethod in pd.procoptions) and
  1886. not is_object(tprocdef(pd).struct)
  1887. )
  1888. then
  1889. Message1(parser_e_dir_not_allowed,arraytokeninfo[_STATIC].str);
  1890. include(pd.procoptions,po_staticmethod);
  1891. end;
  1892. procedure pd_override(pd:tabstractprocdef);
  1893. begin
  1894. if pd.typ<>procdef then
  1895. internalerror(2003042611);
  1896. if is_objectpascal_helper(tprocdef(pd).struct) then
  1897. begin
  1898. if m_objfpc in current_settings.modeswitches then
  1899. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_OVERRIDE].str)
  1900. end
  1901. else if not(is_class_or_interface_or_objc_or_java(tprocdef(pd).struct)) then
  1902. Message(parser_e_no_object_override)
  1903. else if is_objccategory(tprocdef(pd).struct) then
  1904. Message(parser_e_no_category_override)
  1905. else if (po_external in pd.procoptions) and
  1906. not is_objc_class_or_protocol(tprocdef(pd).struct) and
  1907. not is_cppclass(tprocdef(pd).struct) and
  1908. not is_java_class_or_interface(tprocdef(pd).struct) then
  1909. Message2(parser_e_proc_dir_conflict,'OVERRIDE','"EXTERNAL"');
  1910. end;
  1911. procedure pd_overload(pd:tabstractprocdef);
  1912. begin
  1913. if pd.typ<>procdef then
  1914. internalerror(2003042612);
  1915. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1916. end;
  1917. procedure pd_message(pd:tabstractprocdef);
  1918. var
  1919. pt : tnode;
  1920. paracnt : longint;
  1921. begin
  1922. if pd.typ<>procdef then
  1923. internalerror(2003042613);
  1924. if is_objectpascal_helper(tprocdef(pd).struct) then
  1925. begin
  1926. if m_objfpc in current_settings.modeswitches then
  1927. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_MESSAGE].str);
  1928. end
  1929. else
  1930. if not is_class(tprocdef(pd).struct) and
  1931. not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1932. Message(parser_e_msg_only_for_classes);
  1933. if ([po_msgstr,po_msgint]*pd.procoptions)<>[] then
  1934. Message(parser_e_multiple_messages);
  1935. { check parameter type }
  1936. if not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1937. begin
  1938. if po_external in pd.procoptions then
  1939. Message2(parser_e_proc_dir_conflict,'MESSAGE','"EXTERNAL"');
  1940. paracnt:=0;
  1941. pd.parast.SymList.ForEachCall(@check_msg_para,@paracnt);
  1942. if paracnt<>1 then
  1943. Message(parser_e_ill_msg_param);
  1944. end;
  1945. pt:=comp_expr([ef_accept_equal]);
  1946. { message is 1-character long }
  1947. if is_constcharnode(pt) then
  1948. begin
  1949. include(pd.procoptions,po_msgstr);
  1950. tprocdef(pd).messageinf.str:=stringdup(chr(byte(tordconstnode(pt).value.uvalue and $FF)));
  1951. end
  1952. else if pt.nodetype=stringconstn then
  1953. begin
  1954. include(pd.procoptions,po_msgstr);
  1955. if (tstringconstnode(pt).len>255) then
  1956. Message(parser_e_message_string_too_long);
  1957. tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
  1958. end
  1959. else
  1960. if is_constintnode(pt) and
  1961. (is_class(tprocdef(pd).struct) or
  1962. is_objectpascal_helper(tprocdef(pd).struct)) then
  1963. begin
  1964. include(pd.procoptions,po_msgint);
  1965. if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
  1966. (Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
  1967. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(Tprocdef(pd).messageinf.i)),tostr(high(Tprocdef(pd).messageinf.i)))
  1968. else
  1969. Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
  1970. end
  1971. else
  1972. Message(parser_e_ill_msg_expr);
  1973. { check whether the selector name is valid in case of Objective-C }
  1974. if (po_msgstr in pd.procoptions) and
  1975. is_objc_class_or_protocol(tprocdef(pd).struct) and
  1976. not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
  1977. Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
  1978. pt.free;
  1979. end;
  1980. procedure pd_reintroduce(pd:tabstractprocdef);
  1981. begin
  1982. if pd.typ<>procdef then
  1983. internalerror(200401211);
  1984. if is_objectpascal_helper(tprocdef(pd).struct) then
  1985. begin
  1986. if m_objfpc in current_settings.modeswitches then
  1987. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_REINTRODUCE].str);
  1988. end
  1989. else
  1990. if not(is_class_or_interface_or_object(tprocdef(pd).struct)) and
  1991. not(is_objccategory(tprocdef(pd).struct)) and
  1992. not(is_javaclass(tprocdef(pd).struct)) then
  1993. Message(parser_e_no_object_reintroduce);
  1994. end;
  1995. procedure pd_syscall(pd:tabstractprocdef);
  1996. procedure include_po_syscall;
  1997. var
  1998. syscall: psyscallinfo;
  1999. begin
  2000. case target_info.system of
  2001. system_arm_palmos,
  2002. system_m68k_palmos,
  2003. system_m68k_atari,
  2004. system_m68k_amiga,
  2005. system_powerpc_amiga:
  2006. include(pd.procoptions,get_default_syscall);
  2007. system_powerpc_morphos,
  2008. system_arm_aros,
  2009. system_i386_aros,
  2010. system_x86_64_aros:
  2011. begin
  2012. syscall:=get_syscall_by_token(idtoken);
  2013. if assigned(syscall) then
  2014. begin
  2015. if target_info.system in syscall^.validon then
  2016. begin
  2017. consume(idtoken);
  2018. include(pd.procoptions,syscall^.procoption);
  2019. end
  2020. end
  2021. else
  2022. include(pd.procoptions,get_default_syscall);
  2023. end;
  2024. else
  2025. internalerror(2019050526);
  2026. end;
  2027. end;
  2028. function po_syscall_to_varoptions: tvaroptions;
  2029. begin
  2030. result:=[vo_is_syscall_lib,vo_is_hidden_para];
  2031. if ([po_syscall_legacy,po_syscall_basereg,po_syscall_basenone] * tprocdef(pd).procoptions) <> [] then
  2032. include(result,vo_has_explicit_paraloc);
  2033. end;
  2034. function po_syscall_to_regname: string;
  2035. begin
  2036. if po_syscall_legacy in tprocdef(pd).procoptions then
  2037. result:='a6'
  2038. { let nobase on MorphOS store the libbase in r12 as well, because
  2039. we will need the libbase anyway during the call generation }
  2040. else if (po_syscall_basenone in tprocdef(pd).procoptions) and
  2041. (target_info.system = system_powerpc_morphos) then
  2042. result:='r12'
  2043. else if po_syscall_basereg in tprocdef(pd).procoptions then
  2044. begin
  2045. case target_info.system of
  2046. system_i386_aros:
  2047. result:='eax';
  2048. system_x86_64_aros:
  2049. result:='r12';
  2050. system_powerpc_morphos:
  2051. result:='r12';
  2052. else
  2053. internalerror(2016090201);
  2054. end;
  2055. end
  2056. else
  2057. internalerror(2016090101);
  2058. end;
  2059. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2060. const
  2061. syscall_paranr: array[boolean] of aint =
  2062. ( paranr_syscall_lib_last, paranr_syscall_lib_first );
  2063. var
  2064. vs : tparavarsym;
  2065. sym : tsym;
  2066. symtable : TSymtable;
  2067. v: Tconstexprint;
  2068. vo: tvaroptions;
  2069. paranr: aint;
  2070. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2071. begin
  2072. if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
  2073. internalerror(2003042614);
  2074. tprocdef(pd).forwarddef:=false;
  2075. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2076. include_po_syscall;
  2077. if target_info.system in [system_arm_palmos, system_m68k_palmos] then
  2078. begin
  2079. v:=get_intconst;
  2080. tprocdef(pd).extnumber:=longint(v.svalue);
  2081. if ((v<0) or (v>high(word))) then
  2082. message(parser_e_range_check_error);
  2083. if try_to_consume(_COMMA) then
  2084. begin
  2085. v:=get_intconst;
  2086. if ((v<0) or (v>high(word))) then
  2087. message(parser_e_range_check_error);
  2088. tprocdef(pd).import_nr:=longint(v.svalue);
  2089. include(pd.procoptions,po_syscall_has_importnr);
  2090. end;
  2091. exit;
  2092. end;
  2093. if target_info.system = system_m68k_atari then
  2094. begin
  2095. v:=get_intconst;
  2096. if ((v<0) or (v>15)) then
  2097. message(parser_e_range_check_error)
  2098. else
  2099. tprocdef(pd).extnumber:=longint(v.svalue);
  2100. v:=get_intconst;
  2101. if ((v<0) or (v>high(smallint))) then
  2102. message(parser_e_range_check_error)
  2103. else
  2104. tprocdef(pd).import_nr:=longint(v.svalue);
  2105. exit;
  2106. end;
  2107. if consume_sym(sym,symtable) then
  2108. if ((sym.typ=staticvarsym) or
  2109. (sym.typ=absolutevarsym) and (tabsolutevarsym(sym).abstyp=toaddr)) and
  2110. ((tabstractvarsym(sym).vardef.typ=pointerdef) or
  2111. is_32bitint(tabstractvarsym(sym).vardef)) then
  2112. begin
  2113. include(pd.procoptions,po_syscall_has_libsym);
  2114. tcpuprocdef(pd).libsym:=sym;
  2115. vo:=po_syscall_to_varoptions;
  2116. paranr:=syscall_paranr[po_syscall_basefirst in tprocdef(pd).procoptions];
  2117. vs:=cparavarsym.create('$syscalllib',paranr,vs_value,tabstractvarsym(sym).vardef,vo);
  2118. if vo_has_explicit_paraloc in vo then
  2119. if not paramanager.parseparaloc(vs,po_syscall_to_regname) then
  2120. internalerror(2016120301);
  2121. pd.parast.insert(vs);
  2122. end
  2123. else
  2124. Message(parser_e_32bitint_or_pointer_variable_expected);
  2125. paramanager.create_funcretloc_info(pd,calleeside);
  2126. paramanager.create_funcretloc_info(pd,callerside);
  2127. v:=get_intconst;
  2128. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  2129. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(Tprocdef(pd).extnumber)),tostr(high(Tprocdef(pd).extnumber)))
  2130. else
  2131. if target_info.system in [system_arm_aros,system_i386_aros,system_x86_64_aros] then
  2132. Tprocdef(pd).extnumber:=v.uvalue * sizeof(pint)
  2133. else
  2134. Tprocdef(pd).extnumber:=v.uvalue;
  2135. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2136. end;
  2137. procedure pd_external(pd:tabstractprocdef);
  2138. {
  2139. If import_dll=nil the procedure is assumed to be in another
  2140. object file. In that object file it should have the name to
  2141. which import_name is pointing to. Otherwise, the procedure is
  2142. assumed to be in the DLL to which import_dll is pointing to. In
  2143. that case either import_nr<>0 or import_name<>nil is true, so
  2144. the procedure is either imported by number or by name. (DM)
  2145. }
  2146. var
  2147. hs : string;
  2148. v:Tconstexprint;
  2149. is_java_external: boolean;
  2150. begin
  2151. if pd.typ<>procdef then
  2152. internalerror(2003042615);
  2153. { Allow specifying a separate external name for methods in external Java
  2154. because its identifier naming constraints are laxer than FPC's
  2155. (e.g., case sensitive).
  2156. Limitation: only allows specifying the symbol name and not the package name,
  2157. and only for external classes/interfaces }
  2158. is_java_external:=
  2159. (pd.typ=procdef) and
  2160. is_java_class_or_interface(tdef(pd.owner.defowner)) and
  2161. (oo_is_external in tobjectdef(pd.owner.defowner).objectoptions);
  2162. with tprocdef(pd) do
  2163. begin
  2164. forwarddef:=false;
  2165. { forbid local external procedures }
  2166. if parast.symtablelevel>normal_function_level then
  2167. Message(parser_e_no_local_proc_external);
  2168. { If the procedure should be imported from a DLL, a constant string follows.
  2169. This isn't really correct, an contant string expression follows
  2170. so we check if an semicolon follows, else a string constant have to
  2171. follow (FK) }
  2172. if not is_java_external and
  2173. not(token=_SEMICOLON) and not(idtoken=_NAME) then
  2174. begin
  2175. { Always add library prefix and suffix to create an uniform name }
  2176. hs:=get_stringconst;
  2177. if ExtractFileExt(hs)='' then
  2178. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  2179. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  2180. hs:=target_info.sharedlibprefix+hs;
  2181. { the JVM expects java/lang/Object rather than java.lang.Object }
  2182. if target_info.system in systems_jvm then
  2183. Replace(hs,'.','/');
  2184. import_dll:=stringdup(hs);
  2185. include(procoptions,po_has_importdll);
  2186. if (idtoken=_NAME) then
  2187. begin
  2188. consume(_NAME);
  2189. import_name:=stringdup(get_stringconst);
  2190. include(procoptions,po_has_importname);
  2191. if import_name^='' then
  2192. message(parser_e_empty_import_name);
  2193. end;
  2194. if (idtoken=_INDEX) then
  2195. begin
  2196. {After the word index follows the index number in the DLL.}
  2197. consume(_INDEX);
  2198. v:=get_intconst;
  2199. if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
  2200. message(parser_e_range_check_error)
  2201. else
  2202. import_nr:=longint(v.svalue);
  2203. end;
  2204. { default is to used the realname of the procedure }
  2205. if (import_nr=0) and not assigned(import_name) then
  2206. begin
  2207. import_name:=stringdup(procsym.realname);
  2208. include(procoptions,po_has_importname);
  2209. end;
  2210. end
  2211. else
  2212. begin
  2213. if (idtoken=_NAME) or
  2214. is_java_external then
  2215. begin
  2216. consume(_NAME);
  2217. import_name:=stringdup(get_stringconst);
  2218. include(procoptions,po_has_importname);
  2219. if import_name^='' then
  2220. message(parser_e_empty_import_name);
  2221. end;
  2222. end;
  2223. end;
  2224. end;
  2225. procedure pd_weakexternal(pd:tabstractprocdef);
  2226. begin
  2227. if not(target_info.system in systems_weak_linking) then
  2228. message(parser_e_weak_external_not_supported)
  2229. else
  2230. pd_external(pd);
  2231. end;
  2232. procedure pd_winapi(pd:tabstractprocdef);
  2233. begin
  2234. if not(target_info.system in systems_all_windows+[system_i386_nativent]) then
  2235. pd.proccalloption:=pocall_cdecl
  2236. else
  2237. pd.proccalloption:=pocall_stdcall;
  2238. include(pd.procoptions,po_hascallingconvention);
  2239. end;
  2240. procedure pd_hardfloat(pd:tabstractprocdef);
  2241. begin
  2242. if
  2243. {$if defined(arm)}
  2244. (current_settings.fputype=fpu_soft) or
  2245. {$endif defined(arm)}
  2246. (cs_fp_emulation in current_settings.moduleswitches) then
  2247. message(parser_e_cannot_use_hardfloat_in_a_softfloat_environment);
  2248. end;
  2249. type
  2250. pd_handler=procedure(pd:tabstractprocdef);
  2251. proc_dir_rec=record
  2252. idtok : ttoken;
  2253. pd_flags : tpdflags;
  2254. handler : pd_handler;
  2255. pocall : tproccalloption;
  2256. pooption : tprocoptions;
  2257. mutexclpocall : tproccalloptions;
  2258. mutexclpotype : tproctypeoptions;
  2259. mutexclpo : tprocoptions;
  2260. end;
  2261. const
  2262. {Should contain the number of procedure directives we support.}
  2263. num_proc_directives=53;
  2264. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  2265. (
  2266. (
  2267. idtok:_ABSTRACT;
  2268. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2269. handler : @pd_abstract;
  2270. pocall : pocall_none;
  2271. pooption : [po_abstractmethod];
  2272. mutexclpocall : [pocall_internproc];
  2273. mutexclpotype : [];
  2274. mutexclpo : [po_exports,po_interrupt,po_inline]
  2275. ),(
  2276. idtok:_ALIAS;
  2277. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2278. handler : @pd_alias;
  2279. pocall : pocall_none;
  2280. pooption : [];
  2281. mutexclpocall : [];
  2282. mutexclpotype : [];
  2283. mutexclpo : [po_external,po_inline]
  2284. ),(
  2285. idtok:_ASMNAME;
  2286. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  2287. handler : @pd_asmname;
  2288. pocall : pocall_cdecl;
  2289. pooption : [po_external];
  2290. mutexclpocall : [pocall_internproc];
  2291. mutexclpotype : [];
  2292. mutexclpo : [po_external,po_inline]
  2293. ),(
  2294. idtok:_ASSEMBLER;
  2295. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2296. handler : nil;
  2297. pocall : pocall_none;
  2298. pooption : [po_assembler];
  2299. mutexclpocall : [];
  2300. mutexclpotype : [];
  2301. mutexclpo : [po_external]
  2302. ),(
  2303. idtok:_C; {same as cdecl for mode mac}
  2304. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2305. handler : nil;
  2306. pocall : pocall_cdecl;
  2307. pooption : [];
  2308. mutexclpocall : [];
  2309. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2310. mutexclpo : [po_assembler,po_external]
  2311. ),(
  2312. idtok:_CBLOCK;
  2313. pd_flags : [pd_procvar];
  2314. handler : nil;
  2315. pocall : pocall_none;
  2316. pooption : [po_is_block];
  2317. mutexclpocall : [];
  2318. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2319. mutexclpo : [po_assembler,po_external]
  2320. ),(
  2321. idtok:_CDECL;
  2322. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2323. handler : nil;
  2324. pocall : pocall_cdecl;
  2325. pooption : [];
  2326. mutexclpocall : [];
  2327. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2328. mutexclpo : [po_assembler,po_external]
  2329. ),(
  2330. idtok:_DISPID;
  2331. pd_flags : [pd_dispinterface];
  2332. handler : @pd_dispid;
  2333. pocall : pocall_none;
  2334. pooption : [po_dispid];
  2335. mutexclpocall : [pocall_internproc];
  2336. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2337. mutexclpo : [po_interrupt,po_external,po_inline]
  2338. ),(
  2339. idtok:_DYNAMIC;
  2340. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord];
  2341. handler : @pd_virtual;
  2342. pocall : pocall_none;
  2343. pooption : [po_virtualmethod];
  2344. mutexclpocall : [pocall_internproc];
  2345. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2346. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  2347. ),(
  2348. idtok:_EXPORT;
  2349. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf,pd_notrecord,pd_nothelper];
  2350. handler : @pd_export;
  2351. pocall : pocall_none;
  2352. pooption : [po_exports,po_global];
  2353. mutexclpocall : [pocall_internproc];
  2354. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2355. mutexclpo : [po_external,po_interrupt,po_inline]
  2356. ),(
  2357. idtok:_EXTERNAL;
  2358. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper,pd_javaclass,pd_intfjava];
  2359. handler : @pd_external;
  2360. pocall : pocall_none;
  2361. pooption : [po_external];
  2362. mutexclpocall : [pocall_syscall];
  2363. { allowed for external cpp classes }
  2364. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2365. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2366. ),(
  2367. idtok:_FAR;
  2368. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2369. handler : @pd_far;
  2370. pocall : pocall_none;
  2371. pooption : [];
  2372. mutexclpocall : [pocall_internproc];
  2373. mutexclpotype : [];
  2374. mutexclpo : [po_inline]
  2375. ),(
  2376. idtok:_FAR16;
  2377. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject,pd_notrecord,pd_nothelper];
  2378. handler : nil;
  2379. pocall : pocall_far16;
  2380. pooption : [];
  2381. mutexclpocall : [];
  2382. mutexclpotype : [];
  2383. mutexclpo : [po_external]
  2384. ),(
  2385. idtok:_FINAL;
  2386. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2387. handler : @pd_final;
  2388. pocall : pocall_none;
  2389. pooption : [po_finalmethod];
  2390. mutexclpocall : [pocall_internproc];
  2391. mutexclpotype : [];
  2392. mutexclpo : [po_exports,po_interrupt,po_inline]
  2393. ),(
  2394. idtok:_FORWARD;
  2395. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2396. handler : @pd_forward;
  2397. pocall : pocall_none;
  2398. pooption : [];
  2399. mutexclpocall : [pocall_internproc];
  2400. mutexclpotype : [];
  2401. mutexclpo : [po_external,po_inline]
  2402. ),(
  2403. idtok:_OLDFPCCALL;
  2404. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2405. handler : nil;
  2406. pocall : pocall_oldfpccall;
  2407. pooption : [];
  2408. mutexclpocall : [];
  2409. mutexclpotype : [];
  2410. mutexclpo : []
  2411. ),(
  2412. idtok:_INLINE;
  2413. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2414. handler : nil;
  2415. pocall : pocall_none;
  2416. pooption : [po_inline];
  2417. mutexclpocall : [pocall_safecall];
  2418. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2419. mutexclpo : [po_noinline,po_exports,po_external,po_interrupt,po_virtualmethod,po_iocheck]
  2420. ),(
  2421. idtok:_NOINLINE;
  2422. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2423. handler : nil;
  2424. pocall : pocall_none;
  2425. pooption : [po_noinline];
  2426. mutexclpocall : [];
  2427. mutexclpotype : [];
  2428. mutexclpo : [po_inline,po_external]
  2429. ),(
  2430. idtok:_INTERNCONST;
  2431. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2432. handler : @pd_internconst;
  2433. pocall : pocall_none;
  2434. pooption : [po_internconst];
  2435. mutexclpocall : [];
  2436. mutexclpotype : [potype_operator];
  2437. mutexclpo : []
  2438. ),(
  2439. idtok:_INTERNPROC;
  2440. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2441. handler : @pd_internproc;
  2442. pocall : pocall_internproc;
  2443. pooption : [];
  2444. mutexclpocall : [];
  2445. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2446. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  2447. ),(
  2448. idtok:_INTERRUPT;
  2449. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2450. handler : @pd_interrupt;
  2451. {$ifdef i386}
  2452. pocall : pocall_oldfpccall;
  2453. {$else i386}
  2454. pocall : pocall_stdcall;
  2455. {$endif i386}
  2456. pooption : [po_interrupt];
  2457. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,pocall_mwpascal,
  2458. pocall_pascal,pocall_far16,pocall_oldfpccall,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  2459. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2460. mutexclpo : [po_external,po_inline,po_exports]
  2461. ),(
  2462. idtok:_IOCHECK;
  2463. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2464. handler : nil;
  2465. pocall : pocall_none;
  2466. pooption : [po_iocheck];
  2467. mutexclpocall : [pocall_internproc];
  2468. mutexclpotype : [];
  2469. mutexclpo : [po_external]
  2470. ),(
  2471. idtok:_LOCAL;
  2472. pd_flags : [pd_implemen,pd_body];
  2473. handler : nil;
  2474. pocall : pocall_none;
  2475. pooption : [po_kylixlocal];
  2476. mutexclpocall : [pocall_internproc,pocall_far16];
  2477. mutexclpotype : [];
  2478. mutexclpo : [po_external,po_exports]
  2479. ),(
  2480. idtok:_MESSAGE;
  2481. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_objcprot,pd_notrecord];
  2482. handler : @pd_message;
  2483. pocall : pocall_none;
  2484. pooption : []; { can be po_msgstr or po_msgint }
  2485. mutexclpocall : [pocall_internproc];
  2486. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2487. mutexclpo : [po_interrupt,po_inline]
  2488. ),(
  2489. idtok:_MWPASCAL;
  2490. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2491. handler : nil;
  2492. pocall : pocall_mwpascal;
  2493. pooption : [];
  2494. mutexclpocall : [];
  2495. mutexclpotype : [];
  2496. mutexclpo : []
  2497. ),(
  2498. idtok:_NEAR;
  2499. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf,pd_notrecord,pd_nothelper];
  2500. handler : @pd_near;
  2501. pocall : pocall_none;
  2502. pooption : [];
  2503. mutexclpocall : [pocall_internproc];
  2504. mutexclpotype : [];
  2505. mutexclpo : []
  2506. ),(
  2507. idtok:_NORETURN;
  2508. pd_flags : [pd_implemen,pd_interface,pd_body,pd_notobjintf];
  2509. handler : nil;
  2510. pocall : pocall_none;
  2511. pooption : [po_noreturn];
  2512. mutexclpocall : [];
  2513. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2514. mutexclpo : [po_interrupt,po_virtualmethod,po_iocheck]
  2515. ),(
  2516. idtok:_NOSTACKFRAME;
  2517. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  2518. handler : nil;
  2519. pocall : pocall_none;
  2520. pooption : [po_nostackframe];
  2521. mutexclpocall : [pocall_internproc];
  2522. mutexclpotype : [];
  2523. mutexclpo : []
  2524. ),(
  2525. idtok:_OVERLOAD;
  2526. pd_flags : [pd_implemen,pd_interface,pd_body,pd_javaclass,pd_intfjava,pd_objcclass,pd_objcprot];
  2527. handler : @pd_overload;
  2528. pocall : pocall_none;
  2529. pooption : [po_overload];
  2530. mutexclpocall : [pocall_internproc];
  2531. mutexclpotype : [];
  2532. mutexclpo : []
  2533. ),(
  2534. idtok:_OVERRIDE;
  2535. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_javaclass,pd_intfjava,pd_notrecord];
  2536. handler : @pd_override;
  2537. pocall : pocall_none;
  2538. pooption : [po_overridingmethod,po_virtualmethod];
  2539. mutexclpocall : [pocall_internproc];
  2540. mutexclpotype : [];
  2541. mutexclpo : [po_exports,po_interrupt,po_virtualmethod,po_inline]
  2542. ),(
  2543. idtok:_PASCAL;
  2544. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2545. handler : nil;
  2546. pocall : pocall_pascal;
  2547. pooption : [];
  2548. mutexclpocall : [];
  2549. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2550. mutexclpo : [po_external]
  2551. ),(
  2552. idtok:_PUBLIC;
  2553. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2554. handler : @pd_public;
  2555. pocall : pocall_none;
  2556. pooption : [po_public,po_global];
  2557. mutexclpocall : [pocall_internproc];
  2558. mutexclpotype : [];
  2559. mutexclpo : [po_external,po_inline]
  2560. ),(
  2561. idtok:_REGISTER;
  2562. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2563. handler : nil;
  2564. pocall : pocall_register;
  2565. pooption : [];
  2566. mutexclpocall : [];
  2567. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2568. mutexclpo : [po_external]
  2569. ),(
  2570. idtok:_REINTRODUCE;
  2571. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_notrecord,pd_javaclass];
  2572. handler : @pd_reintroduce;
  2573. pocall : pocall_none;
  2574. pooption : [po_reintroduce];
  2575. mutexclpocall : [pocall_internproc];
  2576. mutexclpotype : [];
  2577. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  2578. ),(
  2579. idtok:_SAFECALL;
  2580. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2581. handler : nil;
  2582. pocall : pocall_safecall;
  2583. pooption : [];
  2584. mutexclpocall : [];
  2585. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2586. mutexclpo : [po_external]
  2587. ),(
  2588. idtok:_SOFTFLOAT;
  2589. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2590. handler : nil;
  2591. pocall : pocall_softfloat;
  2592. pooption : [];
  2593. mutexclpocall : [];
  2594. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2595. { it's available with po_external because the libgcc floating point routines on the arm
  2596. uses this calling convention }
  2597. mutexclpo : []
  2598. ),(
  2599. idtok:_STATIC;
  2600. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_record,pd_javaclass,pd_notobjintf];
  2601. handler : @pd_static;
  2602. pocall : pocall_none;
  2603. pooption : [po_staticmethod];
  2604. mutexclpocall : [pocall_internproc];
  2605. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2606. mutexclpo : [po_interrupt,po_exports,po_virtualmethod]
  2607. ),(
  2608. idtok:_STDCALL;
  2609. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2610. handler : nil;
  2611. pocall : pocall_stdcall;
  2612. pooption : [];
  2613. mutexclpocall : [];
  2614. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2615. mutexclpo : [po_external]
  2616. ),(
  2617. idtok:_SYSCALL;
  2618. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  2619. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  2620. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  2621. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  2622. handler : @pd_syscall;
  2623. pocall : pocall_syscall;
  2624. pooption : [];
  2625. mutexclpocall : [];
  2626. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2627. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  2628. ),(
  2629. idtok:_VIRTUAL;
  2630. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2631. handler : @pd_virtual;
  2632. pocall : pocall_none;
  2633. pooption : [po_virtualmethod];
  2634. mutexclpocall : [pocall_internproc];
  2635. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2636. mutexclpo : PD_VIRTUAL_MUTEXCLPO
  2637. ),(
  2638. idtok:_CPPDECL;
  2639. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2640. handler : nil;
  2641. pocall : pocall_cppdecl;
  2642. pooption : [];
  2643. mutexclpocall : [];
  2644. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2645. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  2646. ),(
  2647. idtok:_VARARGS;
  2648. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass,pd_objcprot];
  2649. handler : nil;
  2650. pocall : pocall_none;
  2651. pooption : [po_varargs];
  2652. mutexclpocall : [pocall_internproc,pocall_register,
  2653. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  2654. mutexclpotype : [];
  2655. mutexclpo : [po_assembler,po_interrupt,po_inline]
  2656. ),(
  2657. idtok:_COMPILERPROC;
  2658. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2659. handler : @pd_compilerproc;
  2660. pocall : pocall_none;
  2661. pooption : [po_compilerproc];
  2662. mutexclpocall : [];
  2663. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2664. mutexclpo : [po_interrupt]
  2665. ),(
  2666. idtok:_WEAKEXTERNAL;
  2667. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper];
  2668. handler : @pd_weakexternal;
  2669. pocall : pocall_none;
  2670. { mark it both external and weak external, so we don't have to
  2671. adapt all code for external symbols to also check for weak external
  2672. }
  2673. pooption : [po_external,po_weakexternal];
  2674. mutexclpocall : [pocall_internproc,pocall_syscall];
  2675. { allowed for external cpp classes }
  2676. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2677. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2678. ),(
  2679. idtok:_WINAPI;
  2680. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2681. handler : @pd_winapi;
  2682. pocall : pocall_none;
  2683. pooption : [];
  2684. mutexclpocall : [pocall_stdcall,pocall_cdecl,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  2685. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2686. mutexclpo : [po_external]
  2687. ),(
  2688. idtok:_ENUMERATOR;
  2689. pd_flags : [pd_interface,pd_object,pd_record];
  2690. handler : @pd_enumerator;
  2691. pocall : pocall_none;
  2692. pooption : [];
  2693. mutexclpocall : [pocall_internproc];
  2694. mutexclpotype : [];
  2695. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2696. ),(
  2697. idtok:_RTLPROC;
  2698. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2699. handler : nil;
  2700. pocall : pocall_none;
  2701. pooption : [po_rtlproc];
  2702. mutexclpocall : [];
  2703. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2704. mutexclpo : [po_interrupt]
  2705. ),(
  2706. idtok:_HARDFLOAT;
  2707. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2708. handler : @pd_hardfloat;
  2709. pocall : pocall_hardfloat;
  2710. pooption : [];
  2711. mutexclpocall : [];
  2712. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2713. { it's available with po_external because the libgcc floating point routines on the arm
  2714. uses this calling convention }
  2715. mutexclpo : []
  2716. ),(
  2717. idtok:_SYSV_ABI_DEFAULT;
  2718. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2719. handler : nil;
  2720. pocall : pocall_sysv_abi_default;
  2721. pooption : [];
  2722. mutexclpocall : [];
  2723. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2724. mutexclpo : [po_interrupt]
  2725. ),(
  2726. idtok:_SYSV_ABI_CDECL;
  2727. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2728. handler : nil;
  2729. pocall : pocall_sysv_abi_cdecl;
  2730. pooption : [];
  2731. mutexclpocall : [];
  2732. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2733. mutexclpo : [po_interrupt]
  2734. ),(
  2735. idtok:_MS_ABI_DEFAULT;
  2736. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2737. handler : nil;
  2738. pocall : pocall_ms_abi_default;
  2739. pooption : [];
  2740. mutexclpocall : [];
  2741. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2742. mutexclpo : [po_interrupt]
  2743. ),(
  2744. idtok:_MS_ABI_CDECL;
  2745. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2746. handler : nil;
  2747. pocall : pocall_ms_abi_cdecl;
  2748. pooption : [];
  2749. mutexclpocall : [];
  2750. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2751. mutexclpo : [po_interrupt]
  2752. ),(
  2753. idtok:_VECTORCALL;
  2754. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2755. handler : nil;
  2756. pocall : pocall_vectorcall;
  2757. pooption : [];
  2758. mutexclpocall : [];
  2759. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2760. mutexclpo : [po_interrupt]
  2761. )
  2762. );
  2763. function check_proc_directive(isprocvar:boolean):boolean;
  2764. var
  2765. i : longint;
  2766. begin
  2767. result:=false;
  2768. for i:=1 to num_proc_directives do
  2769. if proc_direcdata[i].idtok=idtoken then
  2770. begin
  2771. if ((not isprocvar) or
  2772. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2773. { don't eat a public directive in classes }
  2774. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2775. result:=true;
  2776. exit;
  2777. end;
  2778. end;
  2779. function find_proc_directive_index(tok: ttoken): longint; inline;
  2780. begin
  2781. result:=-1;
  2782. for result:=1 to num_proc_directives do
  2783. if proc_direcdata[result].idtok=tok then
  2784. exit;
  2785. result:=-1;
  2786. end;
  2787. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2788. {
  2789. Parse the procedure directive, returns true if a correct directive is found
  2790. }
  2791. var
  2792. p : longint;
  2793. name : TIDString;
  2794. po_comp : tprocoptions;
  2795. tokenloc : TFilePosInfo;
  2796. begin
  2797. parse_proc_direc:=false;
  2798. name:=tokeninfo^[idtoken].str;
  2799. { Hint directive? Then exit immediatly }
  2800. if (m_hintdirective in current_settings.modeswitches) then
  2801. begin
  2802. case idtoken of
  2803. _LIBRARY,
  2804. _PLATFORM,
  2805. _UNIMPLEMENTED,
  2806. _EXPERIMENTAL,
  2807. _DEPRECATED :
  2808. if (m_delphi in current_settings.modeswitches) and (pd.typ=procdef) then
  2809. begin
  2810. maybe_parse_hint_directives(tprocdef(pd));
  2811. { could the new token still be a directive? }
  2812. if token<>_ID then
  2813. exit;
  2814. end
  2815. else
  2816. exit;
  2817. else
  2818. ;
  2819. end;
  2820. end;
  2821. { C directive is MacPas only, because it breaks too much existing code
  2822. on other platforms (PFV) }
  2823. if (idtoken=_C) and
  2824. not(m_mac in current_settings.modeswitches) then
  2825. exit;
  2826. { retrieve data for directive if found }
  2827. p:=find_proc_directive_index(idtoken);
  2828. { Check if the procedure directive is known }
  2829. if p=-1 then
  2830. begin
  2831. { parsing a procvar type the name can be any
  2832. next variable !! }
  2833. if ((pdflags * [pd_procvar,pd_object,pd_record,pd_objcclass,pd_objcprot])=[]) and
  2834. not(idtoken in [_PROPERTY,_GENERIC]) then
  2835. Message1(parser_w_unknown_proc_directive_ignored,pattern);
  2836. exit;
  2837. end;
  2838. { check if method and directive not for object, like public.
  2839. This needs to be checked also for procvars }
  2840. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2841. (symtablestack.top.symtabletype=ObjectSymtable) and
  2842. { directive allowed for cpp classes? }
  2843. not((pd_cppobject in proc_direcdata[p].pd_flags) and is_cppclass(tdef(symtablestack.top.defowner))) and
  2844. not((pd_javaclass in proc_direcdata[p].pd_flags) and is_javaclass(tdef(symtablestack.top.defowner))) and
  2845. not((pd_intfjava in proc_direcdata[p].pd_flags) and is_javainterface(tdef(symtablestack.top.defowner))) then
  2846. exit;
  2847. if (pd_notrecord in proc_direcdata[p].pd_flags) and
  2848. (symtablestack.top.symtabletype=recordsymtable) then
  2849. exit;
  2850. { check if method and directive not for java class }
  2851. if not(pd_javaclass in proc_direcdata[p].pd_flags) and
  2852. is_javaclass(tdef(symtablestack.top.defowner)) then
  2853. exit;
  2854. { check if method and directive not for java interface }
  2855. if not(pd_intfjava in proc_direcdata[p].pd_flags) and
  2856. is_javainterface(tdef(symtablestack.top.defowner)) then
  2857. exit;
  2858. { Keep track of the token's position in the file so it's correctly indicated if an error occurs. }
  2859. tokenloc := current_tokenpos;
  2860. { consume directive, and turn flag on }
  2861. consume(token);
  2862. parse_proc_direc:=true;
  2863. { Conflicts between directives? }
  2864. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) then
  2865. begin
  2866. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,ProcTypeOptionKeywords[pd.proctypeoption]);
  2867. exit;
  2868. end;
  2869. if (pd.proccalloption in proc_direcdata[p].mutexclpocall) then
  2870. begin
  2871. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,'"' + UpCase(proccalloptionStr[pd.proccalloption]) + '"');
  2872. exit;
  2873. end;
  2874. po_comp := (pd.procoptions*proc_direcdata[p].mutexclpo);
  2875. if (po_comp<>[]) then
  2876. begin
  2877. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,get_first_proc_str(po_comp));
  2878. exit;
  2879. end;
  2880. { set calling convention }
  2881. if proc_direcdata[p].pocall<>pocall_none then
  2882. begin
  2883. if (po_hascallingconvention in pd.procoptions) then
  2884. begin
  2885. MessagePos2(tokenloc, parser_w_proc_overriding_calling,
  2886. proccalloptionStr[pd.proccalloption],
  2887. proccalloptionStr[proc_direcdata[p].pocall]);
  2888. end;
  2889. { check if the target processor supports this calling convention }
  2890. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2891. begin
  2892. MessagePos1(tokenloc, parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2893. { recover }
  2894. proc_direcdata[p].pocall:=pocall_stdcall;
  2895. end;
  2896. pd.proccalloption:=proc_direcdata[p].pocall;
  2897. include(pd.procoptions,po_hascallingconvention);
  2898. end;
  2899. if pd.typ=procdef then
  2900. begin
  2901. { Check if the directive is only for objects }
  2902. if (pd_object in proc_direcdata[p].pd_flags) and
  2903. not assigned(tprocdef(pd).struct) then
  2904. exit;
  2905. { Check if the directive is only for records }
  2906. if (pd_record in proc_direcdata[p].pd_flags) and
  2907. not assigned(tprocdef(pd).struct) then
  2908. exit;
  2909. { check if method and directive not for interface }
  2910. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2911. is_interface(tprocdef(pd).struct) then
  2912. exit;
  2913. { check if method and directive not for interface }
  2914. if is_dispinterface(tprocdef(pd).struct) and
  2915. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2916. exit;
  2917. { check if method and directive not for objcclass }
  2918. if is_objcclass(tprocdef(pd).struct) and
  2919. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2920. exit;
  2921. { check if method and directive not for objcprotocol }
  2922. if is_objcprotocol(tprocdef(pd).struct) and
  2923. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2924. exit;
  2925. { check if method and directive not for record/class helper }
  2926. if is_objectpascal_helper(tprocdef(pd).struct) and
  2927. (pd_nothelper in proc_direcdata[p].pd_flags) then
  2928. exit;
  2929. end;
  2930. { Check the pd_flags if the directive should be allowed }
  2931. if (pd_interface in pdflags) and
  2932. not(pd_interface in proc_direcdata[p].pd_flags) then
  2933. begin
  2934. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_interface,name);
  2935. exit;
  2936. end;
  2937. if (pd_implemen in pdflags) and
  2938. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2939. begin
  2940. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_implementation,name);
  2941. exit;
  2942. end;
  2943. if (pd_procvar in pdflags) and
  2944. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2945. begin
  2946. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_procvar,name);
  2947. exit;
  2948. end;
  2949. { Return the new pd_flags }
  2950. if not(pd_body in proc_direcdata[p].pd_flags) then
  2951. exclude(pdflags,pd_body);
  2952. { Add the correct flag }
  2953. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2954. { Call the handler }
  2955. if pointer(proc_direcdata[p].handler)<>nil then
  2956. proc_direcdata[p].handler(pd);
  2957. end;
  2958. function proc_get_importname(pd:tprocdef):string;
  2959. var
  2960. dllname, importname : string;
  2961. begin
  2962. result:='';
  2963. if not(po_external in pd.procoptions) then
  2964. internalerror(200412151);
  2965. { external name or number is specified }
  2966. if assigned(pd.import_name) or (pd.import_nr<>0) then
  2967. begin
  2968. if assigned(pd.import_dll) then
  2969. dllname:=pd.import_dll^
  2970. else
  2971. dllname:='';
  2972. if assigned(pd.import_name) then
  2973. importname:=pd.import_name^
  2974. else
  2975. importname:='';
  2976. proc_get_importname:=make_dllmangledname(dllname,
  2977. importname,pd.import_nr,pd.proccalloption);
  2978. end
  2979. else
  2980. begin
  2981. { Default names when importing variables }
  2982. case pd.proccalloption of
  2983. pocall_cdecl,
  2984. pocall_sysv_abi_cdecl,
  2985. pocall_ms_abi_cdecl:
  2986. begin
  2987. if assigned(pd.struct) then
  2988. result:=target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname
  2989. else
  2990. result:=target_info.Cprefix+pd.procsym.realname;
  2991. end;
  2992. pocall_cppdecl :
  2993. begin
  2994. result:=target_info.Cprefix+pd.cplusplusmangledname;
  2995. end;
  2996. else
  2997. begin
  2998. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  2999. { but according to MacPas mode description
  3000. Cprefix should still be used PM }
  3001. if (m_mac in current_settings.modeswitches) then
  3002. result:=target_info.Cprefix+tprocdef(pd).procsym.realname
  3003. else
  3004. result:=pd.procsym.realname;
  3005. {$ifdef i8086}
  3006. { Turbo Pascal expects names of external routines
  3007. to be all uppercase }
  3008. if (target_info.system=system_i8086_msdos) and
  3009. (m_tp7 in current_settings.modeswitches) and
  3010. (pd.proccalloption=pocall_pascal) then
  3011. result:=UpCase(result);
  3012. {$endif i8086}
  3013. end;
  3014. end;
  3015. end;
  3016. end;
  3017. procedure proc_set_mangledname(pd:tprocdef);
  3018. var
  3019. s : string;
  3020. begin
  3021. { When the mangledname is already set we aren't allowed to change
  3022. it because it can already be used somewhere (PFV) }
  3023. if not(po_has_mangledname in pd.procoptions) then
  3024. begin
  3025. if (po_external in pd.procoptions) then
  3026. begin
  3027. { External Procedures are only allowed to change the mangledname
  3028. in their first declaration }
  3029. if (pd.forwarddef or (not pd.hasforward)) then
  3030. begin
  3031. s:=proc_get_importname(pd);
  3032. if s<>'' then
  3033. begin
  3034. pd.setmangledname(s);
  3035. end;
  3036. { since this is an external declaration, there won't be an
  3037. implementation that needs to match the original symbol
  3038. again -> immediately convert here }
  3039. if po_compilerproc in pd.procoptions then
  3040. pd.setcompilerprocname;
  3041. end
  3042. end
  3043. else
  3044. { Normal procedures }
  3045. begin
  3046. if (po_compilerproc in pd.procoptions) then
  3047. begin
  3048. pd.setmangledname(lower(pd.procsym.name));
  3049. end;
  3050. end;
  3051. end;
  3052. { Public/exported alias names }
  3053. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  3054. not(po_has_public_name in pd.procoptions) then
  3055. begin
  3056. case pd.proccalloption of
  3057. pocall_cdecl,
  3058. pocall_sysv_abi_cdecl,
  3059. pocall_ms_abi_cdecl:
  3060. begin
  3061. if assigned(pd.struct) then
  3062. pd.aliasnames.insert(target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname)
  3063. else
  3064. begin
  3065. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  3066. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  3067. (po_exports in pd.procoptions) then
  3068. pd.aliasnames.insert(pd.procsym.realname)
  3069. else
  3070. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  3071. end;
  3072. end;
  3073. pocall_cppdecl :
  3074. begin
  3075. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  3076. end;
  3077. else
  3078. ;
  3079. end;
  3080. { prevent adding the alias a second time }
  3081. include(pd.procoptions,po_has_public_name);
  3082. end;
  3083. end;
  3084. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  3085. {
  3086. Parse the procedure directives. It does not matter if procedure directives
  3087. are written using ;procdir; or ['procdir'] syntax.
  3088. }
  3089. var
  3090. stoprecording,
  3091. res : boolean;
  3092. begin
  3093. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  3094. begin
  3095. tprocdef(pd).aliasnames.insert(target_info.Cprefix+tprocdef(pd).procsym.realname);
  3096. include(pd.procoptions,po_public);
  3097. include(pd.procoptions,po_has_public_name);
  3098. include(pd.procoptions,po_global);
  3099. end;
  3100. { methods from external class definitions are all external themselves }
  3101. if (pd.typ=procdef) and
  3102. assigned(tprocdef(pd).struct) and
  3103. (tprocdef(pd).struct.typ=objectdef) and
  3104. (oo_is_external in tobjectdef(tprocdef(pd).struct).objectoptions) then
  3105. tprocdef(pd).make_external;
  3106. { Class constructors and destructor are static class methods in real. }
  3107. { There are many places in the compiler where either class or static }
  3108. { method flag changes the behavior. It is simplier to add them to }
  3109. { the class constructors/destructors options than to fix all the }
  3110. { occurencies. (Paul) }
  3111. if pd.proctypeoption in [potype_class_constructor,potype_class_destructor] then
  3112. begin
  3113. include(pd.procoptions,po_classmethod);
  3114. include(pd.procoptions,po_staticmethod);
  3115. end;
  3116. { for a generic routine we also need to record the procedure }
  3117. { directives, but only if we aren't already recording for a }
  3118. { surrounding generic }
  3119. if pd.is_generic and (pd.typ=procdef) and not current_scanner.is_recording_tokens then
  3120. begin
  3121. current_scanner.startrecordtokens(tprocdef(pd).genericdecltokenbuf);
  3122. stoprecording:=true;
  3123. end
  3124. else
  3125. stoprecording:=false;
  3126. while (token=_ID) or
  3127. (
  3128. not (m_prefixed_attributes in current_settings.modeswitches) and
  3129. (token=_LECKKLAMMER)
  3130. ) do
  3131. begin
  3132. if not (m_prefixed_attributes in current_settings.modeswitches) and
  3133. try_to_consume(_LECKKLAMMER) then
  3134. begin
  3135. repeat
  3136. parse_proc_direc(pd,pdflags);
  3137. until not try_to_consume(_COMMA);
  3138. consume(_RECKKLAMMER);
  3139. { we always expect at least '[];' }
  3140. res:=true;
  3141. end
  3142. else
  3143. begin
  3144. res:=parse_proc_direc(pd,pdflags);
  3145. end;
  3146. { A procedure directive normally followed by a semicolon, but in
  3147. a const section or reading a type we should stop when _EQ is found,
  3148. because a constant/default value follows }
  3149. if res then
  3150. begin
  3151. if (block_type=bt_const_type) and
  3152. (token=_EQ) then
  3153. break;
  3154. { support procedure proc;stdcall export; }
  3155. if not(check_proc_directive((pd.typ=procvardef))) then
  3156. begin
  3157. { support "record p : procedure stdcall end;" and
  3158. "var p : procedure stdcall = nil;" }
  3159. if (pd_procvar in pdflags) and
  3160. (token in [_END,_RKLAMMER,_EQ]) then
  3161. break
  3162. else
  3163. begin
  3164. if (token=_COLON) then
  3165. begin
  3166. Message(parser_e_field_not_allowed_here);
  3167. consume_all_until(_SEMICOLON);
  3168. end;
  3169. consume(_SEMICOLON)
  3170. end;
  3171. end;
  3172. end
  3173. else
  3174. break;
  3175. end;
  3176. if stoprecording then
  3177. current_scanner.stoprecordtokens;
  3178. { nostackframe requires assembler, but assembler
  3179. may be specified in the implementation part only,
  3180. and in not required if the function is first forward declared
  3181. if it is a procdef that has forwardef set to true
  3182. we postpone the possible error message to the real implementation
  3183. parse_only does not need to be considered as po_nostackframe
  3184. is an implementation only directive }
  3185. if (po_nostackframe in pd.procoptions) and
  3186. not (po_assembler in pd.procoptions) and
  3187. ((pd.typ<>procdef) or not tprocdef(pd).forwarddef) then
  3188. message(parser_e_nostackframe_without_assembler);
  3189. end;
  3190. procedure parse_var_proc_directives(sym:tsym);
  3191. var
  3192. pdflags : tpdflags;
  3193. pd : tabstractprocdef;
  3194. begin
  3195. pdflags:=[pd_procvar];
  3196. pd:=nil;
  3197. case sym.typ of
  3198. fieldvarsym,
  3199. staticvarsym,
  3200. localvarsym,
  3201. paravarsym :
  3202. pd:=tabstractprocdef(tabstractvarsym(sym).vardef);
  3203. typesym :
  3204. pd:=tabstractprocdef(ttypesym(sym).typedef);
  3205. else
  3206. internalerror(2003042617);
  3207. end;
  3208. if pd.typ<>procvardef then
  3209. internalerror(2003042618);
  3210. { names should never be used anyway }
  3211. parse_proc_directives(pd,pdflags);
  3212. end;
  3213. procedure parse_object_proc_directives(pd:tabstractprocdef);
  3214. var
  3215. pdflags : tpdflags;
  3216. begin
  3217. pdflags:=[pd_object];
  3218. parse_proc_directives(pd,pdflags);
  3219. end;
  3220. procedure parse_record_proc_directives(pd:tabstractprocdef);
  3221. var
  3222. pdflags : tpdflags;
  3223. begin
  3224. pdflags:=[pd_record];
  3225. parse_proc_directives(pd,pdflags);
  3226. end;
  3227. end.