pdecsub.pas 129 KB

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