pdecsub.pas 87 KB

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