pdecsub.pas 118 KB

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