pdecsub.pas 93 KB

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