pdecsub.pas 131 KB

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