pdecsub.pas 76 KB

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