2
0

pdecsub.pas 131 KB

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