pdecsub.pas 143 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756
  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,ptrsinttype);
  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. Message(parser_e_interface_id_expected)
  822. else
  823. { in case of a generic or specialized interface we need to use the
  824. name of the def instead of the symbol, so that always the correct
  825. name is used }
  826. if [df_generic,df_specialization]*ttypesym(srsym).typedef.defoptions<>[] then
  827. sp:=tobjectdef(ttypesym(srsym).typedef).objname^;
  828. { must be a directly implemented interface }
  829. if Assigned(ImplIntf.ImplementsGetter) then
  830. Message2(parser_e_implements_no_mapping,ImplIntf.IntfDef.typename,astruct.objrealname^);
  831. consume(_ID);
  832. { Create unique name <interface>.<method> }
  833. hs:=sp+'.'+pattern;
  834. consume(_EQ);
  835. if assigned(ImplIntf) and
  836. (token=_ID) then
  837. ImplIntf.AddMapping(hs,pattern);
  838. consume(_ID);
  839. result:=true;
  840. exit;
  841. end;
  842. { method ? }
  843. srsym:=nil;
  844. if not assigned(astruct) and
  845. (symtablestack.top.symtablelevel=main_program_level) and
  846. try_to_consume(_POINT) then
  847. begin
  848. repeat
  849. classstartfilepos:=procstartfilepos;
  850. searchagain:=false;
  851. { throw the error at the right location }
  852. oldfilepos:=current_filepos;
  853. current_filepos:=procstartfilepos;
  854. if not assigned(astruct) and not assigned(srsym) then
  855. srsym:=search_object_name(sp,true);
  856. current_filepos:=oldfilepos;
  857. { consume proc name }
  858. procstartfilepos:=current_tokenpos;
  859. consume_proc_name;
  860. { qualifier is class name ? }
  861. if (srsym.typ=typesym) and
  862. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) then
  863. begin
  864. astruct:=tabstractrecorddef(ttypesym(srsym).typedef);
  865. if (token<>_POINT) then
  866. if (potype in [potype_class_constructor,potype_class_destructor]) then
  867. sp:=lower(sp)
  868. else
  869. if (potype=potype_operator) and (optoken=NOTOKEN) then
  870. parse_operator_name;
  871. srsym:=tsym(astruct.symtable.Find(sp));
  872. if assigned(srsym) then
  873. begin
  874. if srsym.typ=procsym then
  875. aprocsym:=tprocsym(srsym)
  876. else
  877. if (srsym.typ=typesym) and
  878. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) then
  879. begin
  880. searchagain:=true;
  881. consume(_POINT);
  882. end
  883. else
  884. begin
  885. { we use a different error message for tp7 so it looks more compatible }
  886. if (m_fpc in current_settings.modeswitches) then
  887. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  888. else
  889. Message(parser_e_methode_id_expected);
  890. { rename the name to an unique name to avoid an
  891. error when inserting the symbol in the symtable }
  892. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  893. end;
  894. end
  895. else
  896. begin
  897. MessagePos(procstartfilepos,parser_e_methode_id_expected);
  898. { recover by making it a normal procedure instead of method }
  899. astruct:=nil;
  900. end;
  901. end
  902. else
  903. MessagePos(classstartfilepos,parser_e_class_id_expected);
  904. until not searchagain;
  905. end
  906. else
  907. begin
  908. { check for constructor/destructor/class operators which are not allowed here }
  909. if (not parse_only) and
  910. ((potype in [potype_constructor,potype_destructor,
  911. potype_class_constructor,potype_class_destructor]) or
  912. ((potype=potype_operator) and (m_delphi in current_settings.modeswitches))) then
  913. Message(parser_e_only_methods_allowed);
  914. repeat
  915. { only 1 class constructor and destructor is allowed in the class and
  916. the check was already done with oo_has_class_constructor or
  917. oo_has_class_destructor -> skip searching
  918. (bug #28801) }
  919. if (potype in [potype_class_constructor,potype_class_destructor]) then
  920. break;
  921. searchagain:=false;
  922. current_tokenpos:=procstartfilepos;
  923. if (potype=potype_operator)and(optoken=NOTOKEN) then
  924. parse_operator_name;
  925. srsym:=tsym(symtablestack.top.Find(sp));
  926. { Also look in the globalsymtable if we didn't found
  927. the symbol in the localsymtable }
  928. if not assigned(srsym) and
  929. not(parse_only) and
  930. (symtablestack.top=current_module.localsymtable) and
  931. assigned(current_module.globalsymtable) then
  932. srsym:=tsym(current_module.globalsymtable.Find(sp));
  933. { Check if overloaded is a procsym }
  934. if assigned(srsym) then
  935. begin
  936. if srsym.typ=procsym then
  937. aprocsym:=tprocsym(srsym)
  938. else
  939. begin
  940. { when the other symbol is a unit symbol then hide the unit
  941. symbol, this is not supported in tp7 }
  942. if not(m_tp7 in current_settings.modeswitches) and
  943. (srsym.typ=unitsym) then
  944. begin
  945. HideSym(srsym);
  946. searchagain:=true;
  947. end
  948. else
  949. if (m_delphi in current_settings.modeswitches) and
  950. (srsym.typ=absolutevarsym) and
  951. ([vo_is_funcret,vo_is_result]*tabstractvarsym(srsym).varoptions=[vo_is_funcret]) then
  952. begin
  953. HideSym(srsym);
  954. searchagain:=true;
  955. end
  956. else
  957. begin
  958. { we use a different error message for tp7 so it looks more compatible }
  959. if (m_fpc in current_settings.modeswitches) then
  960. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  961. else
  962. Message1(sym_e_duplicate_id,srsym.realname);
  963. { rename the name to an unique name to avoid an
  964. error when inserting the symbol in the symtable }
  965. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  966. end;
  967. end;
  968. end;
  969. until not searchagain;
  970. end;
  971. { test again if assigned, it can be reset to recover }
  972. if not assigned(aprocsym) then
  973. begin
  974. { create a new procsym and set the real filepos }
  975. current_tokenpos:=procstartfilepos;
  976. { for operator we have only one procsym for each overloaded
  977. operation }
  978. if (potype=potype_operator) then
  979. begin
  980. aprocsym:=Tprocsym(symtablestack.top.Find(sp));
  981. if aprocsym=nil then
  982. aprocsym:=cprocsym.create('$'+sp);
  983. end
  984. else
  985. if (potype in [potype_class_constructor,potype_class_destructor]) then
  986. aprocsym:=cprocsym.create('$'+lower(sp))
  987. else
  988. aprocsym:=cprocsym.create(orgsp);
  989. symtablestack.top.insert(aprocsym);
  990. end;
  991. end;
  992. { to get the correct symtablelevel we must ignore ObjectSymtables }
  993. st:=nil;
  994. checkstack:=symtablestack.stack;
  995. while assigned(checkstack) do
  996. begin
  997. st:=checkstack^.symtable;
  998. if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
  999. break;
  1000. checkstack:=checkstack^.next;
  1001. end;
  1002. pd:=cprocdef.create(st.symtablelevel+1,not assigned(genericdef));
  1003. pd.struct:=astruct;
  1004. pd.procsym:=aprocsym;
  1005. pd.proctypeoption:=potype;
  1006. if assigned(genericparams) then
  1007. begin
  1008. include(pd.defoptions,df_generic);
  1009. { push the parameter symtable so that constraint definitions are added
  1010. there and not in the owner symtable }
  1011. symtablestack.push(pd.parast);
  1012. { register the parameters }
  1013. for i:=0 to genericparams.count-1 do
  1014. begin
  1015. ttypesym(genericparams[i]).register_sym;
  1016. tstoreddef(ttypesym(genericparams[i]).typedef).register_def;
  1017. end;
  1018. insert_generic_parameter_types(pd,nil,genericparams);
  1019. symtablestack.pop(pd.parast);
  1020. freegenericparams:=false;
  1021. parse_generic:=true;
  1022. { also generate a dummy symbol if none exists already }
  1023. if assigned(astruct) then
  1024. dummysym:=tsym(astruct.symtable.find(spnongen))
  1025. else
  1026. begin
  1027. dummysym:=tsym(symtablestack.top.find(spnongen));
  1028. if not assigned(dummysym) and
  1029. (symtablestack.top=current_module.localsymtable) and
  1030. assigned(current_module.globalsymtable) then
  1031. dummysym:=tsym(current_module.globalsymtable.find(spnongen));
  1032. end;
  1033. if not assigned(dummysym) then
  1034. begin
  1035. dummysym:=ctypesym.create(orgspnongen,cundefineddef.create(true),true);
  1036. if assigned(astruct) then
  1037. astruct.symtable.insert(dummysym)
  1038. else
  1039. symtablestack.top.insert(dummysym);
  1040. end;
  1041. include(dummysym.symoptions,sp_generic_dummy);
  1042. { start token recorder for the declaration }
  1043. pd.init_genericdecl;
  1044. current_scanner.startrecordtokens(pd.genericdecltokenbuf);
  1045. end;
  1046. if assigned(genericdef) and not assigned(genericparams) then
  1047. insert_generic_parameter_types(pd,tstoreddef(genericdef),generictypelist);
  1048. { methods inherit df_generic or df_specialization from the objectdef }
  1049. if assigned(pd.struct) and
  1050. (pd.parast.symtablelevel=normal_function_level) then
  1051. begin
  1052. if (df_generic in pd.struct.defoptions) then
  1053. begin
  1054. include(pd.defoptions,df_generic);
  1055. parse_generic:=true;
  1056. end;
  1057. if (df_specialization in pd.struct.defoptions) then
  1058. begin
  1059. if assigned(current_specializedef) then
  1060. begin
  1061. include(pd.defoptions,df_specialization);
  1062. { Find corresponding genericdef, we need it later to
  1063. replay the tokens to generate the body }
  1064. if not assigned(pd.struct.genericdef) then
  1065. internalerror(200512113);
  1066. genericst:=pd.struct.genericdef.GetSymtable(gs_record);
  1067. if not assigned(genericst) then
  1068. internalerror(200512114);
  1069. { when searching for the correct procdef to use as genericdef we need to ignore
  1070. everything except procdefs so that we can find the correct indices }
  1071. index:=0;
  1072. found:=false;
  1073. for i:=0 to pd.owner.deflist.count-1 do
  1074. begin
  1075. if tdef(pd.owner.deflist[i]).typ<>procdef then
  1076. continue;
  1077. if pd.owner.deflist[i]=pd then
  1078. begin
  1079. found:=true;
  1080. break;
  1081. end;
  1082. inc(index);
  1083. end;
  1084. if not found then
  1085. internalerror(2014052301);
  1086. for i:=0 to genericst.deflist.count-1 do
  1087. begin
  1088. if tdef(genericst.deflist[i]).typ<>procdef then
  1089. continue;
  1090. if index=0 then
  1091. pd.genericdef:=tstoreddef(genericst.deflist[i]);
  1092. dec(index);
  1093. end;
  1094. if not assigned(pd.genericdef) or
  1095. (pd.genericdef.typ<>procdef) then
  1096. internalerror(200512115);
  1097. end
  1098. else
  1099. Message(parser_e_explicit_method_implementation_for_specializations_not_allowed);
  1100. end;
  1101. end;
  1102. { methods need to be exported }
  1103. if assigned(astruct) and
  1104. (
  1105. (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) or
  1106. (symtablestack.top.symtablelevel=main_program_level)
  1107. ) then
  1108. include(pd.procoptions,po_global);
  1109. { symbol options that need to be kept per procdef }
  1110. pd.fileinfo:=procstartfilepos;
  1111. pd.visibility:=symtablestack.top.currentvisibility;
  1112. if symtablestack.top.currentlyoptional then
  1113. include(pd.procoptions,po_optional);
  1114. { parse parameters }
  1115. if token=_LKLAMMER then
  1116. begin
  1117. old_current_structdef:=nil;
  1118. old_current_genericdef:=current_genericdef;
  1119. old_current_specializedef:=nil;
  1120. { Add ObjectSymtable to be able to find nested type definitions }
  1121. popclass:=0;
  1122. if assigned(pd.struct) and
  1123. (pd.parast.symtablelevel>=normal_function_level) and
  1124. not(symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1125. begin
  1126. popclass:=push_nested_hierarchy(pd.struct);
  1127. old_current_structdef:=current_structdef;
  1128. old_current_specializedef:=current_specializedef;
  1129. current_structdef:=pd.struct;
  1130. if assigned(current_structdef) and (df_generic in current_structdef.defoptions) then
  1131. current_genericdef:=current_structdef;
  1132. if assigned(current_structdef) and (df_specialization in current_structdef.defoptions) then
  1133. current_specializedef:=current_structdef;
  1134. end;
  1135. if pd.is_generic then
  1136. current_genericdef:=pd;
  1137. { Add parameter symtable }
  1138. if pd.parast.symtabletype<>staticsymtable then
  1139. symtablestack.push(pd.parast);
  1140. parse_parameter_dec(pd);
  1141. if pd.parast.symtabletype<>staticsymtable then
  1142. symtablestack.pop(pd.parast);
  1143. current_genericdef:=old_current_genericdef;
  1144. if popclass>0 then
  1145. begin
  1146. current_structdef:=old_current_structdef;
  1147. current_specializedef:=old_current_specializedef;
  1148. dec(popclass,pop_nested_hierarchy(pd.struct));
  1149. if popclass<>0 then
  1150. internalerror(201011260); // 11 nov 2010 index 0
  1151. end;
  1152. end;
  1153. parse_generic:=old_parse_generic;
  1154. result:=true;
  1155. end;
  1156. procedure parse_proc_dec_finish(pd:tprocdef;isclassmethod:boolean);
  1157. var
  1158. locationstr: string;
  1159. i: integer;
  1160. found: boolean;
  1161. procedure read_returndef(pd: tprocdef);
  1162. var
  1163. popclass: integer;
  1164. old_parse_generic: boolean;
  1165. old_current_structdef: tabstractrecorddef;
  1166. old_current_genericdef,
  1167. old_current_specializedef: tstoreddef;
  1168. begin
  1169. old_parse_generic:=parse_generic;
  1170. { Add ObjectSymtable to be able to find generic type definitions }
  1171. popclass:=0;
  1172. old_current_structdef:=nil;
  1173. old_current_genericdef:=current_genericdef;
  1174. old_current_specializedef:=current_specializedef;
  1175. current_genericdef:=nil;
  1176. current_specializedef:=nil;
  1177. if assigned(pd.struct) and
  1178. (pd.parast.symtablelevel>=normal_function_level) and
  1179. not (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1180. begin
  1181. popclass:=push_nested_hierarchy(pd.struct);
  1182. old_current_structdef:=current_structdef;
  1183. current_structdef:=pd.struct;
  1184. end;
  1185. if df_generic in pd.defoptions then
  1186. begin
  1187. if pd.is_generic then
  1188. current_genericdef:=pd
  1189. else if assigned(pd.struct) then
  1190. current_genericdef:=pd.struct
  1191. else
  1192. internalerror(2016090202);
  1193. end;
  1194. if df_specialization in pd.defoptions then
  1195. begin
  1196. if pd.is_specialization then
  1197. current_specializedef:=pd
  1198. else if assigned(pd.struct) then
  1199. current_specializedef:=pd.struct
  1200. else
  1201. internalerror(2016090203);
  1202. end;
  1203. parse_generic:=(df_generic in pd.defoptions);
  1204. if pd.is_generic or pd.is_specialization then
  1205. symtablestack.push(pd.parast);
  1206. single_type(pd.returndef,[stoAllowSpecialization]);
  1207. // Issue #24863, enabled only for the main progra commented out for now because it breaks building of RTL and needs extensive
  1208. // testing and/or RTL patching.
  1209. {
  1210. if ((pd.returndef=cvarianttype) or (pd.returndef=colevarianttype)) and
  1211. not(cs_compilesystem in current_settings.moduleswitches) then
  1212. current_module.flags:=current_module.flags or uf_uses_variants;
  1213. }
  1214. if is_dispinterface(pd.struct) and not is_automatable(pd.returndef) then
  1215. Message1(type_e_not_automatable,pd.returndef.typename);
  1216. if pd.is_generic or pd.is_specialization then
  1217. symtablestack.pop(pd.parast);
  1218. if popclass>0 then
  1219. begin
  1220. current_structdef:=old_current_structdef;
  1221. dec(popclass,pop_nested_hierarchy(pd.struct));
  1222. if popclass<>0 then
  1223. internalerror(201012020);
  1224. end;
  1225. current_genericdef:=old_current_genericdef;
  1226. current_specializedef:=old_current_specializedef;
  1227. parse_generic:=old_parse_generic;
  1228. end;
  1229. begin
  1230. locationstr:='';
  1231. case pd.proctypeoption of
  1232. potype_procedure:
  1233. begin
  1234. pd.returndef:=voidtype;
  1235. if isclassmethod then
  1236. include(pd.procoptions,po_classmethod);
  1237. end;
  1238. potype_function:
  1239. begin
  1240. if try_to_consume(_COLON) then
  1241. begin
  1242. read_returndef(pd);
  1243. if (target_info.system in [system_m68k_amiga]) then
  1244. begin
  1245. if (idtoken=_LOCATION) then
  1246. begin
  1247. if po_explicitparaloc in pd.procoptions then
  1248. begin
  1249. consume(_LOCATION);
  1250. locationstr:=cstringpattern;
  1251. consume(_CSTRING);
  1252. end
  1253. else
  1254. { I guess this needs a new message... (KB) }
  1255. Message(parser_e_paraloc_all_paras);
  1256. end
  1257. else
  1258. begin
  1259. if po_explicitparaloc in pd.procoptions then
  1260. { assign default locationstr, if none specified }
  1261. { and we've arguments with explicit paraloc }
  1262. locationstr:='D0';
  1263. end;
  1264. end;
  1265. end
  1266. else
  1267. begin
  1268. if (
  1269. parse_only and
  1270. not(is_interface(pd.struct))
  1271. ) or
  1272. (m_repeat_forward in current_settings.modeswitches) then
  1273. begin
  1274. consume(_COLON);
  1275. consume_all_until(_SEMICOLON);
  1276. end;
  1277. end;
  1278. if isclassmethod then
  1279. include(pd.procoptions,po_classmethod);
  1280. end;
  1281. potype_constructor,
  1282. potype_class_constructor:
  1283. begin
  1284. if not isclassmethod and
  1285. assigned(pd) and
  1286. assigned(pd.struct) then
  1287. begin
  1288. { Set return type, class constructors return the
  1289. created instance, object constructors return boolean }
  1290. if is_class(pd.struct) or
  1291. is_record(pd.struct) or
  1292. is_javaclass(pd.struct) then
  1293. pd.returndef:=pd.struct
  1294. else
  1295. if is_objectpascal_helper(pd.struct) then
  1296. pd.returndef:=tobjectdef(pd.struct).extendeddef
  1297. else
  1298. {$ifdef CPU64bitaddr}
  1299. pd.returndef:=bool64type;
  1300. {$else CPU64bitaddr}
  1301. pd.returndef:=bool32type;
  1302. {$endif CPU64bitaddr}
  1303. end
  1304. else
  1305. pd.returndef:=voidtype;
  1306. end;
  1307. potype_class_destructor,
  1308. potype_destructor:
  1309. begin
  1310. if assigned(pd) then
  1311. pd.returndef:=voidtype;
  1312. end;
  1313. potype_operator:
  1314. begin
  1315. { operators always need to be searched in all units (that
  1316. contain operators) }
  1317. include(pd.procoptions,po_overload);
  1318. pd.procsym.owner.includeoption(sto_has_operator);
  1319. if pd.parast.symtablelevel>normal_function_level then
  1320. Message(parser_e_no_local_operator);
  1321. if isclassmethod then
  1322. include(pd.procoptions,po_classmethod);
  1323. if token<>_ID then
  1324. begin
  1325. if not(m_result in current_settings.modeswitches) then
  1326. consume(_ID);
  1327. end
  1328. else
  1329. begin
  1330. pd.resultname:=stringdup(orgpattern);
  1331. consume(_ID);
  1332. end;
  1333. if not try_to_consume(_COLON) then
  1334. begin
  1335. consume(_COLON);
  1336. pd.returndef:=generrordef;
  1337. consume_all_until(_SEMICOLON);
  1338. end
  1339. else
  1340. begin
  1341. read_returndef(pd);
  1342. { check that class operators have either return type of structure or }
  1343. { at least one argument of that type }
  1344. if (po_classmethod in pd.procoptions) and
  1345. (pd.returndef <> pd.struct) then
  1346. begin
  1347. found:=false;
  1348. for i := 0 to pd.parast.SymList.Count - 1 do
  1349. if tparavarsym(pd.parast.SymList[i]).vardef=pd.struct then
  1350. begin
  1351. found:=true;
  1352. break;
  1353. end;
  1354. if not found then
  1355. if assigned(pd.struct) then
  1356. Message1(parser_e_at_least_one_argument_must_be_of_type,pd.struct.RttiName)
  1357. else
  1358. MessagePos(pd.fileinfo,type_e_type_id_expected);
  1359. end;
  1360. if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and
  1361. equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and
  1362. (pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then
  1363. message(parser_e_no_such_assignment)
  1364. else if not isoperatoracceptable(pd,optoken) then
  1365. Message(parser_e_overload_impossible);
  1366. end;
  1367. end;
  1368. else
  1369. internalerror(2015052202);
  1370. end;
  1371. { file types can't be function results }
  1372. if assigned(pd) and
  1373. (pd.returndef.typ=filedef) then
  1374. message(parser_e_illegal_function_result);
  1375. { support procedure proc stdcall export; }
  1376. if not(check_proc_directive(false)) then
  1377. begin
  1378. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1379. begin
  1380. message(parser_e_field_not_allowed_here);
  1381. consume_all_until(_SEMICOLON);
  1382. end;
  1383. consume(_SEMICOLON);
  1384. end;
  1385. if locationstr<>'' then
  1386. begin
  1387. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1388. { I guess this needs a new message... (KB) }
  1389. message(parser_e_illegal_explicit_paraloc);
  1390. end;
  1391. end;
  1392. function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef;isgeneric:boolean):tprocdef;
  1393. var
  1394. pd : tprocdef;
  1395. old_block_type : tblock_type;
  1396. recover : boolean;
  1397. procedure finish_intf_mapping;
  1398. begin
  1399. if token=_COLON then
  1400. begin
  1401. message(parser_e_field_not_allowed_here);
  1402. consume_all_until(_SEMICOLON);
  1403. end;
  1404. consume(_SEMICOLON);
  1405. end;
  1406. begin
  1407. pd:=nil;
  1408. recover:=false;
  1409. case token of
  1410. _FUNCTION :
  1411. begin
  1412. consume(_FUNCTION);
  1413. if parse_proc_head(astruct,potype_function,isgeneric,nil,nil,pd) then
  1414. begin
  1415. { pd=nil when it is a interface mapping }
  1416. if assigned(pd) then
  1417. parse_proc_dec_finish(pd,isclassmethod)
  1418. else
  1419. finish_intf_mapping;
  1420. end
  1421. else
  1422. begin
  1423. { recover }
  1424. consume(_COLON);
  1425. consume_all_until(_SEMICOLON);
  1426. recover:=true;
  1427. end;
  1428. end;
  1429. _PROCEDURE :
  1430. begin
  1431. consume(_PROCEDURE);
  1432. if parse_proc_head(astruct,potype_procedure,isgeneric,nil,nil,pd) then
  1433. begin
  1434. { pd=nil when it is an interface mapping }
  1435. if assigned(pd) then
  1436. parse_proc_dec_finish(pd,isclassmethod)
  1437. else
  1438. finish_intf_mapping;
  1439. end
  1440. else
  1441. recover:=true;
  1442. end;
  1443. _CONSTRUCTOR :
  1444. begin
  1445. consume(_CONSTRUCTOR);
  1446. if isclassmethod then
  1447. recover:=not parse_proc_head(astruct,potype_class_constructor,false,nil,nil,pd)
  1448. else
  1449. recover:=not parse_proc_head(astruct,potype_constructor,false,nil,nil,pd);
  1450. if not recover then
  1451. parse_proc_dec_finish(pd,isclassmethod);
  1452. end;
  1453. _DESTRUCTOR :
  1454. begin
  1455. consume(_DESTRUCTOR);
  1456. if isclassmethod then
  1457. recover:=not parse_proc_head(astruct,potype_class_destructor,false,nil,nil,pd)
  1458. else
  1459. recover:=not parse_proc_head(astruct,potype_destructor,false,nil,nil,pd);
  1460. if not recover then
  1461. parse_proc_dec_finish(pd,isclassmethod);
  1462. end;
  1463. else
  1464. if (token=_OPERATOR) or
  1465. (isclassmethod and (idtoken=_OPERATOR)) then
  1466. begin
  1467. { we need to set the block type to bt_body, so that operator names
  1468. like ">", "=>" or "<>" are parsed correctly instead of e.g.
  1469. _LSHARPBRACKET and _RSHARPBRACKET for "<>" }
  1470. old_block_type:=block_type;
  1471. block_type:=bt_body;
  1472. consume(_OPERATOR);
  1473. parse_proc_head(astruct,potype_operator,false,nil,nil,pd);
  1474. block_type:=old_block_type;
  1475. if assigned(pd) then
  1476. parse_proc_dec_finish(pd,isclassmethod)
  1477. else
  1478. begin
  1479. { recover }
  1480. try_to_consume(_ID);
  1481. consume(_COLON);
  1482. consume_all_until(_SEMICOLON);
  1483. recover:=true;
  1484. end;
  1485. end;
  1486. end;
  1487. if recover and not(check_proc_directive(false)) then
  1488. begin
  1489. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1490. begin
  1491. message(parser_e_field_not_allowed_here);
  1492. consume_all_until(_SEMICOLON);
  1493. end;
  1494. consume(_SEMICOLON);
  1495. end;
  1496. { we've parsed the final semicolon, so stop recording tokens }
  1497. if assigned(pd) and
  1498. (df_generic in pd.defoptions) and
  1499. assigned(pd.genericdecltokenbuf) then
  1500. current_scanner.stoprecordtokens;
  1501. result:=pd;
  1502. end;
  1503. function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean;hadgeneric:boolean): tprocdef;
  1504. var
  1505. oldparse_only: boolean;
  1506. begin
  1507. oldparse_only:=parse_only;
  1508. parse_only:=true;
  1509. result:=parse_proc_dec(is_classdef,astruct,hadgeneric);
  1510. { this is for error recovery as well as forward }
  1511. { interface mappings, i.e. mapping to a method }
  1512. { which isn't declared yet }
  1513. if assigned(result) then
  1514. begin
  1515. parse_record_proc_directives(result);
  1516. { since records have no inheritance, don't allow non-static
  1517. class methods. Delphi does the same. }
  1518. if (result.proctypeoption<>potype_operator) and
  1519. is_classdef and
  1520. not (po_staticmethod in result.procoptions) then
  1521. MessagePos(result.fileinfo, parser_e_class_methods_only_static_in_records);
  1522. // we can't add hidden params here because record is not yet defined
  1523. // and therefore record size which has influence on paramter passing rules may change too
  1524. // look at record_dec to see where calling conventions are applied (issue #0021044)
  1525. handle_calling_convention(result,[hcc_check]);
  1526. { add definition to procsym }
  1527. proc_add_definition(result);
  1528. end;
  1529. maybe_parse_hint_directives(result);
  1530. parse_only:=oldparse_only;
  1531. end;
  1532. procedure insert_record_hidden_paras(astruct: trecorddef);
  1533. var
  1534. pd: tdef;
  1535. i: longint;
  1536. oldpos : tfileposinfo;
  1537. oldparse_only: boolean;
  1538. begin
  1539. // handle calling conventions of record methods
  1540. oldpos:=current_filepos;
  1541. oldparse_only:=parse_only;
  1542. parse_only:=true;
  1543. { don't keep track of procdefs in a separate list, because the
  1544. compiler may add additional procdefs (e.g. property wrappers for
  1545. the jvm backend) }
  1546. for i := 0 to astruct.symtable.deflist.count - 1 do
  1547. begin
  1548. pd:=tdef(astruct.symtable.deflist[i]);
  1549. if pd.typ<>procdef then
  1550. continue;
  1551. current_filepos:=tprocdef(pd).fileinfo;
  1552. handle_calling_convention(tprocdef(pd),[hcc_insert_hidden_paras]);
  1553. end;
  1554. parse_only:=oldparse_only;
  1555. current_filepos:=oldpos;
  1556. end;
  1557. {****************************************************************************
  1558. Procedure directive handlers
  1559. ****************************************************************************}
  1560. procedure pd_compilerproc(pd:tabstractprocdef);
  1561. var
  1562. v : Tconstexprint;
  1563. begin
  1564. { check for optional syssym index }
  1565. if try_to_consume(_COLON) then
  1566. begin
  1567. v:=get_intconst;
  1568. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1569. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1570. else if not assigned(tsyssym.find_by_number(longint(v.svalue))) then
  1571. message1(parser_e_invalid_internal_function_index,tostr(v))
  1572. else
  1573. tprocdef(pd).extnumber:=longint(v.svalue);
  1574. end;
  1575. end;
  1576. procedure pd_far(pd:tabstractprocdef);
  1577. begin
  1578. pd.declared_far;
  1579. end;
  1580. procedure pd_near(pd:tabstractprocdef);
  1581. begin
  1582. pd.declared_near;
  1583. end;
  1584. procedure pd_export(pd:tabstractprocdef);
  1585. begin
  1586. if pd.typ<>procdef then
  1587. internalerror(200304264);
  1588. if assigned(tprocdef(pd).struct) then
  1589. Message(parser_e_methods_dont_be_export);
  1590. if pd.parast.symtablelevel>normal_function_level then
  1591. Message(parser_e_dont_nest_export);
  1592. end;
  1593. procedure pd_forward(pd:tabstractprocdef);
  1594. begin
  1595. if pd.typ<>procdef then
  1596. internalerror(200304265);
  1597. tprocdef(pd).forwarddef:=true;
  1598. end;
  1599. procedure pd_alias(pd:tabstractprocdef);
  1600. begin
  1601. if pd.typ<>procdef then
  1602. internalerror(200304266);
  1603. consume(_COLON);
  1604. tprocdef(pd).aliasnames.insert(get_stringconst);
  1605. include(pd.procoptions,po_has_public_name);
  1606. end;
  1607. procedure pd_public(pd:tabstractprocdef);
  1608. begin
  1609. if pd.typ<>procdef then
  1610. internalerror(200304266);
  1611. if try_to_consume(_NAME) then
  1612. begin
  1613. tprocdef(pd).aliasnames.insert(get_stringconst);
  1614. include(pd.procoptions,po_has_public_name);
  1615. end;
  1616. end;
  1617. procedure pd_asmname(pd:tabstractprocdef);
  1618. begin
  1619. if pd.typ<>procdef then
  1620. internalerror(200304267);
  1621. if token=_CCHAR then
  1622. begin
  1623. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1624. consume(_CCHAR)
  1625. end
  1626. else
  1627. begin
  1628. tprocdef(pd).aliasnames.insert(target_info.Cprefix+cstringpattern);
  1629. consume(_CSTRING);
  1630. end;
  1631. { we don't need anything else }
  1632. tprocdef(pd).forwarddef:=false;
  1633. end;
  1634. procedure pd_internconst(pd:tabstractprocdef);
  1635. var v:Tconstexprint;
  1636. begin
  1637. if pd.typ<>procdef then
  1638. internalerror(200304268);
  1639. consume(_COLON);
  1640. v:=get_intconst;
  1641. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1642. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1643. else
  1644. Tprocdef(pd).extnumber:=longint(v.svalue);
  1645. end;
  1646. procedure pd_internproc(pd:tabstractprocdef);
  1647. var v:Tconstexprint;
  1648. begin
  1649. if pd.typ<>procdef then
  1650. internalerror(200304268);
  1651. consume(_COLON);
  1652. v:=get_intconst;
  1653. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1654. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1655. else
  1656. Tprocdef(pd).extnumber:=longint(v.svalue);
  1657. { the proc is defined }
  1658. tprocdef(pd).forwarddef:=false;
  1659. end;
  1660. procedure pd_interrupt(pd:tabstractprocdef);
  1661. begin
  1662. if pd.parast.symtablelevel>normal_function_level then
  1663. Message(parser_e_dont_nest_interrupt);
  1664. end;
  1665. procedure pd_abstract(pd:tabstractprocdef);
  1666. begin
  1667. if pd.typ<>procdef then
  1668. internalerror(200304269);
  1669. if is_objectpascal_helper(tprocdef(pd).struct) then
  1670. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_ABSTRACT].str);
  1671. if assigned(tprocdef(pd).struct) and
  1672. (oo_is_sealed in tprocdef(pd).struct.objectoptions) then
  1673. Message(parser_e_sealed_class_cannot_have_abstract_methods)
  1674. else if (po_virtualmethod in pd.procoptions) then
  1675. begin
  1676. include(pd.procoptions,po_abstractmethod);
  1677. { one more abstract method }
  1678. inc(tobjectdef(pd.owner.defowner).abstractcnt);
  1679. end
  1680. else
  1681. Message(parser_e_only_virtual_methods_abstract);
  1682. { the method is defined }
  1683. tprocdef(pd).forwarddef:=false;
  1684. end;
  1685. procedure pd_final(pd:tabstractprocdef);
  1686. begin
  1687. if pd.typ<>procdef then
  1688. internalerror(200910170);
  1689. if is_objectpascal_helper(tprocdef(pd).struct) and
  1690. (m_objfpc in current_settings.modeswitches) then
  1691. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_FINAL].str);
  1692. if (po_virtualmethod in pd.procoptions) or
  1693. (is_javaclass(tprocdef(pd).struct) and
  1694. (po_classmethod in pd.procoptions)) then
  1695. include(pd.procoptions,po_finalmethod)
  1696. else
  1697. Message(parser_e_only_virtual_methods_final);
  1698. end;
  1699. procedure pd_enumerator(pd:tabstractprocdef);
  1700. begin
  1701. if pd.typ<>procdef then
  1702. internalerror(200910250);
  1703. if (token = _ID) then
  1704. begin
  1705. if pattern='MOVENEXT' then
  1706. begin
  1707. if oo_has_enumerator_movenext in tprocdef(pd).struct.objectoptions then
  1708. message(parser_e_only_one_enumerator_movenext);
  1709. pd.calcparas;
  1710. if (pd.proctypeoption = potype_function) and is_boolean(pd.returndef) and
  1711. (pd.minparacount = 0) then
  1712. begin
  1713. include(tprocdef(pd).struct.objectoptions, oo_has_enumerator_movenext);
  1714. include(pd.procoptions,po_enumerator_movenext);
  1715. end
  1716. else
  1717. Message(parser_e_enumerator_movenext_is_not_valid)
  1718. end
  1719. else
  1720. Message1(parser_e_invalid_enumerator_identifier, pattern);
  1721. consume(token);
  1722. end
  1723. else
  1724. Message(parser_e_enumerator_identifier_required);
  1725. end;
  1726. procedure pd_virtual(pd:tabstractprocdef);
  1727. {$ifdef WITHDMT}
  1728. var
  1729. pt : tnode;
  1730. {$endif WITHDMT}
  1731. begin
  1732. if (not assigned(pd.owner.defowner) or
  1733. not is_java_class_or_interface(tdef(pd.owner.defowner))) and
  1734. (po_external in pd.procoptions) then
  1735. Message1(parser_e_proc_dir_conflict,'EXTERNAL');
  1736. if pd.typ<>procdef then
  1737. internalerror(2003042610);
  1738. if (pd.proctypeoption=potype_constructor) and
  1739. is_object(tprocdef(pd).struct) then
  1740. Message(parser_e_constructor_cannot_be_not_virtual);
  1741. if pd.is_generic then
  1742. message(parser_e_genfuncs_cannot_be_virtual);
  1743. if is_objectpascal_helper(tprocdef(pd).struct) and
  1744. (m_objfpc in current_settings.modeswitches) then
  1745. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_VIRTUAL].str);
  1746. {$ifdef WITHDMT}
  1747. if is_object(tprocdef(pd).struct) and
  1748. (token<>_SEMICOLON) then
  1749. begin
  1750. { any type of parameter is allowed here! }
  1751. pt:=comp_expr(true);
  1752. if is_constintnode(pt) then
  1753. begin
  1754. include(pd.procoptions,po_msgint);
  1755. pd.messageinf.i:=pt.value;
  1756. end
  1757. else
  1758. Message(parser_e_ill_msg_expr);
  1759. disposetree(pt);
  1760. end;
  1761. {$endif WITHDMT}
  1762. end;
  1763. procedure pd_dispid(pd:tabstractprocdef);
  1764. var pt:Tnode;
  1765. begin
  1766. if pd.typ<>procdef then
  1767. internalerror(200604301);
  1768. pt:=comp_expr([ef_accept_equal]);
  1769. if is_constintnode(pt) then
  1770. if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
  1771. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
  1772. else
  1773. Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
  1774. else
  1775. message(parser_e_dispid_must_be_ord_const);
  1776. pt.free;
  1777. end;
  1778. procedure pd_static(pd:tabstractprocdef);
  1779. begin
  1780. if pd.typ<>procdef then
  1781. internalerror(2013032001);
  1782. if not assigned(tprocdef(pd).struct) then
  1783. internalerror(2013032002);
  1784. include(tprocdef(pd).procsym.symoptions,sp_static);
  1785. { "static" is not allowed for operators or normal methods (except in objects) }
  1786. if (pd.proctypeoption=potype_operator) or
  1787. (
  1788. not (po_classmethod in pd.procoptions) and
  1789. not is_object(tprocdef(pd).struct)
  1790. )
  1791. then
  1792. Message1(parser_e_dir_not_allowed,arraytokeninfo[_STATIC].str);
  1793. include(pd.procoptions,po_staticmethod);
  1794. end;
  1795. procedure pd_override(pd:tabstractprocdef);
  1796. begin
  1797. if pd.typ<>procdef then
  1798. internalerror(2003042611);
  1799. if is_objectpascal_helper(tprocdef(pd).struct) then
  1800. begin
  1801. if m_objfpc in current_settings.modeswitches then
  1802. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_OVERRIDE].str)
  1803. end
  1804. else if not(is_class_or_interface_or_objc_or_java(tprocdef(pd).struct)) then
  1805. Message(parser_e_no_object_override)
  1806. else if is_objccategory(tprocdef(pd).struct) then
  1807. Message(parser_e_no_category_override)
  1808. else if (po_external in pd.procoptions) and
  1809. not is_objc_class_or_protocol(tprocdef(pd).struct) and
  1810. not is_cppclass(tprocdef(pd).struct) and
  1811. not is_java_class_or_interface(tprocdef(pd).struct) then
  1812. Message1(parser_e_proc_dir_conflict,'OVERRIDE');
  1813. end;
  1814. procedure pd_overload(pd:tabstractprocdef);
  1815. begin
  1816. if pd.typ<>procdef then
  1817. internalerror(2003042612);
  1818. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1819. end;
  1820. procedure pd_message(pd:tabstractprocdef);
  1821. var
  1822. pt : tnode;
  1823. paracnt : longint;
  1824. begin
  1825. if pd.typ<>procdef then
  1826. internalerror(2003042613);
  1827. if is_objectpascal_helper(tprocdef(pd).struct) then
  1828. begin
  1829. if m_objfpc in current_settings.modeswitches then
  1830. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_MESSAGE].str);
  1831. end
  1832. else
  1833. if not is_class(tprocdef(pd).struct) and
  1834. not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1835. Message(parser_e_msg_only_for_classes);
  1836. if ([po_msgstr,po_msgint]*pd.procoptions)<>[] then
  1837. Message(parser_e_multiple_messages);
  1838. { check parameter type }
  1839. if not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1840. begin
  1841. if po_external in pd.procoptions then
  1842. Message1(parser_e_proc_dir_conflict,'MESSAGE');
  1843. paracnt:=0;
  1844. pd.parast.SymList.ForEachCall(@check_msg_para,@paracnt);
  1845. if paracnt<>1 then
  1846. Message(parser_e_ill_msg_param);
  1847. end;
  1848. pt:=comp_expr([ef_accept_equal]);
  1849. { message is 1-character long }
  1850. if is_constcharnode(pt) then
  1851. begin
  1852. include(pd.procoptions,po_msgstr);
  1853. tprocdef(pd).messageinf.str:=stringdup(chr(byte(tordconstnode(pt).value.uvalue and $FF)));
  1854. end
  1855. else if pt.nodetype=stringconstn then
  1856. begin
  1857. include(pd.procoptions,po_msgstr);
  1858. if (tstringconstnode(pt).len>255) then
  1859. Message(parser_e_message_string_too_long);
  1860. tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
  1861. end
  1862. else
  1863. if is_constintnode(pt) and
  1864. (is_class(tprocdef(pd).struct) or
  1865. is_objectpascal_helper(tprocdef(pd).struct)) then
  1866. begin
  1867. include(pd.procoptions,po_msgint);
  1868. if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
  1869. (Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
  1870. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(Tprocdef(pd).messageinf.i)),tostr(high(Tprocdef(pd).messageinf.i)))
  1871. else
  1872. Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
  1873. end
  1874. else
  1875. Message(parser_e_ill_msg_expr);
  1876. { check whether the selector name is valid in case of Objective-C }
  1877. if (po_msgstr in pd.procoptions) and
  1878. is_objc_class_or_protocol(tprocdef(pd).struct) and
  1879. not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
  1880. Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
  1881. pt.free;
  1882. end;
  1883. procedure pd_reintroduce(pd:tabstractprocdef);
  1884. begin
  1885. if pd.typ<>procdef then
  1886. internalerror(200401211);
  1887. if is_objectpascal_helper(tprocdef(pd).struct) then
  1888. begin
  1889. if m_objfpc in current_settings.modeswitches then
  1890. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_REINTRODUCE].str);
  1891. end
  1892. else
  1893. if not(is_class_or_interface_or_object(tprocdef(pd).struct)) and
  1894. not(is_objccategory(tprocdef(pd).struct)) and
  1895. not(is_javaclass(tprocdef(pd).struct)) then
  1896. Message(parser_e_no_object_reintroduce);
  1897. end;
  1898. procedure pd_syscall(pd:tabstractprocdef);
  1899. procedure include_po_syscall;
  1900. var
  1901. syscall: psyscallinfo;
  1902. begin
  1903. case target_info.system of
  1904. system_m68k_atari,
  1905. system_m68k_amiga,
  1906. system_powerpc_amiga:
  1907. include(pd.procoptions,get_default_syscall);
  1908. system_powerpc_morphos,
  1909. system_i386_aros,
  1910. system_x86_64_aros:
  1911. begin
  1912. syscall:=get_syscall_by_token(idtoken);
  1913. if assigned(syscall) then
  1914. begin
  1915. if target_info.system in syscall^.validon then
  1916. begin
  1917. consume(idtoken);
  1918. include(pd.procoptions,syscall^.procoption);
  1919. end
  1920. end
  1921. else
  1922. include(pd.procoptions,get_default_syscall);
  1923. end;
  1924. end;
  1925. end;
  1926. function po_syscall_to_varoptions: tvaroptions;
  1927. begin
  1928. result:=[vo_is_syscall_lib,vo_is_hidden_para];
  1929. if ([po_syscall_legacy,po_syscall_r12base,po_syscall_sysv,po_syscall_eaxbase] * tprocdef(pd).procoptions) <> [] then
  1930. include(result,vo_has_explicit_paraloc);
  1931. end;
  1932. function po_syscall_to_regname: string;
  1933. begin
  1934. if po_syscall_legacy in tprocdef(pd).procoptions then
  1935. result:='A6'
  1936. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1937. result:='R12'
  1938. { let sysv store the libbase in r12 as well, because we will
  1939. need the libbase anyway during the call generation }
  1940. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1941. result:='R12'
  1942. else if po_syscall_eaxbase in tprocdef(pd).procoptions then
  1943. begin
  1944. if target_info.system = system_i386_aros then
  1945. result:='EAX'
  1946. else if target_info.system = system_x86_64_aros then
  1947. result:='RAX'
  1948. else
  1949. internalerror(2016090201);
  1950. end
  1951. else
  1952. internalerror(2016090101);
  1953. end;
  1954. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1955. const
  1956. syscall_paranr: array[boolean] of aint =
  1957. ( paranr_syscall_lib_last, paranr_syscall_lib_first );
  1958. var
  1959. vs : tparavarsym;
  1960. sym : tsym;
  1961. symtable : TSymtable;
  1962. v: Tconstexprint;
  1963. vo: tvaroptions;
  1964. paranr: aint;
  1965. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1966. begin
  1967. if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
  1968. internalerror(2003042614);
  1969. tprocdef(pd).forwarddef:=false;
  1970. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1971. include_po_syscall;
  1972. if target_info.system = system_m68k_atari then
  1973. begin
  1974. v:=get_intconst;
  1975. if ((v<0) or (v>15)) then
  1976. message(parser_e_range_check_error)
  1977. else
  1978. tprocdef(pd).extnumber:=longint(v.svalue);
  1979. v:=get_intconst;
  1980. if ((v<0) or (v>high(smallint))) then
  1981. message(parser_e_range_check_error)
  1982. else
  1983. tprocdef(pd).import_nr:=longint(v.svalue);
  1984. exit;
  1985. end;
  1986. if consume_sym(sym,symtable) then
  1987. if (sym.typ=staticvarsym) and
  1988. ((tabstractvarsym(sym).vardef.typ=pointerdef) or
  1989. is_32bitint(tabstractvarsym(sym).vardef)) then
  1990. begin
  1991. include(pd.procoptions,po_syscall_has_libsym);
  1992. tcpuprocdef(pd).libsym:=sym;
  1993. vo:=po_syscall_to_varoptions;
  1994. paranr:=syscall_paranr[po_syscall_basesysv in tprocdef(pd).procoptions];
  1995. vs:=cparavarsym.create('$syscalllib',paranr,vs_value,tabstractvarsym(sym).vardef,vo);
  1996. if vo_has_explicit_paraloc in vo then
  1997. paramanager.parseparaloc(vs,po_syscall_to_regname);
  1998. pd.parast.insert(vs);
  1999. end
  2000. else
  2001. Message(parser_e_32bitint_or_pointer_variable_expected);
  2002. paramanager.create_funcretloc_info(pd,calleeside);
  2003. paramanager.create_funcretloc_info(pd,callerside);
  2004. v:=get_intconst;
  2005. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  2006. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(Tprocdef(pd).extnumber)),tostr(high(Tprocdef(pd).extnumber)))
  2007. else
  2008. if target_info.system in [system_i386_aros,system_x86_64_aros] then
  2009. Tprocdef(pd).extnumber:=v.uvalue * sizeof(pint)
  2010. else
  2011. Tprocdef(pd).extnumber:=v.uvalue;
  2012. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  2013. end;
  2014. procedure pd_external(pd:tabstractprocdef);
  2015. {
  2016. If import_dll=nil the procedure is assumed to be in another
  2017. object file. In that object file it should have the name to
  2018. which import_name is pointing to. Otherwise, the procedure is
  2019. assumed to be in the DLL to which import_dll is pointing to. In
  2020. that case either import_nr<>0 or import_name<>nil is true, so
  2021. the procedure is either imported by number or by name. (DM)
  2022. }
  2023. var
  2024. hs : string;
  2025. v:Tconstexprint;
  2026. is_java_external: boolean;
  2027. begin
  2028. if pd.typ<>procdef then
  2029. internalerror(2003042615);
  2030. { Allow specifying a separate external name for methods in external Java
  2031. because its identifier naming constraints are laxer than FPC's
  2032. (e.g., case sensitive).
  2033. Limitation: only allows specifying the symbol name and not the package name,
  2034. and only for external classes/interfaces }
  2035. is_java_external:=
  2036. (pd.typ=procdef) and
  2037. is_java_class_or_interface(tdef(pd.owner.defowner)) and
  2038. (oo_is_external in tobjectdef(pd.owner.defowner).objectoptions);
  2039. with tprocdef(pd) do
  2040. begin
  2041. forwarddef:=false;
  2042. { forbid local external procedures }
  2043. if parast.symtablelevel>normal_function_level then
  2044. Message(parser_e_no_local_proc_external);
  2045. { If the procedure should be imported from a DLL, a constant string follows.
  2046. This isn't really correct, an contant string expression follows
  2047. so we check if an semicolon follows, else a string constant have to
  2048. follow (FK) }
  2049. if not is_java_external and
  2050. not(token=_SEMICOLON) and not(idtoken=_NAME) then
  2051. begin
  2052. { Always add library prefix and suffix to create an uniform name }
  2053. hs:=get_stringconst;
  2054. if ExtractFileExt(hs)='' then
  2055. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  2056. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  2057. hs:=target_info.sharedlibprefix+hs;
  2058. { the JVM expects java/lang/Object rather than java.lang.Object }
  2059. if target_info.system in systems_jvm then
  2060. Replace(hs,'.','/');
  2061. import_dll:=stringdup(hs);
  2062. include(procoptions,po_has_importdll);
  2063. if (idtoken=_NAME) then
  2064. begin
  2065. consume(_NAME);
  2066. import_name:=stringdup(get_stringconst);
  2067. include(procoptions,po_has_importname);
  2068. if import_name^='' then
  2069. message(parser_e_empty_import_name);
  2070. end;
  2071. if (idtoken=_INDEX) then
  2072. begin
  2073. {After the word index follows the index number in the DLL.}
  2074. consume(_INDEX);
  2075. v:=get_intconst;
  2076. if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
  2077. message(parser_e_range_check_error)
  2078. else
  2079. import_nr:=longint(v.svalue);
  2080. end;
  2081. { default is to used the realname of the procedure }
  2082. if (import_nr=0) and not assigned(import_name) then
  2083. begin
  2084. import_name:=stringdup(procsym.realname);
  2085. include(procoptions,po_has_importname);
  2086. end;
  2087. end
  2088. else
  2089. begin
  2090. if (idtoken=_NAME) or
  2091. is_java_external then
  2092. begin
  2093. consume(_NAME);
  2094. import_name:=stringdup(get_stringconst);
  2095. include(procoptions,po_has_importname);
  2096. if import_name^='' then
  2097. message(parser_e_empty_import_name);
  2098. end;
  2099. end;
  2100. end;
  2101. end;
  2102. procedure pd_weakexternal(pd:tabstractprocdef);
  2103. begin
  2104. if not(target_info.system in systems_weak_linking) then
  2105. message(parser_e_weak_external_not_supported)
  2106. else
  2107. pd_external(pd);
  2108. end;
  2109. procedure pd_winapi(pd:tabstractprocdef);
  2110. begin
  2111. if not(target_info.system in systems_wince) then
  2112. pd.proccalloption:=pocall_cdecl
  2113. else
  2114. pd.proccalloption:=pocall_stdcall;
  2115. end;
  2116. procedure pd_hardfloat(pd:tabstractprocdef);
  2117. begin
  2118. if
  2119. {$if defined(arm)}
  2120. (current_settings.fputype=fpu_soft) or
  2121. {$endif defined(arm)}
  2122. (cs_fp_emulation in current_settings.moduleswitches) then
  2123. message(parser_e_cannot_use_hardfloat_in_a_softfloat_environment);
  2124. end;
  2125. type
  2126. pd_handler=procedure(pd:tabstractprocdef);
  2127. proc_dir_rec=record
  2128. idtok : ttoken;
  2129. pd_flags : tpdflags;
  2130. handler : pd_handler;
  2131. pocall : tproccalloption;
  2132. pooption : tprocoptions;
  2133. mutexclpocall : tproccalloptions;
  2134. mutexclpotype : tproctypeoptions;
  2135. mutexclpo : tprocoptions;
  2136. end;
  2137. const
  2138. {Should contain the number of procedure directives we support.}
  2139. num_proc_directives=46;
  2140. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  2141. (
  2142. (
  2143. idtok:_ABSTRACT;
  2144. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2145. handler : @pd_abstract;
  2146. pocall : pocall_none;
  2147. pooption : [po_abstractmethod];
  2148. mutexclpocall : [pocall_internproc];
  2149. mutexclpotype : [];
  2150. mutexclpo : [po_exports,po_interrupt,po_inline]
  2151. ),(
  2152. idtok:_ALIAS;
  2153. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2154. handler : @pd_alias;
  2155. pocall : pocall_none;
  2156. pooption : [];
  2157. mutexclpocall : [];
  2158. mutexclpotype : [];
  2159. mutexclpo : [po_external,po_inline]
  2160. ),(
  2161. idtok:_ASMNAME;
  2162. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  2163. handler : @pd_asmname;
  2164. pocall : pocall_cdecl;
  2165. pooption : [po_external];
  2166. mutexclpocall : [pocall_internproc];
  2167. mutexclpotype : [];
  2168. mutexclpo : [po_external,po_inline]
  2169. ),(
  2170. idtok:_ASSEMBLER;
  2171. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2172. handler : nil;
  2173. pocall : pocall_none;
  2174. pooption : [po_assembler];
  2175. mutexclpocall : [];
  2176. mutexclpotype : [];
  2177. mutexclpo : [po_external]
  2178. ),(
  2179. idtok:_C; {same as cdecl for mode mac}
  2180. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2181. handler : nil;
  2182. pocall : pocall_cdecl;
  2183. pooption : [];
  2184. mutexclpocall : [];
  2185. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2186. mutexclpo : [po_assembler,po_external]
  2187. ),(
  2188. idtok:_CDECL;
  2189. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2190. handler : nil;
  2191. pocall : pocall_cdecl;
  2192. pooption : [];
  2193. mutexclpocall : [];
  2194. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2195. mutexclpo : [po_assembler,po_external]
  2196. ),(
  2197. idtok:_DISPID;
  2198. pd_flags : [pd_dispinterface];
  2199. handler : @pd_dispid;
  2200. pocall : pocall_none;
  2201. pooption : [po_dispid];
  2202. mutexclpocall : [pocall_internproc];
  2203. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2204. mutexclpo : [po_interrupt,po_external,po_inline]
  2205. ),(
  2206. idtok:_DYNAMIC;
  2207. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord];
  2208. handler : @pd_virtual;
  2209. pocall : pocall_none;
  2210. pooption : [po_virtualmethod];
  2211. mutexclpocall : [pocall_internproc];
  2212. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2213. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  2214. ),(
  2215. idtok:_EXPORT;
  2216. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf,pd_notrecord,pd_nothelper];
  2217. handler : @pd_export;
  2218. pocall : pocall_none;
  2219. pooption : [po_exports,po_global];
  2220. mutexclpocall : [pocall_internproc];
  2221. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2222. mutexclpo : [po_external,po_interrupt,po_inline]
  2223. ),(
  2224. idtok:_EXTERNAL;
  2225. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper,pd_javaclass,pd_intfjava];
  2226. handler : @pd_external;
  2227. pocall : pocall_none;
  2228. pooption : [po_external];
  2229. mutexclpocall : [pocall_syscall];
  2230. { allowed for external cpp classes }
  2231. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2232. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2233. ),(
  2234. idtok:_FAR;
  2235. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2236. handler : @pd_far;
  2237. pocall : pocall_none;
  2238. pooption : [];
  2239. mutexclpocall : [pocall_internproc];
  2240. mutexclpotype : [];
  2241. mutexclpo : [po_inline]
  2242. ),(
  2243. idtok:_FAR16;
  2244. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject,pd_notrecord,pd_nothelper];
  2245. handler : nil;
  2246. pocall : pocall_far16;
  2247. pooption : [];
  2248. mutexclpocall : [];
  2249. mutexclpotype : [];
  2250. mutexclpo : [po_external]
  2251. ),(
  2252. idtok:_FINAL;
  2253. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2254. handler : @pd_final;
  2255. pocall : pocall_none;
  2256. pooption : [po_finalmethod];
  2257. mutexclpocall : [pocall_internproc];
  2258. mutexclpotype : [];
  2259. mutexclpo : [po_exports,po_interrupt,po_inline]
  2260. ),(
  2261. idtok:_FORWARD;
  2262. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2263. handler : @pd_forward;
  2264. pocall : pocall_none;
  2265. pooption : [];
  2266. mutexclpocall : [pocall_internproc];
  2267. mutexclpotype : [];
  2268. mutexclpo : [po_external,po_inline]
  2269. ),(
  2270. idtok:_OLDFPCCALL;
  2271. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2272. handler : nil;
  2273. pocall : pocall_oldfpccall;
  2274. pooption : [];
  2275. mutexclpocall : [];
  2276. mutexclpotype : [];
  2277. mutexclpo : []
  2278. ),(
  2279. idtok:_INLINE;
  2280. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2281. handler : nil;
  2282. pocall : pocall_none;
  2283. pooption : [po_inline];
  2284. mutexclpocall : [pocall_safecall];
  2285. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2286. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_iocheck]
  2287. ),(
  2288. idtok:_INTERNCONST;
  2289. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2290. handler : @pd_internconst;
  2291. pocall : pocall_none;
  2292. pooption : [po_internconst];
  2293. mutexclpocall : [];
  2294. mutexclpotype : [potype_operator];
  2295. mutexclpo : []
  2296. ),(
  2297. idtok:_INTERNPROC;
  2298. pd_flags : [pd_interface,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2299. handler : @pd_internproc;
  2300. pocall : pocall_internproc;
  2301. pooption : [];
  2302. mutexclpocall : [];
  2303. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2304. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  2305. ),(
  2306. idtok:_INTERRUPT;
  2307. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2308. handler : @pd_interrupt;
  2309. pocall : pocall_oldfpccall;
  2310. pooption : [po_interrupt];
  2311. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,pocall_mwpascal,
  2312. pocall_pascal,pocall_far16,pocall_oldfpccall];
  2313. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2314. mutexclpo : [po_external,po_inline,po_exports]
  2315. ),(
  2316. idtok:_IOCHECK;
  2317. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2318. handler : nil;
  2319. pocall : pocall_none;
  2320. pooption : [po_iocheck];
  2321. mutexclpocall : [pocall_internproc];
  2322. mutexclpotype : [];
  2323. mutexclpo : [po_external]
  2324. ),(
  2325. idtok:_LOCAL;
  2326. pd_flags : [pd_implemen,pd_body];
  2327. handler : nil;
  2328. pocall : pocall_none;
  2329. pooption : [po_kylixlocal];
  2330. mutexclpocall : [pocall_internproc,pocall_far16];
  2331. mutexclpotype : [];
  2332. mutexclpo : [po_external,po_exports]
  2333. ),(
  2334. idtok:_MESSAGE;
  2335. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_objcprot,pd_notrecord];
  2336. handler : @pd_message;
  2337. pocall : pocall_none;
  2338. pooption : []; { can be po_msgstr or po_msgint }
  2339. mutexclpocall : [pocall_internproc];
  2340. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2341. mutexclpo : [po_interrupt,po_inline]
  2342. ),(
  2343. idtok:_MWPASCAL;
  2344. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2345. handler : nil;
  2346. pocall : pocall_mwpascal;
  2347. pooption : [];
  2348. mutexclpocall : [];
  2349. mutexclpotype : [];
  2350. mutexclpo : []
  2351. ),(
  2352. idtok:_NEAR;
  2353. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf,pd_notrecord,pd_nothelper];
  2354. handler : @pd_near;
  2355. pocall : pocall_none;
  2356. pooption : [];
  2357. mutexclpocall : [pocall_internproc];
  2358. mutexclpotype : [];
  2359. mutexclpo : []
  2360. ),(
  2361. idtok:_NORETURN;
  2362. pd_flags : [pd_implemen,pd_interface,pd_body,pd_notobjintf];
  2363. handler : nil;
  2364. pocall : pocall_none;
  2365. pooption : [po_noreturn];
  2366. mutexclpocall : [];
  2367. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2368. mutexclpo : [po_interrupt,po_virtualmethod,po_iocheck]
  2369. ),(
  2370. idtok:_NOSTACKFRAME;
  2371. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  2372. handler : nil;
  2373. pocall : pocall_none;
  2374. pooption : [po_nostackframe];
  2375. mutexclpocall : [pocall_internproc];
  2376. mutexclpotype : [];
  2377. mutexclpo : []
  2378. ),(
  2379. idtok:_OVERLOAD;
  2380. pd_flags : [pd_implemen,pd_interface,pd_body,pd_javaclass,pd_intfjava,pd_objcclass,pd_objcprot];
  2381. handler : @pd_overload;
  2382. pocall : pocall_none;
  2383. pooption : [po_overload];
  2384. mutexclpocall : [pocall_internproc];
  2385. mutexclpotype : [];
  2386. mutexclpo : []
  2387. ),(
  2388. idtok:_OVERRIDE;
  2389. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_javaclass,pd_intfjava,pd_notrecord];
  2390. handler : @pd_override;
  2391. pocall : pocall_none;
  2392. pooption : [po_overridingmethod,po_virtualmethod];
  2393. mutexclpocall : [pocall_internproc];
  2394. mutexclpotype : [];
  2395. mutexclpo : [po_exports,po_interrupt,po_virtualmethod,po_inline]
  2396. ),(
  2397. idtok:_PASCAL;
  2398. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2399. handler : nil;
  2400. pocall : pocall_pascal;
  2401. pooption : [];
  2402. mutexclpocall : [];
  2403. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2404. mutexclpo : [po_external]
  2405. ),(
  2406. idtok:_PUBLIC;
  2407. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2408. handler : @pd_public;
  2409. pocall : pocall_none;
  2410. pooption : [po_public,po_global];
  2411. mutexclpocall : [pocall_internproc];
  2412. mutexclpotype : [];
  2413. mutexclpo : [po_external,po_inline]
  2414. ),(
  2415. idtok:_REGISTER;
  2416. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2417. handler : nil;
  2418. pocall : pocall_register;
  2419. pooption : [];
  2420. mutexclpocall : [];
  2421. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2422. mutexclpo : [po_external]
  2423. ),(
  2424. idtok:_REINTRODUCE;
  2425. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_notrecord,pd_javaclass];
  2426. handler : @pd_reintroduce;
  2427. pocall : pocall_none;
  2428. pooption : [po_reintroduce];
  2429. mutexclpocall : [pocall_internproc];
  2430. mutexclpotype : [];
  2431. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  2432. ),(
  2433. idtok:_SAFECALL;
  2434. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2435. handler : nil;
  2436. pocall : pocall_safecall;
  2437. pooption : [];
  2438. mutexclpocall : [];
  2439. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2440. mutexclpo : [po_external]
  2441. ),(
  2442. idtok:_SOFTFLOAT;
  2443. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2444. handler : nil;
  2445. pocall : pocall_softfloat;
  2446. pooption : [];
  2447. mutexclpocall : [];
  2448. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2449. { it's available with po_external because the libgcc floating point routines on the arm
  2450. uses this calling convention }
  2451. mutexclpo : []
  2452. ),(
  2453. idtok:_STATIC;
  2454. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_record,pd_javaclass,pd_notobjintf];
  2455. handler : @pd_static;
  2456. pocall : pocall_none;
  2457. pooption : [po_staticmethod];
  2458. mutexclpocall : [pocall_internproc];
  2459. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2460. mutexclpo : [po_interrupt,po_exports]
  2461. ),(
  2462. idtok:_STDCALL;
  2463. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2464. handler : nil;
  2465. pocall : pocall_stdcall;
  2466. pooption : [];
  2467. mutexclpocall : [];
  2468. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2469. mutexclpo : [po_external]
  2470. ),(
  2471. idtok:_SYSCALL;
  2472. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  2473. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  2474. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  2475. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  2476. handler : @pd_syscall;
  2477. pocall : pocall_syscall;
  2478. pooption : [];
  2479. mutexclpocall : [];
  2480. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2481. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  2482. ),(
  2483. idtok:_VIRTUAL;
  2484. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2485. handler : @pd_virtual;
  2486. pocall : pocall_none;
  2487. pooption : [po_virtualmethod];
  2488. mutexclpocall : [pocall_internproc];
  2489. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2490. mutexclpo : [po_interrupt,po_exports,po_overridingmethod,po_inline]
  2491. ),(
  2492. idtok:_CPPDECL;
  2493. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2494. handler : nil;
  2495. pocall : pocall_cppdecl;
  2496. pooption : [];
  2497. mutexclpocall : [];
  2498. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2499. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  2500. ),(
  2501. idtok:_VARARGS;
  2502. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass,pd_objcprot];
  2503. handler : nil;
  2504. pocall : pocall_none;
  2505. pooption : [po_varargs];
  2506. mutexclpocall : [pocall_internproc,pocall_register,
  2507. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  2508. mutexclpotype : [];
  2509. mutexclpo : [po_assembler,po_interrupt,po_inline]
  2510. ),(
  2511. idtok:_COMPILERPROC;
  2512. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2513. handler : @pd_compilerproc;
  2514. pocall : pocall_none;
  2515. pooption : [po_compilerproc];
  2516. mutexclpocall : [];
  2517. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2518. mutexclpo : [po_interrupt]
  2519. ),(
  2520. idtok:_WEAKEXTERNAL;
  2521. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper];
  2522. handler : @pd_weakexternal;
  2523. pocall : pocall_none;
  2524. { mark it both external and weak external, so we don't have to
  2525. adapt all code for external symbols to also check for weak external
  2526. }
  2527. pooption : [po_external,po_weakexternal];
  2528. mutexclpocall : [pocall_internproc,pocall_syscall];
  2529. { allowed for external cpp classes }
  2530. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2531. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2532. ),(
  2533. idtok:_WINAPI;
  2534. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2535. handler : @pd_winapi;
  2536. pocall : pocall_none;
  2537. pooption : [];
  2538. mutexclpocall : [pocall_stdcall,pocall_cdecl];
  2539. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2540. mutexclpo : [po_external]
  2541. ),(
  2542. idtok:_ENUMERATOR;
  2543. pd_flags : [pd_interface,pd_object,pd_record];
  2544. handler : @pd_enumerator;
  2545. pocall : pocall_none;
  2546. pooption : [];
  2547. mutexclpocall : [pocall_internproc];
  2548. mutexclpotype : [];
  2549. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2550. ),(
  2551. idtok:_RTLPROC;
  2552. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2553. handler : nil;
  2554. pocall : pocall_none;
  2555. pooption : [po_rtlproc];
  2556. mutexclpocall : [];
  2557. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2558. mutexclpo : [po_interrupt]
  2559. ),(
  2560. idtok:_HARDFLOAT;
  2561. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2562. handler : @pd_hardfloat;
  2563. pocall : pocall_hardfloat;
  2564. pooption : [];
  2565. mutexclpocall : [];
  2566. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2567. { it's available with po_external because the libgcc floating point routines on the arm
  2568. uses this calling convention }
  2569. mutexclpo : []
  2570. )
  2571. );
  2572. function check_proc_directive(isprocvar:boolean):boolean;
  2573. var
  2574. i : longint;
  2575. begin
  2576. result:=false;
  2577. for i:=1 to num_proc_directives do
  2578. if proc_direcdata[i].idtok=idtoken then
  2579. begin
  2580. if ((not isprocvar) or
  2581. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2582. { don't eat a public directive in classes }
  2583. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2584. result:=true;
  2585. exit;
  2586. end;
  2587. end;
  2588. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2589. {
  2590. Parse the procedure directive, returns true if a correct directive is found
  2591. }
  2592. var
  2593. p : longint;
  2594. found : boolean;
  2595. name : TIDString;
  2596. begin
  2597. parse_proc_direc:=false;
  2598. name:=tokeninfo^[idtoken].str;
  2599. found:=false;
  2600. { Hint directive? Then exit immediatly }
  2601. if (m_hintdirective in current_settings.modeswitches) then
  2602. begin
  2603. case idtoken of
  2604. _LIBRARY,
  2605. _PLATFORM,
  2606. _UNIMPLEMENTED,
  2607. _EXPERIMENTAL,
  2608. _DEPRECATED :
  2609. if (m_delphi in current_settings.modeswitches) and (pd.typ=procdef) then
  2610. begin
  2611. maybe_parse_hint_directives(tprocdef(pd));
  2612. { could the new token still be a directive? }
  2613. if token<>_ID then
  2614. exit;
  2615. name:=tokeninfo^[idtoken].str;
  2616. end
  2617. else
  2618. exit;
  2619. end;
  2620. end;
  2621. { C directive is MacPas only, because it breaks too much existing code
  2622. on other platforms (PFV) }
  2623. if (idtoken=_C) and
  2624. not(m_mac in current_settings.modeswitches) then
  2625. exit;
  2626. { retrieve data for directive if found }
  2627. for p:=1 to num_proc_directives do
  2628. if proc_direcdata[p].idtok=idtoken then
  2629. begin
  2630. found:=true;
  2631. break;
  2632. end;
  2633. { Check if the procedure directive is known }
  2634. if not found then
  2635. begin
  2636. { parsing a procvar type the name can be any
  2637. next variable !! }
  2638. if ((pdflags * [pd_procvar,pd_object,pd_record,pd_objcclass,pd_objcprot])=[]) and
  2639. not(idtoken in [_PROPERTY,_GENERIC]) then
  2640. Message1(parser_w_unknown_proc_directive_ignored,pattern);
  2641. exit;
  2642. end;
  2643. { check if method and directive not for object, like public.
  2644. This needs to be checked also for procvars }
  2645. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2646. (symtablestack.top.symtabletype=ObjectSymtable) and
  2647. { directive allowed for cpp classes? }
  2648. not((pd_cppobject in proc_direcdata[p].pd_flags) and is_cppclass(tdef(symtablestack.top.defowner))) and
  2649. not((pd_javaclass in proc_direcdata[p].pd_flags) and is_javaclass(tdef(symtablestack.top.defowner))) and
  2650. not((pd_intfjava in proc_direcdata[p].pd_flags) and is_javainterface(tdef(symtablestack.top.defowner))) then
  2651. exit;
  2652. if (pd_notrecord in proc_direcdata[p].pd_flags) and
  2653. (symtablestack.top.symtabletype=recordsymtable) then
  2654. exit;
  2655. { check if method and directive not for java class }
  2656. if not(pd_javaclass in proc_direcdata[p].pd_flags) and
  2657. is_javaclass(tdef(symtablestack.top.defowner)) then
  2658. exit;
  2659. { check if method and directive not for java interface }
  2660. if not(pd_intfjava in proc_direcdata[p].pd_flags) and
  2661. is_javainterface(tdef(symtablestack.top.defowner)) then
  2662. exit;
  2663. { Conflicts between directives ? }
  2664. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  2665. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  2666. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  2667. begin
  2668. Message1(parser_e_proc_dir_conflict,name);
  2669. exit;
  2670. end;
  2671. { set calling convention }
  2672. if proc_direcdata[p].pocall<>pocall_none then
  2673. begin
  2674. if (po_hascallingconvention in pd.procoptions) then
  2675. begin
  2676. Message2(parser_w_proc_overriding_calling,
  2677. proccalloptionStr[pd.proccalloption],
  2678. proccalloptionStr[proc_direcdata[p].pocall]);
  2679. end;
  2680. { check if the target processor supports this calling convention }
  2681. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2682. begin
  2683. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2684. { recover }
  2685. proc_direcdata[p].pocall:=pocall_stdcall;
  2686. end;
  2687. pd.proccalloption:=proc_direcdata[p].pocall;
  2688. include(pd.procoptions,po_hascallingconvention);
  2689. end;
  2690. if pd.typ=procdef then
  2691. begin
  2692. { Check if the directive is only for objects }
  2693. if (pd_object in proc_direcdata[p].pd_flags) and
  2694. not assigned(tprocdef(pd).struct) then
  2695. exit;
  2696. { Check if the directive is only for records }
  2697. if (pd_record in proc_direcdata[p].pd_flags) and
  2698. not assigned(tprocdef(pd).struct) then
  2699. exit;
  2700. { check if method and directive not for interface }
  2701. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2702. is_interface(tprocdef(pd).struct) then
  2703. exit;
  2704. { check if method and directive not for interface }
  2705. if is_dispinterface(tprocdef(pd).struct) and
  2706. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2707. exit;
  2708. { check if method and directive not for objcclass }
  2709. if is_objcclass(tprocdef(pd).struct) and
  2710. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2711. exit;
  2712. { check if method and directive not for objcprotocol }
  2713. if is_objcprotocol(tprocdef(pd).struct) and
  2714. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2715. exit;
  2716. { check if method and directive not for record/class helper }
  2717. if is_objectpascal_helper(tprocdef(pd).struct) and
  2718. (pd_nothelper in proc_direcdata[p].pd_flags) then
  2719. end;
  2720. { consume directive, and turn flag on }
  2721. consume(token);
  2722. parse_proc_direc:=true;
  2723. { Check the pd_flags if the directive should be allowed }
  2724. if (pd_interface in pdflags) and
  2725. not(pd_interface in proc_direcdata[p].pd_flags) then
  2726. begin
  2727. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  2728. exit;
  2729. end;
  2730. if (pd_implemen in pdflags) and
  2731. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2732. begin
  2733. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  2734. exit;
  2735. end;
  2736. if (pd_procvar in pdflags) and
  2737. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2738. begin
  2739. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  2740. exit;
  2741. end;
  2742. { Return the new pd_flags }
  2743. if not(pd_body in proc_direcdata[p].pd_flags) then
  2744. exclude(pdflags,pd_body);
  2745. { Add the correct flag }
  2746. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2747. { Call the handler }
  2748. if pointer(proc_direcdata[p].handler)<>nil then
  2749. proc_direcdata[p].handler(pd);
  2750. end;
  2751. function proc_get_importname(pd:tprocdef):string;
  2752. var
  2753. dllname, importname : string;
  2754. begin
  2755. result:='';
  2756. if not(po_external in pd.procoptions) then
  2757. internalerror(200412151);
  2758. { external name or number is specified }
  2759. if assigned(pd.import_name) or (pd.import_nr<>0) then
  2760. begin
  2761. if assigned(pd.import_dll) then
  2762. dllname:=pd.import_dll^
  2763. else
  2764. dllname:='';
  2765. if assigned(pd.import_name) then
  2766. importname:=pd.import_name^
  2767. else
  2768. importname:='';
  2769. proc_get_importname:=make_dllmangledname(dllname,
  2770. importname,pd.import_nr,pd.proccalloption);
  2771. end
  2772. else
  2773. begin
  2774. { Default names when importing variables }
  2775. case pd.proccalloption of
  2776. pocall_cdecl :
  2777. begin
  2778. if assigned(pd.struct) then
  2779. result:=target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname
  2780. else
  2781. result:=target_info.Cprefix+pd.procsym.realname;
  2782. end;
  2783. pocall_cppdecl :
  2784. begin
  2785. result:=target_info.Cprefix+pd.cplusplusmangledname;
  2786. end;
  2787. else
  2788. begin
  2789. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  2790. { but according to MacPas mode description
  2791. Cprefix should still be used PM }
  2792. if (m_mac in current_settings.modeswitches) then
  2793. result:=target_info.Cprefix+tprocdef(pd).procsym.realname
  2794. else
  2795. result:=pd.procsym.realname;
  2796. end;
  2797. end;
  2798. end;
  2799. end;
  2800. procedure compilerproc_set_symbol_name(pd: tprocdef);
  2801. begin
  2802. pd.procsym.realname:='$'+lower(pd.procsym.name);
  2803. end;
  2804. procedure proc_set_mangledname(pd:tprocdef);
  2805. var
  2806. s : string;
  2807. begin
  2808. { When the mangledname is already set we aren't allowed to change
  2809. it because it can already be used somewhere (PFV) }
  2810. if not(po_has_mangledname in pd.procoptions) then
  2811. begin
  2812. if (po_external in pd.procoptions) then
  2813. begin
  2814. { External Procedures are only allowed to change the mangledname
  2815. in their first declaration }
  2816. if (pd.forwarddef or (not pd.hasforward)) then
  2817. begin
  2818. s:=proc_get_importname(pd);
  2819. if s<>'' then
  2820. begin
  2821. pd.setmangledname(s);
  2822. end;
  2823. { since this is an external declaration, there won't be an
  2824. implementation that needs to match the original symbol
  2825. again -> immediately convert here }
  2826. if po_compilerproc in pd.procoptions then
  2827. compilerproc_set_symbol_name(pd);
  2828. end
  2829. end
  2830. else
  2831. { Normal procedures }
  2832. begin
  2833. if (po_compilerproc in pd.procoptions) then
  2834. begin
  2835. pd.setmangledname(lower(pd.procsym.name));
  2836. end;
  2837. end;
  2838. end;
  2839. { Public/exported alias names }
  2840. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  2841. not(po_has_public_name in pd.procoptions) then
  2842. begin
  2843. case pd.proccalloption of
  2844. pocall_cdecl :
  2845. begin
  2846. if assigned(pd.struct) then
  2847. pd.aliasnames.insert(target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname)
  2848. else
  2849. begin
  2850. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  2851. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  2852. (po_exports in pd.procoptions) then
  2853. pd.aliasnames.insert(pd.procsym.realname)
  2854. else
  2855. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  2856. end;
  2857. end;
  2858. pocall_cppdecl :
  2859. begin
  2860. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  2861. end;
  2862. end;
  2863. { prevent adding the alias a second time }
  2864. include(pd.procoptions,po_has_public_name);
  2865. end;
  2866. end;
  2867. procedure handle_calling_convention(pd:tabstractprocdef;flags:thccflags=hcc_all);
  2868. begin
  2869. if hcc_check in flags then
  2870. begin
  2871. { set the default calling convention if none provided }
  2872. if (pd.typ=procdef) and
  2873. (is_objc_class_or_protocol(tprocdef(pd).struct) or
  2874. is_cppclass(tprocdef(pd).struct)) then
  2875. begin
  2876. { none of the explicit calling conventions should be allowed }
  2877. if (po_hascallingconvention in pd.procoptions) then
  2878. internalerror(2009032501);
  2879. if is_cppclass(tprocdef(pd).struct) then
  2880. pd.proccalloption:=pocall_cppdecl
  2881. else
  2882. pd.proccalloption:=pocall_cdecl;
  2883. end
  2884. else if not(po_hascallingconvention in pd.procoptions) then
  2885. pd.proccalloption:=current_settings.defproccall
  2886. else
  2887. begin
  2888. if pd.proccalloption=pocall_none then
  2889. internalerror(200309081);
  2890. end;
  2891. { handle proccall specific settings }
  2892. case pd.proccalloption of
  2893. pocall_cdecl,
  2894. pocall_cppdecl :
  2895. begin
  2896. { check C cdecl para types }
  2897. check_c_para(pd);
  2898. end;
  2899. pocall_far16 :
  2900. begin
  2901. { Temporary stub, must be rewritten to support OS/2 far16 }
  2902. Message1(parser_w_proc_directive_ignored,'FAR16');
  2903. end;
  2904. end;
  2905. { Inlining is enabled and supported? }
  2906. if (po_inline in pd.procoptions) and
  2907. not(cs_do_inline in current_settings.localswitches) then
  2908. begin
  2909. { Give an error if inline is not supported by the compiler mode,
  2910. otherwise only give a hint that this procedure will not be inlined }
  2911. if not(m_default_inline in current_settings.modeswitches) then
  2912. Message(parser_e_proc_inline_not_supported)
  2913. else
  2914. Message(parser_h_inlining_disabled);
  2915. exclude(pd.procoptions,po_inline);
  2916. end;
  2917. { For varargs directive also cdecl and external must be defined }
  2918. if (po_varargs in pd.procoptions) then
  2919. begin
  2920. { check first for external in the interface, if available there
  2921. then the cdecl must also be there since there is no implementation
  2922. available to contain it }
  2923. if parse_only then
  2924. begin
  2925. { if external is available, then cdecl must also be available,
  2926. procvars don't need external }
  2927. if not((po_external in pd.procoptions) or
  2928. (pd.typ=procvardef) or
  2929. { for objcclasses this is checked later, because the entire
  2930. class may be external. }
  2931. is_objc_class_or_protocol(tprocdef(pd).struct)) and
  2932. not(pd.proccalloption in (cdecl_pocalls + [pocall_mwpascal,pocall_stdcall])) then
  2933. Message(parser_e_varargs_need_cdecl_and_external);
  2934. end
  2935. else
  2936. begin
  2937. { both must be defined now }
  2938. if not((po_external in pd.procoptions) or
  2939. (pd.typ=procvardef)) or
  2940. not(pd.proccalloption in (cdecl_pocalls + [pocall_mwpascal,pocall_stdcall])) then
  2941. Message(parser_e_varargs_need_cdecl_and_external);
  2942. end;
  2943. end;
  2944. end;
  2945. if hcc_insert_hidden_paras in flags then
  2946. begin
  2947. { insert hidden high parameters }
  2948. pd.parast.SymList.ForEachCall(@insert_hidden_para,pd);
  2949. { insert hidden self parameter }
  2950. insert_self_and_vmt_para(pd);
  2951. { insert funcret parameter if required }
  2952. insert_funcret_para(pd);
  2953. { Make var parameters regable, this must be done after the calling
  2954. convention is set. }
  2955. { this must be done before parentfp is insert, because getting all cases
  2956. where parentfp must be in a memory location isn't catched properly so
  2957. we put parentfp never in a register }
  2958. pd.parast.SymList.ForEachCall(@set_addr_param_regable,pd);
  2959. { insert parentfp parameter if required }
  2960. insert_parentfp_para(pd);
  2961. end;
  2962. { Calculate parameter tlist }
  2963. pd.calcparas;
  2964. end;
  2965. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2966. {
  2967. Parse the procedure directives. It does not matter if procedure directives
  2968. are written using ;procdir; or ['procdir'] syntax.
  2969. }
  2970. var
  2971. stoprecording,
  2972. res : boolean;
  2973. begin
  2974. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  2975. begin
  2976. tprocdef(pd).aliasnames.insert(target_info.Cprefix+tprocdef(pd).procsym.realname);
  2977. include(pd.procoptions,po_public);
  2978. include(pd.procoptions,po_has_public_name);
  2979. include(pd.procoptions,po_global);
  2980. end;
  2981. { methods from external class definitions are all external themselves }
  2982. if (pd.typ=procdef) and
  2983. assigned(tprocdef(pd).struct) and
  2984. (tprocdef(pd).struct.typ=objectdef) and
  2985. (oo_is_external in tobjectdef(tprocdef(pd).struct).objectoptions) then
  2986. tprocdef(pd).make_external;
  2987. { Class constructors and destructor are static class methods in real. }
  2988. { There are many places in the compiler where either class or static }
  2989. { method flag changes the behavior. It is simplier to add them to }
  2990. { the class constructors/destructors options than to fix all the }
  2991. { occurencies. (Paul) }
  2992. if pd.proctypeoption in [potype_class_constructor,potype_class_destructor] then
  2993. begin
  2994. include(pd.procoptions,po_classmethod);
  2995. include(pd.procoptions,po_staticmethod);
  2996. end;
  2997. { for a generic routine we also need to record the procedure }
  2998. { directives, but only if we aren't already recording for a }
  2999. { surrounding generic }
  3000. if pd.is_generic and (pd.typ=procdef) and not current_scanner.is_recording_tokens then
  3001. begin
  3002. current_scanner.startrecordtokens(tprocdef(pd).genericdecltokenbuf);
  3003. stoprecording:=true;
  3004. end
  3005. else
  3006. stoprecording:=false;
  3007. while token in [_ID,_LECKKLAMMER] do
  3008. begin
  3009. if try_to_consume(_LECKKLAMMER) then
  3010. begin
  3011. repeat
  3012. parse_proc_direc(pd,pdflags);
  3013. until not try_to_consume(_COMMA);
  3014. consume(_RECKKLAMMER);
  3015. { we always expect at least '[];' }
  3016. res:=true;
  3017. end
  3018. else
  3019. begin
  3020. res:=parse_proc_direc(pd,pdflags);
  3021. end;
  3022. { A procedure directive normally followed by a semicolon, but in
  3023. a const section or reading a type we should stop when _EQ is found,
  3024. because a constant/default value follows }
  3025. if res then
  3026. begin
  3027. if (block_type=bt_const_type) and
  3028. (token=_EQ) then
  3029. break;
  3030. { support procedure proc;stdcall export; }
  3031. if not(check_proc_directive((pd.typ=procvardef))) then
  3032. begin
  3033. { support "record p : procedure stdcall end;" and
  3034. "var p : procedure stdcall = nil;" }
  3035. if (pd_procvar in pdflags) and
  3036. (token in [_END,_RKLAMMER,_EQ]) then
  3037. break
  3038. else
  3039. begin
  3040. if (token=_COLON) then
  3041. begin
  3042. Message(parser_e_field_not_allowed_here);
  3043. consume_all_until(_SEMICOLON);
  3044. end;
  3045. consume(_SEMICOLON)
  3046. end;
  3047. end;
  3048. end
  3049. else
  3050. break;
  3051. end;
  3052. if stoprecording then
  3053. current_scanner.stoprecordtokens;
  3054. { nostackframe requires assembler, but assembler
  3055. may be specified in the implementation part only,
  3056. and in not required if the function is first forward declared
  3057. if it is a procdef that has forwardef set to true
  3058. we postpone the possible error message to the real implementation
  3059. parse_only does not need to be considered as po_nostackframe
  3060. is an implementation only directive }
  3061. if (po_nostackframe in pd.procoptions) and
  3062. not (po_assembler in pd.procoptions) and
  3063. ((pd.typ<>procdef) or not tprocdef(pd).forwarddef) then
  3064. message(parser_e_nostackframe_without_assembler);
  3065. end;
  3066. procedure parse_var_proc_directives(sym:tsym);
  3067. var
  3068. pdflags : tpdflags;
  3069. pd : tabstractprocdef;
  3070. begin
  3071. pdflags:=[pd_procvar];
  3072. pd:=nil;
  3073. case sym.typ of
  3074. fieldvarsym,
  3075. staticvarsym,
  3076. localvarsym,
  3077. paravarsym :
  3078. pd:=tabstractprocdef(tabstractvarsym(sym).vardef);
  3079. typesym :
  3080. pd:=tabstractprocdef(ttypesym(sym).typedef);
  3081. else
  3082. internalerror(2003042617);
  3083. end;
  3084. if pd.typ<>procvardef then
  3085. internalerror(2003042618);
  3086. { names should never be used anyway }
  3087. parse_proc_directives(pd,pdflags);
  3088. end;
  3089. procedure parse_object_proc_directives(pd:tabstractprocdef);
  3090. var
  3091. pdflags : tpdflags;
  3092. begin
  3093. pdflags:=[pd_object];
  3094. parse_proc_directives(pd,pdflags);
  3095. end;
  3096. procedure parse_record_proc_directives(pd:tabstractprocdef);
  3097. var
  3098. pdflags : tpdflags;
  3099. begin
  3100. pdflags:=[pd_record];
  3101. parse_proc_directives(pd,pdflags);
  3102. end;
  3103. function proc_add_definition(var currpd:tprocdef):boolean;
  3104. function equal_generic_procdefs(fwpd,currpd:tprocdef):boolean;
  3105. var
  3106. i : longint;
  3107. fwtype,
  3108. currtype : ttypesym;
  3109. foundretdef : boolean;
  3110. begin
  3111. result:=false;
  3112. if fwpd.genericparas.count<>currpd.genericparas.count then
  3113. exit;
  3114. { comparing generic declarations is a bit more cumbersome as the
  3115. defs of the generic parameter types are not equal, especially if the
  3116. declaration contains constraints; essentially we have two cases:
  3117. - proc declared in interface of unit (or in class/record/object)
  3118. and defined in implementation; here the fwpd might contain
  3119. constraints while currpd must only contain undefineddefs
  3120. - forward declaration in implementation; this case is not supported
  3121. right now }
  3122. foundretdef:=false;
  3123. for i:=0 to fwpd.genericparas.count-1 do
  3124. begin
  3125. fwtype:=ttypesym(fwpd.genericparas[i]);
  3126. currtype:=ttypesym(currpd.genericparas[i]);
  3127. { if the type in the currpd isn't a pure undefineddef, then we can
  3128. stop right there }
  3129. if (currtype.typedef.typ<>undefineddef) or (df_genconstraint in currtype.typedef.defoptions) then
  3130. exit;
  3131. if not foundretdef then
  3132. begin
  3133. { if the returndef is the same as this parameter's def then this
  3134. needs to be the case for both procdefs }
  3135. foundretdef:=fwpd.returndef=fwtype.typedef;
  3136. if foundretdef xor (currpd.returndef=currtype.typedef) then
  3137. exit;
  3138. end;
  3139. end;
  3140. if compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv,cpo_generic])<>te_exact then
  3141. exit;
  3142. if not foundretdef then
  3143. begin
  3144. if tstoreddef(fwpd.returndef).is_specialization and tstoreddef(currpd.returndef).is_specialization then
  3145. { for specializations we're happy with equal defs instead of exactly the same defs }
  3146. result:=equal_defs(fwpd.returndef,currpd.returndef)
  3147. else
  3148. { the returndef isn't a type parameter, so compare as usual }
  3149. result:=compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact;
  3150. end
  3151. else
  3152. result:=true;
  3153. end;
  3154. {
  3155. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  3156. forwarddef is found and reused it returns true
  3157. }
  3158. var
  3159. fwpd : tprocdef;
  3160. currparasym,
  3161. fwparasym : tsym;
  3162. currparacnt,
  3163. fwparacnt,
  3164. curridx,
  3165. fwidx,
  3166. i : longint;
  3167. po_comp : tprocoptions;
  3168. paracompopt: tcompare_paras_options;
  3169. forwardfound : boolean;
  3170. symentry: TSymEntry;
  3171. item : tlinkedlistitem;
  3172. begin
  3173. forwardfound:=false;
  3174. { check overloaded functions if the same function already exists }
  3175. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  3176. begin
  3177. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  3178. { can happen for internally generated routines }
  3179. if (fwpd=currpd) then
  3180. begin
  3181. result:=true;
  3182. exit;
  3183. end;
  3184. { Skip overloaded definitions that are declared in other units }
  3185. if fwpd.procsym<>currpd.procsym then
  3186. continue;
  3187. { check the parameters, for delphi/tp it is possible to
  3188. leave the parameters away in the implementation (forwarddef=false).
  3189. But for an overload declared function this is not allowed }
  3190. if { check if empty implementation arguments match is allowed }
  3191. (
  3192. not(m_repeat_forward in current_settings.modeswitches) and
  3193. not(currpd.forwarddef) and
  3194. is_bareprocdef(currpd) and
  3195. not(po_overload in fwpd.procoptions)
  3196. ) or
  3197. (
  3198. fwpd.is_generic and
  3199. currpd.is_generic and
  3200. equal_generic_procdefs(fwpd,currpd)
  3201. ) or
  3202. { check arguments, we need to check only the user visible parameters. The hidden parameters
  3203. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV)
  3204. don't check default values here, because routines that are the same except for their default
  3205. values should be reported as mismatches (since you can't overload based on different default
  3206. parameter values) }
  3207. (
  3208. (compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact) and
  3209. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact)
  3210. ) then
  3211. begin
  3212. { Check if we've found the forwarddef, if found then
  3213. we need to update the forward def with the current
  3214. implementation settings }
  3215. if fwpd.forwarddef then
  3216. begin
  3217. forwardfound:=true;
  3218. if not(m_repeat_forward in current_settings.modeswitches) and
  3219. (fwpd.proccalloption<>currpd.proccalloption) then
  3220. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv]
  3221. else
  3222. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv];
  3223. { Check calling convention }
  3224. if (fwpd.proccalloption<>currpd.proccalloption) then
  3225. begin
  3226. { In delphi it is possible to specify the calling
  3227. convention in the interface or implementation if
  3228. there was no convention specified in the other
  3229. part }
  3230. if (m_delphi in current_settings.modeswitches) then
  3231. begin
  3232. if not(po_hascallingconvention in currpd.procoptions) then
  3233. currpd.proccalloption:=fwpd.proccalloption
  3234. else
  3235. if not(po_hascallingconvention in fwpd.procoptions) then
  3236. fwpd.proccalloption:=currpd.proccalloption
  3237. else
  3238. begin
  3239. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  3240. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3241. { restore interface settings }
  3242. currpd.proccalloption:=fwpd.proccalloption;
  3243. end;
  3244. end
  3245. else
  3246. begin
  3247. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  3248. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3249. { restore interface settings }
  3250. currpd.proccalloption:=fwpd.proccalloption;
  3251. end;
  3252. end;
  3253. { Check static }
  3254. if (po_staticmethod in fwpd.procoptions) then
  3255. begin
  3256. if not (po_staticmethod in currpd.procoptions) then
  3257. begin
  3258. include(currpd.procoptions, po_staticmethod);
  3259. if (po_classmethod in currpd.procoptions) then
  3260. begin
  3261. { remove self from the hidden paras }
  3262. symentry:=currpd.parast.Find('self');
  3263. if symentry<>nil then
  3264. begin
  3265. currpd.parast.Delete(symentry);
  3266. currpd.calcparas;
  3267. end;
  3268. end;
  3269. end;
  3270. end;
  3271. { Check if the procedure type and return type are correct,
  3272. also the parameters must match also with the type and that
  3273. if the implementation has default parameters, the interface
  3274. also has them and that if they both have them, that they
  3275. have the same value }
  3276. if ((m_repeat_forward in current_settings.modeswitches) or
  3277. not is_bareprocdef(currpd)) and
  3278. (
  3279. (
  3280. fwpd.is_generic and
  3281. currpd.is_generic and
  3282. not equal_generic_procdefs(fwpd,currpd)
  3283. ) or
  3284. (
  3285. (
  3286. not fwpd.is_generic or
  3287. not currpd.is_generic
  3288. ) and
  3289. (
  3290. (compare_paras(fwpd.paras,currpd.paras,cp_all,paracompopt)<>te_exact) or
  3291. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)<>te_exact)
  3292. )
  3293. )
  3294. ) then
  3295. begin
  3296. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3297. fwpd.fullprocname(false));
  3298. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3299. break;
  3300. end;
  3301. { Check if both are declared forward }
  3302. if fwpd.forwarddef and currpd.forwarddef then
  3303. begin
  3304. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  3305. currpd.fullprocname(false));
  3306. end;
  3307. { internconst or internproc only need to be defined once }
  3308. if (fwpd.proccalloption=pocall_internproc) then
  3309. currpd.proccalloption:=fwpd.proccalloption
  3310. else
  3311. if (currpd.proccalloption=pocall_internproc) then
  3312. fwpd.proccalloption:=currpd.proccalloption;
  3313. { Check procedure options, Delphi requires that class is
  3314. repeated in the implementation for class methods }
  3315. if (m_fpc in current_settings.modeswitches) then
  3316. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  3317. else
  3318. po_comp:=[po_classmethod,po_methodpointer];
  3319. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  3320. (fwpd.proctypeoption <> currpd.proctypeoption) or
  3321. { if the implementation version has an "overload" modifier,
  3322. the interface version must also have it (otherwise we can
  3323. get annoying crashes due to interface crc changes) }
  3324. (not(po_overload in fwpd.procoptions) and
  3325. (po_overload in currpd.procoptions)) then
  3326. begin
  3327. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3328. fwpd.fullprocname(false));
  3329. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  3330. { This error is non-fatal, we can recover }
  3331. end;
  3332. { Forward declaration is external? }
  3333. if (po_external in fwpd.procoptions) then
  3334. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  3335. { Check parameters }
  3336. if (m_repeat_forward in current_settings.modeswitches) or
  3337. (currpd.minparacount>0) then
  3338. begin
  3339. { If mangled names are equal then they have the same amount of arguments }
  3340. { We can check the names of the arguments }
  3341. { both symtables are in the same order from left to right }
  3342. curridx:=0;
  3343. fwidx:=0;
  3344. currparacnt:=currpd.parast.SymList.Count;
  3345. fwparacnt:=fwpd.parast.SymList.Count;
  3346. repeat
  3347. { skip default parameter constsyms }
  3348. while (curridx<currparacnt) and
  3349. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  3350. inc(curridx);
  3351. while (fwidx<fwparacnt) and
  3352. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  3353. inc(fwidx);
  3354. { stop when one of the two lists is at the end }
  3355. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  3356. break;
  3357. { compare names of parameters, ignore implictly
  3358. renamed parameters }
  3359. currparasym:=tsym(currpd.parast.SymList[curridx]);
  3360. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  3361. if not(sp_implicitrename in currparasym.symoptions) and
  3362. not(sp_implicitrename in fwparasym.symoptions) then
  3363. begin
  3364. if (currparasym.name<>fwparasym.name) then
  3365. begin
  3366. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  3367. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  3368. break;
  3369. end;
  3370. end;
  3371. { next parameter }
  3372. inc(curridx);
  3373. inc(fwidx);
  3374. until false;
  3375. end;
  3376. { Everything is checked, now we can update the forward declaration
  3377. with the new data from the implementation }
  3378. fwpd.forwarddef:=currpd.forwarddef;
  3379. fwpd.hasforward:=true;
  3380. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  3381. { marked as local but exported from unit? }
  3382. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  3383. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  3384. if fwpd.extnumber=$ffff then
  3385. fwpd.extnumber:=currpd.extnumber;
  3386. while not currpd.aliasnames.empty do
  3387. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  3388. { update fileinfo so position references the implementation,
  3389. also update funcretsym if it is already generated }
  3390. fwpd.fileinfo:=currpd.fileinfo;
  3391. if assigned(fwpd.funcretsym) then
  3392. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  3393. if assigned(currpd.deprecatedmsg) then
  3394. begin
  3395. stringdispose(fwpd.deprecatedmsg);
  3396. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  3397. end;
  3398. { import names }
  3399. if assigned(currpd.import_dll) then
  3400. begin
  3401. stringdispose(fwpd.import_dll);
  3402. fwpd.import_dll:=stringdup(currpd.import_dll^);
  3403. end;
  3404. if assigned(currpd.import_name) then
  3405. begin
  3406. stringdispose(fwpd.import_name);
  3407. fwpd.import_name:=stringdup(currpd.import_name^);
  3408. end;
  3409. fwpd.import_nr:=currpd.import_nr;
  3410. { for compilerproc defines we need to rename and update the
  3411. symbolname to lowercase so users can' access it (can't do
  3412. it immediately, because then the implementation symbol
  3413. won't be matched) }
  3414. if po_compilerproc in fwpd.procoptions then
  3415. begin
  3416. compilerproc_set_symbol_name(fwpd);
  3417. current_module.add_public_asmsym(fwpd.procsym.realname,AB_GLOBAL,AT_FUNCTION);
  3418. end;
  3419. if po_public in fwpd.procoptions then
  3420. begin
  3421. item:=fwpd.aliasnames.first;
  3422. while assigned(item) do
  3423. begin
  3424. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  3425. item:=item.next;
  3426. end;
  3427. end;
  3428. { Release current procdef }
  3429. currpd.owner.deletedef(currpd);
  3430. currpd:=fwpd;
  3431. end
  3432. else
  3433. begin
  3434. { abstract methods aren't forward defined, but this }
  3435. { needs another error message }
  3436. if (po_abstractmethod in fwpd.procoptions) then
  3437. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  3438. else
  3439. begin
  3440. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  3441. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3442. end;
  3443. end;
  3444. { we found one proc with the same arguments, there are no others
  3445. so we can stop }
  3446. break;
  3447. end;
  3448. { check for allowing overload directive }
  3449. if not(m_fpc in current_settings.modeswitches) then
  3450. begin
  3451. { overload directive turns on overloading }
  3452. if ((po_overload in currpd.procoptions) or
  3453. (po_overload in fwpd.procoptions)) then
  3454. begin
  3455. { check if all procs have overloading, but not if the proc is a method or
  3456. already declared forward, then the check is already done }
  3457. if not(fwpd.hasforward or
  3458. assigned(currpd.struct) or
  3459. (currpd.forwarddef<>fwpd.forwarddef) or
  3460. ((po_overload in currpd.procoptions) and
  3461. (po_overload in fwpd.procoptions))) then
  3462. begin
  3463. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3464. break;
  3465. end
  3466. end
  3467. else
  3468. begin
  3469. if not(fwpd.forwarddef) then
  3470. begin
  3471. if (m_tp7 in current_settings.modeswitches) then
  3472. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  3473. else
  3474. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3475. break;
  3476. end;
  3477. end;
  3478. end; { equal arguments }
  3479. end;
  3480. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  3481. list }
  3482. if not forwardfound then
  3483. begin
  3484. { can happen in Delphi mode }
  3485. if (currpd.proctypeoption = potype_function) and
  3486. is_void(currpd.returndef) then
  3487. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  3488. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  3489. if not currpd.forwarddef and (po_public in currpd.procoptions) then
  3490. begin
  3491. item:=currpd.aliasnames.first;
  3492. while assigned(item) do
  3493. begin
  3494. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  3495. item:=item.next;
  3496. end;
  3497. end;
  3498. end;
  3499. proc_add_definition:=forwardfound;
  3500. end;
  3501. end.