pdecsub.pas 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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 defines.inc}
  20. interface
  21. uses
  22. cobjects,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. function check_identical_proc(var p : pprocdef) : boolean;
  34. procedure parameter_dec(aktprocdef:pabstractprocdef);
  35. procedure parse_proc_directives(var pdflags:word);
  36. procedure parse_proc_head(options:tproctypeoption);
  37. procedure parse_proc_dec;
  38. procedure parse_var_proc_directives(var sym : psym);
  39. procedure parse_object_proc_directives(var sym : pprocsym);
  40. implementation
  41. uses
  42. {$ifdef delphi}
  43. sysutils,
  44. {$else delphi}
  45. strings,
  46. {$endif delphi}
  47. { common }
  48. cutils,
  49. { global }
  50. globtype,globals,verbose,
  51. systems,
  52. { aasm }
  53. aasm,
  54. { symtable }
  55. symbase,symtable,types,
  56. { pass 1 }
  57. node,pass_1,htypechk,
  58. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  59. { parser }
  60. fmodule,scanner,
  61. pbase,pexpr,ptype,pdecl,
  62. { linking }
  63. import,gendef,
  64. { codegen }
  65. {$ifdef newcg}
  66. cgbase
  67. {$else}
  68. hcodegen
  69. {$endif}
  70. ;
  71. procedure parameter_dec(aktprocdef:pabstractprocdef);
  72. {
  73. handle_procvar needs the same changes
  74. }
  75. var
  76. is_procvar : boolean;
  77. sc : tidstringlist;
  78. s : string;
  79. hpos,
  80. storetokenpos : tfileposinfo;
  81. tt : ttype;
  82. hvs,
  83. vs : Pvarsym;
  84. hs1,hs2 : string;
  85. varspez : Tvarspez;
  86. inserthigh : boolean;
  87. pdefaultvalue : pconstsym;
  88. defaultrequired : boolean;
  89. begin
  90. { reset }
  91. defaultrequired:=false;
  92. { parsing a proc or procvar ? }
  93. is_procvar:=(aktprocdef^.deftype=procvardef);
  94. consume(_LKLAMMER);
  95. inc(testcurobject);
  96. repeat
  97. if try_to_consume(_VAR) then
  98. varspez:=vs_var
  99. else
  100. if try_to_consume(_CONST) then
  101. varspez:=vs_const
  102. else
  103. if try_to_consume(_OUT) then
  104. varspez:=vs_out
  105. else
  106. varspez:=vs_value;
  107. inserthigh:=false;
  108. pdefaultvalue:=nil;
  109. tt.reset;
  110. { self is only allowed in procvars and class methods }
  111. if (idtoken=_SELF) and
  112. (is_procvar or
  113. (assigned(procinfo^._class) and is_class(procinfo^._class))) then
  114. begin
  115. if not is_procvar then
  116. begin
  117. {$ifndef UseNiceNames}
  118. hs2:=hs2+'$'+'self';
  119. {$else UseNiceNames}
  120. hs2:=hs2+tostr(length('self'))+'self';
  121. {$endif UseNiceNames}
  122. vs:=new(Pvarsym,initdef('@',procinfo^._class));
  123. vs^.varspez:=vs_var;
  124. { insert the sym in the parasymtable }
  125. pprocdef(aktprocdef)^.parast^.insert(vs);
  126. include(aktprocdef^.procoptions,po_containsself);
  127. inc(procinfo^.selfpointer_offset,vs^.address);
  128. end;
  129. consume(idtoken);
  130. consume(_COLON);
  131. single_type(tt,hs1,false);
  132. aktprocdef^.concatpara(tt,vs_value,nil);
  133. { check the types for procedures only }
  134. if not is_procvar then
  135. CheckTypes(tt.def,procinfo^._class);
  136. end
  137. else
  138. begin
  139. { read identifiers }
  140. sc:=idlist;
  141. {$ifdef fixLeaksOnError}
  142. strContStack.push(sc);
  143. {$endif fixLeaksOnError}
  144. { read type declaration, force reading for value and const paras }
  145. if (token=_COLON) or (varspez=vs_value) then
  146. begin
  147. consume(_COLON);
  148. { check for an open array }
  149. if token=_ARRAY then
  150. begin
  151. consume(_ARRAY);
  152. consume(_OF);
  153. { define range and type of range }
  154. tt.setdef(new(Parraydef,init(0,-1,s32bitdef)));
  155. { array of const ? }
  156. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  157. begin
  158. consume(_CONST);
  159. srsym:=nil;
  160. getsymonlyin(systemunit,'TVARREC');
  161. if not assigned(srsym) then
  162. InternalError(1234124);
  163. Parraydef(tt.def)^.elementtype:=ptypesym(srsym)^.restype;
  164. Parraydef(tt.def)^.IsArrayOfConst:=true;
  165. hs1:='array_of_const';
  166. end
  167. else
  168. begin
  169. { define field type }
  170. single_type(parraydef(tt.def)^.elementtype,hs1,false);
  171. hs1:='array_of_'+hs1;
  172. end;
  173. inserthigh:=true;
  174. end
  175. else
  176. begin
  177. { open string ? }
  178. if (varspez=vs_var) and
  179. (
  180. (
  181. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  182. (cs_openstring in aktmoduleswitches) and
  183. not(cs_ansistrings in aktlocalswitches)
  184. ) or
  185. (idtoken=_OPENSTRING)) then
  186. begin
  187. consume(token);
  188. tt.setdef(openshortstringdef);
  189. hs1:='openstring';
  190. inserthigh:=true;
  191. end
  192. else
  193. begin
  194. { everything else }
  195. single_type(tt,hs1,false);
  196. end;
  197. { default parameter }
  198. if (m_default_para in aktmodeswitches) then
  199. begin
  200. if try_to_consume(_EQUAL) then
  201. begin
  202. s:=sc.get(hpos);
  203. if not sc.empty then
  204. Comment(V_Error,'default value only allowed for one parameter');
  205. sc.add(s,hpos);
  206. { prefix 'def' to the parameter name }
  207. pdefaultvalue:=ReadConstant('$def'+Upper(s),hpos);
  208. if assigned(pdefaultvalue) then
  209. pprocdef(aktprocdef)^.parast^.insert(pdefaultvalue);
  210. defaultrequired:=true;
  211. end
  212. else
  213. begin
  214. if defaultrequired then
  215. Comment(V_Error,'default parameter required');
  216. end;
  217. end;
  218. end;
  219. end
  220. else
  221. begin
  222. {$ifndef UseNiceNames}
  223. hs1:='$$$';
  224. {$else UseNiceNames}
  225. hs1:='var';
  226. {$endif UseNiceNames}
  227. tt.setdef(cformaldef);
  228. end;
  229. if not is_procvar then
  230. hs2:=pprocdef(aktprocdef)^.mangledname;
  231. storetokenpos:=akttokenpos;
  232. while not sc.empty do
  233. begin
  234. s:=sc.get(akttokenpos);
  235. aktprocdef^.concatpara(tt,varspez,pdefaultvalue);
  236. { For proc vars we only need the definitions }
  237. if not is_procvar then
  238. begin
  239. {$ifndef UseNiceNames}
  240. hs2:=hs2+'$'+hs1;
  241. {$else UseNiceNames}
  242. hs2:=hs2+tostr(length(hs1))+hs1;
  243. {$endif UseNiceNames}
  244. vs:=new(pvarsym,init(s,tt));
  245. vs^.varspez:=varspez;
  246. { we have to add this to avoid var param to be in registers !!!}
  247. { I don't understand the comment above, }
  248. { but I suppose the comment is wrong and }
  249. { it means that the address of var parameters can be placed }
  250. { in a register (FK) }
  251. if (varspez in [vs_var,vs_const,vs_out]) and push_addr_param(tt.def) then
  252. include(vs^.varoptions,vo_regable);
  253. { insert the sym in the parasymtable }
  254. pprocdef(aktprocdef)^.parast^.insert(vs);
  255. { do we need a local copy? Then rename the varsym, do this after the
  256. insert so the dup id checking is done correctly }
  257. if (varspez=vs_value) and
  258. push_addr_param(tt.def) and
  259. not(is_open_array(tt.def) or is_array_of_const(tt.def)) then
  260. pprocdef(aktprocdef)^.parast^.rename(vs^.name,'val'+vs^.name);
  261. { also need to push a high value? }
  262. if inserthigh then
  263. begin
  264. hvs:=new(Pvarsym,initdef('$high'+Upper(s),s32bitdef));
  265. hvs^.varspez:=vs_const;
  266. pprocdef(aktprocdef)^.parast^.insert(hvs);
  267. end;
  268. end;
  269. end;
  270. {$ifdef fixLeaksOnError}
  271. if PStringContainer(strContStack.pop) <> sc then
  272. writeln('problem with strContStack in pdecl (1)');
  273. {$endif fixLeaksOnError}
  274. sc.free;
  275. akttokenpos:=storetokenpos;
  276. end;
  277. { set the new mangled name }
  278. if not is_procvar then
  279. pprocdef(aktprocdef)^.setmangledname(hs2);
  280. until not try_to_consume(_SEMICOLON);
  281. dec(testcurobject);
  282. consume(_RKLAMMER);
  283. end;
  284. procedure parse_proc_head(options:tproctypeoption);
  285. var orgsp,sp:stringid;
  286. pd:Pprocdef;
  287. paramoffset:longint;
  288. sym:Psym;
  289. hs:string;
  290. st : psymtable;
  291. overloaded_level:word;
  292. storepos,procstartfilepos : tfileposinfo;
  293. i: longint;
  294. begin
  295. { Save the position where this procedure really starts and set col to 1 which
  296. looks nicer }
  297. procstartfilepos:=akttokenpos;
  298. { procstartfilepos.column:=1; I do not agree here !!
  299. lets keep excat position PM }
  300. if (options=potype_operator) then
  301. begin
  302. sp:=overloaded_names[optoken];
  303. orgsp:=sp;
  304. end
  305. else
  306. begin
  307. sp:=pattern;
  308. orgsp:=orgpattern;
  309. consume(_ID);
  310. end;
  311. { examine interface map: function/procedure iname.functionname=locfuncname }
  312. if parse_only and assigned(procinfo^._class) and
  313. assigned(procinfo^._class^.implementedinterfaces) and
  314. (procinfo^._class^.implementedinterfaces^.count>0) and
  315. try_to_consume(_POINT) then
  316. begin
  317. storepos:=akttokenpos;
  318. akttokenpos:=procstartfilepos;
  319. { get interface syms}
  320. getsym(sp,true);
  321. sym:=srsym;
  322. akttokenpos:=storepos;
  323. { load proc name }
  324. sp:=pattern;
  325. if sym^.typ=typesym then
  326. i:=procinfo^._class^.implementedinterfaces^.searchintf(ptypesym(sym)^.restype.def);
  327. { qualifier is interface name? }
  328. if (sym^.typ<>typesym) or (ptypesym(sym)^.restype.def^.deftype<>objectdef) or
  329. (i=-1) then
  330. begin
  331. Message(parser_e_interface_id_expected);
  332. aktprocsym:=nil;
  333. end
  334. else
  335. begin
  336. aktprocsym:=pprocsym(procinfo^._class^.implementedinterfaces^.interfaces(i)^.symtable^.search(sp));
  337. if not(assigned(aktprocsym)) then
  338. Message(parser_e_methode_id_expected);
  339. end;
  340. consume(_ID);
  341. consume(_EQUAL);
  342. if (token=_ID) and assigned(aktprocsym) then
  343. procinfo^._class^.implementedinterfaces^.addmappings(i,sp,pattern);
  344. consume(_ID);
  345. exit;
  346. end;
  347. { method ? }
  348. if not(parse_only) and
  349. (lexlevel=normal_function_level) and
  350. try_to_consume(_POINT) then
  351. begin
  352. storepos:=akttokenpos;
  353. akttokenpos:=procstartfilepos;
  354. getsym(sp,true);
  355. sym:=srsym;
  356. akttokenpos:=storepos;
  357. { load proc name }
  358. sp:=pattern;
  359. orgsp:=orgpattern;
  360. procstartfilepos:=akttokenpos;
  361. { qualifier is class name ? }
  362. if (sym^.typ<>typesym) or
  363. (ptypesym(sym)^.restype.def^.deftype<>objectdef) then
  364. begin
  365. Message(parser_e_class_id_expected);
  366. aktprocsym:=nil;
  367. consume(_ID);
  368. end
  369. else
  370. begin
  371. { used to allow private syms to be seen }
  372. aktobjectdef:=pobjectdef(ptypesym(sym)^.restype.def);
  373. procinfo^._class:=pobjectdef(ptypesym(sym)^.restype.def);
  374. aktprocsym:=pprocsym(procinfo^._class^.symtable^.search(sp));
  375. consume(_ID);
  376. {The procedure has been found. So it is
  377. a global one. Set the flags to mark this.}
  378. procinfo^.flags:=procinfo^.flags or pi_is_global;
  379. aktobjectdef:=nil;
  380. { we solve this below }
  381. if not(assigned(aktprocsym)) then
  382. Message(parser_e_methode_id_expected);
  383. end;
  384. end
  385. else
  386. begin
  387. { check for constructor/destructor which is not allowed here }
  388. if (not parse_only) and
  389. (options in [potype_constructor,potype_destructor]) then
  390. Message(parser_e_constructors_always_objects);
  391. akttokenpos:=procstartfilepos;
  392. aktprocsym:=pprocsym(symtablestack^.search(sp));
  393. if not(parse_only) then
  394. begin
  395. {The procedure we prepare for is in the implementation
  396. part of the unit we compile. It is also possible that we
  397. are compiling a program, which is also some kind of
  398. implementaion part.
  399. We need to find out if the procedure is global. If it is
  400. global, it is in the global symtable.}
  401. if not assigned(aktprocsym) and
  402. (symtablestack^.symtabletype=staticsymtable) then
  403. begin
  404. {Search the procedure in the global symtable.}
  405. aktprocsym:=Pprocsym(search_a_symtable(sp,globalsymtable));
  406. if assigned(aktprocsym) then
  407. begin
  408. {Check if it is a procedure.}
  409. if aktprocsym^.typ<>procsym then
  410. DuplicateSym(aktprocsym);
  411. {The procedure has been found. So it is
  412. a global one. Set the flags to mark this.}
  413. procinfo^.flags:=procinfo^.flags or pi_is_global;
  414. end;
  415. end;
  416. end;
  417. end;
  418. { Create the mangledname }
  419. {$ifndef UseNiceNames}
  420. if assigned(procinfo^._class) then
  421. begin
  422. if (pos('_$$_',procprefix)=0) then
  423. hs:=procprefix+'_$$_'+upper(procinfo^._class^.objname^)+'_$$_'+sp
  424. else
  425. hs:=procprefix+'_$'+sp;
  426. end
  427. else
  428. begin
  429. if lexlevel=normal_function_level then
  430. hs:=procprefix+'_'+sp
  431. else
  432. hs:=procprefix+'_$'+sp;
  433. end;
  434. {$else UseNiceNames}
  435. if assigned(procinfo^._class) then
  436. begin
  437. if (pos('_5Class_',procprefix)=0) then
  438. hs:=procprefix+'_5Class_'+procinfo^._class^.name^+'_'+tostr(length(sp))+sp
  439. else
  440. hs:=procprefix+'_'+tostr(length(sp))+sp;
  441. end
  442. else
  443. begin
  444. if lexlevel=normal_function_level then
  445. hs:=procprefix+'_'+tostr(length(sp))+sp
  446. else
  447. hs:=lowercase(procprefix)+'_'+tostr(length(sp))+sp;
  448. end;
  449. {$endif UseNiceNames}
  450. if assigned(aktprocsym) then
  451. begin
  452. { Check if overloaded is a procsym, we use a different error message
  453. for tp7 so it looks more compatible }
  454. if aktprocsym^.typ<>procsym then
  455. begin
  456. if (m_fpc in aktmodeswitches) then
  457. Message1(parser_e_overloaded_no_procedure,aktprocsym^.realname)
  458. else
  459. DuplicateSym(aktprocsym);
  460. { try to recover by creating a new aktprocsym }
  461. akttokenpos:=procstartfilepos;
  462. aktprocsym:=new(pprocsym,init(orgsp));
  463. end;
  464. end
  465. else
  466. begin
  467. { create a new procsym and set the real filepos }
  468. akttokenpos:=procstartfilepos;
  469. { for operator we have only one definition for each overloaded
  470. operation }
  471. if (options=potype_operator) then
  472. begin
  473. { create the procsym with saving the original case }
  474. aktprocsym:=new(pprocsym,init('$'+sp));
  475. { the only problem is that nextoverloaded might not be in a unit
  476. known for the unit itself }
  477. { not anymore PM }
  478. if assigned(overloaded_operators[optoken]) then
  479. aktprocsym^.definition:=overloaded_operators[optoken]^.definition;
  480. {$ifndef DONOTCHAINOPERATORS}
  481. overloaded_operators[optoken]:=aktprocsym;
  482. {$endif DONOTCHAINOPERATORS}
  483. end
  484. else
  485. aktprocsym:=new(pprocsym,init(orgsp));
  486. symtablestack^.insert(aktprocsym);
  487. end;
  488. st:=symtablestack;
  489. pd:=new(pprocdef,init);
  490. pd^.symtablelevel:=symtablestack^.symtablelevel;
  491. if assigned(procinfo^._class) then
  492. pd^._class := procinfo^._class;
  493. { set the options from the caller (podestructor or poconstructor) }
  494. pd^.proctypeoption:=options;
  495. { calculate the offset of the parameters }
  496. paramoffset:=8;
  497. { calculate frame pointer offset }
  498. if lexlevel>normal_function_level then
  499. begin
  500. procinfo^.framepointer_offset:=paramoffset;
  501. inc(paramoffset,target_os.size_of_pointer);
  502. { this is needed to get correct framepointer push for local
  503. forward functions !! }
  504. pd^.parast^.symtablelevel:=lexlevel;
  505. end;
  506. if assigned (procinfo^._Class) and
  507. is_object(procinfo^._Class) and
  508. (pd^.proctypeoption in [potype_constructor,potype_destructor]) then
  509. inc(paramoffset,target_os.size_of_pointer);
  510. { self pointer offset }
  511. { self isn't pushed in nested procedure of methods }
  512. if assigned(procinfo^._class) and (lexlevel=normal_function_level) then
  513. begin
  514. procinfo^.selfpointer_offset:=paramoffset;
  515. if assigned(aktprocsym^.definition) and
  516. not(po_containsself in aktprocsym^.definition^.procoptions) then
  517. inc(paramoffset,target_os.size_of_pointer);
  518. end;
  519. { con/-destructor flag ? }
  520. if assigned (procinfo^._Class) and
  521. is_class(procinfo^._class) and
  522. (pd^.proctypeoption in [potype_destructor,potype_constructor]) then
  523. inc(paramoffset,target_os.size_of_pointer);
  524. procinfo^.para_offset:=paramoffset;
  525. pd^.parast^.datasize:=0;
  526. pd^.nextoverloaded:=aktprocsym^.definition;
  527. aktprocsym^.definition:=pd;
  528. { this is probably obsolete now PM }
  529. aktprocsym^.definition^.fileinfo:=procstartfilepos;
  530. aktprocsym^.definition^.setmangledname(hs);
  531. aktprocsym^.definition^.procsym:=aktprocsym;
  532. if not parse_only then
  533. begin
  534. overloaded_level:=0;
  535. { we need another procprefix !!! }
  536. { count, but only those in the same unit !!}
  537. while assigned(pd) and
  538. (pd^.owner^.symtabletype in [globalsymtable,staticsymtable]) do
  539. begin
  540. { only count already implemented functions }
  541. if not(pd^.forwarddef) then
  542. inc(overloaded_level);
  543. pd:=pd^.nextoverloaded;
  544. end;
  545. if overloaded_level>0 then
  546. procprefix:=hs+'$'+tostr(overloaded_level)+'$'
  547. else
  548. procprefix:=hs+'$';
  549. end;
  550. { this must also be inserted in the right symtable !! PM }
  551. { otherwise we get subbtle problems with
  552. definitions of args defs in staticsymtable for
  553. implementation of a global method }
  554. if token=_LKLAMMER then
  555. parameter_dec(aktprocsym^.definition);
  556. { so we only restore the symtable now }
  557. symtablestack:=st;
  558. if (options=potype_operator) then
  559. overloaded_operators[optoken]:=aktprocsym;
  560. end;
  561. procedure parse_proc_dec;
  562. var
  563. hs : string;
  564. isclassmethod : boolean;
  565. begin
  566. inc(lexlevel);
  567. { read class method }
  568. if token=_CLASS then
  569. begin
  570. consume(_CLASS);
  571. isclassmethod:=true;
  572. end
  573. else
  574. isclassmethod:=false;
  575. case token of
  576. _FUNCTION : begin
  577. consume(_FUNCTION);
  578. parse_proc_head(potype_none);
  579. if token<>_COLON then
  580. begin
  581. if not(is_interface(aktprocsym^.definition^._class)) and
  582. not(aktprocsym^.definition^.forwarddef) or
  583. (m_repeat_forward in aktmodeswitches) then
  584. begin
  585. consume(_COLON);
  586. consume_all_until(_SEMICOLON);
  587. end;
  588. end
  589. else
  590. begin
  591. consume(_COLON);
  592. inc(testcurobject);
  593. single_type(aktprocsym^.definition^.rettype,hs,false);
  594. aktprocsym^.definition^.test_if_fpu_result;
  595. dec(testcurobject);
  596. end;
  597. end;
  598. _PROCEDURE : begin
  599. consume(_PROCEDURE);
  600. parse_proc_head(potype_none);
  601. aktprocsym^.definition^.rettype.def:=voiddef;
  602. end;
  603. _CONSTRUCTOR : begin
  604. consume(_CONSTRUCTOR);
  605. parse_proc_head(potype_constructor);
  606. if assigned(procinfo^._class) and
  607. is_class(procinfo^._class) then
  608. begin
  609. { CLASS constructors return the created instance }
  610. aktprocsym^.definition^.rettype.def:=procinfo^._class;
  611. end
  612. else
  613. begin
  614. { OBJECT constructors return a boolean }
  615. {$IfDef GDB}
  616. { GDB doesn't like unnamed types !}
  617. aktprocsym^.definition^.rettype.def:=globaldef('boolean');
  618. {$else GDB}
  619. aktprocsym^.definition^.rettype.def:=new(porddef,init(bool8bit,0,1));
  620. {$Endif GDB}
  621. end;
  622. end;
  623. _DESTRUCTOR : begin
  624. consume(_DESTRUCTOR);
  625. parse_proc_head(potype_destructor);
  626. aktprocsym^.definition^.rettype.def:=voiddef;
  627. end;
  628. _OPERATOR : begin
  629. if lexlevel>normal_function_level then
  630. Message(parser_e_no_local_operator);
  631. consume(_OPERATOR);
  632. if not(token in [_PLUS..last_overloaded]) then
  633. Message(parser_e_overload_operator_failed);
  634. optoken:=token;
  635. consume(Token);
  636. procinfo^.flags:=procinfo^.flags or pi_operator;
  637. parse_proc_head(potype_operator);
  638. if token<>_ID then
  639. begin
  640. opsym:=nil;
  641. if not(m_result in aktmodeswitches) then
  642. consume(_ID);
  643. end
  644. else
  645. begin
  646. opsym:=new(pvarsym,initdef(pattern,voiddef));
  647. consume(_ID);
  648. end;
  649. if not try_to_consume(_COLON) then
  650. begin
  651. consume(_COLON);
  652. aktprocsym^.definition^.rettype.def:=generrordef;
  653. consume_all_until(_SEMICOLON);
  654. end
  655. else
  656. begin
  657. single_type(aktprocsym^.definition^.rettype,hs,false);
  658. aktprocsym^.definition^.test_if_fpu_result;
  659. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  660. ((aktprocsym^.definition^.rettype.def^.deftype<>
  661. orddef) or (porddef(aktprocsym^.definition^.
  662. rettype.def)^.typ<>bool8bit)) then
  663. Message(parser_e_comparative_operator_return_boolean);
  664. if assigned(opsym) then
  665. opsym^.vartype.def:=aktprocsym^.definition^.rettype.def;
  666. { We need to add the return type in the mangledname
  667. to allow overloading with just different results !! (PM) }
  668. aktprocsym^.definition^.setmangledname(
  669. aktprocsym^.definition^.mangledname+'$$'+hs);
  670. if (optoken=_ASSIGNMENT) and
  671. is_equal(aktprocsym^.definition^.rettype.def,
  672. pvarsym(aktprocsym^.definition^.parast^.symindex^.first)^.vartype.def) then
  673. message(parser_e_no_such_assignment)
  674. else if not isoperatoracceptable(aktprocsym^.definition,optoken) then
  675. Message(parser_e_overload_impossible);
  676. end;
  677. end;
  678. end;
  679. if isclassmethod and
  680. assigned(aktprocsym) then
  681. include(aktprocsym^.definition^.procoptions,po_classmethod);
  682. { support procedure proc;stdcall export; in Delphi mode only }
  683. if not((m_delphi in aktmodeswitches) and
  684. is_proc_directive(token)) then
  685. consume(_SEMICOLON);
  686. dec(lexlevel);
  687. end;
  688. {****************************************************************************
  689. Procedure directive handlers
  690. ****************************************************************************}
  691. procedure pd_far;
  692. begin
  693. Message(parser_w_proc_far_ignored);
  694. end;
  695. procedure pd_near;
  696. begin
  697. Message(parser_w_proc_near_ignored);
  698. end;
  699. procedure pd_export;
  700. begin
  701. if assigned(procinfo^._class) then
  702. Message(parser_e_methods_dont_be_export);
  703. if lexlevel<>normal_function_level then
  704. Message(parser_e_dont_nest_export);
  705. { only os/2 needs this }
  706. if target_info.target=target_i386_os2 then
  707. begin
  708. aktprocsym^.definition^.aliasnames.insert(aktprocsym^.realname);
  709. procinfo^.exported:=true;
  710. if cs_link_deffile in aktglobalswitches then
  711. deffile.AddExport(aktprocsym^.definition^.mangledname);
  712. end;
  713. end;
  714. procedure pd_inline;
  715. begin
  716. if not(cs_support_inline in aktmoduleswitches) then
  717. Message(parser_e_proc_inline_not_supported);
  718. end;
  719. procedure pd_forward;
  720. begin
  721. aktprocsym^.definition^.forwarddef:=true;
  722. end;
  723. procedure pd_stdcall;
  724. begin
  725. end;
  726. procedure pd_safecall;
  727. begin
  728. end;
  729. procedure pd_alias;
  730. begin
  731. consume(_COLON);
  732. aktprocsym^.definition^.aliasnames.insert(get_stringconst);
  733. end;
  734. procedure pd_asmname;
  735. begin
  736. aktprocsym^.definition^.setmangledname(target_os.Cprefix+pattern);
  737. if token=_CCHAR then
  738. consume(_CCHAR)
  739. else
  740. consume(_CSTRING);
  741. { we don't need anything else }
  742. aktprocsym^.definition^.forwarddef:=false;
  743. end;
  744. procedure pd_intern;
  745. begin
  746. consume(_COLON);
  747. aktprocsym^.definition^.extnumber:=get_intconst;
  748. end;
  749. procedure pd_interrupt;
  750. begin
  751. {$ifndef i386}
  752. Message(parser_w_proc_interrupt_ignored);
  753. {$else i386}
  754. if lexlevel<>normal_function_level then
  755. Message(parser_e_dont_nest_interrupt);
  756. {$endif i386}
  757. end;
  758. procedure pd_system;
  759. begin
  760. aktprocsym^.definition^.setmangledname(aktprocsym^.realname);
  761. end;
  762. procedure pd_abstract;
  763. begin
  764. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  765. include(aktprocsym^.definition^.procoptions,po_abstractmethod)
  766. else
  767. Message(parser_e_only_virtual_methods_abstract);
  768. { the method is defined }
  769. aktprocsym^.definition^.forwarddef:=false;
  770. end;
  771. procedure pd_virtual;
  772. {$ifdef WITHDMT}
  773. var
  774. pt : tnode;
  775. {$endif WITHDMT}
  776. begin
  777. if (aktprocsym^.definition^.proctypeoption=potype_constructor) and
  778. is_object(aktprocsym^.definition^._class) then
  779. Message(parser_e_constructor_cannot_be_not_virtual);
  780. {$ifdef WITHDMT}
  781. if is_object(aktprocsym^.definition^._class) and
  782. (token<>_SEMICOLON) then
  783. begin
  784. { any type of parameter is allowed here! }
  785. pt:=comp_expr(true);
  786. do_firstpass(pt);
  787. if is_constintnode(pt) then
  788. begin
  789. include(aktprocsym^.definition^.procoptions,po_msgint);
  790. aktprocsym^.definition^.messageinf.i:=pt^.value;
  791. end
  792. else
  793. Message(parser_e_ill_msg_expr);
  794. disposetree(pt);
  795. end;
  796. {$endif WITHDMT}
  797. end;
  798. procedure pd_static;
  799. begin
  800. if (cs_static_keyword in aktmoduleswitches) then
  801. begin
  802. include(aktprocsym^.symoptions,sp_static);
  803. include(aktprocsym^.definition^.procoptions,po_staticmethod);
  804. end;
  805. end;
  806. procedure pd_override;
  807. begin
  808. if not(is_class_or_interface(aktprocsym^.definition^._class)) then
  809. Message(parser_e_no_object_override);
  810. end;
  811. procedure pd_overload;
  812. begin
  813. end;
  814. procedure pd_message;
  815. var
  816. pt : tnode;
  817. begin
  818. { check parameter type }
  819. if not(po_containsself in aktprocsym^.definition^.procoptions) and
  820. ((aktprocsym^.definition^.minparacount<>1) or
  821. (aktprocsym^.definition^.maxparacount<>1) or
  822. (TParaItem(aktprocsym^.definition^.Para.first).paratyp<>vs_var)) then
  823. Message(parser_e_ill_msg_param);
  824. pt:=comp_expr(true);
  825. do_firstpass(pt);
  826. if pt.nodetype=stringconstn then
  827. begin
  828. include(aktprocsym^.definition^.procoptions,po_msgstr);
  829. aktprocsym^.definition^.messageinf.str:=strnew(tstringconstnode(pt).value_str);
  830. end
  831. else
  832. if is_constintnode(pt) then
  833. begin
  834. include(aktprocsym^.definition^.procoptions,po_msgint);
  835. aktprocsym^.definition^.messageinf.i:=tordconstnode(pt).value;
  836. end
  837. else
  838. Message(parser_e_ill_msg_expr);
  839. pt.free;
  840. end;
  841. procedure resetvaluepara(p:pnamedindexobject);
  842. begin
  843. if psym(p)^.typ=varsym then
  844. with pvarsym(p)^ do
  845. if copy(name,1,3)='val' then
  846. aktprocsym^.definition^.parast^.symsearch^.rename(name,copy(name,4,length(name)));
  847. end;
  848. procedure pd_cdecl;
  849. begin
  850. if aktprocsym^.definition^.deftype<>procvardef then
  851. aktprocsym^.definition^.setmangledname(target_os.Cprefix+aktprocsym^.realname);
  852. { do not copy on local !! }
  853. if (aktprocsym^.definition^.deftype=procdef) and
  854. assigned(aktprocsym^.definition^.parast) then
  855. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}resetvaluepara);
  856. end;
  857. procedure pd_cppdecl;
  858. begin
  859. if aktprocsym^.definition^.deftype<>procvardef then
  860. aktprocsym^.definition^.setmangledname(
  861. target_os.Cprefix+aktprocsym^.definition^.cplusplusmangledname);
  862. { do not copy on local !! }
  863. if (aktprocsym^.definition^.deftype=procdef) and
  864. assigned(aktprocsym^.definition^.parast) then
  865. aktprocsym^.definition^.parast^.foreach({$ifdef FPCPROCVAR}@{$endif}resetvaluepara);
  866. end;
  867. procedure pd_pascal;
  868. var st,parast : psymtable;
  869. lastps,ps : psym;
  870. begin
  871. new(st,init(parasymtable));
  872. parast:=aktprocsym^.definition^.parast;
  873. lastps:=nil;
  874. while assigned(parast^.symindex^.first) and (lastps<>psym(parast^.symindex^.first)) do
  875. begin
  876. ps:=psym(parast^.symindex^.first);
  877. while assigned(ps^.indexnext) and (psym(ps^.indexnext)<>lastps) do
  878. ps:=psym(ps^.indexnext);
  879. ps^.owner:=st;
  880. { recalculate the corrected offset }
  881. { the really_insert_in_data procedure
  882. for parasymtable should only calculateoffset PM }
  883. pstoredsym(ps)^.insert_in_data;
  884. { reset the owner correctly }
  885. ps^.owner:=parast;
  886. lastps:=ps;
  887. end;
  888. end;
  889. procedure pd_register;
  890. begin
  891. Message1(parser_w_proc_directive_ignored,'REGISTER');
  892. end;
  893. procedure pd_reintroduce;
  894. begin
  895. Message1(parser_w_proc_directive_ignored,'REINTRODUCE');
  896. end;
  897. procedure pd_syscall;
  898. begin
  899. aktprocsym^.definition^.forwarddef:=false;
  900. aktprocsym^.definition^.extnumber:=get_intconst;
  901. end;
  902. procedure pd_external;
  903. {
  904. If import_dll=nil the procedure is assumed to be in another
  905. object file. In that object file it should have the name to
  906. which import_name is pointing to. Otherwise, the procedure is
  907. assumed to be in the DLL to which import_dll is pointing to. In
  908. that case either import_nr<>0 or import_name<>nil is true, so
  909. the procedure is either imported by number or by name. (DM)
  910. }
  911. var
  912. import_dll,
  913. import_name : string;
  914. import_nr : word;
  915. begin
  916. aktprocsym^.definition^.forwarddef:=false;
  917. { If the procedure should be imported from a DLL, a constant string follows.
  918. This isn't really correct, an contant string expression follows
  919. so we check if an semicolon follows, else a string constant have to
  920. follow (FK) }
  921. import_nr:=0;
  922. import_name:='';
  923. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  924. begin
  925. import_dll:=get_stringconst;
  926. if (idtoken=_NAME) then
  927. begin
  928. consume(_NAME);
  929. import_name:=get_stringconst;
  930. end;
  931. if (idtoken=_INDEX) then
  932. begin
  933. {After the word index follows the index number in the DLL.}
  934. consume(_INDEX);
  935. import_nr:=get_intconst;
  936. end;
  937. if (import_nr=0) and (import_name='') then
  938. {if (aktprocsym^.definition^.options and pocdecl)<>0 then
  939. import_name:=aktprocsym^.definition^.mangledname
  940. else
  941. Message(parser_w_empty_import_name);}
  942. { this should work both for win32 and Linux !! PM }
  943. import_name:=aktprocsym^.realname;
  944. if not(current_module.uses_imports) then
  945. begin
  946. current_module.uses_imports:=true;
  947. importlib.preparelib(current_module.modulename^);
  948. end;
  949. if not(m_repeat_forward in aktmodeswitches) then
  950. begin
  951. { we can only have one overloaded here ! }
  952. if assigned(aktprocsym^.definition^.nextoverloaded) then
  953. importlib.importprocedure(aktprocsym^.definition^.nextoverloaded^.mangledname,
  954. import_dll,import_nr,import_name)
  955. else
  956. importlib.importprocedure(aktprocsym^.mangledname,import_dll,import_nr,import_name);
  957. end
  958. else
  959. importlib.importprocedure(aktprocsym^.mangledname,import_dll,import_nr,import_name);
  960. end
  961. else
  962. begin
  963. if (idtoken=_NAME) then
  964. begin
  965. consume(_NAME);
  966. import_name:=get_stringconst;
  967. aktprocsym^.definition^.setmangledname(import_name);
  968. end
  969. else
  970. begin
  971. { external shouldn't override the cdecl/system name }
  972. if not (pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  973. aktprocsym^.definition^.setmangledname(aktprocsym^.realname);
  974. end;
  975. end;
  976. end;
  977. type
  978. pd_handler=procedure;
  979. proc_dir_rec=record
  980. idtok : ttoken;
  981. pd_flags : longint;
  982. handler : pd_handler;
  983. pocall : tproccalloptions;
  984. pooption : tprocoptions;
  985. mutexclpocall : tproccalloptions;
  986. mutexclpotype : tproctypeoptions;
  987. mutexclpo : tprocoptions;
  988. end;
  989. const
  990. {Should contain the number of procedure directives we support.}
  991. num_proc_directives=32;
  992. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  993. (
  994. (
  995. idtok:_ABSTRACT;
  996. pd_flags : pd_interface+pd_object+pd_notobjintf;
  997. handler : {$ifdef FPCPROCVAR}@{$endif}pd_abstract;
  998. pocall : [];
  999. pooption : [po_abstractmethod];
  1000. mutexclpocall : [pocall_internproc,pocall_inline];
  1001. mutexclpotype : [potype_constructor,potype_destructor];
  1002. mutexclpo : [po_exports,po_interrupt,po_external]
  1003. ),(
  1004. idtok:_ALIAS;
  1005. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1006. handler : {$ifdef FPCPROCVAR}@{$endif}pd_alias;
  1007. pocall : [];
  1008. pooption : [];
  1009. mutexclpocall : [pocall_inline];
  1010. mutexclpotype : [];
  1011. mutexclpo : [po_external]
  1012. ),(
  1013. idtok:_ASMNAME;
  1014. pd_flags : pd_interface+pd_implemen+pd_notobjintf;
  1015. handler : {$ifdef FPCPROCVAR}@{$endif}pd_asmname;
  1016. pocall : [pocall_cdecl,pocall_clearstack];
  1017. pooption : [po_external];
  1018. mutexclpocall : [pocall_internproc];
  1019. mutexclpotype : [];
  1020. mutexclpo : [po_external]
  1021. ),(
  1022. idtok:_ASSEMBLER;
  1023. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1024. handler : nil;
  1025. pocall : [];
  1026. pooption : [po_assembler];
  1027. mutexclpocall : [];
  1028. mutexclpotype : [];
  1029. mutexclpo : [po_external]
  1030. ),(
  1031. idtok:_CDECL;
  1032. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1033. handler : {$ifdef FPCPROCVAR}@{$endif}pd_cdecl;
  1034. pocall : [pocall_cdecl,pocall_clearstack];
  1035. pooption : [po_savestdregs];
  1036. mutexclpocall : [pocall_cppdecl,pocall_internproc,
  1037. pocall_leftright,pocall_inline];
  1038. mutexclpotype : [];
  1039. mutexclpo : [po_assembler,po_external]
  1040. ),(
  1041. idtok:_DYNAMIC;
  1042. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1043. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1044. pocall : [];
  1045. pooption : [po_virtualmethod];
  1046. mutexclpocall : [pocall_internproc,pocall_inline];
  1047. mutexclpotype : [];
  1048. mutexclpo : [po_exports,po_interrupt,po_external]
  1049. ),(
  1050. idtok:_EXPORT;
  1051. pd_flags : pd_body+pd_global+pd_interface+pd_implemen{??}+pd_notobjintf;
  1052. handler : {$ifdef FPCPROCVAR}@{$endif}pd_export;
  1053. pocall : [];
  1054. pooption : [po_exports];
  1055. mutexclpocall : [pocall_internproc,pocall_inline];
  1056. mutexclpotype : [];
  1057. mutexclpo : [po_external,po_interrupt]
  1058. ),(
  1059. idtok:_EXTERNAL;
  1060. pd_flags : pd_implemen+pd_interface+pd_notobjintf;
  1061. handler : {$ifdef FPCPROCVAR}@{$endif}pd_external;
  1062. pocall : [];
  1063. pooption : [po_external];
  1064. mutexclpocall : [pocall_internproc,pocall_inline,pocall_palmossyscall];
  1065. mutexclpotype : [];
  1066. mutexclpo : [po_exports,po_interrupt,po_assembler]
  1067. ),(
  1068. idtok:_FAR;
  1069. pd_flags : pd_implemen+pd_body+pd_interface+pd_procvar+pd_notobjintf;
  1070. handler : {$ifdef FPCPROCVAR}@{$endif}pd_far;
  1071. pocall : [];
  1072. pooption : [];
  1073. mutexclpocall : [pocall_internproc,pocall_inline];
  1074. mutexclpotype : [];
  1075. mutexclpo : []
  1076. ),(
  1077. idtok:_FORWARD;
  1078. pd_flags : pd_implemen+pd_notobjintf;
  1079. handler : {$ifdef FPCPROCVAR}@{$endif}pd_forward;
  1080. pocall : [];
  1081. pooption : [];
  1082. mutexclpocall : [pocall_internproc,pocall_inline];
  1083. mutexclpotype : [];
  1084. mutexclpo : [po_external]
  1085. ),(
  1086. idtok:_INLINE;
  1087. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1088. handler : {$ifdef FPCPROCVAR}@{$endif}pd_inline;
  1089. pocall : [pocall_inline];
  1090. pooption : [];
  1091. mutexclpocall : [pocall_internproc];
  1092. mutexclpotype : [potype_constructor,potype_destructor];
  1093. mutexclpo : [po_exports,po_external,po_interrupt]
  1094. ),(
  1095. idtok:_INTERNCONST;
  1096. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1097. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1098. pocall : [pocall_internconst];
  1099. pooption : [];
  1100. mutexclpocall : [];
  1101. mutexclpotype : [potype_operator];
  1102. mutexclpo : []
  1103. ),(
  1104. idtok:_INTERNPROC;
  1105. pd_flags : pd_implemen+pd_notobjintf;
  1106. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1107. pocall : [pocall_internproc];
  1108. pooption : [];
  1109. mutexclpocall : [pocall_inline,pocall_clearstack,pocall_leftright,pocall_cdecl,pocall_cppdecl];
  1110. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1111. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck]
  1112. ),(
  1113. idtok:_INTERRUPT;
  1114. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1115. handler : {$ifdef FPCPROCVAR}@{$endif}pd_interrupt;
  1116. pocall : [];
  1117. pooption : [po_interrupt];
  1118. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,
  1119. pocall_clearstack,pocall_leftright,pocall_inline];
  1120. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1121. mutexclpo : [po_external]
  1122. ),(
  1123. idtok:_IOCHECK;
  1124. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1125. handler : nil;
  1126. pocall : [];
  1127. pooption : [po_iocheck];
  1128. mutexclpocall : [pocall_internproc];
  1129. mutexclpotype : [];
  1130. mutexclpo : [po_external]
  1131. ),(
  1132. idtok:_MESSAGE;
  1133. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1134. handler : {$ifdef FPCPROCVAR}@{$endif}pd_message;
  1135. pocall : [];
  1136. pooption : []; { can be po_msgstr or po_msgint }
  1137. mutexclpocall : [pocall_inline,pocall_internproc];
  1138. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1139. mutexclpo : [po_interrupt,po_external]
  1140. ),(
  1141. idtok:_NEAR;
  1142. pd_flags : pd_implemen+pd_body+pd_procvar+pd_notobjintf;
  1143. handler : {$ifdef FPCPROCVAR}@{$endif}pd_near;
  1144. pocall : [];
  1145. pooption : [];
  1146. mutexclpocall : [pocall_internproc];
  1147. mutexclpotype : [];
  1148. mutexclpo : []
  1149. ),(
  1150. idtok:_OVERLOAD;
  1151. pd_flags : pd_implemen+pd_interface+pd_body;
  1152. handler : {$ifdef FPCPROCVAR}@{$endif}pd_overload;
  1153. pocall : [];
  1154. pooption : [po_overload];
  1155. mutexclpocall : [pocall_internproc];
  1156. mutexclpotype : [];
  1157. mutexclpo : []
  1158. ),(
  1159. idtok:_OVERRIDE;
  1160. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1161. handler : {$ifdef FPCPROCVAR}@{$endif}pd_override;
  1162. pocall : [];
  1163. pooption : [po_overridingmethod,po_virtualmethod];
  1164. mutexclpocall : [pocall_inline,pocall_internproc];
  1165. mutexclpotype : [];
  1166. mutexclpo : [po_exports,po_external,po_interrupt]
  1167. ),(
  1168. idtok:_PASCAL;
  1169. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1170. handler : {$ifdef FPCPROCVAR}@{$endif}pd_pascal;
  1171. pocall : [pocall_leftright];
  1172. pooption : [];
  1173. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,
  1174. pocall_clearstack,pocall_leftright,pocall_inline,
  1175. pocall_safecall];
  1176. mutexclpotype : [];
  1177. mutexclpo : [po_external]
  1178. ),(
  1179. idtok:_POPSTACK;
  1180. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1181. handler : nil;
  1182. pocall : [pocall_clearstack];
  1183. pooption : [];
  1184. mutexclpocall : [pocall_inline,pocall_internproc];
  1185. mutexclpotype : [];
  1186. mutexclpo : [po_assembler,po_external]
  1187. ),(
  1188. idtok:_PUBLIC;
  1189. pd_flags : pd_implemen+pd_body+pd_global+pd_notobject+pd_notobjintf;
  1190. handler : nil;
  1191. pocall : [];
  1192. pooption : [];
  1193. mutexclpocall : [pocall_internproc,pocall_inline];
  1194. mutexclpotype : [];
  1195. mutexclpo : [po_external]
  1196. ),(
  1197. idtok:_REGISTER;
  1198. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1199. handler : {$ifdef FPCPROCVAR}@{$endif}pd_register;
  1200. pocall : [pocall_register];
  1201. pooption : [];
  1202. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_internproc,pocall_cppdecl];
  1203. mutexclpotype : [];
  1204. mutexclpo : [po_external]
  1205. ),(
  1206. idtok:_REINTRODUCE;
  1207. pd_flags : pd_interface+pd_object;
  1208. handler : {$ifdef FPCPROCVAR}@{$endif}pd_reintroduce;
  1209. pocall : [];
  1210. pooption : [];
  1211. mutexclpocall : [];
  1212. mutexclpotype : [];
  1213. mutexclpo : []
  1214. ),(
  1215. idtok:_SAFECALL;
  1216. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1217. handler : {$ifdef FPCPROCVAR}@{$endif}pd_safecall;
  1218. pocall : [pocall_safecall];
  1219. pooption : [po_savestdregs];
  1220. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_cppdecl,
  1221. pocall_internproc,pocall_inline];
  1222. mutexclpotype : [];
  1223. mutexclpo : [po_external]
  1224. ),(
  1225. idtok:_SAVEREGISTERS;
  1226. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar+pd_notobjintf;
  1227. handler : nil;
  1228. pocall : [];
  1229. pooption : [po_saveregisters];
  1230. mutexclpocall : [pocall_internproc];
  1231. mutexclpotype : [];
  1232. mutexclpo : [po_external]
  1233. ),(
  1234. idtok:_STATIC;
  1235. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1236. handler : {$ifdef FPCPROCVAR}@{$endif}pd_static;
  1237. pocall : [];
  1238. pooption : [po_staticmethod];
  1239. mutexclpocall : [pocall_inline,pocall_internproc];
  1240. mutexclpotype : [potype_constructor,potype_destructor];
  1241. mutexclpo : [po_external,po_interrupt,po_exports]
  1242. ),(
  1243. idtok:_STDCALL;
  1244. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1245. handler : {$ifdef FPCPROCVAR}@{$endif}pd_stdcall;
  1246. pocall : [pocall_stdcall];
  1247. pooption : [po_savestdregs];
  1248. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_cppdecl,
  1249. pocall_inline,pocall_internproc,pocall_safecall];
  1250. mutexclpotype : [];
  1251. mutexclpo : [po_external]
  1252. ),(
  1253. idtok:_SYSCALL;
  1254. pd_flags : pd_interface+pd_notobjintf;
  1255. handler : {$ifdef FPCPROCVAR}@{$endif}pd_syscall;
  1256. pocall : [pocall_palmossyscall];
  1257. pooption : [];
  1258. mutexclpocall : [pocall_cdecl,pocall_cppdecl,pocall_inline,
  1259. pocall_internproc,pocall_leftright];
  1260. mutexclpotype : [];
  1261. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1262. ),(
  1263. idtok:_SYSTEM;
  1264. pd_flags : pd_implemen+pd_notobjintf;
  1265. handler : {$ifdef FPCPROCVAR}@{$endif}pd_system;
  1266. pocall : [pocall_clearstack];
  1267. pooption : [];
  1268. mutexclpocall : [pocall_leftright,pocall_inline,pocall_cdecl,
  1269. pocall_internproc,pocall_cppdecl];
  1270. mutexclpotype : [];
  1271. mutexclpo : [po_external,po_assembler,po_interrupt]
  1272. ),(
  1273. idtok:_VIRTUAL;
  1274. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1275. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1276. pocall : [];
  1277. pooption : [po_virtualmethod];
  1278. mutexclpocall : [pocall_inline,pocall_internproc];
  1279. mutexclpotype : [];
  1280. mutexclpo : [po_external,po_interrupt,po_exports]
  1281. ),(
  1282. idtok:_CPPDECL;
  1283. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1284. handler : {$ifdef FPCPROCVAR}@{$endif}pd_cppdecl;
  1285. pocall : [pocall_cppdecl,pocall_clearstack];
  1286. pooption : [po_savestdregs];
  1287. mutexclpocall : [pocall_cdecl,pocall_internproc,pocall_leftright,pocall_inline];
  1288. mutexclpotype : [];
  1289. mutexclpo : [po_assembler,po_external]
  1290. )
  1291. );
  1292. function is_proc_directive(tok:ttoken):boolean;
  1293. var
  1294. i : longint;
  1295. begin
  1296. is_proc_directive:=false;
  1297. for i:=1 to num_proc_directives do
  1298. if proc_direcdata[i].idtok=idtoken then
  1299. begin
  1300. is_proc_directive:=true;
  1301. exit;
  1302. end;
  1303. end;
  1304. function parse_proc_direc(var pdflags:word):boolean;
  1305. {
  1306. Parse the procedure directive, returns true if a correct directive is found
  1307. }
  1308. var
  1309. p : longint;
  1310. found : boolean;
  1311. name : string;
  1312. begin
  1313. parse_proc_direc:=false;
  1314. name:=pattern;
  1315. found:=false;
  1316. for p:=1 to num_proc_directives do
  1317. if proc_direcdata[p].idtok=idtoken then
  1318. begin
  1319. found:=true;
  1320. break;
  1321. end;
  1322. { Check if the procedure directive is known }
  1323. if not found then
  1324. begin
  1325. { parsing a procvar type the name can be any
  1326. next variable !! }
  1327. if (pdflags and (pd_procvar or pd_object))=0 then
  1328. Message1(parser_w_unknown_proc_directive_ignored,name);
  1329. exit;
  1330. end;
  1331. { static needs a special treatment }
  1332. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1333. exit;
  1334. { Conflicts between directives ? }
  1335. if (aktprocsym^.definition^.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1336. ((aktprocsym^.definition^.proccalloptions*proc_direcdata[p].mutexclpocall)<>[]) or
  1337. ((aktprocsym^.definition^.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1338. begin
  1339. Message1(parser_e_proc_dir_conflict,name);
  1340. exit;
  1341. end;
  1342. { Check if the directive is only for objects }
  1343. if ((proc_direcdata[p].pd_flags and pd_object)<>0) and
  1344. not assigned(aktprocsym^.definition^._class) then
  1345. begin
  1346. exit;
  1347. end;
  1348. { check if method and directive not for object public }
  1349. if ((proc_direcdata[p].pd_flags and pd_notobject)<>0) and
  1350. assigned(aktprocsym^.definition^._class) then
  1351. begin
  1352. exit;
  1353. end;
  1354. { check if method and directive not for interface }
  1355. if ((proc_direcdata[p].pd_flags and pd_notobjintf)<>0) and
  1356. is_interface(aktprocsym^.definition^._class) then
  1357. begin
  1358. exit;
  1359. end;
  1360. { consume directive, and turn flag on }
  1361. consume(token);
  1362. parse_proc_direc:=true;
  1363. { Check the pd_flags if the directive should be allowed }
  1364. if ((pdflags and pd_interface)<>0) and
  1365. ((proc_direcdata[p].pd_flags and pd_interface)=0) then
  1366. begin
  1367. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1368. exit;
  1369. end;
  1370. if ((pdflags and pd_implemen)<>0) and
  1371. ((proc_direcdata[p].pd_flags and pd_implemen)=0) then
  1372. begin
  1373. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1374. exit;
  1375. end;
  1376. if ((pdflags and pd_procvar)<>0) and
  1377. ((proc_direcdata[p].pd_flags and pd_procvar)=0) then
  1378. begin
  1379. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1380. exit;
  1381. end;
  1382. { Return the new pd_flags }
  1383. if (proc_direcdata[p].pd_flags and pd_body)=0 then
  1384. pdflags:=pdflags and (not pd_body);
  1385. if (proc_direcdata[p].pd_flags and pd_global)<>0 then
  1386. pdflags:=pdflags or pd_global;
  1387. { Add the correct flag }
  1388. aktprocsym^.definition^.proccalloptions:=aktprocsym^.definition^.proccalloptions+proc_direcdata[p].pocall;
  1389. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+proc_direcdata[p].pooption;
  1390. { Adjust positions of args for cdecl or stdcall }
  1391. if (aktprocsym^.definition^.deftype=procdef) and
  1392. (([pocall_cdecl,pocall_cppdecl,pocall_stdcall]*aktprocsym^.definition^.proccalloptions)<>[]) then
  1393. pstoredsymtable(aktprocsym^.definition^.parast)^.set_alignment(target_os.size_of_longint);
  1394. { Call the handler }
  1395. if pointer({$ifndef FPCPROCVAR}@{$endif}proc_direcdata[p].handler)<>nil then
  1396. proc_direcdata[p].handler{$ifdef FPCPROCVAR}(){$endif};
  1397. end;
  1398. procedure parse_proc_directives(var pdflags:word);
  1399. {
  1400. Parse the procedure directives. It does not matter if procedure directives
  1401. are written using ;procdir; or ['procdir'] syntax.
  1402. }
  1403. var
  1404. res : boolean;
  1405. begin
  1406. while token in [_ID,_LECKKLAMMER] do
  1407. begin
  1408. if try_to_consume(_LECKKLAMMER) then
  1409. begin
  1410. repeat
  1411. parse_proc_direc(pdflags);
  1412. until not try_to_consume(_COMMA);
  1413. consume(_RECKKLAMMER);
  1414. { we always expect at least '[];' }
  1415. res:=true;
  1416. end
  1417. else
  1418. res:=parse_proc_direc(pdflags);
  1419. { A procedure directive normally followed by a semicolon, but in
  1420. a const section we should stop when _EQUAL is found }
  1421. if res then
  1422. begin
  1423. if (block_type=bt_const) and
  1424. (token=_EQUAL) then
  1425. break;
  1426. { support procedure proc;stdcall export; in Delphi mode only }
  1427. if not((m_delphi in aktmodeswitches) and
  1428. is_proc_directive(token)) then
  1429. consume(_SEMICOLON);
  1430. end
  1431. else
  1432. break;
  1433. end;
  1434. end;
  1435. procedure parse_var_proc_directives(var sym : psym);
  1436. var
  1437. pdflags : word;
  1438. oldsym : pprocsym;
  1439. pd : pabstractprocdef;
  1440. begin
  1441. oldsym:=aktprocsym;
  1442. pdflags:=pd_procvar;
  1443. { we create a temporary aktprocsym to read the directives }
  1444. aktprocsym:=new(pprocsym,init(sym^.name));
  1445. case sym^.typ of
  1446. varsym :
  1447. pd:=pabstractprocdef(pvarsym(sym)^.vartype.def);
  1448. typedconstsym :
  1449. pd:=pabstractprocdef(ptypedconstsym(sym)^.typedconsttype.def);
  1450. typesym :
  1451. pd:=pabstractprocdef(ptypesym(sym)^.restype.def);
  1452. else
  1453. internalerror(994932432);
  1454. end;
  1455. if pd^.deftype<>procvardef then
  1456. internalerror(994932433);
  1457. pabstractprocdef(aktprocsym^.definition):=pd;
  1458. { names should never be used anyway }
  1459. inc(lexlevel);
  1460. parse_proc_directives(pdflags);
  1461. dec(lexlevel);
  1462. aktprocsym^.definition:=nil;
  1463. dispose(aktprocsym,done);
  1464. aktprocsym:=oldsym;
  1465. end;
  1466. procedure parse_object_proc_directives(var sym : pprocsym);
  1467. var
  1468. pdflags : word;
  1469. begin
  1470. pdflags:=pd_object;
  1471. inc(lexlevel);
  1472. parse_proc_directives(pdflags);
  1473. dec(lexlevel);
  1474. if (po_containsself in aktprocsym^.definition^.procoptions) and
  1475. (([po_msgstr,po_msgint]*aktprocsym^.definition^.procoptions)=[]) then
  1476. Message(parser_e_self_in_non_message_handler);
  1477. end;
  1478. {***************************************************************************}
  1479. function check_identical_proc(var p : pprocdef) : boolean;
  1480. {
  1481. Search for idendical definitions,
  1482. if there is a forward, then kill this.
  1483. Returns the result of the forward check.
  1484. Removed from unter_dec to keep the source readable
  1485. }
  1486. var
  1487. hd,pd : Pprocdef;
  1488. storeparast : psymtable;
  1489. ad,fd : psym;
  1490. s : string;
  1491. begin
  1492. check_identical_proc:=false;
  1493. p:=nil;
  1494. pd:=aktprocsym^.definition;
  1495. if assigned(pd) then
  1496. begin
  1497. { Is there an overload/forward ? }
  1498. if assigned(pd^.nextoverloaded) then
  1499. begin
  1500. { walk the procdef list }
  1501. while (assigned(pd)) and (assigned(pd^.nextoverloaded)) do
  1502. begin
  1503. hd:=pd^.nextoverloaded;
  1504. { check the parameters }
  1505. if (not(m_repeat_forward in aktmodeswitches) and
  1506. (aktprocsym^.definition^.maxparacount=0)) or
  1507. (equal_paras(aktprocsym^.definition^.para,hd^.para,cp_none) and
  1508. { for operators equal_paras is not enough !! }
  1509. ((aktprocsym^.definition^.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1510. is_equal(hd^.rettype.def,aktprocsym^.definition^.rettype.def))) then
  1511. begin
  1512. if not equal_paras(aktprocsym^.definition^.para,hd^.para,cp_all) and
  1513. ((m_repeat_forward in aktmodeswitches) or
  1514. (aktprocsym^.definition^.maxparacount>0)) then
  1515. begin
  1516. MessagePos1(aktprocsym^.definition^.fileinfo,parser_e_header_dont_match_forward,
  1517. aktprocsym^.definition^.fullprocname);
  1518. exit;
  1519. end;
  1520. if hd^.forwarddef then
  1521. { remove the forward definition but don't delete it, }
  1522. { the symtable is the owner !! }
  1523. begin
  1524. { Check if the procedure type and return type are correct }
  1525. if (hd^.proctypeoption<>aktprocsym^.definition^.proctypeoption) or
  1526. (not(is_equal(hd^.rettype.def,aktprocsym^.definition^.rettype.def)) and
  1527. (m_repeat_forward in aktmodeswitches)) then
  1528. begin
  1529. MessagePos1(aktprocsym^.definition^.fileinfo,parser_e_header_dont_match_forward,
  1530. aktprocsym^.definition^.fullprocname);
  1531. exit;
  1532. end;
  1533. { Check calling convention, no check for internconst,internproc which
  1534. are only defined in interface or implementation }
  1535. if (hd^.proccalloptions-[pocall_internconst,pocall_internproc]<>
  1536. aktprocsym^.definition^.proccalloptions-[pocall_internconst,pocall_internproc]) then
  1537. begin
  1538. { only trigger an error, becuase it doesn't hurt, for delphi check
  1539. if the current implementation has no proccalloptions, then
  1540. take the options from the interface }
  1541. if (m_delphi in aktmodeswitches) then
  1542. begin
  1543. if (aktprocsym^.definition^.proccalloptions=[]) then
  1544. aktprocsym^.definition^.proccalloptions:=hd^.proccalloptions
  1545. else
  1546. MessagePos(aktprocsym^.definition^.fileinfo,parser_e_call_convention_dont_match_forward);
  1547. end
  1548. else
  1549. MessagePos(aktprocsym^.definition^.fileinfo,parser_e_call_convention_dont_match_forward);
  1550. { set the mangledname to the interface name so it doesn't trigger
  1551. the Note about different manglednames (PFV) }
  1552. aktprocsym^.definition^.setmangledname(hd^.mangledname);
  1553. end;
  1554. { manglednames are equal? }
  1555. hd^.count:=false;
  1556. if (m_repeat_forward in aktmodeswitches) or
  1557. aktprocsym^.definition^.haspara then
  1558. begin
  1559. if (hd^.mangledname<>aktprocsym^.definition^.mangledname) then
  1560. begin
  1561. if not(po_external in aktprocsym^.definition^.procoptions) then
  1562. MessagePos2(aktprocsym^.definition^.fileinfo,parser_n_interface_name_diff_implementation_name,hd^.mangledname,
  1563. aktprocsym^.definition^.mangledname);
  1564. { reset the mangledname of the interface part to be sure }
  1565. { this is wrong because the mangled name might have been used already !! }
  1566. if hd^.is_used then
  1567. renameasmsymbol(hd^.mangledname,aktprocsym^.definition^.mangledname);
  1568. hd^.setmangledname(aktprocsym^.definition^.mangledname);
  1569. { so we need to keep the name of interface !!
  1570. No!!!! The procedure directives can change the mangledname.
  1571. I fixed this by first calling check_identical_proc and then doing
  1572. the proc directives, but this is not a good solution.(DM)}
  1573. { this is also wrong (PM)
  1574. aktprocsym^.definition^.setmangledname(hd^.mangledname);}
  1575. end
  1576. else
  1577. begin
  1578. { If mangled names are equal, therefore }
  1579. { they have the same number of parameters }
  1580. { Therefore we can check the name of these }
  1581. { parameters... }
  1582. if hd^.forwarddef and aktprocsym^.definition^.forwarddef then
  1583. begin
  1584. MessagePos1(aktprocsym^.definition^.fileinfo,
  1585. parser_e_function_already_declared_public_forward,
  1586. aktprocsym^.definition^.fullprocname);
  1587. check_identical_proc:=true;
  1588. { Remove other forward from the list to reduce errors }
  1589. pd^.nextoverloaded:=pd^.nextoverloaded^.nextoverloaded;
  1590. exit;
  1591. end;
  1592. ad:=psym(hd^.parast^.symindex^.first);
  1593. fd:=psym(aktprocsym^.definition^.parast^.symindex^.first);
  1594. if assigned(ad) and assigned(fd) then
  1595. begin
  1596. while assigned(ad) and assigned(fd) do
  1597. begin
  1598. s:=ad^.name;
  1599. if s<>fd^.name then
  1600. begin
  1601. MessagePos3(aktprocsym^.definition^.fileinfo,parser_e_header_different_var_names,
  1602. aktprocsym^.name,s,fd^.name);
  1603. break;
  1604. end;
  1605. { it is impossible to have a nil pointer }
  1606. { for only one parameter - since they }
  1607. { have the same number of parameters. }
  1608. { Left = next parameter. }
  1609. ad:=psym(ad^.left);
  1610. fd:=psym(fd^.left);
  1611. end;
  1612. end;
  1613. end;
  1614. end;
  1615. { also the para_offset }
  1616. hd^.parast^.address_fixup:=aktprocsym^.definition^.parast^.address_fixup;
  1617. hd^.count:=true;
  1618. { remove pd^.nextoverloaded from the list }
  1619. { and add aktprocsym^.definition }
  1620. pd^.nextoverloaded:=pd^.nextoverloaded^.nextoverloaded;
  1621. hd^.nextoverloaded:=aktprocsym^.definition^.nextoverloaded;
  1622. { Alert! All fields of aktprocsym^.definition that are modified
  1623. by the procdir handlers must be copied here!.}
  1624. hd^.forwarddef:=false;
  1625. hd^.hasforward:=true;
  1626. hd^.proccalloptions:=hd^.proccalloptions + aktprocsym^.definition^.proccalloptions;
  1627. hd^.procoptions:=hd^.procoptions + aktprocsym^.definition^.procoptions;
  1628. if aktprocsym^.definition^.extnumber=-1 then
  1629. aktprocsym^.definition^.extnumber:=hd^.extnumber
  1630. else
  1631. if hd^.extnumber=-1 then
  1632. hd^.extnumber:=aktprocsym^.definition^.extnumber;
  1633. { copy all aliasnames }
  1634. while not aktprocsym^.definition^.aliasnames.empty do
  1635. hd^.aliasnames.insert(aktprocsym^.definition^.aliasnames.getfirst);
  1636. { switch parast for warning in implementation PM }
  1637. if (m_repeat_forward in aktmodeswitches) or
  1638. aktprocsym^.definition^.haspara then
  1639. begin
  1640. storeparast:=hd^.parast;
  1641. hd^.parast:=aktprocsym^.definition^.parast;
  1642. aktprocsym^.definition^.parast:=storeparast;
  1643. end;
  1644. if pd=aktprocsym^.definition then
  1645. p:=nil
  1646. else
  1647. p:=pd;
  1648. aktprocsym^.definition:=hd;
  1649. check_identical_proc:=true;
  1650. end
  1651. else
  1652. { abstract methods aren't forward defined, but this }
  1653. { needs another error message }
  1654. if not(po_abstractmethod in pd^.nextoverloaded^.procoptions) then
  1655. MessagePos(aktprocsym^.definition^.fileinfo,parser_e_overloaded_have_same_parameters)
  1656. else
  1657. MessagePos(aktprocsym^.definition^.fileinfo,parser_e_abstract_no_definition);
  1658. break;
  1659. end;
  1660. { check for allowing overload directive }
  1661. if not(m_fpc in aktmodeswitches) then
  1662. begin
  1663. { overload directive turns on overloading }
  1664. if ((po_overload in aktprocsym^.definition^.procoptions) or
  1665. ((po_overload in hd^.procoptions))) then
  1666. begin
  1667. { check if all procs have overloading, but not if the proc was
  1668. already declared forward, then the check is already done }
  1669. if not(hd^.hasforward) and
  1670. (aktprocsym^.definition^.forwarddef=hd^.forwarddef) and
  1671. not((po_overload in aktprocsym^.definition^.procoptions) and
  1672. ((po_overload in hd^.procoptions))) then
  1673. begin
  1674. MessagePos1(aktprocsym^.definition^.fileinfo,parser_e_no_overload_for_all_procs,aktprocsym^.realname);
  1675. break;
  1676. end;
  1677. end
  1678. else
  1679. begin
  1680. if not(hd^.forwarddef) then
  1681. begin
  1682. MessagePos(aktprocsym^.definition^.fileinfo,parser_e_procedure_overloading_is_off);
  1683. break;
  1684. end;
  1685. end;
  1686. end;
  1687. { try next overloaded }
  1688. pd:=pd^.nextoverloaded;
  1689. end;
  1690. end
  1691. else
  1692. begin
  1693. { there is no overloaded, so its always identical with itself }
  1694. check_identical_proc:=true;
  1695. end;
  1696. end;
  1697. { insert opsym only in the right symtable }
  1698. if ((procinfo^.flags and pi_operator)<>0) and assigned(opsym)
  1699. and not parse_only then
  1700. begin
  1701. if ret_in_param(aktprocsym^.definition^.rettype.def) then
  1702. begin
  1703. pprocdef(aktprocsym^.definition)^.parast^.insert(opsym);
  1704. { this increases the data size }
  1705. { correct this to get the right ret $value }
  1706. dec(pprocdef(aktprocsym^.definition)^.parast^.datasize,opsym^.getpushsize);
  1707. { this allows to read the funcretoffset }
  1708. opsym^.address:=-4;
  1709. opsym^.varspez:=vs_var;
  1710. end
  1711. else
  1712. pprocdef(aktprocsym^.definition)^.localst^.insert(opsym);
  1713. end;
  1714. end;
  1715. procedure checkvaluepara(p:pnamedindexobject);
  1716. var
  1717. vs : pvarsym;
  1718. s : string;
  1719. begin
  1720. with pvarsym(p)^ do
  1721. begin
  1722. if copy(name,1,3)='val' then
  1723. begin
  1724. s:=Copy(name,4,255);
  1725. if not(po_assembler in aktprocsym^.definition^.procoptions) then
  1726. begin
  1727. vs:=new(Pvarsym,initdef(s,vartype.def));
  1728. vs^.fileinfo:=fileinfo;
  1729. vs^.varspez:=varspez;
  1730. aktprocsym^.definition^.localst^.insert(vs);
  1731. include(vs^.varoptions,vo_is_local_copy);
  1732. vs^.varstate:=vs_assigned;
  1733. localvarsym:=vs;
  1734. inc(refs); { the para was used to set the local copy ! }
  1735. { warnings only on local copy ! }
  1736. varstate:=vs_used;
  1737. end
  1738. else
  1739. begin
  1740. aktprocsym^.definition^.parast^.rename(name,s);
  1741. end;
  1742. end;
  1743. end;
  1744. end;
  1745. end.
  1746. {
  1747. $Log$
  1748. Revision 1.10 2000-12-25 00:07:27 peter
  1749. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1750. tlinkedlist objects)
  1751. Revision 1.9 2000/11/29 00:30:35 florian
  1752. * unused units removed from uses clause
  1753. * some changes for widestrings
  1754. Revision 1.8 2000/11/26 23:45:34 florian
  1755. * pascal modifier in interfaces of units works now
  1756. Revision 1.7 2000/11/06 20:30:55 peter
  1757. * more fixes to get make cycle working
  1758. Revision 1.6 2000/11/04 14:25:20 florian
  1759. + merged Attila's changes for interfaces, not tested yet
  1760. Revision 1.5 2000/11/01 23:04:37 peter
  1761. * tprocdef.fullprocname added for better casesensitve writing of
  1762. procedures
  1763. Revision 1.4 2000/10/31 22:02:49 peter
  1764. * symtable splitted, no real code changes
  1765. Revision 1.3 2000/10/21 18:16:11 florian
  1766. * a lot of changes:
  1767. - basic dyn. array support
  1768. - basic C++ support
  1769. - some work for interfaces done
  1770. ....
  1771. Revision 1.2 2000/10/15 07:47:51 peter
  1772. * unit names and procedure names are stored mixed case
  1773. Revision 1.1 2000/10/14 10:14:51 peter
  1774. * moehrendorf oct 2000 rewrite
  1775. }