pdecsub.pas 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  4. Does the parsing of the procedures/functions
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pdecsub;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. tokens,symconst,symtype,symdef,symsym;
  23. type
  24. tpdflag=(
  25. pd_body, { directive needs a body }
  26. pd_implemen, { directive can be used implementation section }
  27. pd_interface, { directive can be used interface section }
  28. pd_object, { directive can be used object declaration }
  29. pd_procvar, { directive can be used procvar declaration }
  30. pd_notobject, { directive can not be used object declaration }
  31. pd_notobjintf, { directive can not be used interface declaration }
  32. pd_notprocvar { directive can not be used procvar declaration }
  33. );
  34. tpdflags=set of tpdflag;
  35. function is_proc_directive(tok:ttoken;isprocvar:boolean):boolean;
  36. procedure calc_parast(pd:tabstractprocdef);
  37. procedure insert_funcret_local(pd:tprocdef);
  38. function proc_add_definition(var pd:tprocdef):boolean;
  39. procedure handle_calling_convention(pd:tabstractprocdef);
  40. procedure parse_parameter_dec(pd:tabstractprocdef);
  41. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  42. procedure parse_var_proc_directives(sym:tsym);
  43. procedure parse_object_proc_directives(pd:tabstractprocdef);
  44. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption):tprocdef;
  45. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  46. implementation
  47. uses
  48. {$ifdef delphi}
  49. sysutils,
  50. {$else delphi}
  51. strings,
  52. {$endif delphi}
  53. { common }
  54. cutils,cclasses,
  55. { global }
  56. globtype,globals,verbose,
  57. systems,cpubase,
  58. { aasm }
  59. aasmbase,aasmtai,aasmcpu,
  60. { symtable }
  61. symbase,symtable,defutil,defcmp,paramgr,
  62. { pass 1 }
  63. node,htypechk,
  64. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  65. { parser }
  66. fmodule,scanner,
  67. pbase,pexpr,ptype,pdecl,
  68. { linking }
  69. import,gendef,
  70. { codegen }
  71. cpuinfo,cgbase
  72. ;
  73. const
  74. { Please leave this here, this module should NOT use
  75. these variables.
  76. Declaring it as string here results in an error when compiling (PFV) }
  77. current_procinfo = 'error';
  78. procedure insert_funcret_para(pd:tabstractprocdef);
  79. var
  80. storepos : tfileposinfo;
  81. vs : tvarsym;
  82. begin
  83. if not is_void(pd.rettype.def) and
  84. paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  85. begin
  86. storepos:=akttokenpos;
  87. if pd.deftype=procdef then
  88. akttokenpos:=tprocdef(pd).fileinfo;
  89. { Generate result variable accessing function result }
  90. vs:=tvarsym.create('$result',vs_var,pd.rettype);
  91. include(vs.varoptions,vo_is_funcret);
  92. include(vs.varoptions,vo_regable);
  93. pd.parast.insert(vs);
  94. pd.insertpara(vs.vartype,vs,nil,true);
  95. { Store the this symbol as funcretsym for procedures }
  96. if pd.deftype=procdef then
  97. tprocdef(pd).funcretsym:=vs;
  98. akttokenpos:=storepos;
  99. end;
  100. end;
  101. procedure insert_parentfp_para(pd:tabstractprocdef);
  102. var
  103. storepos : tfileposinfo;
  104. vs : tvarsym;
  105. begin
  106. if pd.parast.symtablelevel>normal_function_level then
  107. begin
  108. storepos:=akttokenpos;
  109. if pd.deftype=procdef then
  110. akttokenpos:=tprocdef(pd).fileinfo;
  111. { Generate result variable accessing function result }
  112. vs:=tvarsym.create('$parentfp',vs_var,pd.rettype);
  113. include(vs.varoptions,vo_is_parentfp);
  114. pd.parast.insert(vs);
  115. pd.insertpara(vs.vartype,vs,nil,true);
  116. akttokenpos:=storepos;
  117. end;
  118. end;
  119. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  120. var
  121. storepos : tfileposinfo;
  122. vs : tvarsym;
  123. tt : ttype;
  124. vsp : tvarspez;
  125. begin
  126. if (pd.deftype=procvardef) and
  127. pd.is_methodpointer then
  128. begin
  129. { Generate self variable }
  130. tt:=voidpointertype;
  131. vs:=tvarsym.create('$self',vs_value,tt);
  132. include(vs.varoptions,vo_is_self);
  133. { Insert as hidden parameter }
  134. pd.parast.insert(vs);
  135. pd.insertpara(vs.vartype,vs,nil,true);
  136. end
  137. else
  138. begin
  139. if (pd.deftype=procdef) and
  140. assigned(tprocdef(pd)._class) and
  141. (pd.parast.symtablelevel=normal_function_level) then
  142. begin
  143. storepos:=akttokenpos;
  144. akttokenpos:=tprocdef(pd).fileinfo;
  145. { Generate VMT variable for constructor/destructor }
  146. if pd.proctypeoption in [potype_constructor,potype_destructor] then
  147. begin
  148. { can't use classrefdef as type because inheriting
  149. will then always file because of a type mismatch }
  150. tt:=voidpointertype;
  151. vs:=tvarsym.create('$vmt',vs_value,tt);
  152. include(vs.varoptions,vo_is_vmt);
  153. { Insert as hidden parameter }
  154. pd.parast.insert(vs);
  155. pd.insertpara(vs.vartype,vs,nil,true);
  156. end;
  157. { Generate self variable, for classes we need
  158. to use the generic voidpointer to be compatible with
  159. methodpointers }
  160. vsp:=vs_value;
  161. if (po_staticmethod in pd.procoptions) or
  162. (po_classmethod in pd.procoptions) then
  163. begin
  164. tt.setdef(tprocdef(pd)._class);
  165. tt.setdef(tclassrefdef.create(tt));
  166. end
  167. else
  168. begin
  169. if is_object(tprocdef(pd)._class) then
  170. vsp:=vs_var;
  171. tt.setdef(tprocdef(pd)._class);
  172. end;
  173. vs:=tvarsym.create('$self',vsp,tt);
  174. include(vs.varoptions,vo_is_self);
  175. include(vs.varoptions,vo_regable);
  176. { Insert as hidden parameter }
  177. pd.parast.insert(vs);
  178. pd.insertpara(vs.vartype,vs,nil,true);
  179. akttokenpos:=storepos;
  180. end;
  181. end;
  182. end;
  183. procedure insert_funcret_local(pd:tprocdef);
  184. var
  185. storepos : tfileposinfo;
  186. vs : tvarsym;
  187. begin
  188. if not is_void(pd.rettype.def) then
  189. begin
  190. storepos:=akttokenpos;
  191. akttokenpos:=pd.fileinfo;
  192. { We always need a localsymtable }
  193. if not assigned(pd.localst) then
  194. pd.insert_localst;
  195. { We need to insert a varsym for the result in the localst
  196. when it is returning in a register }
  197. if not paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  198. begin
  199. vs:=tvarsym.create('$result',vs_value,pd.rettype);
  200. include(vs.varoptions,vo_is_funcret);
  201. if tstoreddef(pd.rettype.def).is_intregable then
  202. include(vs.varoptions,vo_regable);
  203. if tstoreddef(pd.rettype.def).is_fpuregable then
  204. include(vs.varoptions,vo_fpuregable);
  205. pd.localst.insert(vs);
  206. pd.funcretsym:=vs;
  207. end;
  208. { insert the name of the procedure as alias for the function result,
  209. we can't use realname because that will not work for compilerprocs
  210. as the name is lowercase and unreachable from the code }
  211. if pd.resultname='' then
  212. pd.resultname:=pd.procsym.name;
  213. vs:=tabsolutesym.create_ref(pd.resultname,pd.rettype,tstoredsym(pd.funcretsym));
  214. include(vs.varoptions,vo_is_funcret);
  215. pd.localst.insert(vs);
  216. { insert result also if support is on }
  217. if (m_result in aktmodeswitches) then
  218. begin
  219. vs:=tabsolutesym.create_ref('RESULT',pd.rettype,tstoredsym(pd.funcretsym));
  220. include(vs.varoptions,vo_is_funcret);
  221. include(vs.varoptions,vo_is_result);
  222. pd.localst.insert(vs);
  223. end;
  224. akttokenpos:=storepos;
  225. end;
  226. end;
  227. procedure insert_hidden_para(pd:tabstractprocdef);
  228. var
  229. currpara : tparaitem;
  230. hvs : tvarsym;
  231. begin
  232. { walk from right to left, so we can insert the
  233. high parameters after the current parameter }
  234. currpara:=tparaitem(pd.para.last);
  235. while assigned(currpara) do
  236. begin
  237. { needs high parameter ? }
  238. if paramanager.push_high_param(currpara.paratyp,currpara.paratype.def,pd.proccalloption) then
  239. begin
  240. if assigned(currpara.parasym) then
  241. begin
  242. hvs:=tvarsym.create('$high'+tvarsym(currpara.parasym).name,vs_const,s32bittype);
  243. include(hvs.varoptions,vo_is_high_value);
  244. tvarsym(currpara.parasym).owner.insert(hvs);
  245. tvarsym(currpara.parasym).highvarsym:=hvs;
  246. end
  247. else
  248. hvs:=nil;
  249. pd.concatpara(currpara,s32bittype,hvs,nil,true);
  250. end
  251. else
  252. begin
  253. { Give a warning that cdecl routines does not include high()
  254. support }
  255. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  256. paramanager.push_high_param(currpara.paratyp,currpara.paratype.def,pocall_default) then
  257. begin
  258. if is_open_string(currpara.paratype.def) then
  259. Message(parser_w_cdecl_no_openstring);
  260. if not (po_external in pd.procoptions) then
  261. Message(parser_w_cdecl_has_no_high);
  262. end;
  263. end;
  264. currpara:=tparaitem(currpara.previous);
  265. end;
  266. end;
  267. procedure check_c_para(p:tnamedindexitem;arg:pointer);
  268. begin
  269. if (tsym(p).typ<>varsym) then
  270. exit;
  271. with tvarsym(p) do
  272. begin
  273. case vartype.def.deftype of
  274. arraydef :
  275. begin
  276. if not is_variant_array(vartype.def) and
  277. not is_array_of_const(vartype.def) then
  278. begin
  279. if (varspez<>vs_var) then
  280. Message(parser_h_c_arrays_are_references);
  281. end;
  282. if is_array_of_const(vartype.def) and
  283. assigned(indexnext) and
  284. (tsym(indexnext).typ=varsym) and
  285. not(vo_is_high_value in tvarsym(indexnext).varoptions) then
  286. Message(parser_e_C_array_of_const_must_be_last);
  287. end;
  288. end;
  289. end;
  290. end;
  291. procedure parse_parameter_dec(pd:tabstractprocdef);
  292. {
  293. handle_procvar needs the same changes
  294. }
  295. var
  296. is_procvar : boolean;
  297. sc : tsinglelist;
  298. tt : ttype;
  299. arrayelementtype : ttype;
  300. vs : tvarsym;
  301. srsym : tsym;
  302. hs1 : string;
  303. varspez : Tvarspez;
  304. tdefaultvalue : tconstsym;
  305. defaultrequired : boolean;
  306. old_object_option : tsymoptions;
  307. currparast : tparasymtable;
  308. begin
  309. consume(_LKLAMMER);
  310. { Delphi/Kylix supports nonsense like }
  311. { procedure p(); }
  312. if try_to_consume(_RKLAMMER) and
  313. not(m_tp7 in aktmodeswitches) then
  314. exit;
  315. { parsing a proc or procvar ? }
  316. is_procvar:=(pd.deftype=procvardef);
  317. currparast:=tparasymtable(pd.parast);
  318. { reset }
  319. sc:=tsinglelist.create;
  320. defaultrequired:=false;
  321. { the variables are always public }
  322. old_object_option:=current_object_option;
  323. current_object_option:=[sp_public];
  324. inc(testcurobject);
  325. repeat
  326. if try_to_consume(_VAR) then
  327. varspez:=vs_var
  328. else
  329. if try_to_consume(_CONST) then
  330. varspez:=vs_const
  331. else
  332. if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  333. begin
  334. consume(_OUT);
  335. varspez:=vs_out
  336. end
  337. else
  338. varspez:=vs_value;
  339. tdefaultvalue:=nil;
  340. tt.reset;
  341. { read identifiers and insert with error type }
  342. sc.reset;
  343. repeat
  344. vs:=tvarsym.create(orgpattern,varspez,generrortype);
  345. currparast.insert(vs);
  346. if assigned(vs.owner) then
  347. sc.insert(vs)
  348. else
  349. vs.free;
  350. consume(_ID);
  351. until not try_to_consume(_COMMA);
  352. { read type declaration, force reading for value and const paras }
  353. if (token=_COLON) or (varspez=vs_value) then
  354. begin
  355. consume(_COLON);
  356. { check for an open array }
  357. if token=_ARRAY then
  358. begin
  359. consume(_ARRAY);
  360. consume(_OF);
  361. { define range and type of range }
  362. tt.setdef(tarraydef.create(0,-1,s32bittype));
  363. { array of const ? }
  364. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  365. begin
  366. consume(_CONST);
  367. srsym:=searchsymonlyin(systemunit,'TVARREC');
  368. if not assigned(srsym) then
  369. InternalError(1234124);
  370. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  371. tarraydef(tt.def).IsArrayOfConst:=true;
  372. end
  373. else
  374. begin
  375. { define field type }
  376. single_type(arrayelementtype,hs1,false);
  377. tarraydef(tt.def).setelementtype(arrayelementtype);
  378. end;
  379. end
  380. else
  381. begin
  382. { open string ? }
  383. if (varspez=vs_var) and
  384. (
  385. (
  386. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  387. (cs_openstring in aktmoduleswitches) and
  388. not(cs_ansistrings in aktlocalswitches)
  389. ) or
  390. (idtoken=_OPENSTRING)) then
  391. begin
  392. consume(token);
  393. tt:=openshortstringtype;
  394. hs1:='openstring';
  395. end
  396. else
  397. begin
  398. { everything else }
  399. single_type(tt,hs1,false);
  400. end;
  401. { default parameter }
  402. if (m_default_para in aktmodeswitches) then
  403. begin
  404. if try_to_consume(_EQUAL) then
  405. begin
  406. vs:=tvarsym(sc.first);
  407. if assigned(vs.listnext) then
  408. Message(parser_e_default_value_only_one_para);
  409. { prefix 'def' to the parameter name }
  410. tdefaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  411. if assigned(tdefaultvalue) then
  412. tprocdef(pd).parast.insert(tdefaultvalue);
  413. defaultrequired:=true;
  414. end
  415. else
  416. begin
  417. if defaultrequired then
  418. Message1(parser_e_default_value_expected_for_para,vs.name);
  419. end;
  420. end;
  421. end;
  422. end
  423. else
  424. begin
  425. {$ifndef UseNiceNames}
  426. hs1:='$$$';
  427. {$else UseNiceNames}
  428. hs1:='var';
  429. {$endif UseNiceNames}
  430. tt:=cformaltype;
  431. end;
  432. { File types are only allowed for var parameters }
  433. if (tt.def.deftype=filedef) and
  434. (varspez<>vs_var) then
  435. CGMessage(cg_e_file_must_call_by_reference);
  436. vs:=tvarsym(sc.first);
  437. while assigned(vs) do
  438. begin
  439. { update varsym }
  440. vs.vartype:=tt;
  441. { For proc vars we only need the definitions }
  442. if not is_procvar then
  443. begin
  444. if (varspez in [vs_var,vs_const,vs_out]) and
  445. paramanager.push_addr_param(varspez,tt.def,pd.proccalloption) then
  446. include(vs.varoptions,vo_regable);
  447. end;
  448. pd.concatpara(nil,tt,vs,tdefaultvalue,false);
  449. vs:=tvarsym(vs.listnext);
  450. end;
  451. until not try_to_consume(_SEMICOLON);
  452. { remove parasymtable from stack }
  453. sc.free;
  454. { reset object options }
  455. dec(testcurobject);
  456. current_object_option:=old_object_option;
  457. consume(_RKLAMMER);
  458. end;
  459. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption):tprocdef;
  460. var
  461. orgsp,sp : stringid;
  462. sym : tsym;
  463. srsymtable : tsymtable;
  464. storepos,
  465. procstartfilepos : tfileposinfo;
  466. searchagain : boolean;
  467. i : longint;
  468. st : tsymtable;
  469. pd : tprocdef;
  470. aprocsym : tprocsym;
  471. begin
  472. { Save the position where this procedure really starts }
  473. procstartfilepos:=akttokenpos;
  474. pd:=nil;
  475. aprocsym:=nil;
  476. if (potype=potype_operator) then
  477. begin
  478. sp:=overloaded_names[optoken];
  479. orgsp:=sp;
  480. end
  481. else
  482. begin
  483. sp:=pattern;
  484. orgsp:=orgpattern;
  485. consume(_ID);
  486. end;
  487. { examine interface map: function/procedure iname.functionname=locfuncname }
  488. if assigned(aclass) and
  489. assigned(aclass.implementedinterfaces) and
  490. (aclass.implementedinterfaces.count>0) and
  491. try_to_consume(_POINT) then
  492. begin
  493. storepos:=akttokenpos;
  494. akttokenpos:=procstartfilepos;
  495. { get interface syms}
  496. searchsym(sp,sym,srsymtable);
  497. if not assigned(sym) then
  498. begin
  499. identifier_not_found(orgsp);
  500. sym:=generrorsym;
  501. end;
  502. akttokenpos:=storepos;
  503. { qualifier is interface? }
  504. if (sym.typ=typesym) and
  505. (ttypesym(sym).restype.def.deftype=objectdef) then
  506. i:=aclass.implementedinterfaces.searchintf(ttypesym(sym).restype.def)
  507. else
  508. i:=-1;
  509. if (i=-1) then
  510. Message(parser_e_interface_id_expected);
  511. consume(_ID);
  512. consume(_EQUAL);
  513. if (token=_ID) then
  514. aclass.implementedinterfaces.addmappings(i,sp,pattern);
  515. consume(_ID);
  516. result:=nil;
  517. exit;
  518. end;
  519. { method ? }
  520. if not assigned(aclass) and
  521. (potype<>potype_operator) and
  522. (symtablestack.symtablelevel=main_program_level) and
  523. try_to_consume(_POINT) then
  524. begin
  525. { search for object name }
  526. storepos:=akttokenpos;
  527. akttokenpos:=procstartfilepos;
  528. searchsym(sp,sym,srsymtable);
  529. if not assigned(sym) then
  530. begin
  531. identifier_not_found(orgsp);
  532. sym:=generrorsym;
  533. end;
  534. akttokenpos:=storepos;
  535. { consume proc name }
  536. sp:=pattern;
  537. orgsp:=orgpattern;
  538. procstartfilepos:=akttokenpos;
  539. consume(_ID);
  540. { qualifier is class name ? }
  541. if (sym.typ=typesym) and
  542. (ttypesym(sym).restype.def.deftype=objectdef) then
  543. begin
  544. aclass:=tobjectdef(ttypesym(sym).restype.def);
  545. aprocsym:=tprocsym(aclass.symtable.search(sp));
  546. { we solve this below }
  547. if assigned(aprocsym) then
  548. begin
  549. if aprocsym.typ<>procsym then
  550. begin
  551. { we use a different error message for tp7 so it looks more compatible }
  552. if (m_fpc in aktmodeswitches) then
  553. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  554. else
  555. Message(parser_e_methode_id_expected);
  556. { rename the name to an unique name to avoid an
  557. error when inserting the symbol in the symtable }
  558. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  559. aprocsym:=nil;
  560. end;
  561. end
  562. else
  563. Message(parser_e_methode_id_expected);
  564. end
  565. else
  566. Message(parser_e_class_id_expected);
  567. end
  568. else
  569. begin
  570. { check for constructor/destructor which is not allowed here }
  571. if (not parse_only) and
  572. (potype in [potype_constructor,potype_destructor]) then
  573. Message(parser_e_constructors_always_objects);
  574. repeat
  575. searchagain:=false;
  576. akttokenpos:=procstartfilepos;
  577. aprocsym:=tprocsym(symtablestack.search(sp));
  578. if not(parse_only) and
  579. not assigned(aprocsym) and
  580. (symtablestack.symtabletype=staticsymtable) and
  581. assigned(symtablestack.next) and
  582. (symtablestack.next.unitid=0) then
  583. begin
  584. { The procedure we prepare for is in the implementation
  585. part of the unit we compile. It is also possible that we
  586. are compiling a program, which is also some kind of
  587. implementaion part.
  588. We need to find out if the procedure is global. If it is
  589. global, it is in the global symtable.}
  590. aprocsym:=tprocsym(symtablestack.next.search(sp));
  591. end;
  592. { Check if overloaded is a procsym }
  593. if assigned(aprocsym) and
  594. (aprocsym.typ<>procsym) then
  595. begin
  596. { when the other symbol is a unit symbol then hide the unit
  597. symbol. Only in tp mode because it's bad programming }
  598. if (m_duplicate_names in aktmodeswitches) and
  599. (aprocsym.typ=unitsym) then
  600. begin
  601. aprocsym.owner.rename(aprocsym.name,'hidden'+aprocsym.name);
  602. searchagain:=true;
  603. end
  604. else
  605. begin
  606. { we use a different error message for tp7 so it looks more compatible }
  607. if (m_fpc in aktmodeswitches) then
  608. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  609. else
  610. DuplicateSym(aprocsym);
  611. { rename the name to an unique name to avoid an
  612. error when inserting the symbol in the symtable }
  613. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  614. { generate a new aktprocsym }
  615. aprocsym:=nil;
  616. end;
  617. end;
  618. until not searchagain;
  619. end;
  620. { test again if assigned, it can be reset to recover }
  621. if not assigned(aprocsym) then
  622. begin
  623. { create a new procsym and set the real filepos }
  624. akttokenpos:=procstartfilepos;
  625. { for operator we have only one procsym for each overloaded
  626. operation }
  627. if (potype=potype_operator) then
  628. begin
  629. { is the current overload sym already in the current unit }
  630. if assigned(overloaded_operators[optoken]) and
  631. (overloaded_operators[optoken].owner=symtablestack) then
  632. aprocsym:=overloaded_operators[optoken]
  633. else
  634. begin
  635. { create the procsym with saving the original case }
  636. aprocsym:=tprocsym.create('$'+sp);
  637. if assigned(overloaded_operators[optoken]) then
  638. overloaded_operators[optoken].concat_procdefs_to(aprocsym);
  639. overloaded_operators[optoken]:=aprocsym;
  640. end;
  641. end
  642. else
  643. aprocsym:=tprocsym.create(orgsp);
  644. symtablestack.insert(aprocsym);
  645. end;
  646. { to get the correct symtablelevel we must ignore objectsymtables }
  647. st:=symtablestack;
  648. while not(st.symtabletype in [staticsymtable,globalsymtable,localsymtable]) do
  649. st:=st.next;
  650. pd:=tprocdef.create(st.symtablelevel+1);
  651. pd._class:=aclass;
  652. pd.procsym:=aprocsym;
  653. pd.proctypeoption:=potype;
  654. { methods need to be exported }
  655. if assigned(aclass) and
  656. (
  657. (symtablestack.symtabletype=objectsymtable) or
  658. (symtablestack.symtablelevel=main_program_level)
  659. ) then
  660. include(pd.procoptions,po_public);
  661. { symbol options that need to be kept per procdef }
  662. pd.fileinfo:=procstartfilepos;
  663. pd.symoptions:=current_object_option;
  664. { parse parameters }
  665. if token=_LKLAMMER then
  666. parse_parameter_dec(pd);
  667. { return created tprocdef }
  668. result:=pd;
  669. end;
  670. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  671. var
  672. pd : tprocdef;
  673. hs : string;
  674. isclassmethod : boolean;
  675. begin
  676. pd:=nil;
  677. { read class method }
  678. if try_to_consume(_CLASS) then
  679. begin
  680. { class method only allowed for procedures and functions }
  681. if not(token in [_FUNCTION,_PROCEDURE]) then
  682. Message(parser_e_procedure_or_function_expected);
  683. isclassmethod:=true;
  684. end
  685. else
  686. isclassmethod:=false;
  687. case token of
  688. _FUNCTION :
  689. begin
  690. consume(_FUNCTION);
  691. pd:=parse_proc_head(aclass,potype_none);
  692. if assigned(pd) then
  693. begin
  694. if try_to_consume(_COLON) then
  695. begin
  696. inc(testcurobject);
  697. single_type(pd.rettype,hs,false);
  698. pd.test_if_fpu_result;
  699. dec(testcurobject);
  700. end
  701. else
  702. begin
  703. if (
  704. not(is_interface(pd._class)) and
  705. not(pd.forwarddef)
  706. ) or
  707. (m_repeat_forward in aktmodeswitches) then
  708. begin
  709. consume(_COLON);
  710. consume_all_until(_SEMICOLON);
  711. end;
  712. end;
  713. if isclassmethod then
  714. include(pd.procoptions,po_classmethod);
  715. end
  716. else
  717. begin
  718. { recover }
  719. consume(_COLON);
  720. consume_all_until(_SEMICOLON);
  721. end;
  722. end;
  723. _PROCEDURE :
  724. begin
  725. consume(_PROCEDURE);
  726. pd:=parse_proc_head(aclass,potype_none);
  727. if assigned(pd) then
  728. begin
  729. pd.rettype:=voidtype;
  730. if isclassmethod then
  731. include(pd.procoptions,po_classmethod);
  732. end;
  733. end;
  734. _CONSTRUCTOR :
  735. begin
  736. consume(_CONSTRUCTOR);
  737. pd:=parse_proc_head(aclass,potype_constructor);
  738. if assigned(pd) and
  739. assigned(pd._class) then
  740. begin
  741. { Set return type, class constructors return the
  742. created instance, object constructors return boolean }
  743. if is_class(pd._class) then
  744. pd.rettype.setdef(pd._class)
  745. else
  746. pd.rettype:=booltype;
  747. end;
  748. end;
  749. _DESTRUCTOR :
  750. begin
  751. consume(_DESTRUCTOR);
  752. pd:=parse_proc_head(aclass,potype_destructor);
  753. if assigned(pd) then
  754. pd.rettype:=voidtype;
  755. end;
  756. _OPERATOR :
  757. begin
  758. consume(_OPERATOR);
  759. if (token in [first_overloaded..last_overloaded]) then
  760. begin
  761. optoken:=token;
  762. end
  763. else
  764. begin
  765. Message(parser_e_overload_operator_failed);
  766. { Use the dummy NOTOKEN that is also declared
  767. for the overloaded_operator[] }
  768. optoken:=NOTOKEN;
  769. end;
  770. consume(token);
  771. pd:=parse_proc_head(aclass,potype_operator);
  772. if assigned(pd) then
  773. begin
  774. if pd.parast.symtablelevel>normal_function_level then
  775. Message(parser_e_no_local_operator);
  776. if token<>_ID then
  777. begin
  778. if not(m_result in aktmodeswitches) then
  779. consume(_ID);
  780. end
  781. else
  782. begin
  783. pd.resultname:=orgpattern;
  784. consume(_ID);
  785. end;
  786. if not try_to_consume(_COLON) then
  787. begin
  788. consume(_COLON);
  789. pd.rettype:=generrortype;
  790. consume_all_until(_SEMICOLON);
  791. end
  792. else
  793. begin
  794. single_type(pd.rettype,hs,false);
  795. pd.test_if_fpu_result;
  796. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  797. ((pd.rettype.def.deftype<>orddef) or
  798. (torddef(pd.rettype.def).typ<>bool8bit)) then
  799. Message(parser_e_comparative_operator_return_boolean);
  800. if (optoken=_ASSIGNMENT) and
  801. equal_defs(pd.rettype.def,
  802. tvarsym(pd.parast.symindex.first).vartype.def) then
  803. message(parser_e_no_such_assignment)
  804. else if not isoperatoracceptable(pd,optoken) then
  805. Message(parser_e_overload_impossible);
  806. end;
  807. end
  808. else
  809. begin
  810. { recover }
  811. try_to_consume(_ID);
  812. consume(_COLON);
  813. consume_all_until(_SEMICOLON);
  814. end;
  815. end;
  816. end;
  817. { support procedure proc stdcall export; }
  818. if not(is_proc_directive(token,false)) 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 : [];
  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;isprocvar:boolean):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. if (not isprocvar) or
  1417. (pd_procvar in proc_direcdata[i].pd_flags) then
  1418. is_proc_directive:=true;
  1419. exit;
  1420. end;
  1421. end;
  1422. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1423. {
  1424. Parse the procedure directive, returns true if a correct directive is found
  1425. }
  1426. var
  1427. p : longint;
  1428. found : boolean;
  1429. name : stringid;
  1430. begin
  1431. parse_proc_direc:=false;
  1432. name:=tokeninfo^[idtoken].str;
  1433. found:=false;
  1434. { Hint directive? Then exit immediatly }
  1435. if (m_hintdirective in aktmodeswitches) then
  1436. begin
  1437. case idtoken of
  1438. _LIBRARY,
  1439. _PLATFORM,
  1440. _UNIMPLEMENTED,
  1441. _DEPRECATED :
  1442. exit;
  1443. end;
  1444. end;
  1445. { retrieve data for directive if found }
  1446. for p:=1 to num_proc_directives do
  1447. if proc_direcdata[p].idtok=idtoken then
  1448. begin
  1449. found:=true;
  1450. break;
  1451. end;
  1452. { Check if the procedure directive is known }
  1453. if not found then
  1454. begin
  1455. { parsing a procvar type the name can be any
  1456. next variable !! }
  1457. if (pdflags * [pd_procvar,pd_object])=[] then
  1458. Message1(parser_w_unknown_proc_directive_ignored,name);
  1459. exit;
  1460. end;
  1461. { static needs a special treatment }
  1462. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1463. exit;
  1464. { Conflicts between directives ? }
  1465. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1466. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1467. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1468. begin
  1469. Message1(parser_e_proc_dir_conflict,name);
  1470. exit;
  1471. end;
  1472. { set calling convention }
  1473. if proc_direcdata[p].pocall<>pocall_none then
  1474. begin
  1475. if (po_hascallingconvention in pd.procoptions) then
  1476. begin
  1477. Message2(parser_w_proc_overriding_calling,
  1478. proccalloptionStr[pd.proccalloption],
  1479. proccalloptionStr[proc_direcdata[p].pocall]);
  1480. end;
  1481. pd.proccalloption:=proc_direcdata[p].pocall;
  1482. include(pd.procoptions,po_hascallingconvention);
  1483. end;
  1484. { check if method and directive not for object, like public.
  1485. This needs to be checked also for procvars }
  1486. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1487. (pd.owner.symtabletype=objectsymtable) then
  1488. exit;
  1489. if pd.deftype=procdef then
  1490. begin
  1491. { Check if the directive is only for objects }
  1492. if (pd_object in proc_direcdata[p].pd_flags) and
  1493. not assigned(tprocdef(pd)._class) then
  1494. exit;
  1495. { check if method and directive not for interface }
  1496. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1497. is_interface(tprocdef(pd)._class) then
  1498. exit;
  1499. end;
  1500. { consume directive, and turn flag on }
  1501. consume(token);
  1502. parse_proc_direc:=true;
  1503. { Check the pd_flags if the directive should be allowed }
  1504. if (pd_interface in pdflags) and
  1505. not(pd_interface in proc_direcdata[p].pd_flags) then
  1506. begin
  1507. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1508. exit;
  1509. end;
  1510. if (pd_implemen in pdflags) and
  1511. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1512. begin
  1513. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1514. exit;
  1515. end;
  1516. if (pd_procvar in pdflags) and
  1517. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1518. begin
  1519. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1520. exit;
  1521. end;
  1522. { Return the new pd_flags }
  1523. if not(pd_body in proc_direcdata[p].pd_flags) then
  1524. exclude(pdflags,pd_body);
  1525. { Add the correct flag }
  1526. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1527. { Call the handler }
  1528. if pointer({$ifndef FPCPROCVAR}@{$endif}proc_direcdata[p].handler)<>nil then
  1529. proc_direcdata[p].handler(pd);
  1530. end;
  1531. procedure handle_calling_convention(pd:tabstractprocdef);
  1532. begin
  1533. { set the default calling convention if none provided }
  1534. if not(po_hascallingconvention in pd.procoptions) then
  1535. pd.proccalloption:=aktdefproccall
  1536. else
  1537. begin
  1538. if pd.proccalloption=pocall_none then
  1539. internalerror(200309081);
  1540. end;
  1541. { handle proccall specific settings }
  1542. case pd.proccalloption of
  1543. pocall_cdecl :
  1544. begin
  1545. { set mangledname }
  1546. if (pd.deftype=procdef) then
  1547. begin
  1548. if not tprocdef(pd).has_mangledname then
  1549. begin
  1550. if assigned(tprocdef(pd)._class) then
  1551. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd)._class.objrealname^+'_'+tprocdef(pd).procsym.realname)
  1552. else
  1553. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd).procsym.realname);
  1554. end;
  1555. { check C cdecl para types }
  1556. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_c_para,nil);
  1557. { Adjust alignment to match cdecl or stdcall }
  1558. pd.paraalign:=std_param_align;
  1559. end;
  1560. end;
  1561. pocall_cppdecl :
  1562. begin
  1563. { set mangledname }
  1564. if (pd.deftype=procdef) then
  1565. begin
  1566. if not tprocdef(pd).has_mangledname then
  1567. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd).cplusplusmangledname);
  1568. { check C cdecl para types }
  1569. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_c_para,nil);
  1570. { Adjust alignment to match cdecl or stdcall }
  1571. pd.paraalign:=std_param_align;
  1572. end;
  1573. end;
  1574. pocall_stdcall :
  1575. begin
  1576. if (pd.deftype=procdef) then
  1577. begin
  1578. { Adjust alignment to match cdecl or stdcall }
  1579. pd.paraalign:=std_param_align;
  1580. end;
  1581. end;
  1582. pocall_compilerproc :
  1583. begin
  1584. if (pd.deftype<>procdef) then
  1585. internalerror(200110232);
  1586. tprocdef(pd).setmangledname(lower(tprocdef(pd).procsym.name));
  1587. end;
  1588. pocall_register :
  1589. begin
  1590. { Adjust alignment to match cdecl or stdcall }
  1591. pd.paraalign:=std_param_align;
  1592. end;
  1593. pocall_far16 :
  1594. begin
  1595. { Temporary stub, must be rewritten to support OS/2 far16 }
  1596. Message1(parser_w_proc_directive_ignored,'FAR16');
  1597. end;
  1598. pocall_palmossyscall :
  1599. begin
  1600. if (pd.deftype=procdef) then
  1601. begin
  1602. { Adjust positions of args for cdecl or stdcall }
  1603. pd.paraalign:=std_param_align;
  1604. end;
  1605. end;
  1606. pocall_inline :
  1607. begin
  1608. if not(cs_support_inline in aktmoduleswitches) then
  1609. begin
  1610. Message(parser_e_proc_inline_not_supported);
  1611. pd.proccalloption:=pocall_default;
  1612. end;
  1613. end;
  1614. end;
  1615. { For varargs directive also cdecl and external must be defined }
  1616. if (po_varargs in pd.procoptions) then
  1617. begin
  1618. { check first for external in the interface, if available there
  1619. then the cdecl must also be there since there is no implementation
  1620. available to contain it }
  1621. if parse_only then
  1622. begin
  1623. { if external is available, then cdecl must also be available }
  1624. if (po_external in pd.procoptions) and
  1625. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1626. Message(parser_e_varargs_need_cdecl_and_external);
  1627. end
  1628. else
  1629. begin
  1630. { both must be defined now }
  1631. if not(po_external in pd.procoptions) or
  1632. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1633. Message(parser_e_varargs_need_cdecl_and_external);
  1634. end;
  1635. end;
  1636. { add mangledname to external list }
  1637. if (pd.deftype=procdef) and
  1638. (po_external in pd.procoptions) and
  1639. target_info.DllScanSupported then
  1640. current_module.externals.insert(tExternalsItem.create(tprocdef(pd).mangledname));
  1641. end;
  1642. procedure calc_parast(pd:tabstractprocdef);
  1643. var
  1644. currpara : tparaitem;
  1645. begin
  1646. { insert hidden high parameters }
  1647. insert_hidden_para(pd);
  1648. { insert hidden self parameter }
  1649. insert_self_and_vmt_para(pd);
  1650. { insert funcret parameter if required }
  1651. insert_funcret_para(pd);
  1652. { insert parentfp parameter if required }
  1653. insert_parentfp_para(pd);
  1654. if pd.proccalloption=pocall_pascal then
  1655. tparaitem(pd.para.first):=reverseparaitems(tparaitem(pd.para.first));
  1656. currpara:=tparaitem(pd.para.first);
  1657. while assigned(currpara) do
  1658. begin
  1659. if not(assigned(currpara.parasym) and (currpara.parasym.typ=varsym)) then
  1660. internalerror(200304232);
  1661. { connect parasym to paraitem }
  1662. tvarsym(currpara.parasym).paraitem:=currpara;
  1663. { We need a local copy for a value parameter when only the
  1664. address is pushed. Open arrays and Array of Const are
  1665. an exception because they are allocated at runtime and the
  1666. address that is pushed is patched }
  1667. if (currpara.paratyp=vs_value) and
  1668. paramanager.push_addr_param(currpara.paratyp,currpara.paratype.def,pd.proccalloption) and
  1669. not(is_open_array(currpara.paratype.def) or
  1670. is_array_of_const(currpara.paratype.def)) then
  1671. include(tvarsym(currpara.parasym).varoptions,vo_has_local_copy);
  1672. currpara:=tparaitem(currpara.next);
  1673. end;
  1674. end;
  1675. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  1676. {
  1677. Parse the procedure directives. It does not matter if procedure directives
  1678. are written using ;procdir; or ['procdir'] syntax.
  1679. }
  1680. var
  1681. res : boolean;
  1682. begin
  1683. while token in [_ID,_LECKKLAMMER] do
  1684. begin
  1685. if try_to_consume(_LECKKLAMMER) then
  1686. begin
  1687. repeat
  1688. parse_proc_direc(pd,pdflags);
  1689. until not try_to_consume(_COMMA);
  1690. consume(_RECKKLAMMER);
  1691. { we always expect at least '[];' }
  1692. res:=true;
  1693. end
  1694. else
  1695. begin
  1696. res:=parse_proc_direc(pd,pdflags);
  1697. end;
  1698. { A procedure directive normally followed by a semicolon, but in
  1699. a const section or reading a type we should stop when _EQUAL is found,
  1700. because a constant/default value follows }
  1701. if res then
  1702. begin
  1703. if (block_type in [bt_const,bt_type]) and
  1704. (token=_EQUAL) then
  1705. break;
  1706. { support procedure proc;stdcall export; }
  1707. if not(is_proc_directive(token,(pd.deftype=procvardef))) then
  1708. consume(_SEMICOLON);
  1709. end
  1710. else
  1711. break;
  1712. end;
  1713. end;
  1714. procedure parse_var_proc_directives(sym:tsym);
  1715. var
  1716. pdflags : tpdflags;
  1717. pd : tabstractprocdef;
  1718. begin
  1719. pdflags:=[pd_procvar];
  1720. pd:=nil;
  1721. case sym.typ of
  1722. varsym :
  1723. pd:=tabstractprocdef(tvarsym(sym).vartype.def);
  1724. typedconstsym :
  1725. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  1726. typesym :
  1727. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  1728. else
  1729. internalerror(2003042617);
  1730. end;
  1731. if pd.deftype<>procvardef then
  1732. internalerror(2003042618);
  1733. { names should never be used anyway }
  1734. parse_proc_directives(pd,pdflags);
  1735. end;
  1736. procedure parse_object_proc_directives(pd:tabstractprocdef);
  1737. var
  1738. pdflags : tpdflags;
  1739. begin
  1740. pdflags:=[pd_object];
  1741. parse_proc_directives(pd,pdflags);
  1742. end;
  1743. function proc_add_definition(var pd:tprocdef):boolean;
  1744. {
  1745. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  1746. forwarddef is found and reused it returns true
  1747. }
  1748. var
  1749. hd : tprocdef;
  1750. ad,fd : tsym;
  1751. s1,s2 : stringid;
  1752. i : cardinal;
  1753. forwardfound : boolean;
  1754. po_comp : tprocoptions;
  1755. aprocsym : tprocsym;
  1756. begin
  1757. forwardfound:=false;
  1758. aprocsym:=tprocsym(pd.procsym);
  1759. { check overloaded functions if the same function already exists }
  1760. for i:=1 to aprocsym.procdef_count do
  1761. begin
  1762. hd:=aprocsym.procdef[i];
  1763. { Skip overloaded definitions that are declared in other
  1764. units }
  1765. if hd.procsym<>aprocsym then
  1766. continue;
  1767. { check the parameters, for delphi/tp it is possible to
  1768. leave the parameters away in the implementation (forwarddef=false).
  1769. But for an overload declared function this is not allowed }
  1770. if { check if empty implementation arguments match is allowed }
  1771. (
  1772. not(m_repeat_forward in aktmodeswitches) and
  1773. not(pd.forwarddef) and
  1774. (pd.maxparacount=0) and
  1775. not(po_overload in hd.procoptions)
  1776. ) or
  1777. { check arguments }
  1778. (
  1779. (compare_paras(pd.para,hd.para,cp_none,false)>=te_equal) and
  1780. { for operators equal_paras is not enough !! }
  1781. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1782. equal_defs(hd.rettype.def,pd.rettype.def))
  1783. ) then
  1784. begin
  1785. { Check if we've found the forwarddef, if found then
  1786. we need to update the forward def with the current
  1787. implementation settings }
  1788. if hd.forwarddef then
  1789. begin
  1790. forwardfound:=true;
  1791. { Check if the procedure type and return type are correct,
  1792. also the parameters must match also with the type }
  1793. if (hd.proctypeoption<>pd.proctypeoption) or
  1794. (
  1795. (m_repeat_forward in aktmodeswitches) and
  1796. (not((pd.maxparacount=0) or
  1797. (compare_paras(pd.para,hd.para,cp_all,false)>=te_equal)))
  1798. ) or
  1799. (
  1800. ((m_repeat_forward in aktmodeswitches) or
  1801. not(is_void(pd.rettype.def))) and
  1802. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  1803. begin
  1804. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  1805. pd.fullprocname(false));
  1806. aprocsym.write_parameter_lists(pd);
  1807. break;
  1808. end;
  1809. { Check if both are declared forward }
  1810. if hd.forwarddef and pd.forwarddef then
  1811. begin
  1812. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  1813. pd.fullprocname(false));
  1814. end;
  1815. { internconst or internproc only need to be defined once }
  1816. if (hd.proccalloption=pocall_internproc) then
  1817. pd.proccalloption:=hd.proccalloption
  1818. else
  1819. if (pd.proccalloption=pocall_internproc) then
  1820. hd.proccalloption:=pd.proccalloption;
  1821. if (po_internconst in hd.procoptions) then
  1822. include(pd.procoptions,po_internconst)
  1823. else if (po_internconst in pd.procoptions) then
  1824. include(hd.procoptions,po_internconst);
  1825. { Check calling convention }
  1826. if (hd.proccalloption<>pd.proccalloption) then
  1827. begin
  1828. { In delphi it is possible to specify the calling
  1829. convention in the interface or implementation if
  1830. there was no convention specified in the other
  1831. part }
  1832. if (m_delphi in aktmodeswitches) then
  1833. begin
  1834. if not(po_hascallingconvention in pd.procoptions) then
  1835. pd.proccalloption:=hd.proccalloption
  1836. else
  1837. if not(po_hascallingconvention in hd.procoptions) then
  1838. hd.proccalloption:=pd.proccalloption
  1839. else
  1840. begin
  1841. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  1842. aprocsym.write_parameter_lists(pd);
  1843. { restore interface settings }
  1844. pd.proccalloption:=hd.proccalloption;
  1845. end;
  1846. end
  1847. else
  1848. begin
  1849. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  1850. aprocsym.write_parameter_lists(pd);
  1851. { restore interface settings }
  1852. pd.proccalloption:=hd.proccalloption;
  1853. end;
  1854. end;
  1855. { Check procedure options, Delphi requires that class is
  1856. repeated in the implementation for class methods }
  1857. if (m_fpc in aktmodeswitches) then
  1858. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  1859. else
  1860. po_comp:=[po_classmethod,po_methodpointer];
  1861. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  1862. begin
  1863. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  1864. pd.fullprocname(false));
  1865. aprocsym.write_parameter_lists(pd);
  1866. { This error is non-fatal, we can recover }
  1867. end;
  1868. { Check manglednames }
  1869. if (m_repeat_forward in aktmodeswitches) or
  1870. (pd.minparacount>0) then
  1871. begin
  1872. { If mangled names are equal then they have the same amount of arguments }
  1873. { We can check the names of the arguments }
  1874. { both symtables are in the same order from left to right }
  1875. ad:=tsym(hd.parast.symindex.first);
  1876. fd:=tsym(pd.parast.symindex.first);
  1877. repeat
  1878. { skip default parameter constsyms }
  1879. while assigned(ad) and (ad.typ<>varsym) do
  1880. ad:=tsym(ad.indexnext);
  1881. while assigned(fd) and (fd.typ<>varsym) do
  1882. fd:=tsym(fd.indexnext);
  1883. { stop when one of the two lists is at the end }
  1884. if not assigned(ad) or not assigned(fd) then
  1885. break;
  1886. { retrieve names, remove reg for register parameters }
  1887. s1:=ad.name;
  1888. s2:=fd.name;
  1889. {$ifdef i386}
  1890. if copy(s1,1,3)='reg' then
  1891. delete(s1,1,3);
  1892. if copy(s2,1,3)='reg' then
  1893. delete(s2,1,3);
  1894. {$endif i386}
  1895. { compare names }
  1896. if (s1<>s2) then
  1897. begin
  1898. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  1899. aprocsym.name,s1,s2);
  1900. break;
  1901. end;
  1902. ad:=tsym(ad.indexnext);
  1903. fd:=tsym(fd.indexnext);
  1904. until false;
  1905. if assigned(ad) xor assigned(fd) then
  1906. internalerror(200204178);
  1907. end;
  1908. { Everything is checked, now we can update the forward declaration
  1909. with the new data from the implementation }
  1910. hd.forwarddef:=pd.forwarddef;
  1911. hd.hasforward:=true;
  1912. hd.paraalign:=pd.paraalign;
  1913. hd.procoptions:=hd.procoptions+pd.procoptions;
  1914. if hd.extnumber=65535 then
  1915. hd.extnumber:=pd.extnumber;
  1916. while not pd.aliasnames.empty do
  1917. hd.aliasnames.insert(pd.aliasnames.getfirst);
  1918. { update fileinfo so position references the implementation,
  1919. also update funcretsym if it is already generated }
  1920. hd.fileinfo:=pd.fileinfo;
  1921. if assigned(hd.funcretsym) then
  1922. hd.funcretsym.fileinfo:=pd.fileinfo;
  1923. { update mangledname if the implementation has a fixed mangledname set }
  1924. if pd.has_mangledname then
  1925. begin
  1926. { rename also asmsymbol first, because the name can already be used }
  1927. objectlibrary.renameasmsymbol(hd.mangledname,pd.mangledname);
  1928. hd.setmangledname(pd.mangledname);
  1929. end;
  1930. { for compilerproc defines we need to rename and update the
  1931. symbolname to lowercase }
  1932. if (pd.proccalloption=pocall_compilerproc) then
  1933. begin
  1934. { rename to lowercase so users can't access it }
  1935. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  1936. { also update the realname that is stored in the ppu }
  1937. stringdispose(aprocsym._realname);
  1938. aprocsym._realname:=stringdup('$'+aprocsym.name);
  1939. { the mangeled name is already changed by the pd_compilerproc }
  1940. { handler. It must be done immediately because if we have a }
  1941. { call to a compilerproc before it's implementation is }
  1942. { encountered, it must already use the new mangled name (JM) }
  1943. end;
  1944. { the procdef will be released by the symtable, we release
  1945. at least the parast }
  1946. pd.releasemem;
  1947. pd:=hd;
  1948. end
  1949. else
  1950. begin
  1951. { abstract methods aren't forward defined, but this }
  1952. { needs another error message }
  1953. if (po_abstractmethod in hd.procoptions) then
  1954. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  1955. else
  1956. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  1957. end;
  1958. { we found one proc with the same arguments, there are no others
  1959. so we can stop }
  1960. break;
  1961. end;
  1962. { check for allowing overload directive }
  1963. if not(m_fpc in aktmodeswitches) then
  1964. begin
  1965. { overload directive turns on overloading }
  1966. if ((po_overload in pd.procoptions) or
  1967. (po_overload in hd.procoptions)) then
  1968. begin
  1969. { check if all procs have overloading, but not if the proc was
  1970. already declared forward or abstract, then the check is already done }
  1971. if not(hd.hasforward or
  1972. (po_abstractmethod in hd.procoptions) or
  1973. (pd.forwarddef<>hd.forwarddef) or
  1974. ((po_overload in pd.procoptions) and
  1975. (po_overload in hd.procoptions))) then
  1976. begin
  1977. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  1978. break;
  1979. end;
  1980. end
  1981. else
  1982. begin
  1983. if not(hd.forwarddef) then
  1984. begin
  1985. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  1986. break;
  1987. end;
  1988. end;
  1989. end; { equal arguments }
  1990. end;
  1991. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  1992. list }
  1993. if not forwardfound then
  1994. begin
  1995. aprocsym.addprocdef(pd);
  1996. { add overloadnumber for unique naming, the overloadcount is
  1997. counted per module and 0 for the first procedure }
  1998. pd.overloadnumber:=aprocsym.overloadcount;
  1999. inc(aprocsym.overloadcount);
  2000. end;
  2001. proc_add_definition:=forwardfound;
  2002. end;
  2003. end.
  2004. {
  2005. $Log$
  2006. Revision 1.143 2003-10-02 21:13:09 peter
  2007. * procvar directive parsing fixes
  2008. Revision 1.142 2003/10/01 19:05:33 peter
  2009. * searchsym_type to search for type definitions. It ignores
  2010. records,objects and parameters
  2011. Revision 1.141 2003/10/01 18:28:55 peter
  2012. * don't look in objectsymtable when parsing the function return type
  2013. Revision 1.140 2003/10/01 16:49:05 florian
  2014. * para items are now reversed for pascal calling conventions
  2015. Revision 1.139 2003/09/28 21:44:55 peter
  2016. * fix check that filedef needs var para
  2017. Revision 1.138 2003/09/28 17:55:04 peter
  2018. * parent framepointer changed to hidden parameter
  2019. * tloadparentfpnode added
  2020. Revision 1.137 2003/09/25 21:24:09 peter
  2021. * don't include vo_has_local_copy for open array/array of const
  2022. Revision 1.136 2003/09/23 20:36:47 peter
  2023. * remove obsolete code
  2024. Revision 1.135 2003/09/23 17:56:05 peter
  2025. * locals and paras are allocated in the code generation
  2026. * tvarsym.localloc contains the location of para/local when
  2027. generating code for the current procedure
  2028. Revision 1.134 2003/09/16 16:17:01 peter
  2029. * varspez in calls to push_addr_param
  2030. Revision 1.133 2003/09/09 21:03:17 peter
  2031. * basics for x86 register calling
  2032. Revision 1.132 2003/09/09 15:54:10 peter
  2033. * calling convention fix
  2034. Revision 1.131 2003/09/07 22:09:35 peter
  2035. * preparations for different default calling conventions
  2036. * various RA fixes
  2037. Revision 1.130 2003/09/03 11:18:37 florian
  2038. * fixed arm concatcopy
  2039. + arm support in the common compiler sources added
  2040. * moved some generic cg code around
  2041. + tfputype added
  2042. * ...
  2043. Revision 1.129 2003/07/02 22:18:04 peter
  2044. * paraloc splitted in callerparaloc,calleeparaloc
  2045. * sparc calling convention updates
  2046. Revision 1.128 2003/06/13 21:19:31 peter
  2047. * current_procdef removed, use current_procinfo.procdef instead
  2048. Revision 1.127 2003/06/05 20:04:43 peter
  2049. * set po_public also when parsing the object declaration
  2050. Revision 1.126 2003/06/02 21:42:05 jonas
  2051. * function results can now also be regvars
  2052. - removed tprocinfo.return_offset, never use it again since it's invalid
  2053. if the result is a regvar
  2054. Revision 1.125 2003/05/22 21:31:35 peter
  2055. * defer codegeneration for nested procedures
  2056. Revision 1.124 2003/05/15 18:58:53 peter
  2057. * removed selfpointer_offset, vmtpointer_offset
  2058. * tvarsym.adjusted_address
  2059. * address in localsymtable is now in the real direction
  2060. * removed some obsolete globals
  2061. Revision 1.123 2003/05/13 15:18:49 peter
  2062. * fixed various crashes
  2063. Revision 1.122 2003/05/09 17:47:03 peter
  2064. * self moved to hidden parameter
  2065. * removed hdisposen,hnewn,selfn
  2066. Revision 1.121 2003/05/05 14:53:16 peter
  2067. * vs_hidden replaced by is_hidden boolean
  2068. Revision 1.120 2003/04/30 09:42:42 florian
  2069. + first changes to make self a hidden parameter
  2070. Revision 1.119 2003/04/27 11:21:33 peter
  2071. * aktprocdef renamed to current_procinfo.procdef
  2072. * procinfo renamed to current_procinfo
  2073. * procinfo will now be stored in current_module so it can be
  2074. cleaned up properly
  2075. * gen_main_procsym changed to create_main_proc and release_main_proc
  2076. to also generate a tprocinfo structure
  2077. * fixed unit implicit initfinal
  2078. Revision 1.118 2003/04/27 07:29:50 peter
  2079. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2080. a new procdef declaration
  2081. * aktprocsym removed
  2082. * lexlevel removed, use symtable.symtablelevel instead
  2083. * implicit init/final code uses the normal genentry/genexit
  2084. * funcret state checking updated for new funcret handling
  2085. Revision 1.117 2003/04/26 00:33:07 peter
  2086. * vo_is_result flag added for the special RESULT symbol
  2087. Revision 1.116 2003/04/25 20:59:33 peter
  2088. * removed funcretn,funcretsym, function result is now in varsym
  2089. and aliases for result and function name are added using absolutesym
  2090. * vs_hidden parameter for funcret passed in parameter
  2091. * vs_hidden fixes
  2092. * writenode changed to printnode and released from extdebug
  2093. * -vp option added to generate a tree.log with the nodetree
  2094. * nicer printnode for statements, callnode
  2095. Revision 1.115 2003/04/24 13:03:01 florian
  2096. * comp is now written with its bit pattern to the ppu instead as an extended
  2097. Revision 1.114 2003/04/23 13:12:26 peter
  2098. * fix po_comp setting for fpc mode
  2099. Revision 1.113 2003/04/23 10:12:51 peter
  2100. * don't check po_varargs for delphi
  2101. Revision 1.112 2003/04/22 13:47:08 peter
  2102. * fixed C style array of const
  2103. * fixed C array passing
  2104. * fixed left to right with high parameters
  2105. Revision 1.111 2003/04/10 17:57:53 peter
  2106. * vs_hidden released
  2107. Revision 1.110 2003/03/28 19:16:56 peter
  2108. * generic constructor working for i386
  2109. * remove fixed self register
  2110. * esi added as address register for i386
  2111. Revision 1.109 2003/03/23 23:21:42 hajny
  2112. + emx target added
  2113. Revision 1.108 2003/03/19 17:34:04 peter
  2114. * only allow class [procedure|function]
  2115. Revision 1.107 2003/03/17 18:56:02 peter
  2116. * fix crash with duplicate id
  2117. Revision 1.106 2003/03/17 15:54:22 peter
  2118. * store symoptions also for procdef
  2119. * check symoptions (private,public) when calculating possible
  2120. overload candidates
  2121. Revision 1.105 2003/01/15 20:02:28 carl
  2122. * fix highname problem
  2123. Revision 1.104 2003/01/12 15:42:23 peter
  2124. * m68k pathexist update from 1.0.x
  2125. * palmos res update from 1.0.x
  2126. Revision 1.103 2003/01/07 19:16:38 peter
  2127. * removed some duplicate code when creating aktprocsym
  2128. Revision 1.102 2003/01/05 18:17:45 peter
  2129. * more conflicts for constructor/destructor types
  2130. Revision 1.100 2003/01/02 19:49:00 peter
  2131. * update self parameter only for methodpointer and methods
  2132. Revision 1.99 2003/01/01 22:51:03 peter
  2133. * high value insertion changed so it works also when 2 parameters
  2134. are passed
  2135. Revision 1.98 2003/01/01 14:35:33 peter
  2136. * don't check for export directive repeat
  2137. Revision 1.97 2002/12/29 18:16:06 peter
  2138. * delphi allows setting calling convention in interface or
  2139. implementation
  2140. Revision 1.96 2002/12/29 14:55:44 peter
  2141. * fix static method check
  2142. * don't require class for class methods in the implementation for
  2143. non delphi modes
  2144. Revision 1.95 2002/12/27 15:25:14 peter
  2145. * check procoptions when a forward is found
  2146. * exclude some call directives for constructor/destructor
  2147. Revision 1.94 2002/12/25 01:26:56 peter
  2148. * duplicate procsym-unitsym fix
  2149. Revision 1.93 2002/12/24 21:21:06 peter
  2150. * remove code that skipped the _ prefix for win32 imports
  2151. Revision 1.92 2002/12/23 21:24:22 peter
  2152. * fix wrong internalerror when var names were different
  2153. Revision 1.91 2002/12/23 20:58:52 peter
  2154. * cdecl array fix, hack to change it to vs_var is not needed
  2155. Revision 1.90 2002/12/17 22:19:33 peter
  2156. * fixed pushing of records>8 bytes with stdcall
  2157. * simplified hightree loading
  2158. Revision 1.89 2002/12/15 21:07:30 peter
  2159. * don't allow external in object declarations
  2160. Revision 1.88 2002/12/15 19:34:31 florian
  2161. + some front end stuff for vs_hidden added
  2162. Revision 1.87 2002/12/07 14:27:07 carl
  2163. * 3% memory optimization
  2164. * changed some types
  2165. + added type checking with different size for call node and for
  2166. parameters
  2167. Revision 1.86 2002/12/06 17:51:10 peter
  2168. * merged cdecl and array fixes
  2169. Revision 1.85 2002/12/01 22:06:14 carl
  2170. * cleanup of error messages
  2171. Revision 1.84 2002/11/29 22:31:19 carl
  2172. + unimplemented hint directive added
  2173. * hint directive parsing implemented
  2174. * warning on these directives
  2175. Revision 1.83 2002/11/27 02:35:28 peter
  2176. * fixed typo in method comparing
  2177. Revision 1.82 2002/11/25 17:43:21 peter
  2178. * splitted defbase in defutil,symutil,defcmp
  2179. * merged isconvertable and is_equal into compare_defs(_ext)
  2180. * made operator search faster by walking the list only once
  2181. Revision 1.81 2002/11/18 17:31:58 peter
  2182. * pass proccalloption to ret_in_xxx and push_xxx functions
  2183. Revision 1.80 2002/11/17 16:31:56 carl
  2184. * memory optimization (3-4%) : cleanup of tai fields,
  2185. cleanup of tdef and tsym fields.
  2186. * make it work for m68k
  2187. Revision 1.79 2002/11/16 14:20:50 peter
  2188. * fix infinite loop in pd_inline
  2189. Revision 1.78 2002/11/15 01:58:53 peter
  2190. * merged changes from 1.0.7 up to 04-11
  2191. - -V option for generating bug report tracing
  2192. - more tracing for option parsing
  2193. - errors for cdecl and high()
  2194. - win32 import stabs
  2195. - win32 records<=8 are returned in eax:edx (turned off by default)
  2196. - heaptrc update
  2197. - more info for temp management in .s file with EXTDEBUG
  2198. Revision 1.77 2002/10/06 15:09:12 peter
  2199. * variant:=nil supported
  2200. Revision 1.76 2002/09/27 21:13:29 carl
  2201. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  2202. Revision 1.75 2002/09/16 14:11:13 peter
  2203. * add argument to equal_paras() to support default values or not
  2204. Revision 1.74 2002/09/10 16:27:28 peter
  2205. * don't insert parast in symtablestack, because typesyms should not be
  2206. searched in the the parast
  2207. Revision 1.73 2002/09/09 19:39:07 peter
  2208. * check return type for forwarddefs also not delphi mode when
  2209. the type is not void
  2210. Revision 1.72 2002/09/09 17:34:15 peter
  2211. * tdicationary.replace added to replace and item in a dictionary. This
  2212. is only allowed for the same name
  2213. * varsyms are inserted in symtable before the types are parsed. This
  2214. fixes the long standing "var longint : longint" bug
  2215. - consume_idlist and idstringlist removed. The loops are inserted
  2216. at the callers place and uses the symtable for duplicate id checking
  2217. Revision 1.71 2002/09/07 15:25:06 peter
  2218. * old logs removed and tabs fixed
  2219. Revision 1.70 2002/09/03 16:26:27 daniel
  2220. * Make Tprocdef.defs protected
  2221. Revision 1.69 2002/09/01 12:11:33 peter
  2222. * calc param_offset after parameters are read, because the calculation
  2223. depends on po_containself
  2224. Revision 1.68 2002/08/25 19:25:20 peter
  2225. * sym.insert_in_data removed
  2226. * symtable.insertvardata/insertconstdata added
  2227. * removed insert_in_data call from symtable.insert, it needs to be
  2228. called separatly. This allows to deref the address calculation
  2229. * procedures now calculate the parast addresses after the procedure
  2230. directives are parsed. This fixes the cdecl parast problem
  2231. * push_addr_param has an extra argument that specifies if cdecl is used
  2232. or not
  2233. Revision 1.67 2002/08/25 11:33:06 peter
  2234. * also check the paratypes when a forward was found
  2235. Revision 1.66 2002/08/19 19:36:44 peter
  2236. * More fixes for cross unit inlining, all tnodes are now implemented
  2237. * Moved pocall_internconst to po_internconst because it is not a
  2238. calling type at all and it conflicted when inlining of these small
  2239. functions was requested
  2240. Revision 1.65 2002/08/18 20:06:24 peter
  2241. * inlining is now also allowed in interface
  2242. * renamed write/load to ppuwrite/ppuload
  2243. * tnode storing in ppu
  2244. * nld,ncon,nbas are already updated for storing in ppu
  2245. Revision 1.64 2002/08/17 09:23:39 florian
  2246. * first part of procinfo rewrite
  2247. Revision 1.63 2002/08/11 14:32:27 peter
  2248. * renamed current_library to objectlibrary
  2249. Revision 1.62 2002/08/11 13:24:12 peter
  2250. * saving of asmsymbols in ppu supported
  2251. * asmsymbollist global is removed and moved into a new class
  2252. tasmlibrarydata that will hold the info of a .a file which
  2253. corresponds with a single module. Added librarydata to tmodule
  2254. to keep the library info stored for the module. In the future the
  2255. objectfiles will also be stored to the tasmlibrarydata class
  2256. * all getlabel/newasmsymbol and friends are moved to the new class
  2257. Revision 1.61 2002/07/26 21:15:40 florian
  2258. * rewrote the system handling
  2259. Revision 1.60 2002/07/20 11:57:55 florian
  2260. * types.pas renamed to defbase.pas because D6 contains a types
  2261. unit so this would conflicts if D6 programms are compiled
  2262. + Willamette/SSE2 instructions to assembler added
  2263. Revision 1.59 2002/07/11 14:41:28 florian
  2264. * start of the new generic parameter handling
  2265. Revision 1.58 2002/07/01 18:46:25 peter
  2266. * internal linker
  2267. * reorganized aasm layer
  2268. Revision 1.57 2002/05/18 13:34:12 peter
  2269. * readded missing revisions
  2270. Revision 1.56 2002/05/16 19:46:42 carl
  2271. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2272. + try to fix temp allocation (still in ifdef)
  2273. + generic constructor calls
  2274. + start of tassembler / tmodulebase class cleanup
  2275. Revision 1.54 2002/05/12 16:53:08 peter
  2276. * moved entry and exitcode to ncgutil and cgobj
  2277. * foreach gets extra argument for passing local data to the
  2278. iterator function
  2279. * -CR checks also class typecasts at runtime by changing them
  2280. into as
  2281. * fixed compiler to cycle with the -CR option
  2282. * fixed stabs with elf writer, finally the global variables can
  2283. be watched
  2284. * removed a lot of routines from cga unit and replaced them by
  2285. calls to cgobj
  2286. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2287. u32bit then the other is typecasted also to u32bit without giving
  2288. a rangecheck warning/error.
  2289. * fixed pascal calling method with reversing also the high tree in
  2290. the parast, detected by tcalcst3 test
  2291. Revision 1.53 2002/04/21 19:02:04 peter
  2292. * removed newn and disposen nodes, the code is now directly
  2293. inlined from pexpr
  2294. * -an option that will write the secondpass nodes to the .s file, this
  2295. requires EXTDEBUG define to actually write the info
  2296. * fixed various internal errors and crashes due recent code changes
  2297. Revision 1.52 2002/04/20 21:32:24 carl
  2298. + generic FPC_CHECKPOINTER
  2299. + first parameter offset in stack now portable
  2300. * rename some constants
  2301. + move some cpu stuff to other units
  2302. - remove unused constents
  2303. * fix stacksize for some targets
  2304. * fix generic size problems which depend now on EXTEND_SIZE constant
  2305. Revision 1.51 2002/04/20 15:27:05 carl
  2306. - remove ifdef i386 define
  2307. Revision 1.50 2002/04/19 15:46:02 peter
  2308. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  2309. in most cases and not written to the ppu
  2310. * add mangeledname_prefix() routine to generate the prefix of
  2311. manglednames depending on the current procedure, object and module
  2312. * removed static procprefix since the mangledname is now build only
  2313. on demand from tprocdef.mangledname
  2314. }