pdecsub.pas 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142
  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. const
  24. pd_global = $1; { directive must be global }
  25. pd_body = $2; { directive needs a body }
  26. pd_implemen = $4; { directive can be used implementation section }
  27. pd_interface = $8; { directive can be used interface section }
  28. pd_object = $10; { directive can be used object declaration }
  29. pd_procvar = $20; { directive can be used procvar declaration }
  30. pd_notobject = $40; { directive can not be used object declaration }
  31. pd_notobjintf= $80; { directive can not be used interface declaration }
  32. function is_proc_directive(tok:ttoken):boolean;
  33. procedure parameter_dec(aktprocdef:tabstractprocdef);
  34. procedure parse_proc_directives(var pdflags:word);
  35. procedure handle_calling_convention(sym:tprocsym;def:tabstractprocdef);
  36. procedure calc_parasymtable_addresses(def:tprocdef);
  37. procedure parse_proc_head(options:tproctypeoption);
  38. procedure parse_proc_dec;
  39. procedure parse_var_proc_directives(var sym : tsym);
  40. procedure parse_object_proc_directives(var sym : tprocsym);
  41. function proc_add_definition(aprocsym:tprocsym;var aprocdef : tprocdef) : boolean;
  42. implementation
  43. uses
  44. {$ifdef delphi}
  45. sysutils,
  46. {$else delphi}
  47. strings,
  48. {$endif delphi}
  49. { common }
  50. cutils,cclasses,
  51. { global }
  52. globtype,globals,verbose,
  53. systems,cpubase,
  54. { aasm }
  55. aasmbase,aasmtai,aasmcpu,
  56. { symtable }
  57. symbase,symtable,defbase,paramgr,
  58. { pass 1 }
  59. node,htypechk,
  60. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  61. { parser }
  62. fmodule,scanner,
  63. pbase,pexpr,ptype,pdecl,
  64. { linking }
  65. import,gendef,
  66. { codegen }
  67. cpuinfo,cgbase
  68. ;
  69. procedure resetvaluepara(p:tnamedindexitem;arg:pointer);
  70. begin
  71. if tsym(p).typ=varsym then
  72. with tvarsym(p) do
  73. if copy(name,1,3)='val' then
  74. aktprocdef.parast.symsearch.rename(name,copy(name,4,length(name)));
  75. end;
  76. procedure parameter_dec(aktprocdef:tabstractprocdef);
  77. {
  78. handle_procvar needs the same changes
  79. }
  80. var
  81. is_procvar : boolean;
  82. sc : tsinglelist;
  83. htype,
  84. tt : ttype;
  85. arrayelementtype : ttype;
  86. hvs,
  87. vs : tvarsym;
  88. srsym : tsym;
  89. hs1 : string;
  90. varspez : Tvarspez;
  91. inserthigh : boolean;
  92. tdefaultvalue : tconstsym;
  93. defaultrequired : boolean;
  94. old_object_option : tsymoptions;
  95. dummyst : tparasymtable;
  96. currparast : tparasymtable;
  97. begin
  98. consume(_LKLAMMER);
  99. { Delphi/Kylix supports nonsense like }
  100. { procedure p(); }
  101. if try_to_consume(_RKLAMMER) and
  102. not(m_tp7 in aktmodeswitches) then
  103. exit;
  104. { parsing a proc or procvar ? }
  105. is_procvar:=(aktprocdef.deftype=procvardef);
  106. { create dummy symtable for procvars }
  107. if is_procvar then
  108. begin
  109. dummyst:=tparasymtable.create;
  110. currparast:=dummyst;
  111. end
  112. else
  113. begin
  114. currparast:=tparasymtable(tprocdef(aktprocdef).parast);
  115. end;
  116. { reset }
  117. sc:=tsinglelist.create;
  118. defaultrequired:=false;
  119. { the variables are always public }
  120. old_object_option:=current_object_option;
  121. current_object_option:=[sp_public];
  122. inc(testcurobject);
  123. repeat
  124. if try_to_consume(_VAR) then
  125. varspez:=vs_var
  126. else
  127. if try_to_consume(_CONST) then
  128. varspez:=vs_const
  129. else
  130. if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  131. begin
  132. consume(_OUT);
  133. varspez:=vs_out
  134. end
  135. else
  136. varspez:=vs_value;
  137. inserthigh:=false;
  138. tdefaultvalue:=nil;
  139. tt.reset;
  140. { self is only allowed in procvars and class methods }
  141. if (idtoken=_SELF) and
  142. (is_procvar or
  143. (assigned(procinfo._class) and is_class(procinfo._class))) then
  144. begin
  145. if varspez <> vs_value then
  146. CGMessage(parser_e_self_call_by_value);
  147. if not is_procvar then
  148. begin
  149. htype.setdef(procinfo._class);
  150. vs:=tvarsym.create('@',htype);
  151. vs.varspez:=vs_var;
  152. { insert the sym in the parasymtable }
  153. tprocdef(aktprocdef).parast.insert(vs);
  154. inc(procinfo.selfpointer_offset,vs.address);
  155. end
  156. else
  157. vs:=nil;
  158. { must also be included for procvars to allow the proc2procvar }
  159. { type conversions (po_containsself is in po_comp) (JM) }
  160. include(aktprocdef.procoptions,po_containsself);
  161. consume(idtoken);
  162. consume(_COLON);
  163. single_type(tt,hs1,false);
  164. { this must be call-by-value, but we generate already an }
  165. { an error above if that's not the case (JM) }
  166. aktprocdef.concatpara(tt,vs,varspez,nil);
  167. { check the types for procedures only }
  168. if not is_procvar then
  169. CheckTypes(tt.def,procinfo._class);
  170. end
  171. else
  172. begin
  173. { read identifiers and insert with error type }
  174. sc.reset;
  175. repeat
  176. vs:=tvarsym.create(orgpattern,generrortype);
  177. currparast.insert(vs);
  178. sc.insert(vs);
  179. consume(_ID);
  180. until not try_to_consume(_COMMA);
  181. { read type declaration, force reading for value and const paras }
  182. if (token=_COLON) or (varspez=vs_value) then
  183. begin
  184. consume(_COLON);
  185. { check for an open array }
  186. if token=_ARRAY then
  187. begin
  188. consume(_ARRAY);
  189. consume(_OF);
  190. { define range and type of range }
  191. tt.setdef(tarraydef.create(0,-1,s32bittype));
  192. { array of const ? }
  193. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  194. begin
  195. consume(_CONST);
  196. srsym:=searchsymonlyin(systemunit,'TVARREC');
  197. if not assigned(srsym) then
  198. InternalError(1234124);
  199. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  200. tarraydef(tt.def).IsArrayOfConst:=true;
  201. end
  202. else
  203. begin
  204. { define field type }
  205. single_type(arrayelementtype,hs1,false);
  206. tarraydef(tt.def).setelementtype(arrayelementtype);
  207. end;
  208. inserthigh:=true;
  209. end
  210. else
  211. begin
  212. { open string ? }
  213. if (varspez=vs_var) and
  214. (
  215. (
  216. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  217. (cs_openstring in aktmoduleswitches) and
  218. not(cs_ansistrings in aktlocalswitches)
  219. ) or
  220. (idtoken=_OPENSTRING)) then
  221. begin
  222. consume(token);
  223. tt:=openshortstringtype;
  224. hs1:='openstring';
  225. inserthigh:=true;
  226. end
  227. else
  228. begin
  229. { everything else }
  230. single_type(tt,hs1,false);
  231. end;
  232. { default parameter }
  233. if (m_default_para in aktmodeswitches) then
  234. begin
  235. if try_to_consume(_EQUAL) then
  236. begin
  237. vs:=tvarsym(sc.first);
  238. if assigned(vs.listnext) then
  239. Message(parser_e_default_value_only_one_para);
  240. { prefix 'def' to the parameter name }
  241. tdefaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  242. if assigned(tdefaultvalue) then
  243. tprocdef(aktprocdef).parast.insert(tdefaultvalue);
  244. defaultrequired:=true;
  245. end
  246. else
  247. begin
  248. if defaultrequired then
  249. Message1(parser_e_default_value_expected_for_para,vs.name);
  250. end;
  251. end;
  252. end;
  253. end
  254. else
  255. begin
  256. {$ifndef UseNiceNames}
  257. hs1:='$$$';
  258. {$else UseNiceNames}
  259. hs1:='var';
  260. {$endif UseNiceNames}
  261. tt:=cformaltype;
  262. end;
  263. { For proc vars we only need the definitions }
  264. if not is_procvar then
  265. begin
  266. vs:=tvarsym(sc.first);
  267. while assigned(vs) do
  268. begin
  269. { update varsym }
  270. vs.vartype:=tt;
  271. vs.varspez:=varspez;
  272. if (varspez in [vs_var,vs_const,vs_out]) and
  273. paramanager.push_addr_param(tt.def,false) then
  274. include(vs.varoptions,vo_regable);
  275. { do we need a local copy? Then rename the varsym, do this after the
  276. insert so the dup id checking is done correctly }
  277. if (varspez=vs_value) and
  278. paramanager.push_addr_param(tt.def,aktprocdef.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  279. not(is_open_array(tt.def) or is_array_of_const(tt.def)) then
  280. currparast.rename(vs.name,'val'+vs.name);
  281. { also need to push a high value? }
  282. if inserthigh then
  283. begin
  284. hvs:=tvarsym.create('$high'+vs.name,s32bittype);
  285. hvs.varspez:=vs_const;
  286. currparast.insert(hvs);
  287. end;
  288. aktprocdef.concatpara(tt,vs,varspez,tdefaultvalue);
  289. vs:=tvarsym(vs.listnext);
  290. end;
  291. end
  292. else
  293. begin
  294. vs:=tvarsym(sc.first);
  295. while assigned(vs) do
  296. begin
  297. { don't insert a parasym, the varsyms will be
  298. disposed }
  299. aktprocdef.concatpara(tt,nil,varspez,tdefaultvalue);
  300. vs:=tvarsym(vs.listnext);
  301. end;
  302. end;
  303. end;
  304. { set the new mangled name }
  305. until not try_to_consume(_SEMICOLON);
  306. { remove parasymtable from stack }
  307. if is_procvar then
  308. dummyst.free;
  309. sc.free;
  310. { reset object options }
  311. dec(testcurobject);
  312. current_object_option:=old_object_option;
  313. consume(_RKLAMMER);
  314. end;
  315. procedure parse_proc_head(options:tproctypeoption);
  316. var
  317. orgsp,sp:stringid;
  318. paramoffset:longint;
  319. sym:tsym;
  320. st : tsymtable;
  321. srsymtable : tsymtable;
  322. pdl : pprocdeflist;
  323. storepos,procstartfilepos : tfileposinfo;
  324. i: longint;
  325. begin
  326. { Save the position where this procedure really starts }
  327. procstartfilepos:=akttokenpos;
  328. aktprocdef:=nil;
  329. if (options=potype_operator) then
  330. begin
  331. sp:=overloaded_names[optoken];
  332. orgsp:=sp;
  333. end
  334. else
  335. begin
  336. sp:=pattern;
  337. orgsp:=orgpattern;
  338. consume(_ID);
  339. end;
  340. { examine interface map: function/procedure iname.functionname=locfuncname }
  341. if parse_only and
  342. assigned(procinfo._class) and
  343. assigned(procinfo._class.implementedinterfaces) and
  344. (procinfo._class.implementedinterfaces.count>0) and
  345. try_to_consume(_POINT) then
  346. begin
  347. storepos:=akttokenpos;
  348. akttokenpos:=procstartfilepos;
  349. { get interface syms}
  350. searchsym(sp,sym,srsymtable);
  351. if not assigned(sym) then
  352. begin
  353. identifier_not_found(orgsp);
  354. sym:=generrorsym;
  355. end;
  356. akttokenpos:=storepos;
  357. { load proc name }
  358. if sym.typ=typesym then
  359. i:=procinfo._class.implementedinterfaces.searchintf(ttypesym(sym).restype.def);
  360. { qualifier is interface name? }
  361. if (sym.typ<>typesym) or (ttypesym(sym).restype.def.deftype<>objectdef) or
  362. (i=-1) then
  363. begin
  364. Message(parser_e_interface_id_expected);
  365. aktprocsym:=nil;
  366. end
  367. else
  368. begin
  369. aktprocsym:=tprocsym(procinfo._class.implementedinterfaces.interfaces(i).symtable.search(sp));
  370. { the method can be declared after the mapping FK
  371. if not(assigned(aktprocsym)) then
  372. Message(parser_e_methode_id_expected);
  373. }
  374. end;
  375. consume(_ID);
  376. consume(_EQUAL);
  377. if (token=_ID) { and assigned(aktprocsym) } then
  378. procinfo._class.implementedinterfaces.addmappings(i,sp,pattern);
  379. consume(_ID);
  380. exit;
  381. end;
  382. { method ? }
  383. if not(parse_only) and
  384. (lexlevel=normal_function_level) and
  385. try_to_consume(_POINT) then
  386. begin
  387. { search for object name }
  388. storepos:=akttokenpos;
  389. akttokenpos:=procstartfilepos;
  390. searchsym(sp,sym,srsymtable);
  391. if not assigned(sym) then
  392. begin
  393. identifier_not_found(orgsp);
  394. sym:=generrorsym;
  395. end;
  396. akttokenpos:=storepos;
  397. { consume proc name }
  398. sp:=pattern;
  399. orgsp:=orgpattern;
  400. procstartfilepos:=akttokenpos;
  401. consume(_ID);
  402. { qualifier is class name ? }
  403. if (sym.typ<>typesym) or
  404. (ttypesym(sym).restype.def.deftype<>objectdef) then
  405. begin
  406. Message(parser_e_class_id_expected);
  407. aktprocsym:=nil;
  408. aktprocdef:=nil;
  409. end
  410. else
  411. begin
  412. { used to allow private syms to be seen }
  413. aktobjectdef:=tobjectdef(ttypesym(sym).restype.def);
  414. procinfo._class:=tobjectdef(ttypesym(sym).restype.def);
  415. aktprocsym:=tprocsym(procinfo._class.symtable.search(sp));
  416. {The procedure has been found. So it is
  417. a global one. Set the flags to mark this.}
  418. procinfo.flags:=procinfo.flags or pi_is_global;
  419. aktobjectdef:=nil;
  420. { we solve this below }
  421. if not(assigned(aktprocsym)) then
  422. Message(parser_e_methode_id_expected);
  423. end;
  424. end
  425. else
  426. begin
  427. { check for constructor/destructor which is not allowed here }
  428. if (not parse_only) and
  429. (options in [potype_constructor,potype_destructor]) then
  430. Message(parser_e_constructors_always_objects);
  431. akttokenpos:=procstartfilepos;
  432. aktprocsym:=tprocsym(symtablestack.search(sp));
  433. if not(parse_only) then
  434. begin
  435. {The procedure we prepare for is in the implementation
  436. part of the unit we compile. It is also possible that we
  437. are compiling a program, which is also some kind of
  438. implementaion part.
  439. We need to find out if the procedure is global. If it is
  440. global, it is in the global symtable.}
  441. if not assigned(aktprocsym) and
  442. (symtablestack.symtabletype=staticsymtable) and
  443. assigned(symtablestack.next) and
  444. (symtablestack.next.unitid=0) then
  445. begin
  446. {Search the procedure in the global symtable.}
  447. aktprocsym:=tprocsym(symtablestack.next.search(sp));
  448. if assigned(aktprocsym) then
  449. begin
  450. {Check if it is a procedure.}
  451. if aktprocsym.typ<>procsym then
  452. DuplicateSym(aktprocsym);
  453. {The procedure has been found. So it is
  454. a global one. Set the flags to mark this.}
  455. procinfo.flags:=procinfo.flags or pi_is_global;
  456. end;
  457. end;
  458. end;
  459. end;
  460. if assigned(aktprocsym) then
  461. begin
  462. { Check if overloaded is a procsym }
  463. if aktprocsym.typ<>procsym then
  464. begin
  465. { when the other symbol is a unit symbol then hide the unit
  466. symbol. Only in tp mode because it's bad programming }
  467. if (m_duplicate_names in aktmodeswitches) and
  468. (aktprocsym.typ=unitsym) then
  469. begin
  470. aktprocsym.owner.rename(aktprocsym.name,'hidden'+aktprocsym.name);
  471. end
  472. else
  473. begin
  474. { we use a different error message for tp7 so it looks more compatible }
  475. if (m_fpc in aktmodeswitches) then
  476. Message1(parser_e_overloaded_no_procedure,aktprocsym.realname)
  477. else
  478. DuplicateSym(aktprocsym);
  479. { rename the name to an unique name to avoid an
  480. error when inserting the symbol in the symtable }
  481. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  482. end;
  483. { generate a new aktprocsym }
  484. aktprocsym:=nil;
  485. end;
  486. end;
  487. { test again if assigned, it can be reset to recover }
  488. if not assigned(aktprocsym) then
  489. begin
  490. { create a new procsym and set the real filepos }
  491. akttokenpos:=procstartfilepos;
  492. { for operator we have only one procsym for each overloaded
  493. operation }
  494. if (options=potype_operator) then
  495. begin
  496. { is the current overload sym already in the current unit }
  497. if assigned(overloaded_operators[optoken]) and
  498. (overloaded_operators[optoken].owner=symtablestack) then
  499. aktprocsym:=overloaded_operators[optoken]
  500. else
  501. begin
  502. { create the procsym with saving the original case }
  503. aktprocsym:=tprocsym.create('$'+sp);
  504. if assigned(overloaded_operators[optoken]) then
  505. overloaded_operators[optoken].concat_procdefs_to(aktprocsym);
  506. end;
  507. end
  508. else
  509. aktprocsym:=tprocsym.create(orgsp);
  510. symtablestack.insert(aktprocsym);
  511. end;
  512. st:=symtablestack;
  513. aktprocdef:=tprocdef.create;
  514. aktprocdef.symtablelevel:=symtablestack.symtablelevel;
  515. if assigned(procinfo._class) then
  516. aktprocdef._class := procinfo._class;
  517. { set the options from the caller (podestructor or poconstructor) }
  518. aktprocdef.proctypeoption:=options;
  519. { add procsym to the procdef }
  520. aktprocdef.procsym:=aktprocsym;
  521. { save file position }
  522. aktprocdef.fileinfo:=procstartfilepos;
  523. { this must also be inserted in the right symtable !! PM }
  524. { otherwise we get subbtle problems with
  525. definitions of args defs in staticsymtable for
  526. implementation of a global method }
  527. if token=_LKLAMMER then
  528. parameter_dec(aktprocdef);
  529. { calculate the offset of the parameters }
  530. paramoffset:=target_info.first_parm_offset;
  531. { calculate frame pointer offset }
  532. if lexlevel>normal_function_level then
  533. begin
  534. procinfo.framepointer_offset:=paramoffset;
  535. inc(paramoffset,pointer_size);
  536. { this is needed to get correct framepointer push for local
  537. forward functions !! }
  538. aktprocdef.parast.symtablelevel:=lexlevel;
  539. end;
  540. if assigned (procinfo._Class) and
  541. is_object(procinfo._Class) and
  542. (aktprocdef.proctypeoption in [potype_constructor,potype_destructor]) then
  543. inc(paramoffset,pointer_size);
  544. { self pointer offset, must be done after parsing the parameters }
  545. { self isn't pushed in nested procedure of methods }
  546. if assigned(procinfo._class) and (lexlevel=normal_function_level) then
  547. begin
  548. procinfo.selfpointer_offset:=paramoffset;
  549. if assigned(aktprocdef) and
  550. not(po_containsself in aktprocdef.procoptions) then
  551. inc(paramoffset,pointer_size);
  552. end;
  553. { con/-destructor flag ? }
  554. if assigned (procinfo._Class) and
  555. is_class(procinfo._class) and
  556. (aktprocdef.proctypeoption in [potype_destructor,potype_constructor]) then
  557. inc(paramoffset,pointer_size);
  558. procinfo.para_offset:=paramoffset;
  559. { so we only restore the symtable now }
  560. symtablestack:=st;
  561. if (options=potype_operator) then
  562. overloaded_operators[optoken]:=aktprocsym;
  563. end;
  564. procedure parse_proc_dec;
  565. var
  566. hs : string;
  567. isclassmethod : boolean;
  568. begin
  569. inc(lexlevel);
  570. { read class method }
  571. if token=_CLASS then
  572. begin
  573. consume(_CLASS);
  574. isclassmethod:=true;
  575. end
  576. else
  577. isclassmethod:=false;
  578. case token of
  579. _FUNCTION : begin
  580. consume(_FUNCTION);
  581. parse_proc_head(potype_none);
  582. if token<>_COLON then
  583. begin
  584. if assigned(aktprocsym) and
  585. not(is_interface(aktprocdef._class)) and
  586. not(aktprocdef.forwarddef) or
  587. (m_repeat_forward in aktmodeswitches) then
  588. begin
  589. consume(_COLON);
  590. consume_all_until(_SEMICOLON);
  591. end;
  592. end
  593. else
  594. begin
  595. consume(_COLON);
  596. inc(testcurobject);
  597. single_type(aktprocdef.rettype,hs,false);
  598. aktprocdef.test_if_fpu_result;
  599. dec(testcurobject);
  600. end;
  601. end;
  602. _PROCEDURE : begin
  603. consume(_PROCEDURE);
  604. parse_proc_head(potype_none);
  605. if assigned(aktprocsym) then
  606. aktprocdef.rettype:=voidtype;
  607. end;
  608. _CONSTRUCTOR : begin
  609. consume(_CONSTRUCTOR);
  610. parse_proc_head(potype_constructor);
  611. if assigned(procinfo._class) and
  612. is_class(procinfo._class) then
  613. begin
  614. { CLASS constructors return the created instance }
  615. aktprocdef.rettype.setdef(procinfo._class);
  616. end
  617. else
  618. begin
  619. { OBJECT constructors return a boolean }
  620. aktprocdef.rettype:=booltype;
  621. end;
  622. end;
  623. _DESTRUCTOR : begin
  624. consume(_DESTRUCTOR);
  625. parse_proc_head(potype_destructor);
  626. aktprocdef.rettype:=voidtype;
  627. end;
  628. _OPERATOR : begin
  629. if lexlevel>normal_function_level then
  630. Message(parser_e_no_local_operator);
  631. consume(_OPERATOR);
  632. if (token in [first_overloaded..last_overloaded]) then
  633. begin
  634. procinfo.flags:=procinfo.flags or pi_operator;
  635. optoken:=token;
  636. end
  637. else
  638. begin
  639. Message(parser_e_overload_operator_failed);
  640. { Use the dummy NOTOKEN that is also declared
  641. for the overloaded_operator[] }
  642. optoken:=NOTOKEN;
  643. end;
  644. consume(Token);
  645. parse_proc_head(potype_operator);
  646. if token<>_ID then
  647. begin
  648. otsym:=nil;
  649. if not(m_result in aktmodeswitches) then
  650. consume(_ID);
  651. end
  652. else
  653. begin
  654. otsym:=tvarsym.create(pattern,voidtype);
  655. consume(_ID);
  656. end;
  657. if not try_to_consume(_COLON) then
  658. begin
  659. consume(_COLON);
  660. aktprocdef.rettype:=generrortype;
  661. consume_all_until(_SEMICOLON);
  662. end
  663. else
  664. begin
  665. single_type(aktprocdef.rettype,hs,false);
  666. aktprocdef.test_if_fpu_result;
  667. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  668. ((aktprocdef.rettype.def.deftype<>orddef) or
  669. (torddef(aktprocdef.rettype.def).typ<>bool8bit)) then
  670. Message(parser_e_comparative_operator_return_boolean);
  671. if assigned(otsym) then
  672. otsym.vartype.def:=aktprocdef.rettype.def;
  673. if (optoken=_ASSIGNMENT) and
  674. is_equal(aktprocdef.rettype.def,
  675. tvarsym(aktprocdef.parast.symindex.first).vartype.def) then
  676. message(parser_e_no_such_assignment)
  677. else if not isoperatoracceptable(aktprocdef,optoken) then
  678. Message(parser_e_overload_impossible);
  679. end;
  680. end;
  681. end;
  682. if isclassmethod and
  683. assigned(aktprocsym) then
  684. include(aktprocdef.procoptions,po_classmethod);
  685. { support procedure proc;stdcall export; in Delphi mode only }
  686. if not((m_delphi in aktmodeswitches) and
  687. is_proc_directive(token)) then
  688. consume(_SEMICOLON);
  689. dec(lexlevel);
  690. end;
  691. {****************************************************************************
  692. Procedure directive handlers
  693. ****************************************************************************}
  694. procedure pd_far;
  695. begin
  696. Message(parser_w_proc_far_ignored);
  697. end;
  698. procedure pd_near;
  699. begin
  700. Message(parser_w_proc_near_ignored);
  701. end;
  702. procedure pd_export;
  703. begin
  704. if assigned(procinfo._class) then
  705. Message(parser_e_methods_dont_be_export);
  706. if lexlevel<>normal_function_level then
  707. Message(parser_e_dont_nest_export);
  708. { only os/2 needs this }
  709. if target_info.system=system_i386_os2 then
  710. begin
  711. aktprocdef.aliasnames.insert(aktprocsym.realname);
  712. procinfo.exported:=true;
  713. if cs_link_deffile in aktglobalswitches then
  714. deffile.AddExport(aktprocdef.mangledname);
  715. end;
  716. end;
  717. procedure pd_forward;
  718. begin
  719. aktprocdef.forwarddef:=true;
  720. end;
  721. procedure pd_alias;
  722. begin
  723. consume(_COLON);
  724. aktprocdef.aliasnames.insert(get_stringconst);
  725. end;
  726. procedure pd_asmname;
  727. begin
  728. aktprocdef.setmangledname(target_info.Cprefix+pattern);
  729. aktprocdef.has_mangledname:=true;
  730. if token=_CCHAR then
  731. consume(_CCHAR)
  732. else
  733. consume(_CSTRING);
  734. { we don't need anything else }
  735. aktprocdef.forwarddef:=false;
  736. end;
  737. procedure pd_intern;
  738. begin
  739. consume(_COLON);
  740. aktprocdef.extnumber:=get_intconst;
  741. end;
  742. procedure pd_interrupt;
  743. begin
  744. if lexlevel<>normal_function_level then
  745. Message(parser_e_dont_nest_interrupt);
  746. end;
  747. procedure pd_abstract;
  748. begin
  749. if (po_virtualmethod in aktprocdef.procoptions) then
  750. include(aktprocdef.procoptions,po_abstractmethod)
  751. else
  752. Message(parser_e_only_virtual_methods_abstract);
  753. { the method is defined }
  754. aktprocdef.forwarddef:=false;
  755. end;
  756. procedure pd_virtual;
  757. {$ifdef WITHDMT}
  758. var
  759. pt : tnode;
  760. {$endif WITHDMT}
  761. begin
  762. if (aktprocdef.proctypeoption=potype_constructor) and
  763. is_object(aktprocdef._class) then
  764. Message(parser_e_constructor_cannot_be_not_virtual);
  765. {$ifdef WITHDMT}
  766. if is_object(aktprocdef._class) and
  767. (token<>_SEMICOLON) then
  768. begin
  769. { any type of parameter is allowed here! }
  770. pt:=comp_expr(true);
  771. if is_constintnode(pt) then
  772. begin
  773. include(aktprocdef.procoptions,po_msgint);
  774. aktprocdef.messageinf.i:=pt^.value;
  775. end
  776. else
  777. Message(parser_e_ill_msg_expr);
  778. disposetree(pt);
  779. end;
  780. {$endif WITHDMT}
  781. end;
  782. procedure pd_static;
  783. begin
  784. if (cs_static_keyword in aktmoduleswitches) then
  785. begin
  786. include(aktprocsym.symoptions,sp_static);
  787. include(aktprocdef.procoptions,po_staticmethod);
  788. end;
  789. end;
  790. procedure pd_override;
  791. begin
  792. if not(is_class_or_interface(aktprocdef._class)) then
  793. Message(parser_e_no_object_override);
  794. end;
  795. procedure pd_overload;
  796. begin
  797. include(aktprocsym.symoptions,sp_has_overloaded);
  798. end;
  799. procedure pd_message;
  800. var
  801. pt : tnode;
  802. begin
  803. { check parameter type }
  804. if not(po_containsself in aktprocdef.procoptions) and
  805. ((aktprocdef.minparacount<>1) or
  806. (aktprocdef.maxparacount<>1) or
  807. (TParaItem(aktprocdef.Para.first).paratyp<>vs_var)) then
  808. Message(parser_e_ill_msg_param);
  809. pt:=comp_expr(true);
  810. if pt.nodetype=stringconstn then
  811. begin
  812. include(aktprocdef.procoptions,po_msgstr);
  813. aktprocdef.messageinf.str:=strnew(tstringconstnode(pt).value_str);
  814. end
  815. else
  816. if is_constintnode(pt) then
  817. begin
  818. include(aktprocdef.procoptions,po_msgint);
  819. aktprocdef.messageinf.i:=tordconstnode(pt).value;
  820. end
  821. else
  822. Message(parser_e_ill_msg_expr);
  823. pt.free;
  824. end;
  825. procedure pd_reintroduce;
  826. begin
  827. Message1(parser_w_proc_directive_ignored,'REINTRODUCE');
  828. end;
  829. procedure pd_syscall;
  830. begin
  831. aktprocdef.forwarddef:=false;
  832. aktprocdef.extnumber:=get_intconst;
  833. end;
  834. procedure pd_external;
  835. {
  836. If import_dll=nil the procedure is assumed to be in another
  837. object file. In that object file it should have the name to
  838. which import_name is pointing to. Otherwise, the procedure is
  839. assumed to be in the DLL to which import_dll is pointing to. In
  840. that case either import_nr<>0 or import_name<>nil is true, so
  841. the procedure is either imported by number or by name. (DM)
  842. }
  843. var
  844. import_dll,
  845. import_name : string;
  846. import_nr : word;
  847. begin
  848. aktprocdef.forwarddef:=false;
  849. { forbid local external procedures }
  850. if lexlevel>normal_function_level then
  851. Message(parser_e_no_local_external);
  852. { If the procedure should be imported from a DLL, a constant string follows.
  853. This isn't really correct, an contant string expression follows
  854. so we check if an semicolon follows, else a string constant have to
  855. follow (FK) }
  856. import_nr:=0;
  857. import_name:='';
  858. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  859. begin
  860. import_dll:=get_stringconst;
  861. if (idtoken=_NAME) then
  862. begin
  863. consume(_NAME);
  864. import_name:=get_stringconst;
  865. end;
  866. if (idtoken=_INDEX) then
  867. begin
  868. {After the word index follows the index number in the DLL.}
  869. consume(_INDEX);
  870. import_nr:=get_intconst;
  871. end;
  872. { default is to used the realname of the procedure }
  873. if (import_nr=0) and (import_name='') then
  874. import_name:=aktprocsym.realname;
  875. { create importlib if not already done }
  876. if not(current_module.uses_imports) then
  877. begin
  878. current_module.uses_imports:=true;
  879. importlib.preparelib(current_module.modulename^);
  880. end;
  881. {$ifdef notused}
  882. if not(m_repeat_forward in aktmodeswitches) and
  883. { if the procedure is declared with the overload option }
  884. { it requires a full declaration in the implementation part }
  885. not(sp_has_overloaded in aktprocsym.symoptions) then
  886. begin
  887. { we can only have one overloaded here ! }
  888. if assigned(aktprocdef.defs.next) then
  889. importlib.importprocedure(aktprocdef.defs.next.mangledname,
  890. import_dll,import_nr,import_name)
  891. else
  892. importlib.importprocedure(aktprocdef.mangledname,import_dll,import_nr,import_name);
  893. end
  894. else
  895. {$endif notused}
  896. importlib.importprocedure(aktprocdef.mangledname,import_dll,import_nr,import_name);
  897. end
  898. else
  899. begin
  900. if (idtoken=_NAME) then
  901. begin
  902. consume(_NAME);
  903. import_name:=get_stringconst;
  904. aktprocdef.setmangledname(import_name);
  905. aktprocdef.has_mangledname:=true;
  906. end;
  907. end;
  908. end;
  909. type
  910. pd_handler=procedure;
  911. proc_dir_rec=record
  912. idtok : ttoken;
  913. pd_flags : longint;
  914. handler : pd_handler;
  915. pocall : tproccalloption;
  916. pooption : tprocoptions;
  917. mutexclpocall : tproccalloptions;
  918. mutexclpotype : tproctypeoptions;
  919. mutexclpo : tprocoptions;
  920. end;
  921. const
  922. {Should contain the number of procedure directives we support.}
  923. num_proc_directives=36;
  924. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  925. (
  926. (
  927. idtok:_ABSTRACT;
  928. pd_flags : pd_interface+pd_object+pd_notobjintf;
  929. handler : {$ifdef FPCPROCVAR}@{$endif}pd_abstract;
  930. pocall : pocall_none;
  931. pooption : [po_abstractmethod];
  932. mutexclpocall : [pocall_internproc,pocall_inline];
  933. mutexclpotype : [potype_constructor,potype_destructor];
  934. mutexclpo : [po_exports,po_interrupt,po_external]
  935. ),(
  936. idtok:_ALIAS;
  937. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  938. handler : {$ifdef FPCPROCVAR}@{$endif}pd_alias;
  939. pocall : pocall_none;
  940. pooption : [];
  941. mutexclpocall : [pocall_inline];
  942. mutexclpotype : [];
  943. mutexclpo : [po_external]
  944. ),(
  945. idtok:_ASMNAME;
  946. pd_flags : pd_interface+pd_implemen+pd_notobjintf;
  947. handler : {$ifdef FPCPROCVAR}@{$endif}pd_asmname;
  948. pocall : pocall_cdecl;
  949. pooption : [po_external];
  950. mutexclpocall : [pocall_internproc,pocall_inline];
  951. mutexclpotype : [];
  952. mutexclpo : [po_external]
  953. ),(
  954. idtok:_ASSEMBLER;
  955. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  956. handler : nil;
  957. pocall : pocall_none;
  958. pooption : [po_assembler];
  959. mutexclpocall : [];
  960. mutexclpotype : [];
  961. mutexclpo : [po_external]
  962. ),(
  963. idtok:_CDECL;
  964. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  965. handler : nil;
  966. pocall : pocall_cdecl;
  967. pooption : [];
  968. mutexclpocall : [];
  969. mutexclpotype : [];
  970. mutexclpo : [po_assembler,po_external]
  971. ),(
  972. idtok:_DYNAMIC;
  973. pd_flags : pd_interface+pd_object+pd_notobjintf;
  974. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  975. pocall : pocall_none;
  976. pooption : [po_virtualmethod];
  977. mutexclpocall : [pocall_internproc,pocall_inline];
  978. mutexclpotype : [];
  979. mutexclpo : [po_exports,po_interrupt,po_external]
  980. ),(
  981. idtok:_EXPORT;
  982. pd_flags : pd_body+pd_global+pd_interface+pd_implemen{??}+pd_notobjintf;
  983. handler : {$ifdef FPCPROCVAR}@{$endif}pd_export;
  984. pocall : pocall_none;
  985. pooption : [po_exports];
  986. mutexclpocall : [pocall_internproc,pocall_inline];
  987. mutexclpotype : [];
  988. mutexclpo : [po_external,po_interrupt]
  989. ),(
  990. idtok:_EXTERNAL;
  991. pd_flags : pd_implemen+pd_interface+pd_notobjintf;
  992. handler : {$ifdef FPCPROCVAR}@{$endif}pd_external;
  993. pocall : pocall_none;
  994. pooption : [po_external];
  995. mutexclpocall : [pocall_internproc,pocall_inline,pocall_palmossyscall];
  996. mutexclpotype : [];
  997. mutexclpo : [po_exports,po_interrupt,po_assembler]
  998. ),(
  999. idtok:_FAR;
  1000. pd_flags : pd_implemen+pd_body+pd_interface+pd_procvar+pd_notobjintf;
  1001. handler : {$ifdef FPCPROCVAR}@{$endif}pd_far;
  1002. pocall : pocall_none;
  1003. pooption : [];
  1004. mutexclpocall : [pocall_internproc,pocall_inline];
  1005. mutexclpotype : [];
  1006. mutexclpo : []
  1007. ),(
  1008. idtok:_FAR16;
  1009. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1010. handler : nil;
  1011. pocall : pocall_far16;
  1012. pooption : [];
  1013. mutexclpocall : [];
  1014. mutexclpotype : [];
  1015. mutexclpo : [po_external,po_leftright]
  1016. ),(
  1017. idtok:_FORWARD;
  1018. pd_flags : pd_implemen+pd_notobjintf;
  1019. handler : {$ifdef FPCPROCVAR}@{$endif}pd_forward;
  1020. pocall : pocall_none;
  1021. pooption : [];
  1022. mutexclpocall : [pocall_internproc,pocall_inline];
  1023. mutexclpotype : [];
  1024. mutexclpo : [po_external]
  1025. ),(
  1026. idtok:_FPCCALL;
  1027. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1028. handler : nil;
  1029. pocall : pocall_fpccall;
  1030. pooption : [];
  1031. mutexclpocall : [];
  1032. mutexclpotype : [];
  1033. mutexclpo : [po_leftright]
  1034. ),(
  1035. idtok:_INLINE;
  1036. pd_flags : pd_interface+pd_implemen+pd_body+pd_notobjintf;
  1037. handler : nil;
  1038. pocall : pocall_inline;
  1039. pooption : [];
  1040. mutexclpocall : [];
  1041. mutexclpotype : [potype_constructor,potype_destructor];
  1042. mutexclpo : [po_exports,po_external,po_interrupt]
  1043. ),(
  1044. idtok:_INTERNCONST;
  1045. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1046. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1047. pocall : pocall_none;
  1048. pooption : [po_internconst];
  1049. mutexclpocall : [];
  1050. mutexclpotype : [potype_operator];
  1051. mutexclpo : []
  1052. ),(
  1053. idtok:_INTERNPROC;
  1054. pd_flags : pd_implemen+pd_notobjintf;
  1055. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1056. pocall : pocall_internproc;
  1057. pooption : [];
  1058. mutexclpocall : [];
  1059. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1060. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_leftright]
  1061. ),(
  1062. idtok:_INTERRUPT;
  1063. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1064. handler : {$ifdef FPCPROCVAR}@{$endif}pd_interrupt;
  1065. pocall : pocall_none;
  1066. pooption : [po_interrupt];
  1067. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,
  1068. pocall_inline,pocall_pascal,pocall_system,pocall_far16,pocall_fpccall];
  1069. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1070. mutexclpo : [po_external,po_leftright,po_clearstack]
  1071. ),(
  1072. idtok:_IOCHECK;
  1073. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1074. handler : nil;
  1075. pocall : pocall_none;
  1076. pooption : [po_iocheck];
  1077. mutexclpocall : [pocall_internproc];
  1078. mutexclpotype : [];
  1079. mutexclpo : [po_external]
  1080. ),(
  1081. idtok:_MESSAGE;
  1082. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1083. handler : {$ifdef FPCPROCVAR}@{$endif}pd_message;
  1084. pocall : pocall_none;
  1085. pooption : []; { can be po_msgstr or po_msgint }
  1086. mutexclpocall : [pocall_inline,pocall_internproc];
  1087. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1088. mutexclpo : [po_interrupt,po_external]
  1089. ),(
  1090. idtok:_NEAR;
  1091. pd_flags : pd_implemen+pd_body+pd_procvar+pd_notobjintf;
  1092. handler : {$ifdef FPCPROCVAR}@{$endif}pd_near;
  1093. pocall : pocall_none;
  1094. pooption : [];
  1095. mutexclpocall : [pocall_internproc];
  1096. mutexclpotype : [];
  1097. mutexclpo : []
  1098. ),(
  1099. idtok:_OVERLOAD;
  1100. pd_flags : pd_implemen+pd_interface+pd_body;
  1101. handler : {$ifdef FPCPROCVAR}@{$endif}pd_overload;
  1102. pocall : pocall_none;
  1103. pooption : [po_overload];
  1104. mutexclpocall : [pocall_internproc];
  1105. mutexclpotype : [];
  1106. mutexclpo : []
  1107. ),(
  1108. idtok:_OVERRIDE;
  1109. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1110. handler : {$ifdef FPCPROCVAR}@{$endif}pd_override;
  1111. pocall : pocall_none;
  1112. pooption : [po_overridingmethod,po_virtualmethod];
  1113. mutexclpocall : [pocall_inline,pocall_internproc];
  1114. mutexclpotype : [];
  1115. mutexclpo : [po_exports,po_external,po_interrupt]
  1116. ),(
  1117. idtok:_PASCAL;
  1118. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1119. handler : nil;
  1120. pocall : pocall_pascal;
  1121. pooption : [];
  1122. mutexclpocall : [];
  1123. mutexclpotype : [];
  1124. mutexclpo : [po_external]
  1125. ),(
  1126. idtok:_POPSTACK;
  1127. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1128. handler : nil;
  1129. pocall : pocall_none;
  1130. pooption : [po_clearstack];
  1131. mutexclpocall : [pocall_inline,pocall_internproc,pocall_stdcall];
  1132. mutexclpotype : [];
  1133. mutexclpo : [po_assembler,po_external]
  1134. ),(
  1135. idtok:_PUBLIC;
  1136. pd_flags : pd_implemen+pd_body+pd_global+pd_notobject+pd_notobjintf;
  1137. handler : nil;
  1138. pocall : pocall_none;
  1139. pooption : [];
  1140. mutexclpocall : [pocall_internproc,pocall_inline];
  1141. mutexclpotype : [];
  1142. mutexclpo : [po_external]
  1143. ),(
  1144. idtok:_REGISTER;
  1145. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1146. handler : nil;
  1147. pocall : pocall_register;
  1148. pooption : [];
  1149. mutexclpocall : [];
  1150. mutexclpotype : [];
  1151. mutexclpo : [po_external]
  1152. ),(
  1153. idtok:_REINTRODUCE;
  1154. pd_flags : pd_interface+pd_object;
  1155. handler : {$ifdef FPCPROCVAR}@{$endif}pd_reintroduce;
  1156. pocall : pocall_none;
  1157. pooption : [];
  1158. mutexclpocall : [];
  1159. mutexclpotype : [];
  1160. mutexclpo : []
  1161. ),(
  1162. idtok:_SAFECALL;
  1163. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1164. handler : nil;
  1165. pocall : pocall_safecall;
  1166. pooption : [];
  1167. mutexclpocall : [];
  1168. mutexclpotype : [];
  1169. mutexclpo : [po_external]
  1170. ),(
  1171. idtok:_SAVEREGISTERS;
  1172. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar+pd_notobjintf;
  1173. handler : nil;
  1174. pocall : pocall_none;
  1175. pooption : [po_saveregisters];
  1176. mutexclpocall : [pocall_internproc];
  1177. mutexclpotype : [];
  1178. mutexclpo : [po_external]
  1179. ),(
  1180. idtok:_STATIC;
  1181. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1182. handler : {$ifdef FPCPROCVAR}@{$endif}pd_static;
  1183. pocall : pocall_none;
  1184. pooption : [po_staticmethod];
  1185. mutexclpocall : [pocall_inline,pocall_internproc];
  1186. mutexclpotype : [potype_constructor,potype_destructor];
  1187. mutexclpo : [po_external,po_interrupt,po_exports]
  1188. ),(
  1189. idtok:_STDCALL;
  1190. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1191. handler : nil;
  1192. pocall : pocall_stdcall;
  1193. pooption : [];
  1194. mutexclpocall : [];
  1195. mutexclpotype : [];
  1196. mutexclpo : [po_external]
  1197. ),(
  1198. idtok:_SYSCALL;
  1199. pd_flags : pd_interface+pd_implemen+pd_notobjintf;
  1200. handler : {$ifdef FPCPROCVAR}@{$endif}pd_syscall;
  1201. pocall : pocall_palmossyscall;
  1202. pooption : [];
  1203. mutexclpocall : [];
  1204. mutexclpotype : [];
  1205. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1206. ),(
  1207. idtok:_SYSTEM;
  1208. pd_flags : pd_implemen+pd_notobjintf;
  1209. handler : nil;
  1210. pocall : pocall_system;
  1211. pooption : [];
  1212. mutexclpocall : [];
  1213. mutexclpotype : [];
  1214. mutexclpo : [po_external,po_assembler,po_interrupt]
  1215. ),(
  1216. idtok:_VIRTUAL;
  1217. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1218. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1219. pocall : pocall_none;
  1220. pooption : [po_virtualmethod];
  1221. mutexclpocall : [pocall_inline,pocall_internproc];
  1222. mutexclpotype : [];
  1223. mutexclpo : [po_external,po_interrupt,po_exports]
  1224. ),(
  1225. idtok:_CPPDECL;
  1226. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1227. handler : nil;
  1228. pocall : pocall_cppdecl;
  1229. pooption : [po_savestdregs];
  1230. mutexclpocall : [];
  1231. mutexclpotype : [];
  1232. mutexclpo : [po_assembler,po_external]
  1233. ),(
  1234. idtok:_VARARGS;
  1235. pd_flags : pd_interface+pd_implemen+pd_procvar;
  1236. handler : nil;
  1237. pocall : pocall_none;
  1238. pooption : [po_varargs];
  1239. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1240. pocall_inline,pocall_far16,pocall_fpccall];
  1241. mutexclpotype : [];
  1242. mutexclpo : [po_assembler,po_interrupt,po_leftright]
  1243. ),(
  1244. idtok:_COMPILERPROC;
  1245. pd_flags : pd_interface+pd_implemen+pd_body+pd_notobjintf;
  1246. handler : nil;
  1247. pocall : pocall_compilerproc;
  1248. pooption : [];
  1249. mutexclpocall : [];
  1250. mutexclpotype : [];
  1251. mutexclpo : [po_interrupt]
  1252. )
  1253. );
  1254. function is_proc_directive(tok:ttoken):boolean;
  1255. var
  1256. i : longint;
  1257. begin
  1258. is_proc_directive:=false;
  1259. for i:=1 to num_proc_directives do
  1260. if proc_direcdata[i].idtok=idtoken then
  1261. begin
  1262. is_proc_directive:=true;
  1263. exit;
  1264. end;
  1265. end;
  1266. function parse_proc_direc(var pdflags:word):boolean;
  1267. {
  1268. Parse the procedure directive, returns true if a correct directive is found
  1269. }
  1270. var
  1271. p : longint;
  1272. found : boolean;
  1273. name : stringid;
  1274. begin
  1275. parse_proc_direc:=false;
  1276. name:=tokeninfo^[idtoken].str;
  1277. found:=false;
  1278. { Hint directive? Then exit immediatly }
  1279. if (m_hintdirective in aktmodeswitches) then
  1280. begin
  1281. case idtoken of
  1282. _LIBRARY,
  1283. _PLATFORM,
  1284. _DEPRECATED :
  1285. exit;
  1286. end;
  1287. end;
  1288. { retrieve data for directive if found }
  1289. for p:=1 to num_proc_directives do
  1290. if proc_direcdata[p].idtok=idtoken then
  1291. begin
  1292. found:=true;
  1293. break;
  1294. end;
  1295. { Check if the procedure directive is known }
  1296. if not found then
  1297. begin
  1298. { parsing a procvar type the name can be any
  1299. next variable !! }
  1300. if (pdflags and (pd_procvar or pd_object))=0 then
  1301. Message1(parser_w_unknown_proc_directive_ignored,name);
  1302. exit;
  1303. end;
  1304. { static needs a special treatment }
  1305. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1306. exit;
  1307. { Conflicts between directives ? }
  1308. if (aktprocdef.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1309. (aktprocdef.proccalloption in proc_direcdata[p].mutexclpocall) or
  1310. ((aktprocdef.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1311. begin
  1312. Message1(parser_e_proc_dir_conflict,name);
  1313. exit;
  1314. end;
  1315. { set calling convention }
  1316. if proc_direcdata[p].pocall<>pocall_none then
  1317. begin
  1318. if aktprocdef.proccalloption<>pocall_none then
  1319. begin
  1320. Message2(parser_w_proc_overriding_calling,
  1321. proccalloptionStr[aktprocdef.proccalloption],
  1322. proccalloptionStr[proc_direcdata[p].pocall]);
  1323. end;
  1324. aktprocdef.proccalloption:=proc_direcdata[p].pocall;
  1325. end;
  1326. { check if method and directive not for object, like public.
  1327. This needs to be checked also for procvars }
  1328. if ((proc_direcdata[p].pd_flags and pd_notobject)<>0) and
  1329. (aktprocdef.owner.symtabletype=objectsymtable) then
  1330. exit;
  1331. if aktprocdef.deftype=procdef then
  1332. begin
  1333. { Check if the directive is only for objects }
  1334. if ((proc_direcdata[p].pd_flags and pd_object)<>0) and
  1335. not assigned(aktprocdef._class) then
  1336. exit;
  1337. { check if method and directive not for interface }
  1338. if ((proc_direcdata[p].pd_flags and pd_notobjintf)<>0) and
  1339. is_interface(aktprocdef._class) then
  1340. exit;
  1341. end;
  1342. { consume directive, and turn flag on }
  1343. consume(token);
  1344. parse_proc_direc:=true;
  1345. { Check the pd_flags if the directive should be allowed }
  1346. if ((pdflags and pd_interface)<>0) and
  1347. ((proc_direcdata[p].pd_flags and pd_interface)=0) then
  1348. begin
  1349. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1350. exit;
  1351. end;
  1352. if ((pdflags and pd_implemen)<>0) and
  1353. ((proc_direcdata[p].pd_flags and pd_implemen)=0) then
  1354. begin
  1355. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1356. exit;
  1357. end;
  1358. if ((pdflags and pd_procvar)<>0) and
  1359. ((proc_direcdata[p].pd_flags and pd_procvar)=0) then
  1360. begin
  1361. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1362. exit;
  1363. end;
  1364. { Return the new pd_flags }
  1365. if (proc_direcdata[p].pd_flags and pd_body)=0 then
  1366. pdflags:=pdflags and (not pd_body);
  1367. if (proc_direcdata[p].pd_flags and pd_global)<>0 then
  1368. pdflags:=pdflags or pd_global;
  1369. { Add the correct flag }
  1370. aktprocdef.procoptions:=aktprocdef.procoptions+proc_direcdata[p].pooption;
  1371. { Call the handler }
  1372. if pointer({$ifndef FPCPROCVAR}@{$endif}proc_direcdata[p].handler)<>nil then
  1373. proc_direcdata[p].handler{$ifdef FPCPROCVAR}(){$endif};
  1374. end;
  1375. procedure handle_calling_convention(sym:tprocsym;def:tabstractprocdef);
  1376. begin
  1377. { set the default calling convention }
  1378. if def.proccalloption=pocall_none then
  1379. def.proccalloption:=aktdefproccall;
  1380. case def.proccalloption of
  1381. pocall_cdecl :
  1382. begin
  1383. { use popstack and save std registers }
  1384. include(def.procoptions,po_clearstack);
  1385. include(def.procoptions,po_savestdregs);
  1386. { set mangledname }
  1387. if (def.deftype=procdef) then
  1388. begin
  1389. if not tprocdef(def).has_mangledname then
  1390. begin
  1391. if assigned(tprocdef(def)._class) then
  1392. tprocdef(def).setmangledname(target_info.Cprefix+tprocdef(def)._class.objrealname^+'_'+sym.realname)
  1393. else
  1394. tprocdef(def).setmangledname(target_info.Cprefix+sym.realname);
  1395. end;
  1396. if not assigned(tprocdef(def).parast) then
  1397. internalerror(200110234);
  1398. { do not copy on local !! }
  1399. tprocdef(def).parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}resetvaluepara,nil);
  1400. { Adjust alignment to match cdecl or stdcall }
  1401. tprocdef(def).parast.dataalignment:=std_param_align;
  1402. end;
  1403. end;
  1404. pocall_cppdecl :
  1405. begin
  1406. if not assigned(sym) then
  1407. internalerror(200110231);
  1408. { use popstack and save std registers }
  1409. include(def.procoptions,po_clearstack);
  1410. include(def.procoptions,po_savestdregs);
  1411. { set mangledname }
  1412. if (def.deftype=procdef) then
  1413. begin
  1414. if not tprocdef(def).has_mangledname then
  1415. tprocdef(def).setmangledname(target_info.Cprefix+tprocdef(def).cplusplusmangledname);
  1416. if not assigned(tprocdef(def).parast) then
  1417. internalerror(200110235);
  1418. { do not copy on local !! }
  1419. tprocdef(def).parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}resetvaluepara,nil);
  1420. { Adjust alignment to match cdecl or stdcall }
  1421. tprocdef(def).parast.dataalignment:=std_param_align;
  1422. end;
  1423. end;
  1424. pocall_stdcall :
  1425. begin
  1426. include(def.procoptions,po_savestdregs);
  1427. if (def.deftype=procdef) then
  1428. begin
  1429. if not assigned(tprocdef(def).parast) then
  1430. internalerror(200110236);
  1431. { Adjust alignment to match cdecl or stdcall }
  1432. tprocdef(def).parast.dataalignment:=std_param_align;
  1433. end;
  1434. end;
  1435. pocall_safecall :
  1436. begin
  1437. include(def.procoptions,po_savestdregs);
  1438. end;
  1439. pocall_compilerproc :
  1440. begin
  1441. if (not assigned(sym)) or
  1442. (def.deftype<>procdef) then
  1443. internalerror(200110232);
  1444. tprocdef(def).setmangledname(lower(sym.name));
  1445. end;
  1446. pocall_pascal :
  1447. begin
  1448. include(def.procoptions,po_leftright);
  1449. end;
  1450. pocall_register :
  1451. begin
  1452. Message1(parser_w_proc_directive_ignored,'REGISTER');
  1453. end;
  1454. pocall_far16 :
  1455. begin
  1456. { Temporary stub, must be rewritten to support OS/2 far16 }
  1457. Message1(parser_w_proc_directive_ignored,'FAR16');
  1458. end;
  1459. pocall_system :
  1460. begin
  1461. include(def.procoptions,po_clearstack);
  1462. if (not assigned(sym)) or
  1463. (def.deftype<>procdef) then
  1464. internalerror(200110233);
  1465. if not tprocdef(def).has_mangledname then
  1466. tprocdef(def).setmangledname(sym.realname);
  1467. end;
  1468. pocall_palmossyscall :
  1469. begin
  1470. { use popstack and save std registers }
  1471. include(def.procoptions,po_clearstack);
  1472. include(def.procoptions,po_savestdregs);
  1473. if (def.deftype=procdef) then
  1474. begin
  1475. if not assigned(tprocdef(def).parast) then
  1476. internalerror(200110236);
  1477. { do not copy on local !! }
  1478. tprocdef(def).parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}resetvaluepara,nil);
  1479. { Adjust positions of args for cdecl or stdcall }
  1480. tprocdef(def).parast.dataalignment:=std_param_align;
  1481. end;
  1482. end;
  1483. pocall_inline :
  1484. begin
  1485. if not(cs_support_inline in aktmoduleswitches) then
  1486. begin
  1487. Message(parser_e_proc_inline_not_supported);
  1488. def.proccalloption:=pocall_fpccall;
  1489. end;
  1490. end;
  1491. end;
  1492. { add mangledname to external list }
  1493. if (def.deftype=procdef) and
  1494. (po_external in def.procoptions) and
  1495. target_info.DllScanSupported then
  1496. current_module.externals.insert(tExternalsItem.create(tprocdef(def).mangledname));
  1497. end;
  1498. procedure calc_parasymtable_addresses(def:tprocdef);
  1499. var
  1500. lastps,
  1501. highps,ps : tsym;
  1502. st : tsymtable;
  1503. begin
  1504. st:=def.parast;
  1505. if po_leftright in def.procoptions then
  1506. begin
  1507. { pushed in reversed order, left to right }
  1508. highps:=nil;
  1509. lastps:=nil;
  1510. while assigned(st.symindex.first) and (lastps<>tsym(st.symindex.first)) do
  1511. begin
  1512. ps:=tsym(st.symindex.first);
  1513. while assigned(ps.indexnext) and (tsym(ps.indexnext)<>lastps) do
  1514. ps:=tsym(ps.indexnext);
  1515. if ps.typ=varsym then
  1516. begin
  1517. { Wait with inserting the high value, it needs to be inserted
  1518. after the corresponding parameter }
  1519. if Copy(ps.name,1,4)='high' then
  1520. highps:=ps
  1521. else
  1522. begin
  1523. st.insertvardata(ps);
  1524. { add also the high tree if it was saved }
  1525. if assigned(highps) then
  1526. begin
  1527. st.insertvardata(highps);
  1528. highps:=nil;
  1529. end;
  1530. end;
  1531. end;
  1532. lastps:=ps;
  1533. end;
  1534. if assigned(highps) then
  1535. internalerror(200208257);
  1536. end
  1537. else
  1538. begin
  1539. { pushed in normal order, right to left }
  1540. ps:=tsym(st.symindex.first);
  1541. while assigned(ps) do
  1542. begin
  1543. if ps.typ=varsym then
  1544. st.insertvardata(ps);
  1545. ps:=tsym(ps.indexnext);
  1546. end;
  1547. end;
  1548. end;
  1549. procedure parse_proc_directives(var pdflags:word);
  1550. {
  1551. Parse the procedure directives. It does not matter if procedure directives
  1552. are written using ;procdir; or ['procdir'] syntax.
  1553. }
  1554. var
  1555. res : boolean;
  1556. begin
  1557. while token in [_ID,_LECKKLAMMER] do
  1558. begin
  1559. if try_to_consume(_LECKKLAMMER) then
  1560. begin
  1561. repeat
  1562. parse_proc_direc(pdflags);
  1563. until not try_to_consume(_COMMA);
  1564. consume(_RECKKLAMMER);
  1565. { we always expect at least '[];' }
  1566. res:=true;
  1567. end
  1568. else
  1569. begin
  1570. res:=parse_proc_direc(pdflags);
  1571. end;
  1572. { A procedure directive normally followed by a semicolon, but in
  1573. a const section we should stop when _EQUAL is found }
  1574. if res then
  1575. begin
  1576. if (block_type=bt_const) and
  1577. (token=_EQUAL) then
  1578. break;
  1579. { support procedure proc;stdcall export; in Delphi mode only }
  1580. if not((m_delphi in aktmodeswitches) and
  1581. is_proc_directive(token)) then
  1582. consume(_SEMICOLON);
  1583. end
  1584. else
  1585. break;
  1586. end;
  1587. handle_calling_convention(aktprocsym,aktprocdef);
  1588. { calculate addresses in parasymtable }
  1589. if aktprocdef.deftype=procdef then
  1590. calc_parasymtable_addresses(aktprocdef);
  1591. end;
  1592. procedure parse_var_proc_directives(var sym : tsym);
  1593. var
  1594. pdflags : word;
  1595. oldsym : tprocsym;
  1596. olddef : tprocdef;
  1597. pd : tabstractprocdef;
  1598. begin
  1599. oldsym:=aktprocsym;
  1600. olddef:=aktprocdef;
  1601. pdflags:=pd_procvar;
  1602. { we create a temporary aktprocsym to read the directives }
  1603. aktprocsym:=tprocsym.create(sym.name);
  1604. case sym.typ of
  1605. varsym :
  1606. pd:=tabstractprocdef(tvarsym(sym).vartype.def);
  1607. typedconstsym :
  1608. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  1609. typesym :
  1610. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  1611. else
  1612. internalerror(994932432);
  1613. end;
  1614. if pd.deftype<>procvardef then
  1615. internalerror(994932433);
  1616. tabstractprocdef(aktprocdef):=pd;
  1617. { names should never be used anyway }
  1618. inc(lexlevel);
  1619. parse_proc_directives(pdflags);
  1620. dec(lexlevel);
  1621. aktprocsym.free;
  1622. aktprocsym:=oldsym;
  1623. aktprocdef:=olddef;
  1624. end;
  1625. procedure parse_object_proc_directives(var sym : tprocsym);
  1626. var
  1627. pdflags : word;
  1628. begin
  1629. pdflags:=pd_object;
  1630. inc(lexlevel);
  1631. parse_proc_directives(pdflags);
  1632. dec(lexlevel);
  1633. if (po_containsself in aktprocdef.procoptions) and
  1634. (([po_msgstr,po_msgint]*aktprocdef.procoptions)=[]) then
  1635. Message(parser_e_self_in_non_message_handler);
  1636. end;
  1637. function proc_add_definition(aprocsym:tprocsym;var aprocdef : tprocdef) : boolean;
  1638. {
  1639. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  1640. forwarddef is found and reused it returns true
  1641. }
  1642. var
  1643. hd : tprocdef;
  1644. ad,fd : tsym;
  1645. forwardfound : boolean;
  1646. i : cardinal;
  1647. begin
  1648. forwardfound:=false;
  1649. { check overloaded functions if the same function already exists }
  1650. for i:=1 to aprocsym.procdef_count do
  1651. begin
  1652. hd:=aprocsym.procdef[i];
  1653. { Skip overloaded definitions that are declared in other
  1654. units }
  1655. if hd.procsym<>aprocsym then
  1656. continue;
  1657. { check the parameters, for delphi/tp it is possible to
  1658. leave the parameters away in the implementation (forwarddef=false).
  1659. But for an overload declared function this is not allowed }
  1660. if { check if empty implementation arguments match is allowed }
  1661. (
  1662. not(m_repeat_forward in aktmodeswitches) and
  1663. not(aprocdef.forwarddef) and
  1664. (aprocdef.maxparacount=0) and
  1665. not(po_overload in hd.procoptions)
  1666. ) or
  1667. { check arguments }
  1668. (
  1669. equal_paras(aprocdef.para,hd.para,cp_none,false) and
  1670. { for operators equal_paras is not enough !! }
  1671. ((aprocdef.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1672. is_equal(hd.rettype.def,aprocdef.rettype.def))
  1673. ) then
  1674. begin
  1675. { Check if we've found the forwarddef, if found then
  1676. we need to update the forward def with the current
  1677. implementation settings }
  1678. if hd.forwarddef then
  1679. begin
  1680. forwardfound:=true;
  1681. { Check if the procedure type and return type are correct,
  1682. also the parameters must match also with the type }
  1683. if (hd.proctypeoption<>aprocdef.proctypeoption) or
  1684. (
  1685. (m_repeat_forward in aktmodeswitches) and
  1686. (not((aprocdef.maxparacount=0) or
  1687. equal_paras(aprocdef.para,hd.para,cp_all,false)))
  1688. ) or
  1689. (
  1690. ((m_repeat_forward in aktmodeswitches) or
  1691. not(is_void(aprocdef.rettype.def))) and
  1692. (not is_equal(hd.rettype.def,aprocdef.rettype.def))) then
  1693. begin
  1694. MessagePos1(aprocdef.fileinfo,parser_e_header_dont_match_forward,
  1695. aprocdef.fullprocname);
  1696. break;
  1697. end;
  1698. { Check if both are declared forward }
  1699. if hd.forwarddef and aprocdef.forwarddef then
  1700. begin
  1701. MessagePos1(aprocdef.fileinfo,parser_e_function_already_declared_public_forward,
  1702. aprocdef.fullprocname);
  1703. end;
  1704. { internconst or internproc only need to be defined once }
  1705. if (hd.proccalloption=pocall_internproc) then
  1706. aprocdef.proccalloption:=hd.proccalloption
  1707. else
  1708. if (aprocdef.proccalloption=pocall_internproc) then
  1709. hd.proccalloption:=aprocdef.proccalloption;
  1710. if (po_internconst in hd.procoptions) then
  1711. include(aprocdef.procoptions,po_internconst)
  1712. else if (po_internconst in aprocdef.procoptions) then
  1713. include(hd.procoptions,po_internconst);
  1714. { Check calling convention }
  1715. if (hd.proccalloption<>aprocdef.proccalloption) then
  1716. begin
  1717. { For delphi check if the current implementation has no proccalloption, then
  1718. take the options from the interface }
  1719. if not(m_delphi in aktmodeswitches) or
  1720. (aprocdef.proccalloption<>pocall_none) then
  1721. MessagePos(aprocdef.fileinfo,parser_e_call_convention_dont_match_forward);
  1722. { restore interface settings }
  1723. aprocdef.proccalloption:=hd.proccalloption;
  1724. aprocdef.has_mangledname:=hd.has_mangledname;
  1725. if hd.has_mangledname then
  1726. aprocdef.setmangledname(hd.mangledname);
  1727. end;
  1728. { Check manglednames }
  1729. if (m_repeat_forward in aktmodeswitches) or
  1730. aprocdef.haspara then
  1731. begin
  1732. { If mangled names are equal then they have the same amount of arguments }
  1733. { We can check the names of the arguments }
  1734. { both symtables are in the same order from left to right }
  1735. ad:=tsym(hd.parast.symindex.first);
  1736. fd:=tsym(aprocdef.parast.symindex.first);
  1737. repeat
  1738. { skip default parameter constsyms }
  1739. while assigned(ad) and (ad.typ<>varsym) do
  1740. ad:=tsym(ad.indexnext);
  1741. while assigned(fd) and (fd.typ<>varsym) do
  1742. fd:=tsym(fd.indexnext);
  1743. { stop when one of the two lists is at the end }
  1744. if not assigned(ad) or not assigned(fd) then
  1745. break;
  1746. if (ad.name<>fd.name) then
  1747. begin
  1748. MessagePos3(aprocdef.fileinfo,parser_e_header_different_var_names,
  1749. aprocsym.name,ad.name,fd.name);
  1750. break;
  1751. end;
  1752. ad:=tsym(ad.indexnext);
  1753. fd:=tsym(fd.indexnext);
  1754. until false;
  1755. if assigned(ad) or assigned(fd) then
  1756. internalerror(200204178);
  1757. end;
  1758. { Everything is checked, now we can update the forward declaration
  1759. with the new data from the implementation }
  1760. hd.forwarddef:=aprocdef.forwarddef;
  1761. hd.hasforward:=true;
  1762. hd.parast.address_fixup:=aprocdef.parast.address_fixup;
  1763. hd.procoptions:=hd.procoptions+aprocdef.procoptions;
  1764. if hd.extnumber=65535 then
  1765. hd.extnumber:=aprocdef.extnumber;
  1766. while not aprocdef.aliasnames.empty do
  1767. hd.aliasnames.insert(aprocdef.aliasnames.getfirst);
  1768. { update mangledname if the implementation has a fixed mangledname set }
  1769. if aprocdef.has_mangledname then
  1770. begin
  1771. { rename also asmsymbol first, because the name can already be used }
  1772. objectlibrary.renameasmsymbol(hd.mangledname,aprocdef.mangledname);
  1773. { update the mangledname }
  1774. hd.has_mangledname:=true;
  1775. hd.setmangledname(aprocdef.mangledname);
  1776. end;
  1777. { for compilerproc defines we need to rename and update the
  1778. symbolname to lowercase }
  1779. if (aprocdef.proccalloption=pocall_compilerproc) then
  1780. begin
  1781. { rename to lowercase so users can't access it }
  1782. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  1783. { also update the realname that is stored in the ppu }
  1784. stringdispose(aprocsym._realname);
  1785. aprocsym._realname:=stringdup('$'+aprocsym.name);
  1786. { the mangeled name is already changed by the pd_compilerproc }
  1787. { handler. It must be done immediately because if we have a }
  1788. { call to a compilerproc before it's implementation is }
  1789. { encountered, it must already use the new mangled name (JM) }
  1790. end;
  1791. { return the forwarddef }
  1792. aprocdef:=hd;
  1793. end
  1794. else
  1795. begin
  1796. { abstract methods aren't forward defined, but this }
  1797. { needs another error message }
  1798. if (po_abstractmethod in hd.procoptions) then
  1799. MessagePos(aprocdef.fileinfo,parser_e_abstract_no_definition)
  1800. else
  1801. MessagePos(aprocdef.fileinfo,parser_e_overloaded_have_same_parameters);
  1802. end;
  1803. { we found one proc with the same arguments, there are no others
  1804. so we can stop }
  1805. break;
  1806. end;
  1807. { check for allowing overload directive }
  1808. if not(m_fpc in aktmodeswitches) then
  1809. begin
  1810. { overload directive turns on overloading }
  1811. if ((po_overload in aprocdef.procoptions) or
  1812. (po_overload in hd.procoptions)) then
  1813. begin
  1814. { check if all procs have overloading, but not if the proc was
  1815. already declared forward, then the check is already done }
  1816. if not(hd.hasforward or
  1817. (aprocdef.forwarddef<>hd.forwarddef) or
  1818. ((po_overload in aprocdef.procoptions) and
  1819. (po_overload in hd.procoptions))) then
  1820. begin
  1821. MessagePos1(aprocdef.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  1822. break;
  1823. end;
  1824. end
  1825. else
  1826. begin
  1827. if not(hd.forwarddef) then
  1828. begin
  1829. MessagePos(aprocdef.fileinfo,parser_e_procedure_overloading_is_off);
  1830. break;
  1831. end;
  1832. end;
  1833. end; { equal arguments }
  1834. end;
  1835. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  1836. list }
  1837. if not forwardfound then
  1838. begin
  1839. aprocsym.addprocdef(aprocdef);
  1840. { add overloadnumber for unique naming, the overloadcount is
  1841. counted per module and 0 for the first procedure }
  1842. aprocdef.overloadnumber:=aprocsym.overloadcount;
  1843. inc(aprocsym.overloadcount);
  1844. end;
  1845. { insert otsym only in the right symtable }
  1846. if ((procinfo.flags and pi_operator)<>0) and
  1847. assigned(otsym) then
  1848. begin
  1849. if not parse_only then
  1850. begin
  1851. if paramanager.ret_in_param(aprocdef.rettype.def) then
  1852. begin
  1853. aprocdef.parast.insert(otsym);
  1854. { this allows to read the funcretoffset }
  1855. otsym.address:=-4;
  1856. otsym.varspez:=vs_var;
  1857. end
  1858. else
  1859. begin
  1860. aprocdef.localst.insert(otsym);
  1861. aprocdef.localst.insertvardata(otsym);
  1862. end;
  1863. end
  1864. else
  1865. begin
  1866. { this is not required anymore }
  1867. otsym.free;
  1868. otsym:=nil;
  1869. end;
  1870. end;
  1871. paramanager.create_param_loc_info(aprocdef);
  1872. proc_add_definition:=forwardfound;
  1873. end;
  1874. end.
  1875. {
  1876. $Log$
  1877. Revision 1.77 2002-10-06 15:09:12 peter
  1878. * variant:=nil supported
  1879. Revision 1.76 2002/09/27 21:13:29 carl
  1880. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  1881. Revision 1.75 2002/09/16 14:11:13 peter
  1882. * add argument to equal_paras() to support default values or not
  1883. Revision 1.74 2002/09/10 16:27:28 peter
  1884. * don't insert parast in symtablestack, because typesyms should not be
  1885. searched in the the parast
  1886. Revision 1.73 2002/09/09 19:39:07 peter
  1887. * check return type for forwarddefs also not delphi mode when
  1888. the type is not void
  1889. Revision 1.72 2002/09/09 17:34:15 peter
  1890. * tdicationary.replace added to replace and item in a dictionary. This
  1891. is only allowed for the same name
  1892. * varsyms are inserted in symtable before the types are parsed. This
  1893. fixes the long standing "var longint : longint" bug
  1894. - consume_idlist and idstringlist removed. The loops are inserted
  1895. at the callers place and uses the symtable for duplicate id checking
  1896. Revision 1.71 2002/09/07 15:25:06 peter
  1897. * old logs removed and tabs fixed
  1898. Revision 1.70 2002/09/03 16:26:27 daniel
  1899. * Make Tprocdef.defs protected
  1900. Revision 1.69 2002/09/01 12:11:33 peter
  1901. * calc param_offset after parameters are read, because the calculation
  1902. depends on po_containself
  1903. Revision 1.68 2002/08/25 19:25:20 peter
  1904. * sym.insert_in_data removed
  1905. * symtable.insertvardata/insertconstdata added
  1906. * removed insert_in_data call from symtable.insert, it needs to be
  1907. called separatly. This allows to deref the address calculation
  1908. * procedures now calculate the parast addresses after the procedure
  1909. directives are parsed. This fixes the cdecl parast problem
  1910. * push_addr_param has an extra argument that specifies if cdecl is used
  1911. or not
  1912. Revision 1.67 2002/08/25 11:33:06 peter
  1913. * also check the paratypes when a forward was found
  1914. Revision 1.66 2002/08/19 19:36:44 peter
  1915. * More fixes for cross unit inlining, all tnodes are now implemented
  1916. * Moved pocall_internconst to po_internconst because it is not a
  1917. calling type at all and it conflicted when inlining of these small
  1918. functions was requested
  1919. Revision 1.65 2002/08/18 20:06:24 peter
  1920. * inlining is now also allowed in interface
  1921. * renamed write/load to ppuwrite/ppuload
  1922. * tnode storing in ppu
  1923. * nld,ncon,nbas are already updated for storing in ppu
  1924. Revision 1.64 2002/08/17 09:23:39 florian
  1925. * first part of procinfo rewrite
  1926. Revision 1.63 2002/08/11 14:32:27 peter
  1927. * renamed current_library to objectlibrary
  1928. Revision 1.62 2002/08/11 13:24:12 peter
  1929. * saving of asmsymbols in ppu supported
  1930. * asmsymbollist global is removed and moved into a new class
  1931. tasmlibrarydata that will hold the info of a .a file which
  1932. corresponds with a single module. Added librarydata to tmodule
  1933. to keep the library info stored for the module. In the future the
  1934. objectfiles will also be stored to the tasmlibrarydata class
  1935. * all getlabel/newasmsymbol and friends are moved to the new class
  1936. Revision 1.61 2002/07/26 21:15:40 florian
  1937. * rewrote the system handling
  1938. Revision 1.60 2002/07/20 11:57:55 florian
  1939. * types.pas renamed to defbase.pas because D6 contains a types
  1940. unit so this would conflicts if D6 programms are compiled
  1941. + Willamette/SSE2 instructions to assembler added
  1942. Revision 1.59 2002/07/11 14:41:28 florian
  1943. * start of the new generic parameter handling
  1944. Revision 1.58 2002/07/01 18:46:25 peter
  1945. * internal linker
  1946. * reorganized aasm layer
  1947. Revision 1.57 2002/05/18 13:34:12 peter
  1948. * readded missing revisions
  1949. Revision 1.56 2002/05/16 19:46:42 carl
  1950. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1951. + try to fix temp allocation (still in ifdef)
  1952. + generic constructor calls
  1953. + start of tassembler / tmodulebase class cleanup
  1954. Revision 1.54 2002/05/12 16:53:08 peter
  1955. * moved entry and exitcode to ncgutil and cgobj
  1956. * foreach gets extra argument for passing local data to the
  1957. iterator function
  1958. * -CR checks also class typecasts at runtime by changing them
  1959. into as
  1960. * fixed compiler to cycle with the -CR option
  1961. * fixed stabs with elf writer, finally the global variables can
  1962. be watched
  1963. * removed a lot of routines from cga unit and replaced them by
  1964. calls to cgobj
  1965. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1966. u32bit then the other is typecasted also to u32bit without giving
  1967. a rangecheck warning/error.
  1968. * fixed pascal calling method with reversing also the high tree in
  1969. the parast, detected by tcalcst3 test
  1970. Revision 1.53 2002/04/21 19:02:04 peter
  1971. * removed newn and disposen nodes, the code is now directly
  1972. inlined from pexpr
  1973. * -an option that will write the secondpass nodes to the .s file, this
  1974. requires EXTDEBUG define to actually write the info
  1975. * fixed various internal errors and crashes due recent code changes
  1976. Revision 1.52 2002/04/20 21:32:24 carl
  1977. + generic FPC_CHECKPOINTER
  1978. + first parameter offset in stack now portable
  1979. * rename some constants
  1980. + move some cpu stuff to other units
  1981. - remove unused constents
  1982. * fix stacksize for some targets
  1983. * fix generic size problems which depend now on EXTEND_SIZE constant
  1984. Revision 1.51 2002/04/20 15:27:05 carl
  1985. - remove ifdef i386 define
  1986. Revision 1.50 2002/04/19 15:46:02 peter
  1987. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  1988. in most cases and not written to the ppu
  1989. * add mangeledname_prefix() routine to generate the prefix of
  1990. manglednames depending on the current procedure, object and module
  1991. * removed static procprefix since the mangledname is now build only
  1992. on demand from tprocdef.mangledname
  1993. }