pdecsub.pas 142 KB

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