pdecsub.pas 81 KB

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