pdecsub.pas 96 KB

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