pdecsub.pas 143 KB

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