pdecsub.pas 143 KB

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