pdecsub.pas 144 KB

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