pdecsub.pas 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631
  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. begin
  825. locationstr:='';
  826. pd:=nil;
  827. isclassmethod:=false;
  828. { read class method }
  829. if try_to_consume(_CLASS) then
  830. begin
  831. { class method only allowed for procedures and functions }
  832. if not(token in [_FUNCTION,_PROCEDURE]) then
  833. Message(parser_e_procedure_or_function_expected);
  834. if is_interface(aclass) then
  835. Message(parser_e_no_static_method_in_interfaces)
  836. else
  837. isclassmethod:=true;
  838. end;
  839. case token of
  840. _FUNCTION :
  841. begin
  842. consume(_FUNCTION);
  843. if parse_proc_head(aclass,potype_function,pd) then
  844. begin
  845. { pd=nil when it is a interface mapping }
  846. if assigned(pd) then
  847. begin
  848. if try_to_consume(_COLON) then
  849. begin
  850. inc(testcurobject);
  851. single_type(pd.rettype,false);
  852. pd.test_if_fpu_result;
  853. dec(testcurobject);
  854. if (target_info.system in [system_m68k_amiga]) then
  855. begin
  856. if (idtoken=_LOCATION) then
  857. begin
  858. if po_explicitparaloc in pd.procoptions then
  859. begin
  860. consume(_LOCATION);
  861. locationstr:=pattern;
  862. consume(_CSTRING);
  863. end
  864. else
  865. { I guess this needs a new message... (KB) }
  866. Message(parser_e_paraloc_all_paras);
  867. end
  868. else
  869. begin
  870. if po_explicitparaloc in pd.procoptions then
  871. { assign default locationstr, if none specified }
  872. { and we've arguments with explicit paraloc }
  873. locationstr:='D0';
  874. end;
  875. end;
  876. end
  877. else
  878. begin
  879. if (
  880. parse_only and
  881. not(is_interface(pd._class))
  882. ) or
  883. (m_repeat_forward in aktmodeswitches) then
  884. begin
  885. consume(_COLON);
  886. consume_all_until(_SEMICOLON);
  887. end;
  888. end;
  889. if isclassmethod then
  890. include(pd.procoptions,po_classmethod);
  891. end;
  892. end
  893. else
  894. begin
  895. { recover }
  896. consume(_COLON);
  897. consume_all_until(_SEMICOLON);
  898. end;
  899. end;
  900. _PROCEDURE :
  901. begin
  902. consume(_PROCEDURE);
  903. if parse_proc_head(aclass,potype_procedure,pd) then
  904. begin
  905. { pd=nil when it is a interface mapping }
  906. if assigned(pd) then
  907. begin
  908. pd.rettype:=voidtype;
  909. if isclassmethod then
  910. include(pd.procoptions,po_classmethod);
  911. end;
  912. end;
  913. end;
  914. _CONSTRUCTOR :
  915. begin
  916. consume(_CONSTRUCTOR);
  917. parse_proc_head(aclass,potype_constructor,pd);
  918. if assigned(pd) and
  919. assigned(pd._class) then
  920. begin
  921. { Set return type, class constructors return the
  922. created instance, object constructors return boolean }
  923. if is_class(pd._class) then
  924. pd.rettype.setdef(pd._class)
  925. else
  926. pd.rettype:=booltype;
  927. end;
  928. end;
  929. _DESTRUCTOR :
  930. begin
  931. consume(_DESTRUCTOR);
  932. parse_proc_head(aclass,potype_destructor,pd);
  933. if assigned(pd) then
  934. pd.rettype:=voidtype;
  935. end;
  936. _OPERATOR :
  937. begin
  938. consume(_OPERATOR);
  939. if (token in [first_overloaded..last_overloaded]) then
  940. begin
  941. optoken:=token;
  942. end
  943. else
  944. begin
  945. Message(parser_e_overload_operator_failed);
  946. { Use the dummy NOTOKEN that is also declared
  947. for the overloaded_operator[] }
  948. optoken:=NOTOKEN;
  949. end;
  950. consume(token);
  951. parse_proc_head(aclass,potype_operator,pd);
  952. if assigned(pd) then
  953. begin
  954. if pd.parast.symtablelevel>normal_function_level then
  955. Message(parser_e_no_local_operator);
  956. if token<>_ID then
  957. begin
  958. if not(m_result in aktmodeswitches) then
  959. consume(_ID);
  960. end
  961. else
  962. begin
  963. pd.resultname:=orgpattern;
  964. consume(_ID);
  965. end;
  966. if not try_to_consume(_COLON) then
  967. begin
  968. consume(_COLON);
  969. pd.rettype:=generrortype;
  970. consume_all_until(_SEMICOLON);
  971. end
  972. else
  973. begin
  974. single_type(pd.rettype,false);
  975. pd.test_if_fpu_result;
  976. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  977. ((pd.rettype.def.deftype<>orddef) or
  978. (torddef(pd.rettype.def).typ<>bool8bit)) then
  979. Message(parser_e_comparative_operator_return_boolean);
  980. if (optoken=_ASSIGNMENT) and
  981. equal_defs(pd.rettype.def,
  982. tparavarsym(pd.parast.symindex.first).vartype.def) then
  983. message(parser_e_no_such_assignment)
  984. else if not isoperatoracceptable(pd,optoken) then
  985. Message(parser_e_overload_impossible);
  986. end;
  987. end
  988. else
  989. begin
  990. { recover }
  991. try_to_consume(_ID);
  992. consume(_COLON);
  993. consume_all_until(_SEMICOLON);
  994. end;
  995. end;
  996. end;
  997. { support procedure proc stdcall export; }
  998. if not(check_proc_directive(false)) then
  999. consume(_SEMICOLON);
  1000. result:=pd;
  1001. if locationstr<>'' then
  1002. begin
  1003. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1004. { I guess this needs a new message... (KB) }
  1005. message(parser_e_illegal_explicit_paraloc);
  1006. end;
  1007. end;
  1008. {****************************************************************************
  1009. Procedure directive handlers
  1010. ****************************************************************************}
  1011. procedure pd_far(pd:tabstractprocdef);
  1012. begin
  1013. Message1(parser_w_proc_directive_ignored,'FAR');
  1014. end;
  1015. procedure pd_near(pd:tabstractprocdef);
  1016. begin
  1017. Message1(parser_w_proc_directive_ignored,'NEAR');
  1018. end;
  1019. procedure pd_export(pd:tabstractprocdef);
  1020. begin
  1021. if pd.deftype<>procdef then
  1022. internalerror(200304264);
  1023. if assigned(tprocdef(pd)._class) then
  1024. Message(parser_e_methods_dont_be_export);
  1025. if pd.parast.symtablelevel>normal_function_level then
  1026. Message(parser_e_dont_nest_export);
  1027. end;
  1028. procedure pd_forward(pd:tabstractprocdef);
  1029. begin
  1030. if pd.deftype<>procdef then
  1031. internalerror(200304265);
  1032. tprocdef(pd).forwarddef:=true;
  1033. end;
  1034. procedure pd_alias(pd:tabstractprocdef);
  1035. begin
  1036. if pd.deftype<>procdef then
  1037. internalerror(200304266);
  1038. consume(_COLON);
  1039. tprocdef(pd).aliasnames.insert(get_stringconst);
  1040. include(pd.procoptions,po_has_public_name);
  1041. end;
  1042. procedure pd_public(pd:tabstractprocdef);
  1043. begin
  1044. if pd.deftype<>procdef then
  1045. internalerror(200304266);
  1046. if try_to_consume(_NAME) then
  1047. begin
  1048. tprocdef(pd).aliasnames.insert(get_stringconst);
  1049. include(pd.procoptions,po_has_public_name);
  1050. end;
  1051. end;
  1052. procedure pd_asmname(pd:tabstractprocdef);
  1053. begin
  1054. if pd.deftype<>procdef then
  1055. internalerror(200304267);
  1056. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1057. if token=_CCHAR then
  1058. consume(_CCHAR)
  1059. else
  1060. consume(_CSTRING);
  1061. { we don't need anything else }
  1062. tprocdef(pd).forwarddef:=false;
  1063. end;
  1064. procedure pd_inline(pd:tabstractprocdef);
  1065. begin
  1066. { Check if there are parameters that can't be inlined }
  1067. pd.parast.foreach_static(@check_inline_para,pd);
  1068. end;
  1069. procedure pd_internconst(pd:tabstractprocdef);
  1070. begin
  1071. if pd.deftype<>procdef then
  1072. internalerror(200304268);
  1073. consume(_COLON);
  1074. tprocdef(pd).extnumber:=longint(get_intconst);
  1075. end;
  1076. procedure pd_internproc(pd:tabstractprocdef);
  1077. begin
  1078. if pd.deftype<>procdef then
  1079. internalerror(200304268);
  1080. consume(_COLON);
  1081. tprocdef(pd).extnumber:=longint(get_intconst);
  1082. { the proc is defined }
  1083. tprocdef(pd).forwarddef:=false;
  1084. end;
  1085. procedure pd_interrupt(pd:tabstractprocdef);
  1086. begin
  1087. if pd.parast.symtablelevel>normal_function_level then
  1088. Message(parser_e_dont_nest_interrupt);
  1089. end;
  1090. procedure pd_abstract(pd:tabstractprocdef);
  1091. begin
  1092. if pd.deftype<>procdef then
  1093. internalerror(200304269);
  1094. if (po_virtualmethod in pd.procoptions) then
  1095. include(pd.procoptions,po_abstractmethod)
  1096. else
  1097. Message(parser_e_only_virtual_methods_abstract);
  1098. { the method is defined }
  1099. tprocdef(pd).forwarddef:=false;
  1100. end;
  1101. procedure pd_virtual(pd:tabstractprocdef);
  1102. {$ifdef WITHDMT}
  1103. var
  1104. pt : tnode;
  1105. {$endif WITHDMT}
  1106. begin
  1107. if pd.deftype<>procdef then
  1108. internalerror(2003042610);
  1109. if (pd.proctypeoption=potype_constructor) and
  1110. is_object(tprocdef(pd)._class) then
  1111. Message(parser_e_constructor_cannot_be_not_virtual);
  1112. {$ifdef WITHDMT}
  1113. if is_object(tprocdef(pd)._class) and
  1114. (token<>_SEMICOLON) then
  1115. begin
  1116. { any type of parameter is allowed here! }
  1117. pt:=comp_expr(true);
  1118. if is_constintnode(pt) then
  1119. begin
  1120. include(pd.procoptions,po_msgint);
  1121. pd.messageinf.i:=pt.value;
  1122. end
  1123. else
  1124. Message(parser_e_ill_msg_expr);
  1125. disposetree(pt);
  1126. end;
  1127. {$endif WITHDMT}
  1128. end;
  1129. procedure pd_dispid(pd:tabstractprocdef);
  1130. var
  1131. pt : tnode;
  1132. begin
  1133. if pd.deftype<>procdef then
  1134. internalerror(200604301);
  1135. pt:=comp_expr(true);
  1136. if is_constintnode(pt) then
  1137. tprocdef(pd).extnumber:=tordconstnode(pt).value
  1138. else
  1139. Message(parser_e_dispid_must_be_ord_const);
  1140. pt.free;
  1141. end;
  1142. procedure pd_static(pd:tabstractprocdef);
  1143. begin
  1144. if (cs_static_keyword in aktmoduleswitches) then
  1145. begin
  1146. if pd.deftype=procdef then
  1147. include(tprocdef(pd).procsym.symoptions,sp_static);
  1148. include(pd.procoptions,po_staticmethod);
  1149. end;
  1150. end;
  1151. procedure pd_override(pd:tabstractprocdef);
  1152. begin
  1153. if pd.deftype<>procdef then
  1154. internalerror(2003042611);
  1155. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1156. Message(parser_e_no_object_override);
  1157. end;
  1158. procedure pd_overload(pd:tabstractprocdef);
  1159. begin
  1160. if pd.deftype<>procdef then
  1161. internalerror(2003042612);
  1162. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1163. end;
  1164. procedure pd_message(pd:tabstractprocdef);
  1165. var
  1166. pt : tnode;
  1167. paracnt : longint;
  1168. begin
  1169. if pd.deftype<>procdef then
  1170. internalerror(2003042613);
  1171. if not is_class(tprocdef(pd)._class) then
  1172. Message(parser_e_msg_only_for_classes);
  1173. { check parameter type }
  1174. paracnt:=0;
  1175. pd.parast.foreach_static(@check_msg_para,@paracnt);
  1176. if paracnt<>1 then
  1177. Message(parser_e_ill_msg_param);
  1178. pt:=comp_expr(true);
  1179. if pt.nodetype=stringconstn then
  1180. begin
  1181. include(pd.procoptions,po_msgstr);
  1182. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1183. end
  1184. else
  1185. if is_constintnode(pt) then
  1186. begin
  1187. include(pd.procoptions,po_msgint);
  1188. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1189. end
  1190. else
  1191. Message(parser_e_ill_msg_expr);
  1192. pt.free;
  1193. end;
  1194. procedure pd_reintroduce(pd:tabstractprocdef);
  1195. begin
  1196. if pd.deftype<>procdef then
  1197. internalerror(200401211);
  1198. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1199. Message(parser_e_no_object_reintroduce);
  1200. end;
  1201. procedure pd_syscall(pd:tabstractprocdef);
  1202. {$if defined(powerpc) or defined(m68k)}
  1203. var
  1204. vs : tparavarsym;
  1205. sym : tsym;
  1206. symtable : tsymtable;
  1207. {$endif defined(powerpc) or defined(m68k)}
  1208. begin
  1209. if (pd.deftype<>procdef) and (target_info.system <> system_powerpc_amiga) then
  1210. internalerror(2003042614);
  1211. tprocdef(pd).forwarddef:=false;
  1212. {$ifdef m68k}
  1213. if target_info.system in [system_m68k_amiga] then
  1214. begin
  1215. include(pd.procoptions,po_syscall_legacy);
  1216. if consume_sym(sym,symtable) then
  1217. begin
  1218. if (sym.typ=globalvarsym) and
  1219. (
  1220. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1221. is_32bitint(tabstractvarsym(sym).vartype.def)
  1222. ) then
  1223. begin
  1224. tprocdef(pd).libsym:=sym;
  1225. if po_syscall_legacy in tprocdef(pd).procoptions then
  1226. begin
  1227. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1228. paramanager.parseparaloc(vs,'A6');
  1229. pd.parast.insert(vs);
  1230. end
  1231. end
  1232. else
  1233. Message(parser_e_32bitint_or_pointer_variable_expected);
  1234. end;
  1235. (paramanager as tm68kparamanager).create_funcretloc_info(pd,calleeside);
  1236. (paramanager as tm68kparamanager).create_funcretloc_info(pd,callerside);
  1237. tprocdef(pd).extnumber:=get_intconst;
  1238. end;
  1239. {$endif m68k}
  1240. {$ifdef powerpc}
  1241. if target_info.system = system_powerpc_amiga then
  1242. begin
  1243. include(pd.procoptions,po_syscall_sysv);
  1244. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1245. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1246. end else
  1247. if target_info.system = system_powerpc_morphos then
  1248. begin
  1249. if idtoken=_LEGACY then
  1250. begin
  1251. consume(_LEGACY);
  1252. include(pd.procoptions,po_syscall_legacy);
  1253. end
  1254. else if idtoken=_SYSV then
  1255. begin
  1256. consume(_SYSV);
  1257. include(pd.procoptions,po_syscall_sysv);
  1258. end
  1259. else if idtoken=_BASESYSV then
  1260. begin
  1261. consume(_BASESYSV);
  1262. include(pd.procoptions,po_syscall_basesysv);
  1263. end
  1264. else if idtoken=_SYSVBASE then
  1265. begin
  1266. consume(_SYSVBASE);
  1267. include(pd.procoptions,po_syscall_sysvbase);
  1268. end
  1269. else if idtoken=_R12BASE then
  1270. begin
  1271. consume(_R12BASE);
  1272. include(pd.procoptions,po_syscall_r12base);
  1273. end
  1274. else
  1275. if syscall_convention='LEGACY' then
  1276. include(pd.procoptions,po_syscall_legacy)
  1277. else if syscall_convention='SYSV' then
  1278. include(pd.procoptions,po_syscall_sysv)
  1279. else if syscall_convention='BASESYSV' then
  1280. include(pd.procoptions,po_syscall_basesysv)
  1281. else if syscall_convention='SYSVBASE' then
  1282. include(pd.procoptions,po_syscall_sysvbase)
  1283. else if syscall_convention='R12BASE' then
  1284. include(pd.procoptions,po_syscall_r12base)
  1285. else
  1286. internalerror(2005010404);
  1287. if consume_sym(sym,symtable) then
  1288. begin
  1289. if (sym.typ=globalvarsym) and
  1290. (
  1291. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1292. is_32bitint(tabstractvarsym(sym).vartype.def)
  1293. ) then
  1294. begin
  1295. tprocdef(pd).libsym:=sym;
  1296. if po_syscall_legacy in tprocdef(pd).procoptions then
  1297. begin
  1298. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1299. paramanager.parseparaloc(vs,'A6');
  1300. pd.parast.insert(vs);
  1301. end
  1302. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1303. begin
  1304. { Nothing to be done for sysv here for now, but this might change }
  1305. end
  1306. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1307. begin
  1308. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1309. pd.parast.insert(vs);
  1310. end
  1311. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1312. begin
  1313. vs:=tparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1314. pd.parast.insert(vs);
  1315. end
  1316. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1317. begin
  1318. vs:=tparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1319. paramanager.parseparaloc(vs,'R12');
  1320. pd.parast.insert(vs);
  1321. end
  1322. else
  1323. internalerror(2005010501);
  1324. end
  1325. else
  1326. Message(parser_e_32bitint_or_pointer_variable_expected);
  1327. end;
  1328. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1329. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1330. tprocdef(pd).extnumber:=get_intconst;
  1331. end;
  1332. {$endif powerpc}
  1333. end;
  1334. procedure pd_external(pd:tabstractprocdef);
  1335. {
  1336. If import_dll=nil the procedure is assumed to be in another
  1337. object file. In that object file it should have the name to
  1338. which import_name is pointing to. Otherwise, the procedure is
  1339. assumed to be in the DLL to which import_dll is pointing to. In
  1340. that case either import_nr<>0 or import_name<>nil is true, so
  1341. the procedure is either imported by number or by name. (DM)
  1342. }
  1343. var
  1344. hs : string;
  1345. begin
  1346. if pd.deftype<>procdef then
  1347. internalerror(2003042615);
  1348. with tprocdef(pd) do
  1349. begin
  1350. forwarddef:=false;
  1351. { forbid local external procedures }
  1352. if parast.symtablelevel>normal_function_level then
  1353. Message(parser_e_no_local_proc_external);
  1354. { If the procedure should be imported from a DLL, a constant string follows.
  1355. This isn't really correct, an contant string expression follows
  1356. so we check if an semicolon follows, else a string constant have to
  1357. follow (FK) }
  1358. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1359. begin
  1360. { Always add library prefix and suffix to create an uniform name }
  1361. hs:=AddExtension(get_stringconst,target_info.sharedlibext);
  1362. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  1363. hs:=target_info.sharedlibprefix+hs;
  1364. import_dll:=stringdup(hs);
  1365. include(procoptions,po_has_importdll);
  1366. if (idtoken=_NAME) then
  1367. begin
  1368. consume(_NAME);
  1369. import_name:=stringdup(get_stringconst);
  1370. include(procoptions,po_has_importname);
  1371. if import_name^='' then
  1372. message(parser_e_empty_import_name);
  1373. end;
  1374. if (idtoken=_INDEX) then
  1375. begin
  1376. {After the word index follows the index number in the DLL.}
  1377. consume(_INDEX);
  1378. import_nr:=longint(get_intconst);
  1379. end;
  1380. { default is to used the realname of the procedure }
  1381. if (import_nr=0) and not assigned(import_name) then
  1382. begin
  1383. import_name:=stringdup(procsym.realname);
  1384. include(procoptions,po_has_importname);
  1385. end;
  1386. end
  1387. else
  1388. begin
  1389. if (idtoken=_NAME) then
  1390. begin
  1391. consume(_NAME);
  1392. import_name:=stringdup(get_stringconst);
  1393. include(procoptions,po_has_importname);
  1394. if import_name^='' then
  1395. message(parser_e_empty_import_name);
  1396. end;
  1397. end;
  1398. end;
  1399. end;
  1400. type
  1401. pd_handler=procedure(pd:tabstractprocdef);
  1402. proc_dir_rec=record
  1403. idtok : ttoken;
  1404. pd_flags : tpdflags;
  1405. handler : pd_handler;
  1406. pocall : tproccalloption;
  1407. pooption : tprocoptions;
  1408. mutexclpocall : tproccalloptions;
  1409. mutexclpotype : tproctypeoptions;
  1410. mutexclpo : tprocoptions;
  1411. end;
  1412. const
  1413. {Should contain the number of procedure directives we support.}
  1414. num_proc_directives=38;
  1415. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1416. (
  1417. (
  1418. idtok:_ABSTRACT;
  1419. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1420. handler : @pd_abstract;
  1421. pocall : pocall_none;
  1422. pooption : [po_abstractmethod];
  1423. mutexclpocall : [pocall_internproc];
  1424. mutexclpotype : [];
  1425. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  1426. ),(
  1427. idtok:_ALIAS;
  1428. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1429. handler : @pd_alias;
  1430. pocall : pocall_none;
  1431. pooption : [];
  1432. mutexclpocall : [];
  1433. mutexclpotype : [];
  1434. mutexclpo : [po_external,po_inline]
  1435. ),(
  1436. idtok:_ASMNAME;
  1437. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1438. handler : @pd_asmname;
  1439. pocall : pocall_cdecl;
  1440. pooption : [po_external];
  1441. mutexclpocall : [pocall_internproc];
  1442. mutexclpotype : [];
  1443. mutexclpo : [po_external,po_inline]
  1444. ),(
  1445. idtok:_ASSEMBLER;
  1446. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1447. handler : nil;
  1448. pocall : pocall_none;
  1449. pooption : [po_assembler];
  1450. mutexclpocall : [];
  1451. mutexclpotype : [];
  1452. mutexclpo : [po_external]
  1453. ),(
  1454. idtok:_C; {same as cdecl for mode mac}
  1455. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1456. handler : nil;
  1457. pocall : pocall_cdecl;
  1458. pooption : [];
  1459. mutexclpocall : [];
  1460. mutexclpotype : [potype_constructor,potype_destructor];
  1461. mutexclpo : [po_assembler,po_external]
  1462. ),(
  1463. idtok:_CDECL;
  1464. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1465. handler : nil;
  1466. pocall : pocall_cdecl;
  1467. pooption : [];
  1468. mutexclpocall : [];
  1469. mutexclpotype : [potype_constructor,potype_destructor];
  1470. mutexclpo : [po_assembler,po_external]
  1471. ),(
  1472. idtok:_DISPID;
  1473. pd_flags : [pd_dispinterface];
  1474. handler : @pd_dispid;
  1475. pocall : pocall_none;
  1476. pooption : [];
  1477. mutexclpocall : [pocall_internproc];
  1478. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1479. mutexclpo : [po_interrupt,po_external,po_inline]
  1480. ),(
  1481. idtok:_DYNAMIC;
  1482. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1483. handler : @pd_virtual;
  1484. pocall : pocall_none;
  1485. pooption : [po_virtualmethod];
  1486. mutexclpocall : [pocall_internproc];
  1487. mutexclpotype : [];
  1488. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  1489. ),(
  1490. idtok:_EXPORT;
  1491. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1492. handler : @pd_export;
  1493. pocall : pocall_none;
  1494. pooption : [po_exports,po_global];
  1495. mutexclpocall : [pocall_internproc];
  1496. mutexclpotype : [potype_constructor,potype_destructor];
  1497. mutexclpo : [po_external,po_interrupt,po_inline]
  1498. ),(
  1499. idtok:_EXTERNAL;
  1500. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1501. handler : @pd_external;
  1502. pocall : pocall_none;
  1503. pooption : [po_external];
  1504. mutexclpocall : [pocall_internproc,pocall_syscall];
  1505. mutexclpotype : [potype_constructor,potype_destructor];
  1506. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  1507. ),(
  1508. idtok:_FAR;
  1509. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1510. handler : @pd_far;
  1511. pocall : pocall_none;
  1512. pooption : [];
  1513. mutexclpocall : [pocall_internproc];
  1514. mutexclpotype : [];
  1515. mutexclpo : [po_inline]
  1516. ),(
  1517. idtok:_FAR16;
  1518. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1519. handler : nil;
  1520. pocall : pocall_far16;
  1521. pooption : [];
  1522. mutexclpocall : [];
  1523. mutexclpotype : [];
  1524. mutexclpo : [po_external]
  1525. ),(
  1526. idtok:_FORWARD;
  1527. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1528. handler : @pd_forward;
  1529. pocall : pocall_none;
  1530. pooption : [];
  1531. mutexclpocall : [pocall_internproc];
  1532. mutexclpotype : [];
  1533. mutexclpo : [po_external,po_inline]
  1534. ),(
  1535. idtok:_OLDFPCCALL;
  1536. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1537. handler : nil;
  1538. pocall : pocall_oldfpccall;
  1539. pooption : [];
  1540. mutexclpocall : [];
  1541. mutexclpotype : [];
  1542. mutexclpo : []
  1543. ),(
  1544. idtok:_INLINE;
  1545. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1546. handler : @pd_inline;
  1547. pocall : pocall_none;
  1548. pooption : [po_inline];
  1549. mutexclpocall : [];
  1550. mutexclpotype : [potype_constructor,potype_destructor];
  1551. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1552. ),(
  1553. idtok:_INTERNCONST;
  1554. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf];
  1555. handler : @pd_internconst;
  1556. pocall : pocall_none;
  1557. pooption : [po_internconst];
  1558. mutexclpocall : [];
  1559. mutexclpotype : [potype_operator];
  1560. mutexclpo : []
  1561. ),(
  1562. idtok:_INTERNPROC;
  1563. pd_flags : [pd_interface,pd_notobject,pd_notobjintf];
  1564. handler : @pd_internproc;
  1565. pocall : pocall_internproc;
  1566. pooption : [];
  1567. mutexclpocall : [];
  1568. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1569. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1570. ),(
  1571. idtok:_INTERRUPT;
  1572. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1573. handler : @pd_interrupt;
  1574. pocall : pocall_none;
  1575. pooption : [po_interrupt];
  1576. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1577. pocall_pascal,pocall_far16,pocall_oldfpccall];
  1578. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1579. mutexclpo : [po_external,po_inline]
  1580. ),(
  1581. idtok:_IOCHECK;
  1582. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1583. handler : nil;
  1584. pocall : pocall_none;
  1585. pooption : [po_iocheck];
  1586. mutexclpocall : [pocall_internproc];
  1587. mutexclpotype : [];
  1588. mutexclpo : [po_external]
  1589. ),(
  1590. idtok:_MESSAGE;
  1591. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1592. handler : @pd_message;
  1593. pocall : pocall_none;
  1594. pooption : []; { can be po_msgstr or po_msgint }
  1595. mutexclpocall : [pocall_internproc];
  1596. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1597. mutexclpo : [po_interrupt,po_external,po_inline]
  1598. ),(
  1599. idtok:_MWPASCAL;
  1600. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1601. handler : nil;
  1602. pocall : pocall_mwpascal;
  1603. pooption : [];
  1604. mutexclpocall : [];
  1605. mutexclpotype : [];
  1606. mutexclpo : []
  1607. ),(
  1608. idtok:_NEAR;
  1609. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1610. handler : @pd_near;
  1611. pocall : pocall_none;
  1612. pooption : [];
  1613. mutexclpocall : [pocall_internproc];
  1614. mutexclpotype : [];
  1615. mutexclpo : []
  1616. ),(
  1617. idtok:_NOSTACKFRAME;
  1618. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1619. handler : nil;
  1620. pocall : pocall_none;
  1621. pooption : [po_nostackframe];
  1622. mutexclpocall : [pocall_internproc];
  1623. mutexclpotype : [];
  1624. mutexclpo : []
  1625. ),(
  1626. idtok:_OVERLOAD;
  1627. pd_flags : [pd_implemen,pd_interface,pd_body];
  1628. handler : @pd_overload;
  1629. pocall : pocall_none;
  1630. pooption : [po_overload];
  1631. mutexclpocall : [pocall_internproc];
  1632. mutexclpotype : [];
  1633. mutexclpo : []
  1634. ),(
  1635. idtok:_OVERRIDE;
  1636. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1637. handler : @pd_override;
  1638. pocall : pocall_none;
  1639. pooption : [po_overridingmethod,po_virtualmethod];
  1640. mutexclpocall : [pocall_internproc];
  1641. mutexclpotype : [];
  1642. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_inline]
  1643. ),(
  1644. idtok:_PASCAL;
  1645. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1646. handler : nil;
  1647. pocall : pocall_pascal;
  1648. pooption : [];
  1649. mutexclpocall : [];
  1650. mutexclpotype : [potype_constructor,potype_destructor];
  1651. mutexclpo : [po_external]
  1652. ),(
  1653. idtok:_PUBLIC;
  1654. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1655. handler : @pd_public;
  1656. pocall : pocall_none;
  1657. pooption : [po_public,po_global];
  1658. mutexclpocall : [pocall_internproc];
  1659. mutexclpotype : [];
  1660. mutexclpo : [po_external,po_inline]
  1661. ),(
  1662. idtok:_REGISTER;
  1663. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1664. handler : nil;
  1665. pocall : pocall_register;
  1666. pooption : [];
  1667. mutexclpocall : [];
  1668. mutexclpotype : [potype_constructor,potype_destructor];
  1669. mutexclpo : [po_external]
  1670. ),(
  1671. idtok:_REINTRODUCE;
  1672. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1673. handler : @pd_reintroduce;
  1674. pocall : pocall_none;
  1675. pooption : [po_reintroduce];
  1676. mutexclpocall : [pocall_internproc];
  1677. mutexclpotype : [];
  1678. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1679. ),(
  1680. idtok:_SAFECALL;
  1681. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1682. handler : nil;
  1683. pocall : pocall_safecall;
  1684. pooption : [];
  1685. mutexclpocall : [];
  1686. mutexclpotype : [potype_constructor,potype_destructor];
  1687. mutexclpo : [po_external]
  1688. ),(
  1689. idtok:_SOFTFLOAT;
  1690. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1691. handler : nil;
  1692. pocall : pocall_softfloat;
  1693. pooption : [];
  1694. mutexclpocall : [];
  1695. mutexclpotype : [potype_constructor,potype_destructor];
  1696. { it's available with po_external because the libgcc floating point routines on the arm
  1697. uses this calling convention }
  1698. mutexclpo : []
  1699. ),(
  1700. idtok:_STATIC;
  1701. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1702. handler : @pd_static;
  1703. pocall : pocall_none;
  1704. pooption : [po_staticmethod];
  1705. mutexclpocall : [pocall_internproc];
  1706. mutexclpotype : [potype_constructor,potype_destructor];
  1707. mutexclpo : [po_external,po_interrupt,po_exports,po_inline]
  1708. ),(
  1709. idtok:_STDCALL;
  1710. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1711. handler : nil;
  1712. pocall : pocall_stdcall;
  1713. pooption : [];
  1714. mutexclpocall : [];
  1715. mutexclpotype : [potype_constructor,potype_destructor];
  1716. mutexclpo : [po_external]
  1717. ),(
  1718. idtok:_SYSCALL;
  1719. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  1720. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  1721. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  1722. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1723. handler : @pd_syscall;
  1724. pocall : pocall_syscall;
  1725. pooption : [];
  1726. mutexclpocall : [];
  1727. mutexclpotype : [potype_constructor,potype_destructor];
  1728. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1729. ),(
  1730. idtok:_VIRTUAL;
  1731. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1732. handler : @pd_virtual;
  1733. pocall : pocall_none;
  1734. pooption : [po_virtualmethod];
  1735. mutexclpocall : [pocall_internproc];
  1736. mutexclpotype : [];
  1737. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1738. ),(
  1739. idtok:_CPPDECL;
  1740. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1741. handler : nil;
  1742. pocall : pocall_cppdecl;
  1743. pooption : [];
  1744. mutexclpocall : [];
  1745. mutexclpotype : [potype_constructor,potype_destructor];
  1746. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1747. ),(
  1748. idtok:_VARARGS;
  1749. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1750. handler : nil;
  1751. pocall : pocall_none;
  1752. pooption : [po_varargs];
  1753. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1754. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  1755. mutexclpotype : [];
  1756. mutexclpo : [po_assembler,po_interrupt,po_inline]
  1757. ),(
  1758. idtok:_COMPILERPROC;
  1759. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1760. handler : nil;
  1761. pocall : pocall_none;
  1762. pooption : [po_compilerproc];
  1763. mutexclpocall : [];
  1764. mutexclpotype : [potype_constructor,potype_destructor];
  1765. mutexclpo : [po_interrupt]
  1766. )
  1767. );
  1768. function check_proc_directive(isprocvar:boolean):boolean;
  1769. var
  1770. i : longint;
  1771. begin
  1772. result:=false;
  1773. for i:=1 to num_proc_directives do
  1774. if proc_direcdata[i].idtok=idtoken then
  1775. begin
  1776. if ((not isprocvar) or
  1777. (pd_procvar in proc_direcdata[i].pd_flags)) and
  1778. { don't eat a public directive in classes }
  1779. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=objectsymtable)) then
  1780. result:=true;
  1781. exit;
  1782. end;
  1783. end;
  1784. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1785. {
  1786. Parse the procedure directive, returns true if a correct directive is found
  1787. }
  1788. var
  1789. p : longint;
  1790. found : boolean;
  1791. name : stringid;
  1792. begin
  1793. parse_proc_direc:=false;
  1794. name:=tokeninfo^[idtoken].str;
  1795. found:=false;
  1796. { Hint directive? Then exit immediatly }
  1797. if (m_hintdirective in aktmodeswitches) then
  1798. begin
  1799. case idtoken of
  1800. _LIBRARY,
  1801. _PLATFORM,
  1802. _UNIMPLEMENTED,
  1803. _DEPRECATED :
  1804. exit;
  1805. end;
  1806. end;
  1807. { C directive is MAC only, because it breaks too much existing code
  1808. on other platforms (PFV) }
  1809. if (idtoken=_C) and
  1810. not(m_mac in aktmodeswitches) then
  1811. exit;
  1812. { retrieve data for directive if found }
  1813. for p:=1 to num_proc_directives do
  1814. if proc_direcdata[p].idtok=idtoken then
  1815. begin
  1816. found:=true;
  1817. break;
  1818. end;
  1819. { Check if the procedure directive is known }
  1820. if not found then
  1821. begin
  1822. { parsing a procvar type the name can be any
  1823. next variable !! }
  1824. if ((pdflags * [pd_procvar,pd_object])=[]) and
  1825. not(idtoken=_PROPERTY) then
  1826. Message1(parser_w_unknown_proc_directive_ignored,name);
  1827. exit;
  1828. end;
  1829. { static needs a special treatment }
  1830. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1831. exit;
  1832. { check if method and directive not for object, like public.
  1833. This needs to be checked also for procvars }
  1834. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1835. (symtablestack.top.symtabletype=objectsymtable) then
  1836. exit;
  1837. { Conflicts between directives ? }
  1838. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1839. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1840. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1841. begin
  1842. Message1(parser_e_proc_dir_conflict,name);
  1843. exit;
  1844. end;
  1845. { set calling convention }
  1846. if proc_direcdata[p].pocall<>pocall_none then
  1847. begin
  1848. if (po_hascallingconvention in pd.procoptions) then
  1849. begin
  1850. Message2(parser_w_proc_overriding_calling,
  1851. proccalloptionStr[pd.proccalloption],
  1852. proccalloptionStr[proc_direcdata[p].pocall]);
  1853. end;
  1854. { check if the target processor supports this calling convention }
  1855. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1856. begin
  1857. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1858. { recover }
  1859. proc_direcdata[p].pocall:=pocall_stdcall;
  1860. end;
  1861. pd.proccalloption:=proc_direcdata[p].pocall;
  1862. include(pd.procoptions,po_hascallingconvention);
  1863. end;
  1864. if pd.deftype=procdef then
  1865. begin
  1866. { Check if the directive is only for objects }
  1867. if (pd_object in proc_direcdata[p].pd_flags) and
  1868. not assigned(tprocdef(pd)._class) then
  1869. exit;
  1870. { check if method and directive not for interface }
  1871. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1872. is_interface(tprocdef(pd)._class) then
  1873. exit;
  1874. { check if method and directive not for interface }
  1875. if is_dispinterface(tprocdef(pd)._class) and
  1876. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  1877. exit;
  1878. end;
  1879. { consume directive, and turn flag on }
  1880. consume(token);
  1881. parse_proc_direc:=true;
  1882. { Check the pd_flags if the directive should be allowed }
  1883. if (pd_interface in pdflags) and
  1884. not(pd_interface in proc_direcdata[p].pd_flags) then
  1885. begin
  1886. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1887. exit;
  1888. end;
  1889. if (pd_implemen in pdflags) and
  1890. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1891. begin
  1892. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1893. exit;
  1894. end;
  1895. if (pd_procvar in pdflags) and
  1896. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1897. begin
  1898. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1899. exit;
  1900. end;
  1901. { Return the new pd_flags }
  1902. if not(pd_body in proc_direcdata[p].pd_flags) then
  1903. exclude(pdflags,pd_body);
  1904. { Add the correct flag }
  1905. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1906. { Call the handler }
  1907. if pointer(proc_direcdata[p].handler)<>nil then
  1908. proc_direcdata[p].handler(pd);
  1909. end;
  1910. function proc_get_importname(pd:tprocdef):string;
  1911. function maybe_cprefix(const s:string):string;
  1912. begin
  1913. if not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1914. result:=s
  1915. else
  1916. result:=target_info.Cprefix+s;
  1917. end;
  1918. begin
  1919. result:='';
  1920. if not(po_external in pd.procoptions) then
  1921. internalerror(200412151);
  1922. { import by number? }
  1923. if pd.import_nr<>0 then
  1924. begin
  1925. { Nothing to do }
  1926. end
  1927. else
  1928. { external name specified }
  1929. if assigned(pd.import_name) then
  1930. begin
  1931. if assigned(pd.import_dll) then
  1932. begin
  1933. { If we are not using direct dll linking under win32 then imports
  1934. need to use the normal name since to functions can refer to the
  1935. same DLL function. This is also needed for compatability
  1936. with Delphi and TP7 }
  1937. case target_info.system of
  1938. system_i386_wdosx,
  1939. system_i386_emx,system_i386_os2,
  1940. system_arm_wince,system_i386_wince :
  1941. begin
  1942. { keep normal mangledname }
  1943. end;
  1944. else
  1945. result:=maybe_cprefix(pd.import_name^);
  1946. end;
  1947. end
  1948. else
  1949. result:=maybe_cprefix(pd.import_name^);
  1950. end
  1951. else
  1952. begin
  1953. { Default names when importing variables }
  1954. case pd.proccalloption of
  1955. pocall_cdecl :
  1956. begin
  1957. if assigned(pd._class) then
  1958. result:=target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname
  1959. else
  1960. result:=target_info.Cprefix+pd.procsym.realname;
  1961. end;
  1962. pocall_cppdecl :
  1963. begin
  1964. result:=target_info.Cprefix+pd.cplusplusmangledname;
  1965. end;
  1966. else
  1967. begin
  1968. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  1969. if (m_mac in aktmodeswitches) then
  1970. result:=tprocdef(pd).procsym.realname;
  1971. end;
  1972. end;
  1973. end;
  1974. end;
  1975. procedure proc_set_mangledname(pd:tprocdef);
  1976. var
  1977. s : string;
  1978. begin
  1979. { When the mangledname is already set we aren't allowed to change
  1980. it because it can already be used somewhere (PFV) }
  1981. if not(po_has_mangledname in pd.procoptions) then
  1982. begin
  1983. if (po_external in pd.procoptions) then
  1984. begin
  1985. { External Procedures are only allowed to change the mangledname
  1986. in their first declaration }
  1987. if (pd.forwarddef or (not pd.hasforward)) then
  1988. begin
  1989. s:=proc_get_importname(pd);
  1990. if s<>'' then
  1991. pd.setmangledname(s);
  1992. end;
  1993. end
  1994. else
  1995. { Normal procedures }
  1996. begin
  1997. if (po_compilerproc in pd.procoptions) then
  1998. begin
  1999. pd.setmangledname(lower(pd.procsym.name));
  2000. end;
  2001. end;
  2002. end;
  2003. { Public/exported alias names }
  2004. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  2005. not(po_has_public_name in pd.procoptions) then
  2006. begin
  2007. case pd.proccalloption of
  2008. pocall_cdecl :
  2009. begin
  2010. if assigned(pd._class) then
  2011. pd.aliasnames.insert(target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname)
  2012. else
  2013. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  2014. end;
  2015. pocall_cppdecl :
  2016. begin
  2017. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  2018. end;
  2019. end;
  2020. { prevent adding the alias a second time }
  2021. include(pd.procoptions,po_has_public_name);
  2022. end;
  2023. end;
  2024. procedure handle_calling_convention(pd:tabstractprocdef);
  2025. begin
  2026. { set the default calling convention if none provided }
  2027. if not(po_hascallingconvention in pd.procoptions) then
  2028. pd.proccalloption:=aktdefproccall
  2029. else
  2030. begin
  2031. if pd.proccalloption=pocall_none then
  2032. internalerror(200309081);
  2033. end;
  2034. { handle proccall specific settings }
  2035. case pd.proccalloption of
  2036. pocall_cdecl,
  2037. pocall_cppdecl :
  2038. begin
  2039. { check C cdecl para types }
  2040. pd.parast.foreach_static(@check_c_para,nil);
  2041. end;
  2042. pocall_far16 :
  2043. begin
  2044. { Temporary stub, must be rewritten to support OS/2 far16 }
  2045. Message1(parser_w_proc_directive_ignored,'FAR16');
  2046. end;
  2047. end;
  2048. if (po_inline in pd.procoptions) then
  2049. begin
  2050. if not(cs_support_inline in aktmoduleswitches) then
  2051. begin
  2052. Message(parser_e_proc_inline_not_supported);
  2053. exclude(pd.procoptions,po_inline);
  2054. end;
  2055. end;
  2056. { For varargs directive also cdecl and external must be defined }
  2057. if (po_varargs in pd.procoptions) then
  2058. begin
  2059. { check first for external in the interface, if available there
  2060. then the cdecl must also be there since there is no implementation
  2061. available to contain it }
  2062. if parse_only then
  2063. begin
  2064. { if external is available, then cdecl must also be available,
  2065. procvars don't need external }
  2066. if not((po_external in pd.procoptions) or
  2067. (pd.deftype=procvardef)) and
  2068. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2069. Message(parser_e_varargs_need_cdecl_and_external);
  2070. end
  2071. else
  2072. begin
  2073. { both must be defined now }
  2074. if not((po_external in pd.procoptions) or
  2075. (pd.deftype=procvardef)) or
  2076. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2077. Message(parser_e_varargs_need_cdecl_and_external);
  2078. end;
  2079. end;
  2080. { insert hidden high parameters }
  2081. pd.parast.foreach_static(@insert_hidden_para,pd);
  2082. { insert hidden self parameter }
  2083. insert_self_and_vmt_para(pd);
  2084. { insert funcret parameter if required }
  2085. insert_funcret_para(pd);
  2086. { Make var parameters regable, this must be done after the calling
  2087. convention is set. }
  2088. { this must be done before parentfp is insert, because getting all cases
  2089. where parentfp must be in a memory location isn't catched properly so
  2090. we put parentfp never in a register }
  2091. pd.parast.foreach_static(@set_addr_param_regable,pd);
  2092. { insert parentfp parameter if required }
  2093. insert_parentfp_para(pd);
  2094. { Calculate parameter tlist }
  2095. pd.calcparas;
  2096. end;
  2097. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2098. {
  2099. Parse the procedure directives. It does not matter if procedure directives
  2100. are written using ;procdir; or ['procdir'] syntax.
  2101. }
  2102. var
  2103. res : boolean;
  2104. begin
  2105. if (m_mac in aktmodeswitches) and (cs_externally_visible in aktlocalswitches) then
  2106. begin
  2107. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  2108. include(pd.procoptions,po_public);
  2109. include(pd.procoptions,po_has_public_name);
  2110. include(pd.procoptions,po_global);
  2111. end;
  2112. while token in [_ID,_LECKKLAMMER] do
  2113. begin
  2114. if try_to_consume(_LECKKLAMMER) then
  2115. begin
  2116. repeat
  2117. parse_proc_direc(pd,pdflags);
  2118. until not try_to_consume(_COMMA);
  2119. consume(_RECKKLAMMER);
  2120. { we always expect at least '[];' }
  2121. res:=true;
  2122. end
  2123. else
  2124. begin
  2125. res:=parse_proc_direc(pd,pdflags);
  2126. end;
  2127. { A procedure directive normally followed by a semicolon, but in
  2128. a const section or reading a type we should stop when _EQUAL is found,
  2129. because a constant/default value follows }
  2130. if res then
  2131. begin
  2132. if (block_type in [bt_const,bt_type]) and
  2133. (token=_EQUAL) then
  2134. break;
  2135. { support procedure proc;stdcall export; }
  2136. if not(check_proc_directive((pd.deftype=procvardef))) then
  2137. begin
  2138. { support "record p : procedure stdcall end;" and
  2139. "var p : procedure stdcall = nil;" }
  2140. if (pd_procvar in pdflags) and
  2141. (token in [_END,_RKLAMMER,_EQUAL]) then
  2142. break
  2143. else
  2144. consume(_SEMICOLON);
  2145. end;
  2146. end
  2147. else
  2148. break;
  2149. end;
  2150. end;
  2151. procedure parse_var_proc_directives(sym:tsym);
  2152. var
  2153. pdflags : tpdflags;
  2154. pd : tabstractprocdef;
  2155. begin
  2156. pdflags:=[pd_procvar];
  2157. pd:=nil;
  2158. case sym.typ of
  2159. fieldvarsym,
  2160. globalvarsym,
  2161. localvarsym,
  2162. paravarsym :
  2163. pd:=tabstractprocdef(tabstractvarsym(sym).vartype.def);
  2164. typedconstsym :
  2165. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  2166. typesym :
  2167. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  2168. else
  2169. internalerror(2003042617);
  2170. end;
  2171. if pd.deftype<>procvardef then
  2172. internalerror(2003042618);
  2173. { names should never be used anyway }
  2174. parse_proc_directives(pd,pdflags);
  2175. end;
  2176. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2177. var
  2178. pdflags : tpdflags;
  2179. begin
  2180. pdflags:=[pd_object];
  2181. parse_proc_directives(pd,pdflags);
  2182. end;
  2183. function proc_add_definition(var pd:tprocdef):boolean;
  2184. {
  2185. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2186. forwarddef is found and reused it returns true
  2187. }
  2188. var
  2189. hd : tprocdef;
  2190. ad,fd : tsym;
  2191. i : cardinal;
  2192. forwardfound : boolean;
  2193. po_comp : tprocoptions;
  2194. aprocsym : tprocsym;
  2195. begin
  2196. forwardfound:=false;
  2197. aprocsym:=tprocsym(pd.procsym);
  2198. { check overloaded functions if the same function already exists }
  2199. for i:=1 to aprocsym.procdef_count do
  2200. begin
  2201. hd:=aprocsym.procdef[i];
  2202. { Skip overloaded definitions that are declared in other
  2203. units }
  2204. if hd.procsym<>aprocsym then
  2205. continue;
  2206. { check the parameters, for delphi/tp it is possible to
  2207. leave the parameters away in the implementation (forwarddef=false).
  2208. But for an overload declared function this is not allowed }
  2209. if { check if empty implementation arguments match is allowed }
  2210. (
  2211. not(m_repeat_forward in aktmodeswitches) and
  2212. not(pd.forwarddef) and
  2213. (pd.maxparacount=0) and
  2214. not(po_overload in hd.procoptions)
  2215. ) or
  2216. { check arguments }
  2217. (
  2218. (compare_paras(pd.paras,hd.paras,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  2219. { for operators equal_paras is not enough !! }
  2220. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  2221. { be careful here, equal_defs doesn't take care of unique }
  2222. (hd.rettype.def=pd.rettype.def) or
  2223. (equal_defs(hd.rettype.def,pd.rettype.def) and
  2224. not(df_unique in hd.rettype.def.defoptions) and not(df_unique in pd.rettype.def.defoptions)
  2225. )
  2226. )
  2227. ) then
  2228. begin
  2229. { Check if we've found the forwarddef, if found then
  2230. we need to update the forward def with the current
  2231. implementation settings }
  2232. if hd.forwarddef then
  2233. begin
  2234. forwardfound:=true;
  2235. { Check if the procedure type and return type are correct,
  2236. also the parameters must match also with the type }
  2237. if (hd.proctypeoption<>pd.proctypeoption) or
  2238. (
  2239. (m_repeat_forward in aktmodeswitches) and
  2240. (not((pd.maxparacount=0) or
  2241. (compare_paras(pd.paras,hd.paras,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  2242. ) or
  2243. (
  2244. ((m_repeat_forward in aktmodeswitches) or
  2245. not(is_void(pd.rettype.def))) and
  2246. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  2247. begin
  2248. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2249. pd.fullprocname(false));
  2250. aprocsym.write_parameter_lists(pd);
  2251. break;
  2252. end;
  2253. { Check if both are declared forward }
  2254. if hd.forwarddef and pd.forwarddef then
  2255. begin
  2256. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  2257. pd.fullprocname(false));
  2258. end;
  2259. { internconst or internproc only need to be defined once }
  2260. if (hd.proccalloption=pocall_internproc) then
  2261. pd.proccalloption:=hd.proccalloption
  2262. else
  2263. if (pd.proccalloption=pocall_internproc) then
  2264. hd.proccalloption:=pd.proccalloption;
  2265. { Check calling convention }
  2266. if (hd.proccalloption<>pd.proccalloption) then
  2267. begin
  2268. { In delphi it is possible to specify the calling
  2269. convention in the interface or implementation if
  2270. there was no convention specified in the other
  2271. part }
  2272. if (m_delphi in aktmodeswitches) then
  2273. begin
  2274. if not(po_hascallingconvention in pd.procoptions) then
  2275. pd.proccalloption:=hd.proccalloption
  2276. else
  2277. if not(po_hascallingconvention in hd.procoptions) then
  2278. hd.proccalloption:=pd.proccalloption
  2279. else
  2280. begin
  2281. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2282. aprocsym.write_parameter_lists(pd);
  2283. { restore interface settings }
  2284. pd.proccalloption:=hd.proccalloption;
  2285. end;
  2286. end
  2287. else
  2288. begin
  2289. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2290. aprocsym.write_parameter_lists(pd);
  2291. { restore interface settings }
  2292. pd.proccalloption:=hd.proccalloption;
  2293. end;
  2294. end;
  2295. { Check procedure options, Delphi requires that class is
  2296. repeated in the implementation for class methods }
  2297. if (m_fpc in aktmodeswitches) then
  2298. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  2299. else
  2300. po_comp:=[po_classmethod,po_methodpointer];
  2301. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  2302. begin
  2303. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2304. pd.fullprocname(false));
  2305. aprocsym.write_parameter_lists(pd);
  2306. { This error is non-fatal, we can recover }
  2307. end;
  2308. { Forward declaration is external? }
  2309. if (po_external in hd.procoptions) then
  2310. MessagePos(pd.fileinfo,parser_e_proc_already_external);
  2311. { Check parameters }
  2312. if (m_repeat_forward in aktmodeswitches) or
  2313. (pd.minparacount>0) then
  2314. begin
  2315. { If mangled names are equal then they have the same amount of arguments }
  2316. { We can check the names of the arguments }
  2317. { both symtables are in the same order from left to right }
  2318. ad:=tsym(hd.parast.symindex.first);
  2319. fd:=tsym(pd.parast.symindex.first);
  2320. repeat
  2321. { skip default parameter constsyms }
  2322. while assigned(ad) and (ad.typ<>paravarsym) do
  2323. ad:=tsym(ad.indexnext);
  2324. while assigned(fd) and (fd.typ<>paravarsym) do
  2325. fd:=tsym(fd.indexnext);
  2326. { stop when one of the two lists is at the end }
  2327. if not assigned(ad) or not assigned(fd) then
  2328. break;
  2329. { compare names of parameters, ignore implictly
  2330. renamed parameters }
  2331. if not(sp_implicitrename in ad.symoptions) and
  2332. not(sp_implicitrename in fd.symoptions) then
  2333. begin
  2334. if (ad.name<>fd.name) then
  2335. begin
  2336. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  2337. aprocsym.realname,ad.realname,fd.realname);
  2338. break;
  2339. end;
  2340. end;
  2341. ad:=tsym(ad.indexnext);
  2342. fd:=tsym(fd.indexnext);
  2343. until false;
  2344. if assigned(ad) xor assigned(fd) then
  2345. internalerror(200204178);
  2346. end;
  2347. { Everything is checked, now we can update the forward declaration
  2348. with the new data from the implementation }
  2349. hd.forwarddef:=pd.forwarddef;
  2350. hd.hasforward:=true;
  2351. hd.procoptions:=hd.procoptions+pd.procoptions;
  2352. if hd.extnumber=65535 then
  2353. hd.extnumber:=pd.extnumber;
  2354. while not pd.aliasnames.empty do
  2355. hd.aliasnames.insert(pd.aliasnames.getfirst);
  2356. { update fileinfo so position references the implementation,
  2357. also update funcretsym if it is already generated }
  2358. hd.fileinfo:=pd.fileinfo;
  2359. if assigned(hd.funcretsym) then
  2360. hd.funcretsym.fileinfo:=pd.fileinfo;
  2361. { import names }
  2362. if assigned(pd.import_dll) then
  2363. begin
  2364. stringdispose(hd.import_dll);
  2365. hd.import_dll:=stringdup(pd.import_dll^);
  2366. end;
  2367. if assigned(pd.import_name) then
  2368. begin
  2369. stringdispose(hd.import_name);
  2370. hd.import_name:=stringdup(pd.import_name^);
  2371. end;
  2372. hd.import_nr:=pd.import_nr;
  2373. { for compilerproc defines we need to rename and update the
  2374. symbolname to lowercase }
  2375. if (po_compilerproc in pd.procoptions) then
  2376. begin
  2377. { rename to lowercase so users can't access it }
  2378. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  2379. { also update the realname that is stored in the ppu }
  2380. stringdispose(aprocsym._realname);
  2381. aprocsym._realname:=stringdup('$'+aprocsym.name);
  2382. { the mangeled name is already changed by the pd_compilerproc }
  2383. { handler. It must be done immediately because if we have a }
  2384. { call to a compilerproc before it's implementation is }
  2385. { encountered, it must already use the new mangled name (JM) }
  2386. end;
  2387. { the procdef will be released by the symtable, we release
  2388. at least the parast }
  2389. pd.releasemem;
  2390. pd:=hd;
  2391. end
  2392. else
  2393. begin
  2394. { abstract methods aren't forward defined, but this }
  2395. { needs another error message }
  2396. if (po_abstractmethod in hd.procoptions) then
  2397. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  2398. else
  2399. begin
  2400. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  2401. aprocsym.write_parameter_lists(pd);
  2402. end;
  2403. end;
  2404. { we found one proc with the same arguments, there are no others
  2405. so we can stop }
  2406. break;
  2407. end;
  2408. { check for allowing overload directive }
  2409. if not(m_fpc in aktmodeswitches) then
  2410. begin
  2411. { overload directive turns on overloading }
  2412. if ((po_overload in pd.procoptions) or
  2413. (po_overload in hd.procoptions)) then
  2414. begin
  2415. { check if all procs have overloading, but not if the proc is a method or
  2416. already declared forward, then the check is already done }
  2417. if not(hd.hasforward or
  2418. assigned(pd._class) or
  2419. (pd.forwarddef<>hd.forwarddef) or
  2420. ((po_overload in pd.procoptions) and
  2421. (po_overload in hd.procoptions))) then
  2422. begin
  2423. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2424. break;
  2425. end;
  2426. end
  2427. else
  2428. begin
  2429. if not(hd.forwarddef) then
  2430. begin
  2431. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2432. break;
  2433. end;
  2434. end;
  2435. end; { equal arguments }
  2436. end;
  2437. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2438. list }
  2439. if not forwardfound then
  2440. aprocsym.addprocdef(pd);
  2441. proc_add_definition:=forwardfound;
  2442. end;
  2443. end.