pdecsub.pas 131 KB

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