pdecsub.pas 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596
  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. tokens,symconst,symtype,symdef,symsym;
  22. type
  23. tpdflag=(
  24. pd_body, { directive needs a body }
  25. pd_implemen, { directive can be used implementation section }
  26. pd_interface, { directive can be used interface section }
  27. pd_object, { directive can be used object declaration }
  28. pd_procvar, { directive can be used procvar declaration }
  29. pd_notobject, { directive can not be used object declaration }
  30. pd_notobjintf, { directive can not be used interface declaration }
  31. pd_notprocvar { directive can not be used procvar declaration }
  32. );
  33. tpdflags=set of tpdflag;
  34. function check_proc_directive(isprocvar:boolean):boolean;
  35. procedure insert_funcret_local(pd:tprocdef);
  36. function proc_add_definition(var pd:tprocdef):boolean;
  37. function proc_get_importname(pd:tprocdef):string;
  38. procedure proc_set_mangledname(pd:tprocdef);
  39. procedure handle_calling_convention(pd:tabstractprocdef);
  40. procedure parse_parameter_dec(pd:tabstractprocdef);
  41. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  42. procedure parse_var_proc_directives(sym:tsym);
  43. procedure parse_object_proc_directives(pd:tabstractprocdef);
  44. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  45. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  46. implementation
  47. uses
  48. strings,
  49. { common }
  50. cutils,cclasses,
  51. { global }
  52. globtype,globals,verbose,
  53. systems,
  54. cpuinfo,
  55. { symtable }
  56. symbase,symtable,defutil,defcmp,paramgr,cpupara,
  57. { pass 1 }
  58. fmodule,node,htypechk,
  59. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  60. { parser }
  61. scanner,
  62. pbase,pexpr,ptype,pdecl
  63. ;
  64. const
  65. { Please leave this here, this module should NOT use
  66. these variables.
  67. Declaring it as string here results in an error when compiling (PFV) }
  68. current_procinfo = 'error';
  69. procedure insert_funcret_para(pd:tabstractprocdef);
  70. var
  71. storepos : tfileposinfo;
  72. vs : tparavarsym;
  73. paranr : word;
  74. begin
  75. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  76. not is_void(pd.rettype.def) and
  77. paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  78. begin
  79. storepos:=akttokenpos;
  80. if pd.deftype=procdef then
  81. akttokenpos:=tprocdef(pd).fileinfo;
  82. { For left to right add it at the end to be delphi compatible }
  83. if pd.proccalloption in pushleftright_pocalls then
  84. paranr:=paranr_result_leftright
  85. else
  86. paranr:=paranr_result;
  87. { Generate result variable accessing function result }
  88. vs:=tparavarsym.create('$result',paranr,vs_var,pd.rettype,[vo_is_funcret,vo_is_hidden_para]);
  89. pd.parast.insert(vs);
  90. { Store the this symbol as funcretsym for procedures }
  91. if pd.deftype=procdef then
  92. tprocdef(pd).funcretsym:=vs;
  93. akttokenpos:=storepos;
  94. end;
  95. end;
  96. procedure insert_parentfp_para(pd:tabstractprocdef);
  97. var
  98. storepos : tfileposinfo;
  99. vs : tparavarsym;
  100. begin
  101. if pd.parast.symtablelevel>normal_function_level then
  102. begin
  103. storepos:=akttokenpos;
  104. if pd.deftype=procdef then
  105. akttokenpos:=tprocdef(pd).fileinfo;
  106. { Generate result variable accessing function result, it
  107. can't be put in a register since it must be accessable
  108. from the framepointer }
  109. vs:=tparavarsym.create('$parentfp',paranr_parentfp,vs_var,voidpointertype,[vo_is_parentfp,vo_is_hidden_para]);
  110. vs.varregable:=vr_none;
  111. pd.parast.insert(vs);
  112. akttokenpos:=storepos;
  113. end;
  114. end;
  115. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  116. var
  117. storepos : tfileposinfo;
  118. vs : tparavarsym;
  119. tt : ttype;
  120. vsp : tvarspez;
  121. begin
  122. if (pd.deftype=procvardef) and
  123. pd.is_methodpointer then
  124. begin
  125. { Generate self variable }
  126. tt:=voidpointertype;
  127. vs:=tparavarsym.create('$self',paranr_self,vs_value,tt,[vo_is_self,vo_is_hidden_para]);
  128. pd.parast.insert(vs);
  129. end
  130. else
  131. begin
  132. if (pd.deftype=procdef) and
  133. assigned(tprocdef(pd)._class) and
  134. (pd.parast.symtablelevel=normal_function_level) then
  135. begin
  136. storepos:=akttokenpos;
  137. akttokenpos:=tprocdef(pd).fileinfo;
  138. { Generate VMT variable for constructor/destructor }
  139. if pd.proctypeoption in [potype_constructor,potype_destructor] then
  140. begin
  141. { can't use classrefdef as type because inheriting
  142. will then always file because of a type mismatch }
  143. tt:=voidpointertype;
  144. vs:=tparavarsym.create('$vmt',paranr_vmt,vs_value,tt,[vo_is_vmt,vo_is_hidden_para]);
  145. pd.parast.insert(vs);
  146. end;
  147. { Generate self variable, for classes we need
  148. to use the generic voidpointer to be compatible with
  149. methodpointers }
  150. vsp:=vs_value;
  151. if (po_staticmethod in pd.procoptions) or
  152. (po_classmethod in pd.procoptions) then
  153. begin
  154. tt.setdef(tprocdef(pd)._class);
  155. tt.setdef(tclassrefdef.create(tt));
  156. end
  157. else
  158. begin
  159. if is_object(tprocdef(pd)._class) then
  160. vsp:=vs_var;
  161. tt.setdef(tprocdef(pd)._class);
  162. end;
  163. vs:=tparavarsym.create('$self',paranr_self,vsp,tt,[vo_is_self,vo_is_hidden_para]);
  164. pd.parast.insert(vs);
  165. akttokenpos:=storepos;
  166. end;
  167. end;
  168. end;
  169. procedure insert_funcret_local(pd:tprocdef);
  170. var
  171. storepos : tfileposinfo;
  172. vs : tlocalvarsym;
  173. aliasvs : tabsolutevarsym;
  174. sl : tsymlist;
  175. begin
  176. { The result from constructors and destructors can't be accessed directly }
  177. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  178. not is_void(pd.rettype.def) then
  179. begin
  180. storepos:=akttokenpos;
  181. akttokenpos:=pd.fileinfo;
  182. { We always need a localsymtable }
  183. if not assigned(pd.localst) then
  184. pd.insert_localst;
  185. { We need to insert a varsym for the result in the localst
  186. when it is returning in a register }
  187. if not paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  188. begin
  189. vs:=tlocalvarsym.create('$result',vs_value,pd.rettype,[vo_is_funcret]);
  190. pd.localst.insert(vs);
  191. pd.funcretsym:=vs;
  192. end;
  193. { insert the name of the procedure as alias for the function result,
  194. we can't use realname because that will not work for compilerprocs
  195. as the name is lowercase and unreachable from the code }
  196. if pd.resultname='' then
  197. pd.resultname:=pd.procsym.name;
  198. sl:=tsymlist.create;
  199. sl.addsym(sl_load,pd.funcretsym);
  200. aliasvs:=tabsolutevarsym.create_ref(pd.resultname,pd.rettype,sl);
  201. include(aliasvs.varoptions,vo_is_funcret);
  202. tlocalsymtable(pd.localst).insert(aliasvs);
  203. { insert result also if support is on }
  204. if (m_result in aktmodeswitches) then
  205. begin
  206. sl:=tsymlist.create;
  207. sl.addsym(sl_load,pd.funcretsym);
  208. aliasvs:=tabsolutevarsym.create_ref('RESULT',pd.rettype,sl);
  209. include(aliasvs.varoptions,vo_is_funcret);
  210. include(aliasvs.varoptions,vo_is_result);
  211. tlocalsymtable(pd.localst).insert(aliasvs);
  212. end;
  213. akttokenpos:=storepos;
  214. end;
  215. end;
  216. procedure insert_hidden_para(p:tnamedindexitem;arg:pointer);
  217. var
  218. hvs : tparavarsym;
  219. pd : tabstractprocdef absolute arg;
  220. begin
  221. if (tsym(p).typ<>paravarsym) then
  222. exit;
  223. with tparavarsym(p) do
  224. begin
  225. { We need a local copy for a value parameter when only the
  226. address is pushed. Open arrays and Array of Const are
  227. an exception because they are allocated at runtime and the
  228. address that is pushed is patched }
  229. if (varspez=vs_value) and
  230. paramanager.push_addr_param(varspez,vartype.def,pd.proccalloption) and
  231. not(is_open_array(vartype.def) or
  232. is_array_of_const(vartype.def)) then
  233. include(varoptions,vo_has_local_copy);
  234. { needs high parameter ? }
  235. if paramanager.push_high_param(varspez,vartype.def,pd.proccalloption) then
  236. begin
  237. hvs:=tparavarsym.create('$high'+name,paranr+1,vs_const,sinttype,[vo_is_high_para,vo_is_hidden_para]);
  238. owner.insert(hvs);
  239. end
  240. else
  241. begin
  242. { Give a warning that cdecl routines does not include high()
  243. support }
  244. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  245. paramanager.push_high_param(varspez,vartype.def,pocall_default) then
  246. begin
  247. if is_open_string(vartype.def) then
  248. Message(parser_w_cdecl_no_openstring);
  249. if not (po_external in pd.procoptions) then
  250. Message(parser_w_cdecl_has_no_high);
  251. end;
  252. end;
  253. end;
  254. end;
  255. procedure check_c_para(p:tnamedindexitem;arg:pointer);
  256. begin
  257. if (tsym(p).typ<>paravarsym) then
  258. exit;
  259. with tparavarsym(p) do
  260. begin
  261. case vartype.def.deftype of
  262. arraydef :
  263. begin
  264. if not is_variant_array(vartype.def) and
  265. not is_array_of_const(vartype.def) then
  266. begin
  267. if (varspez<>vs_var) then
  268. Message(parser_h_c_arrays_are_references);
  269. end;
  270. if is_array_of_const(vartype.def) and
  271. assigned(indexnext) and
  272. (tsym(indexnext).typ=paravarsym) and
  273. not(vo_is_high_para in tparavarsym(indexnext).varoptions) then
  274. Message(parser_e_C_array_of_const_must_be_last);
  275. end;
  276. end;
  277. end;
  278. end;
  279. procedure check_msg_para(p:tnamedindexitem;arg:pointer);
  280. begin
  281. if (tsym(p).typ<>paravarsym) then
  282. exit;
  283. with tparavarsym(p) do
  284. begin
  285. { Count parameters }
  286. if (paranr>=10) then
  287. inc(plongint(arg)^);
  288. { First parameter must be var }
  289. if (paranr=10) and
  290. (varspez<>vs_var) then
  291. Message(parser_e_ill_msg_param);
  292. end;
  293. end;
  294. procedure check_inline_para(p:tnamedindexitem;arg:pointer);
  295. var
  296. pd : tabstractprocdef absolute arg;
  297. begin
  298. if not(po_inline in pd.procoptions) or
  299. (tsym(p).typ<>paravarsym) then
  300. exit;
  301. with tparavarsym(p) do
  302. begin
  303. case vartype.def.deftype of
  304. arraydef :
  305. begin
  306. if is_array_constructor(vartype.def) or
  307. is_variant_array(vartype.def) then
  308. begin
  309. Message1(parser_w_not_supported_for_inline,'array of const');
  310. Message(parser_w_inlining_disabled);
  311. pd.proccalloption:=pocall_default;
  312. end;
  313. end;
  314. end;
  315. end;
  316. end;
  317. procedure set_addr_param_regable(p:tnamedindexitem;arg:pointer);
  318. begin
  319. if (tsym(p).typ<>paravarsym) then
  320. exit;
  321. with tparavarsym(p) do
  322. begin
  323. if not vartype.def.needs_inittable and
  324. paramanager.push_addr_param(varspez,vartype.def,tprocdef(arg).proccalloption) then
  325. varregable:=vr_intreg;
  326. end;
  327. end;
  328. procedure parse_parameter_dec(pd:tabstractprocdef);
  329. {
  330. handle_procvar needs the same changes
  331. }
  332. type
  333. tppv = (pv_none,pv_proc,pv_func);
  334. var
  335. sc : TFPObjectList;
  336. tt : ttype;
  337. arrayelementtype : ttype;
  338. vs : tparavarsym;
  339. i : longint;
  340. srsym : tsym;
  341. pv : tprocvardef;
  342. varspez : Tvarspez;
  343. defaultvalue : tconstsym;
  344. defaultrequired : boolean;
  345. old_object_option : tsymoptions;
  346. currparast : tparasymtable;
  347. parseprocvar : tppv;
  348. explicit_paraloc : boolean;
  349. locationstr : string;
  350. paranr : integer;
  351. dummytype : ttypesym;
  352. begin
  353. explicit_paraloc:=false;
  354. consume(_LKLAMMER);
  355. { Delphi/Kylix supports nonsense like }
  356. { procedure p(); }
  357. if try_to_consume(_RKLAMMER) and
  358. not(m_tp7 in aktmodeswitches) then
  359. exit;
  360. { parsing a proc or procvar ? }
  361. currparast:=tparasymtable(pd.parast);
  362. { reset }
  363. sc:=TFPObjectList.create(false);
  364. defaultrequired:=false;
  365. paranr:=0;
  366. { the variables are always public }
  367. old_object_option:=current_object_option;
  368. current_object_option:=[sp_public];
  369. inc(testcurobject);
  370. repeat
  371. parseprocvar:=pv_none;
  372. if try_to_consume(_VAR) then
  373. varspez:=vs_var
  374. else
  375. if try_to_consume(_CONST) then
  376. varspez:=vs_const
  377. else
  378. if (m_out in aktmodeswitches) and
  379. try_to_consume(_OUT) then
  380. varspez:=vs_out
  381. else
  382. if (m_mac in aktmodeswitches) and
  383. try_to_consume(_POINTPOINTPOINT) then
  384. begin
  385. include(pd.procoptions,po_varargs);
  386. break;
  387. end
  388. else
  389. if (m_mac in aktmodeswitches) and
  390. try_to_consume(_PROCEDURE) then
  391. begin
  392. parseprocvar:=pv_proc;
  393. varspez:=vs_const;
  394. end
  395. else
  396. if (m_mac in aktmodeswitches) and
  397. try_to_consume(_FUNCTION) then
  398. begin
  399. parseprocvar:=pv_func;
  400. varspez:=vs_const;
  401. end
  402. else
  403. varspez:=vs_value;
  404. defaultvalue:=nil;
  405. tt.reset;
  406. { read identifiers and insert with error type }
  407. sc.clear;
  408. repeat
  409. inc(paranr);
  410. vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrortype,[]);
  411. currparast.insert(vs);
  412. if assigned(vs.owner) then
  413. sc.add(vs)
  414. else
  415. vs.free;
  416. consume(_ID);
  417. until not try_to_consume(_COMMA);
  418. locationstr:='';
  419. { macpas anonymous procvar }
  420. if parseprocvar<>pv_none then
  421. begin
  422. pv:=tprocvardef.create(normal_function_level);
  423. if token=_LKLAMMER then
  424. parse_parameter_dec(pv);
  425. if parseprocvar=pv_func then
  426. begin
  427. consume(_COLON);
  428. single_type(pv.rettype,false);
  429. end;
  430. tt.def:=pv;
  431. { possible proc directives }
  432. if check_proc_directive(true) then
  433. begin
  434. dummytype:=ttypesym.create('unnamed',tt);
  435. parse_var_proc_directives(tsym(dummytype));
  436. dummytype.restype.def:=nil;
  437. tt.def.typesym:=nil;
  438. dummytype.free;
  439. end;
  440. { Add implicit hidden parameters and function result }
  441. handle_calling_convention(pv);
  442. end
  443. else
  444. { read type declaration, force reading for value and const paras }
  445. if (token=_COLON) or (varspez=vs_value) then
  446. begin
  447. consume(_COLON);
  448. { check for an open array }
  449. if token=_ARRAY then
  450. begin
  451. consume(_ARRAY);
  452. consume(_OF);
  453. { define range and type of range }
  454. tt.setdef(tarraydef.create(0,-1,s32inttype));
  455. { array of const ? }
  456. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  457. begin
  458. consume(_CONST);
  459. srsym:=search_system_type('TVARREC');
  460. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  461. include(tarraydef(tt.def).arrayoptions,ado_IsArrayOfConst);
  462. end
  463. else
  464. begin
  465. { define field type }
  466. single_type(arrayelementtype,false);
  467. tarraydef(tt.def).setelementtype(arrayelementtype);
  468. end;
  469. end
  470. else
  471. begin
  472. if (m_mac in aktmodeswitches) then
  473. try_to_consume(_UNIV); {currently does nothing}
  474. single_type(tt,false);
  475. { open string ? }
  476. if (varspez in [vs_out,vs_var]) and
  477. (cs_openstring in aktmoduleswitches) and
  478. is_shortstring(tt.def) then
  479. tt:=openshortstringtype;
  480. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  481. begin
  482. if (idtoken=_LOCATION) then
  483. begin
  484. consume(_LOCATION);
  485. locationstr:=pattern;
  486. consume(_CSTRING);
  487. end
  488. else
  489. begin
  490. if explicit_paraloc then
  491. Message(parser_e_paraloc_all_paras);
  492. locationstr:='';
  493. end;
  494. end
  495. else
  496. locationstr:='';
  497. { default parameter }
  498. if (m_default_para in aktmodeswitches) then
  499. begin
  500. if try_to_consume(_EQUAL) then
  501. begin
  502. vs:=tparavarsym(sc[0]);
  503. if sc.count>1 then
  504. Message(parser_e_default_value_only_one_para);
  505. { prefix 'def' to the parameter name }
  506. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  507. if assigned(defaultvalue) then
  508. begin
  509. include(defaultvalue.symoptions,sp_internal);
  510. pd.parast.insert(defaultvalue);
  511. end;
  512. defaultrequired:=true;
  513. end
  514. else
  515. begin
  516. if defaultrequired then
  517. Message1(parser_e_default_value_expected_for_para,vs.name);
  518. end;
  519. end;
  520. end;
  521. end
  522. else
  523. tt:=cformaltype;
  524. { File types are only allowed for var and out parameters }
  525. if (tt.def.deftype=filedef) and
  526. not(varspez in [vs_out,vs_var]) then
  527. CGMessage(cg_e_file_must_call_by_reference);
  528. for i:=0 to sc.count-1 do
  529. begin
  530. vs:=tparavarsym(sc[i]);
  531. { update varsym }
  532. vs.vartype:=tt;
  533. vs.defaultconstsym:=defaultvalue;
  534. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  535. begin
  536. if locationstr<>'' then
  537. begin
  538. if sc.count>1 then
  539. Message(parser_e_paraloc_only_one_para);
  540. if (paranr>1) and not(explicit_paraloc) then
  541. Message(parser_e_paraloc_all_paras);
  542. explicit_paraloc:=true;
  543. include(vs.varoptions,vo_has_explicit_paraloc);
  544. if not(paramanager.parseparaloc(vs,upper(locationstr))) then
  545. message(parser_e_illegal_explicit_paraloc);
  546. end
  547. else
  548. if explicit_paraloc then
  549. Message(parser_e_paraloc_all_paras);
  550. end;
  551. end;
  552. until not try_to_consume(_SEMICOLON);
  553. if explicit_paraloc then
  554. begin
  555. pd.has_paraloc_info:=true;
  556. include(pd.procoptions,po_explicitparaloc);
  557. end;
  558. { remove parasymtable from stack }
  559. sc.free;
  560. { reset object options }
  561. dec(testcurobject);
  562. current_object_option:=old_object_option;
  563. consume(_RKLAMMER);
  564. end;
  565. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  566. var
  567. hs : string;
  568. orgsp,sp : stringid;
  569. srsym : tsym;
  570. srsymtable : tsymtable;
  571. checkstack : psymtablestackitem;
  572. storepos,
  573. procstartfilepos : tfileposinfo;
  574. searchagain : boolean;
  575. i : longint;
  576. st : tsymtable;
  577. aprocsym : tprocsym;
  578. popclass : boolean;
  579. begin
  580. { Save the position where this procedure really starts }
  581. procstartfilepos:=akttokenpos;
  582. result:=false;
  583. pd:=nil;
  584. aprocsym:=nil;
  585. if (potype=potype_operator) then
  586. begin
  587. sp:=overloaded_names[optoken];
  588. orgsp:=sp;
  589. end
  590. else
  591. begin
  592. sp:=pattern;
  593. orgsp:=orgpattern;
  594. consume(_ID);
  595. end;
  596. { examine interface map: function/procedure iname.functionname=locfuncname }
  597. if assigned(aclass) and
  598. assigned(aclass.implementedinterfaces) and
  599. (aclass.implementedinterfaces.count>0) and
  600. try_to_consume(_POINT) then
  601. begin
  602. storepos:=akttokenpos;
  603. akttokenpos:=procstartfilepos;
  604. { get interface syms}
  605. searchsym(sp,srsym,srsymtable);
  606. if not assigned(srsym) then
  607. begin
  608. identifier_not_found(orgsp);
  609. srsym:=generrorsym;
  610. end;
  611. akttokenpos:=storepos;
  612. { qualifier is interface? }
  613. if (srsym.typ=typesym) and
  614. (ttypesym(srsym).restype.def.deftype=objectdef) then
  615. i:=aclass.implementedinterfaces.searchintf(ttypesym(srsym).restype.def)
  616. else
  617. i:=-1;
  618. if (i=-1) then
  619. Message(parser_e_interface_id_expected);
  620. consume(_ID);
  621. { Create unique name <interface>.<method> }
  622. hs:=sp+'.'+pattern;
  623. consume(_EQUAL);
  624. if (i<>-1) and
  625. (token=_ID) then
  626. aclass.implementedinterfaces.addmappings(i,hs,pattern);
  627. consume(_ID);
  628. result:=true;
  629. exit;
  630. end;
  631. { method ? }
  632. if not assigned(aclass) and
  633. (potype<>potype_operator) and
  634. (symtablestack.top.symtablelevel=main_program_level) and
  635. try_to_consume(_POINT) then
  636. begin
  637. { search for object name }
  638. storepos:=akttokenpos;
  639. akttokenpos:=procstartfilepos;
  640. searchsym(sp,srsym,srsymtable);
  641. if not assigned(srsym) then
  642. begin
  643. identifier_not_found(orgsp);
  644. srsym:=generrorsym;
  645. end;
  646. akttokenpos:=storepos;
  647. { consume proc name }
  648. sp:=pattern;
  649. orgsp:=orgpattern;
  650. procstartfilepos:=akttokenpos;
  651. consume(_ID);
  652. { qualifier is class name ? }
  653. if (srsym.typ=typesym) and
  654. (ttypesym(srsym).restype.def.deftype=objectdef) then
  655. begin
  656. aclass:=tobjectdef(ttypesym(srsym).restype.def);
  657. aprocsym:=tprocsym(aclass.symtable.search(sp));
  658. { we solve this below }
  659. if assigned(aprocsym) then
  660. begin
  661. if aprocsym.typ<>procsym then
  662. begin
  663. { we use a different error message for tp7 so it looks more compatible }
  664. if (m_fpc in aktmodeswitches) then
  665. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  666. else
  667. Message(parser_e_methode_id_expected);
  668. { rename the name to an unique name to avoid an
  669. error when inserting the symbol in the symtable }
  670. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  671. aprocsym:=nil;
  672. end;
  673. end
  674. else
  675. begin
  676. Message(parser_e_methode_id_expected);
  677. { recover by making it a normal procedure instead of method }
  678. aclass:=nil;
  679. end;
  680. end
  681. else
  682. Message(parser_e_class_id_expected);
  683. end
  684. else
  685. begin
  686. { check for constructor/destructor which is not allowed here }
  687. if (not parse_only) and
  688. (potype in [potype_constructor,potype_destructor]) then
  689. Message(parser_e_constructors_always_objects);
  690. repeat
  691. searchagain:=false;
  692. akttokenpos:=procstartfilepos;
  693. srsymtable:=symtablestack.top;
  694. srsym:=tsym(srsymtable.search(sp));
  695. { Also look in the globalsymtable if we didn't found
  696. the symbol in the localsymtable }
  697. if not assigned(srsym) and
  698. not(parse_only) and
  699. (srsymtable=current_module.localsymtable) and
  700. assigned(current_module.globalsymtable) then
  701. srsym:=tsym(current_module.globalsymtable.search(sp));
  702. { Check if overloaded is a procsym }
  703. if assigned(srsym) then
  704. begin
  705. if srsym.typ=procsym then
  706. aprocsym:=tprocsym(srsym)
  707. else
  708. begin
  709. { when the other symbol is a unit symbol then hide the unit
  710. symbol }
  711. if (srsym.typ=unitsym) then
  712. begin
  713. HideSym(srsym);
  714. searchagain:=true;
  715. end
  716. else
  717. begin
  718. { we use a different error message for tp7 so it looks more compatible }
  719. if (m_fpc in aktmodeswitches) then
  720. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  721. else
  722. DuplicateSym(nil,srsym);
  723. { rename the name to an unique name to avoid an
  724. error when inserting the symbol in the symtable }
  725. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  726. end;
  727. end;
  728. end;
  729. until not searchagain;
  730. end;
  731. { test again if assigned, it can be reset to recover }
  732. if not assigned(aprocsym) then
  733. begin
  734. { create a new procsym and set the real filepos }
  735. akttokenpos:=procstartfilepos;
  736. { for operator we have only one procsym for each overloaded
  737. operation }
  738. if (potype=potype_operator) then
  739. begin
  740. Aprocsym:=Tprocsym(symtablestack.top.search(sp));
  741. if Aprocsym=nil then
  742. Aprocsym:=tprocsym.create('$'+sp);
  743. end
  744. else
  745. aprocsym:=tprocsym.create(orgsp);
  746. symtablestack.top.insert(aprocsym);
  747. end;
  748. { to get the correct symtablelevel we must ignore objectsymtables }
  749. st:=nil;
  750. checkstack:=symtablestack.stack;
  751. while assigned(checkstack) do
  752. begin
  753. st:=checkstack^.symtable;
  754. if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
  755. break;
  756. checkstack:=checkstack^.next;
  757. end;
  758. pd:=tprocdef.create(st.symtablelevel+1);
  759. pd._class:=aclass;
  760. pd.procsym:=aprocsym;
  761. pd.proctypeoption:=potype;
  762. { methods inherit df_generic or df_specialization from the objectdef }
  763. if assigned(pd._class) then
  764. begin
  765. if (df_generic in pd._class.defoptions) then
  766. include(pd.defoptions,df_generic);
  767. if (df_specialization in pd._class.defoptions) then
  768. begin
  769. include(pd.defoptions,df_specialization);
  770. { Find corresponding genericdef, we need it later to
  771. replay the tokens to generate the body }
  772. if not assigned(pd._class.genericdef) then
  773. internalerror(200512113);
  774. st:=pd._class.genericdef.getsymtable(gs_record);
  775. if not assigned(st) then
  776. internalerror(200512114);
  777. { We are parsing the same objectdef, the def index numbers
  778. are the same }
  779. pd.genericdef:=tstoreddef(st.getdefnr(pd.indexnr));
  780. if not assigned(pd.genericdef) or
  781. (pd.genericdef.deftype<>procdef) then
  782. internalerror(200512115);
  783. end;
  784. end;
  785. { methods need to be exported }
  786. if assigned(aclass) and
  787. (
  788. (symtablestack.top.symtabletype=objectsymtable) or
  789. (symtablestack.top.symtablelevel=main_program_level)
  790. ) then
  791. include(pd.procoptions,po_global);
  792. { symbol options that need to be kept per procdef }
  793. pd.fileinfo:=procstartfilepos;
  794. pd.symoptions:=current_object_option;
  795. { parse parameters }
  796. if token=_LKLAMMER then
  797. begin
  798. { Add objectsymtable to be able to find generic type definitions }
  799. popclass:=false;
  800. if assigned(pd._class) and
  801. (pd.parast.symtablelevel=normal_function_level) and
  802. (symtablestack.top.symtabletype<>objectsymtable) then
  803. begin
  804. symtablestack.push(pd._class.symtable);
  805. popclass:=true;
  806. end;
  807. { Add parameter symtable }
  808. if pd.parast.symtabletype<>staticsymtable then
  809. symtablestack.push(pd.parast);
  810. parse_parameter_dec(pd);
  811. if pd.parast.symtabletype<>staticsymtable then
  812. symtablestack.pop(pd.parast);
  813. if popclass then
  814. symtablestack.pop(pd._class.symtable);
  815. end;
  816. result:=true;
  817. end;
  818. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  819. var
  820. pd : tprocdef;
  821. isclassmethod : boolean;
  822. locationstr: string;
  823. begin
  824. locationstr:='';
  825. pd:=nil;
  826. isclassmethod:=false;
  827. { read class method }
  828. if try_to_consume(_CLASS) then
  829. begin
  830. { class method only allowed for procedures and functions }
  831. if not(token in [_FUNCTION,_PROCEDURE]) then
  832. Message(parser_e_procedure_or_function_expected);
  833. if is_interface(aclass) then
  834. Message(parser_e_no_static_method_in_interfaces)
  835. else
  836. isclassmethod:=true;
  837. end;
  838. case token of
  839. _FUNCTION :
  840. begin
  841. consume(_FUNCTION);
  842. if parse_proc_head(aclass,potype_function,pd) then
  843. begin
  844. { pd=nil when it is a interface mapping }
  845. if assigned(pd) then
  846. begin
  847. if try_to_consume(_COLON) then
  848. begin
  849. inc(testcurobject);
  850. single_type(pd.rettype,false);
  851. pd.test_if_fpu_result;
  852. dec(testcurobject);
  853. if (target_info.system in [system_m68k_amiga]) then
  854. begin
  855. if (idtoken=_LOCATION) then
  856. begin
  857. if po_explicitparaloc in pd.procoptions then
  858. begin
  859. consume(_LOCATION);
  860. locationstr:=pattern;
  861. consume(_CSTRING);
  862. end
  863. else
  864. { I guess this needs a new message... (KB) }
  865. Message(parser_e_paraloc_all_paras);
  866. end
  867. else
  868. begin
  869. if po_explicitparaloc in pd.procoptions then
  870. { assign default locationstr, if none specified }
  871. { and we've arguments with explicit paraloc }
  872. locationstr:='D0';
  873. end;
  874. end;
  875. end
  876. else
  877. begin
  878. if (
  879. parse_only and
  880. not(is_interface(pd._class))
  881. ) or
  882. (m_repeat_forward in aktmodeswitches) then
  883. begin
  884. consume(_COLON);
  885. consume_all_until(_SEMICOLON);
  886. end;
  887. end;
  888. if isclassmethod then
  889. include(pd.procoptions,po_classmethod);
  890. end;
  891. end
  892. else
  893. begin
  894. { recover }
  895. consume(_COLON);
  896. consume_all_until(_SEMICOLON);
  897. end;
  898. end;
  899. _PROCEDURE :
  900. begin
  901. consume(_PROCEDURE);
  902. if parse_proc_head(aclass,potype_procedure,pd) then
  903. begin
  904. { pd=nil when it is a interface mapping }
  905. if assigned(pd) then
  906. begin
  907. pd.rettype:=voidtype;
  908. if isclassmethod then
  909. include(pd.procoptions,po_classmethod);
  910. end;
  911. end;
  912. end;
  913. _CONSTRUCTOR :
  914. begin
  915. consume(_CONSTRUCTOR);
  916. parse_proc_head(aclass,potype_constructor,pd);
  917. if assigned(pd) and
  918. assigned(pd._class) then
  919. begin
  920. { Set return type, class constructors return the
  921. created instance, object constructors return boolean }
  922. if is_class(pd._class) then
  923. pd.rettype.setdef(pd._class)
  924. else
  925. pd.rettype:=booltype;
  926. end;
  927. end;
  928. _DESTRUCTOR :
  929. begin
  930. consume(_DESTRUCTOR);
  931. parse_proc_head(aclass,potype_destructor,pd);
  932. if assigned(pd) then
  933. pd.rettype:=voidtype;
  934. end;
  935. _OPERATOR :
  936. begin
  937. consume(_OPERATOR);
  938. if (token in [first_overloaded..last_overloaded]) then
  939. begin
  940. optoken:=token;
  941. end
  942. else
  943. begin
  944. Message(parser_e_overload_operator_failed);
  945. { Use the dummy NOTOKEN that is also declared
  946. for the overloaded_operator[] }
  947. optoken:=NOTOKEN;
  948. end;
  949. consume(token);
  950. parse_proc_head(aclass,potype_operator,pd);
  951. if assigned(pd) then
  952. begin
  953. if pd.parast.symtablelevel>normal_function_level then
  954. Message(parser_e_no_local_operator);
  955. if token<>_ID then
  956. begin
  957. if not(m_result in aktmodeswitches) then
  958. consume(_ID);
  959. end
  960. else
  961. begin
  962. pd.resultname:=orgpattern;
  963. consume(_ID);
  964. end;
  965. if not try_to_consume(_COLON) then
  966. begin
  967. consume(_COLON);
  968. pd.rettype:=generrortype;
  969. consume_all_until(_SEMICOLON);
  970. end
  971. else
  972. begin
  973. single_type(pd.rettype,false);
  974. pd.test_if_fpu_result;
  975. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  976. ((pd.rettype.def.deftype<>orddef) or
  977. (torddef(pd.rettype.def).typ<>bool8bit)) then
  978. Message(parser_e_comparative_operator_return_boolean);
  979. if (optoken=_ASSIGNMENT) and
  980. equal_defs(pd.rettype.def,
  981. tparavarsym(pd.parast.symindex.first).vartype.def) then
  982. message(parser_e_no_such_assignment)
  983. else if not isoperatoracceptable(pd,optoken) then
  984. Message(parser_e_overload_impossible);
  985. end;
  986. end
  987. else
  988. begin
  989. { recover }
  990. try_to_consume(_ID);
  991. consume(_COLON);
  992. consume_all_until(_SEMICOLON);
  993. end;
  994. end;
  995. end;
  996. { support procedure proc stdcall export; }
  997. if not(check_proc_directive(false)) then
  998. consume(_SEMICOLON);
  999. result:=pd;
  1000. if locationstr<>'' then
  1001. begin
  1002. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1003. { I guess this needs a new message... (KB) }
  1004. message(parser_e_illegal_explicit_paraloc);
  1005. end;
  1006. end;
  1007. {****************************************************************************
  1008. Procedure directive handlers
  1009. ****************************************************************************}
  1010. procedure pd_far(pd:tabstractprocdef);
  1011. begin
  1012. Message1(parser_w_proc_directive_ignored,'FAR');
  1013. end;
  1014. procedure pd_near(pd:tabstractprocdef);
  1015. begin
  1016. Message1(parser_w_proc_directive_ignored,'NEAR');
  1017. end;
  1018. procedure pd_export(pd:tabstractprocdef);
  1019. begin
  1020. if pd.deftype<>procdef then
  1021. internalerror(200304264);
  1022. if assigned(tprocdef(pd)._class) then
  1023. Message(parser_e_methods_dont_be_export);
  1024. if pd.parast.symtablelevel>normal_function_level then
  1025. Message(parser_e_dont_nest_export);
  1026. end;
  1027. procedure pd_forward(pd:tabstractprocdef);
  1028. begin
  1029. if pd.deftype<>procdef then
  1030. internalerror(200304265);
  1031. tprocdef(pd).forwarddef:=true;
  1032. end;
  1033. procedure pd_alias(pd:tabstractprocdef);
  1034. begin
  1035. if pd.deftype<>procdef then
  1036. internalerror(200304266);
  1037. consume(_COLON);
  1038. tprocdef(pd).aliasnames.insert(get_stringconst);
  1039. include(pd.procoptions,po_has_public_name);
  1040. end;
  1041. procedure pd_public(pd:tabstractprocdef);
  1042. begin
  1043. if pd.deftype<>procdef then
  1044. internalerror(200304266);
  1045. if try_to_consume(_NAME) then
  1046. begin
  1047. tprocdef(pd).aliasnames.insert(get_stringconst);
  1048. include(pd.procoptions,po_has_public_name);
  1049. end;
  1050. end;
  1051. procedure pd_asmname(pd:tabstractprocdef);
  1052. begin
  1053. if pd.deftype<>procdef then
  1054. internalerror(200304267);
  1055. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1056. if token=_CCHAR then
  1057. consume(_CCHAR)
  1058. else
  1059. consume(_CSTRING);
  1060. { we don't need anything else }
  1061. tprocdef(pd).forwarddef:=false;
  1062. end;
  1063. procedure pd_inline(pd:tabstractprocdef);
  1064. begin
  1065. { Check if there are parameters that can't be inlined }
  1066. pd.parast.foreach_static(@check_inline_para,pd);
  1067. end;
  1068. procedure pd_internconst(pd:tabstractprocdef);
  1069. begin
  1070. if pd.deftype<>procdef then
  1071. internalerror(200304268);
  1072. consume(_COLON);
  1073. tprocdef(pd).extnumber:=longint(get_intconst);
  1074. end;
  1075. procedure pd_internproc(pd:tabstractprocdef);
  1076. begin
  1077. if pd.deftype<>procdef then
  1078. internalerror(200304268);
  1079. consume(_COLON);
  1080. tprocdef(pd).extnumber:=longint(get_intconst);
  1081. { the proc is defined }
  1082. tprocdef(pd).forwarddef:=false;
  1083. end;
  1084. procedure pd_interrupt(pd:tabstractprocdef);
  1085. begin
  1086. if pd.parast.symtablelevel>normal_function_level then
  1087. Message(parser_e_dont_nest_interrupt);
  1088. end;
  1089. procedure pd_abstract(pd:tabstractprocdef);
  1090. begin
  1091. if pd.deftype<>procdef then
  1092. internalerror(200304269);
  1093. if (po_virtualmethod in pd.procoptions) then
  1094. include(pd.procoptions,po_abstractmethod)
  1095. else
  1096. Message(parser_e_only_virtual_methods_abstract);
  1097. { the method is defined }
  1098. tprocdef(pd).forwarddef:=false;
  1099. end;
  1100. procedure pd_virtual(pd:tabstractprocdef);
  1101. {$ifdef WITHDMT}
  1102. var
  1103. pt : tnode;
  1104. {$endif WITHDMT}
  1105. begin
  1106. if pd.deftype<>procdef then
  1107. internalerror(2003042610);
  1108. if (pd.proctypeoption=potype_constructor) and
  1109. is_object(tprocdef(pd)._class) then
  1110. Message(parser_e_constructor_cannot_be_not_virtual);
  1111. {$ifdef WITHDMT}
  1112. if is_object(tprocdef(pd)._class) and
  1113. (token<>_SEMICOLON) then
  1114. begin
  1115. { any type of parameter is allowed here! }
  1116. pt:=comp_expr(true);
  1117. if is_constintnode(pt) then
  1118. begin
  1119. include(pd.procoptions,po_msgint);
  1120. pd.messageinf.i:=pt^.value;
  1121. end
  1122. else
  1123. Message(parser_e_ill_msg_expr);
  1124. disposetree(pt);
  1125. end;
  1126. {$endif WITHDMT}
  1127. end;
  1128. procedure pd_static(pd:tabstractprocdef);
  1129. begin
  1130. if (cs_static_keyword in aktmoduleswitches) then
  1131. begin
  1132. if pd.deftype=procdef then
  1133. include(tprocdef(pd).procsym.symoptions,sp_static);
  1134. include(pd.procoptions,po_staticmethod);
  1135. end;
  1136. end;
  1137. procedure pd_override(pd:tabstractprocdef);
  1138. begin
  1139. if pd.deftype<>procdef then
  1140. internalerror(2003042611);
  1141. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1142. Message(parser_e_no_object_override);
  1143. end;
  1144. procedure pd_overload(pd:tabstractprocdef);
  1145. begin
  1146. if pd.deftype<>procdef then
  1147. internalerror(2003042612);
  1148. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1149. end;
  1150. procedure pd_message(pd:tabstractprocdef);
  1151. var
  1152. pt : tnode;
  1153. paracnt : longint;
  1154. begin
  1155. if pd.deftype<>procdef then
  1156. internalerror(2003042613);
  1157. if not is_class(tprocdef(pd)._class) then
  1158. Message(parser_e_msg_only_for_classes);
  1159. { check parameter type }
  1160. paracnt:=0;
  1161. pd.parast.foreach_static(@check_msg_para,@paracnt);
  1162. if paracnt<>1 then
  1163. Message(parser_e_ill_msg_param);
  1164. pt:=comp_expr(true);
  1165. if pt.nodetype=stringconstn then
  1166. begin
  1167. include(pd.procoptions,po_msgstr);
  1168. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1169. end
  1170. else
  1171. if is_constintnode(pt) then
  1172. begin
  1173. include(pd.procoptions,po_msgint);
  1174. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1175. end
  1176. else
  1177. Message(parser_e_ill_msg_expr);
  1178. pt.free;
  1179. end;
  1180. procedure pd_reintroduce(pd:tabstractprocdef);
  1181. begin
  1182. if pd.deftype<>procdef then
  1183. internalerror(200401211);
  1184. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1185. Message(parser_e_no_object_reintroduce);
  1186. end;
  1187. procedure pd_syscall(pd:tabstractprocdef);
  1188. {$if defined(powerpc) or defined(m68k)}
  1189. var
  1190. vs : tparavarsym;
  1191. sym : tsym;
  1192. symtable : tsymtable;
  1193. {$endif defined(powerpc) or defined(m68k)}
  1194. begin
  1195. if (pd.deftype<>procdef) and (target_info.system <> system_powerpc_amiga) then
  1196. internalerror(2003042614);
  1197. tprocdef(pd).forwarddef:=false;
  1198. {$ifdef m68k}
  1199. if target_info.system in [system_m68k_amiga] then
  1200. begin
  1201. include(pd.procoptions,po_syscall_legacy);
  1202. if consume_sym(sym,symtable) then
  1203. begin
  1204. if (sym.typ=globalvarsym) and
  1205. (
  1206. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1207. is_32bitint(tabstractvarsym(sym).vartype.def)
  1208. ) then
  1209. begin
  1210. tprocdef(pd).libsym:=sym;
  1211. if po_syscall_legacy in tprocdef(pd).procoptions then
  1212. begin
  1213. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1214. paramanager.parseparaloc(vs,'A6');
  1215. pd.parast.insert(vs);
  1216. end
  1217. end
  1218. else
  1219. Message(parser_e_32bitint_or_pointer_variable_expected);
  1220. end;
  1221. (paramanager as tm68kparamanager).create_funcretloc_info(pd,calleeside);
  1222. (paramanager as tm68kparamanager).create_funcretloc_info(pd,callerside);
  1223. tprocdef(pd).extnumber:=get_intconst;
  1224. end;
  1225. {$endif m68k}
  1226. {$ifdef powerpc}
  1227. if target_info.system = system_powerpc_amiga then
  1228. begin
  1229. include(pd.procoptions,po_syscall_sysv);
  1230. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1231. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1232. end else
  1233. if target_info.system = system_powerpc_morphos then
  1234. begin
  1235. if idtoken=_LEGACY then
  1236. begin
  1237. consume(_LEGACY);
  1238. include(pd.procoptions,po_syscall_legacy);
  1239. end
  1240. else if idtoken=_SYSV then
  1241. begin
  1242. consume(_SYSV);
  1243. include(pd.procoptions,po_syscall_sysv);
  1244. end
  1245. else if idtoken=_BASESYSV then
  1246. begin
  1247. consume(_BASESYSV);
  1248. include(pd.procoptions,po_syscall_basesysv);
  1249. end
  1250. else if idtoken=_SYSVBASE then
  1251. begin
  1252. consume(_SYSVBASE);
  1253. include(pd.procoptions,po_syscall_sysvbase);
  1254. end
  1255. else if idtoken=_R12BASE then
  1256. begin
  1257. consume(_R12BASE);
  1258. include(pd.procoptions,po_syscall_r12base);
  1259. end
  1260. else
  1261. if syscall_convention='LEGACY' then
  1262. include(pd.procoptions,po_syscall_legacy)
  1263. else if syscall_convention='SYSV' then
  1264. include(pd.procoptions,po_syscall_sysv)
  1265. else if syscall_convention='BASESYSV' then
  1266. include(pd.procoptions,po_syscall_basesysv)
  1267. else if syscall_convention='SYSVBASE' then
  1268. include(pd.procoptions,po_syscall_sysvbase)
  1269. else if syscall_convention='R12BASE' then
  1270. include(pd.procoptions,po_syscall_r12base)
  1271. else
  1272. internalerror(2005010404);
  1273. if consume_sym(sym,symtable) then
  1274. begin
  1275. if (sym.typ=globalvarsym) and
  1276. (
  1277. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1278. is_32bitint(tabstractvarsym(sym).vartype.def)
  1279. ) then
  1280. begin
  1281. tprocdef(pd).libsym:=sym;
  1282. if po_syscall_legacy in tprocdef(pd).procoptions then
  1283. begin
  1284. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1285. paramanager.parseparaloc(vs,'A6');
  1286. pd.parast.insert(vs);
  1287. end
  1288. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1289. begin
  1290. { Nothing to be done for sysv here for now, but this might change }
  1291. end
  1292. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1293. begin
  1294. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1295. pd.parast.insert(vs);
  1296. end
  1297. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1298. begin
  1299. vs:=tparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1300. pd.parast.insert(vs);
  1301. end
  1302. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1303. begin
  1304. vs:=tparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1305. paramanager.parseparaloc(vs,'R12');
  1306. pd.parast.insert(vs);
  1307. end
  1308. else
  1309. internalerror(2005010501);
  1310. end
  1311. else
  1312. Message(parser_e_32bitint_or_pointer_variable_expected);
  1313. end;
  1314. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1315. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1316. tprocdef(pd).extnumber:=get_intconst;
  1317. end;
  1318. {$endif powerpc}
  1319. end;
  1320. procedure pd_external(pd:tabstractprocdef);
  1321. {
  1322. If import_dll=nil the procedure is assumed to be in another
  1323. object file. In that object file it should have the name to
  1324. which import_name is pointing to. Otherwise, the procedure is
  1325. assumed to be in the DLL to which import_dll is pointing to. In
  1326. that case either import_nr<>0 or import_name<>nil is true, so
  1327. the procedure is either imported by number or by name. (DM)
  1328. }
  1329. begin
  1330. if pd.deftype<>procdef then
  1331. internalerror(2003042615);
  1332. with tprocdef(pd) do
  1333. begin
  1334. forwarddef:=false;
  1335. { forbid local external procedures }
  1336. if parast.symtablelevel>normal_function_level then
  1337. Message(parser_e_no_local_proc_external);
  1338. { If the procedure should be imported from a DLL, a constant string follows.
  1339. This isn't really correct, an contant string expression follows
  1340. so we check if an semicolon follows, else a string constant have to
  1341. follow (FK) }
  1342. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1343. begin
  1344. import_dll:=stringdup(get_stringconst);
  1345. if (idtoken=_NAME) then
  1346. begin
  1347. consume(_NAME);
  1348. import_name:=stringdup(get_stringconst);
  1349. if import_name^='' then
  1350. message(parser_e_empty_import_name);
  1351. end;
  1352. if (idtoken=_INDEX) then
  1353. begin
  1354. {After the word index follows the index number in the DLL.}
  1355. consume(_INDEX);
  1356. import_nr:=longint(get_intconst);
  1357. end;
  1358. { default is to used the realname of the procedure }
  1359. if (import_nr=0) and not assigned(import_name) then
  1360. import_name:=stringdup(procsym.realname);
  1361. end
  1362. else
  1363. begin
  1364. if (idtoken=_NAME) then
  1365. begin
  1366. consume(_NAME);
  1367. import_name:=stringdup(get_stringconst);
  1368. if import_name^='' then
  1369. message(parser_e_empty_import_name);
  1370. end;
  1371. end;
  1372. end;
  1373. end;
  1374. type
  1375. pd_handler=procedure(pd:tabstractprocdef);
  1376. proc_dir_rec=record
  1377. idtok : ttoken;
  1378. pd_flags : tpdflags;
  1379. handler : pd_handler;
  1380. pocall : tproccalloption;
  1381. pooption : tprocoptions;
  1382. mutexclpocall : tproccalloptions;
  1383. mutexclpotype : tproctypeoptions;
  1384. mutexclpo : tprocoptions;
  1385. end;
  1386. const
  1387. {Should contain the number of procedure directives we support.}
  1388. num_proc_directives=37;
  1389. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1390. (
  1391. (
  1392. idtok:_ABSTRACT;
  1393. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1394. handler : @pd_abstract;
  1395. pocall : pocall_none;
  1396. pooption : [po_abstractmethod];
  1397. mutexclpocall : [pocall_internproc];
  1398. mutexclpotype : [];
  1399. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  1400. ),(
  1401. idtok:_ALIAS;
  1402. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1403. handler : @pd_alias;
  1404. pocall : pocall_none;
  1405. pooption : [];
  1406. mutexclpocall : [];
  1407. mutexclpotype : [];
  1408. mutexclpo : [po_external,po_inline]
  1409. ),(
  1410. idtok:_ASMNAME;
  1411. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1412. handler : @pd_asmname;
  1413. pocall : pocall_cdecl;
  1414. pooption : [po_external];
  1415. mutexclpocall : [pocall_internproc];
  1416. mutexclpotype : [];
  1417. mutexclpo : [po_external,po_inline]
  1418. ),(
  1419. idtok:_ASSEMBLER;
  1420. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1421. handler : nil;
  1422. pocall : pocall_none;
  1423. pooption : [po_assembler];
  1424. mutexclpocall : [];
  1425. mutexclpotype : [];
  1426. mutexclpo : [po_external]
  1427. ),(
  1428. idtok:_C; {same as cdecl for mode mac}
  1429. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1430. handler : nil;
  1431. pocall : pocall_cdecl;
  1432. pooption : [];
  1433. mutexclpocall : [];
  1434. mutexclpotype : [potype_constructor,potype_destructor];
  1435. mutexclpo : [po_assembler,po_external]
  1436. ),(
  1437. idtok:_CDECL;
  1438. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1439. handler : nil;
  1440. pocall : pocall_cdecl;
  1441. pooption : [];
  1442. mutexclpocall : [];
  1443. mutexclpotype : [potype_constructor,potype_destructor];
  1444. mutexclpo : [po_assembler,po_external]
  1445. ),(
  1446. idtok:_DYNAMIC;
  1447. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1448. handler : @pd_virtual;
  1449. pocall : pocall_none;
  1450. pooption : [po_virtualmethod];
  1451. mutexclpocall : [pocall_internproc];
  1452. mutexclpotype : [];
  1453. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  1454. ),(
  1455. idtok:_EXPORT;
  1456. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1457. handler : @pd_export;
  1458. pocall : pocall_none;
  1459. pooption : [po_exports,po_global];
  1460. mutexclpocall : [pocall_internproc];
  1461. mutexclpotype : [potype_constructor,potype_destructor];
  1462. mutexclpo : [po_external,po_interrupt,po_inline]
  1463. ),(
  1464. idtok:_EXTERNAL;
  1465. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1466. handler : @pd_external;
  1467. pocall : pocall_none;
  1468. pooption : [po_external];
  1469. mutexclpocall : [pocall_internproc,pocall_syscall];
  1470. mutexclpotype : [potype_constructor,potype_destructor];
  1471. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  1472. ),(
  1473. idtok:_FAR;
  1474. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1475. handler : @pd_far;
  1476. pocall : pocall_none;
  1477. pooption : [];
  1478. mutexclpocall : [pocall_internproc];
  1479. mutexclpotype : [];
  1480. mutexclpo : [po_inline]
  1481. ),(
  1482. idtok:_FAR16;
  1483. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1484. handler : nil;
  1485. pocall : pocall_far16;
  1486. pooption : [];
  1487. mutexclpocall : [];
  1488. mutexclpotype : [];
  1489. mutexclpo : [po_external]
  1490. ),(
  1491. idtok:_FORWARD;
  1492. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1493. handler : @pd_forward;
  1494. pocall : pocall_none;
  1495. pooption : [];
  1496. mutexclpocall : [pocall_internproc];
  1497. mutexclpotype : [];
  1498. mutexclpo : [po_external,po_inline]
  1499. ),(
  1500. idtok:_OLDFPCCALL;
  1501. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1502. handler : nil;
  1503. pocall : pocall_oldfpccall;
  1504. pooption : [];
  1505. mutexclpocall : [];
  1506. mutexclpotype : [];
  1507. mutexclpo : []
  1508. ),(
  1509. idtok:_INLINE;
  1510. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1511. handler : @pd_inline;
  1512. pocall : pocall_none;
  1513. pooption : [po_inline];
  1514. mutexclpocall : [];
  1515. mutexclpotype : [potype_constructor,potype_destructor];
  1516. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1517. ),(
  1518. idtok:_INTERNCONST;
  1519. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf];
  1520. handler : @pd_internconst;
  1521. pocall : pocall_none;
  1522. pooption : [po_internconst];
  1523. mutexclpocall : [];
  1524. mutexclpotype : [potype_operator];
  1525. mutexclpo : []
  1526. ),(
  1527. idtok:_INTERNPROC;
  1528. pd_flags : [pd_interface,pd_notobject,pd_notobjintf];
  1529. handler : @pd_internproc;
  1530. pocall : pocall_internproc;
  1531. pooption : [];
  1532. mutexclpocall : [];
  1533. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1534. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1535. ),(
  1536. idtok:_INTERRUPT;
  1537. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1538. handler : @pd_interrupt;
  1539. pocall : pocall_none;
  1540. pooption : [po_interrupt];
  1541. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1542. pocall_pascal,pocall_far16,pocall_oldfpccall];
  1543. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1544. mutexclpo : [po_external,po_inline]
  1545. ),(
  1546. idtok:_IOCHECK;
  1547. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1548. handler : nil;
  1549. pocall : pocall_none;
  1550. pooption : [po_iocheck];
  1551. mutexclpocall : [pocall_internproc];
  1552. mutexclpotype : [];
  1553. mutexclpo : [po_external]
  1554. ),(
  1555. idtok:_MESSAGE;
  1556. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1557. handler : @pd_message;
  1558. pocall : pocall_none;
  1559. pooption : []; { can be po_msgstr or po_msgint }
  1560. mutexclpocall : [pocall_internproc];
  1561. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1562. mutexclpo : [po_interrupt,po_external,po_inline]
  1563. ),(
  1564. idtok:_MWPASCAL;
  1565. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1566. handler : nil;
  1567. pocall : pocall_mwpascal;
  1568. pooption : [];
  1569. mutexclpocall : [];
  1570. mutexclpotype : [];
  1571. mutexclpo : []
  1572. ),(
  1573. idtok:_NEAR;
  1574. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1575. handler : @pd_near;
  1576. pocall : pocall_none;
  1577. pooption : [];
  1578. mutexclpocall : [pocall_internproc];
  1579. mutexclpotype : [];
  1580. mutexclpo : []
  1581. ),(
  1582. idtok:_NOSTACKFRAME;
  1583. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1584. handler : nil;
  1585. pocall : pocall_none;
  1586. pooption : [po_nostackframe];
  1587. mutexclpocall : [pocall_internproc];
  1588. mutexclpotype : [];
  1589. mutexclpo : []
  1590. ),(
  1591. idtok:_OVERLOAD;
  1592. pd_flags : [pd_implemen,pd_interface,pd_body];
  1593. handler : @pd_overload;
  1594. pocall : pocall_none;
  1595. pooption : [po_overload];
  1596. mutexclpocall : [pocall_internproc];
  1597. mutexclpotype : [];
  1598. mutexclpo : []
  1599. ),(
  1600. idtok:_OVERRIDE;
  1601. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1602. handler : @pd_override;
  1603. pocall : pocall_none;
  1604. pooption : [po_overridingmethod,po_virtualmethod];
  1605. mutexclpocall : [pocall_internproc];
  1606. mutexclpotype : [];
  1607. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_inline]
  1608. ),(
  1609. idtok:_PASCAL;
  1610. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1611. handler : nil;
  1612. pocall : pocall_pascal;
  1613. pooption : [];
  1614. mutexclpocall : [];
  1615. mutexclpotype : [potype_constructor,potype_destructor];
  1616. mutexclpo : [po_external]
  1617. ),(
  1618. idtok:_PUBLIC;
  1619. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1620. handler : @pd_public;
  1621. pocall : pocall_none;
  1622. pooption : [po_public,po_global];
  1623. mutexclpocall : [pocall_internproc];
  1624. mutexclpotype : [];
  1625. mutexclpo : [po_external,po_inline]
  1626. ),(
  1627. idtok:_REGISTER;
  1628. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1629. handler : nil;
  1630. pocall : pocall_register;
  1631. pooption : [];
  1632. mutexclpocall : [];
  1633. mutexclpotype : [potype_constructor,potype_destructor];
  1634. mutexclpo : [po_external]
  1635. ),(
  1636. idtok:_REINTRODUCE;
  1637. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1638. handler : @pd_reintroduce;
  1639. pocall : pocall_none;
  1640. pooption : [po_reintroduce];
  1641. mutexclpocall : [pocall_internproc];
  1642. mutexclpotype : [];
  1643. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1644. ),(
  1645. idtok:_SAFECALL;
  1646. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1647. handler : nil;
  1648. pocall : pocall_safecall;
  1649. pooption : [];
  1650. mutexclpocall : [];
  1651. mutexclpotype : [potype_constructor,potype_destructor];
  1652. mutexclpo : [po_external]
  1653. ),(
  1654. idtok:_SOFTFLOAT;
  1655. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1656. handler : nil;
  1657. pocall : pocall_softfloat;
  1658. pooption : [];
  1659. mutexclpocall : [];
  1660. mutexclpotype : [potype_constructor,potype_destructor];
  1661. { it's available with po_external because the libgcc floating point routines on the arm
  1662. uses this calling convention }
  1663. mutexclpo : []
  1664. ),(
  1665. idtok:_STATIC;
  1666. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1667. handler : @pd_static;
  1668. pocall : pocall_none;
  1669. pooption : [po_staticmethod];
  1670. mutexclpocall : [pocall_internproc];
  1671. mutexclpotype : [potype_constructor,potype_destructor];
  1672. mutexclpo : [po_external,po_interrupt,po_exports,po_inline]
  1673. ),(
  1674. idtok:_STDCALL;
  1675. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1676. handler : nil;
  1677. pocall : pocall_stdcall;
  1678. pooption : [];
  1679. mutexclpocall : [];
  1680. mutexclpotype : [potype_constructor,potype_destructor];
  1681. mutexclpo : [po_external]
  1682. ),(
  1683. idtok:_SYSCALL;
  1684. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  1685. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  1686. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  1687. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1688. handler : @pd_syscall;
  1689. pocall : pocall_syscall;
  1690. pooption : [];
  1691. mutexclpocall : [];
  1692. mutexclpotype : [potype_constructor,potype_destructor];
  1693. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1694. ),(
  1695. idtok:_VIRTUAL;
  1696. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1697. handler : @pd_virtual;
  1698. pocall : pocall_none;
  1699. pooption : [po_virtualmethod];
  1700. mutexclpocall : [pocall_internproc];
  1701. mutexclpotype : [];
  1702. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1703. ),(
  1704. idtok:_CPPDECL;
  1705. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1706. handler : nil;
  1707. pocall : pocall_cppdecl;
  1708. pooption : [];
  1709. mutexclpocall : [];
  1710. mutexclpotype : [potype_constructor,potype_destructor];
  1711. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1712. ),(
  1713. idtok:_VARARGS;
  1714. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1715. handler : nil;
  1716. pocall : pocall_none;
  1717. pooption : [po_varargs];
  1718. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1719. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  1720. mutexclpotype : [];
  1721. mutexclpo : [po_assembler,po_interrupt,po_inline]
  1722. ),(
  1723. idtok:_COMPILERPROC;
  1724. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1725. handler : nil;
  1726. pocall : pocall_none;
  1727. pooption : [po_compilerproc];
  1728. mutexclpocall : [];
  1729. mutexclpotype : [potype_constructor,potype_destructor];
  1730. mutexclpo : [po_interrupt]
  1731. )
  1732. );
  1733. function check_proc_directive(isprocvar:boolean):boolean;
  1734. var
  1735. i : longint;
  1736. begin
  1737. result:=false;
  1738. for i:=1 to num_proc_directives do
  1739. if proc_direcdata[i].idtok=idtoken then
  1740. begin
  1741. if ((not isprocvar) or
  1742. (pd_procvar in proc_direcdata[i].pd_flags)) and
  1743. { don't eat a public directive in classes }
  1744. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=objectsymtable)) then
  1745. result:=true;
  1746. exit;
  1747. end;
  1748. end;
  1749. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1750. {
  1751. Parse the procedure directive, returns true if a correct directive is found
  1752. }
  1753. var
  1754. p : longint;
  1755. found : boolean;
  1756. name : stringid;
  1757. begin
  1758. parse_proc_direc:=false;
  1759. name:=tokeninfo^[idtoken].str;
  1760. found:=false;
  1761. { Hint directive? Then exit immediatly }
  1762. if (m_hintdirective in aktmodeswitches) then
  1763. begin
  1764. case idtoken of
  1765. _LIBRARY,
  1766. _PLATFORM,
  1767. _UNIMPLEMENTED,
  1768. _DEPRECATED :
  1769. exit;
  1770. end;
  1771. end;
  1772. { C directive is MAC only, because it breaks too much existing code
  1773. on other platforms (PFV) }
  1774. if (idtoken=_C) and
  1775. not(m_mac in aktmodeswitches) then
  1776. exit;
  1777. { retrieve data for directive if found }
  1778. for p:=1 to num_proc_directives do
  1779. if proc_direcdata[p].idtok=idtoken then
  1780. begin
  1781. found:=true;
  1782. break;
  1783. end;
  1784. { Check if the procedure directive is known }
  1785. if not found then
  1786. begin
  1787. { parsing a procvar type the name can be any
  1788. next variable !! }
  1789. if ((pdflags * [pd_procvar,pd_object])=[]) and
  1790. not(idtoken=_PROPERTY) then
  1791. Message1(parser_w_unknown_proc_directive_ignored,name);
  1792. exit;
  1793. end;
  1794. { static needs a special treatment }
  1795. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1796. exit;
  1797. { check if method and directive not for object, like public.
  1798. This needs to be checked also for procvars }
  1799. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1800. (symtablestack.top.symtabletype=objectsymtable) then
  1801. exit;
  1802. { Conflicts between directives ? }
  1803. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1804. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1805. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1806. begin
  1807. Message1(parser_e_proc_dir_conflict,name);
  1808. exit;
  1809. end;
  1810. { set calling convention }
  1811. if proc_direcdata[p].pocall<>pocall_none then
  1812. begin
  1813. if (po_hascallingconvention in pd.procoptions) then
  1814. begin
  1815. Message2(parser_w_proc_overriding_calling,
  1816. proccalloptionStr[pd.proccalloption],
  1817. proccalloptionStr[proc_direcdata[p].pocall]);
  1818. end;
  1819. { check if the target processor supports this calling convention }
  1820. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1821. begin
  1822. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1823. { recover }
  1824. proc_direcdata[p].pocall:=pocall_stdcall;
  1825. end;
  1826. pd.proccalloption:=proc_direcdata[p].pocall;
  1827. include(pd.procoptions,po_hascallingconvention);
  1828. end;
  1829. if pd.deftype=procdef then
  1830. begin
  1831. { Check if the directive is only for objects }
  1832. if (pd_object in proc_direcdata[p].pd_flags) and
  1833. not assigned(tprocdef(pd)._class) then
  1834. exit;
  1835. { check if method and directive not for interface }
  1836. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1837. is_interface(tprocdef(pd)._class) then
  1838. exit;
  1839. end;
  1840. { consume directive, and turn flag on }
  1841. consume(token);
  1842. parse_proc_direc:=true;
  1843. { Check the pd_flags if the directive should be allowed }
  1844. if (pd_interface in pdflags) and
  1845. not(pd_interface in proc_direcdata[p].pd_flags) then
  1846. begin
  1847. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1848. exit;
  1849. end;
  1850. if (pd_implemen in pdflags) and
  1851. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1852. begin
  1853. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1854. exit;
  1855. end;
  1856. if (pd_procvar in pdflags) and
  1857. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1858. begin
  1859. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1860. exit;
  1861. end;
  1862. { Return the new pd_flags }
  1863. if not(pd_body in proc_direcdata[p].pd_flags) then
  1864. exclude(pdflags,pd_body);
  1865. { Add the correct flag }
  1866. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1867. { Call the handler }
  1868. if pointer(proc_direcdata[p].handler)<>nil then
  1869. proc_direcdata[p].handler(pd);
  1870. end;
  1871. function proc_get_importname(pd:tprocdef):string;
  1872. function maybe_cprefix(const s:string):string;
  1873. begin
  1874. if not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1875. result:=s
  1876. else
  1877. result:=target_info.Cprefix+s;
  1878. end;
  1879. begin
  1880. result:='';
  1881. if not(po_external in pd.procoptions) then
  1882. internalerror(200412151);
  1883. { import by number? }
  1884. if pd.import_nr<>0 then
  1885. begin
  1886. { Nothing to do }
  1887. end
  1888. else
  1889. { external name specified }
  1890. if assigned(pd.import_name) then
  1891. begin
  1892. if assigned(pd.import_dll) then
  1893. begin
  1894. { If we are not using direct dll linking under win32 then imports
  1895. need to use the normal name since to functions can refer to the
  1896. same DLL function. This is also needed for compatability
  1897. with Delphi and TP7 }
  1898. case target_info.system of
  1899. system_i386_win32 :
  1900. begin
  1901. { We need to use the name with a _ prefix if we let ld.exe do
  1902. the importing for us }
  1903. if not GenerateImportSection then
  1904. result:=target_info.Cprefix+pd.import_name^;
  1905. end;
  1906. system_i386_wdosx,
  1907. system_i386_emx,system_i386_os2,
  1908. system_arm_wince,system_i386_wince :
  1909. begin
  1910. { keep normal mangledname }
  1911. end;
  1912. else
  1913. result:=maybe_cprefix(pd.import_name^);
  1914. end;
  1915. end
  1916. else
  1917. result:=maybe_cprefix(pd.import_name^);
  1918. end
  1919. else
  1920. begin
  1921. { Default names when importing variables }
  1922. case pd.proccalloption of
  1923. pocall_cdecl :
  1924. begin
  1925. if assigned(pd._class) then
  1926. result:=target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname
  1927. else
  1928. result:=target_info.Cprefix+pd.procsym.realname;
  1929. end;
  1930. pocall_cppdecl :
  1931. begin
  1932. result:=target_info.Cprefix+pd.cplusplusmangledname;
  1933. end;
  1934. else
  1935. begin
  1936. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  1937. if (m_mac in aktmodeswitches) then
  1938. result:=tprocdef(pd).procsym.realname;
  1939. end;
  1940. end;
  1941. end;
  1942. end;
  1943. procedure proc_set_mangledname(pd:tprocdef);
  1944. var
  1945. s : string;
  1946. begin
  1947. { When the mangledname is already set we aren't allowed to change
  1948. it because it can already be used somewhere (PFV) }
  1949. if not(po_has_mangledname in pd.procoptions) then
  1950. begin
  1951. if (po_external in pd.procoptions) then
  1952. begin
  1953. { External Procedures are only allowed to change the mangledname
  1954. in their first declaration }
  1955. if (pd.forwarddef or (not pd.hasforward)) then
  1956. begin
  1957. s:=proc_get_importname(pd);
  1958. if s<>'' then
  1959. pd.setmangledname(s);
  1960. end;
  1961. end
  1962. else
  1963. { Normal procedures }
  1964. begin
  1965. if (po_compilerproc in pd.procoptions) then
  1966. begin
  1967. pd.setmangledname(lower(pd.procsym.name));
  1968. end;
  1969. end;
  1970. end;
  1971. { Public/exported alias names }
  1972. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  1973. not(po_has_public_name in pd.procoptions) then
  1974. begin
  1975. case pd.proccalloption of
  1976. pocall_cdecl :
  1977. begin
  1978. if assigned(pd._class) then
  1979. pd.aliasnames.insert(target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname)
  1980. else
  1981. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  1982. end;
  1983. pocall_cppdecl :
  1984. begin
  1985. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  1986. end;
  1987. end;
  1988. { prevent adding the alias a second time }
  1989. include(pd.procoptions,po_has_public_name);
  1990. end;
  1991. end;
  1992. procedure handle_calling_convention(pd:tabstractprocdef);
  1993. begin
  1994. { set the default calling convention if none provided }
  1995. if not(po_hascallingconvention in pd.procoptions) then
  1996. pd.proccalloption:=aktdefproccall
  1997. else
  1998. begin
  1999. if pd.proccalloption=pocall_none then
  2000. internalerror(200309081);
  2001. end;
  2002. { handle proccall specific settings }
  2003. case pd.proccalloption of
  2004. pocall_cdecl,
  2005. pocall_cppdecl :
  2006. begin
  2007. { check C cdecl para types }
  2008. pd.parast.foreach_static(@check_c_para,nil);
  2009. end;
  2010. pocall_far16 :
  2011. begin
  2012. { Temporary stub, must be rewritten to support OS/2 far16 }
  2013. Message1(parser_w_proc_directive_ignored,'FAR16');
  2014. end;
  2015. end;
  2016. if (po_inline in pd.procoptions) then
  2017. begin
  2018. if not(cs_support_inline in aktmoduleswitches) then
  2019. begin
  2020. Message(parser_e_proc_inline_not_supported);
  2021. exclude(pd.procoptions,po_inline);
  2022. end;
  2023. end;
  2024. { For varargs directive also cdecl and external must be defined }
  2025. if (po_varargs in pd.procoptions) then
  2026. begin
  2027. { check first for external in the interface, if available there
  2028. then the cdecl must also be there since there is no implementation
  2029. available to contain it }
  2030. if parse_only then
  2031. begin
  2032. { if external is available, then cdecl must also be available,
  2033. procvars don't need external }
  2034. if not((po_external in pd.procoptions) or
  2035. (pd.deftype=procvardef)) and
  2036. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2037. Message(parser_e_varargs_need_cdecl_and_external);
  2038. end
  2039. else
  2040. begin
  2041. { both must be defined now }
  2042. if not((po_external in pd.procoptions) or
  2043. (pd.deftype=procvardef)) or
  2044. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2045. Message(parser_e_varargs_need_cdecl_and_external);
  2046. end;
  2047. end;
  2048. { insert hidden high parameters }
  2049. pd.parast.foreach_static(@insert_hidden_para,pd);
  2050. { insert hidden self parameter }
  2051. insert_self_and_vmt_para(pd);
  2052. { insert funcret parameter if required }
  2053. insert_funcret_para(pd);
  2054. { Make var parameters regable, this must be done after the calling
  2055. convention is set. }
  2056. { this must be done before parentfp is insert, because getting all cases
  2057. where parentfp must be in a memory location isn't catched properly so
  2058. we put parentfp never in a register }
  2059. pd.parast.foreach_static(@set_addr_param_regable,pd);
  2060. { insert parentfp parameter if required }
  2061. insert_parentfp_para(pd);
  2062. { Calculate parameter tlist }
  2063. pd.calcparas;
  2064. end;
  2065. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2066. {
  2067. Parse the procedure directives. It does not matter if procedure directives
  2068. are written using ;procdir; or ['procdir'] syntax.
  2069. }
  2070. var
  2071. res : boolean;
  2072. begin
  2073. if (m_mac in aktmodeswitches) and (cs_externally_visible in aktlocalswitches) then
  2074. begin
  2075. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  2076. include(pd.procoptions,po_public);
  2077. include(pd.procoptions,po_has_public_name);
  2078. include(pd.procoptions,po_global);
  2079. end;
  2080. while token in [_ID,_LECKKLAMMER] do
  2081. begin
  2082. if try_to_consume(_LECKKLAMMER) then
  2083. begin
  2084. repeat
  2085. parse_proc_direc(pd,pdflags);
  2086. until not try_to_consume(_COMMA);
  2087. consume(_RECKKLAMMER);
  2088. { we always expect at least '[];' }
  2089. res:=true;
  2090. end
  2091. else
  2092. begin
  2093. res:=parse_proc_direc(pd,pdflags);
  2094. end;
  2095. { A procedure directive normally followed by a semicolon, but in
  2096. a const section or reading a type we should stop when _EQUAL is found,
  2097. because a constant/default value follows }
  2098. if res then
  2099. begin
  2100. if (block_type in [bt_const,bt_type]) and
  2101. (token=_EQUAL) then
  2102. break;
  2103. { support procedure proc;stdcall export; }
  2104. if not(check_proc_directive((pd.deftype=procvardef))) then
  2105. begin
  2106. { support "record p : procedure stdcall end;" and
  2107. "var p : procedure stdcall = nil;" }
  2108. if (pd_procvar in pdflags) and
  2109. (token in [_END,_RKLAMMER,_EQUAL]) then
  2110. break
  2111. else
  2112. consume(_SEMICOLON);
  2113. end;
  2114. end
  2115. else
  2116. break;
  2117. end;
  2118. end;
  2119. procedure parse_var_proc_directives(sym:tsym);
  2120. var
  2121. pdflags : tpdflags;
  2122. pd : tabstractprocdef;
  2123. begin
  2124. pdflags:=[pd_procvar];
  2125. pd:=nil;
  2126. case sym.typ of
  2127. fieldvarsym,
  2128. globalvarsym,
  2129. localvarsym,
  2130. paravarsym :
  2131. pd:=tabstractprocdef(tabstractvarsym(sym).vartype.def);
  2132. typedconstsym :
  2133. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  2134. typesym :
  2135. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  2136. else
  2137. internalerror(2003042617);
  2138. end;
  2139. if pd.deftype<>procvardef then
  2140. internalerror(2003042618);
  2141. { names should never be used anyway }
  2142. parse_proc_directives(pd,pdflags);
  2143. end;
  2144. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2145. var
  2146. pdflags : tpdflags;
  2147. begin
  2148. pdflags:=[pd_object];
  2149. parse_proc_directives(pd,pdflags);
  2150. end;
  2151. function proc_add_definition(var pd:tprocdef):boolean;
  2152. {
  2153. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2154. forwarddef is found and reused it returns true
  2155. }
  2156. var
  2157. hd : tprocdef;
  2158. ad,fd : tsym;
  2159. i : cardinal;
  2160. forwardfound : boolean;
  2161. po_comp : tprocoptions;
  2162. aprocsym : tprocsym;
  2163. begin
  2164. forwardfound:=false;
  2165. aprocsym:=tprocsym(pd.procsym);
  2166. { check overloaded functions if the same function already exists }
  2167. for i:=1 to aprocsym.procdef_count do
  2168. begin
  2169. hd:=aprocsym.procdef[i];
  2170. { Skip overloaded definitions that are declared in other
  2171. units }
  2172. if hd.procsym<>aprocsym then
  2173. continue;
  2174. { check the parameters, for delphi/tp it is possible to
  2175. leave the parameters away in the implementation (forwarddef=false).
  2176. But for an overload declared function this is not allowed }
  2177. if { check if empty implementation arguments match is allowed }
  2178. (
  2179. not(m_repeat_forward in aktmodeswitches) and
  2180. not(pd.forwarddef) and
  2181. (pd.maxparacount=0) and
  2182. not(po_overload in hd.procoptions)
  2183. ) or
  2184. { check arguments }
  2185. (
  2186. (compare_paras(pd.paras,hd.paras,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  2187. { for operators equal_paras is not enough !! }
  2188. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  2189. { be careful here, equal_defs doesn't take care of unique }
  2190. (hd.rettype.def=pd.rettype.def) or
  2191. (equal_defs(hd.rettype.def,pd.rettype.def) and
  2192. not(df_unique in hd.rettype.def.defoptions) and not(df_unique in pd.rettype.def.defoptions)
  2193. )
  2194. )
  2195. ) then
  2196. begin
  2197. { Check if we've found the forwarddef, if found then
  2198. we need to update the forward def with the current
  2199. implementation settings }
  2200. if hd.forwarddef then
  2201. begin
  2202. forwardfound:=true;
  2203. { Check if the procedure type and return type are correct,
  2204. also the parameters must match also with the type }
  2205. if (hd.proctypeoption<>pd.proctypeoption) or
  2206. (
  2207. (m_repeat_forward in aktmodeswitches) and
  2208. (not((pd.maxparacount=0) or
  2209. (compare_paras(pd.paras,hd.paras,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  2210. ) or
  2211. (
  2212. ((m_repeat_forward in aktmodeswitches) or
  2213. not(is_void(pd.rettype.def))) and
  2214. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  2215. begin
  2216. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2217. pd.fullprocname(false));
  2218. aprocsym.write_parameter_lists(pd);
  2219. break;
  2220. end;
  2221. { Check if both are declared forward }
  2222. if hd.forwarddef and pd.forwarddef then
  2223. begin
  2224. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  2225. pd.fullprocname(false));
  2226. end;
  2227. { internconst or internproc only need to be defined once }
  2228. if (hd.proccalloption=pocall_internproc) then
  2229. pd.proccalloption:=hd.proccalloption
  2230. else
  2231. if (pd.proccalloption=pocall_internproc) then
  2232. hd.proccalloption:=pd.proccalloption;
  2233. { Check calling convention }
  2234. if (hd.proccalloption<>pd.proccalloption) then
  2235. begin
  2236. { In delphi it is possible to specify the calling
  2237. convention in the interface or implementation if
  2238. there was no convention specified in the other
  2239. part }
  2240. if (m_delphi in aktmodeswitches) then
  2241. begin
  2242. if not(po_hascallingconvention in pd.procoptions) then
  2243. pd.proccalloption:=hd.proccalloption
  2244. else
  2245. if not(po_hascallingconvention in hd.procoptions) then
  2246. hd.proccalloption:=pd.proccalloption
  2247. else
  2248. begin
  2249. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2250. aprocsym.write_parameter_lists(pd);
  2251. { restore interface settings }
  2252. pd.proccalloption:=hd.proccalloption;
  2253. end;
  2254. end
  2255. else
  2256. begin
  2257. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2258. aprocsym.write_parameter_lists(pd);
  2259. { restore interface settings }
  2260. pd.proccalloption:=hd.proccalloption;
  2261. end;
  2262. end;
  2263. { Check procedure options, Delphi requires that class is
  2264. repeated in the implementation for class methods }
  2265. if (m_fpc in aktmodeswitches) then
  2266. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  2267. else
  2268. po_comp:=[po_classmethod,po_methodpointer];
  2269. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  2270. begin
  2271. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2272. pd.fullprocname(false));
  2273. aprocsym.write_parameter_lists(pd);
  2274. { This error is non-fatal, we can recover }
  2275. end;
  2276. { Forward declaration is external? }
  2277. if (po_external in hd.procoptions) then
  2278. MessagePos(pd.fileinfo,parser_e_proc_already_external);
  2279. { Check parameters }
  2280. if (m_repeat_forward in aktmodeswitches) or
  2281. (pd.minparacount>0) then
  2282. begin
  2283. { If mangled names are equal then they have the same amount of arguments }
  2284. { We can check the names of the arguments }
  2285. { both symtables are in the same order from left to right }
  2286. ad:=tsym(hd.parast.symindex.first);
  2287. fd:=tsym(pd.parast.symindex.first);
  2288. repeat
  2289. { skip default parameter constsyms }
  2290. while assigned(ad) and (ad.typ<>paravarsym) do
  2291. ad:=tsym(ad.indexnext);
  2292. while assigned(fd) and (fd.typ<>paravarsym) do
  2293. fd:=tsym(fd.indexnext);
  2294. { stop when one of the two lists is at the end }
  2295. if not assigned(ad) or not assigned(fd) then
  2296. break;
  2297. { compare names of parameters, ignore implictly
  2298. renamed parameters }
  2299. if not(sp_implicitrename in ad.symoptions) and
  2300. not(sp_implicitrename in fd.symoptions) then
  2301. begin
  2302. if (ad.name<>fd.name) then
  2303. begin
  2304. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  2305. aprocsym.realname,ad.realname,fd.realname);
  2306. break;
  2307. end;
  2308. end;
  2309. ad:=tsym(ad.indexnext);
  2310. fd:=tsym(fd.indexnext);
  2311. until false;
  2312. if assigned(ad) xor assigned(fd) then
  2313. internalerror(200204178);
  2314. end;
  2315. { Everything is checked, now we can update the forward declaration
  2316. with the new data from the implementation }
  2317. hd.forwarddef:=pd.forwarddef;
  2318. hd.hasforward:=true;
  2319. hd.procoptions:=hd.procoptions+pd.procoptions;
  2320. if hd.extnumber=65535 then
  2321. hd.extnumber:=pd.extnumber;
  2322. while not pd.aliasnames.empty do
  2323. hd.aliasnames.insert(pd.aliasnames.getfirst);
  2324. { update fileinfo so position references the implementation,
  2325. also update funcretsym if it is already generated }
  2326. hd.fileinfo:=pd.fileinfo;
  2327. if assigned(hd.funcretsym) then
  2328. hd.funcretsym.fileinfo:=pd.fileinfo;
  2329. { import names }
  2330. if assigned(pd.import_dll) then
  2331. begin
  2332. stringdispose(hd.import_dll);
  2333. hd.import_dll:=stringdup(pd.import_dll^);
  2334. end;
  2335. if assigned(pd.import_name) then
  2336. begin
  2337. stringdispose(hd.import_name);
  2338. hd.import_name:=stringdup(pd.import_name^);
  2339. end;
  2340. hd.import_nr:=pd.import_nr;
  2341. { for compilerproc defines we need to rename and update the
  2342. symbolname to lowercase }
  2343. if (po_compilerproc in pd.procoptions) then
  2344. begin
  2345. { rename to lowercase so users can't access it }
  2346. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  2347. { also update the realname that is stored in the ppu }
  2348. stringdispose(aprocsym._realname);
  2349. aprocsym._realname:=stringdup('$'+aprocsym.name);
  2350. { the mangeled name is already changed by the pd_compilerproc }
  2351. { handler. It must be done immediately because if we have a }
  2352. { call to a compilerproc before it's implementation is }
  2353. { encountered, it must already use the new mangled name (JM) }
  2354. end;
  2355. { the procdef will be released by the symtable, we release
  2356. at least the parast }
  2357. pd.releasemem;
  2358. pd:=hd;
  2359. end
  2360. else
  2361. begin
  2362. { abstract methods aren't forward defined, but this }
  2363. { needs another error message }
  2364. if (po_abstractmethod in hd.procoptions) then
  2365. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  2366. else
  2367. begin
  2368. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  2369. aprocsym.write_parameter_lists(pd);
  2370. end;
  2371. end;
  2372. { we found one proc with the same arguments, there are no others
  2373. so we can stop }
  2374. break;
  2375. end;
  2376. { check for allowing overload directive }
  2377. if not(m_fpc in aktmodeswitches) then
  2378. begin
  2379. { overload directive turns on overloading }
  2380. if ((po_overload in pd.procoptions) or
  2381. (po_overload in hd.procoptions)) then
  2382. begin
  2383. { check if all procs have overloading, but not if the proc is a method or
  2384. already declared forward, then the check is already done }
  2385. if not(hd.hasforward or
  2386. assigned(pd._class) or
  2387. (pd.forwarddef<>hd.forwarddef) or
  2388. ((po_overload in pd.procoptions) and
  2389. (po_overload in hd.procoptions))) then
  2390. begin
  2391. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2392. break;
  2393. end;
  2394. end
  2395. else
  2396. begin
  2397. if not(hd.forwarddef) then
  2398. begin
  2399. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2400. break;
  2401. end;
  2402. end;
  2403. end; { equal arguments }
  2404. end;
  2405. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2406. list }
  2407. if not forwardfound then
  2408. aprocsym.addprocdef(pd);
  2409. proc_add_definition:=forwardfound;
  2410. end;
  2411. end.