pdecsub.pas 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738
  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_amiga,
  1905. system_powerpc_amiga:
  1906. include(pd.procoptions,get_default_syscall);
  1907. system_powerpc_morphos,
  1908. system_i386_aros,
  1909. system_x86_64_aros:
  1910. begin
  1911. syscall:=get_syscall_by_token(idtoken);
  1912. if assigned(syscall) then
  1913. begin
  1914. if target_info.system in syscall^.validon then
  1915. begin
  1916. consume(idtoken);
  1917. include(pd.procoptions,syscall^.procoption);
  1918. end
  1919. end
  1920. else
  1921. include(pd.procoptions,get_default_syscall);
  1922. end;
  1923. end;
  1924. end;
  1925. function po_syscall_to_varoptions: tvaroptions;
  1926. begin
  1927. result:=[vo_is_syscall_lib,vo_is_hidden_para];
  1928. if ([po_syscall_legacy,po_syscall_r12base,po_syscall_sysv,po_syscall_eaxbase] * tprocdef(pd).procoptions) <> [] then
  1929. include(result,vo_has_explicit_paraloc);
  1930. end;
  1931. function po_syscall_to_regname: string;
  1932. begin
  1933. if po_syscall_legacy in tprocdef(pd).procoptions then
  1934. result:='A6'
  1935. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1936. result:='R12'
  1937. { let sysv store the libbase in r12 as well, because we will
  1938. need the libbase anyway during the call generation }
  1939. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1940. result:='R12'
  1941. else if po_syscall_eaxbase in tprocdef(pd).procoptions then
  1942. begin
  1943. if target_info.system = system_i386_aros then
  1944. result:='EAX'
  1945. else if target_info.system = system_x86_64_aros then
  1946. result:='RAX'
  1947. else
  1948. internalerror(2016090201);
  1949. end
  1950. else
  1951. internalerror(2016090101);
  1952. end;
  1953. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1954. const
  1955. syscall_paranr: array[boolean] of aint =
  1956. ( paranr_syscall_lib_last, paranr_syscall_lib_first );
  1957. var
  1958. vs : tparavarsym;
  1959. sym : tsym;
  1960. symtable : TSymtable;
  1961. v: Tconstexprint;
  1962. vo: tvaroptions;
  1963. paranr: aint;
  1964. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1965. begin
  1966. if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
  1967. internalerror(2003042614);
  1968. tprocdef(pd).forwarddef:=false;
  1969. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1970. include_po_syscall;
  1971. if consume_sym(sym,symtable) then
  1972. if (sym.typ=staticvarsym) and
  1973. ((tabstractvarsym(sym).vardef.typ=pointerdef) or
  1974. is_32bitint(tabstractvarsym(sym).vardef)) then
  1975. begin
  1976. include(pd.procoptions,po_syscall_has_libsym);
  1977. tcpuprocdef(pd).libsym:=sym;
  1978. vo:=po_syscall_to_varoptions;
  1979. paranr:=syscall_paranr[po_syscall_basesysv in tprocdef(pd).procoptions];
  1980. vs:=cparavarsym.create('$syscalllib',paranr,vs_value,tabstractvarsym(sym).vardef,vo);
  1981. if vo_has_explicit_paraloc in vo then
  1982. paramanager.parseparaloc(vs,po_syscall_to_regname);
  1983. pd.parast.insert(vs);
  1984. end
  1985. else
  1986. Message(parser_e_32bitint_or_pointer_variable_expected);
  1987. paramanager.create_funcretloc_info(pd,calleeside);
  1988. paramanager.create_funcretloc_info(pd,callerside);
  1989. v:=get_intconst;
  1990. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1991. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(Tprocdef(pd).extnumber)),tostr(high(Tprocdef(pd).extnumber)))
  1992. else
  1993. if target_info.system in [system_i386_aros,system_x86_64_aros] then
  1994. Tprocdef(pd).extnumber:=v.uvalue * sizeof(pint)
  1995. else
  1996. Tprocdef(pd).extnumber:=v.uvalue;
  1997. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64)}
  1998. end;
  1999. procedure pd_external(pd:tabstractprocdef);
  2000. {
  2001. If import_dll=nil the procedure is assumed to be in another
  2002. object file. In that object file it should have the name to
  2003. which import_name is pointing to. Otherwise, the procedure is
  2004. assumed to be in the DLL to which import_dll is pointing to. In
  2005. that case either import_nr<>0 or import_name<>nil is true, so
  2006. the procedure is either imported by number or by name. (DM)
  2007. }
  2008. var
  2009. hs : string;
  2010. v:Tconstexprint;
  2011. is_java_external: boolean;
  2012. begin
  2013. if pd.typ<>procdef then
  2014. internalerror(2003042615);
  2015. { Allow specifying a separate external name for methods in external Java
  2016. because its identifier naming constraints are laxer than FPC's
  2017. (e.g., case sensitive).
  2018. Limitation: only allows specifying the symbol name and not the package name,
  2019. and only for external classes/interfaces }
  2020. is_java_external:=
  2021. (pd.typ=procdef) and
  2022. is_java_class_or_interface(tdef(pd.owner.defowner)) and
  2023. (oo_is_external in tobjectdef(pd.owner.defowner).objectoptions);
  2024. with tprocdef(pd) do
  2025. begin
  2026. forwarddef:=false;
  2027. { forbid local external procedures }
  2028. if parast.symtablelevel>normal_function_level then
  2029. Message(parser_e_no_local_proc_external);
  2030. { If the procedure should be imported from a DLL, a constant string follows.
  2031. This isn't really correct, an contant string expression follows
  2032. so we check if an semicolon follows, else a string constant have to
  2033. follow (FK) }
  2034. if not is_java_external and
  2035. not(token=_SEMICOLON) and not(idtoken=_NAME) then
  2036. begin
  2037. { Always add library prefix and suffix to create an uniform name }
  2038. hs:=get_stringconst;
  2039. if ExtractFileExt(hs)='' then
  2040. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  2041. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  2042. hs:=target_info.sharedlibprefix+hs;
  2043. { the JVM expects java/lang/Object rather than java.lang.Object }
  2044. if target_info.system in systems_jvm then
  2045. Replace(hs,'.','/');
  2046. import_dll:=stringdup(hs);
  2047. include(procoptions,po_has_importdll);
  2048. if (idtoken=_NAME) then
  2049. begin
  2050. consume(_NAME);
  2051. import_name:=stringdup(get_stringconst);
  2052. include(procoptions,po_has_importname);
  2053. if import_name^='' then
  2054. message(parser_e_empty_import_name);
  2055. end;
  2056. if (idtoken=_INDEX) then
  2057. begin
  2058. {After the word index follows the index number in the DLL.}
  2059. consume(_INDEX);
  2060. v:=get_intconst;
  2061. if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
  2062. message(parser_e_range_check_error)
  2063. else
  2064. import_nr:=longint(v.svalue);
  2065. end;
  2066. { default is to used the realname of the procedure }
  2067. if (import_nr=0) and not assigned(import_name) then
  2068. begin
  2069. import_name:=stringdup(procsym.realname);
  2070. include(procoptions,po_has_importname);
  2071. end;
  2072. end
  2073. else
  2074. begin
  2075. if (idtoken=_NAME) or
  2076. is_java_external then
  2077. begin
  2078. consume(_NAME);
  2079. import_name:=stringdup(get_stringconst);
  2080. include(procoptions,po_has_importname);
  2081. if import_name^='' then
  2082. message(parser_e_empty_import_name);
  2083. end;
  2084. end;
  2085. end;
  2086. end;
  2087. procedure pd_weakexternal(pd:tabstractprocdef);
  2088. begin
  2089. if not(target_info.system in systems_weak_linking) then
  2090. message(parser_e_weak_external_not_supported)
  2091. else
  2092. pd_external(pd);
  2093. end;
  2094. procedure pd_winapi(pd:tabstractprocdef);
  2095. begin
  2096. if not(target_info.system in systems_wince) then
  2097. pd.proccalloption:=pocall_cdecl
  2098. else
  2099. pd.proccalloption:=pocall_stdcall;
  2100. end;
  2101. procedure pd_hardfloat(pd:tabstractprocdef);
  2102. begin
  2103. if
  2104. {$if defined(arm)}
  2105. (current_settings.fputype=fpu_soft) or
  2106. {$endif defined(arm)}
  2107. (cs_fp_emulation in current_settings.moduleswitches) then
  2108. message(parser_e_cannot_use_hardfloat_in_a_softfloat_environment);
  2109. end;
  2110. type
  2111. pd_handler=procedure(pd:tabstractprocdef);
  2112. proc_dir_rec=record
  2113. idtok : ttoken;
  2114. pd_flags : tpdflags;
  2115. handler : pd_handler;
  2116. pocall : tproccalloption;
  2117. pooption : tprocoptions;
  2118. mutexclpocall : tproccalloptions;
  2119. mutexclpotype : tproctypeoptions;
  2120. mutexclpo : tprocoptions;
  2121. end;
  2122. const
  2123. {Should contain the number of procedure directives we support.}
  2124. num_proc_directives=46;
  2125. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  2126. (
  2127. (
  2128. idtok:_ABSTRACT;
  2129. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2130. handler : @pd_abstract;
  2131. pocall : pocall_none;
  2132. pooption : [po_abstractmethod];
  2133. mutexclpocall : [pocall_internproc];
  2134. mutexclpotype : [];
  2135. mutexclpo : [po_exports,po_interrupt,po_inline]
  2136. ),(
  2137. idtok:_ALIAS;
  2138. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2139. handler : @pd_alias;
  2140. pocall : pocall_none;
  2141. pooption : [];
  2142. mutexclpocall : [];
  2143. mutexclpotype : [];
  2144. mutexclpo : [po_external,po_inline]
  2145. ),(
  2146. idtok:_ASMNAME;
  2147. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  2148. handler : @pd_asmname;
  2149. pocall : pocall_cdecl;
  2150. pooption : [po_external];
  2151. mutexclpocall : [pocall_internproc];
  2152. mutexclpotype : [];
  2153. mutexclpo : [po_external,po_inline]
  2154. ),(
  2155. idtok:_ASSEMBLER;
  2156. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2157. handler : nil;
  2158. pocall : pocall_none;
  2159. pooption : [po_assembler];
  2160. mutexclpocall : [];
  2161. mutexclpotype : [];
  2162. mutexclpo : [po_external]
  2163. ),(
  2164. idtok:_C; {same as cdecl for mode mac}
  2165. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2166. handler : nil;
  2167. pocall : pocall_cdecl;
  2168. pooption : [];
  2169. mutexclpocall : [];
  2170. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2171. mutexclpo : [po_assembler,po_external]
  2172. ),(
  2173. idtok:_CDECL;
  2174. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2175. handler : nil;
  2176. pocall : pocall_cdecl;
  2177. pooption : [];
  2178. mutexclpocall : [];
  2179. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2180. mutexclpo : [po_assembler,po_external]
  2181. ),(
  2182. idtok:_DISPID;
  2183. pd_flags : [pd_dispinterface];
  2184. handler : @pd_dispid;
  2185. pocall : pocall_none;
  2186. pooption : [po_dispid];
  2187. mutexclpocall : [pocall_internproc];
  2188. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2189. mutexclpo : [po_interrupt,po_external,po_inline]
  2190. ),(
  2191. idtok:_DYNAMIC;
  2192. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord];
  2193. handler : @pd_virtual;
  2194. pocall : pocall_none;
  2195. pooption : [po_virtualmethod];
  2196. mutexclpocall : [pocall_internproc];
  2197. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2198. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  2199. ),(
  2200. idtok:_EXPORT;
  2201. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf,pd_notrecord,pd_nothelper];
  2202. handler : @pd_export;
  2203. pocall : pocall_none;
  2204. pooption : [po_exports,po_global];
  2205. mutexclpocall : [pocall_internproc];
  2206. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2207. mutexclpo : [po_external,po_interrupt,po_inline]
  2208. ),(
  2209. idtok:_EXTERNAL;
  2210. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper,pd_javaclass,pd_intfjava];
  2211. handler : @pd_external;
  2212. pocall : pocall_none;
  2213. pooption : [po_external];
  2214. mutexclpocall : [pocall_syscall];
  2215. { allowed for external cpp classes }
  2216. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2217. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2218. ),(
  2219. idtok:_FAR;
  2220. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2221. handler : @pd_far;
  2222. pocall : pocall_none;
  2223. pooption : [];
  2224. mutexclpocall : [pocall_internproc];
  2225. mutexclpotype : [];
  2226. mutexclpo : [po_inline]
  2227. ),(
  2228. idtok:_FAR16;
  2229. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject,pd_notrecord,pd_nothelper];
  2230. handler : nil;
  2231. pocall : pocall_far16;
  2232. pooption : [];
  2233. mutexclpocall : [];
  2234. mutexclpotype : [];
  2235. mutexclpo : [po_external]
  2236. ),(
  2237. idtok:_FINAL;
  2238. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2239. handler : @pd_final;
  2240. pocall : pocall_none;
  2241. pooption : [po_finalmethod];
  2242. mutexclpocall : [pocall_internproc];
  2243. mutexclpotype : [];
  2244. mutexclpo : [po_exports,po_interrupt,po_inline]
  2245. ),(
  2246. idtok:_FORWARD;
  2247. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2248. handler : @pd_forward;
  2249. pocall : pocall_none;
  2250. pooption : [];
  2251. mutexclpocall : [pocall_internproc];
  2252. mutexclpotype : [];
  2253. mutexclpo : [po_external,po_inline]
  2254. ),(
  2255. idtok:_OLDFPCCALL;
  2256. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2257. handler : nil;
  2258. pocall : pocall_oldfpccall;
  2259. pooption : [];
  2260. mutexclpocall : [];
  2261. mutexclpotype : [];
  2262. mutexclpo : []
  2263. ),(
  2264. idtok:_INLINE;
  2265. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2266. handler : nil;
  2267. pocall : pocall_none;
  2268. pooption : [po_inline];
  2269. mutexclpocall : [pocall_safecall];
  2270. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2271. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_iocheck]
  2272. ),(
  2273. idtok:_INTERNCONST;
  2274. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2275. handler : @pd_internconst;
  2276. pocall : pocall_none;
  2277. pooption : [po_internconst];
  2278. mutexclpocall : [];
  2279. mutexclpotype : [potype_operator];
  2280. mutexclpo : []
  2281. ),(
  2282. idtok:_INTERNPROC;
  2283. pd_flags : [pd_interface,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2284. handler : @pd_internproc;
  2285. pocall : pocall_internproc;
  2286. pooption : [];
  2287. mutexclpocall : [];
  2288. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2289. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  2290. ),(
  2291. idtok:_INTERRUPT;
  2292. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2293. handler : @pd_interrupt;
  2294. pocall : pocall_oldfpccall;
  2295. pooption : [po_interrupt];
  2296. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,pocall_mwpascal,
  2297. pocall_pascal,pocall_far16,pocall_oldfpccall];
  2298. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2299. mutexclpo : [po_external,po_inline,po_exports]
  2300. ),(
  2301. idtok:_IOCHECK;
  2302. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2303. handler : nil;
  2304. pocall : pocall_none;
  2305. pooption : [po_iocheck];
  2306. mutexclpocall : [pocall_internproc];
  2307. mutexclpotype : [];
  2308. mutexclpo : [po_external]
  2309. ),(
  2310. idtok:_LOCAL;
  2311. pd_flags : [pd_implemen,pd_body];
  2312. handler : nil;
  2313. pocall : pocall_none;
  2314. pooption : [po_kylixlocal];
  2315. mutexclpocall : [pocall_internproc,pocall_far16];
  2316. mutexclpotype : [];
  2317. mutexclpo : [po_external,po_exports]
  2318. ),(
  2319. idtok:_MESSAGE;
  2320. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_objcprot,pd_notrecord];
  2321. handler : @pd_message;
  2322. pocall : pocall_none;
  2323. pooption : []; { can be po_msgstr or po_msgint }
  2324. mutexclpocall : [pocall_internproc];
  2325. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2326. mutexclpo : [po_interrupt,po_inline]
  2327. ),(
  2328. idtok:_MWPASCAL;
  2329. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2330. handler : nil;
  2331. pocall : pocall_mwpascal;
  2332. pooption : [];
  2333. mutexclpocall : [];
  2334. mutexclpotype : [];
  2335. mutexclpo : []
  2336. ),(
  2337. idtok:_NEAR;
  2338. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf,pd_notrecord,pd_nothelper];
  2339. handler : @pd_near;
  2340. pocall : pocall_none;
  2341. pooption : [];
  2342. mutexclpocall : [pocall_internproc];
  2343. mutexclpotype : [];
  2344. mutexclpo : []
  2345. ),(
  2346. idtok:_NORETURN;
  2347. pd_flags : [pd_implemen,pd_interface,pd_body,pd_notobjintf];
  2348. handler : nil;
  2349. pocall : pocall_none;
  2350. pooption : [po_noreturn];
  2351. mutexclpocall : [];
  2352. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2353. mutexclpo : [po_interrupt,po_virtualmethod,po_iocheck]
  2354. ),(
  2355. idtok:_NOSTACKFRAME;
  2356. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  2357. handler : nil;
  2358. pocall : pocall_none;
  2359. pooption : [po_nostackframe];
  2360. mutexclpocall : [pocall_internproc];
  2361. mutexclpotype : [];
  2362. mutexclpo : []
  2363. ),(
  2364. idtok:_OVERLOAD;
  2365. pd_flags : [pd_implemen,pd_interface,pd_body,pd_javaclass,pd_intfjava,pd_objcclass,pd_objcprot];
  2366. handler : @pd_overload;
  2367. pocall : pocall_none;
  2368. pooption : [po_overload];
  2369. mutexclpocall : [pocall_internproc];
  2370. mutexclpotype : [];
  2371. mutexclpo : []
  2372. ),(
  2373. idtok:_OVERRIDE;
  2374. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_javaclass,pd_intfjava,pd_notrecord];
  2375. handler : @pd_override;
  2376. pocall : pocall_none;
  2377. pooption : [po_overridingmethod,po_virtualmethod];
  2378. mutexclpocall : [pocall_internproc];
  2379. mutexclpotype : [];
  2380. mutexclpo : [po_exports,po_interrupt,po_virtualmethod,po_inline]
  2381. ),(
  2382. idtok:_PASCAL;
  2383. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2384. handler : nil;
  2385. pocall : pocall_pascal;
  2386. pooption : [];
  2387. mutexclpocall : [];
  2388. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2389. mutexclpo : [po_external]
  2390. ),(
  2391. idtok:_PUBLIC;
  2392. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2393. handler : @pd_public;
  2394. pocall : pocall_none;
  2395. pooption : [po_public,po_global];
  2396. mutexclpocall : [pocall_internproc];
  2397. mutexclpotype : [];
  2398. mutexclpo : [po_external,po_inline]
  2399. ),(
  2400. idtok:_REGISTER;
  2401. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2402. handler : nil;
  2403. pocall : pocall_register;
  2404. pooption : [];
  2405. mutexclpocall : [];
  2406. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2407. mutexclpo : [po_external]
  2408. ),(
  2409. idtok:_REINTRODUCE;
  2410. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_notrecord,pd_javaclass];
  2411. handler : @pd_reintroduce;
  2412. pocall : pocall_none;
  2413. pooption : [po_reintroduce];
  2414. mutexclpocall : [pocall_internproc];
  2415. mutexclpotype : [];
  2416. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  2417. ),(
  2418. idtok:_SAFECALL;
  2419. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2420. handler : nil;
  2421. pocall : pocall_safecall;
  2422. pooption : [];
  2423. mutexclpocall : [];
  2424. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2425. mutexclpo : [po_external]
  2426. ),(
  2427. idtok:_SOFTFLOAT;
  2428. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2429. handler : nil;
  2430. pocall : pocall_softfloat;
  2431. pooption : [];
  2432. mutexclpocall : [];
  2433. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2434. { it's available with po_external because the libgcc floating point routines on the arm
  2435. uses this calling convention }
  2436. mutexclpo : []
  2437. ),(
  2438. idtok:_STATIC;
  2439. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_record,pd_javaclass,pd_notobjintf];
  2440. handler : @pd_static;
  2441. pocall : pocall_none;
  2442. pooption : [po_staticmethod];
  2443. mutexclpocall : [pocall_internproc];
  2444. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2445. mutexclpo : [po_interrupt,po_exports]
  2446. ),(
  2447. idtok:_STDCALL;
  2448. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2449. handler : nil;
  2450. pocall : pocall_stdcall;
  2451. pooption : [];
  2452. mutexclpocall : [];
  2453. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2454. mutexclpo : [po_external]
  2455. ),(
  2456. idtok:_SYSCALL;
  2457. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  2458. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  2459. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  2460. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  2461. handler : @pd_syscall;
  2462. pocall : pocall_syscall;
  2463. pooption : [];
  2464. mutexclpocall : [];
  2465. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2466. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  2467. ),(
  2468. idtok:_VIRTUAL;
  2469. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2470. handler : @pd_virtual;
  2471. pocall : pocall_none;
  2472. pooption : [po_virtualmethod];
  2473. mutexclpocall : [pocall_internproc];
  2474. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2475. mutexclpo : [po_interrupt,po_exports,po_overridingmethod,po_inline]
  2476. ),(
  2477. idtok:_CPPDECL;
  2478. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2479. handler : nil;
  2480. pocall : pocall_cppdecl;
  2481. pooption : [];
  2482. mutexclpocall : [];
  2483. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2484. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  2485. ),(
  2486. idtok:_VARARGS;
  2487. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass,pd_objcprot];
  2488. handler : nil;
  2489. pocall : pocall_none;
  2490. pooption : [po_varargs];
  2491. mutexclpocall : [pocall_internproc,pocall_register,
  2492. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  2493. mutexclpotype : [];
  2494. mutexclpo : [po_assembler,po_interrupt,po_inline]
  2495. ),(
  2496. idtok:_COMPILERPROC;
  2497. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2498. handler : @pd_compilerproc;
  2499. pocall : pocall_none;
  2500. pooption : [po_compilerproc];
  2501. mutexclpocall : [];
  2502. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2503. mutexclpo : [po_interrupt]
  2504. ),(
  2505. idtok:_WEAKEXTERNAL;
  2506. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper];
  2507. handler : @pd_weakexternal;
  2508. pocall : pocall_none;
  2509. { mark it both external and weak external, so we don't have to
  2510. adapt all code for external symbols to also check for weak external
  2511. }
  2512. pooption : [po_external,po_weakexternal];
  2513. mutexclpocall : [pocall_internproc,pocall_syscall];
  2514. { allowed for external cpp classes }
  2515. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2516. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2517. ),(
  2518. idtok:_WINAPI;
  2519. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2520. handler : @pd_winapi;
  2521. pocall : pocall_none;
  2522. pooption : [];
  2523. mutexclpocall : [pocall_stdcall,pocall_cdecl];
  2524. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2525. mutexclpo : [po_external]
  2526. ),(
  2527. idtok:_ENUMERATOR;
  2528. pd_flags : [pd_interface,pd_object,pd_record];
  2529. handler : @pd_enumerator;
  2530. pocall : pocall_none;
  2531. pooption : [];
  2532. mutexclpocall : [pocall_internproc];
  2533. mutexclpotype : [];
  2534. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2535. ),(
  2536. idtok:_RTLPROC;
  2537. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2538. handler : nil;
  2539. pocall : pocall_none;
  2540. pooption : [po_rtlproc];
  2541. mutexclpocall : [];
  2542. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2543. mutexclpo : [po_interrupt]
  2544. ),(
  2545. idtok:_HARDFLOAT;
  2546. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2547. handler : @pd_hardfloat;
  2548. pocall : pocall_hardfloat;
  2549. pooption : [];
  2550. mutexclpocall : [];
  2551. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2552. { it's available with po_external because the libgcc floating point routines on the arm
  2553. uses this calling convention }
  2554. mutexclpo : []
  2555. )
  2556. );
  2557. function check_proc_directive(isprocvar:boolean):boolean;
  2558. var
  2559. i : longint;
  2560. begin
  2561. result:=false;
  2562. for i:=1 to num_proc_directives do
  2563. if proc_direcdata[i].idtok=idtoken then
  2564. begin
  2565. if ((not isprocvar) or
  2566. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2567. { don't eat a public directive in classes }
  2568. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2569. result:=true;
  2570. exit;
  2571. end;
  2572. end;
  2573. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2574. {
  2575. Parse the procedure directive, returns true if a correct directive is found
  2576. }
  2577. var
  2578. p : longint;
  2579. found : boolean;
  2580. name : TIDString;
  2581. begin
  2582. parse_proc_direc:=false;
  2583. name:=tokeninfo^[idtoken].str;
  2584. found:=false;
  2585. { Hint directive? Then exit immediatly }
  2586. if (m_hintdirective in current_settings.modeswitches) then
  2587. begin
  2588. case idtoken of
  2589. _LIBRARY,
  2590. _PLATFORM,
  2591. _UNIMPLEMENTED,
  2592. _EXPERIMENTAL,
  2593. _DEPRECATED :
  2594. if (m_delphi in current_settings.modeswitches) and (pd.typ=procdef) then
  2595. begin
  2596. maybe_parse_hint_directives(tprocdef(pd));
  2597. { could the new token still be a directive? }
  2598. if token<>_ID then
  2599. exit;
  2600. name:=tokeninfo^[idtoken].str;
  2601. end
  2602. else
  2603. exit;
  2604. end;
  2605. end;
  2606. { C directive is MacPas only, because it breaks too much existing code
  2607. on other platforms (PFV) }
  2608. if (idtoken=_C) and
  2609. not(m_mac in current_settings.modeswitches) then
  2610. exit;
  2611. { retrieve data for directive if found }
  2612. for p:=1 to num_proc_directives do
  2613. if proc_direcdata[p].idtok=idtoken then
  2614. begin
  2615. found:=true;
  2616. break;
  2617. end;
  2618. { Check if the procedure directive is known }
  2619. if not found then
  2620. begin
  2621. { parsing a procvar type the name can be any
  2622. next variable !! }
  2623. if ((pdflags * [pd_procvar,pd_object,pd_record,pd_objcclass,pd_objcprot])=[]) and
  2624. not(idtoken in [_PROPERTY,_GENERIC]) then
  2625. Message1(parser_w_unknown_proc_directive_ignored,pattern);
  2626. exit;
  2627. end;
  2628. { check if method and directive not for object, like public.
  2629. This needs to be checked also for procvars }
  2630. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2631. (symtablestack.top.symtabletype=ObjectSymtable) and
  2632. { directive allowed for cpp classes? }
  2633. not((pd_cppobject in proc_direcdata[p].pd_flags) and is_cppclass(tdef(symtablestack.top.defowner))) and
  2634. not((pd_javaclass in proc_direcdata[p].pd_flags) and is_javaclass(tdef(symtablestack.top.defowner))) and
  2635. not((pd_intfjava in proc_direcdata[p].pd_flags) and is_javainterface(tdef(symtablestack.top.defowner))) then
  2636. exit;
  2637. if (pd_notrecord in proc_direcdata[p].pd_flags) and
  2638. (symtablestack.top.symtabletype=recordsymtable) then
  2639. exit;
  2640. { check if method and directive not for java class }
  2641. if not(pd_javaclass in proc_direcdata[p].pd_flags) and
  2642. is_javaclass(tdef(symtablestack.top.defowner)) then
  2643. exit;
  2644. { check if method and directive not for java interface }
  2645. if not(pd_intfjava in proc_direcdata[p].pd_flags) and
  2646. is_javainterface(tdef(symtablestack.top.defowner)) then
  2647. exit;
  2648. { Conflicts between directives ? }
  2649. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  2650. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  2651. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  2652. begin
  2653. Message1(parser_e_proc_dir_conflict,name);
  2654. exit;
  2655. end;
  2656. { set calling convention }
  2657. if proc_direcdata[p].pocall<>pocall_none then
  2658. begin
  2659. if (po_hascallingconvention in pd.procoptions) then
  2660. begin
  2661. Message2(parser_w_proc_overriding_calling,
  2662. proccalloptionStr[pd.proccalloption],
  2663. proccalloptionStr[proc_direcdata[p].pocall]);
  2664. end;
  2665. { check if the target processor supports this calling convention }
  2666. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2667. begin
  2668. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2669. { recover }
  2670. proc_direcdata[p].pocall:=pocall_stdcall;
  2671. end;
  2672. pd.proccalloption:=proc_direcdata[p].pocall;
  2673. include(pd.procoptions,po_hascallingconvention);
  2674. end;
  2675. if pd.typ=procdef then
  2676. begin
  2677. { Check if the directive is only for objects }
  2678. if (pd_object in proc_direcdata[p].pd_flags) and
  2679. not assigned(tprocdef(pd).struct) then
  2680. exit;
  2681. { Check if the directive is only for records }
  2682. if (pd_record in proc_direcdata[p].pd_flags) and
  2683. not assigned(tprocdef(pd).struct) then
  2684. exit;
  2685. { check if method and directive not for interface }
  2686. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2687. is_interface(tprocdef(pd).struct) then
  2688. exit;
  2689. { check if method and directive not for interface }
  2690. if is_dispinterface(tprocdef(pd).struct) and
  2691. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2692. exit;
  2693. { check if method and directive not for objcclass }
  2694. if is_objcclass(tprocdef(pd).struct) and
  2695. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2696. exit;
  2697. { check if method and directive not for objcprotocol }
  2698. if is_objcprotocol(tprocdef(pd).struct) and
  2699. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2700. exit;
  2701. { check if method and directive not for record/class helper }
  2702. if is_objectpascal_helper(tprocdef(pd).struct) and
  2703. (pd_nothelper in proc_direcdata[p].pd_flags) then
  2704. end;
  2705. { consume directive, and turn flag on }
  2706. consume(token);
  2707. parse_proc_direc:=true;
  2708. { Check the pd_flags if the directive should be allowed }
  2709. if (pd_interface in pdflags) and
  2710. not(pd_interface in proc_direcdata[p].pd_flags) then
  2711. begin
  2712. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  2713. exit;
  2714. end;
  2715. if (pd_implemen in pdflags) and
  2716. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2717. begin
  2718. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  2719. exit;
  2720. end;
  2721. if (pd_procvar in pdflags) and
  2722. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2723. begin
  2724. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  2725. exit;
  2726. end;
  2727. { Return the new pd_flags }
  2728. if not(pd_body in proc_direcdata[p].pd_flags) then
  2729. exclude(pdflags,pd_body);
  2730. { Add the correct flag }
  2731. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2732. { Call the handler }
  2733. if pointer(proc_direcdata[p].handler)<>nil then
  2734. proc_direcdata[p].handler(pd);
  2735. end;
  2736. function proc_get_importname(pd:tprocdef):string;
  2737. var
  2738. dllname, importname : string;
  2739. begin
  2740. result:='';
  2741. if not(po_external in pd.procoptions) then
  2742. internalerror(200412151);
  2743. { external name or number is specified }
  2744. if assigned(pd.import_name) or (pd.import_nr<>0) then
  2745. begin
  2746. if assigned(pd.import_dll) then
  2747. dllname:=pd.import_dll^
  2748. else
  2749. dllname:='';
  2750. if assigned(pd.import_name) then
  2751. importname:=pd.import_name^
  2752. else
  2753. importname:='';
  2754. proc_get_importname:=make_dllmangledname(dllname,
  2755. importname,pd.import_nr,pd.proccalloption);
  2756. end
  2757. else
  2758. begin
  2759. { Default names when importing variables }
  2760. case pd.proccalloption of
  2761. pocall_cdecl :
  2762. begin
  2763. if assigned(pd.struct) then
  2764. result:=target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname
  2765. else
  2766. result:=target_info.Cprefix+pd.procsym.realname;
  2767. end;
  2768. pocall_cppdecl :
  2769. begin
  2770. result:=target_info.Cprefix+pd.cplusplusmangledname;
  2771. end;
  2772. else
  2773. begin
  2774. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  2775. { but according to MacPas mode description
  2776. Cprefix should still be used PM }
  2777. if (m_mac in current_settings.modeswitches) then
  2778. result:=target_info.Cprefix+tprocdef(pd).procsym.realname
  2779. else
  2780. result:=pd.procsym.realname;
  2781. end;
  2782. end;
  2783. end;
  2784. end;
  2785. procedure compilerproc_set_symbol_name(pd: tprocdef);
  2786. begin
  2787. pd.procsym.realname:='$'+lower(pd.procsym.name);
  2788. end;
  2789. procedure proc_set_mangledname(pd:tprocdef);
  2790. var
  2791. s : string;
  2792. begin
  2793. { When the mangledname is already set we aren't allowed to change
  2794. it because it can already be used somewhere (PFV) }
  2795. if not(po_has_mangledname in pd.procoptions) then
  2796. begin
  2797. if (po_external in pd.procoptions) then
  2798. begin
  2799. { External Procedures are only allowed to change the mangledname
  2800. in their first declaration }
  2801. if (pd.forwarddef or (not pd.hasforward)) then
  2802. begin
  2803. s:=proc_get_importname(pd);
  2804. if s<>'' then
  2805. begin
  2806. pd.setmangledname(s);
  2807. end;
  2808. { since this is an external declaration, there won't be an
  2809. implementation that needs to match the original symbol
  2810. again -> immediately convert here }
  2811. if po_compilerproc in pd.procoptions then
  2812. compilerproc_set_symbol_name(pd);
  2813. end
  2814. end
  2815. else
  2816. { Normal procedures }
  2817. begin
  2818. if (po_compilerproc in pd.procoptions) then
  2819. begin
  2820. pd.setmangledname(lower(pd.procsym.name));
  2821. end;
  2822. end;
  2823. end;
  2824. { Public/exported alias names }
  2825. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  2826. not(po_has_public_name in pd.procoptions) then
  2827. begin
  2828. case pd.proccalloption of
  2829. pocall_cdecl :
  2830. begin
  2831. if assigned(pd.struct) then
  2832. pd.aliasnames.insert(target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname)
  2833. else
  2834. begin
  2835. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  2836. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  2837. (po_exports in pd.procoptions) then
  2838. pd.aliasnames.insert(pd.procsym.realname)
  2839. else
  2840. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  2841. end;
  2842. end;
  2843. pocall_cppdecl :
  2844. begin
  2845. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  2846. end;
  2847. end;
  2848. { prevent adding the alias a second time }
  2849. include(pd.procoptions,po_has_public_name);
  2850. end;
  2851. end;
  2852. procedure handle_calling_convention(pd:tabstractprocdef;flags:thccflags=hcc_all);
  2853. begin
  2854. if hcc_check in flags then
  2855. begin
  2856. { set the default calling convention if none provided }
  2857. if (pd.typ=procdef) and
  2858. (is_objc_class_or_protocol(tprocdef(pd).struct) or
  2859. is_cppclass(tprocdef(pd).struct)) then
  2860. begin
  2861. { none of the explicit calling conventions should be allowed }
  2862. if (po_hascallingconvention in pd.procoptions) then
  2863. internalerror(2009032501);
  2864. if is_cppclass(tprocdef(pd).struct) then
  2865. pd.proccalloption:=pocall_cppdecl
  2866. else
  2867. pd.proccalloption:=pocall_cdecl;
  2868. end
  2869. else if not(po_hascallingconvention in pd.procoptions) then
  2870. pd.proccalloption:=current_settings.defproccall
  2871. else
  2872. begin
  2873. if pd.proccalloption=pocall_none then
  2874. internalerror(200309081);
  2875. end;
  2876. { handle proccall specific settings }
  2877. case pd.proccalloption of
  2878. pocall_cdecl,
  2879. pocall_cppdecl :
  2880. begin
  2881. { check C cdecl para types }
  2882. check_c_para(pd);
  2883. end;
  2884. pocall_far16 :
  2885. begin
  2886. { Temporary stub, must be rewritten to support OS/2 far16 }
  2887. Message1(parser_w_proc_directive_ignored,'FAR16');
  2888. end;
  2889. end;
  2890. { Inlining is enabled and supported? }
  2891. if (po_inline in pd.procoptions) and
  2892. not(cs_do_inline in current_settings.localswitches) then
  2893. begin
  2894. { Give an error if inline is not supported by the compiler mode,
  2895. otherwise only give a hint that this procedure will not be inlined }
  2896. if not(m_default_inline in current_settings.modeswitches) then
  2897. Message(parser_e_proc_inline_not_supported)
  2898. else
  2899. Message(parser_h_inlining_disabled);
  2900. exclude(pd.procoptions,po_inline);
  2901. end;
  2902. { For varargs directive also cdecl and external must be defined }
  2903. if (po_varargs in pd.procoptions) then
  2904. begin
  2905. { check first for external in the interface, if available there
  2906. then the cdecl must also be there since there is no implementation
  2907. available to contain it }
  2908. if parse_only then
  2909. begin
  2910. { if external is available, then cdecl must also be available,
  2911. procvars don't need external }
  2912. if not((po_external in pd.procoptions) or
  2913. (pd.typ=procvardef) or
  2914. { for objcclasses this is checked later, because the entire
  2915. class may be external. }
  2916. is_objc_class_or_protocol(tprocdef(pd).struct)) and
  2917. not(pd.proccalloption in (cdecl_pocalls + [pocall_mwpascal,pocall_stdcall])) then
  2918. Message(parser_e_varargs_need_cdecl_and_external);
  2919. end
  2920. else
  2921. begin
  2922. { both must be defined now }
  2923. if not((po_external in pd.procoptions) or
  2924. (pd.typ=procvardef)) or
  2925. not(pd.proccalloption in (cdecl_pocalls + [pocall_mwpascal,pocall_stdcall])) then
  2926. Message(parser_e_varargs_need_cdecl_and_external);
  2927. end;
  2928. end;
  2929. end;
  2930. if hcc_insert_hidden_paras in flags then
  2931. begin
  2932. { insert hidden high parameters }
  2933. pd.parast.SymList.ForEachCall(@insert_hidden_para,pd);
  2934. { insert hidden self parameter }
  2935. insert_self_and_vmt_para(pd);
  2936. { insert funcret parameter if required }
  2937. insert_funcret_para(pd);
  2938. { Make var parameters regable, this must be done after the calling
  2939. convention is set. }
  2940. { this must be done before parentfp is insert, because getting all cases
  2941. where parentfp must be in a memory location isn't catched properly so
  2942. we put parentfp never in a register }
  2943. pd.parast.SymList.ForEachCall(@set_addr_param_regable,pd);
  2944. { insert parentfp parameter if required }
  2945. insert_parentfp_para(pd);
  2946. end;
  2947. { Calculate parameter tlist }
  2948. pd.calcparas;
  2949. end;
  2950. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2951. {
  2952. Parse the procedure directives. It does not matter if procedure directives
  2953. are written using ;procdir; or ['procdir'] syntax.
  2954. }
  2955. var
  2956. stoprecording,
  2957. res : boolean;
  2958. begin
  2959. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  2960. begin
  2961. tprocdef(pd).aliasnames.insert(target_info.Cprefix+tprocdef(pd).procsym.realname);
  2962. include(pd.procoptions,po_public);
  2963. include(pd.procoptions,po_has_public_name);
  2964. include(pd.procoptions,po_global);
  2965. end;
  2966. { methods from external class definitions are all external themselves }
  2967. if (pd.typ=procdef) and
  2968. assigned(tprocdef(pd).struct) and
  2969. (tprocdef(pd).struct.typ=objectdef) and
  2970. (oo_is_external in tobjectdef(tprocdef(pd).struct).objectoptions) then
  2971. tprocdef(pd).make_external;
  2972. { Class constructors and destructor are static class methods in real. }
  2973. { There are many places in the compiler where either class or static }
  2974. { method flag changes the behavior. It is simplier to add them to }
  2975. { the class constructors/destructors options than to fix all the }
  2976. { occurencies. (Paul) }
  2977. if pd.proctypeoption in [potype_class_constructor,potype_class_destructor] then
  2978. begin
  2979. include(pd.procoptions,po_classmethod);
  2980. include(pd.procoptions,po_staticmethod);
  2981. end;
  2982. { for a generic routine we also need to record the procedure }
  2983. { directives, but only if we aren't already recording for a }
  2984. { surrounding generic }
  2985. if pd.is_generic and (pd.typ=procdef) and not current_scanner.is_recording_tokens then
  2986. begin
  2987. current_scanner.startrecordtokens(tprocdef(pd).genericdecltokenbuf);
  2988. stoprecording:=true;
  2989. end
  2990. else
  2991. stoprecording:=false;
  2992. while token in [_ID,_LECKKLAMMER] do
  2993. begin
  2994. if try_to_consume(_LECKKLAMMER) then
  2995. begin
  2996. repeat
  2997. parse_proc_direc(pd,pdflags);
  2998. until not try_to_consume(_COMMA);
  2999. consume(_RECKKLAMMER);
  3000. { we always expect at least '[];' }
  3001. res:=true;
  3002. end
  3003. else
  3004. begin
  3005. res:=parse_proc_direc(pd,pdflags);
  3006. end;
  3007. { A procedure directive normally followed by a semicolon, but in
  3008. a const section or reading a type we should stop when _EQ is found,
  3009. because a constant/default value follows }
  3010. if res then
  3011. begin
  3012. if (block_type=bt_const_type) and
  3013. (token=_EQ) then
  3014. break;
  3015. { support procedure proc;stdcall export; }
  3016. if not(check_proc_directive((pd.typ=procvardef))) then
  3017. begin
  3018. { support "record p : procedure stdcall end;" and
  3019. "var p : procedure stdcall = nil;" }
  3020. if (pd_procvar in pdflags) and
  3021. (token in [_END,_RKLAMMER,_EQ]) then
  3022. break
  3023. else
  3024. begin
  3025. if (token=_COLON) then
  3026. begin
  3027. Message(parser_e_field_not_allowed_here);
  3028. consume_all_until(_SEMICOLON);
  3029. end;
  3030. consume(_SEMICOLON)
  3031. end;
  3032. end;
  3033. end
  3034. else
  3035. break;
  3036. end;
  3037. if stoprecording then
  3038. current_scanner.stoprecordtokens;
  3039. { nostackframe requires assembler, but assembler
  3040. may be specified in the implementation part only,
  3041. and in not required if the function is first forward declared
  3042. if it is a procdef that has forwardef set to true
  3043. we postpone the possible error message to the real implementation
  3044. parse_only does not need to be considered as po_nostackframe
  3045. is an implementation only directive }
  3046. if (po_nostackframe in pd.procoptions) and
  3047. not (po_assembler in pd.procoptions) and
  3048. ((pd.typ<>procdef) or not tprocdef(pd).forwarddef) then
  3049. message(parser_e_nostackframe_without_assembler);
  3050. end;
  3051. procedure parse_var_proc_directives(sym:tsym);
  3052. var
  3053. pdflags : tpdflags;
  3054. pd : tabstractprocdef;
  3055. begin
  3056. pdflags:=[pd_procvar];
  3057. pd:=nil;
  3058. case sym.typ of
  3059. fieldvarsym,
  3060. staticvarsym,
  3061. localvarsym,
  3062. paravarsym :
  3063. pd:=tabstractprocdef(tabstractvarsym(sym).vardef);
  3064. typesym :
  3065. pd:=tabstractprocdef(ttypesym(sym).typedef);
  3066. else
  3067. internalerror(2003042617);
  3068. end;
  3069. if pd.typ<>procvardef then
  3070. internalerror(2003042618);
  3071. { names should never be used anyway }
  3072. parse_proc_directives(pd,pdflags);
  3073. end;
  3074. procedure parse_object_proc_directives(pd:tabstractprocdef);
  3075. var
  3076. pdflags : tpdflags;
  3077. begin
  3078. pdflags:=[pd_object];
  3079. parse_proc_directives(pd,pdflags);
  3080. end;
  3081. procedure parse_record_proc_directives(pd:tabstractprocdef);
  3082. var
  3083. pdflags : tpdflags;
  3084. begin
  3085. pdflags:=[pd_record];
  3086. parse_proc_directives(pd,pdflags);
  3087. end;
  3088. function proc_add_definition(var currpd:tprocdef):boolean;
  3089. function equal_generic_procdefs(fwpd,currpd:tprocdef):boolean;
  3090. var
  3091. i : longint;
  3092. fwtype,
  3093. currtype : ttypesym;
  3094. foundretdef : boolean;
  3095. begin
  3096. result:=false;
  3097. if fwpd.genericparas.count<>currpd.genericparas.count then
  3098. exit;
  3099. { comparing generic declarations is a bit more cumbersome as the
  3100. defs of the generic parameter types are not equal, especially if the
  3101. declaration contains constraints; essentially we have two cases:
  3102. - proc declared in interface of unit (or in class/record/object)
  3103. and defined in implementation; here the fwpd might contain
  3104. constraints while currpd must only contain undefineddefs
  3105. - forward declaration in implementation; this case is not supported
  3106. right now }
  3107. foundretdef:=false;
  3108. for i:=0 to fwpd.genericparas.count-1 do
  3109. begin
  3110. fwtype:=ttypesym(fwpd.genericparas[i]);
  3111. currtype:=ttypesym(currpd.genericparas[i]);
  3112. { if the type in the currpd isn't a pure undefineddef, then we can
  3113. stop right there }
  3114. if (currtype.typedef.typ<>undefineddef) or (df_genconstraint in currtype.typedef.defoptions) then
  3115. exit;
  3116. if not foundretdef then
  3117. begin
  3118. { if the returndef is the same as this parameter's def then this
  3119. needs to be the case for both procdefs }
  3120. foundretdef:=fwpd.returndef=fwtype.typedef;
  3121. if foundretdef xor (currpd.returndef=currtype.typedef) then
  3122. exit;
  3123. end;
  3124. end;
  3125. if compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv,cpo_generic])<>te_exact then
  3126. exit;
  3127. if not foundretdef then
  3128. begin
  3129. if tstoreddef(fwpd.returndef).is_specialization and tstoreddef(currpd.returndef).is_specialization then
  3130. { for specializations we're happy with equal defs instead of exactly the same defs }
  3131. result:=equal_defs(fwpd.returndef,currpd.returndef)
  3132. else
  3133. { the returndef isn't a type parameter, so compare as usual }
  3134. result:=compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact;
  3135. end
  3136. else
  3137. result:=true;
  3138. end;
  3139. {
  3140. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  3141. forwarddef is found and reused it returns true
  3142. }
  3143. var
  3144. fwpd : tprocdef;
  3145. currparasym,
  3146. fwparasym : tsym;
  3147. currparacnt,
  3148. fwparacnt,
  3149. curridx,
  3150. fwidx,
  3151. i : longint;
  3152. po_comp : tprocoptions;
  3153. paracompopt: tcompare_paras_options;
  3154. forwardfound : boolean;
  3155. symentry: TSymEntry;
  3156. item : tlinkedlistitem;
  3157. begin
  3158. forwardfound:=false;
  3159. { check overloaded functions if the same function already exists }
  3160. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  3161. begin
  3162. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  3163. { can happen for internally generated routines }
  3164. if (fwpd=currpd) then
  3165. begin
  3166. result:=true;
  3167. exit;
  3168. end;
  3169. { Skip overloaded definitions that are declared in other units }
  3170. if fwpd.procsym<>currpd.procsym then
  3171. continue;
  3172. { check the parameters, for delphi/tp it is possible to
  3173. leave the parameters away in the implementation (forwarddef=false).
  3174. But for an overload declared function this is not allowed }
  3175. if { check if empty implementation arguments match is allowed }
  3176. (
  3177. not(m_repeat_forward in current_settings.modeswitches) and
  3178. not(currpd.forwarddef) and
  3179. is_bareprocdef(currpd) and
  3180. not(po_overload in fwpd.procoptions)
  3181. ) or
  3182. (
  3183. fwpd.is_generic and
  3184. currpd.is_generic and
  3185. equal_generic_procdefs(fwpd,currpd)
  3186. ) or
  3187. { check arguments, we need to check only the user visible parameters. The hidden parameters
  3188. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV)
  3189. don't check default values here, because routines that are the same except for their default
  3190. values should be reported as mismatches (since you can't overload based on different default
  3191. parameter values) }
  3192. (
  3193. (compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact) and
  3194. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact)
  3195. ) then
  3196. begin
  3197. { Check if we've found the forwarddef, if found then
  3198. we need to update the forward def with the current
  3199. implementation settings }
  3200. if fwpd.forwarddef then
  3201. begin
  3202. forwardfound:=true;
  3203. if not(m_repeat_forward in current_settings.modeswitches) and
  3204. (fwpd.proccalloption<>currpd.proccalloption) then
  3205. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv]
  3206. else
  3207. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv];
  3208. { Check calling convention }
  3209. if (fwpd.proccalloption<>currpd.proccalloption) then
  3210. begin
  3211. { In delphi it is possible to specify the calling
  3212. convention in the interface or implementation if
  3213. there was no convention specified in the other
  3214. part }
  3215. if (m_delphi in current_settings.modeswitches) then
  3216. begin
  3217. if not(po_hascallingconvention in currpd.procoptions) then
  3218. currpd.proccalloption:=fwpd.proccalloption
  3219. else
  3220. if not(po_hascallingconvention in fwpd.procoptions) then
  3221. fwpd.proccalloption:=currpd.proccalloption
  3222. else
  3223. begin
  3224. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  3225. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3226. { restore interface settings }
  3227. currpd.proccalloption:=fwpd.proccalloption;
  3228. end;
  3229. end
  3230. else
  3231. begin
  3232. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  3233. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3234. { restore interface settings }
  3235. currpd.proccalloption:=fwpd.proccalloption;
  3236. end;
  3237. end;
  3238. { Check static }
  3239. if (po_staticmethod in fwpd.procoptions) then
  3240. begin
  3241. if not (po_staticmethod in currpd.procoptions) then
  3242. begin
  3243. include(currpd.procoptions, po_staticmethod);
  3244. if (po_classmethod in currpd.procoptions) then
  3245. begin
  3246. { remove self from the hidden paras }
  3247. symentry:=currpd.parast.Find('self');
  3248. if symentry<>nil then
  3249. begin
  3250. currpd.parast.Delete(symentry);
  3251. currpd.calcparas;
  3252. end;
  3253. end;
  3254. end;
  3255. end;
  3256. { Check if the procedure type and return type are correct,
  3257. also the parameters must match also with the type and that
  3258. if the implementation has default parameters, the interface
  3259. also has them and that if they both have them, that they
  3260. have the same value }
  3261. if ((m_repeat_forward in current_settings.modeswitches) or
  3262. not is_bareprocdef(currpd)) and
  3263. (
  3264. (
  3265. fwpd.is_generic and
  3266. currpd.is_generic and
  3267. not equal_generic_procdefs(fwpd,currpd)
  3268. ) or
  3269. (
  3270. (
  3271. not fwpd.is_generic or
  3272. not currpd.is_generic
  3273. ) and
  3274. (
  3275. (compare_paras(fwpd.paras,currpd.paras,cp_all,paracompopt)<>te_exact) or
  3276. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)<>te_exact)
  3277. )
  3278. )
  3279. ) then
  3280. begin
  3281. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3282. fwpd.fullprocname(false));
  3283. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3284. break;
  3285. end;
  3286. { Check if both are declared forward }
  3287. if fwpd.forwarddef and currpd.forwarddef then
  3288. begin
  3289. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  3290. currpd.fullprocname(false));
  3291. end;
  3292. { internconst or internproc only need to be defined once }
  3293. if (fwpd.proccalloption=pocall_internproc) then
  3294. currpd.proccalloption:=fwpd.proccalloption
  3295. else
  3296. if (currpd.proccalloption=pocall_internproc) then
  3297. fwpd.proccalloption:=currpd.proccalloption;
  3298. { Check procedure options, Delphi requires that class is
  3299. repeated in the implementation for class methods }
  3300. if (m_fpc in current_settings.modeswitches) then
  3301. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  3302. else
  3303. po_comp:=[po_classmethod,po_methodpointer];
  3304. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  3305. (fwpd.proctypeoption <> currpd.proctypeoption) or
  3306. { if the implementation version has an "overload" modifier,
  3307. the interface version must also have it (otherwise we can
  3308. get annoying crashes due to interface crc changes) }
  3309. (not(po_overload in fwpd.procoptions) and
  3310. (po_overload in currpd.procoptions)) then
  3311. begin
  3312. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3313. fwpd.fullprocname(false));
  3314. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  3315. { This error is non-fatal, we can recover }
  3316. end;
  3317. { Forward declaration is external? }
  3318. if (po_external in fwpd.procoptions) then
  3319. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  3320. { Check parameters }
  3321. if (m_repeat_forward in current_settings.modeswitches) or
  3322. (currpd.minparacount>0) then
  3323. begin
  3324. { If mangled names are equal then they have the same amount of arguments }
  3325. { We can check the names of the arguments }
  3326. { both symtables are in the same order from left to right }
  3327. curridx:=0;
  3328. fwidx:=0;
  3329. currparacnt:=currpd.parast.SymList.Count;
  3330. fwparacnt:=fwpd.parast.SymList.Count;
  3331. repeat
  3332. { skip default parameter constsyms }
  3333. while (curridx<currparacnt) and
  3334. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  3335. inc(curridx);
  3336. while (fwidx<fwparacnt) and
  3337. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  3338. inc(fwidx);
  3339. { stop when one of the two lists is at the end }
  3340. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  3341. break;
  3342. { compare names of parameters, ignore implictly
  3343. renamed parameters }
  3344. currparasym:=tsym(currpd.parast.SymList[curridx]);
  3345. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  3346. if not(sp_implicitrename in currparasym.symoptions) and
  3347. not(sp_implicitrename in fwparasym.symoptions) then
  3348. begin
  3349. if (currparasym.name<>fwparasym.name) then
  3350. begin
  3351. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  3352. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  3353. break;
  3354. end;
  3355. end;
  3356. { next parameter }
  3357. inc(curridx);
  3358. inc(fwidx);
  3359. until false;
  3360. end;
  3361. { Everything is checked, now we can update the forward declaration
  3362. with the new data from the implementation }
  3363. fwpd.forwarddef:=currpd.forwarddef;
  3364. fwpd.hasforward:=true;
  3365. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  3366. { marked as local but exported from unit? }
  3367. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  3368. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  3369. if fwpd.extnumber=$ffff then
  3370. fwpd.extnumber:=currpd.extnumber;
  3371. while not currpd.aliasnames.empty do
  3372. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  3373. { update fileinfo so position references the implementation,
  3374. also update funcretsym if it is already generated }
  3375. fwpd.fileinfo:=currpd.fileinfo;
  3376. if assigned(fwpd.funcretsym) then
  3377. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  3378. if assigned(currpd.deprecatedmsg) then
  3379. begin
  3380. stringdispose(fwpd.deprecatedmsg);
  3381. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  3382. end;
  3383. { import names }
  3384. if assigned(currpd.import_dll) then
  3385. begin
  3386. stringdispose(fwpd.import_dll);
  3387. fwpd.import_dll:=stringdup(currpd.import_dll^);
  3388. end;
  3389. if assigned(currpd.import_name) then
  3390. begin
  3391. stringdispose(fwpd.import_name);
  3392. fwpd.import_name:=stringdup(currpd.import_name^);
  3393. end;
  3394. fwpd.import_nr:=currpd.import_nr;
  3395. { for compilerproc defines we need to rename and update the
  3396. symbolname to lowercase so users can' access it (can't do
  3397. it immediately, because then the implementation symbol
  3398. won't be matched) }
  3399. if po_compilerproc in fwpd.procoptions then
  3400. begin
  3401. compilerproc_set_symbol_name(fwpd);
  3402. current_module.add_public_asmsym(fwpd.procsym.realname,AB_GLOBAL,AT_FUNCTION);
  3403. end;
  3404. if po_public in fwpd.procoptions then
  3405. begin
  3406. item:=fwpd.aliasnames.first;
  3407. while assigned(item) do
  3408. begin
  3409. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  3410. item:=item.next;
  3411. end;
  3412. end;
  3413. { Release current procdef }
  3414. currpd.owner.deletedef(currpd);
  3415. currpd:=fwpd;
  3416. end
  3417. else
  3418. begin
  3419. { abstract methods aren't forward defined, but this }
  3420. { needs another error message }
  3421. if (po_abstractmethod in fwpd.procoptions) then
  3422. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  3423. else
  3424. begin
  3425. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  3426. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3427. end;
  3428. end;
  3429. { we found one proc with the same arguments, there are no others
  3430. so we can stop }
  3431. break;
  3432. end;
  3433. { check for allowing overload directive }
  3434. if not(m_fpc in current_settings.modeswitches) then
  3435. begin
  3436. { overload directive turns on overloading }
  3437. if ((po_overload in currpd.procoptions) or
  3438. (po_overload in fwpd.procoptions)) then
  3439. begin
  3440. { check if all procs have overloading, but not if the proc is a method or
  3441. already declared forward, then the check is already done }
  3442. if not(fwpd.hasforward or
  3443. assigned(currpd.struct) or
  3444. (currpd.forwarddef<>fwpd.forwarddef) or
  3445. ((po_overload in currpd.procoptions) and
  3446. (po_overload in fwpd.procoptions))) then
  3447. begin
  3448. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3449. break;
  3450. end
  3451. end
  3452. else
  3453. begin
  3454. if not(fwpd.forwarddef) then
  3455. begin
  3456. if (m_tp7 in current_settings.modeswitches) then
  3457. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  3458. else
  3459. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3460. break;
  3461. end;
  3462. end;
  3463. end; { equal arguments }
  3464. end;
  3465. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  3466. list }
  3467. if not forwardfound then
  3468. begin
  3469. { can happen in Delphi mode }
  3470. if (currpd.proctypeoption = potype_function) and
  3471. is_void(currpd.returndef) then
  3472. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  3473. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  3474. if not currpd.forwarddef and (po_public in currpd.procoptions) then
  3475. begin
  3476. item:=currpd.aliasnames.first;
  3477. while assigned(item) do
  3478. begin
  3479. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  3480. item:=item.next;
  3481. end;
  3482. end;
  3483. end;
  3484. proc_add_definition:=forwardfound;
  3485. end;
  3486. end.