pdecsub.pas 92 KB

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