pdecsub.pas 140 KB

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