pdecsub.pas 112 KB

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