pdecsub.pas 90 KB

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