pdecsub.pas 92 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634
  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 check_proc_directive(isprocvar:boolean):boolean;
  36. procedure insert_funcret_local(pd:tprocdef);
  37. function proc_add_definition(var pd:tprocdef):boolean;
  38. function proc_get_importname(pd:tprocdef):string;
  39. procedure proc_set_mangledname(pd:tprocdef);
  40. procedure handle_calling_convention(pd:tabstractprocdef);
  41. procedure parse_parameter_dec(pd:tabstractprocdef);
  42. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  43. procedure parse_var_proc_directives(sym:tsym);
  44. procedure parse_object_proc_directives(pd:tabstractprocdef);
  45. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  46. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  47. implementation
  48. uses
  49. strings,
  50. { common }
  51. cutils,cclasses,
  52. { global }
  53. globtype,globals,verbose,
  54. systems,
  55. cpuinfo,
  56. { symtable }
  57. symbase,symtable,defutil,defcmp,paramgr,cpupara,
  58. { pass 1 }
  59. node,htypechk,
  60. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  61. { parser }
  62. scanner,
  63. pbase,pexpr,ptype,pdecl
  64. ;
  65. const
  66. { Please leave this here, this module should NOT use
  67. these variables.
  68. Declaring it as string here results in an error when compiling (PFV) }
  69. current_procinfo = 'error';
  70. procedure insert_funcret_para(pd:tabstractprocdef);
  71. var
  72. storepos : tfileposinfo;
  73. vs : tparavarsym;
  74. paranr : word;
  75. begin
  76. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  77. not is_void(pd.rettype.def) and
  78. paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  79. begin
  80. storepos:=akttokenpos;
  81. if pd.deftype=procdef then
  82. akttokenpos:=tprocdef(pd).fileinfo;
  83. { For left to right add it at the end to be delphi compatible }
  84. if pd.proccalloption in pushleftright_pocalls then
  85. paranr:=paranr_result_leftright
  86. else
  87. paranr:=paranr_result;
  88. { Generate result variable accessing function result }
  89. vs:=tparavarsym.create('$result',paranr,vs_var,pd.rettype,[vo_is_funcret,vo_is_hidden_para]);
  90. pd.parast.insert(vs);
  91. { Store the this symbol as funcretsym for procedures }
  92. if pd.deftype=procdef then
  93. tprocdef(pd).funcretsym:=vs;
  94. akttokenpos:=storepos;
  95. end;
  96. end;
  97. procedure insert_parentfp_para(pd:tabstractprocdef);
  98. var
  99. storepos : tfileposinfo;
  100. vs : tparavarsym;
  101. begin
  102. if pd.parast.symtablelevel>normal_function_level then
  103. begin
  104. storepos:=akttokenpos;
  105. if pd.deftype=procdef then
  106. akttokenpos:=tprocdef(pd).fileinfo;
  107. { Generate result variable accessing function result, it
  108. can't be put in a register since it must be accessable
  109. from the framepointer }
  110. vs:=tparavarsym.create('$parentfp',paranr_parentfp,vs_var,voidpointertype,[vo_is_parentfp,vo_is_hidden_para]);
  111. vs.varregable:=vr_none;
  112. pd.parast.insert(vs);
  113. akttokenpos:=storepos;
  114. end;
  115. end;
  116. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  117. var
  118. storepos : tfileposinfo;
  119. vs : tparavarsym;
  120. tt : ttype;
  121. vsp : tvarspez;
  122. begin
  123. if (pd.deftype=procvardef) and
  124. pd.is_methodpointer then
  125. begin
  126. { Generate self variable }
  127. tt:=voidpointertype;
  128. vs:=tparavarsym.create('$self',paranr_self,vs_value,tt,[vo_is_self,vo_is_hidden_para]);
  129. pd.parast.insert(vs);
  130. end
  131. else
  132. begin
  133. if (pd.deftype=procdef) and
  134. assigned(tprocdef(pd)._class) and
  135. (pd.parast.symtablelevel=normal_function_level) then
  136. begin
  137. storepos:=akttokenpos;
  138. akttokenpos:=tprocdef(pd).fileinfo;
  139. { Generate VMT variable for constructor/destructor }
  140. if pd.proctypeoption in [potype_constructor,potype_destructor] then
  141. begin
  142. { can't use classrefdef as type because inheriting
  143. will then always file because of a type mismatch }
  144. tt:=voidpointertype;
  145. vs:=tparavarsym.create('$vmt',paranr_vmt,vs_value,tt,[vo_is_vmt,vo_is_hidden_para]);
  146. pd.parast.insert(vs);
  147. end;
  148. { Generate self variable, for classes we need
  149. to use the generic voidpointer to be compatible with
  150. methodpointers }
  151. vsp:=vs_value;
  152. if (po_staticmethod in pd.procoptions) or
  153. (po_classmethod in pd.procoptions) then
  154. begin
  155. tt.setdef(tprocdef(pd)._class);
  156. tt.setdef(tclassrefdef.create(tt));
  157. end
  158. else
  159. begin
  160. if is_object(tprocdef(pd)._class) then
  161. vsp:=vs_var;
  162. tt.setdef(tprocdef(pd)._class);
  163. end;
  164. vs:=tparavarsym.create('$self',paranr_self,vsp,tt,[vo_is_self,vo_is_hidden_para]);
  165. pd.parast.insert(vs);
  166. akttokenpos:=storepos;
  167. end;
  168. end;
  169. end;
  170. procedure insert_funcret_local(pd:tprocdef);
  171. var
  172. storepos : tfileposinfo;
  173. vs : tlocalvarsym;
  174. aliasvs : tabsolutevarsym;
  175. sl : tsymlist;
  176. begin
  177. { The result from constructors and destructors can't be accessed directly }
  178. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  179. not is_void(pd.rettype.def) then
  180. begin
  181. storepos:=akttokenpos;
  182. akttokenpos:=pd.fileinfo;
  183. { We always need a localsymtable }
  184. if not assigned(pd.localst) then
  185. pd.insert_localst;
  186. { We need to insert a varsym for the result in the localst
  187. when it is returning in a register }
  188. if not paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  189. begin
  190. vs:=tlocalvarsym.create('$result',vs_value,pd.rettype,[vo_is_funcret]);
  191. pd.localst.insert(vs);
  192. pd.funcretsym:=vs;
  193. end;
  194. { insert the name of the procedure as alias for the function result,
  195. we can't use realname because that will not work for compilerprocs
  196. as the name is lowercase and unreachable from the code }
  197. if pd.resultname='' then
  198. pd.resultname:=pd.procsym.name;
  199. sl:=tsymlist.create;
  200. sl.addsym(sl_load,pd.funcretsym);
  201. aliasvs:=tabsolutevarsym.create_ref(pd.resultname,pd.rettype,sl);
  202. include(aliasvs.varoptions,vo_is_funcret);
  203. pd.localst.insert(aliasvs);
  204. { insert result also if support is on }
  205. if (m_result in aktmodeswitches) then
  206. begin
  207. sl:=tsymlist.create;
  208. sl.addsym(sl_load,pd.funcretsym);
  209. aliasvs:=tabsolutevarsym.create_ref('RESULT',pd.rettype,sl);
  210. include(aliasvs.varoptions,vo_is_funcret);
  211. include(aliasvs.varoptions,vo_is_result);
  212. pd.localst.insert(aliasvs);
  213. end;
  214. akttokenpos:=storepos;
  215. end;
  216. end;
  217. procedure insert_hidden_para(p:tnamedindexitem;arg:pointer);
  218. var
  219. hvs : tparavarsym;
  220. pd : tabstractprocdef absolute arg;
  221. begin
  222. if (tsym(p).typ<>paravarsym) then
  223. exit;
  224. with tparavarsym(p) do
  225. begin
  226. { We need a local copy for a value parameter when only the
  227. address is pushed. Open arrays and Array of Const are
  228. an exception because they are allocated at runtime and the
  229. address that is pushed is patched }
  230. if (varspez=vs_value) and
  231. paramanager.push_addr_param(varspez,vartype.def,pd.proccalloption) and
  232. not(is_open_array(vartype.def) or
  233. is_array_of_const(vartype.def)) then
  234. include(varoptions,vo_has_local_copy);
  235. { needs high parameter ? }
  236. if paramanager.push_high_param(varspez,vartype.def,pd.proccalloption) then
  237. begin
  238. hvs:=tparavarsym.create('$high'+name,paranr+1,vs_const,sinttype,[vo_is_high_para,vo_is_hidden_para]);
  239. owner.insert(hvs);
  240. end
  241. else
  242. begin
  243. { Give a warning that cdecl routines does not include high()
  244. support }
  245. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  246. paramanager.push_high_param(varspez,vartype.def,pocall_default) then
  247. begin
  248. if is_open_string(vartype.def) then
  249. Message(parser_w_cdecl_no_openstring);
  250. if not (po_external in pd.procoptions) then
  251. Message(parser_w_cdecl_has_no_high);
  252. end;
  253. end;
  254. end;
  255. end;
  256. procedure check_c_para(p:tnamedindexitem;arg:pointer);
  257. begin
  258. if (tsym(p).typ<>paravarsym) then
  259. exit;
  260. with tparavarsym(p) do
  261. begin
  262. case vartype.def.deftype of
  263. arraydef :
  264. begin
  265. if not is_variant_array(vartype.def) and
  266. not is_array_of_const(vartype.def) then
  267. begin
  268. if (varspez<>vs_var) then
  269. Message(parser_h_c_arrays_are_references);
  270. end;
  271. if is_array_of_const(vartype.def) and
  272. assigned(indexnext) and
  273. (tsym(indexnext).typ=paravarsym) and
  274. not(vo_is_high_para in tparavarsym(indexnext).varoptions) then
  275. Message(parser_e_C_array_of_const_must_be_last);
  276. end;
  277. end;
  278. end;
  279. end;
  280. procedure check_msg_para(p:tnamedindexitem;arg:pointer);
  281. begin
  282. if (tsym(p).typ<>paravarsym) then
  283. exit;
  284. with tparavarsym(p) do
  285. begin
  286. { Count parameters }
  287. if (paranr>=10) then
  288. inc(plongint(arg)^);
  289. { First parameter must be var }
  290. if (paranr=10) and
  291. (varspez<>vs_var) then
  292. Message(parser_e_ill_msg_param);
  293. end;
  294. end;
  295. procedure check_inline_para(p:tnamedindexitem;arg:pointer);
  296. var
  297. pd : tabstractprocdef absolute arg;
  298. begin
  299. if (pd.proccalloption<>pocall_inline) or
  300. (tsym(p).typ<>paravarsym) then
  301. exit;
  302. with tparavarsym(p) do
  303. begin
  304. case vartype.def.deftype of
  305. arraydef :
  306. begin
  307. with tarraydef(vartype.def) do
  308. if IsVariant or IsConstructor then
  309. begin
  310. Message1(parser_w_not_supported_for_inline,'array of const');
  311. Message(parser_w_inlining_disabled);
  312. pd.proccalloption:=pocall_default;
  313. end;
  314. end;
  315. end;
  316. end;
  317. end;
  318. procedure set_addr_param_regable(p:tnamedindexitem;arg:pointer);
  319. begin
  320. if (tsym(p).typ<>paravarsym) then
  321. exit;
  322. with tparavarsym(p) do
  323. begin
  324. if not vartype.def.needs_inittable and
  325. paramanager.push_addr_param(varspez,vartype.def,tprocdef(arg).proccalloption) then
  326. varregable:=vr_intreg;
  327. end;
  328. end;
  329. procedure parse_parameter_dec(pd:tabstractprocdef);
  330. {
  331. handle_procvar needs the same changes
  332. }
  333. type
  334. tppv = (pv_none,pv_proc,pv_func);
  335. var
  336. sc : tsinglelist;
  337. tt : ttype;
  338. arrayelementtype : ttype;
  339. vs : tparavarsym;
  340. srsym : tsym;
  341. pv : tprocvardef;
  342. varspez : Tvarspez;
  343. defaultvalue : tconstsym;
  344. defaultrequired : boolean;
  345. old_object_option : tsymoptions;
  346. currparast : tparasymtable;
  347. parseprocvar : tppv;
  348. explicit_paraloc : boolean;
  349. locationstr : string;
  350. paranr : integer;
  351. dummytype : ttypesym;
  352. begin
  353. explicit_paraloc:=false;
  354. consume(_LKLAMMER);
  355. { Delphi/Kylix supports nonsense like }
  356. { procedure p(); }
  357. if try_to_consume(_RKLAMMER) and
  358. not(m_tp7 in aktmodeswitches) then
  359. exit;
  360. { parsing a proc or procvar ? }
  361. currparast:=tparasymtable(pd.parast);
  362. { reset }
  363. sc:=tsinglelist.create;
  364. defaultrequired:=false;
  365. paranr:=0;
  366. { the variables are always public }
  367. old_object_option:=current_object_option;
  368. current_object_option:=[sp_public];
  369. inc(testcurobject);
  370. repeat
  371. parseprocvar:=pv_none;
  372. if try_to_consume(_VAR) then
  373. varspez:=vs_var
  374. else
  375. if try_to_consume(_CONST) then
  376. varspez:=vs_const
  377. else
  378. if (m_out in aktmodeswitches) and
  379. try_to_consume(_OUT) then
  380. varspez:=vs_out
  381. else
  382. if (m_mac in aktmodeswitches) and
  383. try_to_consume(_POINTPOINTPOINT) then
  384. begin
  385. include(pd.procoptions,po_varargs);
  386. break;
  387. end
  388. else
  389. if (m_mac in aktmodeswitches) and
  390. try_to_consume(_PROCEDURE) then
  391. begin
  392. parseprocvar:=pv_proc;
  393. varspez:=vs_const;
  394. end
  395. else
  396. if (m_mac in aktmodeswitches) and
  397. try_to_consume(_FUNCTION) then
  398. begin
  399. parseprocvar:=pv_func;
  400. varspez:=vs_const;
  401. end
  402. else
  403. varspez:=vs_value;
  404. defaultvalue:=nil;
  405. tt.reset;
  406. { read identifiers and insert with error type }
  407. sc.reset;
  408. repeat
  409. inc(paranr);
  410. vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrortype,[]);
  411. currparast.insert(vs);
  412. if assigned(vs.owner) then
  413. sc.insert(vs)
  414. else
  415. vs.free;
  416. consume(_ID);
  417. until not try_to_consume(_COMMA);
  418. locationstr:='';
  419. { macpas anonymous procvar }
  420. if parseprocvar<>pv_none then
  421. begin
  422. pv:=tprocvardef.create(normal_function_level);
  423. if token=_LKLAMMER then
  424. parse_parameter_dec(pv);
  425. if parseprocvar=pv_func then
  426. begin
  427. consume(_COLON);
  428. single_type(pv.rettype,false);
  429. end;
  430. tt.def:=pv;
  431. { possible proc directives }
  432. if check_proc_directive(true) then
  433. begin
  434. dummytype:=ttypesym.create('unnamed',tt);
  435. parse_var_proc_directives(tsym(dummytype));
  436. dummytype.restype.def:=nil;
  437. tt.def.typesym:=nil;
  438. dummytype.free;
  439. end;
  440. { Add implicit hidden parameters and function result }
  441. handle_calling_convention(pv);
  442. end
  443. else
  444. { read type declaration, force reading for value and const paras }
  445. if (token=_COLON) or (varspez=vs_value) then
  446. begin
  447. consume(_COLON);
  448. { check for an open array }
  449. if token=_ARRAY then
  450. begin
  451. consume(_ARRAY);
  452. consume(_OF);
  453. { define range and type of range }
  454. tt.setdef(tarraydef.create(0,-1,s32inttype));
  455. { array of const ? }
  456. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  457. begin
  458. consume(_CONST);
  459. srsym:=searchsymonlyin(systemunit,'TVARREC');
  460. if not assigned(srsym) then
  461. InternalError(200404181);
  462. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  463. tarraydef(tt.def).IsArrayOfConst:=true;
  464. end
  465. else
  466. begin
  467. { define field type }
  468. single_type(arrayelementtype,false);
  469. tarraydef(tt.def).setelementtype(arrayelementtype);
  470. end;
  471. end
  472. else
  473. begin
  474. { open string ? }
  475. if (varspez=vs_var) and
  476. (
  477. (
  478. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  479. (cs_openstring in aktmoduleswitches) and
  480. not(cs_ansistrings in aktlocalswitches)
  481. ) or
  482. (idtoken=_OPENSTRING)) then
  483. begin
  484. consume(token);
  485. tt:=openshortstringtype;
  486. end
  487. else
  488. begin
  489. { everything else }
  490. if (m_mac in aktmodeswitches) then
  491. try_to_consume(_UNIV); {currently does nothing}
  492. single_type(tt,false);
  493. end;
  494. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  495. begin
  496. if (idtoken=_LOCATION) then
  497. begin
  498. consume(_LOCATION);
  499. locationstr:=pattern;
  500. consume(_CSTRING);
  501. end
  502. else
  503. begin
  504. if explicit_paraloc then
  505. Message(parser_e_paraloc_all_paras);
  506. locationstr:='';
  507. end;
  508. end
  509. else
  510. locationstr:='';
  511. { default parameter }
  512. if (m_default_para in aktmodeswitches) then
  513. begin
  514. if try_to_consume(_EQUAL) then
  515. begin
  516. vs:=tparavarsym(sc.first);
  517. if assigned(vs.listnext) then
  518. Message(parser_e_default_value_only_one_para);
  519. { prefix 'def' to the parameter name }
  520. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  521. if assigned(defaultvalue) then
  522. begin
  523. include(defaultvalue.symoptions,sp_internal);
  524. pd.parast.insert(defaultvalue);
  525. end;
  526. defaultrequired:=true;
  527. end
  528. else
  529. begin
  530. if defaultrequired then
  531. Message1(parser_e_default_value_expected_for_para,vs.name);
  532. end;
  533. end;
  534. end;
  535. end
  536. else
  537. tt:=cformaltype;
  538. { File types are only allowed for var parameters }
  539. if (tt.def.deftype=filedef) and
  540. (varspez<>vs_var) then
  541. CGMessage(cg_e_file_must_call_by_reference);
  542. vs:=tparavarsym(sc.first);
  543. while assigned(vs) do
  544. begin
  545. { update varsym }
  546. vs.vartype:=tt;
  547. vs.defaultconstsym:=defaultvalue;
  548. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  549. begin
  550. if locationstr<>'' then
  551. begin
  552. if assigned(sc.first.listnext) then
  553. Message(parser_e_paraloc_only_one_para);
  554. if (paranr>1) and not(explicit_paraloc) then
  555. Message(parser_e_paraloc_all_paras);
  556. explicit_paraloc:=true;
  557. include(vs.varoptions,vo_has_explicit_paraloc);
  558. if not(paramanager.parseparaloc(vs,upper(locationstr))) then
  559. message(parser_e_illegal_explicit_paraloc);
  560. end
  561. else
  562. if explicit_paraloc then
  563. Message(parser_e_paraloc_all_paras);
  564. end;
  565. vs:=tparavarsym(vs.listnext);
  566. end;
  567. until not try_to_consume(_SEMICOLON);
  568. if explicit_paraloc then
  569. begin
  570. pd.has_paraloc_info:=true;
  571. include(pd.procoptions,po_explicitparaloc);
  572. end;
  573. { remove parasymtable from stack }
  574. sc.free;
  575. { reset object options }
  576. dec(testcurobject);
  577. current_object_option:=old_object_option;
  578. consume(_RKLAMMER);
  579. end;
  580. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  581. var
  582. orgsp,sp : stringid;
  583. sym : tsym;
  584. srsym : tsym;
  585. srsymtable : tsymtable;
  586. storepos,
  587. procstartfilepos : tfileposinfo;
  588. searchagain : boolean;
  589. i : longint;
  590. st : tsymtable;
  591. aprocsym : tprocsym;
  592. begin
  593. { Save the position where this procedure really starts }
  594. procstartfilepos:=akttokenpos;
  595. result:=false;
  596. pd:=nil;
  597. aprocsym:=nil;
  598. if (potype=potype_operator) then
  599. begin
  600. sp:=overloaded_names[optoken];
  601. orgsp:=sp;
  602. end
  603. else
  604. begin
  605. sp:=pattern;
  606. orgsp:=orgpattern;
  607. consume(_ID);
  608. end;
  609. { examine interface map: function/procedure iname.functionname=locfuncname }
  610. if assigned(aclass) and
  611. assigned(aclass.implementedinterfaces) and
  612. (aclass.implementedinterfaces.count>0) and
  613. try_to_consume(_POINT) then
  614. begin
  615. storepos:=akttokenpos;
  616. akttokenpos:=procstartfilepos;
  617. { get interface syms}
  618. searchsym(sp,sym,srsymtable);
  619. if not assigned(sym) then
  620. begin
  621. identifier_not_found(orgsp);
  622. sym:=generrorsym;
  623. end;
  624. akttokenpos:=storepos;
  625. { qualifier is interface? }
  626. if (sym.typ=typesym) and
  627. (ttypesym(sym).restype.def.deftype=objectdef) then
  628. i:=aclass.implementedinterfaces.searchintf(ttypesym(sym).restype.def)
  629. else
  630. i:=-1;
  631. if (i=-1) then
  632. Message(parser_e_interface_id_expected);
  633. consume(_ID);
  634. consume(_EQUAL);
  635. if (token=_ID) then
  636. aclass.implementedinterfaces.addmappings(i,sp,pattern);
  637. consume(_ID);
  638. result:=true;
  639. exit;
  640. end;
  641. { method ? }
  642. if not assigned(aclass) and
  643. (potype<>potype_operator) and
  644. (symtablestack.symtablelevel=main_program_level) and
  645. try_to_consume(_POINT) then
  646. begin
  647. { search for object name }
  648. storepos:=akttokenpos;
  649. akttokenpos:=procstartfilepos;
  650. searchsym(sp,sym,srsymtable);
  651. if not assigned(sym) then
  652. begin
  653. identifier_not_found(orgsp);
  654. sym:=generrorsym;
  655. end;
  656. akttokenpos:=storepos;
  657. { consume proc name }
  658. sp:=pattern;
  659. orgsp:=orgpattern;
  660. procstartfilepos:=akttokenpos;
  661. consume(_ID);
  662. { qualifier is class name ? }
  663. if (sym.typ=typesym) and
  664. (ttypesym(sym).restype.def.deftype=objectdef) then
  665. begin
  666. aclass:=tobjectdef(ttypesym(sym).restype.def);
  667. aprocsym:=tprocsym(aclass.symtable.search(sp));
  668. { we solve this below }
  669. if assigned(aprocsym) then
  670. begin
  671. if aprocsym.typ<>procsym then
  672. begin
  673. { we use a different error message for tp7 so it looks more compatible }
  674. if (m_fpc in aktmodeswitches) then
  675. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  676. else
  677. Message(parser_e_methode_id_expected);
  678. { rename the name to an unique name to avoid an
  679. error when inserting the symbol in the symtable }
  680. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  681. aprocsym:=nil;
  682. end;
  683. end
  684. else
  685. begin
  686. Message(parser_e_methode_id_expected);
  687. { recover by making it a normal procedure instead of method }
  688. aclass:=nil;
  689. end;
  690. end
  691. else
  692. Message(parser_e_class_id_expected);
  693. end
  694. else
  695. begin
  696. { check for constructor/destructor which is not allowed here }
  697. if (not parse_only) and
  698. (potype in [potype_constructor,potype_destructor]) then
  699. Message(parser_e_constructors_always_objects);
  700. repeat
  701. searchagain:=false;
  702. akttokenpos:=procstartfilepos;
  703. srsym:=tsym(symtablestack.search(sp));
  704. if not(parse_only) and
  705. not assigned(srsym) and
  706. (symtablestack.symtabletype=staticsymtable) and
  707. assigned(symtablestack.next) and
  708. (symtablestack.next.iscurrentunit) then
  709. begin
  710. { The procedure we prepare for is in the implementation
  711. part of the unit we compile. It is also possible that we
  712. are compiling a program, which is also some kind of
  713. implementaion part.
  714. We need to find out if the procedure is global. If it is
  715. global, it is in the global symtable.}
  716. srsym:=tsym(symtablestack.next.search(sp));
  717. end;
  718. { Check if overloaded is a procsym }
  719. if assigned(srsym) then
  720. begin
  721. if srsym.typ=procsym then
  722. aprocsym:=tprocsym(srsym)
  723. else
  724. begin
  725. { when the other symbol is a unit symbol then hide the unit
  726. symbol }
  727. if (srsym.typ=unitsym) then
  728. begin
  729. srsym.owner.rename(srsym.name,'hidden'+srsym.name);
  730. searchagain:=true;
  731. end
  732. else
  733. begin
  734. { we use a different error message for tp7 so it looks more compatible }
  735. if (m_fpc in aktmodeswitches) then
  736. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  737. else
  738. tstoredsymtable(symtablestack).DuplicateSym(nil,srsym);
  739. { rename the name to an unique name to avoid an
  740. error when inserting the symbol in the symtable }
  741. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  742. end;
  743. end;
  744. end;
  745. until not searchagain;
  746. end;
  747. { test again if assigned, it can be reset to recover }
  748. if not assigned(aprocsym) then
  749. begin
  750. { create a new procsym and set the real filepos }
  751. akttokenpos:=procstartfilepos;
  752. { for operator we have only one procsym for each overloaded
  753. operation }
  754. if (potype=potype_operator) then
  755. begin
  756. Aprocsym:=Tprocsym(symtablestack.search(sp));
  757. if Aprocsym=nil then
  758. Aprocsym:=tprocsym.create('$'+sp);
  759. end
  760. else
  761. aprocsym:=tprocsym.create(orgsp);
  762. symtablestack.insert(aprocsym);
  763. end;
  764. { to get the correct symtablelevel we must ignore objectsymtables }
  765. st:=symtablestack;
  766. while not(st.symtabletype in [staticsymtable,globalsymtable,localsymtable]) do
  767. st:=st.next;
  768. pd:=tprocdef.create(st.symtablelevel+1);
  769. pd._class:=aclass;
  770. pd.procsym:=aprocsym;
  771. pd.proctypeoption:=potype;
  772. { methods need to be exported }
  773. if assigned(aclass) and
  774. (
  775. (symtablestack.symtabletype=objectsymtable) or
  776. (symtablestack.symtablelevel=main_program_level)
  777. ) then
  778. include(pd.procoptions,po_global);
  779. { symbol options that need to be kept per procdef }
  780. pd.fileinfo:=procstartfilepos;
  781. pd.symoptions:=current_object_option;
  782. { parse parameters }
  783. if token=_LKLAMMER then
  784. parse_parameter_dec(pd);
  785. result:=true;
  786. end;
  787. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  788. var
  789. pd : tprocdef;
  790. isclassmethod : boolean;
  791. begin
  792. pd:=nil;
  793. isclassmethod:=false;
  794. { read class method }
  795. if try_to_consume(_CLASS) then
  796. begin
  797. { class method only allowed for procedures and functions }
  798. if not(token in [_FUNCTION,_PROCEDURE]) then
  799. Message(parser_e_procedure_or_function_expected);
  800. if is_interface(aclass) then
  801. Message(parser_e_no_static_method_in_interfaces)
  802. else
  803. isclassmethod:=true;
  804. end;
  805. case token of
  806. _FUNCTION :
  807. begin
  808. consume(_FUNCTION);
  809. if parse_proc_head(aclass,potype_none,pd) then
  810. begin
  811. { pd=nil when it is a interface mapping }
  812. if assigned(pd) then
  813. begin
  814. if try_to_consume(_COLON) then
  815. begin
  816. inc(testcurobject);
  817. single_type(pd.rettype,false);
  818. pd.test_if_fpu_result;
  819. dec(testcurobject);
  820. end
  821. else
  822. begin
  823. if (
  824. parse_only and
  825. not(is_interface(pd._class))
  826. ) or
  827. (m_repeat_forward in aktmodeswitches) then
  828. begin
  829. consume(_COLON);
  830. consume_all_until(_SEMICOLON);
  831. end;
  832. end;
  833. if isclassmethod then
  834. include(pd.procoptions,po_classmethod);
  835. end;
  836. end
  837. else
  838. begin
  839. { recover }
  840. consume(_COLON);
  841. consume_all_until(_SEMICOLON);
  842. end;
  843. end;
  844. _PROCEDURE :
  845. begin
  846. consume(_PROCEDURE);
  847. if parse_proc_head(aclass,potype_none,pd) then
  848. begin
  849. { pd=nil when it is a interface mapping }
  850. if assigned(pd) then
  851. begin
  852. pd.rettype:=voidtype;
  853. if isclassmethod then
  854. include(pd.procoptions,po_classmethod);
  855. end;
  856. end;
  857. end;
  858. _CONSTRUCTOR :
  859. begin
  860. consume(_CONSTRUCTOR);
  861. parse_proc_head(aclass,potype_constructor,pd);
  862. if assigned(pd) and
  863. assigned(pd._class) then
  864. begin
  865. { Set return type, class constructors return the
  866. created instance, object constructors return boolean }
  867. if is_class(pd._class) then
  868. pd.rettype.setdef(pd._class)
  869. else
  870. pd.rettype:=booltype;
  871. end;
  872. end;
  873. _DESTRUCTOR :
  874. begin
  875. consume(_DESTRUCTOR);
  876. parse_proc_head(aclass,potype_destructor,pd);
  877. if assigned(pd) then
  878. pd.rettype:=voidtype;
  879. end;
  880. _OPERATOR :
  881. begin
  882. consume(_OPERATOR);
  883. if (token in [first_overloaded..last_overloaded]) then
  884. begin
  885. optoken:=token;
  886. end
  887. else
  888. begin
  889. Message(parser_e_overload_operator_failed);
  890. { Use the dummy NOTOKEN that is also declared
  891. for the overloaded_operator[] }
  892. optoken:=NOTOKEN;
  893. end;
  894. consume(token);
  895. parse_proc_head(aclass,potype_operator,pd);
  896. if assigned(pd) then
  897. begin
  898. if pd.parast.symtablelevel>normal_function_level then
  899. Message(parser_e_no_local_operator);
  900. if token<>_ID then
  901. begin
  902. if not(m_result in aktmodeswitches) then
  903. consume(_ID);
  904. end
  905. else
  906. begin
  907. pd.resultname:=orgpattern;
  908. consume(_ID);
  909. end;
  910. if not try_to_consume(_COLON) then
  911. begin
  912. consume(_COLON);
  913. pd.rettype:=generrortype;
  914. consume_all_until(_SEMICOLON);
  915. end
  916. else
  917. begin
  918. single_type(pd.rettype,false);
  919. pd.test_if_fpu_result;
  920. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  921. ((pd.rettype.def.deftype<>orddef) or
  922. (torddef(pd.rettype.def).typ<>bool8bit)) then
  923. Message(parser_e_comparative_operator_return_boolean);
  924. if (optoken=_ASSIGNMENT) and
  925. equal_defs(pd.rettype.def,
  926. tparavarsym(pd.parast.symindex.first).vartype.def) then
  927. message(parser_e_no_such_assignment)
  928. else if not isoperatoracceptable(pd,optoken) then
  929. Message(parser_e_overload_impossible);
  930. end;
  931. end
  932. else
  933. begin
  934. { recover }
  935. try_to_consume(_ID);
  936. consume(_COLON);
  937. consume_all_until(_SEMICOLON);
  938. end;
  939. end;
  940. end;
  941. { support procedure proc stdcall export; }
  942. if not(check_proc_directive(false)) then
  943. consume(_SEMICOLON);
  944. result:=pd;
  945. end;
  946. {****************************************************************************
  947. Procedure directive handlers
  948. ****************************************************************************}
  949. procedure pd_far(pd:tabstractprocdef);
  950. begin
  951. Message1(parser_w_proc_directive_ignored,'FAR');
  952. end;
  953. procedure pd_near(pd:tabstractprocdef);
  954. begin
  955. Message1(parser_w_proc_directive_ignored,'NEAR');
  956. end;
  957. procedure pd_export(pd:tabstractprocdef);
  958. begin
  959. if pd.deftype<>procdef then
  960. internalerror(200304264);
  961. if assigned(tprocdef(pd)._class) then
  962. Message(parser_e_methods_dont_be_export);
  963. if pd.parast.symtablelevel>normal_function_level then
  964. Message(parser_e_dont_nest_export);
  965. end;
  966. procedure pd_forward(pd:tabstractprocdef);
  967. begin
  968. if pd.deftype<>procdef then
  969. internalerror(200304265);
  970. tprocdef(pd).forwarddef:=true;
  971. end;
  972. procedure pd_alias(pd:tabstractprocdef);
  973. begin
  974. if pd.deftype<>procdef then
  975. internalerror(200304266);
  976. consume(_COLON);
  977. tprocdef(pd).aliasnames.insert(get_stringconst);
  978. include(pd.procoptions,po_has_public_name);
  979. end;
  980. procedure pd_public(pd:tabstractprocdef);
  981. begin
  982. if pd.deftype<>procdef then
  983. internalerror(200304266);
  984. if try_to_consume(_NAME) then
  985. begin
  986. tprocdef(pd).aliasnames.insert(get_stringconst);
  987. include(pd.procoptions,po_has_public_name);
  988. end;
  989. end;
  990. procedure pd_asmname(pd:tabstractprocdef);
  991. begin
  992. if pd.deftype<>procdef then
  993. internalerror(200304267);
  994. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  995. if token=_CCHAR then
  996. consume(_CCHAR)
  997. else
  998. consume(_CSTRING);
  999. { we don't need anything else }
  1000. tprocdef(pd).forwarddef:=false;
  1001. end;
  1002. procedure pd_inline(pd:tabstractprocdef);
  1003. begin
  1004. { Check if there are parameters that can't be inlined }
  1005. pd.parast.foreach_static(@check_inline_para,pd);
  1006. end;
  1007. procedure pd_internconst(pd:tabstractprocdef);
  1008. begin
  1009. if pd.deftype<>procdef then
  1010. internalerror(200304268);
  1011. consume(_COLON);
  1012. tprocdef(pd).extnumber:=get_intconst;
  1013. end;
  1014. procedure pd_internproc(pd:tabstractprocdef);
  1015. begin
  1016. if pd.deftype<>procdef then
  1017. internalerror(200304268);
  1018. consume(_COLON);
  1019. tprocdef(pd).extnumber:=get_intconst;
  1020. { the proc is defined }
  1021. tprocdef(pd).forwarddef:=false;
  1022. end;
  1023. procedure pd_interrupt(pd:tabstractprocdef);
  1024. begin
  1025. if pd.parast.symtablelevel>normal_function_level then
  1026. Message(parser_e_dont_nest_interrupt);
  1027. end;
  1028. procedure pd_abstract(pd:tabstractprocdef);
  1029. begin
  1030. if pd.deftype<>procdef then
  1031. internalerror(200304269);
  1032. if (po_virtualmethod in pd.procoptions) then
  1033. include(pd.procoptions,po_abstractmethod)
  1034. else
  1035. Message(parser_e_only_virtual_methods_abstract);
  1036. { the method is defined }
  1037. tprocdef(pd).forwarddef:=false;
  1038. end;
  1039. procedure pd_virtual(pd:tabstractprocdef);
  1040. {$ifdef WITHDMT}
  1041. var
  1042. pt : tnode;
  1043. {$endif WITHDMT}
  1044. begin
  1045. if pd.deftype<>procdef then
  1046. internalerror(2003042610);
  1047. if (pd.proctypeoption=potype_constructor) and
  1048. is_object(tprocdef(pd)._class) then
  1049. Message(parser_e_constructor_cannot_be_not_virtual);
  1050. {$ifdef WITHDMT}
  1051. if is_object(tprocdef(pd)._class) and
  1052. (token<>_SEMICOLON) then
  1053. begin
  1054. { any type of parameter is allowed here! }
  1055. pt:=comp_expr(true);
  1056. if is_constintnode(pt) then
  1057. begin
  1058. include(pd.procoptions,po_msgint);
  1059. pd.messageinf.i:=pt^.value;
  1060. end
  1061. else
  1062. Message(parser_e_ill_msg_expr);
  1063. disposetree(pt);
  1064. end;
  1065. {$endif WITHDMT}
  1066. end;
  1067. procedure pd_static(pd:tabstractprocdef);
  1068. begin
  1069. if (cs_static_keyword in aktmoduleswitches) then
  1070. begin
  1071. if pd.deftype=procdef then
  1072. include(tprocdef(pd).procsym.symoptions,sp_static);
  1073. include(pd.procoptions,po_staticmethod);
  1074. end;
  1075. end;
  1076. procedure pd_override(pd:tabstractprocdef);
  1077. begin
  1078. if pd.deftype<>procdef then
  1079. internalerror(2003042611);
  1080. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1081. Message(parser_e_no_object_override);
  1082. end;
  1083. procedure pd_overload(pd:tabstractprocdef);
  1084. begin
  1085. if pd.deftype<>procdef then
  1086. internalerror(2003042612);
  1087. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1088. end;
  1089. procedure pd_message(pd:tabstractprocdef);
  1090. var
  1091. pt : tnode;
  1092. paracnt : longint;
  1093. begin
  1094. if pd.deftype<>procdef then
  1095. internalerror(2003042613);
  1096. if not is_class(tprocdef(pd)._class) then
  1097. Message(parser_e_msg_only_for_classes);
  1098. { check parameter type }
  1099. paracnt:=0;
  1100. pd.parast.foreach_static(@check_msg_para,@paracnt);
  1101. if paracnt<>1 then
  1102. Message(parser_e_ill_msg_param);
  1103. pt:=comp_expr(true);
  1104. if pt.nodetype=stringconstn then
  1105. begin
  1106. include(pd.procoptions,po_msgstr);
  1107. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1108. end
  1109. else
  1110. if is_constintnode(pt) then
  1111. begin
  1112. include(pd.procoptions,po_msgint);
  1113. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1114. end
  1115. else
  1116. Message(parser_e_ill_msg_expr);
  1117. pt.free;
  1118. end;
  1119. procedure pd_reintroduce(pd:tabstractprocdef);
  1120. begin
  1121. if pd.deftype<>procdef then
  1122. internalerror(200401211);
  1123. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1124. Message(parser_e_no_object_reintroduce);
  1125. end;
  1126. procedure pd_syscall(pd:tabstractprocdef);
  1127. {$ifdef powerpc}
  1128. var
  1129. vs : tparavarsym;
  1130. sym : tsym;
  1131. symtable : tsymtable;
  1132. {$endif powerpc}
  1133. begin
  1134. if pd.deftype<>procdef then
  1135. internalerror(2003042614);
  1136. tprocdef(pd).forwarddef:=false;
  1137. {$ifdef powerpc}
  1138. if target_info.system in [system_powerpc_morphos] then
  1139. begin
  1140. if idtoken=_LEGACY then
  1141. begin
  1142. consume(_LEGACY);
  1143. include(pd.procoptions,po_syscall_legacy);
  1144. end
  1145. else if idtoken=_SYSV then
  1146. begin
  1147. consume(_SYSV);
  1148. include(pd.procoptions,po_syscall_sysv);
  1149. end
  1150. else if idtoken=_BASESYSV then
  1151. begin
  1152. consume(_BASESYSV);
  1153. include(pd.procoptions,po_syscall_basesysv);
  1154. end
  1155. else if idtoken=_SYSVBASE then
  1156. begin
  1157. consume(_SYSVBASE);
  1158. include(pd.procoptions,po_syscall_sysvbase);
  1159. end
  1160. else if idtoken=_R12BASE then
  1161. begin
  1162. consume(_R12BASE);
  1163. include(pd.procoptions,po_syscall_r12base);
  1164. end
  1165. else
  1166. if syscall_convention='LEGACY' then
  1167. include(pd.procoptions,po_syscall_legacy)
  1168. else if syscall_convention='SYSV' then
  1169. include(pd.procoptions,po_syscall_sysv)
  1170. else if syscall_convention='BASESYSV' then
  1171. include(pd.procoptions,po_syscall_basesysv)
  1172. else if syscall_convention='SYSVBASE' then
  1173. include(pd.procoptions,po_syscall_sysvbase)
  1174. else if syscall_convention='R12BASE' then
  1175. include(pd.procoptions,po_syscall_r12base)
  1176. else
  1177. internalerror(2005010404);
  1178. if consume_sym(sym,symtable) then
  1179. begin
  1180. if (sym.typ=globalvarsym) and
  1181. (
  1182. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1183. is_32bitint(tabstractvarsym(sym).vartype.def)
  1184. ) then
  1185. begin
  1186. tprocdef(pd).libsym:=sym;
  1187. if po_syscall_legacy in tprocdef(pd).procoptions then
  1188. begin
  1189. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1190. paramanager.parseparaloc(vs,'A6');
  1191. pd.parast.insert(vs);
  1192. end
  1193. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1194. begin
  1195. { Nothing to be done for sysv here for now, but this might change }
  1196. end
  1197. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1198. begin
  1199. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1200. pd.parast.insert(vs);
  1201. end
  1202. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1203. begin
  1204. vs:=tparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1205. pd.parast.insert(vs);
  1206. end
  1207. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1208. begin
  1209. vs:=tparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1210. paramanager.parseparaloc(vs,'R12');
  1211. pd.parast.insert(vs);
  1212. end
  1213. else
  1214. internalerror(2005010501);
  1215. end
  1216. else
  1217. Message(parser_e_32bitint_or_pointer_variable_expected);
  1218. end;
  1219. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1220. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1221. end;
  1222. {$endif powerpc}
  1223. tprocdef(pd).extnumber:=get_intconst;
  1224. end;
  1225. procedure pd_external(pd:tabstractprocdef);
  1226. {
  1227. If import_dll=nil the procedure is assumed to be in another
  1228. object file. In that object file it should have the name to
  1229. which import_name is pointing to. Otherwise, the procedure is
  1230. assumed to be in the DLL to which import_dll is pointing to. In
  1231. that case either import_nr<>0 or import_name<>nil is true, so
  1232. the procedure is either imported by number or by name. (DM)
  1233. }
  1234. begin
  1235. if pd.deftype<>procdef then
  1236. internalerror(2003042615);
  1237. with tprocdef(pd) do
  1238. begin
  1239. forwarddef:=false;
  1240. { forbid local external procedures }
  1241. if parast.symtablelevel>normal_function_level then
  1242. Message(parser_e_no_local_proc_external);
  1243. { If the procedure should be imported from a DLL, a constant string follows.
  1244. This isn't really correct, an contant string expression follows
  1245. so we check if an semicolon follows, else a string constant have to
  1246. follow (FK) }
  1247. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1248. begin
  1249. import_dll:=stringdup(get_stringconst);
  1250. if (idtoken=_NAME) then
  1251. begin
  1252. consume(_NAME);
  1253. import_name:=stringdup(get_stringconst);
  1254. if import_name^='' then
  1255. message(parser_e_empty_import_name);
  1256. end;
  1257. if (idtoken=_INDEX) then
  1258. begin
  1259. {After the word index follows the index number in the DLL.}
  1260. consume(_INDEX);
  1261. import_nr:=get_intconst;
  1262. end;
  1263. { default is to used the realname of the procedure }
  1264. if (import_nr=0) and not assigned(import_name) then
  1265. import_name:=stringdup(procsym.realname);
  1266. end
  1267. else
  1268. begin
  1269. if (idtoken=_NAME) then
  1270. begin
  1271. consume(_NAME);
  1272. import_name:=stringdup(get_stringconst);
  1273. if import_name^='' then
  1274. message(parser_e_empty_import_name);
  1275. end;
  1276. end;
  1277. end;
  1278. end;
  1279. type
  1280. pd_handler=procedure(pd:tabstractprocdef);
  1281. proc_dir_rec=record
  1282. idtok : ttoken;
  1283. pd_flags : tpdflags;
  1284. handler : pd_handler;
  1285. pocall : tproccalloption;
  1286. pooption : tprocoptions;
  1287. mutexclpocall : tproccalloptions;
  1288. mutexclpotype : tproctypeoptions;
  1289. mutexclpo : tprocoptions;
  1290. end;
  1291. const
  1292. {Should contain the number of procedure directives we support.}
  1293. num_proc_directives=36;
  1294. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1295. (
  1296. (
  1297. idtok:_ABSTRACT;
  1298. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1299. handler : @pd_abstract;
  1300. pocall : pocall_none;
  1301. pooption : [po_abstractmethod];
  1302. mutexclpocall : [pocall_internproc,pocall_inline];
  1303. mutexclpotype : [];
  1304. mutexclpo : [po_exports,po_interrupt,po_external]
  1305. ),(
  1306. idtok:_ALIAS;
  1307. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1308. handler : @pd_alias;
  1309. pocall : pocall_none;
  1310. pooption : [];
  1311. mutexclpocall : [pocall_inline];
  1312. mutexclpotype : [];
  1313. mutexclpo : [po_external]
  1314. ),(
  1315. idtok:_ASMNAME;
  1316. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1317. handler : @pd_asmname;
  1318. pocall : pocall_cdecl;
  1319. pooption : [po_external];
  1320. mutexclpocall : [pocall_internproc,pocall_inline];
  1321. mutexclpotype : [];
  1322. mutexclpo : [po_external]
  1323. ),(
  1324. idtok:_ASSEMBLER;
  1325. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1326. handler : nil;
  1327. pocall : pocall_none;
  1328. pooption : [po_assembler];
  1329. mutexclpocall : [];
  1330. mutexclpotype : [];
  1331. mutexclpo : [po_external]
  1332. ),(
  1333. idtok:_C; {same as cdecl for mode mac}
  1334. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1335. handler : nil;
  1336. pocall : pocall_cdecl;
  1337. pooption : [];
  1338. mutexclpocall : [];
  1339. mutexclpotype : [potype_constructor,potype_destructor];
  1340. mutexclpo : [po_assembler,po_external]
  1341. ),(
  1342. idtok:_CDECL;
  1343. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1344. handler : nil;
  1345. pocall : pocall_cdecl;
  1346. pooption : [];
  1347. mutexclpocall : [];
  1348. mutexclpotype : [potype_constructor,potype_destructor];
  1349. mutexclpo : [po_assembler,po_external]
  1350. ),(
  1351. idtok:_DYNAMIC;
  1352. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1353. handler : @pd_virtual;
  1354. pocall : pocall_none;
  1355. pooption : [po_virtualmethod];
  1356. mutexclpocall : [pocall_internproc,pocall_inline];
  1357. mutexclpotype : [];
  1358. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod]
  1359. ),(
  1360. idtok:_EXPORT;
  1361. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1362. handler : @pd_export;
  1363. pocall : pocall_none;
  1364. pooption : [po_exports,po_global];
  1365. mutexclpocall : [pocall_internproc,pocall_inline];
  1366. mutexclpotype : [potype_constructor,potype_destructor];
  1367. mutexclpo : [po_external,po_interrupt]
  1368. ),(
  1369. idtok:_EXTERNAL;
  1370. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1371. handler : @pd_external;
  1372. pocall : pocall_none;
  1373. pooption : [po_external];
  1374. mutexclpocall : [pocall_internproc,pocall_inline,pocall_syscall];
  1375. mutexclpotype : [potype_constructor,potype_destructor];
  1376. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler]
  1377. ),(
  1378. idtok:_FAR;
  1379. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1380. handler : @pd_far;
  1381. pocall : pocall_none;
  1382. pooption : [];
  1383. mutexclpocall : [pocall_internproc,pocall_inline];
  1384. mutexclpotype : [];
  1385. mutexclpo : []
  1386. ),(
  1387. idtok:_FAR16;
  1388. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1389. handler : nil;
  1390. pocall : pocall_far16;
  1391. pooption : [];
  1392. mutexclpocall : [];
  1393. mutexclpotype : [];
  1394. mutexclpo : [po_external]
  1395. ),(
  1396. idtok:_FORWARD;
  1397. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1398. handler : @pd_forward;
  1399. pocall : pocall_none;
  1400. pooption : [];
  1401. mutexclpocall : [pocall_internproc,pocall_inline];
  1402. mutexclpotype : [];
  1403. mutexclpo : [po_external]
  1404. ),(
  1405. idtok:_OLDFPCCALL;
  1406. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1407. handler : nil;
  1408. pocall : pocall_oldfpccall;
  1409. pooption : [];
  1410. mutexclpocall : [];
  1411. mutexclpotype : [];
  1412. mutexclpo : []
  1413. ),(
  1414. idtok:_INLINE;
  1415. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1416. handler : @pd_inline;
  1417. pocall : pocall_inline;
  1418. pooption : [];
  1419. mutexclpocall : [];
  1420. mutexclpotype : [potype_constructor,potype_destructor];
  1421. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1422. ),(
  1423. idtok:_INTERNCONST;
  1424. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf];
  1425. handler : @pd_internconst;
  1426. pocall : pocall_none;
  1427. pooption : [po_internconst];
  1428. mutexclpocall : [];
  1429. mutexclpotype : [potype_operator];
  1430. mutexclpo : []
  1431. ),(
  1432. idtok:_INTERNPROC;
  1433. pd_flags : [pd_interface,pd_notobject,pd_notobjintf];
  1434. handler : @pd_internproc;
  1435. pocall : pocall_internproc;
  1436. pooption : [];
  1437. mutexclpocall : [];
  1438. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1439. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1440. ),(
  1441. idtok:_INTERRUPT;
  1442. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1443. handler : @pd_interrupt;
  1444. pocall : pocall_none;
  1445. pooption : [po_interrupt];
  1446. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1447. pocall_inline,pocall_pascal,pocall_far16,pocall_oldfpccall];
  1448. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1449. mutexclpo : [po_external]
  1450. ),(
  1451. idtok:_IOCHECK;
  1452. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1453. handler : nil;
  1454. pocall : pocall_none;
  1455. pooption : [po_iocheck];
  1456. mutexclpocall : [pocall_internproc];
  1457. mutexclpotype : [];
  1458. mutexclpo : [po_external]
  1459. ),(
  1460. idtok:_MESSAGE;
  1461. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1462. handler : @pd_message;
  1463. pocall : pocall_none;
  1464. pooption : []; { can be po_msgstr or po_msgint }
  1465. mutexclpocall : [pocall_inline,pocall_internproc];
  1466. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1467. mutexclpo : [po_interrupt,po_external]
  1468. ),(
  1469. idtok:_NEAR;
  1470. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1471. handler : @pd_near;
  1472. pocall : pocall_none;
  1473. pooption : [];
  1474. mutexclpocall : [pocall_internproc];
  1475. mutexclpotype : [];
  1476. mutexclpo : []
  1477. ),(
  1478. idtok:_NOSTACKFRAME;
  1479. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1480. handler : nil;
  1481. pocall : pocall_none;
  1482. pooption : [po_nostackframe];
  1483. mutexclpocall : [pocall_internproc];
  1484. mutexclpotype : [];
  1485. mutexclpo : []
  1486. ),(
  1487. idtok:_OVERLOAD;
  1488. pd_flags : [pd_implemen,pd_interface,pd_body];
  1489. handler : @pd_overload;
  1490. pocall : pocall_none;
  1491. pooption : [po_overload];
  1492. mutexclpocall : [pocall_internproc];
  1493. mutexclpotype : [];
  1494. mutexclpo : []
  1495. ),(
  1496. idtok:_OVERRIDE;
  1497. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1498. handler : @pd_override;
  1499. pocall : pocall_none;
  1500. pooption : [po_overridingmethod,po_virtualmethod];
  1501. mutexclpocall : [pocall_inline,pocall_internproc];
  1502. mutexclpotype : [];
  1503. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1504. ),(
  1505. idtok:_PASCAL;
  1506. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1507. handler : nil;
  1508. pocall : pocall_pascal;
  1509. pooption : [];
  1510. mutexclpocall : [];
  1511. mutexclpotype : [potype_constructor,potype_destructor];
  1512. mutexclpo : [po_external]
  1513. ),(
  1514. idtok:_PUBLIC;
  1515. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1516. handler : @pd_public;
  1517. pocall : pocall_none;
  1518. pooption : [po_public,po_global];
  1519. mutexclpocall : [pocall_internproc,pocall_inline];
  1520. mutexclpotype : [];
  1521. mutexclpo : [po_external]
  1522. ),(
  1523. idtok:_REGISTER;
  1524. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1525. handler : nil;
  1526. pocall : pocall_register;
  1527. pooption : [];
  1528. mutexclpocall : [];
  1529. mutexclpotype : [potype_constructor,potype_destructor];
  1530. mutexclpo : [po_external]
  1531. ),(
  1532. idtok:_REINTRODUCE;
  1533. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1534. handler : @pd_reintroduce;
  1535. pocall : pocall_none;
  1536. pooption : [po_reintroduce];
  1537. mutexclpocall : [pocall_inline,pocall_internproc];
  1538. mutexclpotype : [];
  1539. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod]
  1540. ),(
  1541. idtok:_SAFECALL;
  1542. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1543. handler : nil;
  1544. pocall : pocall_safecall;
  1545. pooption : [];
  1546. mutexclpocall : [];
  1547. mutexclpotype : [potype_constructor,potype_destructor];
  1548. mutexclpo : [po_external]
  1549. ),(
  1550. idtok:_SOFTFLOAT;
  1551. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1552. handler : nil;
  1553. pocall : pocall_softfloat;
  1554. pooption : [];
  1555. mutexclpocall : [];
  1556. mutexclpotype : [potype_constructor,potype_destructor];
  1557. { it's available with po_external because the libgcc floating point routines on the arm
  1558. uses this calling convention }
  1559. mutexclpo : []
  1560. ),(
  1561. idtok:_STATIC;
  1562. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1563. handler : @pd_static;
  1564. pocall : pocall_none;
  1565. pooption : [po_staticmethod];
  1566. mutexclpocall : [pocall_inline,pocall_internproc];
  1567. mutexclpotype : [potype_constructor,potype_destructor];
  1568. mutexclpo : [po_external,po_interrupt,po_exports]
  1569. ),(
  1570. idtok:_STDCALL;
  1571. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1572. handler : nil;
  1573. pocall : pocall_stdcall;
  1574. pooption : [];
  1575. mutexclpocall : [];
  1576. mutexclpotype : [potype_constructor,potype_destructor];
  1577. mutexclpo : [po_external]
  1578. ),(
  1579. idtok:_SYSCALL;
  1580. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf];
  1581. handler : @pd_syscall;
  1582. pocall : pocall_syscall;
  1583. pooption : [];
  1584. mutexclpocall : [];
  1585. mutexclpotype : [potype_constructor,potype_destructor];
  1586. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1587. ),(
  1588. idtok:_VIRTUAL;
  1589. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1590. handler : @pd_virtual;
  1591. pocall : pocall_none;
  1592. pooption : [po_virtualmethod];
  1593. mutexclpocall : [pocall_inline,pocall_internproc];
  1594. mutexclpotype : [];
  1595. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod]
  1596. ),(
  1597. idtok:_CPPDECL;
  1598. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1599. handler : nil;
  1600. pocall : pocall_cppdecl;
  1601. pooption : [];
  1602. mutexclpocall : [];
  1603. mutexclpotype : [potype_constructor,potype_destructor];
  1604. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1605. ),(
  1606. idtok:_VARARGS;
  1607. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1608. handler : nil;
  1609. pocall : pocall_none;
  1610. pooption : [po_varargs];
  1611. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1612. pocall_inline,pocall_far16,pocall_oldfpccall];
  1613. mutexclpotype : [];
  1614. mutexclpo : [po_assembler,po_interrupt]
  1615. ),(
  1616. idtok:_COMPILERPROC;
  1617. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1618. handler : nil;
  1619. pocall : pocall_compilerproc;
  1620. pooption : [];
  1621. mutexclpocall : [];
  1622. mutexclpotype : [potype_constructor,potype_destructor];
  1623. mutexclpo : [po_interrupt]
  1624. )
  1625. );
  1626. function check_proc_directive(isprocvar:boolean):boolean;
  1627. var
  1628. i : longint;
  1629. begin
  1630. result:=false;
  1631. for i:=1 to num_proc_directives do
  1632. if proc_direcdata[i].idtok=idtoken then
  1633. begin
  1634. if ((not isprocvar) or
  1635. (pd_procvar in proc_direcdata[i].pd_flags)) and
  1636. { don't eat a public directive in classes }
  1637. not((idtoken=_PUBLIC) and (symtablestack.symtabletype=objectsymtable)) then
  1638. result:=true;
  1639. exit;
  1640. end;
  1641. end;
  1642. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1643. {
  1644. Parse the procedure directive, returns true if a correct directive is found
  1645. }
  1646. var
  1647. p : longint;
  1648. found : boolean;
  1649. name : stringid;
  1650. begin
  1651. parse_proc_direc:=false;
  1652. name:=tokeninfo^[idtoken].str;
  1653. found:=false;
  1654. { Hint directive? Then exit immediatly }
  1655. if (m_hintdirective in aktmodeswitches) then
  1656. begin
  1657. case idtoken of
  1658. _LIBRARY,
  1659. _PLATFORM,
  1660. _UNIMPLEMENTED,
  1661. _DEPRECATED :
  1662. exit;
  1663. end;
  1664. end;
  1665. { C directive is MAC only, because it breaks too much existing code
  1666. on other platforms (PFV) }
  1667. if (idtoken=_C) and
  1668. not(m_mac in aktmodeswitches) then
  1669. exit;
  1670. { retrieve data for directive if found }
  1671. for p:=1 to num_proc_directives do
  1672. if proc_direcdata[p].idtok=idtoken then
  1673. begin
  1674. found:=true;
  1675. break;
  1676. end;
  1677. { Check if the procedure directive is known }
  1678. if not found then
  1679. begin
  1680. { parsing a procvar type the name can be any
  1681. next variable !! }
  1682. if ((pdflags * [pd_procvar,pd_object])=[]) and
  1683. not(idtoken=_PROPERTY) then
  1684. Message1(parser_w_unknown_proc_directive_ignored,name);
  1685. exit;
  1686. end;
  1687. { static needs a special treatment }
  1688. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1689. exit;
  1690. { check if method and directive not for object, like public.
  1691. This needs to be checked also for procvars }
  1692. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1693. (symtablestack.symtabletype=objectsymtable) then
  1694. exit;
  1695. { Conflicts between directives ? }
  1696. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1697. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1698. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1699. begin
  1700. Message1(parser_e_proc_dir_conflict,name);
  1701. exit;
  1702. end;
  1703. { set calling convention }
  1704. if proc_direcdata[p].pocall<>pocall_none then
  1705. begin
  1706. if (po_hascallingconvention in pd.procoptions) then
  1707. begin
  1708. Message2(parser_w_proc_overriding_calling,
  1709. proccalloptionStr[pd.proccalloption],
  1710. proccalloptionStr[proc_direcdata[p].pocall]);
  1711. end;
  1712. { check if the target processor supports this calling convention }
  1713. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1714. begin
  1715. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1716. { recover }
  1717. proc_direcdata[p].pocall:=pocall_stdcall;
  1718. end;
  1719. pd.proccalloption:=proc_direcdata[p].pocall;
  1720. include(pd.procoptions,po_hascallingconvention);
  1721. end;
  1722. if pd.deftype=procdef then
  1723. begin
  1724. { Check if the directive is only for objects }
  1725. if (pd_object in proc_direcdata[p].pd_flags) and
  1726. not assigned(tprocdef(pd)._class) then
  1727. exit;
  1728. { check if method and directive not for interface }
  1729. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1730. is_interface(tprocdef(pd)._class) then
  1731. exit;
  1732. end;
  1733. { consume directive, and turn flag on }
  1734. consume(token);
  1735. parse_proc_direc:=true;
  1736. { Check the pd_flags if the directive should be allowed }
  1737. if (pd_interface in pdflags) and
  1738. not(pd_interface in proc_direcdata[p].pd_flags) then
  1739. begin
  1740. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1741. exit;
  1742. end;
  1743. if (pd_implemen in pdflags) and
  1744. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1745. begin
  1746. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1747. exit;
  1748. end;
  1749. if (pd_procvar in pdflags) and
  1750. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1751. begin
  1752. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1753. exit;
  1754. end;
  1755. { Return the new pd_flags }
  1756. if not(pd_body in proc_direcdata[p].pd_flags) then
  1757. exclude(pdflags,pd_body);
  1758. { Add the correct flag }
  1759. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1760. { Call the handler }
  1761. if pointer(proc_direcdata[p].handler)<>nil then
  1762. proc_direcdata[p].handler(pd);
  1763. end;
  1764. function proc_get_importname(pd:tprocdef):string;
  1765. begin
  1766. result:='';
  1767. if not(po_external in pd.procoptions) then
  1768. internalerror(200412151);
  1769. { import by number? }
  1770. if pd.import_nr<>0 then
  1771. begin
  1772. { Nothing to do }
  1773. end
  1774. else
  1775. { external name specified }
  1776. if assigned(pd.import_name) then
  1777. begin
  1778. { Win32 imports need to use the normal name since to functions
  1779. can refer to the same DLL function. This is also needed for compatability
  1780. with Delphi and TP7 }
  1781. if not(
  1782. assigned(pd.import_dll) and
  1783. (target_info.system in [system_i386_win32,system_i386_wdosx,
  1784. system_i386_emx,system_i386_os2])
  1785. ) then
  1786. begin
  1787. if not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1788. result:=pd.import_name^
  1789. else
  1790. result:=target_info.Cprefix+pd.import_name^;
  1791. end;
  1792. end
  1793. else
  1794. begin
  1795. { Default names when importing variables }
  1796. case pd.proccalloption of
  1797. pocall_cdecl :
  1798. begin
  1799. if assigned(pd._class) then
  1800. result:=target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname
  1801. else
  1802. result:=target_info.Cprefix+pd.procsym.realname;
  1803. end;
  1804. pocall_cppdecl :
  1805. begin
  1806. result:=target_info.Cprefix+pd.cplusplusmangledname;
  1807. end;
  1808. else
  1809. begin
  1810. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  1811. if (m_mac in aktmodeswitches) then
  1812. result:=tprocdef(pd).procsym.realname;
  1813. end;
  1814. end;
  1815. end;
  1816. end;
  1817. procedure proc_set_mangledname(pd:tprocdef);
  1818. var
  1819. s : string;
  1820. begin
  1821. { When the mangledname is already set we aren't allowed to change
  1822. it because it can already be used somewhere (PFV) }
  1823. if not(po_has_mangledname in pd.procoptions) then
  1824. begin
  1825. if (po_external in pd.procoptions) then
  1826. begin
  1827. { External Procedures are only allowed to change the mangledname
  1828. in their first declaration }
  1829. if (pd.forwarddef or (not pd.hasforward)) then
  1830. begin
  1831. s:=proc_get_importname(pd);
  1832. if s<>'' then
  1833. pd.setmangledname(s);
  1834. end;
  1835. end
  1836. else
  1837. { Normal procedures }
  1838. begin
  1839. case pd.proccalloption of
  1840. pocall_compilerproc :
  1841. begin
  1842. pd.setmangledname(lower(pd.procsym.name));
  1843. end;
  1844. end;
  1845. end;
  1846. end;
  1847. { Public/exported alias names }
  1848. if (po_public in pd.procoptions) and
  1849. not(po_has_public_name in pd.procoptions) then
  1850. begin
  1851. case pd.proccalloption of
  1852. pocall_cdecl :
  1853. begin
  1854. if assigned(pd._class) then
  1855. pd.aliasnames.insert(target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname)
  1856. else
  1857. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  1858. end;
  1859. pocall_cppdecl :
  1860. begin
  1861. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  1862. end;
  1863. end;
  1864. { prevent adding the alias a second time }
  1865. include(pd.procoptions,po_has_public_name);
  1866. end;
  1867. end;
  1868. procedure handle_calling_convention(pd:tabstractprocdef);
  1869. begin
  1870. { set the default calling convention if none provided }
  1871. if not(po_hascallingconvention in pd.procoptions) then
  1872. pd.proccalloption:=aktdefproccall
  1873. else
  1874. begin
  1875. if pd.proccalloption=pocall_none then
  1876. internalerror(200309081);
  1877. end;
  1878. { handle proccall specific settings }
  1879. case pd.proccalloption of
  1880. pocall_cdecl,
  1881. pocall_cppdecl :
  1882. begin
  1883. { check C cdecl para types }
  1884. pd.parast.foreach_static(@check_c_para,nil);
  1885. end;
  1886. pocall_far16 :
  1887. begin
  1888. { Temporary stub, must be rewritten to support OS/2 far16 }
  1889. Message1(parser_w_proc_directive_ignored,'FAR16');
  1890. end;
  1891. pocall_inline :
  1892. begin
  1893. if not(cs_support_inline in aktmoduleswitches) then
  1894. begin
  1895. Message(parser_e_proc_inline_not_supported);
  1896. pd.proccalloption:=pocall_default;
  1897. end;
  1898. end;
  1899. end;
  1900. { For varargs directive also cdecl and external must be defined }
  1901. if (po_varargs in pd.procoptions) then
  1902. begin
  1903. { check first for external in the interface, if available there
  1904. then the cdecl must also be there since there is no implementation
  1905. available to contain it }
  1906. if parse_only then
  1907. begin
  1908. { if external is available, then cdecl must also be available,
  1909. procvars don't need external }
  1910. if not((po_external in pd.procoptions) or
  1911. (pd.deftype=procvardef)) and
  1912. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1913. Message(parser_e_varargs_need_cdecl_and_external);
  1914. end
  1915. else
  1916. begin
  1917. { both must be defined now }
  1918. if not((po_external in pd.procoptions) or
  1919. (pd.deftype=procvardef)) or
  1920. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1921. Message(parser_e_varargs_need_cdecl_and_external);
  1922. end;
  1923. end;
  1924. { Make var parameters regable, this must be done after the calling
  1925. convention is set. }
  1926. pd.parast.foreach_static(@set_addr_param_regable,pd);
  1927. { insert hidden high parameters }
  1928. pd.parast.foreach_static(@insert_hidden_para,pd);
  1929. { insert hidden self parameter }
  1930. insert_self_and_vmt_para(pd);
  1931. { insert funcret parameter if required }
  1932. insert_funcret_para(pd);
  1933. { insert parentfp parameter if required }
  1934. insert_parentfp_para(pd);
  1935. { Calculate parameter tlist }
  1936. pd.calcparas;
  1937. end;
  1938. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  1939. {
  1940. Parse the procedure directives. It does not matter if procedure directives
  1941. are written using ;procdir; or ['procdir'] syntax.
  1942. }
  1943. var
  1944. res : boolean;
  1945. begin
  1946. if (m_mac in aktmodeswitches) and (cs_externally_visible in aktlocalswitches) then
  1947. begin
  1948. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  1949. include(pd.procoptions,po_public);
  1950. include(pd.procoptions,po_has_public_name);
  1951. include(pd.procoptions,po_global);
  1952. end;
  1953. while token in [_ID,_LECKKLAMMER] do
  1954. begin
  1955. if try_to_consume(_LECKKLAMMER) then
  1956. begin
  1957. repeat
  1958. parse_proc_direc(pd,pdflags);
  1959. until not try_to_consume(_COMMA);
  1960. consume(_RECKKLAMMER);
  1961. { we always expect at least '[];' }
  1962. res:=true;
  1963. end
  1964. else
  1965. begin
  1966. res:=parse_proc_direc(pd,pdflags);
  1967. end;
  1968. { A procedure directive normally followed by a semicolon, but in
  1969. a const section or reading a type we should stop when _EQUAL is found,
  1970. because a constant/default value follows }
  1971. if res then
  1972. begin
  1973. if (block_type in [bt_const,bt_type]) and
  1974. (token=_EQUAL) then
  1975. break;
  1976. { support procedure proc;stdcall export; }
  1977. if not(check_proc_directive((pd.deftype=procvardef))) then
  1978. begin
  1979. { support "record p : procedure stdcall end;" and
  1980. "var p : procedure stdcall = nil;" }
  1981. if (pd_procvar in pdflags) and
  1982. (token in [_END,_RKLAMMER,_EQUAL]) then
  1983. break
  1984. else
  1985. consume(_SEMICOLON);
  1986. end;
  1987. end
  1988. else
  1989. break;
  1990. end;
  1991. end;
  1992. procedure parse_var_proc_directives(sym:tsym);
  1993. var
  1994. pdflags : tpdflags;
  1995. pd : tabstractprocdef;
  1996. begin
  1997. pdflags:=[pd_procvar];
  1998. pd:=nil;
  1999. case sym.typ of
  2000. fieldvarsym,
  2001. globalvarsym,
  2002. localvarsym,
  2003. paravarsym :
  2004. pd:=tabstractprocdef(tabstractvarsym(sym).vartype.def);
  2005. typedconstsym :
  2006. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  2007. typesym :
  2008. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  2009. else
  2010. internalerror(2003042617);
  2011. end;
  2012. if pd.deftype<>procvardef then
  2013. internalerror(2003042618);
  2014. { names should never be used anyway }
  2015. parse_proc_directives(pd,pdflags);
  2016. end;
  2017. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2018. var
  2019. pdflags : tpdflags;
  2020. begin
  2021. pdflags:=[pd_object];
  2022. parse_proc_directives(pd,pdflags);
  2023. end;
  2024. function proc_add_definition(var pd:tprocdef):boolean;
  2025. {
  2026. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2027. forwarddef is found and reused it returns true
  2028. }
  2029. var
  2030. hd : tprocdef;
  2031. ad,fd : tsym;
  2032. s1,s2 : stringid;
  2033. i : cardinal;
  2034. forwardfound : boolean;
  2035. po_comp : tprocoptions;
  2036. aprocsym : tprocsym;
  2037. begin
  2038. forwardfound:=false;
  2039. aprocsym:=tprocsym(pd.procsym);
  2040. { check overloaded functions if the same function already exists }
  2041. for i:=1 to aprocsym.procdef_count do
  2042. begin
  2043. hd:=aprocsym.procdef[i];
  2044. { Skip overloaded definitions that are declared in other
  2045. units }
  2046. if hd.procsym<>aprocsym then
  2047. continue;
  2048. { check the parameters, for delphi/tp it is possible to
  2049. leave the parameters away in the implementation (forwarddef=false).
  2050. But for an overload declared function this is not allowed }
  2051. if { check if empty implementation arguments match is allowed }
  2052. (
  2053. not(m_repeat_forward in aktmodeswitches) and
  2054. not(pd.forwarddef) and
  2055. (pd.maxparacount=0) and
  2056. not(po_overload in hd.procoptions)
  2057. ) or
  2058. { check arguments }
  2059. (
  2060. (compare_paras(pd.paras,hd.paras,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  2061. { for operators equal_paras is not enough !! }
  2062. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  2063. equal_defs(hd.rettype.def,pd.rettype.def))
  2064. ) then
  2065. begin
  2066. { Check if we've found the forwarddef, if found then
  2067. we need to update the forward def with the current
  2068. implementation settings }
  2069. if hd.forwarddef then
  2070. begin
  2071. forwardfound:=true;
  2072. { Check if the procedure type and return type are correct,
  2073. also the parameters must match also with the type }
  2074. if (hd.proctypeoption<>pd.proctypeoption) or
  2075. (
  2076. (m_repeat_forward in aktmodeswitches) and
  2077. (not((pd.maxparacount=0) or
  2078. (compare_paras(pd.paras,hd.paras,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  2079. ) or
  2080. (
  2081. ((m_repeat_forward in aktmodeswitches) or
  2082. not(is_void(pd.rettype.def))) and
  2083. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  2084. begin
  2085. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2086. pd.fullprocname(false));
  2087. aprocsym.write_parameter_lists(pd);
  2088. break;
  2089. end;
  2090. { Check if both are declared forward }
  2091. if hd.forwarddef and pd.forwarddef then
  2092. begin
  2093. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  2094. pd.fullprocname(false));
  2095. end;
  2096. { internconst or internproc only need to be defined once }
  2097. if (hd.proccalloption=pocall_internproc) then
  2098. pd.proccalloption:=hd.proccalloption
  2099. else
  2100. if (pd.proccalloption=pocall_internproc) then
  2101. hd.proccalloption:=pd.proccalloption;
  2102. { Check calling convention }
  2103. if (hd.proccalloption<>pd.proccalloption) then
  2104. begin
  2105. { In delphi it is possible to specify the calling
  2106. convention in the interface or implementation if
  2107. there was no convention specified in the other
  2108. part }
  2109. if (m_delphi in aktmodeswitches) then
  2110. begin
  2111. if not(po_hascallingconvention in pd.procoptions) then
  2112. pd.proccalloption:=hd.proccalloption
  2113. else
  2114. if not(po_hascallingconvention in hd.procoptions) then
  2115. hd.proccalloption:=pd.proccalloption
  2116. else
  2117. begin
  2118. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2119. aprocsym.write_parameter_lists(pd);
  2120. { restore interface settings }
  2121. pd.proccalloption:=hd.proccalloption;
  2122. end;
  2123. end
  2124. else
  2125. begin
  2126. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2127. aprocsym.write_parameter_lists(pd);
  2128. { restore interface settings }
  2129. pd.proccalloption:=hd.proccalloption;
  2130. end;
  2131. end;
  2132. { Check procedure options, Delphi requires that class is
  2133. repeated in the implementation for class methods }
  2134. if (m_fpc in aktmodeswitches) then
  2135. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  2136. else
  2137. po_comp:=[po_classmethod,po_methodpointer];
  2138. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  2139. begin
  2140. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2141. pd.fullprocname(false));
  2142. aprocsym.write_parameter_lists(pd);
  2143. { This error is non-fatal, we can recover }
  2144. end;
  2145. { Forward declaration is external? }
  2146. if (po_external in hd.procoptions) then
  2147. MessagePos(pd.fileinfo,parser_e_proc_already_external);
  2148. { Check parameters }
  2149. if (m_repeat_forward in aktmodeswitches) or
  2150. (pd.minparacount>0) then
  2151. begin
  2152. { If mangled names are equal then they have the same amount of arguments }
  2153. { We can check the names of the arguments }
  2154. { both symtables are in the same order from left to right }
  2155. ad:=tsym(hd.parast.symindex.first);
  2156. fd:=tsym(pd.parast.symindex.first);
  2157. repeat
  2158. { skip default parameter constsyms }
  2159. while assigned(ad) and (ad.typ<>paravarsym) do
  2160. ad:=tsym(ad.indexnext);
  2161. while assigned(fd) and (fd.typ<>paravarsym) do
  2162. fd:=tsym(fd.indexnext);
  2163. { stop when one of the two lists is at the end }
  2164. if not assigned(ad) or not assigned(fd) then
  2165. break;
  2166. { retrieve names, remove reg for register parameters }
  2167. s1:=ad.name;
  2168. s2:=fd.name;
  2169. { compare names }
  2170. if (s1<>s2) then
  2171. begin
  2172. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  2173. aprocsym.name,s1,s2);
  2174. break;
  2175. end;
  2176. ad:=tsym(ad.indexnext);
  2177. fd:=tsym(fd.indexnext);
  2178. until false;
  2179. if assigned(ad) xor assigned(fd) then
  2180. internalerror(200204178);
  2181. end;
  2182. { Everything is checked, now we can update the forward declaration
  2183. with the new data from the implementation }
  2184. hd.forwarddef:=pd.forwarddef;
  2185. hd.hasforward:=true;
  2186. hd.procoptions:=hd.procoptions+pd.procoptions;
  2187. if hd.extnumber=65535 then
  2188. hd.extnumber:=pd.extnumber;
  2189. while not pd.aliasnames.empty do
  2190. hd.aliasnames.insert(pd.aliasnames.getfirst);
  2191. { update fileinfo so position references the implementation,
  2192. also update funcretsym if it is already generated }
  2193. hd.fileinfo:=pd.fileinfo;
  2194. if assigned(hd.funcretsym) then
  2195. hd.funcretsym.fileinfo:=pd.fileinfo;
  2196. { import names }
  2197. if assigned(pd.import_dll) then
  2198. begin
  2199. stringdispose(hd.import_dll);
  2200. hd.import_dll:=stringdup(pd.import_dll^);
  2201. end;
  2202. if assigned(pd.import_name) then
  2203. begin
  2204. stringdispose(hd.import_name);
  2205. hd.import_name:=stringdup(pd.import_name^);
  2206. end;
  2207. hd.import_nr:=pd.import_nr;
  2208. { for compilerproc defines we need to rename and update the
  2209. symbolname to lowercase }
  2210. if (pd.proccalloption=pocall_compilerproc) then
  2211. begin
  2212. { rename to lowercase so users can't access it }
  2213. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  2214. { also update the realname that is stored in the ppu }
  2215. stringdispose(aprocsym._realname);
  2216. aprocsym._realname:=stringdup('$'+aprocsym.name);
  2217. { the mangeled name is already changed by the pd_compilerproc }
  2218. { handler. It must be done immediately because if we have a }
  2219. { call to a compilerproc before it's implementation is }
  2220. { encountered, it must already use the new mangled name (JM) }
  2221. end;
  2222. { the procdef will be released by the symtable, we release
  2223. at least the parast }
  2224. pd.releasemem;
  2225. pd:=hd;
  2226. end
  2227. else
  2228. begin
  2229. { abstract methods aren't forward defined, but this }
  2230. { needs another error message }
  2231. if (po_abstractmethod in hd.procoptions) then
  2232. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  2233. else
  2234. begin
  2235. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  2236. aprocsym.write_parameter_lists(pd);
  2237. end;
  2238. end;
  2239. { we found one proc with the same arguments, there are no others
  2240. so we can stop }
  2241. break;
  2242. end;
  2243. { check for allowing overload directive }
  2244. if not(m_fpc in aktmodeswitches) then
  2245. begin
  2246. { overload directive turns on overloading }
  2247. if ((po_overload in pd.procoptions) or
  2248. (po_overload in hd.procoptions)) then
  2249. begin
  2250. { check if all procs have overloading, but not if the proc is a method or
  2251. already declared forward, then the check is already done }
  2252. if not(hd.hasforward or
  2253. assigned(pd._class) or
  2254. (pd.forwarddef<>hd.forwarddef) or
  2255. ((po_overload in pd.procoptions) and
  2256. (po_overload in hd.procoptions))) then
  2257. begin
  2258. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2259. break;
  2260. end;
  2261. end
  2262. else
  2263. begin
  2264. if not(hd.forwarddef) then
  2265. begin
  2266. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2267. break;
  2268. end;
  2269. end;
  2270. end; { equal arguments }
  2271. end;
  2272. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2273. list }
  2274. if not forwardfound then
  2275. aprocsym.addprocdef(pd);
  2276. proc_add_definition:=forwardfound;
  2277. end;
  2278. end.
  2279. {
  2280. $Log$
  2281. Revision 1.229 2005-02-03 17:11:40 peter
  2282. * more procvar directive fixes
  2283. Revision 1.228 2005/02/01 08:46:13 michael
  2284. * Patch from peter: fix macpas anonymous function procvar
  2285. Revision 1.227 2005/01/31 21:27:51 peter
  2286. * macpas procvars in parameters
  2287. Revision 1.226 2005/01/19 22:19:41 peter
  2288. * unit mapping rewrite
  2289. * new derefmap added
  2290. Revision 1.225 2005/01/06 02:13:03 karoly
  2291. * more SysV call support stuff for MorphOS
  2292. Revision 1.224 2005/01/05 02:31:06 karoly
  2293. * fixed SysV syscall support (MorphOS)
  2294. Revision 1.223 2005/01/04 17:40:33 karoly
  2295. + sysv style syscalls added for MorphOS
  2296. Revision 1.222 2004/12/27 17:32:06 peter
  2297. * don't parse public,private,protected as procdirectives, leave
  2298. procdirective parsing before any other check is done
  2299. Revision 1.221 2004/12/26 20:12:23 peter
  2300. * don't allow class methods in interfaces
  2301. Revision 1.220 2004/12/15 19:30:32 peter
  2302. * syscall with sysv abi for morphos
  2303. Revision 1.219 2004/12/15 16:00:16 peter
  2304. * external is again allowed in implementation
  2305. Revision 1.218 2004/12/07 16:11:52 peter
  2306. * set vo_explicit_paraloc flag
  2307. Revision 1.217 2004/12/05 12:28:11 peter
  2308. * procvar handling for tp procvar mode fixed
  2309. * proc to procvar moved from addrnode to typeconvnode
  2310. * inlininginfo is now allocated only for inline routines that
  2311. can be inlined, introduced a new flag po_has_inlining_info
  2312. Revision 1.216 2004/12/05 00:32:56 olle
  2313. + bugfix for $Z+ for mode macpas
  2314. Revision 1.215 2004/11/29 21:50:08 peter
  2315. * public is allowd in interface
  2316. Revision 1.214 2004/11/29 17:48:34 peter
  2317. * when importing by index don't change mangledname
  2318. Revision 1.213 2004/11/22 12:22:25 jonas
  2319. * fixed importing of cdecl routines for OS'es which have a cprefix
  2320. Revision 1.212 2004/11/21 17:54:59 peter
  2321. * ttempcreatenode.create_reg merged into .create with parameter
  2322. whether a register is allowed
  2323. * funcret_paraloc renamed to funcretloc
  2324. Revision 1.211 2004/11/21 16:33:19 peter
  2325. * fixed message methods
  2326. * fixed typo with win32 dll import from implementation
  2327. * released external check
  2328. Revision 1.210 2004/11/19 08:17:01 michael
  2329. * Split po_public into po_public and po_global (Peter)
  2330. Revision 1.209 2004/11/17 22:41:41 peter
  2331. * make some checks EXTDEBUG only for now so linux cycles again
  2332. Revision 1.208 2004/11/17 22:21:35 peter
  2333. mangledname setting moved to place after the complete proc declaration is read
  2334. import generation moved to place where body is also parsed (still gives problems with win32)
  2335. Revision 1.207 2004/11/16 22:09:57 peter
  2336. * _mangledname for symbols moved only to symbols that really need it
  2337. * overload number removed, add function result type to the mangledname fo
  2338. procdefs
  2339. Revision 1.206 2004/11/16 20:32:40 peter
  2340. * fixes for win32 mangledname
  2341. Revision 1.205 2004/11/15 23:35:31 peter
  2342. * tparaitem removed, use tparavarsym instead
  2343. * parameter order is now calculated from paranr value in tparavarsym
  2344. Revision 1.204 2004/11/14 16:26:29 florian
  2345. * fixed morphos syscall
  2346. Revision 1.203 2004/11/11 19:31:33 peter
  2347. * fixed compile of powerpc,sparc,arm
  2348. Revision 1.202 2004/11/09 22:32:59 peter
  2349. * small m68k updates to bring it up2date
  2350. * give better error for external local variable
  2351. Revision 1.201 2004/11/09 17:26:47 peter
  2352. * fixed wrong typecasts
  2353. Revision 1.200 2004/11/08 22:09:59 peter
  2354. * tvarsym splitted
  2355. Revision 1.199 2004/11/05 21:16:55 peter
  2356. * rename duplicate symbols and insert with unique name in the
  2357. symtable
  2358. Revision 1.198 2004/10/31 18:54:24 peter
  2359. * $fpctarget expands to <cpu>-<os>
  2360. * allow * in middle of the path to support ../*/units/$fpctarget
  2361. Revision 1.197 2004/10/24 20:01:08 peter
  2362. * remove saveregister calling convention
  2363. Revision 1.196 2004/10/24 13:48:50 peter
  2364. * don't give warning for property as unknwon proc directive
  2365. Revision 1.195 2004/10/24 11:44:28 peter
  2366. * small regvar fixes
  2367. * loadref parameter removed from concatcopy,incrrefcount,etc
  2368. Revision 1.194 2004/10/15 09:14:17 mazen
  2369. - remove $IFDEF DELPHI and related code
  2370. - remove $IFDEF FPCPROCVAR and related code
  2371. Revision 1.193 2004/10/11 15:45:35 peter
  2372. * mark non-regable after calling convention is set
  2373. Revision 1.192 2004/10/10 21:08:55 peter
  2374. * parameter regvar fixes
  2375. Revision 1.191 2004/10/08 17:09:43 peter
  2376. * tvarsym.varregable added, split vo_regable from varoptions
  2377. Revision 1.190 2004/08/29 11:28:41 peter
  2378. fixed crash with error in default value
  2379. allow assembler directive in interface
  2380. Revision 1.189 2004/08/25 15:57:19 peter
  2381. * fix for tw3261
  2382. Revision 1.188 2004/08/22 20:11:38 florian
  2383. * morphos now takes any pointer var. as libbase
  2384. * alignment for sparc fixed
  2385. * int -> double conversion on sparc fixed
  2386. Revision 1.187 2004/08/22 11:24:27 peter
  2387. * don't insert result variables for constructor/destructors
  2388. Revision 1.186 2004/08/13 17:53:37 jonas
  2389. * only set the mangled name immediately for external procedures in macpas
  2390. mode if the procedure isn't cdecl (so that the c-prefix is taken into
  2391. account, necessary for Mac OS X)
  2392. Revision 1.185 2004/08/08 12:35:09 florian
  2393. * proc. var declarations in a class doesn't eat a public anymore
  2394. Revision 1.184 2004/07/17 13:51:57 florian
  2395. * function result location for syscalls on MOS hopefully correctly set now
  2396. Revision 1.183 2004/07/14 23:19:21 olle
  2397. + added external facilities for macpas
  2398. Revision 1.182 2004/06/20 08:55:30 florian
  2399. * logs truncated
  2400. Revision 1.181 2004/06/16 20:07:09 florian
  2401. * dwarf branch merged
  2402. Revision 1.180 2004/05/23 20:54:39 peter
  2403. * fixed 3114
  2404. Revision 1.179 2004/05/23 19:06:26 peter
  2405. * expect : after function when it is a forwarddef
  2406. Revision 1.178 2004/05/12 13:21:09 karoly
  2407. * few small changes to add syscall support to M68k/Amiga target
  2408. Revision 1.177 2004/05/11 22:52:48 olle
  2409. * Moved import_implicit_external to symsym
  2410. }