pdecsub.pas 96 KB

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