pdecsub.pas 131 KB

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