pdecsub.pas 93 KB

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