pdecsub.pas 87 KB

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