pdecsub.pas 89 KB

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