pdecsub.pas 131 KB

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