pdecsub.pas 132 KB

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