pdecsub.pas 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  4. Does the parsing of the procedures/functions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pdecsub;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. tokens,symconst,symtype,symdef,symsym;
  23. type
  24. tpdflag=(
  25. pd_body, { directive needs a body }
  26. pd_implemen, { directive can be used implementation section }
  27. pd_interface, { directive can be used interface section }
  28. pd_object, { directive can be used object declaration }
  29. pd_procvar, { directive can be used procvar declaration }
  30. pd_notobject, { directive can not be used object declaration }
  31. pd_notobjintf, { directive can not be used interface declaration }
  32. pd_notprocvar { directive can not be used procvar declaration }
  33. );
  34. tpdflags=set of tpdflag;
  35. function is_proc_directive(tok:ttoken;isprocvar:boolean):boolean;
  36. procedure calc_parast(pd:tabstractprocdef);
  37. procedure insert_funcret_local(pd:tprocdef);
  38. function proc_add_definition(var pd:tprocdef):boolean;
  39. procedure handle_calling_convention(pd:tabstractprocdef);
  40. procedure parse_parameter_dec(pd:tabstractprocdef);
  41. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  42. procedure parse_var_proc_directives(sym:tsym);
  43. procedure parse_object_proc_directives(pd:tabstractprocdef);
  44. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  45. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  46. implementation
  47. uses
  48. {$ifdef delphi}
  49. sysutils,
  50. {$else delphi}
  51. strings,
  52. {$endif delphi}
  53. { common }
  54. cutils,cclasses,
  55. { global }
  56. globtype,globals,verbose,
  57. systems,
  58. cpuinfo,
  59. { aasm }
  60. aasmbase,
  61. { symtable }
  62. symbase,symtable,defutil,defcmp,paramgr,
  63. { pass 1 }
  64. node,htypechk,
  65. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  66. { parser }
  67. fmodule,scanner,
  68. pbase,pexpr,ptype,pdecl,
  69. { linking }
  70. import,gendef
  71. ;
  72. const
  73. { Please leave this here, this module should NOT use
  74. these variables.
  75. Declaring it as string here results in an error when compiling (PFV) }
  76. current_procinfo = 'error';
  77. procedure insert_funcret_para(pd:tabstractprocdef);
  78. var
  79. storepos : tfileposinfo;
  80. vs : tvarsym;
  81. begin
  82. if not is_void(pd.rettype.def) and
  83. paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  84. begin
  85. storepos:=akttokenpos;
  86. if pd.deftype=procdef then
  87. akttokenpos:=tprocdef(pd).fileinfo;
  88. { Generate result variable accessing function result }
  89. vs:=tvarsym.create('$result',vs_var,pd.rettype);
  90. include(vs.varoptions,vo_is_funcret);
  91. include(vs.varoptions,vo_regable);
  92. pd.parast.insert(vs);
  93. { For left to right add it at the end to be delphi compatible }
  94. if pd.proccalloption in pushleftright_pocalls then
  95. pd.concatpara(nil,vs.vartype,vs,nil,true)
  96. else
  97. pd.insertpara(vs.vartype,vs,nil,true);
  98. { Store the this symbol as funcretsym for procedures }
  99. if pd.deftype=procdef then
  100. tprocdef(pd).funcretsym:=vs;
  101. akttokenpos:=storepos;
  102. end;
  103. end;
  104. procedure insert_parentfp_para(pd:tabstractprocdef);
  105. var
  106. storepos : tfileposinfo;
  107. vs : tvarsym;
  108. begin
  109. if pd.parast.symtablelevel>normal_function_level then
  110. begin
  111. storepos:=akttokenpos;
  112. if pd.deftype=procdef then
  113. akttokenpos:=tprocdef(pd).fileinfo;
  114. { Generate result variable accessing function result }
  115. vs:=tvarsym.create('$parentfp',vs_var,voidpointertype);
  116. include(vs.varoptions,vo_is_parentfp);
  117. pd.parast.insert(vs);
  118. pd.insertpara(vs.vartype,vs,nil,true);
  119. akttokenpos:=storepos;
  120. end;
  121. end;
  122. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  123. var
  124. storepos : tfileposinfo;
  125. vs : tvarsym;
  126. tt : ttype;
  127. vsp : tvarspez;
  128. begin
  129. if (pd.deftype=procvardef) and
  130. pd.is_methodpointer then
  131. begin
  132. { Generate self variable }
  133. tt:=voidpointertype;
  134. vs:=tvarsym.create('$self',vs_value,tt);
  135. include(vs.varoptions,vo_is_self);
  136. { Insert as hidden parameter }
  137. pd.parast.insert(vs);
  138. pd.insertpara(vs.vartype,vs,nil,true);
  139. end
  140. else
  141. begin
  142. if (pd.deftype=procdef) and
  143. assigned(tprocdef(pd)._class) and
  144. (pd.parast.symtablelevel=normal_function_level) then
  145. begin
  146. storepos:=akttokenpos;
  147. akttokenpos:=tprocdef(pd).fileinfo;
  148. { Generate VMT variable for constructor/destructor }
  149. if pd.proctypeoption in [potype_constructor,potype_destructor] then
  150. begin
  151. { can't use classrefdef as type because inheriting
  152. will then always file because of a type mismatch }
  153. tt:=voidpointertype;
  154. vs:=tvarsym.create('$vmt',vs_value,tt);
  155. include(vs.varoptions,vo_is_vmt);
  156. { Insert as hidden parameter }
  157. pd.parast.insert(vs);
  158. pd.insertpara(vs.vartype,vs,nil,true);
  159. end;
  160. { Generate self variable, for classes we need
  161. to use the generic voidpointer to be compatible with
  162. methodpointers }
  163. vsp:=vs_value;
  164. if (po_staticmethod in pd.procoptions) or
  165. (po_classmethod in pd.procoptions) then
  166. begin
  167. tt.setdef(tprocdef(pd)._class);
  168. tt.setdef(tclassrefdef.create(tt));
  169. end
  170. else
  171. begin
  172. if is_object(tprocdef(pd)._class) then
  173. vsp:=vs_var;
  174. tt.setdef(tprocdef(pd)._class);
  175. end;
  176. vs:=tvarsym.create('$self',vsp,tt);
  177. include(vs.varoptions,vo_is_self);
  178. include(vs.varoptions,vo_regable);
  179. { Insert as hidden parameter }
  180. pd.parast.insert(vs);
  181. pd.insertpara(vs.vartype,vs,nil,true);
  182. akttokenpos:=storepos;
  183. end;
  184. end;
  185. end;
  186. procedure insert_funcret_local(pd:tprocdef);
  187. var
  188. storepos : tfileposinfo;
  189. vs : tvarsym;
  190. sl : tsymlist;
  191. begin
  192. if not is_void(pd.rettype.def) then
  193. begin
  194. storepos:=akttokenpos;
  195. akttokenpos:=pd.fileinfo;
  196. { We always need a localsymtable }
  197. if not assigned(pd.localst) then
  198. pd.insert_localst;
  199. { We need to insert a varsym for the result in the localst
  200. when it is returning in a register }
  201. if not paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  202. begin
  203. vs:=tvarsym.create('$result',vs_value,pd.rettype);
  204. include(vs.varoptions,vo_is_funcret);
  205. if tstoreddef(pd.rettype.def).is_intregable then
  206. include(vs.varoptions,vo_regable);
  207. if tstoreddef(pd.rettype.def).is_fpuregable then
  208. include(vs.varoptions,vo_fpuregable);
  209. pd.localst.insert(vs);
  210. pd.funcretsym:=vs;
  211. end;
  212. { insert the name of the procedure as alias for the function result,
  213. we can't use realname because that will not work for compilerprocs
  214. as the name is lowercase and unreachable from the code }
  215. if pd.resultname='' then
  216. pd.resultname:=pd.procsym.name;
  217. sl:=tsymlist.create;
  218. sl.addsym(sl_load,pd.funcretsym);
  219. vs:=tabsolutesym.create_ref(pd.resultname,pd.rettype,sl);
  220. include(vs.varoptions,vo_is_funcret);
  221. pd.localst.insert(vs);
  222. { insert result also if support is on }
  223. if (m_result in aktmodeswitches) then
  224. begin
  225. sl:=tsymlist.create;
  226. sl.addsym(sl_load,pd.funcretsym);
  227. vs:=tabsolutesym.create_ref('RESULT',pd.rettype,sl);
  228. include(vs.varoptions,vo_is_funcret);
  229. include(vs.varoptions,vo_is_result);
  230. pd.localst.insert(vs);
  231. end;
  232. akttokenpos:=storepos;
  233. end;
  234. end;
  235. procedure insert_hidden_para(pd:tabstractprocdef);
  236. var
  237. currpara : tparaitem;
  238. hvs : tvarsym;
  239. begin
  240. { walk from right to left, so we can insert the
  241. high parameters after the current parameter }
  242. currpara:=tparaitem(pd.para.last);
  243. while assigned(currpara) do
  244. begin
  245. { needs high parameter ? }
  246. if paramanager.push_high_param(currpara.paratyp,currpara.paratype.def,pd.proccalloption) then
  247. begin
  248. if assigned(currpara.parasym) then
  249. begin
  250. hvs:=tvarsym.create('$high'+tvarsym(currpara.parasym).name,vs_const,s32inttype);
  251. include(hvs.varoptions,vo_is_high_value);
  252. tvarsym(currpara.parasym).owner.insert(hvs);
  253. end
  254. else
  255. hvs:=nil;
  256. pd.concatpara(currpara,s32inttype,hvs,nil,true);
  257. end
  258. else
  259. begin
  260. { Give a warning that cdecl routines does not include high()
  261. support }
  262. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  263. paramanager.push_high_param(currpara.paratyp,currpara.paratype.def,pocall_default) then
  264. begin
  265. if is_open_string(currpara.paratype.def) then
  266. Message(parser_w_cdecl_no_openstring);
  267. if not (po_external in pd.procoptions) then
  268. Message(parser_w_cdecl_has_no_high);
  269. end;
  270. end;
  271. currpara:=tparaitem(currpara.previous);
  272. end;
  273. end;
  274. procedure check_c_para(p:tnamedindexitem;arg:pointer);
  275. begin
  276. if (tsym(p).typ<>varsym) then
  277. exit;
  278. with tvarsym(p) do
  279. begin
  280. case vartype.def.deftype of
  281. arraydef :
  282. begin
  283. if not is_variant_array(vartype.def) and
  284. not is_array_of_const(vartype.def) then
  285. begin
  286. if (varspez<>vs_var) then
  287. Message(parser_h_c_arrays_are_references);
  288. end;
  289. if is_array_of_const(vartype.def) and
  290. assigned(indexnext) and
  291. (tsym(indexnext).typ=varsym) and
  292. not(vo_is_high_value in tvarsym(indexnext).varoptions) then
  293. Message(parser_e_C_array_of_const_must_be_last);
  294. end;
  295. end;
  296. end;
  297. end;
  298. procedure parse_parameter_dec(pd:tabstractprocdef);
  299. {
  300. handle_procvar needs the same changes
  301. }
  302. var
  303. is_procvar : boolean;
  304. sc : tsinglelist;
  305. tt : ttype;
  306. arrayelementtype : ttype;
  307. vs : tvarsym;
  308. srsym : tsym;
  309. hs1 : string;
  310. varspez : Tvarspez;
  311. defaultvalue : tconstsym;
  312. defaultrequired : boolean;
  313. old_object_option : tsymoptions;
  314. currparast : tparasymtable;
  315. explicit_paraloc : boolean;
  316. locationstr : string;
  317. begin
  318. explicit_paraloc:=false;
  319. consume(_LKLAMMER);
  320. { Delphi/Kylix supports nonsense like }
  321. { procedure p(); }
  322. if try_to_consume(_RKLAMMER) and
  323. not(m_tp7 in aktmodeswitches) then
  324. exit;
  325. { parsing a proc or procvar ? }
  326. is_procvar:=(pd.deftype=procvardef);
  327. currparast:=tparasymtable(pd.parast);
  328. { reset }
  329. sc:=tsinglelist.create;
  330. defaultrequired:=false;
  331. { the variables are always public }
  332. old_object_option:=current_object_option;
  333. current_object_option:=[sp_public];
  334. inc(testcurobject);
  335. repeat
  336. if try_to_consume(_VAR) then
  337. varspez:=vs_var
  338. else
  339. if try_to_consume(_CONST) then
  340. varspez:=vs_const
  341. else
  342. if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  343. begin
  344. consume(_OUT);
  345. varspez:=vs_out
  346. end
  347. else
  348. if (token=_POINTPOINTPOINT) and (m_mac in aktmodeswitches) then
  349. begin
  350. consume(_POINTPOINTPOINT);
  351. include(pd.procoptions,po_varargs);
  352. break;
  353. end
  354. else
  355. varspez:=vs_value;
  356. defaultvalue:=nil;
  357. tt.reset;
  358. { read identifiers and insert with error type }
  359. sc.reset;
  360. repeat
  361. vs:=tvarsym.create(orgpattern,varspez,generrortype);
  362. currparast.insert(vs);
  363. if assigned(vs.owner) then
  364. sc.insert(vs)
  365. else
  366. vs.free;
  367. consume(_ID);
  368. until not try_to_consume(_COMMA);
  369. locationstr:='';
  370. { read type declaration, force reading for value and const paras }
  371. if (token=_COLON) or (varspez=vs_value) then
  372. begin
  373. consume(_COLON);
  374. { check for an open array }
  375. if token=_ARRAY then
  376. begin
  377. consume(_ARRAY);
  378. consume(_OF);
  379. { define range and type of range }
  380. tt.setdef(tarraydef.create(0,-1,s32inttype));
  381. { array of const ? }
  382. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  383. begin
  384. consume(_CONST);
  385. srsym:=searchsymonlyin(systemunit,'TVARREC');
  386. if not assigned(srsym) then
  387. InternalError(200404181);
  388. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  389. tarraydef(tt.def).IsArrayOfConst:=true;
  390. end
  391. else
  392. begin
  393. { define field type }
  394. single_type(arrayelementtype,hs1,false);
  395. tarraydef(tt.def).setelementtype(arrayelementtype);
  396. end;
  397. end
  398. else
  399. begin
  400. { open string ? }
  401. if (varspez=vs_var) and
  402. (
  403. (
  404. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  405. (cs_openstring in aktmoduleswitches) and
  406. not(cs_ansistrings in aktlocalswitches)
  407. ) or
  408. (idtoken=_OPENSTRING)) then
  409. begin
  410. consume(token);
  411. tt:=openshortstringtype;
  412. hs1:='openstring';
  413. end
  414. else
  415. begin
  416. { everything else }
  417. if (m_mac in aktmodeswitches) then
  418. try_to_consume(_UNIV); {currently does nothing}
  419. single_type(tt,hs1,false);
  420. end;
  421. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  422. begin
  423. if (idtoken=_LOCATION) then
  424. begin
  425. consume(_LOCATION);
  426. locationstr:=pattern;
  427. consume(_CSTRING);
  428. end
  429. else
  430. begin
  431. if explicit_paraloc then
  432. Message(parser_e_paraloc_all_paras);
  433. locationstr:='';
  434. end;
  435. end
  436. else
  437. locationstr:='';
  438. { default parameter }
  439. if (m_default_para in aktmodeswitches) then
  440. begin
  441. if try_to_consume(_EQUAL) then
  442. begin
  443. vs:=tvarsym(sc.first);
  444. if assigned(vs.listnext) then
  445. Message(parser_e_default_value_only_one_para);
  446. { prefix 'def' to the parameter name }
  447. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  448. include(defaultvalue.symoptions,sp_internal);
  449. if assigned(defaultvalue) then
  450. tprocdef(pd).parast.insert(defaultvalue);
  451. defaultrequired:=true;
  452. end
  453. else
  454. begin
  455. if defaultrequired then
  456. Message1(parser_e_default_value_expected_for_para,vs.name);
  457. end;
  458. end;
  459. end;
  460. end
  461. else
  462. begin
  463. {$ifndef UseNiceNames}
  464. hs1:='$$$';
  465. {$else UseNiceNames}
  466. hs1:='var';
  467. {$endif UseNiceNames}
  468. tt:=cformaltype;
  469. end;
  470. { File types are only allowed for var parameters }
  471. if (tt.def.deftype=filedef) and
  472. (varspez<>vs_var) then
  473. CGMessage(cg_e_file_must_call_by_reference);
  474. vs:=tvarsym(sc.first);
  475. while assigned(vs) do
  476. begin
  477. { update varsym }
  478. vs.vartype:=tt;
  479. { For proc vars we only need the definitions }
  480. if not is_procvar then
  481. begin
  482. if (varspez in [vs_var,vs_const,vs_out]) and
  483. paramanager.push_addr_param(varspez,tt.def,pd.proccalloption) then
  484. include(vs.varoptions,vo_regable);
  485. end;
  486. pd.concatpara(nil,tt,vs,defaultvalue,false);
  487. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  488. begin
  489. if locationstr<>'' then
  490. begin
  491. if assigned(sc.first.listnext) then
  492. Message(parser_e_paraloc_only_one_para);
  493. if (pd.para.first<>pd.para.last) and not(explicit_paraloc) then
  494. Message(parser_e_paraloc_all_paras);
  495. explicit_paraloc:=true;
  496. if not(paramanager.parseparaloc(tparaitem(pd.para.last),upper(locationstr))) then
  497. message(parser_e_illegal_explicit_paraloc);
  498. end
  499. else
  500. if explicit_paraloc then
  501. Message(parser_e_paraloc_all_paras);
  502. end;
  503. vs:=tvarsym(vs.listnext);
  504. end;
  505. until not try_to_consume(_SEMICOLON);
  506. if explicit_paraloc then
  507. begin
  508. pd.has_paraloc_info:=true;
  509. include(pd.procoptions,po_explicitparaloc);
  510. end;
  511. { remove parasymtable from stack }
  512. sc.free;
  513. { reset object options }
  514. dec(testcurobject);
  515. current_object_option:=old_object_option;
  516. consume(_RKLAMMER);
  517. end;
  518. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  519. var
  520. orgsp,sp : stringid;
  521. sym : tsym;
  522. srsymtable : tsymtable;
  523. storepos,
  524. procstartfilepos : tfileposinfo;
  525. searchagain : boolean;
  526. i : longint;
  527. st : tsymtable;
  528. aprocsym : tprocsym;
  529. begin
  530. { Save the position where this procedure really starts }
  531. procstartfilepos:=akttokenpos;
  532. result:=false;
  533. pd:=nil;
  534. aprocsym:=nil;
  535. if (potype=potype_operator) then
  536. begin
  537. sp:=overloaded_names[optoken];
  538. orgsp:=sp;
  539. end
  540. else
  541. begin
  542. sp:=pattern;
  543. orgsp:=orgpattern;
  544. consume(_ID);
  545. end;
  546. { examine interface map: function/procedure iname.functionname=locfuncname }
  547. if assigned(aclass) and
  548. assigned(aclass.implementedinterfaces) and
  549. (aclass.implementedinterfaces.count>0) and
  550. try_to_consume(_POINT) then
  551. begin
  552. storepos:=akttokenpos;
  553. akttokenpos:=procstartfilepos;
  554. { get interface syms}
  555. searchsym(sp,sym,srsymtable);
  556. if not assigned(sym) then
  557. begin
  558. identifier_not_found(orgsp);
  559. sym:=generrorsym;
  560. end;
  561. akttokenpos:=storepos;
  562. { qualifier is interface? }
  563. if (sym.typ=typesym) and
  564. (ttypesym(sym).restype.def.deftype=objectdef) then
  565. i:=aclass.implementedinterfaces.searchintf(ttypesym(sym).restype.def)
  566. else
  567. i:=-1;
  568. if (i=-1) then
  569. Message(parser_e_interface_id_expected);
  570. consume(_ID);
  571. consume(_EQUAL);
  572. if (token=_ID) then
  573. aclass.implementedinterfaces.addmappings(i,sp,pattern);
  574. consume(_ID);
  575. result:=true;
  576. exit;
  577. end;
  578. { method ? }
  579. if not assigned(aclass) and
  580. (potype<>potype_operator) and
  581. (symtablestack.symtablelevel=main_program_level) and
  582. try_to_consume(_POINT) then
  583. begin
  584. { search for object name }
  585. storepos:=akttokenpos;
  586. akttokenpos:=procstartfilepos;
  587. searchsym(sp,sym,srsymtable);
  588. if not assigned(sym) then
  589. begin
  590. identifier_not_found(orgsp);
  591. sym:=generrorsym;
  592. end;
  593. akttokenpos:=storepos;
  594. { consume proc name }
  595. sp:=pattern;
  596. orgsp:=orgpattern;
  597. procstartfilepos:=akttokenpos;
  598. consume(_ID);
  599. { qualifier is class name ? }
  600. if (sym.typ=typesym) and
  601. (ttypesym(sym).restype.def.deftype=objectdef) then
  602. begin
  603. aclass:=tobjectdef(ttypesym(sym).restype.def);
  604. aprocsym:=tprocsym(aclass.symtable.search(sp));
  605. { we solve this below }
  606. if assigned(aprocsym) then
  607. begin
  608. if aprocsym.typ<>procsym then
  609. begin
  610. { we use a different error message for tp7 so it looks more compatible }
  611. if (m_fpc in aktmodeswitches) then
  612. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  613. else
  614. Message(parser_e_methode_id_expected);
  615. { rename the name to an unique name to avoid an
  616. error when inserting the symbol in the symtable }
  617. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  618. aprocsym:=nil;
  619. end;
  620. end
  621. else
  622. begin
  623. Message(parser_e_methode_id_expected);
  624. { recover by making it a normal procedure instead of method }
  625. aclass:=nil;
  626. end;
  627. end
  628. else
  629. Message(parser_e_class_id_expected);
  630. end
  631. else
  632. begin
  633. { check for constructor/destructor which is not allowed here }
  634. if (not parse_only) and
  635. (potype in [potype_constructor,potype_destructor]) then
  636. Message(parser_e_constructors_always_objects);
  637. repeat
  638. searchagain:=false;
  639. akttokenpos:=procstartfilepos;
  640. aprocsym:=tprocsym(symtablestack.search(sp));
  641. if not(parse_only) and
  642. not assigned(aprocsym) and
  643. (symtablestack.symtabletype=staticsymtable) and
  644. assigned(symtablestack.next) and
  645. (symtablestack.next.unitid=0) then
  646. begin
  647. { The procedure we prepare for is in the implementation
  648. part of the unit we compile. It is also possible that we
  649. are compiling a program, which is also some kind of
  650. implementaion part.
  651. We need to find out if the procedure is global. If it is
  652. global, it is in the global symtable.}
  653. aprocsym:=tprocsym(symtablestack.next.search(sp));
  654. end;
  655. { Check if overloaded is a procsym }
  656. if assigned(aprocsym) and
  657. (aprocsym.typ<>procsym) then
  658. begin
  659. { when the other symbol is a unit symbol then hide the unit
  660. symbol }
  661. if (aprocsym.typ=unitsym) then
  662. begin
  663. aprocsym.owner.rename(aprocsym.name,'hidden'+aprocsym.name);
  664. searchagain:=true;
  665. end
  666. else
  667. begin
  668. { we use a different error message for tp7 so it looks more compatible }
  669. if (m_fpc in aktmodeswitches) then
  670. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  671. else
  672. DuplicateSym(aprocsym);
  673. { rename the name to an unique name to avoid an
  674. error when inserting the symbol in the symtable }
  675. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  676. { generate a new aktprocsym }
  677. aprocsym:=nil;
  678. end;
  679. end;
  680. until not searchagain;
  681. end;
  682. { test again if assigned, it can be reset to recover }
  683. if not assigned(aprocsym) then
  684. begin
  685. { create a new procsym and set the real filepos }
  686. akttokenpos:=procstartfilepos;
  687. { for operator we have only one procsym for each overloaded
  688. operation }
  689. if (potype=potype_operator) then
  690. begin
  691. Aprocsym:=Tprocsym(symtablestack.search(sp));
  692. if Aprocsym=nil then
  693. Aprocsym:=tprocsym.create('$'+sp);
  694. end
  695. else
  696. aprocsym:=tprocsym.create(orgsp);
  697. symtablestack.insert(aprocsym);
  698. end;
  699. { to get the correct symtablelevel we must ignore objectsymtables }
  700. st:=symtablestack;
  701. while not(st.symtabletype in [staticsymtable,globalsymtable,localsymtable]) do
  702. st:=st.next;
  703. pd:=tprocdef.create(st.symtablelevel+1);
  704. pd._class:=aclass;
  705. pd.procsym:=aprocsym;
  706. pd.proctypeoption:=potype;
  707. { methods need to be exported }
  708. if assigned(aclass) and
  709. (
  710. (symtablestack.symtabletype=objectsymtable) or
  711. (symtablestack.symtablelevel=main_program_level)
  712. ) then
  713. include(pd.procoptions,po_public);
  714. { symbol options that need to be kept per procdef }
  715. pd.fileinfo:=procstartfilepos;
  716. pd.symoptions:=current_object_option;
  717. { parse parameters }
  718. if token=_LKLAMMER then
  719. parse_parameter_dec(pd);
  720. result:=true;
  721. end;
  722. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  723. var
  724. pd : tprocdef;
  725. hs : string;
  726. isclassmethod : boolean;
  727. begin
  728. pd:=nil;
  729. { read class method }
  730. if try_to_consume(_CLASS) then
  731. begin
  732. { class method only allowed for procedures and functions }
  733. if not(token in [_FUNCTION,_PROCEDURE]) then
  734. Message(parser_e_procedure_or_function_expected);
  735. isclassmethod:=true;
  736. end
  737. else
  738. isclassmethod:=false;
  739. case token of
  740. _FUNCTION :
  741. begin
  742. consume(_FUNCTION);
  743. if parse_proc_head(aclass,potype_none,pd) then
  744. begin
  745. { pd=nil when it is a interface mapping }
  746. if assigned(pd) then
  747. begin
  748. if try_to_consume(_COLON) then
  749. begin
  750. inc(testcurobject);
  751. single_type(pd.rettype,hs,false);
  752. pd.test_if_fpu_result;
  753. dec(testcurobject);
  754. end
  755. else
  756. begin
  757. if (
  758. not(is_interface(pd._class)) and
  759. not(pd.forwarddef)
  760. ) or
  761. (m_repeat_forward in aktmodeswitches) then
  762. begin
  763. consume(_COLON);
  764. consume_all_until(_SEMICOLON);
  765. end;
  766. end;
  767. if isclassmethod then
  768. include(pd.procoptions,po_classmethod);
  769. end;
  770. end
  771. else
  772. begin
  773. { recover }
  774. consume(_COLON);
  775. consume_all_until(_SEMICOLON);
  776. end;
  777. end;
  778. _PROCEDURE :
  779. begin
  780. consume(_PROCEDURE);
  781. if parse_proc_head(aclass,potype_none,pd) then
  782. begin
  783. { pd=nil when it is a interface mapping }
  784. if assigned(pd) then
  785. begin
  786. pd.rettype:=voidtype;
  787. if isclassmethod then
  788. include(pd.procoptions,po_classmethod);
  789. end;
  790. end;
  791. end;
  792. _CONSTRUCTOR :
  793. begin
  794. consume(_CONSTRUCTOR);
  795. parse_proc_head(aclass,potype_constructor,pd);
  796. if assigned(pd) and
  797. assigned(pd._class) then
  798. begin
  799. { Set return type, class constructors return the
  800. created instance, object constructors return boolean }
  801. if is_class(pd._class) then
  802. pd.rettype.setdef(pd._class)
  803. else
  804. pd.rettype:=booltype;
  805. end;
  806. end;
  807. _DESTRUCTOR :
  808. begin
  809. consume(_DESTRUCTOR);
  810. parse_proc_head(aclass,potype_destructor,pd);
  811. if assigned(pd) then
  812. pd.rettype:=voidtype;
  813. end;
  814. _OPERATOR :
  815. begin
  816. consume(_OPERATOR);
  817. if (token in [first_overloaded..last_overloaded]) then
  818. begin
  819. optoken:=token;
  820. end
  821. else
  822. begin
  823. Message(parser_e_overload_operator_failed);
  824. { Use the dummy NOTOKEN that is also declared
  825. for the overloaded_operator[] }
  826. optoken:=NOTOKEN;
  827. end;
  828. consume(token);
  829. parse_proc_head(aclass,potype_operator,pd);
  830. if assigned(pd) then
  831. begin
  832. if pd.parast.symtablelevel>normal_function_level then
  833. Message(parser_e_no_local_operator);
  834. if token<>_ID then
  835. begin
  836. if not(m_result in aktmodeswitches) then
  837. consume(_ID);
  838. end
  839. else
  840. begin
  841. pd.resultname:=orgpattern;
  842. consume(_ID);
  843. end;
  844. if not try_to_consume(_COLON) then
  845. begin
  846. consume(_COLON);
  847. pd.rettype:=generrortype;
  848. consume_all_until(_SEMICOLON);
  849. end
  850. else
  851. begin
  852. single_type(pd.rettype,hs,false);
  853. pd.test_if_fpu_result;
  854. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  855. ((pd.rettype.def.deftype<>orddef) or
  856. (torddef(pd.rettype.def).typ<>bool8bit)) then
  857. Message(parser_e_comparative_operator_return_boolean);
  858. if (optoken=_ASSIGNMENT) and
  859. equal_defs(pd.rettype.def,
  860. tvarsym(pd.parast.symindex.first).vartype.def) then
  861. message(parser_e_no_such_assignment)
  862. else if not isoperatoracceptable(pd,optoken) then
  863. Message(parser_e_overload_impossible);
  864. end;
  865. end
  866. else
  867. begin
  868. { recover }
  869. try_to_consume(_ID);
  870. consume(_COLON);
  871. consume_all_until(_SEMICOLON);
  872. end;
  873. end;
  874. end;
  875. { support procedure proc stdcall export; }
  876. if not(is_proc_directive(token,false)) then
  877. consume(_SEMICOLON);
  878. result:=pd;
  879. end;
  880. {****************************************************************************
  881. Procedure directive handlers
  882. ****************************************************************************}
  883. procedure pd_far(pd:tabstractprocdef);
  884. begin
  885. Message1(parser_w_proc_directive_ignored,'FAR');
  886. end;
  887. procedure pd_near(pd:tabstractprocdef);
  888. begin
  889. Message1(parser_w_proc_directive_ignored,'NEAR');
  890. end;
  891. procedure pd_export(pd:tabstractprocdef);
  892. begin
  893. if pd.deftype<>procdef then
  894. internalerror(200304264);
  895. if assigned(tprocdef(pd)._class) then
  896. Message(parser_e_methods_dont_be_export);
  897. if pd.parast.symtablelevel>normal_function_level then
  898. Message(parser_e_dont_nest_export);
  899. { only os/2 and emx need this }
  900. if target_info.system in [system_i386_os2,system_i386_emx] then
  901. begin
  902. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  903. if cs_link_deffile in aktglobalswitches then
  904. deffile.AddExport(tprocdef(pd).mangledname);
  905. end;
  906. end;
  907. procedure pd_forward(pd:tabstractprocdef);
  908. begin
  909. if pd.deftype<>procdef then
  910. internalerror(200304265);
  911. tprocdef(pd).forwarddef:=true;
  912. end;
  913. procedure pd_alias(pd:tabstractprocdef);
  914. begin
  915. if pd.deftype<>procdef then
  916. internalerror(200304266);
  917. consume(_COLON);
  918. tprocdef(pd).aliasnames.insert(get_stringconst);
  919. end;
  920. procedure pd_asmname(pd:tabstractprocdef);
  921. begin
  922. if pd.deftype<>procdef then
  923. internalerror(200304267);
  924. tprocdef(pd).setmangledname(target_info.Cprefix+pattern);
  925. if token=_CCHAR then
  926. consume(_CCHAR)
  927. else
  928. consume(_CSTRING);
  929. { we don't need anything else }
  930. tprocdef(pd).forwarddef:=false;
  931. end;
  932. procedure pd_inline(pd:tabstractprocdef);
  933. var
  934. hp : tparaitem;
  935. begin
  936. { check if there is an array of const }
  937. hp:=tparaitem(pd.para.first);
  938. while assigned(hp) do
  939. begin
  940. if assigned(hp.paratype.def) and
  941. (hp.paratype.def.deftype=arraydef) then
  942. begin
  943. with tarraydef(hp.paratype.def) do
  944. if IsVariant or IsConstructor {or IsArrayOfConst} then
  945. begin
  946. Message1(parser_w_not_supported_for_inline,'array of const');
  947. Message(parser_w_inlining_disabled);
  948. pd.proccalloption:=pocall_default;
  949. end;
  950. end;
  951. hp:=tparaitem(hp.next);
  952. end;
  953. end;
  954. procedure pd_intern(pd:tabstractprocdef);
  955. begin
  956. if pd.deftype<>procdef then
  957. internalerror(200304268);
  958. consume(_COLON);
  959. tprocdef(pd).extnumber:=get_intconst;
  960. end;
  961. procedure pd_interrupt(pd:tabstractprocdef);
  962. begin
  963. if pd.parast.symtablelevel>normal_function_level then
  964. Message(parser_e_dont_nest_interrupt);
  965. end;
  966. procedure pd_abstract(pd:tabstractprocdef);
  967. begin
  968. if pd.deftype<>procdef then
  969. internalerror(200304269);
  970. if (po_virtualmethod in pd.procoptions) then
  971. include(pd.procoptions,po_abstractmethod)
  972. else
  973. Message(parser_e_only_virtual_methods_abstract);
  974. { the method is defined }
  975. tprocdef(pd).forwarddef:=false;
  976. end;
  977. procedure pd_virtual(pd:tabstractprocdef);
  978. {$ifdef WITHDMT}
  979. var
  980. pt : tnode;
  981. {$endif WITHDMT}
  982. begin
  983. if pd.deftype<>procdef then
  984. internalerror(2003042610);
  985. if (pd.proctypeoption=potype_constructor) and
  986. is_object(tprocdef(pd)._class) then
  987. Message(parser_e_constructor_cannot_be_not_virtual);
  988. {$ifdef WITHDMT}
  989. if is_object(tprocdef(pd)._class) and
  990. (token<>_SEMICOLON) then
  991. begin
  992. { any type of parameter is allowed here! }
  993. pt:=comp_expr(true);
  994. if is_constintnode(pt) then
  995. begin
  996. include(pd.procoptions,po_msgint);
  997. pd.messageinf.i:=pt^.value;
  998. end
  999. else
  1000. Message(parser_e_ill_msg_expr);
  1001. disposetree(pt);
  1002. end;
  1003. {$endif WITHDMT}
  1004. end;
  1005. procedure pd_static(pd:tabstractprocdef);
  1006. begin
  1007. if (cs_static_keyword in aktmoduleswitches) then
  1008. begin
  1009. if pd.deftype=procdef then
  1010. include(tprocdef(pd).procsym.symoptions,sp_static);
  1011. include(pd.procoptions,po_staticmethod);
  1012. end;
  1013. end;
  1014. procedure pd_override(pd:tabstractprocdef);
  1015. begin
  1016. if pd.deftype<>procdef then
  1017. internalerror(2003042611);
  1018. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1019. Message(parser_e_no_object_override);
  1020. end;
  1021. procedure pd_overload(pd:tabstractprocdef);
  1022. begin
  1023. if pd.deftype<>procdef then
  1024. internalerror(2003042612);
  1025. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1026. end;
  1027. procedure pd_message(pd:tabstractprocdef);
  1028. var
  1029. pt : tnode;
  1030. begin
  1031. if pd.deftype<>procdef then
  1032. internalerror(2003042613);
  1033. if not is_class(tprocdef(pd)._class) then
  1034. Message(parser_e_msg_only_for_classes);
  1035. { check parameter type }
  1036. if ((pd.minparacount<>1) or
  1037. (pd.maxparacount<>1) or
  1038. (TParaItem(pd.Para.first).paratyp<>vs_var)) then
  1039. Message(parser_e_ill_msg_param);
  1040. pt:=comp_expr(true);
  1041. if pt.nodetype=stringconstn then
  1042. begin
  1043. include(pd.procoptions,po_msgstr);
  1044. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1045. end
  1046. else
  1047. if is_constintnode(pt) then
  1048. begin
  1049. include(pd.procoptions,po_msgint);
  1050. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1051. end
  1052. else
  1053. Message(parser_e_ill_msg_expr);
  1054. pt.free;
  1055. end;
  1056. procedure pd_reintroduce(pd:tabstractprocdef);
  1057. begin
  1058. if pd.deftype<>procdef then
  1059. internalerror(200401211);
  1060. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1061. Message(parser_e_no_object_reintroduce);
  1062. end;
  1063. procedure pd_syscall(pd:tabstractprocdef);
  1064. var
  1065. sym : tsym;
  1066. symtable : tsymtable;
  1067. begin
  1068. if pd.deftype<>procdef then
  1069. internalerror(2003042614);
  1070. tprocdef(pd).forwarddef:=false;
  1071. {$ifdef powerpc}
  1072. if target_info.system in [system_powerpc_morphos,system_m68k_amiga] then
  1073. begin
  1074. pd.has_paraloc_info:=true;
  1075. include(pd.procoptions,po_explicitparaloc);
  1076. if consume_sym(sym,symtable) then
  1077. begin
  1078. if (sym.typ=varsym) and
  1079. (is_voidpointer(tvarsym(sym).vartype.def) or
  1080. is_32bitint(tvarsym(sym).vartype.def)) then
  1081. begin
  1082. tprocdef(pd).libsym:=sym;
  1083. pd.concatpara(nil,tvarsym(sym).vartype,tvarsym(sym),nil,true);
  1084. paramanager.parseparaloc(tparaitem(pd.para.last),'A6');
  1085. end
  1086. else
  1087. Message(parser_e_32bitint_or_pointer_variable_expected);
  1088. end;
  1089. end;
  1090. {$endif powerpc}
  1091. tprocdef(pd).extnumber:=get_intconst;
  1092. end;
  1093. procedure pd_external(pd:tabstractprocdef);
  1094. {
  1095. If import_dll=nil the procedure is assumed to be in another
  1096. object file. In that object file it should have the name to
  1097. which import_name is pointing to. Otherwise, the procedure is
  1098. assumed to be in the DLL to which import_dll is pointing to. In
  1099. that case either import_nr<>0 or import_name<>nil is true, so
  1100. the procedure is either imported by number or by name. (DM)
  1101. }
  1102. var
  1103. import_dll,
  1104. import_name : string;
  1105. import_nr : word;
  1106. hpd : tprocdef;
  1107. begin
  1108. if pd.deftype<>procdef then
  1109. internalerror(2003042615);
  1110. tprocdef(pd).forwarddef:=false;
  1111. { forbid local external procedures }
  1112. if pd.parast.symtablelevel>normal_function_level then
  1113. Message(parser_e_no_local_external);
  1114. { If the procedure should be imported from a DLL, a constant string follows.
  1115. This isn't really correct, an contant string expression follows
  1116. so we check if an semicolon follows, else a string constant have to
  1117. follow (FK) }
  1118. import_nr:=0;
  1119. import_name:='';
  1120. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1121. begin
  1122. import_dll:=get_stringconst;
  1123. if (idtoken=_NAME) then
  1124. begin
  1125. consume(_NAME);
  1126. import_name:=get_stringconst;
  1127. end;
  1128. if (idtoken=_INDEX) then
  1129. begin
  1130. {After the word index follows the index number in the DLL.}
  1131. consume(_INDEX);
  1132. import_nr:=get_intconst;
  1133. end;
  1134. { default is to used the realname of the procedure }
  1135. if (import_nr=0) and (import_name='') then
  1136. import_name:=tprocdef(pd).procsym.realname;
  1137. { create importlib if not already done }
  1138. if not(current_module.uses_imports) then
  1139. begin
  1140. current_module.uses_imports:=true;
  1141. importlib.preparelib(current_module.modulename^);
  1142. end;
  1143. if not(m_repeat_forward in aktmodeswitches) then
  1144. begin
  1145. { we can only have one overloaded here ! }
  1146. if tprocsym(tprocdef(pd).procsym).procdef_count>1 then
  1147. hpd:=tprocsym(tprocdef(pd).procsym).procdef[2]
  1148. else
  1149. hpd:=tprocdef(pd);
  1150. end
  1151. else
  1152. hpd:=tprocdef(pd);
  1153. importlib.importprocedure(hpd,import_dll,import_nr,import_name);
  1154. end
  1155. else
  1156. begin
  1157. if (idtoken=_NAME) then
  1158. begin
  1159. consume(_NAME);
  1160. import_name:=get_stringconst;
  1161. tprocdef(pd).setmangledname(import_name);
  1162. end;
  1163. end;
  1164. end;
  1165. type
  1166. pd_handler=procedure(pd:tabstractprocdef);
  1167. proc_dir_rec=record
  1168. idtok : ttoken;
  1169. pd_flags : tpdflags;
  1170. handler : pd_handler;
  1171. pocall : tproccalloption;
  1172. pooption : tprocoptions;
  1173. mutexclpocall : tproccalloptions;
  1174. mutexclpotype : tproctypeoptions;
  1175. mutexclpo : tprocoptions;
  1176. end;
  1177. const
  1178. {Should contain the number of procedure directives we support.}
  1179. num_proc_directives=36;
  1180. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1181. (
  1182. (
  1183. idtok:_ABSTRACT;
  1184. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1185. handler : {$ifdef FPCPROCVAR}@{$endif}pd_abstract;
  1186. pocall : pocall_none;
  1187. pooption : [po_abstractmethod];
  1188. mutexclpocall : [pocall_internproc,pocall_inline];
  1189. mutexclpotype : [];
  1190. mutexclpo : [po_exports,po_interrupt,po_external]
  1191. ),(
  1192. idtok:_ALIAS;
  1193. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1194. handler : {$ifdef FPCPROCVAR}@{$endif}pd_alias;
  1195. pocall : pocall_none;
  1196. pooption : [];
  1197. mutexclpocall : [pocall_inline];
  1198. mutexclpotype : [];
  1199. mutexclpo : [po_external]
  1200. ),(
  1201. idtok:_ASMNAME;
  1202. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1203. handler : {$ifdef FPCPROCVAR}@{$endif}pd_asmname;
  1204. pocall : pocall_cdecl;
  1205. pooption : [po_external];
  1206. mutexclpocall : [pocall_internproc,pocall_inline];
  1207. mutexclpotype : [];
  1208. mutexclpo : [po_external]
  1209. ),(
  1210. idtok:_ASSEMBLER;
  1211. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1212. handler : nil;
  1213. pocall : pocall_none;
  1214. pooption : [po_assembler];
  1215. mutexclpocall : [];
  1216. mutexclpotype : [];
  1217. mutexclpo : [po_external]
  1218. ),(
  1219. idtok:_C; {same as cdecl for mode mac}
  1220. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1221. handler : nil;
  1222. pocall : pocall_cdecl;
  1223. pooption : [];
  1224. mutexclpocall : [];
  1225. mutexclpotype : [potype_constructor,potype_destructor];
  1226. mutexclpo : [po_assembler,po_external]
  1227. ),(
  1228. idtok:_CDECL;
  1229. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1230. handler : nil;
  1231. pocall : pocall_cdecl;
  1232. pooption : [];
  1233. mutexclpocall : [];
  1234. mutexclpotype : [potype_constructor,potype_destructor];
  1235. mutexclpo : [po_assembler,po_external]
  1236. ),(
  1237. idtok:_DYNAMIC;
  1238. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1239. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1240. pocall : pocall_none;
  1241. pooption : [po_virtualmethod];
  1242. mutexclpocall : [pocall_internproc,pocall_inline];
  1243. mutexclpotype : [];
  1244. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod]
  1245. ),(
  1246. idtok:_EXPORT;
  1247. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1248. handler : {$ifdef FPCPROCVAR}@{$endif}pd_export;
  1249. pocall : pocall_none;
  1250. pooption : [po_exports,po_public];
  1251. mutexclpocall : [pocall_internproc,pocall_inline];
  1252. mutexclpotype : [potype_constructor,potype_destructor];
  1253. mutexclpo : [po_external,po_interrupt]
  1254. ),(
  1255. idtok:_EXTERNAL;
  1256. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1257. handler : {$ifdef FPCPROCVAR}@{$endif}pd_external;
  1258. pocall : pocall_none;
  1259. pooption : [po_external];
  1260. mutexclpocall : [pocall_internproc,pocall_inline,pocall_syscall];
  1261. mutexclpotype : [potype_constructor,potype_destructor];
  1262. mutexclpo : [po_exports,po_interrupt,po_assembler]
  1263. ),(
  1264. idtok:_FAR;
  1265. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1266. handler : {$ifdef FPCPROCVAR}@{$endif}pd_far;
  1267. pocall : pocall_none;
  1268. pooption : [];
  1269. mutexclpocall : [pocall_internproc,pocall_inline];
  1270. mutexclpotype : [];
  1271. mutexclpo : []
  1272. ),(
  1273. idtok:_FAR16;
  1274. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1275. handler : nil;
  1276. pocall : pocall_far16;
  1277. pooption : [];
  1278. mutexclpocall : [];
  1279. mutexclpotype : [];
  1280. mutexclpo : [po_external]
  1281. ),(
  1282. idtok:_FORWARD;
  1283. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1284. handler : {$ifdef FPCPROCVAR}@{$endif}pd_forward;
  1285. pocall : pocall_none;
  1286. pooption : [];
  1287. mutexclpocall : [pocall_internproc,pocall_inline];
  1288. mutexclpotype : [];
  1289. mutexclpo : [po_external]
  1290. ),(
  1291. idtok:_OLDFPCCALL;
  1292. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1293. handler : nil;
  1294. pocall : pocall_oldfpccall;
  1295. pooption : [];
  1296. mutexclpocall : [];
  1297. mutexclpotype : [];
  1298. mutexclpo : []
  1299. ),(
  1300. idtok:_INLINE;
  1301. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1302. handler : {$ifdef FPCPROCVAR}@{$endif}pd_inline;
  1303. pocall : pocall_inline;
  1304. pooption : [];
  1305. mutexclpocall : [];
  1306. mutexclpotype : [potype_constructor,potype_destructor];
  1307. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1308. ),(
  1309. idtok:_INTERNCONST;
  1310. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1311. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1312. pocall : pocall_none;
  1313. pooption : [po_internconst];
  1314. mutexclpocall : [];
  1315. mutexclpotype : [potype_operator];
  1316. mutexclpo : []
  1317. ),(
  1318. idtok:_INTERNPROC;
  1319. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1320. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1321. pocall : pocall_internproc;
  1322. pooption : [];
  1323. mutexclpocall : [];
  1324. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1325. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1326. ),(
  1327. idtok:_INTERRUPT;
  1328. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1329. handler : {$ifdef FPCPROCVAR}@{$endif}pd_interrupt;
  1330. pocall : pocall_none;
  1331. pooption : [po_interrupt];
  1332. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1333. pocall_inline,pocall_pascal,pocall_far16,pocall_oldfpccall];
  1334. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1335. mutexclpo : [po_external]
  1336. ),(
  1337. idtok:_IOCHECK;
  1338. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1339. handler : nil;
  1340. pocall : pocall_none;
  1341. pooption : [po_iocheck];
  1342. mutexclpocall : [pocall_internproc];
  1343. mutexclpotype : [];
  1344. mutexclpo : [po_external]
  1345. ),(
  1346. idtok:_MESSAGE;
  1347. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1348. handler : {$ifdef FPCPROCVAR}@{$endif}pd_message;
  1349. pocall : pocall_none;
  1350. pooption : []; { can be po_msgstr or po_msgint }
  1351. mutexclpocall : [pocall_inline,pocall_internproc];
  1352. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1353. mutexclpo : [po_interrupt,po_external]
  1354. ),(
  1355. idtok:_NEAR;
  1356. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1357. handler : {$ifdef FPCPROCVAR}@{$endif}pd_near;
  1358. pocall : pocall_none;
  1359. pooption : [];
  1360. mutexclpocall : [pocall_internproc];
  1361. mutexclpotype : [];
  1362. mutexclpo : []
  1363. ),(
  1364. idtok:_OVERLOAD;
  1365. pd_flags : [pd_implemen,pd_interface,pd_body];
  1366. handler : {$ifdef FPCPROCVAR}@{$endif}pd_overload;
  1367. pocall : pocall_none;
  1368. pooption : [po_overload];
  1369. mutexclpocall : [pocall_internproc];
  1370. mutexclpotype : [];
  1371. mutexclpo : []
  1372. ),(
  1373. idtok:_OVERRIDE;
  1374. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1375. handler : {$ifdef FPCPROCVAR}@{$endif}pd_override;
  1376. pocall : pocall_none;
  1377. pooption : [po_overridingmethod,po_virtualmethod];
  1378. mutexclpocall : [pocall_inline,pocall_internproc];
  1379. mutexclpotype : [];
  1380. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1381. ),(
  1382. idtok:_PASCAL;
  1383. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1384. handler : nil;
  1385. pocall : pocall_pascal;
  1386. pooption : [];
  1387. mutexclpocall : [];
  1388. mutexclpotype : [potype_constructor,potype_destructor];
  1389. mutexclpo : [po_external]
  1390. ),(
  1391. idtok:_PUBLIC;
  1392. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1393. handler : nil;
  1394. pocall : pocall_none;
  1395. pooption : [po_public];
  1396. mutexclpocall : [pocall_internproc,pocall_inline];
  1397. mutexclpotype : [];
  1398. mutexclpo : [po_external]
  1399. ),(
  1400. idtok:_REGISTER;
  1401. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1402. handler : nil;
  1403. pocall : pocall_register;
  1404. pooption : [];
  1405. mutexclpocall : [];
  1406. mutexclpotype : [potype_constructor,potype_destructor];
  1407. mutexclpo : [po_external]
  1408. ),(
  1409. idtok:_REINTRODUCE;
  1410. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1411. handler : {$ifdef FPCPROCVAR}@{$endif}pd_reintroduce;
  1412. pocall : pocall_none;
  1413. pooption : [po_reintroduce];
  1414. mutexclpocall : [pocall_inline,pocall_internproc];
  1415. mutexclpotype : [];
  1416. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod]
  1417. ),(
  1418. idtok:_SAFECALL;
  1419. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1420. handler : nil;
  1421. pocall : pocall_safecall;
  1422. pooption : [];
  1423. mutexclpocall : [];
  1424. mutexclpotype : [potype_constructor,potype_destructor];
  1425. mutexclpo : [po_external]
  1426. ),(
  1427. idtok:_SAVEREGISTERS;
  1428. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1429. handler : nil;
  1430. pocall : pocall_none;
  1431. pooption : [po_saveregisters];
  1432. mutexclpocall : [pocall_internproc];
  1433. mutexclpotype : [potype_constructor,potype_destructor];
  1434. mutexclpo : [po_external]
  1435. ),(
  1436. idtok:_SOFTFLOAT;
  1437. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1438. handler : nil;
  1439. pocall : pocall_softfloat;
  1440. pooption : [];
  1441. mutexclpocall : [];
  1442. mutexclpotype : [potype_constructor,potype_destructor];
  1443. { it's available with po_external because the libgcc floating point routines on the arm
  1444. uses this calling convention }
  1445. mutexclpo : []
  1446. ),(
  1447. idtok:_STATIC;
  1448. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1449. handler : {$ifdef FPCPROCVAR}@{$endif}pd_static;
  1450. pocall : pocall_none;
  1451. pooption : [po_staticmethod];
  1452. mutexclpocall : [pocall_inline,pocall_internproc];
  1453. mutexclpotype : [potype_constructor,potype_destructor];
  1454. mutexclpo : [po_external,po_interrupt,po_exports]
  1455. ),(
  1456. idtok:_STDCALL;
  1457. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1458. handler : nil;
  1459. pocall : pocall_stdcall;
  1460. pooption : [];
  1461. mutexclpocall : [];
  1462. mutexclpotype : [potype_constructor,potype_destructor];
  1463. mutexclpo : [po_external]
  1464. ),(
  1465. idtok:_SYSCALL;
  1466. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf];
  1467. handler : {$ifdef FPCPROCVAR}@{$endif}pd_syscall;
  1468. pocall : pocall_syscall;
  1469. pooption : [];
  1470. mutexclpocall : [];
  1471. mutexclpotype : [potype_constructor,potype_destructor];
  1472. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1473. ),(
  1474. idtok:_VIRTUAL;
  1475. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1476. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1477. pocall : pocall_none;
  1478. pooption : [po_virtualmethod];
  1479. mutexclpocall : [pocall_inline,pocall_internproc];
  1480. mutexclpotype : [];
  1481. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod]
  1482. ),(
  1483. idtok:_CPPDECL;
  1484. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1485. handler : nil;
  1486. pocall : pocall_cppdecl;
  1487. pooption : [];
  1488. mutexclpocall : [];
  1489. mutexclpotype : [potype_constructor,potype_destructor];
  1490. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1491. ),(
  1492. idtok:_VARARGS;
  1493. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1494. handler : nil;
  1495. pocall : pocall_none;
  1496. pooption : [po_varargs];
  1497. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1498. pocall_inline,pocall_far16,pocall_oldfpccall];
  1499. mutexclpotype : [];
  1500. mutexclpo : [po_assembler,po_interrupt]
  1501. ),(
  1502. idtok:_COMPILERPROC;
  1503. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1504. handler : nil;
  1505. pocall : pocall_compilerproc;
  1506. pooption : [];
  1507. mutexclpocall : [];
  1508. mutexclpotype : [potype_constructor,potype_destructor];
  1509. mutexclpo : [po_interrupt]
  1510. )
  1511. );
  1512. function is_proc_directive(tok:ttoken;isprocvar:boolean):boolean;
  1513. var
  1514. i : longint;
  1515. begin
  1516. is_proc_directive:=false;
  1517. for i:=1 to num_proc_directives do
  1518. if proc_direcdata[i].idtok=idtoken then
  1519. begin
  1520. if (not isprocvar) or
  1521. (pd_procvar in proc_direcdata[i].pd_flags) then
  1522. is_proc_directive:=true;
  1523. exit;
  1524. end;
  1525. end;
  1526. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1527. {
  1528. Parse the procedure directive, returns true if a correct directive is found
  1529. }
  1530. var
  1531. p : longint;
  1532. found : boolean;
  1533. name : stringid;
  1534. begin
  1535. parse_proc_direc:=false;
  1536. name:=tokeninfo^[idtoken].str;
  1537. found:=false;
  1538. { Hint directive? Then exit immediatly }
  1539. if (m_hintdirective in aktmodeswitches) then
  1540. begin
  1541. case idtoken of
  1542. _LIBRARY,
  1543. _PLATFORM,
  1544. _UNIMPLEMENTED,
  1545. _DEPRECATED :
  1546. exit;
  1547. end;
  1548. end;
  1549. { C directive is MAC only, because it breaks too much existing code
  1550. on other platforms (PFV) }
  1551. if (idtoken=_C) and
  1552. not(m_mac in aktmodeswitches) then
  1553. exit;
  1554. { retrieve data for directive if found }
  1555. for p:=1 to num_proc_directives do
  1556. if proc_direcdata[p].idtok=idtoken then
  1557. begin
  1558. found:=true;
  1559. break;
  1560. end;
  1561. { Check if the procedure directive is known }
  1562. if not found then
  1563. begin
  1564. { parsing a procvar type the name can be any
  1565. next variable !! }
  1566. if (pdflags * [pd_procvar,pd_object])=[] then
  1567. Message1(parser_w_unknown_proc_directive_ignored,name);
  1568. exit;
  1569. end;
  1570. { static needs a special treatment }
  1571. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1572. exit;
  1573. { Conflicts between directives ? }
  1574. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1575. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1576. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1577. begin
  1578. Message1(parser_e_proc_dir_conflict,name);
  1579. exit;
  1580. end;
  1581. { set calling convention }
  1582. if proc_direcdata[p].pocall<>pocall_none then
  1583. begin
  1584. if (po_hascallingconvention in pd.procoptions) then
  1585. begin
  1586. Message2(parser_w_proc_overriding_calling,
  1587. proccalloptionStr[pd.proccalloption],
  1588. proccalloptionStr[proc_direcdata[p].pocall]);
  1589. end;
  1590. { check if the target processor supports this calling convention }
  1591. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1592. begin
  1593. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1594. { recover }
  1595. proc_direcdata[p].pocall:=pocall_stdcall;
  1596. end;
  1597. pd.proccalloption:=proc_direcdata[p].pocall;
  1598. include(pd.procoptions,po_hascallingconvention);
  1599. end;
  1600. { check if method and directive not for object, like public.
  1601. This needs to be checked also for procvars }
  1602. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1603. (pd.owner.symtabletype=objectsymtable) then
  1604. exit;
  1605. if pd.deftype=procdef then
  1606. begin
  1607. { Check if the directive is only for objects }
  1608. if (pd_object in proc_direcdata[p].pd_flags) and
  1609. not assigned(tprocdef(pd)._class) then
  1610. exit;
  1611. { check if method and directive not for interface }
  1612. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1613. is_interface(tprocdef(pd)._class) then
  1614. exit;
  1615. end;
  1616. { consume directive, and turn flag on }
  1617. consume(token);
  1618. parse_proc_direc:=true;
  1619. { Check the pd_flags if the directive should be allowed }
  1620. if (pd_interface in pdflags) and
  1621. not(pd_interface in proc_direcdata[p].pd_flags) then
  1622. begin
  1623. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1624. exit;
  1625. end;
  1626. if (pd_implemen in pdflags) and
  1627. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1628. begin
  1629. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1630. exit;
  1631. end;
  1632. if (pd_procvar in pdflags) and
  1633. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1634. begin
  1635. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1636. exit;
  1637. end;
  1638. { Return the new pd_flags }
  1639. if not(pd_body in proc_direcdata[p].pd_flags) then
  1640. exclude(pdflags,pd_body);
  1641. { Add the correct flag }
  1642. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1643. { Call the handler }
  1644. if pointer({$ifndef FPCPROCVAR}@{$endif}proc_direcdata[p].handler)<>nil then
  1645. proc_direcdata[p].handler(pd);
  1646. end;
  1647. procedure handle_calling_convention(pd:tabstractprocdef);
  1648. begin
  1649. { set the default calling convention if none provided }
  1650. if not(po_hascallingconvention in pd.procoptions) then
  1651. pd.proccalloption:=aktdefproccall
  1652. else
  1653. begin
  1654. if pd.proccalloption=pocall_none then
  1655. internalerror(200309081);
  1656. end;
  1657. { handle proccall specific settings }
  1658. case pd.proccalloption of
  1659. pocall_cdecl :
  1660. begin
  1661. { set mangledname }
  1662. if (pd.deftype=procdef) then
  1663. begin
  1664. if not tprocdef(pd).has_mangledname then
  1665. begin
  1666. if assigned(tprocdef(pd)._class) then
  1667. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd)._class.objrealname^+'_'+tprocdef(pd).procsym.realname)
  1668. else
  1669. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd).procsym.realname);
  1670. end;
  1671. { check C cdecl para types }
  1672. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_c_para,nil);
  1673. end;
  1674. end;
  1675. pocall_cppdecl :
  1676. begin
  1677. { set mangledname }
  1678. if (pd.deftype=procdef) then
  1679. begin
  1680. if not tprocdef(pd).has_mangledname then
  1681. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd).cplusplusmangledname);
  1682. { check C cdecl para types }
  1683. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_c_para,nil);
  1684. end;
  1685. end;
  1686. pocall_compilerproc :
  1687. begin
  1688. if (pd.deftype<>procdef) then
  1689. internalerror(200110232);
  1690. if (target_info.system<>system_i386_watcom) then
  1691. tprocdef(pd).setmangledname(lower(tprocdef(pd).procsym.name));
  1692. end;
  1693. pocall_far16 :
  1694. begin
  1695. { Temporary stub, must be rewritten to support OS/2 far16 }
  1696. Message1(parser_w_proc_directive_ignored,'FAR16');
  1697. end;
  1698. pocall_inline :
  1699. begin
  1700. if not(cs_support_inline in aktmoduleswitches) then
  1701. begin
  1702. Message(parser_e_proc_inline_not_supported);
  1703. pd.proccalloption:=pocall_default;
  1704. end;
  1705. end;
  1706. end;
  1707. { For varargs directive also cdecl and external must be defined }
  1708. if (po_varargs in pd.procoptions) then
  1709. begin
  1710. { check first for external in the interface, if available there
  1711. then the cdecl must also be there since there is no implementation
  1712. available to contain it }
  1713. if parse_only then
  1714. begin
  1715. { if external is available, then cdecl must also be available,
  1716. procvars don't need external }
  1717. if not((po_external in pd.procoptions) or
  1718. (pd.deftype=procvardef)) and
  1719. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1720. Message(parser_e_varargs_need_cdecl_and_external);
  1721. end
  1722. else
  1723. begin
  1724. { both must be defined now }
  1725. if not((po_external in pd.procoptions) or
  1726. (pd.deftype=procvardef)) or
  1727. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1728. Message(parser_e_varargs_need_cdecl_and_external);
  1729. end;
  1730. end;
  1731. { add mangledname to external list }
  1732. if (pd.deftype=procdef) and
  1733. (po_external in pd.procoptions) and
  1734. target_info.DllScanSupported then
  1735. current_module.externals.insert(tExternalsItem.create(tprocdef(pd).mangledname));
  1736. end;
  1737. procedure calc_parast(pd:tabstractprocdef);
  1738. var
  1739. currpara : tparaitem;
  1740. begin
  1741. { insert hidden high parameters }
  1742. insert_hidden_para(pd);
  1743. { insert hidden self parameter }
  1744. insert_self_and_vmt_para(pd);
  1745. { insert funcret parameter if required }
  1746. insert_funcret_para(pd);
  1747. { insert parentfp parameter if required }
  1748. insert_parentfp_para(pd);
  1749. currpara:=tparaitem(pd.para.first);
  1750. while assigned(currpara) do
  1751. begin
  1752. if not(assigned(currpara.parasym) and (currpara.parasym.typ=varsym)) then
  1753. internalerror(200304232);
  1754. { connect parasym to paraitem }
  1755. tvarsym(currpara.parasym).paraitem:=currpara;
  1756. { We need a local copy for a value parameter when only the
  1757. address is pushed. Open arrays and Array of Const are
  1758. an exception because they are allocated at runtime and the
  1759. address that is pushed is patched }
  1760. if (currpara.paratyp=vs_value) and
  1761. paramanager.push_addr_param(currpara.paratyp,currpara.paratype.def,pd.proccalloption) and
  1762. not(is_open_array(currpara.paratype.def) or
  1763. is_array_of_const(currpara.paratype.def)) then
  1764. include(tvarsym(currpara.parasym).varoptions,vo_has_local_copy);
  1765. currpara:=tparaitem(currpara.next);
  1766. end;
  1767. end;
  1768. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  1769. {
  1770. Parse the procedure directives. It does not matter if procedure directives
  1771. are written using ;procdir; or ['procdir'] syntax.
  1772. }
  1773. var
  1774. res : boolean;
  1775. begin
  1776. while token in [_ID,_LECKKLAMMER] do
  1777. begin
  1778. if try_to_consume(_LECKKLAMMER) then
  1779. begin
  1780. repeat
  1781. parse_proc_direc(pd,pdflags);
  1782. until not try_to_consume(_COMMA);
  1783. consume(_RECKKLAMMER);
  1784. { we always expect at least '[];' }
  1785. res:=true;
  1786. end
  1787. else
  1788. begin
  1789. res:=parse_proc_direc(pd,pdflags);
  1790. end;
  1791. { A procedure directive normally followed by a semicolon, but in
  1792. a const section or reading a type we should stop when _EQUAL is found,
  1793. because a constant/default value follows }
  1794. if res then
  1795. begin
  1796. if (block_type in [bt_const,bt_type]) and
  1797. (token=_EQUAL) then
  1798. break;
  1799. { support procedure proc;stdcall export; }
  1800. if not(is_proc_directive(token,(pd.deftype=procvardef))) then
  1801. consume(_SEMICOLON);
  1802. end
  1803. else
  1804. break;
  1805. end;
  1806. end;
  1807. procedure parse_var_proc_directives(sym:tsym);
  1808. var
  1809. pdflags : tpdflags;
  1810. pd : tabstractprocdef;
  1811. begin
  1812. pdflags:=[pd_procvar];
  1813. pd:=nil;
  1814. case sym.typ of
  1815. varsym :
  1816. pd:=tabstractprocdef(tvarsym(sym).vartype.def);
  1817. typedconstsym :
  1818. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  1819. typesym :
  1820. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  1821. else
  1822. internalerror(2003042617);
  1823. end;
  1824. if pd.deftype<>procvardef then
  1825. internalerror(2003042618);
  1826. { names should never be used anyway }
  1827. parse_proc_directives(pd,pdflags);
  1828. end;
  1829. procedure parse_object_proc_directives(pd:tabstractprocdef);
  1830. var
  1831. pdflags : tpdflags;
  1832. begin
  1833. pdflags:=[pd_object];
  1834. parse_proc_directives(pd,pdflags);
  1835. end;
  1836. function proc_add_definition(var pd:tprocdef):boolean;
  1837. {
  1838. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  1839. forwarddef is found and reused it returns true
  1840. }
  1841. var
  1842. hd : tprocdef;
  1843. ad,fd : tsym;
  1844. s1,s2 : stringid;
  1845. i : cardinal;
  1846. forwardfound : boolean;
  1847. po_comp : tprocoptions;
  1848. aprocsym : tprocsym;
  1849. begin
  1850. forwardfound:=false;
  1851. aprocsym:=tprocsym(pd.procsym);
  1852. { check overloaded functions if the same function already exists }
  1853. for i:=1 to aprocsym.procdef_count do
  1854. begin
  1855. hd:=aprocsym.procdef[i];
  1856. { Skip overloaded definitions that are declared in other
  1857. units }
  1858. if hd.procsym<>aprocsym then
  1859. continue;
  1860. { check the parameters, for delphi/tp it is possible to
  1861. leave the parameters away in the implementation (forwarddef=false).
  1862. But for an overload declared function this is not allowed }
  1863. if { check if empty implementation arguments match is allowed }
  1864. (
  1865. not(m_repeat_forward in aktmodeswitches) and
  1866. not(pd.forwarddef) and
  1867. (pd.maxparacount=0) and
  1868. not(po_overload in hd.procoptions)
  1869. ) or
  1870. { check arguments }
  1871. (
  1872. (compare_paras(pd.para,hd.para,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  1873. { for operators equal_paras is not enough !! }
  1874. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1875. equal_defs(hd.rettype.def,pd.rettype.def))
  1876. ) then
  1877. begin
  1878. { Check if we've found the forwarddef, if found then
  1879. we need to update the forward def with the current
  1880. implementation settings }
  1881. if hd.forwarddef then
  1882. begin
  1883. forwardfound:=true;
  1884. { Check if the procedure type and return type are correct,
  1885. also the parameters must match also with the type }
  1886. if (hd.proctypeoption<>pd.proctypeoption) or
  1887. (
  1888. (m_repeat_forward in aktmodeswitches) and
  1889. (not((pd.maxparacount=0) or
  1890. (compare_paras(pd.para,hd.para,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  1891. ) or
  1892. (
  1893. ((m_repeat_forward in aktmodeswitches) or
  1894. not(is_void(pd.rettype.def))) and
  1895. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  1896. begin
  1897. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  1898. pd.fullprocname(false));
  1899. aprocsym.write_parameter_lists(pd);
  1900. break;
  1901. end;
  1902. { Check if both are declared forward }
  1903. if hd.forwarddef and pd.forwarddef then
  1904. begin
  1905. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  1906. pd.fullprocname(false));
  1907. end;
  1908. { internconst or internproc only need to be defined once }
  1909. if (hd.proccalloption=pocall_internproc) then
  1910. pd.proccalloption:=hd.proccalloption
  1911. else
  1912. if (pd.proccalloption=pocall_internproc) then
  1913. hd.proccalloption:=pd.proccalloption;
  1914. if (po_internconst in hd.procoptions) then
  1915. include(pd.procoptions,po_internconst)
  1916. else if (po_internconst in pd.procoptions) then
  1917. include(hd.procoptions,po_internconst);
  1918. { Check calling convention }
  1919. if (hd.proccalloption<>pd.proccalloption) then
  1920. begin
  1921. { In delphi it is possible to specify the calling
  1922. convention in the interface or implementation if
  1923. there was no convention specified in the other
  1924. part }
  1925. if (m_delphi in aktmodeswitches) then
  1926. begin
  1927. if not(po_hascallingconvention in pd.procoptions) then
  1928. pd.proccalloption:=hd.proccalloption
  1929. else
  1930. if not(po_hascallingconvention in hd.procoptions) then
  1931. hd.proccalloption:=pd.proccalloption
  1932. else
  1933. begin
  1934. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  1935. aprocsym.write_parameter_lists(pd);
  1936. { restore interface settings }
  1937. pd.proccalloption:=hd.proccalloption;
  1938. end;
  1939. end
  1940. else
  1941. begin
  1942. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  1943. aprocsym.write_parameter_lists(pd);
  1944. { restore interface settings }
  1945. pd.proccalloption:=hd.proccalloption;
  1946. end;
  1947. end;
  1948. { Check procedure options, Delphi requires that class is
  1949. repeated in the implementation for class methods }
  1950. if (m_fpc in aktmodeswitches) then
  1951. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  1952. else
  1953. po_comp:=[po_classmethod,po_methodpointer];
  1954. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  1955. begin
  1956. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  1957. pd.fullprocname(false));
  1958. aprocsym.write_parameter_lists(pd);
  1959. { This error is non-fatal, we can recover }
  1960. end;
  1961. { Check manglednames }
  1962. if (m_repeat_forward in aktmodeswitches) or
  1963. (pd.minparacount>0) then
  1964. begin
  1965. { If mangled names are equal then they have the same amount of arguments }
  1966. { We can check the names of the arguments }
  1967. { both symtables are in the same order from left to right }
  1968. ad:=tsym(hd.parast.symindex.first);
  1969. fd:=tsym(pd.parast.symindex.first);
  1970. repeat
  1971. { skip default parameter constsyms }
  1972. while assigned(ad) and (ad.typ<>varsym) do
  1973. ad:=tsym(ad.indexnext);
  1974. while assigned(fd) and (fd.typ<>varsym) do
  1975. fd:=tsym(fd.indexnext);
  1976. { stop when one of the two lists is at the end }
  1977. if not assigned(ad) or not assigned(fd) then
  1978. break;
  1979. { retrieve names, remove reg for register parameters }
  1980. s1:=ad.name;
  1981. s2:=fd.name;
  1982. { compare names }
  1983. if (s1<>s2) then
  1984. begin
  1985. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  1986. aprocsym.name,s1,s2);
  1987. break;
  1988. end;
  1989. ad:=tsym(ad.indexnext);
  1990. fd:=tsym(fd.indexnext);
  1991. until false;
  1992. if assigned(ad) xor assigned(fd) then
  1993. internalerror(200204178);
  1994. end;
  1995. { Everything is checked, now we can update the forward declaration
  1996. with the new data from the implementation }
  1997. hd.forwarddef:=pd.forwarddef;
  1998. hd.hasforward:=true;
  1999. hd.procoptions:=hd.procoptions+pd.procoptions;
  2000. if hd.extnumber=65535 then
  2001. hd.extnumber:=pd.extnumber;
  2002. while not pd.aliasnames.empty do
  2003. hd.aliasnames.insert(pd.aliasnames.getfirst);
  2004. { update fileinfo so position references the implementation,
  2005. also update funcretsym if it is already generated }
  2006. hd.fileinfo:=pd.fileinfo;
  2007. if assigned(hd.funcretsym) then
  2008. hd.funcretsym.fileinfo:=pd.fileinfo;
  2009. { update mangledname if the implementation has a fixed mangledname set }
  2010. if pd.has_mangledname then
  2011. begin
  2012. { rename also asmsymbol first, because the name can already be used }
  2013. objectlibrary.renameasmsymbol(hd.mangledname,pd.mangledname);
  2014. hd.setmangledname(pd.mangledname);
  2015. end;
  2016. { for compilerproc defines we need to rename and update the
  2017. symbolname to lowercase }
  2018. if (pd.proccalloption=pocall_compilerproc) then
  2019. begin
  2020. { rename to lowercase so users can't access it }
  2021. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  2022. { also update the realname that is stored in the ppu }
  2023. stringdispose(aprocsym._realname);
  2024. aprocsym._realname:=stringdup('$'+aprocsym.name);
  2025. { the mangeled name is already changed by the pd_compilerproc }
  2026. { handler. It must be done immediately because if we have a }
  2027. { call to a compilerproc before it's implementation is }
  2028. { encountered, it must already use the new mangled name (JM) }
  2029. end;
  2030. { the procdef will be released by the symtable, we release
  2031. at least the parast }
  2032. pd.releasemem;
  2033. pd:=hd;
  2034. end
  2035. else
  2036. begin
  2037. { abstract methods aren't forward defined, but this }
  2038. { needs another error message }
  2039. if (po_abstractmethod in hd.procoptions) then
  2040. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  2041. else
  2042. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  2043. end;
  2044. { we found one proc with the same arguments, there are no others
  2045. so we can stop }
  2046. break;
  2047. end;
  2048. { check for allowing overload directive }
  2049. if not(m_fpc in aktmodeswitches) then
  2050. begin
  2051. { overload directive turns on overloading }
  2052. if ((po_overload in pd.procoptions) or
  2053. (po_overload in hd.procoptions)) then
  2054. begin
  2055. { check if all procs have overloading, but not if the proc is a method or
  2056. already declared forward, then the check is already done }
  2057. if not(hd.hasforward or
  2058. assigned(pd._class) or
  2059. (pd.forwarddef<>hd.forwarddef) or
  2060. ((po_overload in pd.procoptions) and
  2061. (po_overload in hd.procoptions))) then
  2062. begin
  2063. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2064. break;
  2065. end;
  2066. end
  2067. else
  2068. begin
  2069. if not(hd.forwarddef) then
  2070. begin
  2071. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2072. break;
  2073. end;
  2074. end;
  2075. end; { equal arguments }
  2076. end;
  2077. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2078. list }
  2079. if not forwardfound then
  2080. begin
  2081. aprocsym.addprocdef(pd);
  2082. { add overloadnumber for unique naming, the overloadcount is
  2083. counted per module and 0 for the first procedure }
  2084. pd.overloadnumber:=aprocsym.overloadcount;
  2085. inc(aprocsym.overloadcount);
  2086. end;
  2087. proc_add_definition:=forwardfound;
  2088. end;
  2089. end.
  2090. {
  2091. $Log$
  2092. Revision 1.178 2004-05-12 13:21:09 karoly
  2093. * few small changes to add syscall support to M68k/Amiga target
  2094. Revision 1.177 2004/05/11 22:52:48 olle
  2095. * Moved import_implicit_external to symsym
  2096. Revision 1.176 2004/05/11 18:29:41 olle
  2097. + mode macpas: support for implicit external
  2098. Revision 1.175 2004/05/11 06:59:35 michael
  2099. + Patch from peter to hide system unit as symbol
  2100. Revision 1.174 2004/05/09 12:49:14 peter
  2101. C directive is mac only
  2102. Revision 1.173 2004/05/03 20:02:42 jonas
  2103. - removed change_forward_to_external() declaration
  2104. Revision 1.172 2004/05/03 10:06:38 olle
  2105. + added language constructs UNIV, C, ... for mode mac
  2106. * consolidated macro expression to conform to Pascal
  2107. * macro true is defined as <> 0
  2108. Revision 1.171 2004/05/01 22:38:13 florian
  2109. * fixed MorphOS syscall without parameters
  2110. Revision 1.170 2004/05/01 22:05:01 florian
  2111. + added lib support for Amiga/MorphOS syscalls
  2112. Revision 1.169 2004/04/29 21:10:13 florian
  2113. + locationstr always reset
  2114. Revision 1.168 2004/04/28 15:19:03 florian
  2115. + syscall directive support for MorphOS added
  2116. Revision 1.167 2004/04/28 00:20:43 karoly
  2117. * fixed locationstr having nonsense values in some cases
  2118. Revision 1.166 2004/04/19 02:12:18 karoly
  2119. * quick fix for PowerPC/MorphOS location support
  2120. Revision 1.165 2004/04/18 15:22:24 florian
  2121. + location support for arguments, currently PowerPC/MorphOS only
  2122. Revision 1.164 2004/02/26 16:13:25 peter
  2123. * fix crash when method is not declared in object declaration
  2124. * fix parsing of mapped interface functions
  2125. Revision 1.163 2004/02/20 21:54:47 peter
  2126. * use sp_internal flag to silence unused internal variable
  2127. Revision 1.162 2004/02/13 15:41:24 peter
  2128. * overload directive checking for methods is now done
  2129. when the vmt is generated
  2130. Revision 1.161 2004/02/05 14:13:53 daniel
  2131. * Tvarsym.highvarsym removed
  2132. Revision 1.160 2004/02/04 22:54:57 daniel
  2133. * Tvarsym.highvarsym commented out (unused by compiler, purpose unknown)
  2134. Revision 1.159 2004/02/04 22:15:15 daniel
  2135. * Rtti generation moved to ncgutil
  2136. * Assmtai usage of symsym removed
  2137. * operator overloading cleanup up
  2138. Revision 1.158 2004/02/03 22:32:54 peter
  2139. * renamed xNNbittype to xNNinttype
  2140. * renamed registers32 to registersint
  2141. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2142. Revision 1.157 2004/01/31 17:45:17 peter
  2143. * Change several $ifdef i386 to x86
  2144. * Change several OS_32 to OS_INT/OS_ADDR
  2145. Revision 1.156 2004/01/21 14:22:00 florian
  2146. + reintroduce implemented
  2147. Revision 1.155 2003/11/23 17:05:15 peter
  2148. * register calling is left-right
  2149. * parameter ordering
  2150. * left-right calling inserts result parameter last
  2151. Revision 1.154 2003/11/12 15:49:06 peter
  2152. * virtual conflicts with override
  2153. Revision 1.153 2003/11/10 19:09:29 peter
  2154. * procvar default value support
  2155. Revision 1.152 2003/11/07 15:58:32 florian
  2156. * Florian's culmutative nr. 1; contains:
  2157. - invalid calling conventions for a certain cpu are rejected
  2158. - arm softfloat calling conventions
  2159. - -Sp for cpu dependend code generation
  2160. - several arm fixes
  2161. - remaining code for value open array paras on heap
  2162. Revision 1.151 2003/11/03 17:47:30 peter
  2163. * insert framepointer as voidpointer instead of returntype
  2164. Revision 1.150 2003/10/30 16:23:13 peter
  2165. * don't search for overloads in parents for constructors
  2166. Revision 1.149 2003/10/28 15:36:01 peter
  2167. * absolute to object field supported, fixes tb0458
  2168. Revision 1.148 2003/10/07 21:14:33 peter
  2169. * compare_paras() has a parameter to ignore hidden parameters
  2170. * cross unit overload searching ignores hidden parameters when
  2171. comparing parameter lists. Now function(string):string is
  2172. not overriden with procedure(string) which has the same visible
  2173. parameter list
  2174. Revision 1.147 2003/10/07 20:52:54 peter
  2175. * procvar varargs fixed
  2176. Revision 1.146 2003/10/05 21:21:52 peter
  2177. * c style array of const generates callparanodes
  2178. * varargs paraloc fixes
  2179. Revision 1.145 2003/10/05 11:10:52 peter
  2180. * temporary fix for compilerprocs on watcom
  2181. Revision 1.144 2003/10/03 22:00:33 peter
  2182. * parameter alignment fixes
  2183. Revision 1.143 2003/10/02 21:13:09 peter
  2184. * procvar directive parsing fixes
  2185. Revision 1.142 2003/10/01 19:05:33 peter
  2186. * searchsym_type to search for type definitions. It ignores
  2187. records,objects and parameters
  2188. Revision 1.141 2003/10/01 18:28:55 peter
  2189. * don't look in objectsymtable when parsing the function return type
  2190. Revision 1.140 2003/10/01 16:49:05 florian
  2191. * para items are now reversed for pascal calling conventions
  2192. Revision 1.139 2003/09/28 21:44:55 peter
  2193. * fix check that filedef needs var para
  2194. Revision 1.138 2003/09/28 17:55:04 peter
  2195. * parent framepointer changed to hidden parameter
  2196. * tloadparentfpnode added
  2197. Revision 1.137 2003/09/25 21:24:09 peter
  2198. * don't include vo_has_local_copy for open array/array of const
  2199. Revision 1.136 2003/09/23 20:36:47 peter
  2200. * remove obsolete code
  2201. Revision 1.135 2003/09/23 17:56:05 peter
  2202. * locals and paras are allocated in the code generation
  2203. * tvarsym.localloc contains the location of para/local when
  2204. generating code for the current procedure
  2205. Revision 1.134 2003/09/16 16:17:01 peter
  2206. * varspez in calls to push_addr_param
  2207. Revision 1.133 2003/09/09 21:03:17 peter
  2208. * basics for x86 register calling
  2209. Revision 1.132 2003/09/09 15:54:10 peter
  2210. * calling convention fix
  2211. Revision 1.131 2003/09/07 22:09:35 peter
  2212. * preparations for different default calling conventions
  2213. * various RA fixes
  2214. Revision 1.130 2003/09/03 11:18:37 florian
  2215. * fixed arm concatcopy
  2216. + arm support in the common compiler sources added
  2217. * moved some generic cg code around
  2218. + tfputype added
  2219. * ...
  2220. Revision 1.129 2003/07/02 22:18:04 peter
  2221. * paraloc splitted in callerparaloc,calleeparaloc
  2222. * sparc calling convention updates
  2223. Revision 1.128 2003/06/13 21:19:31 peter
  2224. * current_procdef removed, use current_procinfo.procdef instead
  2225. Revision 1.127 2003/06/05 20:04:43 peter
  2226. * set po_public also when parsing the object declaration
  2227. Revision 1.126 2003/06/02 21:42:05 jonas
  2228. * function results can now also be regvars
  2229. - removed tprocinfo.return_offset, never use it again since it's invalid
  2230. if the result is a regvar
  2231. Revision 1.125 2003/05/22 21:31:35 peter
  2232. * defer codegeneration for nested procedures
  2233. Revision 1.124 2003/05/15 18:58:53 peter
  2234. * removed selfpointer_offset, vmtpointer_offset
  2235. * tvarsym.adjusted_address
  2236. * address in localsymtable is now in the real direction
  2237. * removed some obsolete globals
  2238. Revision 1.123 2003/05/13 15:18:49 peter
  2239. * fixed various crashes
  2240. Revision 1.122 2003/05/09 17:47:03 peter
  2241. * self moved to hidden parameter
  2242. * removed hdisposen,hnewn,selfn
  2243. Revision 1.121 2003/05/05 14:53:16 peter
  2244. * vs_hidden replaced by is_hidden boolean
  2245. Revision 1.120 2003/04/30 09:42:42 florian
  2246. + first changes to make self a hidden parameter
  2247. Revision 1.119 2003/04/27 11:21:33 peter
  2248. * aktprocdef renamed to current_procinfo.procdef
  2249. * procinfo renamed to current_procinfo
  2250. * procinfo will now be stored in current_module so it can be
  2251. cleaned up properly
  2252. * gen_main_procsym changed to create_main_proc and release_main_proc
  2253. to also generate a tprocinfo structure
  2254. * fixed unit implicit initfinal
  2255. Revision 1.118 2003/04/27 07:29:50 peter
  2256. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2257. a new procdef declaration
  2258. * aktprocsym removed
  2259. * lexlevel removed, use symtable.symtablelevel instead
  2260. * implicit init/final code uses the normal genentry/genexit
  2261. * funcret state checking updated for new funcret handling
  2262. Revision 1.117 2003/04/26 00:33:07 peter
  2263. * vo_is_result flag added for the special RESULT symbol
  2264. Revision 1.116 2003/04/25 20:59:33 peter
  2265. * removed funcretn,funcretsym, function result is now in varsym
  2266. and aliases for result and function name are added using absolutesym
  2267. * vs_hidden parameter for funcret passed in parameter
  2268. * vs_hidden fixes
  2269. * writenode changed to printnode and released from extdebug
  2270. * -vp option added to generate a tree.log with the nodetree
  2271. * nicer printnode for statements, callnode
  2272. Revision 1.115 2003/04/24 13:03:01 florian
  2273. * comp is now written with its bit pattern to the ppu instead as an extended
  2274. Revision 1.114 2003/04/23 13:12:26 peter
  2275. * fix po_comp setting for fpc mode
  2276. Revision 1.113 2003/04/23 10:12:51 peter
  2277. * don't check po_varargs for delphi
  2278. Revision 1.112 2003/04/22 13:47:08 peter
  2279. * fixed C style array of const
  2280. * fixed C array passing
  2281. * fixed left to right with high parameters
  2282. Revision 1.111 2003/04/10 17:57:53 peter
  2283. * vs_hidden released
  2284. Revision 1.110 2003/03/28 19:16:56 peter
  2285. * generic constructor working for i386
  2286. * remove fixed self register
  2287. * esi added as address register for i386
  2288. Revision 1.109 2003/03/23 23:21:42 hajny
  2289. + emx target added
  2290. Revision 1.108 2003/03/19 17:34:04 peter
  2291. * only allow class [procedure|function]
  2292. Revision 1.107 2003/03/17 18:56:02 peter
  2293. * fix crash with duplicate id
  2294. Revision 1.106 2003/03/17 15:54:22 peter
  2295. * store symoptions also for procdef
  2296. * check symoptions (private,public) when calculating possible
  2297. overload candidates
  2298. Revision 1.105 2003/01/15 20:02:28 carl
  2299. * fix highname problem
  2300. Revision 1.104 2003/01/12 15:42:23 peter
  2301. * m68k pathexist update from 1.0.x
  2302. * palmos res update from 1.0.x
  2303. Revision 1.103 2003/01/07 19:16:38 peter
  2304. * removed some duplicate code when creating aktprocsym
  2305. Revision 1.102 2003/01/05 18:17:45 peter
  2306. * more conflicts for constructor/destructor types
  2307. Revision 1.100 2003/01/02 19:49:00 peter
  2308. * update self parameter only for methodpointer and methods
  2309. Revision 1.99 2003/01/01 22:51:03 peter
  2310. * high value insertion changed so it works also when 2 parameters
  2311. are passed
  2312. Revision 1.98 2003/01/01 14:35:33 peter
  2313. * don't check for export directive repeat
  2314. Revision 1.97 2002/12/29 18:16:06 peter
  2315. * delphi allows setting calling convention in interface or
  2316. implementation
  2317. Revision 1.96 2002/12/29 14:55:44 peter
  2318. * fix static method check
  2319. * don't require class for class methods in the implementation for
  2320. non delphi modes
  2321. Revision 1.95 2002/12/27 15:25:14 peter
  2322. * check procoptions when a forward is found
  2323. * exclude some call directives for constructor/destructor
  2324. Revision 1.94 2002/12/25 01:26:56 peter
  2325. * duplicate procsym-unitsym fix
  2326. Revision 1.93 2002/12/24 21:21:06 peter
  2327. * remove code that skipped the _ prefix for win32 imports
  2328. Revision 1.92 2002/12/23 21:24:22 peter
  2329. * fix wrong internalerror when var names were different
  2330. Revision 1.91 2002/12/23 20:58:52 peter
  2331. * cdecl array fix, hack to change it to vs_var is not needed
  2332. Revision 1.90 2002/12/17 22:19:33 peter
  2333. * fixed pushing of records>8 bytes with stdcall
  2334. * simplified hightree loading
  2335. Revision 1.89 2002/12/15 21:07:30 peter
  2336. * don't allow external in object declarations
  2337. Revision 1.88 2002/12/15 19:34:31 florian
  2338. + some front end stuff for vs_hidden added
  2339. Revision 1.87 2002/12/07 14:27:07 carl
  2340. * 3% memory optimization
  2341. * changed some types
  2342. + added type checking with different size for call node and for
  2343. parameters
  2344. Revision 1.86 2002/12/06 17:51:10 peter
  2345. * merged cdecl and array fixes
  2346. Revision 1.85 2002/12/01 22:06:14 carl
  2347. * cleanup of error messages
  2348. Revision 1.84 2002/11/29 22:31:19 carl
  2349. + unimplemented hint directive added
  2350. * hint directive parsing implemented
  2351. * warning on these directives
  2352. Revision 1.83 2002/11/27 02:35:28 peter
  2353. * fixed typo in method comparing
  2354. Revision 1.82 2002/11/25 17:43:21 peter
  2355. * splitted defbase in defutil,symutil,defcmp
  2356. * merged isconvertable and is_equal into compare_defs(_ext)
  2357. * made operator search faster by walking the list only once
  2358. Revision 1.81 2002/11/18 17:31:58 peter
  2359. * pass proccalloption to ret_in_xxx and push_xxx functions
  2360. Revision 1.80 2002/11/17 16:31:56 carl
  2361. * memory optimization (3-4%) : cleanup of tai fields,
  2362. cleanup of tdef and tsym fields.
  2363. * make it work for m68k
  2364. Revision 1.79 2002/11/16 14:20:50 peter
  2365. * fix infinite loop in pd_inline
  2366. Revision 1.78 2002/11/15 01:58:53 peter
  2367. * merged changes from 1.0.7 up to 04-11
  2368. - -V option for generating bug report tracing
  2369. - more tracing for option parsing
  2370. - errors for cdecl and high()
  2371. - win32 import stabs
  2372. - win32 records<=8 are returned in eax:edx (turned off by default)
  2373. - heaptrc update
  2374. - more info for temp management in .s file with EXTDEBUG
  2375. Revision 1.77 2002/10/06 15:09:12 peter
  2376. * variant:=nil supported
  2377. Revision 1.76 2002/09/27 21:13:29 carl
  2378. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  2379. Revision 1.75 2002/09/16 14:11:13 peter
  2380. * add argument to equal_paras() to support default values or not
  2381. Revision 1.74 2002/09/10 16:27:28 peter
  2382. * don't insert parast in symtablestack, because typesyms should not be
  2383. searched in the the parast
  2384. Revision 1.73 2002/09/09 19:39:07 peter
  2385. * check return type for forwarddefs also not delphi mode when
  2386. the type is not void
  2387. Revision 1.72 2002/09/09 17:34:15 peter
  2388. * tdicationary.replace added to replace and item in a dictionary. This
  2389. is only allowed for the same name
  2390. * varsyms are inserted in symtable before the types are parsed. This
  2391. fixes the long standing "var longint : longint" bug
  2392. - consume_idlist and idstringlist removed. The loops are inserted
  2393. at the callers place and uses the symtable for duplicate id checking
  2394. Revision 1.71 2002/09/07 15:25:06 peter
  2395. * old logs removed and tabs fixed
  2396. Revision 1.70 2002/09/03 16:26:27 daniel
  2397. * Make Tprocdef.defs protected
  2398. Revision 1.69 2002/09/01 12:11:33 peter
  2399. * calc param_offset after parameters are read, because the calculation
  2400. depends on po_containself
  2401. Revision 1.68 2002/08/25 19:25:20 peter
  2402. * sym.insert_in_data removed
  2403. * symtable.insertvardata/insertconstdata added
  2404. * removed insert_in_data call from symtable.insert, it needs to be
  2405. called separatly. This allows to deref the address calculation
  2406. * procedures now calculate the parast addresses after the procedure
  2407. directives are parsed. This fixes the cdecl parast problem
  2408. * push_addr_param has an extra argument that specifies if cdecl is used
  2409. or not
  2410. Revision 1.67 2002/08/25 11:33:06 peter
  2411. * also check the paratypes when a forward was found
  2412. Revision 1.66 2002/08/19 19:36:44 peter
  2413. * More fixes for cross unit inlining, all tnodes are now implemented
  2414. * Moved pocall_internconst to po_internconst because it is not a
  2415. calling type at all and it conflicted when inlining of these small
  2416. functions was requested
  2417. Revision 1.65 2002/08/18 20:06:24 peter
  2418. * inlining is now also allowed in interface
  2419. * renamed write/load to ppuwrite/ppuload
  2420. * tnode storing in ppu
  2421. * nld,ncon,nbas are already updated for storing in ppu
  2422. Revision 1.64 2002/08/17 09:23:39 florian
  2423. * first part of procinfo rewrite
  2424. Revision 1.63 2002/08/11 14:32:27 peter
  2425. * renamed current_library to objectlibrary
  2426. Revision 1.62 2002/08/11 13:24:12 peter
  2427. * saving of asmsymbols in ppu supported
  2428. * asmsymbollist global is removed and moved into a new class
  2429. tasmlibrarydata that will hold the info of a .a file which
  2430. corresponds with a single module. Added librarydata to tmodule
  2431. to keep the library info stored for the module. In the future the
  2432. objectfiles will also be stored to the tasmlibrarydata class
  2433. * all getlabel/newasmsymbol and friends are moved to the new class
  2434. Revision 1.61 2002/07/26 21:15:40 florian
  2435. * rewrote the system handling
  2436. Revision 1.60 2002/07/20 11:57:55 florian
  2437. * types.pas renamed to defbase.pas because D6 contains a types
  2438. unit so this would conflicts if D6 programms are compiled
  2439. + Willamette/SSE2 instructions to assembler added
  2440. Revision 1.59 2002/07/11 14:41:28 florian
  2441. * start of the new generic parameter handling
  2442. Revision 1.58 2002/07/01 18:46:25 peter
  2443. * internal linker
  2444. * reorganized aasm layer
  2445. Revision 1.57 2002/05/18 13:34:12 peter
  2446. * readded missing revisions
  2447. Revision 1.56 2002/05/16 19:46:42 carl
  2448. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2449. + try to fix temp allocation (still in ifdef)
  2450. + generic constructor calls
  2451. + start of tassembler / tmodulebase class cleanup
  2452. Revision 1.54 2002/05/12 16:53:08 peter
  2453. * moved entry and exitcode to ncgutil and cgobj
  2454. * foreach gets extra argument for passing local data to the
  2455. iterator function
  2456. * -CR checks also class typecasts at runtime by changing them
  2457. into as
  2458. * fixed compiler to cycle with the -CR option
  2459. * fixed stabs with elf writer, finally the global variables can
  2460. be watched
  2461. * removed a lot of routines from cga unit and replaced them by
  2462. calls to cgobj
  2463. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2464. u32bit then the other is typecasted also to u32bit without giving
  2465. a rangecheck warning/error.
  2466. * fixed pascal calling method with reversing also the high tree in
  2467. the parast, detected by tcalcst3 test
  2468. Revision 1.53 2002/04/21 19:02:04 peter
  2469. * removed newn and disposen nodes, the code is now directly
  2470. inlined from pexpr
  2471. * -an option that will write the secondpass nodes to the .s file, this
  2472. requires EXTDEBUG define to actually write the info
  2473. * fixed various internal errors and crashes due recent code changes
  2474. Revision 1.52 2002/04/20 21:32:24 carl
  2475. + generic FPC_CHECKPOINTER
  2476. + first parameter offset in stack now portable
  2477. * rename some constants
  2478. + move some cpu stuff to other units
  2479. - remove unused constents
  2480. * fix stacksize for some targets
  2481. * fix generic size problems which depend now on EXTEND_SIZE constant
  2482. Revision 1.51 2002/04/20 15:27:05 carl
  2483. - remove ifdef i386 define
  2484. Revision 1.50 2002/04/19 15:46:02 peter
  2485. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  2486. in most cases and not written to the ppu
  2487. * add mangeledname_prefix() routine to generate the prefix of
  2488. manglednames depending on the current procedure, object and module
  2489. * removed static procprefix since the mangledname is now build only
  2490. on demand from tprocdef.mangledname
  2491. }