pdecsub.pas 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl, Daniel Mantione
  3. Does the parsing of the procedures/functions
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit pdecsub;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. tokens,symconst,symtype,symdef,symsym;
  22. type
  23. tpdflag=(
  24. pd_body, { directive needs a body }
  25. pd_implemen, { directive can be used implementation section }
  26. pd_interface, { directive can be used interface section }
  27. pd_object, { directive can be used object declaration }
  28. pd_procvar, { directive can be used procvar declaration }
  29. pd_notobject, { directive can not be used object declaration }
  30. pd_notobjintf, { directive can not be used interface declaration }
  31. pd_notprocvar { directive can not be used procvar declaration }
  32. );
  33. tpdflags=set of tpdflag;
  34. function check_proc_directive(isprocvar:boolean):boolean;
  35. procedure insert_funcret_local(pd:tprocdef);
  36. function proc_add_definition(var pd:tprocdef):boolean;
  37. function proc_get_importname(pd:tprocdef):string;
  38. procedure proc_set_mangledname(pd:tprocdef);
  39. procedure handle_calling_convention(pd:tabstractprocdef);
  40. procedure parse_parameter_dec(pd:tabstractprocdef);
  41. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  42. procedure parse_var_proc_directives(sym:tsym);
  43. procedure parse_object_proc_directives(pd:tabstractprocdef);
  44. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  45. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  46. implementation
  47. uses
  48. strings,
  49. { common }
  50. cutils,cclasses,
  51. { global }
  52. globtype,globals,verbose,
  53. systems,
  54. cpuinfo,
  55. { symtable }
  56. symbase,symtable,defutil,defcmp,paramgr,cpupara,
  57. { pass 1 }
  58. node,htypechk,
  59. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  60. { parser }
  61. scanner,
  62. pbase,pexpr,ptype,pdecl
  63. ;
  64. const
  65. { Please leave this here, this module should NOT use
  66. these variables.
  67. Declaring it as string here results in an error when compiling (PFV) }
  68. current_procinfo = 'error';
  69. procedure insert_funcret_para(pd:tabstractprocdef);
  70. var
  71. storepos : tfileposinfo;
  72. vs : tparavarsym;
  73. paranr : word;
  74. begin
  75. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  76. not is_void(pd.rettype.def) and
  77. paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  78. begin
  79. storepos:=akttokenpos;
  80. if pd.deftype=procdef then
  81. akttokenpos:=tprocdef(pd).fileinfo;
  82. { For left to right add it at the end to be delphi compatible }
  83. if pd.proccalloption in pushleftright_pocalls then
  84. paranr:=paranr_result_leftright
  85. else
  86. paranr:=paranr_result;
  87. { Generate result variable accessing function result }
  88. vs:=tparavarsym.create('$result',paranr,vs_var,pd.rettype,[vo_is_funcret,vo_is_hidden_para]);
  89. pd.parast.insert(vs);
  90. { Store the this symbol as funcretsym for procedures }
  91. if pd.deftype=procdef then
  92. tprocdef(pd).funcretsym:=vs;
  93. akttokenpos:=storepos;
  94. end;
  95. end;
  96. procedure insert_parentfp_para(pd:tabstractprocdef);
  97. var
  98. storepos : tfileposinfo;
  99. vs : tparavarsym;
  100. begin
  101. if pd.parast.symtablelevel>normal_function_level then
  102. begin
  103. storepos:=akttokenpos;
  104. if pd.deftype=procdef then
  105. akttokenpos:=tprocdef(pd).fileinfo;
  106. { Generate result variable accessing function result, it
  107. can't be put in a register since it must be accessable
  108. from the framepointer }
  109. vs:=tparavarsym.create('$parentfp',paranr_parentfp,vs_var,voidpointertype,[vo_is_parentfp,vo_is_hidden_para]);
  110. vs.varregable:=vr_none;
  111. pd.parast.insert(vs);
  112. akttokenpos:=storepos;
  113. end;
  114. end;
  115. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  116. var
  117. storepos : tfileposinfo;
  118. vs : tparavarsym;
  119. tt : ttype;
  120. vsp : tvarspez;
  121. begin
  122. if (pd.deftype=procvardef) and
  123. pd.is_methodpointer then
  124. begin
  125. { Generate self variable }
  126. tt:=voidpointertype;
  127. vs:=tparavarsym.create('$self',paranr_self,vs_value,tt,[vo_is_self,vo_is_hidden_para]);
  128. pd.parast.insert(vs);
  129. end
  130. else
  131. begin
  132. if (pd.deftype=procdef) and
  133. assigned(tprocdef(pd)._class) and
  134. (pd.parast.symtablelevel=normal_function_level) then
  135. begin
  136. storepos:=akttokenpos;
  137. akttokenpos:=tprocdef(pd).fileinfo;
  138. { Generate VMT variable for constructor/destructor }
  139. if pd.proctypeoption in [potype_constructor,potype_destructor] then
  140. begin
  141. { can't use classrefdef as type because inheriting
  142. will then always file because of a type mismatch }
  143. tt:=voidpointertype;
  144. vs:=tparavarsym.create('$vmt',paranr_vmt,vs_value,tt,[vo_is_vmt,vo_is_hidden_para]);
  145. pd.parast.insert(vs);
  146. end;
  147. { Generate self variable, for classes we need
  148. to use the generic voidpointer to be compatible with
  149. methodpointers }
  150. vsp:=vs_value;
  151. if (po_staticmethod in pd.procoptions) or
  152. (po_classmethod in pd.procoptions) then
  153. begin
  154. tt.setdef(tprocdef(pd)._class);
  155. tt.setdef(tclassrefdef.create(tt));
  156. end
  157. else
  158. begin
  159. if is_object(tprocdef(pd)._class) then
  160. vsp:=vs_var;
  161. tt.setdef(tprocdef(pd)._class);
  162. end;
  163. vs:=tparavarsym.create('$self',paranr_self,vsp,tt,[vo_is_self,vo_is_hidden_para]);
  164. pd.parast.insert(vs);
  165. akttokenpos:=storepos;
  166. end;
  167. end;
  168. end;
  169. procedure insert_funcret_local(pd:tprocdef);
  170. var
  171. storepos : tfileposinfo;
  172. vs : tlocalvarsym;
  173. aliasvs : tabsolutevarsym;
  174. sl : tsymlist;
  175. begin
  176. { The result from constructors and destructors can't be accessed directly }
  177. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  178. not is_void(pd.rettype.def) then
  179. begin
  180. storepos:=akttokenpos;
  181. akttokenpos:=pd.fileinfo;
  182. { We always need a localsymtable }
  183. if not assigned(pd.localst) then
  184. pd.insert_localst;
  185. { We need to insert a varsym for the result in the localst
  186. when it is returning in a register }
  187. if not paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  188. begin
  189. vs:=tlocalvarsym.create('$result',vs_value,pd.rettype,[vo_is_funcret]);
  190. pd.localst.insert(vs);
  191. pd.funcretsym:=vs;
  192. end;
  193. { insert the name of the procedure as alias for the function result,
  194. we can't use realname because that will not work for compilerprocs
  195. as the name is lowercase and unreachable from the code }
  196. if pd.resultname='' then
  197. pd.resultname:=pd.procsym.name;
  198. sl:=tsymlist.create;
  199. sl.addsym(sl_load,pd.funcretsym);
  200. aliasvs:=tabsolutevarsym.create_ref(pd.resultname,pd.rettype,sl);
  201. include(aliasvs.varoptions,vo_is_funcret);
  202. pd.localst.insert(aliasvs);
  203. { insert result also if support is on }
  204. if (m_result in aktmodeswitches) then
  205. begin
  206. sl:=tsymlist.create;
  207. sl.addsym(sl_load,pd.funcretsym);
  208. aliasvs:=tabsolutevarsym.create_ref('RESULT',pd.rettype,sl);
  209. include(aliasvs.varoptions,vo_is_funcret);
  210. include(aliasvs.varoptions,vo_is_result);
  211. pd.localst.insert(aliasvs);
  212. end;
  213. akttokenpos:=storepos;
  214. end;
  215. end;
  216. procedure insert_hidden_para(p:tnamedindexitem;arg:pointer);
  217. var
  218. hvs : tparavarsym;
  219. pd : tabstractprocdef absolute arg;
  220. begin
  221. if (tsym(p).typ<>paravarsym) then
  222. exit;
  223. with tparavarsym(p) do
  224. begin
  225. { We need a local copy for a value parameter when only the
  226. address is pushed. Open arrays and Array of Const are
  227. an exception because they are allocated at runtime and the
  228. address that is pushed is patched }
  229. if (varspez=vs_value) and
  230. paramanager.push_addr_param(varspez,vartype.def,pd.proccalloption) and
  231. not(is_open_array(vartype.def) or
  232. is_array_of_const(vartype.def)) then
  233. include(varoptions,vo_has_local_copy);
  234. { needs high parameter ? }
  235. if paramanager.push_high_param(varspez,vartype.def,pd.proccalloption) then
  236. begin
  237. hvs:=tparavarsym.create('$high'+name,paranr+1,vs_const,sinttype,[vo_is_high_para,vo_is_hidden_para]);
  238. owner.insert(hvs);
  239. end
  240. else
  241. begin
  242. { Give a warning that cdecl routines does not include high()
  243. support }
  244. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  245. paramanager.push_high_param(varspez,vartype.def,pocall_default) then
  246. begin
  247. if is_open_string(vartype.def) then
  248. Message(parser_w_cdecl_no_openstring);
  249. if not (po_external in pd.procoptions) then
  250. Message(parser_w_cdecl_has_no_high);
  251. end;
  252. end;
  253. end;
  254. end;
  255. procedure check_c_para(p:tnamedindexitem;arg:pointer);
  256. begin
  257. if (tsym(p).typ<>paravarsym) then
  258. exit;
  259. with tparavarsym(p) do
  260. begin
  261. case vartype.def.deftype of
  262. arraydef :
  263. begin
  264. if not is_variant_array(vartype.def) and
  265. not is_array_of_const(vartype.def) then
  266. begin
  267. if (varspez<>vs_var) then
  268. Message(parser_h_c_arrays_are_references);
  269. end;
  270. if is_array_of_const(vartype.def) and
  271. assigned(indexnext) and
  272. (tsym(indexnext).typ=paravarsym) and
  273. not(vo_is_high_para in tparavarsym(indexnext).varoptions) then
  274. Message(parser_e_C_array_of_const_must_be_last);
  275. end;
  276. end;
  277. end;
  278. end;
  279. procedure check_msg_para(p:tnamedindexitem;arg:pointer);
  280. begin
  281. if (tsym(p).typ<>paravarsym) then
  282. exit;
  283. with tparavarsym(p) do
  284. begin
  285. { Count parameters }
  286. if (paranr>=10) then
  287. inc(plongint(arg)^);
  288. { First parameter must be var }
  289. if (paranr=10) and
  290. (varspez<>vs_var) then
  291. Message(parser_e_ill_msg_param);
  292. end;
  293. end;
  294. procedure check_inline_para(p:tnamedindexitem;arg:pointer);
  295. var
  296. pd : tabstractprocdef absolute arg;
  297. begin
  298. if not(po_inline in pd.procoptions) or
  299. (tsym(p).typ<>paravarsym) then
  300. exit;
  301. with tparavarsym(p) do
  302. begin
  303. case vartype.def.deftype of
  304. arraydef :
  305. begin
  306. with tarraydef(vartype.def) do
  307. if IsVariant or IsConstructor then
  308. begin
  309. Message1(parser_w_not_supported_for_inline,'array of const');
  310. Message(parser_w_inlining_disabled);
  311. pd.proccalloption:=pocall_default;
  312. end;
  313. end;
  314. end;
  315. end;
  316. end;
  317. procedure set_addr_param_regable(p:tnamedindexitem;arg:pointer);
  318. begin
  319. if (tsym(p).typ<>paravarsym) then
  320. exit;
  321. with tparavarsym(p) do
  322. begin
  323. if not vartype.def.needs_inittable and
  324. paramanager.push_addr_param(varspez,vartype.def,tprocdef(arg).proccalloption) then
  325. varregable:=vr_intreg;
  326. end;
  327. end;
  328. procedure parse_parameter_dec(pd:tabstractprocdef);
  329. {
  330. handle_procvar needs the same changes
  331. }
  332. type
  333. tppv = (pv_none,pv_proc,pv_func);
  334. var
  335. sc : tsinglelist;
  336. tt : ttype;
  337. arrayelementtype : ttype;
  338. vs : tparavarsym;
  339. srsym : tsym;
  340. pv : tprocvardef;
  341. varspez : Tvarspez;
  342. defaultvalue : tconstsym;
  343. defaultrequired : boolean;
  344. old_object_option : tsymoptions;
  345. currparast : tparasymtable;
  346. parseprocvar : tppv;
  347. explicit_paraloc : boolean;
  348. locationstr : string;
  349. paranr : integer;
  350. dummytype : ttypesym;
  351. begin
  352. explicit_paraloc:=false;
  353. consume(_LKLAMMER);
  354. { Delphi/Kylix supports nonsense like }
  355. { procedure p(); }
  356. if try_to_consume(_RKLAMMER) and
  357. not(m_tp7 in aktmodeswitches) then
  358. exit;
  359. { parsing a proc or procvar ? }
  360. currparast:=tparasymtable(pd.parast);
  361. { reset }
  362. sc:=tsinglelist.create;
  363. defaultrequired:=false;
  364. paranr:=0;
  365. { the variables are always public }
  366. old_object_option:=current_object_option;
  367. current_object_option:=[sp_public];
  368. inc(testcurobject);
  369. repeat
  370. parseprocvar:=pv_none;
  371. if try_to_consume(_VAR) then
  372. varspez:=vs_var
  373. else
  374. if try_to_consume(_CONST) then
  375. varspez:=vs_const
  376. else
  377. if (m_out in aktmodeswitches) and
  378. try_to_consume(_OUT) then
  379. varspez:=vs_out
  380. else
  381. if (m_mac in aktmodeswitches) and
  382. try_to_consume(_POINTPOINTPOINT) then
  383. begin
  384. include(pd.procoptions,po_varargs);
  385. break;
  386. end
  387. else
  388. if (m_mac in aktmodeswitches) and
  389. try_to_consume(_PROCEDURE) then
  390. begin
  391. parseprocvar:=pv_proc;
  392. varspez:=vs_const;
  393. end
  394. else
  395. if (m_mac in aktmodeswitches) and
  396. try_to_consume(_FUNCTION) then
  397. begin
  398. parseprocvar:=pv_func;
  399. varspez:=vs_const;
  400. end
  401. else
  402. varspez:=vs_value;
  403. defaultvalue:=nil;
  404. tt.reset;
  405. { read identifiers and insert with error type }
  406. sc.reset;
  407. repeat
  408. inc(paranr);
  409. vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrortype,[]);
  410. currparast.insert(vs);
  411. if assigned(vs.owner) then
  412. sc.insert(vs)
  413. else
  414. vs.free;
  415. consume(_ID);
  416. until not try_to_consume(_COMMA);
  417. locationstr:='';
  418. { macpas anonymous procvar }
  419. if parseprocvar<>pv_none then
  420. begin
  421. pv:=tprocvardef.create(normal_function_level);
  422. if token=_LKLAMMER then
  423. parse_parameter_dec(pv);
  424. if parseprocvar=pv_func then
  425. begin
  426. consume(_COLON);
  427. single_type(pv.rettype,false);
  428. end;
  429. tt.def:=pv;
  430. { possible proc directives }
  431. if check_proc_directive(true) then
  432. begin
  433. dummytype:=ttypesym.create('unnamed',tt);
  434. parse_var_proc_directives(tsym(dummytype));
  435. dummytype.restype.def:=nil;
  436. tt.def.typesym:=nil;
  437. dummytype.free;
  438. end;
  439. { Add implicit hidden parameters and function result }
  440. handle_calling_convention(pv);
  441. end
  442. else
  443. { read type declaration, force reading for value and const paras }
  444. if (token=_COLON) or (varspez=vs_value) then
  445. begin
  446. consume(_COLON);
  447. { check for an open array }
  448. if token=_ARRAY then
  449. begin
  450. consume(_ARRAY);
  451. consume(_OF);
  452. { define range and type of range }
  453. tt.setdef(tarraydef.create(0,-1,s32inttype));
  454. { array of const ? }
  455. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  456. begin
  457. consume(_CONST);
  458. srsym:=searchsymonlyin(systemunit,'TVARREC');
  459. if not assigned(srsym) then
  460. InternalError(200404181);
  461. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  462. tarraydef(tt.def).IsArrayOfConst:=true;
  463. end
  464. else
  465. begin
  466. { define field type }
  467. single_type(arrayelementtype,false);
  468. tarraydef(tt.def).setelementtype(arrayelementtype);
  469. end;
  470. end
  471. else
  472. begin
  473. { open string ? }
  474. if (varspez in [vs_out,vs_var]) and
  475. (
  476. (
  477. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  478. (cs_openstring in aktmoduleswitches) and
  479. not(cs_ansistrings in aktlocalswitches)
  480. ) or
  481. (idtoken=_OPENSTRING)) then
  482. begin
  483. consume(token);
  484. tt:=openshortstringtype;
  485. end
  486. else
  487. begin
  488. { everything else }
  489. if (m_mac in aktmodeswitches) then
  490. try_to_consume(_UNIV); {currently does nothing}
  491. single_type(tt,false);
  492. end;
  493. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  494. begin
  495. if (idtoken=_LOCATION) then
  496. begin
  497. consume(_LOCATION);
  498. locationstr:=pattern;
  499. consume(_CSTRING);
  500. end
  501. else
  502. begin
  503. if explicit_paraloc then
  504. Message(parser_e_paraloc_all_paras);
  505. locationstr:='';
  506. end;
  507. end
  508. else
  509. locationstr:='';
  510. { default parameter }
  511. if (m_default_para in aktmodeswitches) then
  512. begin
  513. if try_to_consume(_EQUAL) then
  514. begin
  515. vs:=tparavarsym(sc.first);
  516. if assigned(vs.listnext) then
  517. Message(parser_e_default_value_only_one_para);
  518. { prefix 'def' to the parameter name }
  519. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  520. if assigned(defaultvalue) then
  521. begin
  522. include(defaultvalue.symoptions,sp_internal);
  523. pd.parast.insert(defaultvalue);
  524. end;
  525. defaultrequired:=true;
  526. end
  527. else
  528. begin
  529. if defaultrequired then
  530. Message1(parser_e_default_value_expected_for_para,vs.name);
  531. end;
  532. end;
  533. end;
  534. end
  535. else
  536. tt:=cformaltype;
  537. { File types are only allowed for var parameters }
  538. if (tt.def.deftype=filedef) and
  539. (varspez<>vs_var) then
  540. CGMessage(cg_e_file_must_call_by_reference);
  541. vs:=tparavarsym(sc.first);
  542. while assigned(vs) do
  543. begin
  544. { update varsym }
  545. vs.vartype:=tt;
  546. vs.defaultconstsym:=defaultvalue;
  547. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  548. begin
  549. if locationstr<>'' then
  550. begin
  551. if assigned(sc.first.listnext) then
  552. Message(parser_e_paraloc_only_one_para);
  553. if (paranr>1) and not(explicit_paraloc) then
  554. Message(parser_e_paraloc_all_paras);
  555. explicit_paraloc:=true;
  556. include(vs.varoptions,vo_has_explicit_paraloc);
  557. if not(paramanager.parseparaloc(vs,upper(locationstr))) then
  558. message(parser_e_illegal_explicit_paraloc);
  559. end
  560. else
  561. if explicit_paraloc then
  562. Message(parser_e_paraloc_all_paras);
  563. end;
  564. vs:=tparavarsym(vs.listnext);
  565. end;
  566. until not try_to_consume(_SEMICOLON);
  567. if explicit_paraloc then
  568. begin
  569. pd.has_paraloc_info:=true;
  570. include(pd.procoptions,po_explicitparaloc);
  571. end;
  572. { remove parasymtable from stack }
  573. sc.free;
  574. { reset object options }
  575. dec(testcurobject);
  576. current_object_option:=old_object_option;
  577. consume(_RKLAMMER);
  578. end;
  579. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  580. var
  581. hs : string;
  582. orgsp,sp : stringid;
  583. sym : tsym;
  584. srsym : tsym;
  585. srsymtable : tsymtable;
  586. storepos,
  587. procstartfilepos : tfileposinfo;
  588. searchagain : boolean;
  589. i : longint;
  590. st : tsymtable;
  591. aprocsym : tprocsym;
  592. begin
  593. { Save the position where this procedure really starts }
  594. procstartfilepos:=akttokenpos;
  595. result:=false;
  596. pd:=nil;
  597. aprocsym:=nil;
  598. if (potype=potype_operator) then
  599. begin
  600. sp:=overloaded_names[optoken];
  601. orgsp:=sp;
  602. end
  603. else
  604. begin
  605. sp:=pattern;
  606. orgsp:=orgpattern;
  607. consume(_ID);
  608. end;
  609. { examine interface map: function/procedure iname.functionname=locfuncname }
  610. if assigned(aclass) and
  611. assigned(aclass.implementedinterfaces) and
  612. (aclass.implementedinterfaces.count>0) and
  613. try_to_consume(_POINT) then
  614. begin
  615. storepos:=akttokenpos;
  616. akttokenpos:=procstartfilepos;
  617. { get interface syms}
  618. searchsym(sp,sym,srsymtable);
  619. if not assigned(sym) then
  620. begin
  621. identifier_not_found(orgsp);
  622. sym:=generrorsym;
  623. end;
  624. akttokenpos:=storepos;
  625. { qualifier is interface? }
  626. if (sym.typ=typesym) and
  627. (ttypesym(sym).restype.def.deftype=objectdef) then
  628. i:=aclass.implementedinterfaces.searchintf(ttypesym(sym).restype.def)
  629. else
  630. i:=-1;
  631. if (i=-1) then
  632. Message(parser_e_interface_id_expected);
  633. consume(_ID);
  634. { Create unique name <interface>.<method> }
  635. hs:=sp+'.'+pattern;
  636. consume(_EQUAL);
  637. if (token=_ID) then
  638. aclass.implementedinterfaces.addmappings(i,hs,pattern);
  639. consume(_ID);
  640. result:=true;
  641. exit;
  642. end;
  643. { method ? }
  644. if not assigned(aclass) and
  645. (potype<>potype_operator) and
  646. (symtablestack.symtablelevel=main_program_level) and
  647. try_to_consume(_POINT) then
  648. begin
  649. { search for object name }
  650. storepos:=akttokenpos;
  651. akttokenpos:=procstartfilepos;
  652. searchsym(sp,sym,srsymtable);
  653. if not assigned(sym) then
  654. begin
  655. identifier_not_found(orgsp);
  656. sym:=generrorsym;
  657. end;
  658. akttokenpos:=storepos;
  659. { consume proc name }
  660. sp:=pattern;
  661. orgsp:=orgpattern;
  662. procstartfilepos:=akttokenpos;
  663. consume(_ID);
  664. { qualifier is class name ? }
  665. if (sym.typ=typesym) and
  666. (ttypesym(sym).restype.def.deftype=objectdef) then
  667. begin
  668. aclass:=tobjectdef(ttypesym(sym).restype.def);
  669. aprocsym:=tprocsym(aclass.symtable.search(sp));
  670. { we solve this below }
  671. if assigned(aprocsym) then
  672. begin
  673. if aprocsym.typ<>procsym then
  674. begin
  675. { we use a different error message for tp7 so it looks more compatible }
  676. if (m_fpc in aktmodeswitches) then
  677. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  678. else
  679. Message(parser_e_methode_id_expected);
  680. { rename the name to an unique name to avoid an
  681. error when inserting the symbol in the symtable }
  682. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  683. aprocsym:=nil;
  684. end;
  685. end
  686. else
  687. begin
  688. Message(parser_e_methode_id_expected);
  689. { recover by making it a normal procedure instead of method }
  690. aclass:=nil;
  691. end;
  692. end
  693. else
  694. Message(parser_e_class_id_expected);
  695. end
  696. else
  697. begin
  698. { check for constructor/destructor which is not allowed here }
  699. if (not parse_only) and
  700. (potype in [potype_constructor,potype_destructor]) then
  701. Message(parser_e_constructors_always_objects);
  702. repeat
  703. searchagain:=false;
  704. akttokenpos:=procstartfilepos;
  705. srsym:=tsym(symtablestack.search(sp));
  706. if not(parse_only) and
  707. not assigned(srsym) and
  708. (symtablestack.symtabletype=staticsymtable) and
  709. assigned(symtablestack.next) and
  710. (symtablestack.next.iscurrentunit) then
  711. begin
  712. { The procedure we prepare for is in the implementation
  713. part of the unit we compile. It is also possible that we
  714. are compiling a program, which is also some kind of
  715. implementaion part.
  716. We need to find out if the procedure is global. If it is
  717. global, it is in the global symtable.}
  718. srsym:=tsym(symtablestack.next.search(sp));
  719. end;
  720. { Check if overloaded is a procsym }
  721. if assigned(srsym) then
  722. begin
  723. if srsym.typ=procsym then
  724. aprocsym:=tprocsym(srsym)
  725. else
  726. begin
  727. { when the other symbol is a unit symbol then hide the unit
  728. symbol }
  729. if (srsym.typ=unitsym) then
  730. begin
  731. HideSym(srsym);
  732. searchagain:=true;
  733. end
  734. else
  735. begin
  736. { we use a different error message for tp7 so it looks more compatible }
  737. if (m_fpc in aktmodeswitches) then
  738. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  739. else
  740. DuplicateSym(nil,srsym);
  741. { rename the name to an unique name to avoid an
  742. error when inserting the symbol in the symtable }
  743. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  744. end;
  745. end;
  746. end;
  747. until not searchagain;
  748. end;
  749. { test again if assigned, it can be reset to recover }
  750. if not assigned(aprocsym) then
  751. begin
  752. { create a new procsym and set the real filepos }
  753. akttokenpos:=procstartfilepos;
  754. { for operator we have only one procsym for each overloaded
  755. operation }
  756. if (potype=potype_operator) then
  757. begin
  758. Aprocsym:=Tprocsym(symtablestack.search(sp));
  759. if Aprocsym=nil then
  760. Aprocsym:=tprocsym.create('$'+sp);
  761. end
  762. else
  763. aprocsym:=tprocsym.create(orgsp);
  764. symtablestack.insert(aprocsym);
  765. end;
  766. { to get the correct symtablelevel we must ignore objectsymtables }
  767. st:=symtablestack;
  768. while not(st.symtabletype in [staticsymtable,globalsymtable,localsymtable]) do
  769. st:=st.next;
  770. pd:=tprocdef.create(st.symtablelevel+1);
  771. pd._class:=aclass;
  772. pd.procsym:=aprocsym;
  773. pd.proctypeoption:=potype;
  774. { methods need to be exported }
  775. if assigned(aclass) and
  776. (
  777. (symtablestack.symtabletype=objectsymtable) or
  778. (symtablestack.symtablelevel=main_program_level)
  779. ) then
  780. include(pd.procoptions,po_global);
  781. { symbol options that need to be kept per procdef }
  782. pd.fileinfo:=procstartfilepos;
  783. pd.symoptions:=current_object_option;
  784. { parse parameters }
  785. if token=_LKLAMMER then
  786. parse_parameter_dec(pd);
  787. result:=true;
  788. end;
  789. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  790. var
  791. pd : tprocdef;
  792. isclassmethod : boolean;
  793. locationstr: string;
  794. begin
  795. locationstr:='';
  796. pd:=nil;
  797. isclassmethod:=false;
  798. { read class method }
  799. if try_to_consume(_CLASS) then
  800. begin
  801. { class method only allowed for procedures and functions }
  802. if not(token in [_FUNCTION,_PROCEDURE]) then
  803. Message(parser_e_procedure_or_function_expected);
  804. if is_interface(aclass) then
  805. Message(parser_e_no_static_method_in_interfaces)
  806. else
  807. isclassmethod:=true;
  808. end;
  809. case token of
  810. _FUNCTION :
  811. begin
  812. consume(_FUNCTION);
  813. if parse_proc_head(aclass,potype_function,pd) then
  814. begin
  815. { pd=nil when it is a interface mapping }
  816. if assigned(pd) then
  817. begin
  818. if try_to_consume(_COLON) then
  819. begin
  820. inc(testcurobject);
  821. single_type(pd.rettype,false);
  822. pd.test_if_fpu_result;
  823. dec(testcurobject);
  824. if (target_info.system in [system_m68k_amiga]) then
  825. begin
  826. if (idtoken=_LOCATION) then
  827. begin
  828. if po_explicitparaloc in pd.procoptions then
  829. begin
  830. consume(_LOCATION);
  831. locationstr:=pattern;
  832. consume(_CSTRING);
  833. end
  834. else
  835. { I guess this needs a new message... (KB) }
  836. Message(parser_e_paraloc_all_paras);
  837. end
  838. else
  839. begin
  840. if po_explicitparaloc in pd.procoptions then
  841. { assign default locationstr, if none specified }
  842. { and we've arguments with explicit paraloc }
  843. locationstr:='D0';
  844. end;
  845. end;
  846. end
  847. else
  848. begin
  849. if (
  850. parse_only and
  851. not(is_interface(pd._class))
  852. ) or
  853. (m_repeat_forward in aktmodeswitches) then
  854. begin
  855. consume(_COLON);
  856. consume_all_until(_SEMICOLON);
  857. end;
  858. end;
  859. if isclassmethod then
  860. include(pd.procoptions,po_classmethod);
  861. end;
  862. end
  863. else
  864. begin
  865. { recover }
  866. consume(_COLON);
  867. consume_all_until(_SEMICOLON);
  868. end;
  869. end;
  870. _PROCEDURE :
  871. begin
  872. consume(_PROCEDURE);
  873. if parse_proc_head(aclass,potype_procedure,pd) then
  874. begin
  875. { pd=nil when it is a interface mapping }
  876. if assigned(pd) then
  877. begin
  878. pd.rettype:=voidtype;
  879. if isclassmethod then
  880. include(pd.procoptions,po_classmethod);
  881. end;
  882. end;
  883. end;
  884. _CONSTRUCTOR :
  885. begin
  886. consume(_CONSTRUCTOR);
  887. parse_proc_head(aclass,potype_constructor,pd);
  888. if assigned(pd) and
  889. assigned(pd._class) then
  890. begin
  891. { Set return type, class constructors return the
  892. created instance, object constructors return boolean }
  893. if is_class(pd._class) then
  894. pd.rettype.setdef(pd._class)
  895. else
  896. pd.rettype:=booltype;
  897. end;
  898. end;
  899. _DESTRUCTOR :
  900. begin
  901. consume(_DESTRUCTOR);
  902. parse_proc_head(aclass,potype_destructor,pd);
  903. if assigned(pd) then
  904. pd.rettype:=voidtype;
  905. end;
  906. _OPERATOR :
  907. begin
  908. consume(_OPERATOR);
  909. if (token in [first_overloaded..last_overloaded]) then
  910. begin
  911. optoken:=token;
  912. end
  913. else
  914. begin
  915. Message(parser_e_overload_operator_failed);
  916. { Use the dummy NOTOKEN that is also declared
  917. for the overloaded_operator[] }
  918. optoken:=NOTOKEN;
  919. end;
  920. consume(token);
  921. parse_proc_head(aclass,potype_operator,pd);
  922. if assigned(pd) then
  923. begin
  924. if pd.parast.symtablelevel>normal_function_level then
  925. Message(parser_e_no_local_operator);
  926. if token<>_ID then
  927. begin
  928. if not(m_result in aktmodeswitches) then
  929. consume(_ID);
  930. end
  931. else
  932. begin
  933. pd.resultname:=orgpattern;
  934. consume(_ID);
  935. end;
  936. if not try_to_consume(_COLON) then
  937. begin
  938. consume(_COLON);
  939. pd.rettype:=generrortype;
  940. consume_all_until(_SEMICOLON);
  941. end
  942. else
  943. begin
  944. single_type(pd.rettype,false);
  945. pd.test_if_fpu_result;
  946. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  947. ((pd.rettype.def.deftype<>orddef) or
  948. (torddef(pd.rettype.def).typ<>bool8bit)) then
  949. Message(parser_e_comparative_operator_return_boolean);
  950. if (optoken=_ASSIGNMENT) and
  951. equal_defs(pd.rettype.def,
  952. tparavarsym(pd.parast.symindex.first).vartype.def) then
  953. message(parser_e_no_such_assignment)
  954. else if not isoperatoracceptable(pd,optoken) then
  955. Message(parser_e_overload_impossible);
  956. end;
  957. end
  958. else
  959. begin
  960. { recover }
  961. try_to_consume(_ID);
  962. consume(_COLON);
  963. consume_all_until(_SEMICOLON);
  964. end;
  965. end;
  966. end;
  967. { support procedure proc stdcall export; }
  968. if not(check_proc_directive(false)) then
  969. consume(_SEMICOLON);
  970. result:=pd;
  971. if locationstr<>'' then
  972. begin
  973. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  974. { I guess this needs a new message... (KB) }
  975. message(parser_e_illegal_explicit_paraloc);
  976. end;
  977. end;
  978. {****************************************************************************
  979. Procedure directive handlers
  980. ****************************************************************************}
  981. procedure pd_far(pd:tabstractprocdef);
  982. begin
  983. Message1(parser_w_proc_directive_ignored,'FAR');
  984. end;
  985. procedure pd_near(pd:tabstractprocdef);
  986. begin
  987. Message1(parser_w_proc_directive_ignored,'NEAR');
  988. end;
  989. procedure pd_export(pd:tabstractprocdef);
  990. begin
  991. if pd.deftype<>procdef then
  992. internalerror(200304264);
  993. if assigned(tprocdef(pd)._class) then
  994. Message(parser_e_methods_dont_be_export);
  995. if pd.parast.symtablelevel>normal_function_level then
  996. Message(parser_e_dont_nest_export);
  997. end;
  998. procedure pd_forward(pd:tabstractprocdef);
  999. begin
  1000. if pd.deftype<>procdef then
  1001. internalerror(200304265);
  1002. tprocdef(pd).forwarddef:=true;
  1003. end;
  1004. procedure pd_alias(pd:tabstractprocdef);
  1005. begin
  1006. if pd.deftype<>procdef then
  1007. internalerror(200304266);
  1008. consume(_COLON);
  1009. tprocdef(pd).aliasnames.insert(get_stringconst);
  1010. include(pd.procoptions,po_has_public_name);
  1011. end;
  1012. procedure pd_public(pd:tabstractprocdef);
  1013. begin
  1014. if pd.deftype<>procdef then
  1015. internalerror(200304266);
  1016. if try_to_consume(_NAME) then
  1017. begin
  1018. tprocdef(pd).aliasnames.insert(get_stringconst);
  1019. include(pd.procoptions,po_has_public_name);
  1020. end;
  1021. end;
  1022. procedure pd_asmname(pd:tabstractprocdef);
  1023. begin
  1024. if pd.deftype<>procdef then
  1025. internalerror(200304267);
  1026. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1027. if token=_CCHAR then
  1028. consume(_CCHAR)
  1029. else
  1030. consume(_CSTRING);
  1031. { we don't need anything else }
  1032. tprocdef(pd).forwarddef:=false;
  1033. end;
  1034. procedure pd_inline(pd:tabstractprocdef);
  1035. begin
  1036. { Check if there are parameters that can't be inlined }
  1037. pd.parast.foreach_static(@check_inline_para,pd);
  1038. end;
  1039. procedure pd_internconst(pd:tabstractprocdef);
  1040. begin
  1041. if pd.deftype<>procdef then
  1042. internalerror(200304268);
  1043. consume(_COLON);
  1044. tprocdef(pd).extnumber:=get_intconst;
  1045. end;
  1046. procedure pd_internproc(pd:tabstractprocdef);
  1047. begin
  1048. if pd.deftype<>procdef then
  1049. internalerror(200304268);
  1050. consume(_COLON);
  1051. tprocdef(pd).extnumber:=get_intconst;
  1052. { the proc is defined }
  1053. tprocdef(pd).forwarddef:=false;
  1054. end;
  1055. procedure pd_interrupt(pd:tabstractprocdef);
  1056. begin
  1057. if pd.parast.symtablelevel>normal_function_level then
  1058. Message(parser_e_dont_nest_interrupt);
  1059. end;
  1060. procedure pd_abstract(pd:tabstractprocdef);
  1061. begin
  1062. if pd.deftype<>procdef then
  1063. internalerror(200304269);
  1064. if (po_virtualmethod in pd.procoptions) then
  1065. include(pd.procoptions,po_abstractmethod)
  1066. else
  1067. Message(parser_e_only_virtual_methods_abstract);
  1068. { the method is defined }
  1069. tprocdef(pd).forwarddef:=false;
  1070. end;
  1071. procedure pd_virtual(pd:tabstractprocdef);
  1072. {$ifdef WITHDMT}
  1073. var
  1074. pt : tnode;
  1075. {$endif WITHDMT}
  1076. begin
  1077. if pd.deftype<>procdef then
  1078. internalerror(2003042610);
  1079. if (pd.proctypeoption=potype_constructor) and
  1080. is_object(tprocdef(pd)._class) then
  1081. Message(parser_e_constructor_cannot_be_not_virtual);
  1082. {$ifdef WITHDMT}
  1083. if is_object(tprocdef(pd)._class) and
  1084. (token<>_SEMICOLON) then
  1085. begin
  1086. { any type of parameter is allowed here! }
  1087. pt:=comp_expr(true);
  1088. if is_constintnode(pt) then
  1089. begin
  1090. include(pd.procoptions,po_msgint);
  1091. pd.messageinf.i:=pt^.value;
  1092. end
  1093. else
  1094. Message(parser_e_ill_msg_expr);
  1095. disposetree(pt);
  1096. end;
  1097. {$endif WITHDMT}
  1098. end;
  1099. procedure pd_static(pd:tabstractprocdef);
  1100. begin
  1101. if (cs_static_keyword in aktmoduleswitches) then
  1102. begin
  1103. if pd.deftype=procdef then
  1104. include(tprocdef(pd).procsym.symoptions,sp_static);
  1105. include(pd.procoptions,po_staticmethod);
  1106. end;
  1107. end;
  1108. procedure pd_override(pd:tabstractprocdef);
  1109. begin
  1110. if pd.deftype<>procdef then
  1111. internalerror(2003042611);
  1112. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1113. Message(parser_e_no_object_override);
  1114. end;
  1115. procedure pd_overload(pd:tabstractprocdef);
  1116. begin
  1117. if pd.deftype<>procdef then
  1118. internalerror(2003042612);
  1119. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1120. end;
  1121. procedure pd_message(pd:tabstractprocdef);
  1122. var
  1123. pt : tnode;
  1124. paracnt : longint;
  1125. begin
  1126. if pd.deftype<>procdef then
  1127. internalerror(2003042613);
  1128. if not is_class(tprocdef(pd)._class) then
  1129. Message(parser_e_msg_only_for_classes);
  1130. { check parameter type }
  1131. paracnt:=0;
  1132. pd.parast.foreach_static(@check_msg_para,@paracnt);
  1133. if paracnt<>1 then
  1134. Message(parser_e_ill_msg_param);
  1135. pt:=comp_expr(true);
  1136. if pt.nodetype=stringconstn then
  1137. begin
  1138. include(pd.procoptions,po_msgstr);
  1139. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1140. end
  1141. else
  1142. if is_constintnode(pt) then
  1143. begin
  1144. include(pd.procoptions,po_msgint);
  1145. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1146. end
  1147. else
  1148. Message(parser_e_ill_msg_expr);
  1149. pt.free;
  1150. end;
  1151. procedure pd_reintroduce(pd:tabstractprocdef);
  1152. begin
  1153. if pd.deftype<>procdef then
  1154. internalerror(200401211);
  1155. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1156. Message(parser_e_no_object_reintroduce);
  1157. end;
  1158. procedure pd_syscall(pd:tabstractprocdef);
  1159. {$if defined(powerpc) or defined(m68k)}
  1160. var
  1161. vs : tparavarsym;
  1162. sym : tsym;
  1163. symtable : tsymtable;
  1164. {$endif defined(powerpc) or defined(m68k)}
  1165. begin
  1166. if pd.deftype<>procdef then
  1167. internalerror(2003042614);
  1168. tprocdef(pd).forwarddef:=false;
  1169. {$ifdef m68k}
  1170. if target_info.system in [system_m68k_amiga] then
  1171. begin
  1172. include(pd.procoptions,po_syscall_legacy);
  1173. if consume_sym(sym,symtable) then
  1174. begin
  1175. if (sym.typ=globalvarsym) and
  1176. (
  1177. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1178. is_32bitint(tabstractvarsym(sym).vartype.def)
  1179. ) then
  1180. begin
  1181. tprocdef(pd).libsym:=sym;
  1182. if po_syscall_legacy in tprocdef(pd).procoptions then
  1183. begin
  1184. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1185. paramanager.parseparaloc(vs,'A6');
  1186. pd.parast.insert(vs);
  1187. end
  1188. end
  1189. else
  1190. Message(parser_e_32bitint_or_pointer_variable_expected);
  1191. end;
  1192. (paramanager as tm68kparamanager).create_funcretloc_info(pd,calleeside);
  1193. (paramanager as tm68kparamanager).create_funcretloc_info(pd,callerside);
  1194. end;
  1195. {$endif m68k}
  1196. {$ifdef powerpc}
  1197. if target_info.system in [system_powerpc_morphos] then
  1198. begin
  1199. if idtoken=_LEGACY then
  1200. begin
  1201. consume(_LEGACY);
  1202. include(pd.procoptions,po_syscall_legacy);
  1203. end
  1204. else if idtoken=_SYSV then
  1205. begin
  1206. consume(_SYSV);
  1207. include(pd.procoptions,po_syscall_sysv);
  1208. end
  1209. else if idtoken=_BASESYSV then
  1210. begin
  1211. consume(_BASESYSV);
  1212. include(pd.procoptions,po_syscall_basesysv);
  1213. end
  1214. else if idtoken=_SYSVBASE then
  1215. begin
  1216. consume(_SYSVBASE);
  1217. include(pd.procoptions,po_syscall_sysvbase);
  1218. end
  1219. else if idtoken=_R12BASE then
  1220. begin
  1221. consume(_R12BASE);
  1222. include(pd.procoptions,po_syscall_r12base);
  1223. end
  1224. else
  1225. if syscall_convention='LEGACY' then
  1226. include(pd.procoptions,po_syscall_legacy)
  1227. else if syscall_convention='SYSV' then
  1228. include(pd.procoptions,po_syscall_sysv)
  1229. else if syscall_convention='BASESYSV' then
  1230. include(pd.procoptions,po_syscall_basesysv)
  1231. else if syscall_convention='SYSVBASE' then
  1232. include(pd.procoptions,po_syscall_sysvbase)
  1233. else if syscall_convention='R12BASE' then
  1234. include(pd.procoptions,po_syscall_r12base)
  1235. else
  1236. internalerror(2005010404);
  1237. if consume_sym(sym,symtable) then
  1238. begin
  1239. if (sym.typ=globalvarsym) and
  1240. (
  1241. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1242. is_32bitint(tabstractvarsym(sym).vartype.def)
  1243. ) then
  1244. begin
  1245. tprocdef(pd).libsym:=sym;
  1246. if po_syscall_legacy in tprocdef(pd).procoptions then
  1247. begin
  1248. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1249. paramanager.parseparaloc(vs,'A6');
  1250. pd.parast.insert(vs);
  1251. end
  1252. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1253. begin
  1254. { Nothing to be done for sysv here for now, but this might change }
  1255. end
  1256. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1257. begin
  1258. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1259. pd.parast.insert(vs);
  1260. end
  1261. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1262. begin
  1263. vs:=tparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1264. pd.parast.insert(vs);
  1265. end
  1266. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1267. begin
  1268. vs:=tparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1269. paramanager.parseparaloc(vs,'R12');
  1270. pd.parast.insert(vs);
  1271. end
  1272. else
  1273. internalerror(2005010501);
  1274. end
  1275. else
  1276. Message(parser_e_32bitint_or_pointer_variable_expected);
  1277. end;
  1278. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1279. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1280. end;
  1281. {$endif powerpc}
  1282. tprocdef(pd).extnumber:=get_intconst;
  1283. end;
  1284. procedure pd_external(pd:tabstractprocdef);
  1285. {
  1286. If import_dll=nil the procedure is assumed to be in another
  1287. object file. In that object file it should have the name to
  1288. which import_name is pointing to. Otherwise, the procedure is
  1289. assumed to be in the DLL to which import_dll is pointing to. In
  1290. that case either import_nr<>0 or import_name<>nil is true, so
  1291. the procedure is either imported by number or by name. (DM)
  1292. }
  1293. begin
  1294. if pd.deftype<>procdef then
  1295. internalerror(2003042615);
  1296. with tprocdef(pd) do
  1297. begin
  1298. forwarddef:=false;
  1299. { forbid local external procedures }
  1300. if parast.symtablelevel>normal_function_level then
  1301. Message(parser_e_no_local_proc_external);
  1302. { If the procedure should be imported from a DLL, a constant string follows.
  1303. This isn't really correct, an contant string expression follows
  1304. so we check if an semicolon follows, else a string constant have to
  1305. follow (FK) }
  1306. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1307. begin
  1308. import_dll:=stringdup(get_stringconst);
  1309. if (idtoken=_NAME) then
  1310. begin
  1311. consume(_NAME);
  1312. import_name:=stringdup(get_stringconst);
  1313. if import_name^='' then
  1314. message(parser_e_empty_import_name);
  1315. end;
  1316. if (idtoken=_INDEX) then
  1317. begin
  1318. {After the word index follows the index number in the DLL.}
  1319. consume(_INDEX);
  1320. import_nr:=get_intconst;
  1321. end;
  1322. { default is to used the realname of the procedure }
  1323. if (import_nr=0) and not assigned(import_name) then
  1324. import_name:=stringdup(procsym.realname);
  1325. end
  1326. else
  1327. begin
  1328. if (idtoken=_NAME) then
  1329. begin
  1330. consume(_NAME);
  1331. import_name:=stringdup(get_stringconst);
  1332. if import_name^='' then
  1333. message(parser_e_empty_import_name);
  1334. end;
  1335. end;
  1336. end;
  1337. end;
  1338. type
  1339. pd_handler=procedure(pd:tabstractprocdef);
  1340. proc_dir_rec=record
  1341. idtok : ttoken;
  1342. pd_flags : tpdflags;
  1343. handler : pd_handler;
  1344. pocall : tproccalloption;
  1345. pooption : tprocoptions;
  1346. mutexclpocall : tproccalloptions;
  1347. mutexclpotype : tproctypeoptions;
  1348. mutexclpo : tprocoptions;
  1349. end;
  1350. const
  1351. {Should contain the number of procedure directives we support.}
  1352. num_proc_directives=37;
  1353. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1354. (
  1355. (
  1356. idtok:_ABSTRACT;
  1357. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1358. handler : @pd_abstract;
  1359. pocall : pocall_none;
  1360. pooption : [po_abstractmethod];
  1361. mutexclpocall : [pocall_internproc];
  1362. mutexclpotype : [];
  1363. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  1364. ),(
  1365. idtok:_ALIAS;
  1366. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1367. handler : @pd_alias;
  1368. pocall : pocall_none;
  1369. pooption : [];
  1370. mutexclpocall : [];
  1371. mutexclpotype : [];
  1372. mutexclpo : [po_external,po_inline]
  1373. ),(
  1374. idtok:_ASMNAME;
  1375. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1376. handler : @pd_asmname;
  1377. pocall : pocall_cdecl;
  1378. pooption : [po_external];
  1379. mutexclpocall : [pocall_internproc];
  1380. mutexclpotype : [];
  1381. mutexclpo : [po_external,po_inline]
  1382. ),(
  1383. idtok:_ASSEMBLER;
  1384. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1385. handler : nil;
  1386. pocall : pocall_none;
  1387. pooption : [po_assembler];
  1388. mutexclpocall : [];
  1389. mutexclpotype : [];
  1390. mutexclpo : [po_external]
  1391. ),(
  1392. idtok:_C; {same as cdecl for mode mac}
  1393. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1394. handler : nil;
  1395. pocall : pocall_cdecl;
  1396. pooption : [];
  1397. mutexclpocall : [];
  1398. mutexclpotype : [potype_constructor,potype_destructor];
  1399. mutexclpo : [po_assembler,po_external]
  1400. ),(
  1401. idtok:_CDECL;
  1402. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1403. handler : nil;
  1404. pocall : pocall_cdecl;
  1405. pooption : [];
  1406. mutexclpocall : [];
  1407. mutexclpotype : [potype_constructor,potype_destructor];
  1408. mutexclpo : [po_assembler,po_external]
  1409. ),(
  1410. idtok:_DYNAMIC;
  1411. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1412. handler : @pd_virtual;
  1413. pocall : pocall_none;
  1414. pooption : [po_virtualmethod];
  1415. mutexclpocall : [pocall_internproc];
  1416. mutexclpotype : [];
  1417. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  1418. ),(
  1419. idtok:_EXPORT;
  1420. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1421. handler : @pd_export;
  1422. pocall : pocall_none;
  1423. pooption : [po_exports,po_global];
  1424. mutexclpocall : [pocall_internproc];
  1425. mutexclpotype : [potype_constructor,potype_destructor];
  1426. mutexclpo : [po_external,po_interrupt,po_inline]
  1427. ),(
  1428. idtok:_EXTERNAL;
  1429. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1430. handler : @pd_external;
  1431. pocall : pocall_none;
  1432. pooption : [po_external];
  1433. mutexclpocall : [pocall_internproc,pocall_syscall];
  1434. mutexclpotype : [potype_constructor,potype_destructor];
  1435. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  1436. ),(
  1437. idtok:_FAR;
  1438. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1439. handler : @pd_far;
  1440. pocall : pocall_none;
  1441. pooption : [];
  1442. mutexclpocall : [pocall_internproc];
  1443. mutexclpotype : [];
  1444. mutexclpo : [po_inline]
  1445. ),(
  1446. idtok:_FAR16;
  1447. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1448. handler : nil;
  1449. pocall : pocall_far16;
  1450. pooption : [];
  1451. mutexclpocall : [];
  1452. mutexclpotype : [];
  1453. mutexclpo : [po_external]
  1454. ),(
  1455. idtok:_FORWARD;
  1456. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1457. handler : @pd_forward;
  1458. pocall : pocall_none;
  1459. pooption : [];
  1460. mutexclpocall : [pocall_internproc];
  1461. mutexclpotype : [];
  1462. mutexclpo : [po_external,po_inline]
  1463. ),(
  1464. idtok:_OLDFPCCALL;
  1465. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1466. handler : nil;
  1467. pocall : pocall_oldfpccall;
  1468. pooption : [];
  1469. mutexclpocall : [];
  1470. mutexclpotype : [];
  1471. mutexclpo : []
  1472. ),(
  1473. idtok:_INLINE;
  1474. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1475. handler : @pd_inline;
  1476. pocall : pocall_none;
  1477. pooption : [po_inline];
  1478. mutexclpocall : [];
  1479. mutexclpotype : [potype_constructor,potype_destructor];
  1480. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1481. ),(
  1482. idtok:_INTERNCONST;
  1483. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf];
  1484. handler : @pd_internconst;
  1485. pocall : pocall_none;
  1486. pooption : [po_internconst];
  1487. mutexclpocall : [];
  1488. mutexclpotype : [potype_operator];
  1489. mutexclpo : []
  1490. ),(
  1491. idtok:_INTERNPROC;
  1492. pd_flags : [pd_interface,pd_notobject,pd_notobjintf];
  1493. handler : @pd_internproc;
  1494. pocall : pocall_internproc;
  1495. pooption : [];
  1496. mutexclpocall : [];
  1497. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1498. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1499. ),(
  1500. idtok:_INTERRUPT;
  1501. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1502. handler : @pd_interrupt;
  1503. pocall : pocall_none;
  1504. pooption : [po_interrupt];
  1505. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1506. pocall_pascal,pocall_far16,pocall_oldfpccall];
  1507. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1508. mutexclpo : [po_external,po_inline]
  1509. ),(
  1510. idtok:_IOCHECK;
  1511. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1512. handler : nil;
  1513. pocall : pocall_none;
  1514. pooption : [po_iocheck];
  1515. mutexclpocall : [pocall_internproc];
  1516. mutexclpotype : [];
  1517. mutexclpo : [po_external]
  1518. ),(
  1519. idtok:_MESSAGE;
  1520. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1521. handler : @pd_message;
  1522. pocall : pocall_none;
  1523. pooption : []; { can be po_msgstr or po_msgint }
  1524. mutexclpocall : [pocall_internproc];
  1525. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1526. mutexclpo : [po_interrupt,po_external,po_inline]
  1527. ),(
  1528. idtok:_MWPASCAL;
  1529. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1530. handler : nil;
  1531. pocall : pocall_mwpascal;
  1532. pooption : [];
  1533. mutexclpocall : [];
  1534. mutexclpotype : [];
  1535. mutexclpo : []
  1536. ),(
  1537. idtok:_NEAR;
  1538. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1539. handler : @pd_near;
  1540. pocall : pocall_none;
  1541. pooption : [];
  1542. mutexclpocall : [pocall_internproc];
  1543. mutexclpotype : [];
  1544. mutexclpo : []
  1545. ),(
  1546. idtok:_NOSTACKFRAME;
  1547. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1548. handler : nil;
  1549. pocall : pocall_none;
  1550. pooption : [po_nostackframe];
  1551. mutexclpocall : [pocall_internproc];
  1552. mutexclpotype : [];
  1553. mutexclpo : []
  1554. ),(
  1555. idtok:_OVERLOAD;
  1556. pd_flags : [pd_implemen,pd_interface,pd_body];
  1557. handler : @pd_overload;
  1558. pocall : pocall_none;
  1559. pooption : [po_overload];
  1560. mutexclpocall : [pocall_internproc];
  1561. mutexclpotype : [];
  1562. mutexclpo : []
  1563. ),(
  1564. idtok:_OVERRIDE;
  1565. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1566. handler : @pd_override;
  1567. pocall : pocall_none;
  1568. pooption : [po_overridingmethod,po_virtualmethod];
  1569. mutexclpocall : [pocall_internproc];
  1570. mutexclpotype : [];
  1571. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_inline]
  1572. ),(
  1573. idtok:_PASCAL;
  1574. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1575. handler : nil;
  1576. pocall : pocall_pascal;
  1577. pooption : [];
  1578. mutexclpocall : [];
  1579. mutexclpotype : [potype_constructor,potype_destructor];
  1580. mutexclpo : [po_external]
  1581. ),(
  1582. idtok:_PUBLIC;
  1583. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1584. handler : @pd_public;
  1585. pocall : pocall_none;
  1586. pooption : [po_public,po_global];
  1587. mutexclpocall : [pocall_internproc];
  1588. mutexclpotype : [];
  1589. mutexclpo : [po_external,po_inline]
  1590. ),(
  1591. idtok:_REGISTER;
  1592. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1593. handler : nil;
  1594. pocall : pocall_register;
  1595. pooption : [];
  1596. mutexclpocall : [];
  1597. mutexclpotype : [potype_constructor,potype_destructor];
  1598. mutexclpo : [po_external]
  1599. ),(
  1600. idtok:_REINTRODUCE;
  1601. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1602. handler : @pd_reintroduce;
  1603. pocall : pocall_none;
  1604. pooption : [po_reintroduce];
  1605. mutexclpocall : [pocall_internproc];
  1606. mutexclpotype : [];
  1607. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1608. ),(
  1609. idtok:_SAFECALL;
  1610. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1611. handler : nil;
  1612. pocall : pocall_safecall;
  1613. pooption : [];
  1614. mutexclpocall : [];
  1615. mutexclpotype : [potype_constructor,potype_destructor];
  1616. mutexclpo : [po_external]
  1617. ),(
  1618. idtok:_SOFTFLOAT;
  1619. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1620. handler : nil;
  1621. pocall : pocall_softfloat;
  1622. pooption : [];
  1623. mutexclpocall : [];
  1624. mutexclpotype : [potype_constructor,potype_destructor];
  1625. { it's available with po_external because the libgcc floating point routines on the arm
  1626. uses this calling convention }
  1627. mutexclpo : []
  1628. ),(
  1629. idtok:_STATIC;
  1630. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1631. handler : @pd_static;
  1632. pocall : pocall_none;
  1633. pooption : [po_staticmethod];
  1634. mutexclpocall : [pocall_internproc];
  1635. mutexclpotype : [potype_constructor,potype_destructor];
  1636. mutexclpo : [po_external,po_interrupt,po_exports,po_inline]
  1637. ),(
  1638. idtok:_STDCALL;
  1639. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1640. handler : nil;
  1641. pocall : pocall_stdcall;
  1642. pooption : [];
  1643. mutexclpocall : [];
  1644. mutexclpotype : [potype_constructor,potype_destructor];
  1645. mutexclpo : [po_external]
  1646. ),(
  1647. idtok:_SYSCALL;
  1648. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf];
  1649. handler : @pd_syscall;
  1650. pocall : pocall_syscall;
  1651. pooption : [];
  1652. mutexclpocall : [];
  1653. mutexclpotype : [potype_constructor,potype_destructor];
  1654. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1655. ),(
  1656. idtok:_VIRTUAL;
  1657. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1658. handler : @pd_virtual;
  1659. pocall : pocall_none;
  1660. pooption : [po_virtualmethod];
  1661. mutexclpocall : [pocall_internproc];
  1662. mutexclpotype : [];
  1663. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1664. ),(
  1665. idtok:_CPPDECL;
  1666. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1667. handler : nil;
  1668. pocall : pocall_cppdecl;
  1669. pooption : [];
  1670. mutexclpocall : [];
  1671. mutexclpotype : [potype_constructor,potype_destructor];
  1672. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1673. ),(
  1674. idtok:_VARARGS;
  1675. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1676. handler : nil;
  1677. pocall : pocall_none;
  1678. pooption : [po_varargs];
  1679. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1680. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  1681. mutexclpotype : [];
  1682. mutexclpo : [po_assembler,po_interrupt,po_inline]
  1683. ),(
  1684. idtok:_COMPILERPROC;
  1685. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1686. handler : nil;
  1687. pocall : pocall_none;
  1688. pooption : [po_compilerproc];
  1689. mutexclpocall : [];
  1690. mutexclpotype : [potype_constructor,potype_destructor];
  1691. mutexclpo : [po_interrupt]
  1692. )
  1693. );
  1694. function check_proc_directive(isprocvar:boolean):boolean;
  1695. var
  1696. i : longint;
  1697. begin
  1698. result:=false;
  1699. for i:=1 to num_proc_directives do
  1700. if proc_direcdata[i].idtok=idtoken then
  1701. begin
  1702. if ((not isprocvar) or
  1703. (pd_procvar in proc_direcdata[i].pd_flags)) and
  1704. { don't eat a public directive in classes }
  1705. not((idtoken=_PUBLIC) and (symtablestack.symtabletype=objectsymtable)) then
  1706. result:=true;
  1707. exit;
  1708. end;
  1709. end;
  1710. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1711. {
  1712. Parse the procedure directive, returns true if a correct directive is found
  1713. }
  1714. var
  1715. p : longint;
  1716. found : boolean;
  1717. name : stringid;
  1718. begin
  1719. parse_proc_direc:=false;
  1720. name:=tokeninfo^[idtoken].str;
  1721. found:=false;
  1722. { Hint directive? Then exit immediatly }
  1723. if (m_hintdirective in aktmodeswitches) then
  1724. begin
  1725. case idtoken of
  1726. _LIBRARY,
  1727. _PLATFORM,
  1728. _UNIMPLEMENTED,
  1729. _DEPRECATED :
  1730. exit;
  1731. end;
  1732. end;
  1733. { C directive is MAC only, because it breaks too much existing code
  1734. on other platforms (PFV) }
  1735. if (idtoken=_C) and
  1736. not(m_mac in aktmodeswitches) then
  1737. exit;
  1738. { retrieve data for directive if found }
  1739. for p:=1 to num_proc_directives do
  1740. if proc_direcdata[p].idtok=idtoken then
  1741. begin
  1742. found:=true;
  1743. break;
  1744. end;
  1745. { Check if the procedure directive is known }
  1746. if not found then
  1747. begin
  1748. { parsing a procvar type the name can be any
  1749. next variable !! }
  1750. if ((pdflags * [pd_procvar,pd_object])=[]) and
  1751. not(idtoken=_PROPERTY) then
  1752. Message1(parser_w_unknown_proc_directive_ignored,name);
  1753. exit;
  1754. end;
  1755. { static needs a special treatment }
  1756. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1757. exit;
  1758. { check if method and directive not for object, like public.
  1759. This needs to be checked also for procvars }
  1760. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1761. (symtablestack.symtabletype=objectsymtable) then
  1762. exit;
  1763. { Conflicts between directives ? }
  1764. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1765. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1766. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1767. begin
  1768. Message1(parser_e_proc_dir_conflict,name);
  1769. exit;
  1770. end;
  1771. { set calling convention }
  1772. if proc_direcdata[p].pocall<>pocall_none then
  1773. begin
  1774. if (po_hascallingconvention in pd.procoptions) then
  1775. begin
  1776. Message2(parser_w_proc_overriding_calling,
  1777. proccalloptionStr[pd.proccalloption],
  1778. proccalloptionStr[proc_direcdata[p].pocall]);
  1779. end;
  1780. { check if the target processor supports this calling convention }
  1781. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1782. begin
  1783. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1784. { recover }
  1785. proc_direcdata[p].pocall:=pocall_stdcall;
  1786. end;
  1787. pd.proccalloption:=proc_direcdata[p].pocall;
  1788. include(pd.procoptions,po_hascallingconvention);
  1789. end;
  1790. if pd.deftype=procdef then
  1791. begin
  1792. { Check if the directive is only for objects }
  1793. if (pd_object in proc_direcdata[p].pd_flags) and
  1794. not assigned(tprocdef(pd)._class) then
  1795. exit;
  1796. { check if method and directive not for interface }
  1797. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1798. is_interface(tprocdef(pd)._class) then
  1799. exit;
  1800. end;
  1801. { consume directive, and turn flag on }
  1802. consume(token);
  1803. parse_proc_direc:=true;
  1804. { Check the pd_flags if the directive should be allowed }
  1805. if (pd_interface in pdflags) and
  1806. not(pd_interface in proc_direcdata[p].pd_flags) then
  1807. begin
  1808. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1809. exit;
  1810. end;
  1811. if (pd_implemen in pdflags) and
  1812. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1813. begin
  1814. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1815. exit;
  1816. end;
  1817. if (pd_procvar in pdflags) and
  1818. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1819. begin
  1820. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1821. exit;
  1822. end;
  1823. { Return the new pd_flags }
  1824. if not(pd_body in proc_direcdata[p].pd_flags) then
  1825. exclude(pdflags,pd_body);
  1826. { Add the correct flag }
  1827. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1828. { Call the handler }
  1829. if pointer(proc_direcdata[p].handler)<>nil then
  1830. proc_direcdata[p].handler(pd);
  1831. end;
  1832. function proc_get_importname(pd:tprocdef):string;
  1833. begin
  1834. result:='';
  1835. if not(po_external in pd.procoptions) then
  1836. internalerror(200412151);
  1837. { import by number? }
  1838. if pd.import_nr<>0 then
  1839. begin
  1840. { Nothing to do }
  1841. end
  1842. else
  1843. { external name specified }
  1844. if assigned(pd.import_name) then
  1845. begin
  1846. { Win32 imports need to use the normal name since to functions
  1847. can refer to the same DLL function. This is also needed for compatability
  1848. with Delphi and TP7 }
  1849. if not(
  1850. assigned(pd.import_dll) and
  1851. (target_info.system in [system_i386_win32,system_i386_wdosx,
  1852. system_i386_emx,system_i386_os2,system_arm_wince,system_i386_wince])
  1853. ) then
  1854. begin
  1855. if not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1856. result:=pd.import_name^
  1857. else
  1858. result:=target_info.Cprefix+pd.import_name^;
  1859. end;
  1860. end
  1861. else
  1862. begin
  1863. { Default names when importing variables }
  1864. case pd.proccalloption of
  1865. pocall_cdecl :
  1866. begin
  1867. if assigned(pd._class) then
  1868. result:=target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname
  1869. else
  1870. result:=target_info.Cprefix+pd.procsym.realname;
  1871. end;
  1872. pocall_cppdecl :
  1873. begin
  1874. result:=target_info.Cprefix+pd.cplusplusmangledname;
  1875. end;
  1876. else
  1877. begin
  1878. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  1879. if (m_mac in aktmodeswitches) then
  1880. result:=tprocdef(pd).procsym.realname;
  1881. end;
  1882. end;
  1883. end;
  1884. end;
  1885. procedure proc_set_mangledname(pd:tprocdef);
  1886. var
  1887. s : string;
  1888. begin
  1889. { When the mangledname is already set we aren't allowed to change
  1890. it because it can already be used somewhere (PFV) }
  1891. if not(po_has_mangledname in pd.procoptions) then
  1892. begin
  1893. if (po_external in pd.procoptions) then
  1894. begin
  1895. { External Procedures are only allowed to change the mangledname
  1896. in their first declaration }
  1897. if (pd.forwarddef or (not pd.hasforward)) then
  1898. begin
  1899. s:=proc_get_importname(pd);
  1900. if s<>'' then
  1901. pd.setmangledname(s);
  1902. end;
  1903. end
  1904. else
  1905. { Normal procedures }
  1906. begin
  1907. if (po_compilerproc in pd.procoptions) then
  1908. begin
  1909. pd.setmangledname(lower(pd.procsym.name));
  1910. end;
  1911. end;
  1912. end;
  1913. { Public/exported alias names }
  1914. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  1915. not(po_has_public_name in pd.procoptions) then
  1916. begin
  1917. case pd.proccalloption of
  1918. pocall_cdecl :
  1919. begin
  1920. if assigned(pd._class) then
  1921. pd.aliasnames.insert(target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname)
  1922. else
  1923. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  1924. end;
  1925. pocall_cppdecl :
  1926. begin
  1927. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  1928. end;
  1929. end;
  1930. { prevent adding the alias a second time }
  1931. include(pd.procoptions,po_has_public_name);
  1932. end;
  1933. end;
  1934. procedure handle_calling_convention(pd:tabstractprocdef);
  1935. begin
  1936. { set the default calling convention if none provided }
  1937. if not(po_hascallingconvention in pd.procoptions) then
  1938. pd.proccalloption:=aktdefproccall
  1939. else
  1940. begin
  1941. if pd.proccalloption=pocall_none then
  1942. internalerror(200309081);
  1943. end;
  1944. { handle proccall specific settings }
  1945. case pd.proccalloption of
  1946. pocall_cdecl,
  1947. pocall_cppdecl :
  1948. begin
  1949. { check C cdecl para types }
  1950. pd.parast.foreach_static(@check_c_para,nil);
  1951. end;
  1952. pocall_far16 :
  1953. begin
  1954. { Temporary stub, must be rewritten to support OS/2 far16 }
  1955. Message1(parser_w_proc_directive_ignored,'FAR16');
  1956. end;
  1957. end;
  1958. if (po_inline in pd.procoptions) then
  1959. begin
  1960. if not(cs_support_inline in aktmoduleswitches) then
  1961. begin
  1962. Message(parser_e_proc_inline_not_supported);
  1963. exclude(pd.procoptions,po_inline);
  1964. end;
  1965. end;
  1966. { For varargs directive also cdecl and external must be defined }
  1967. if (po_varargs in pd.procoptions) then
  1968. begin
  1969. { check first for external in the interface, if available there
  1970. then the cdecl must also be there since there is no implementation
  1971. available to contain it }
  1972. if parse_only then
  1973. begin
  1974. { if external is available, then cdecl must also be available,
  1975. procvars don't need external }
  1976. if not((po_external in pd.procoptions) or
  1977. (pd.deftype=procvardef)) and
  1978. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1979. Message(parser_e_varargs_need_cdecl_and_external);
  1980. end
  1981. else
  1982. begin
  1983. { both must be defined now }
  1984. if not((po_external in pd.procoptions) or
  1985. (pd.deftype=procvardef)) or
  1986. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1987. Message(parser_e_varargs_need_cdecl_and_external);
  1988. end;
  1989. end;
  1990. { insert hidden high parameters }
  1991. pd.parast.foreach_static(@insert_hidden_para,pd);
  1992. { insert hidden self parameter }
  1993. insert_self_and_vmt_para(pd);
  1994. { insert funcret parameter if required }
  1995. insert_funcret_para(pd);
  1996. { Make var parameters regable, this must be done after the calling
  1997. convention is set. }
  1998. { this must be done before parentfp is insert, because getting all cases
  1999. where parentfp must be in a memory location isn't catched properly so
  2000. we put parentfp never in a register }
  2001. pd.parast.foreach_static(@set_addr_param_regable,pd);
  2002. { insert parentfp parameter if required }
  2003. insert_parentfp_para(pd);
  2004. { Calculate parameter tlist }
  2005. pd.calcparas;
  2006. end;
  2007. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2008. {
  2009. Parse the procedure directives. It does not matter if procedure directives
  2010. are written using ;procdir; or ['procdir'] syntax.
  2011. }
  2012. var
  2013. res : boolean;
  2014. begin
  2015. if (m_mac in aktmodeswitches) and (cs_externally_visible in aktlocalswitches) then
  2016. begin
  2017. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  2018. include(pd.procoptions,po_public);
  2019. include(pd.procoptions,po_has_public_name);
  2020. include(pd.procoptions,po_global);
  2021. end;
  2022. while token in [_ID,_LECKKLAMMER] do
  2023. begin
  2024. if try_to_consume(_LECKKLAMMER) then
  2025. begin
  2026. repeat
  2027. parse_proc_direc(pd,pdflags);
  2028. until not try_to_consume(_COMMA);
  2029. consume(_RECKKLAMMER);
  2030. { we always expect at least '[];' }
  2031. res:=true;
  2032. end
  2033. else
  2034. begin
  2035. res:=parse_proc_direc(pd,pdflags);
  2036. end;
  2037. { A procedure directive normally followed by a semicolon, but in
  2038. a const section or reading a type we should stop when _EQUAL is found,
  2039. because a constant/default value follows }
  2040. if res then
  2041. begin
  2042. if (block_type in [bt_const,bt_type]) and
  2043. (token=_EQUAL) then
  2044. break;
  2045. { support procedure proc;stdcall export; }
  2046. if not(check_proc_directive((pd.deftype=procvardef))) then
  2047. begin
  2048. { support "record p : procedure stdcall end;" and
  2049. "var p : procedure stdcall = nil;" }
  2050. if (pd_procvar in pdflags) and
  2051. (token in [_END,_RKLAMMER,_EQUAL]) then
  2052. break
  2053. else
  2054. consume(_SEMICOLON);
  2055. end;
  2056. end
  2057. else
  2058. break;
  2059. end;
  2060. end;
  2061. procedure parse_var_proc_directives(sym:tsym);
  2062. var
  2063. pdflags : tpdflags;
  2064. pd : tabstractprocdef;
  2065. begin
  2066. pdflags:=[pd_procvar];
  2067. pd:=nil;
  2068. case sym.typ of
  2069. fieldvarsym,
  2070. globalvarsym,
  2071. localvarsym,
  2072. paravarsym :
  2073. pd:=tabstractprocdef(tabstractvarsym(sym).vartype.def);
  2074. typedconstsym :
  2075. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  2076. typesym :
  2077. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  2078. else
  2079. internalerror(2003042617);
  2080. end;
  2081. if pd.deftype<>procvardef then
  2082. internalerror(2003042618);
  2083. { names should never be used anyway }
  2084. parse_proc_directives(pd,pdflags);
  2085. end;
  2086. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2087. var
  2088. pdflags : tpdflags;
  2089. begin
  2090. pdflags:=[pd_object];
  2091. parse_proc_directives(pd,pdflags);
  2092. end;
  2093. function proc_add_definition(var pd:tprocdef):boolean;
  2094. {
  2095. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2096. forwarddef is found and reused it returns true
  2097. }
  2098. var
  2099. hd : tprocdef;
  2100. ad,fd : tsym;
  2101. s1,s2 : stringid;
  2102. i : cardinal;
  2103. forwardfound : boolean;
  2104. po_comp : tprocoptions;
  2105. aprocsym : tprocsym;
  2106. begin
  2107. forwardfound:=false;
  2108. aprocsym:=tprocsym(pd.procsym);
  2109. { check overloaded functions if the same function already exists }
  2110. for i:=1 to aprocsym.procdef_count do
  2111. begin
  2112. hd:=aprocsym.procdef[i];
  2113. { Skip overloaded definitions that are declared in other
  2114. units }
  2115. if hd.procsym<>aprocsym then
  2116. continue;
  2117. { check the parameters, for delphi/tp it is possible to
  2118. leave the parameters away in the implementation (forwarddef=false).
  2119. But for an overload declared function this is not allowed }
  2120. if { check if empty implementation arguments match is allowed }
  2121. (
  2122. not(m_repeat_forward in aktmodeswitches) and
  2123. not(pd.forwarddef) and
  2124. (pd.maxparacount=0) and
  2125. not(po_overload in hd.procoptions)
  2126. ) or
  2127. { check arguments }
  2128. (
  2129. (compare_paras(pd.paras,hd.paras,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  2130. { for operators equal_paras is not enough !! }
  2131. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  2132. { be careful here, equal_defs doesn't take care of unique }
  2133. (hd.rettype.def=pd.rettype.def) or
  2134. (equal_defs(hd.rettype.def,pd.rettype.def) and
  2135. not(df_unique in hd.rettype.def.defoptions) and not(df_unique in pd.rettype.def.defoptions)
  2136. )
  2137. )
  2138. ) then
  2139. begin
  2140. { Check if we've found the forwarddef, if found then
  2141. we need to update the forward def with the current
  2142. implementation settings }
  2143. if hd.forwarddef then
  2144. begin
  2145. forwardfound:=true;
  2146. { Check if the procedure type and return type are correct,
  2147. also the parameters must match also with the type }
  2148. if (hd.proctypeoption<>pd.proctypeoption) or
  2149. (
  2150. (m_repeat_forward in aktmodeswitches) and
  2151. (not((pd.maxparacount=0) or
  2152. (compare_paras(pd.paras,hd.paras,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  2153. ) or
  2154. (
  2155. ((m_repeat_forward in aktmodeswitches) or
  2156. not(is_void(pd.rettype.def))) and
  2157. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  2158. begin
  2159. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2160. pd.fullprocname(false));
  2161. aprocsym.write_parameter_lists(pd);
  2162. break;
  2163. end;
  2164. { Check if both are declared forward }
  2165. if hd.forwarddef and pd.forwarddef then
  2166. begin
  2167. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  2168. pd.fullprocname(false));
  2169. end;
  2170. { internconst or internproc only need to be defined once }
  2171. if (hd.proccalloption=pocall_internproc) then
  2172. pd.proccalloption:=hd.proccalloption
  2173. else
  2174. if (pd.proccalloption=pocall_internproc) then
  2175. hd.proccalloption:=pd.proccalloption;
  2176. { Check calling convention }
  2177. if (hd.proccalloption<>pd.proccalloption) then
  2178. begin
  2179. { In delphi it is possible to specify the calling
  2180. convention in the interface or implementation if
  2181. there was no convention specified in the other
  2182. part }
  2183. if (m_delphi in aktmodeswitches) then
  2184. begin
  2185. if not(po_hascallingconvention in pd.procoptions) then
  2186. pd.proccalloption:=hd.proccalloption
  2187. else
  2188. if not(po_hascallingconvention in hd.procoptions) then
  2189. hd.proccalloption:=pd.proccalloption
  2190. else
  2191. begin
  2192. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2193. aprocsym.write_parameter_lists(pd);
  2194. { restore interface settings }
  2195. pd.proccalloption:=hd.proccalloption;
  2196. end;
  2197. end
  2198. else
  2199. begin
  2200. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2201. aprocsym.write_parameter_lists(pd);
  2202. { restore interface settings }
  2203. pd.proccalloption:=hd.proccalloption;
  2204. end;
  2205. end;
  2206. { Check procedure options, Delphi requires that class is
  2207. repeated in the implementation for class methods }
  2208. if (m_fpc in aktmodeswitches) then
  2209. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  2210. else
  2211. po_comp:=[po_classmethod,po_methodpointer];
  2212. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  2213. begin
  2214. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2215. pd.fullprocname(false));
  2216. aprocsym.write_parameter_lists(pd);
  2217. { This error is non-fatal, we can recover }
  2218. end;
  2219. { Forward declaration is external? }
  2220. if (po_external in hd.procoptions) then
  2221. MessagePos(pd.fileinfo,parser_e_proc_already_external);
  2222. { Check parameters }
  2223. if (m_repeat_forward in aktmodeswitches) or
  2224. (pd.minparacount>0) then
  2225. begin
  2226. { If mangled names are equal then they have the same amount of arguments }
  2227. { We can check the names of the arguments }
  2228. { both symtables are in the same order from left to right }
  2229. ad:=tsym(hd.parast.symindex.first);
  2230. fd:=tsym(pd.parast.symindex.first);
  2231. repeat
  2232. { skip default parameter constsyms }
  2233. while assigned(ad) and (ad.typ<>paravarsym) do
  2234. ad:=tsym(ad.indexnext);
  2235. while assigned(fd) and (fd.typ<>paravarsym) do
  2236. fd:=tsym(fd.indexnext);
  2237. { stop when one of the two lists is at the end }
  2238. if not assigned(ad) or not assigned(fd) then
  2239. break;
  2240. { retrieve names, remove reg for register parameters }
  2241. s1:=ad.name;
  2242. s2:=fd.name;
  2243. { compare names }
  2244. if (s1<>s2) then
  2245. begin
  2246. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  2247. aprocsym.name,s1,s2);
  2248. break;
  2249. end;
  2250. ad:=tsym(ad.indexnext);
  2251. fd:=tsym(fd.indexnext);
  2252. until false;
  2253. if assigned(ad) xor assigned(fd) then
  2254. internalerror(200204178);
  2255. end;
  2256. { Everything is checked, now we can update the forward declaration
  2257. with the new data from the implementation }
  2258. hd.forwarddef:=pd.forwarddef;
  2259. hd.hasforward:=true;
  2260. hd.procoptions:=hd.procoptions+pd.procoptions;
  2261. if hd.extnumber=65535 then
  2262. hd.extnumber:=pd.extnumber;
  2263. while not pd.aliasnames.empty do
  2264. hd.aliasnames.insert(pd.aliasnames.getfirst);
  2265. { update fileinfo so position references the implementation,
  2266. also update funcretsym if it is already generated }
  2267. hd.fileinfo:=pd.fileinfo;
  2268. if assigned(hd.funcretsym) then
  2269. hd.funcretsym.fileinfo:=pd.fileinfo;
  2270. { import names }
  2271. if assigned(pd.import_dll) then
  2272. begin
  2273. stringdispose(hd.import_dll);
  2274. hd.import_dll:=stringdup(pd.import_dll^);
  2275. end;
  2276. if assigned(pd.import_name) then
  2277. begin
  2278. stringdispose(hd.import_name);
  2279. hd.import_name:=stringdup(pd.import_name^);
  2280. end;
  2281. hd.import_nr:=pd.import_nr;
  2282. { for compilerproc defines we need to rename and update the
  2283. symbolname to lowercase }
  2284. if (po_compilerproc in pd.procoptions) then
  2285. begin
  2286. { rename to lowercase so users can't access it }
  2287. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  2288. { also update the realname that is stored in the ppu }
  2289. stringdispose(aprocsym._realname);
  2290. aprocsym._realname:=stringdup('$'+aprocsym.name);
  2291. { the mangeled name is already changed by the pd_compilerproc }
  2292. { handler. It must be done immediately because if we have a }
  2293. { call to a compilerproc before it's implementation is }
  2294. { encountered, it must already use the new mangled name (JM) }
  2295. end;
  2296. { the procdef will be released by the symtable, we release
  2297. at least the parast }
  2298. pd.releasemem;
  2299. pd:=hd;
  2300. end
  2301. else
  2302. begin
  2303. { abstract methods aren't forward defined, but this }
  2304. { needs another error message }
  2305. if (po_abstractmethod in hd.procoptions) then
  2306. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  2307. else
  2308. begin
  2309. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  2310. aprocsym.write_parameter_lists(pd);
  2311. end;
  2312. end;
  2313. { we found one proc with the same arguments, there are no others
  2314. so we can stop }
  2315. break;
  2316. end;
  2317. { check for allowing overload directive }
  2318. if not(m_fpc in aktmodeswitches) then
  2319. begin
  2320. { overload directive turns on overloading }
  2321. if ((po_overload in pd.procoptions) or
  2322. (po_overload in hd.procoptions)) then
  2323. begin
  2324. { check if all procs have overloading, but not if the proc is a method or
  2325. already declared forward, then the check is already done }
  2326. if not(hd.hasforward or
  2327. assigned(pd._class) or
  2328. (pd.forwarddef<>hd.forwarddef) or
  2329. ((po_overload in pd.procoptions) and
  2330. (po_overload in hd.procoptions))) then
  2331. begin
  2332. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2333. break;
  2334. end;
  2335. end
  2336. else
  2337. begin
  2338. if not(hd.forwarddef) then
  2339. begin
  2340. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2341. break;
  2342. end;
  2343. end;
  2344. end; { equal arguments }
  2345. end;
  2346. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2347. list }
  2348. if not forwardfound then
  2349. aprocsym.addprocdef(pd);
  2350. proc_add_definition:=forwardfound;
  2351. end;
  2352. end.