pdecsub.pas 114 KB

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