pdecsub.pas 90 KB

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