pdecsub.pas 90 KB

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