pdecsub.pas 95 KB

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