pdecsub.pas 109 KB

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