pdecsub.pas 112 KB

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