pdecsub.pas 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576
  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. oldsymtablestack,
  586. srsymtable : tsymtable;
  587. storepos,
  588. procstartfilepos : tfileposinfo;
  589. searchagain : boolean;
  590. i : longint;
  591. st : tsymtable;
  592. aprocsym : tprocsym;
  593. begin
  594. { Save the position where this procedure really starts }
  595. procstartfilepos:=akttokenpos;
  596. result:=false;
  597. pd:=nil;
  598. aprocsym:=nil;
  599. if (potype=potype_operator) then
  600. begin
  601. sp:=overloaded_names[optoken];
  602. orgsp:=sp;
  603. end
  604. else
  605. begin
  606. sp:=pattern;
  607. orgsp:=orgpattern;
  608. consume(_ID);
  609. end;
  610. { examine interface map: function/procedure iname.functionname=locfuncname }
  611. if assigned(aclass) and
  612. assigned(aclass.implementedinterfaces) and
  613. (aclass.implementedinterfaces.count>0) and
  614. try_to_consume(_POINT) then
  615. begin
  616. storepos:=akttokenpos;
  617. akttokenpos:=procstartfilepos;
  618. { get interface syms}
  619. searchsym(sp,sym,srsymtable);
  620. if not assigned(sym) then
  621. begin
  622. identifier_not_found(orgsp);
  623. sym:=generrorsym;
  624. end;
  625. akttokenpos:=storepos;
  626. { qualifier is interface? }
  627. if (sym.typ=typesym) and
  628. (ttypesym(sym).restype.def.deftype=objectdef) then
  629. i:=aclass.implementedinterfaces.searchintf(ttypesym(sym).restype.def)
  630. else
  631. i:=-1;
  632. if (i=-1) then
  633. Message(parser_e_interface_id_expected);
  634. consume(_ID);
  635. { Create unique name <interface>.<method> }
  636. hs:=sp+'.'+pattern;
  637. consume(_EQUAL);
  638. if (token=_ID) then
  639. aclass.implementedinterfaces.addmappings(i,hs,pattern);
  640. consume(_ID);
  641. result:=true;
  642. exit;
  643. end;
  644. { method ? }
  645. if not assigned(aclass) and
  646. (potype<>potype_operator) and
  647. (symtablestack.symtablelevel=main_program_level) and
  648. try_to_consume(_POINT) then
  649. begin
  650. { search for object name }
  651. storepos:=akttokenpos;
  652. akttokenpos:=procstartfilepos;
  653. searchsym(sp,sym,srsymtable);
  654. if not assigned(sym) then
  655. begin
  656. identifier_not_found(orgsp);
  657. sym:=generrorsym;
  658. end;
  659. akttokenpos:=storepos;
  660. { consume proc name }
  661. sp:=pattern;
  662. orgsp:=orgpattern;
  663. procstartfilepos:=akttokenpos;
  664. consume(_ID);
  665. { qualifier is class name ? }
  666. if (sym.typ=typesym) and
  667. (ttypesym(sym).restype.def.deftype=objectdef) then
  668. begin
  669. aclass:=tobjectdef(ttypesym(sym).restype.def);
  670. aprocsym:=tprocsym(aclass.symtable.search(sp));
  671. { we solve this below }
  672. if assigned(aprocsym) then
  673. begin
  674. if aprocsym.typ<>procsym then
  675. begin
  676. { we use a different error message for tp7 so it looks more compatible }
  677. if (m_fpc in aktmodeswitches) then
  678. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  679. else
  680. Message(parser_e_methode_id_expected);
  681. { rename the name to an unique name to avoid an
  682. error when inserting the symbol in the symtable }
  683. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  684. aprocsym:=nil;
  685. end;
  686. end
  687. else
  688. begin
  689. Message(parser_e_methode_id_expected);
  690. { recover by making it a normal procedure instead of method }
  691. aclass:=nil;
  692. end;
  693. end
  694. else
  695. Message(parser_e_class_id_expected);
  696. end
  697. else
  698. begin
  699. { check for constructor/destructor which is not allowed here }
  700. if (not parse_only) and
  701. (potype in [potype_constructor,potype_destructor]) then
  702. Message(parser_e_constructors_always_objects);
  703. repeat
  704. searchagain:=false;
  705. akttokenpos:=procstartfilepos;
  706. srsym:=tsym(symtablestack.search(sp));
  707. if not(parse_only) and
  708. not assigned(srsym) and
  709. (symtablestack.symtabletype=staticsymtable) and
  710. assigned(symtablestack.next) and
  711. (symtablestack.next.iscurrentunit) then
  712. begin
  713. { The procedure we prepare for is in the implementation
  714. part of the unit we compile. It is also possible that we
  715. are compiling a program, which is also some kind of
  716. implementaion part.
  717. We need to find out if the procedure is global. If it is
  718. global, it is in the global symtable.}
  719. srsym:=tsym(symtablestack.next.search(sp));
  720. end;
  721. { Check if overloaded is a procsym }
  722. if assigned(srsym) then
  723. begin
  724. if srsym.typ=procsym then
  725. aprocsym:=tprocsym(srsym)
  726. else
  727. begin
  728. { when the other symbol is a unit symbol then hide the unit
  729. symbol }
  730. if (srsym.typ=unitsym) then
  731. begin
  732. HideSym(srsym);
  733. searchagain:=true;
  734. end
  735. else
  736. begin
  737. { we use a different error message for tp7 so it looks more compatible }
  738. if (m_fpc in aktmodeswitches) then
  739. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  740. else
  741. DuplicateSym(nil,srsym);
  742. { rename the name to an unique name to avoid an
  743. error when inserting the symbol in the symtable }
  744. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  745. end;
  746. end;
  747. end;
  748. until not searchagain;
  749. end;
  750. { test again if assigned, it can be reset to recover }
  751. if not assigned(aprocsym) then
  752. begin
  753. { create a new procsym and set the real filepos }
  754. akttokenpos:=procstartfilepos;
  755. { for operator we have only one procsym for each overloaded
  756. operation }
  757. if (potype=potype_operator) then
  758. begin
  759. Aprocsym:=Tprocsym(symtablestack.search(sp));
  760. if Aprocsym=nil then
  761. Aprocsym:=tprocsym.create('$'+sp);
  762. end
  763. else
  764. aprocsym:=tprocsym.create(orgsp);
  765. symtablestack.insert(aprocsym);
  766. end;
  767. { to get the correct symtablelevel we must ignore objectsymtables }
  768. st:=symtablestack;
  769. while not(st.symtabletype in [staticsymtable,globalsymtable,localsymtable]) do
  770. st:=st.next;
  771. pd:=tprocdef.create(st.symtablelevel+1);
  772. pd._class:=aclass;
  773. pd.procsym:=aprocsym;
  774. pd.proctypeoption:=potype;
  775. { methods inherit df_generic or df_specialization from the objectdef }
  776. if assigned(pd._class) then
  777. begin
  778. if (df_generic in pd._class.defoptions) then
  779. include(pd.defoptions,df_generic);
  780. if (df_specialization in pd._class.defoptions) then
  781. begin
  782. include(pd.defoptions,df_specialization);
  783. { Find corresponding genericdef, we need it later to
  784. replay the tokens to generate the body }
  785. if not assigned(pd._class.genericdef) then
  786. internalerror(200512113);
  787. st:=pd._class.genericdef.getsymtable(gs_record);
  788. if not assigned(st) then
  789. internalerror(200512114);
  790. { We are parsing the same objectdef, the def index numbers
  791. are the same }
  792. pd.genericdef:=tstoreddef(st.getdefnr(pd.indexnr));
  793. if not assigned(pd.genericdef) or
  794. (pd.genericdef.deftype<>procdef) then
  795. internalerror(200512115);
  796. end;
  797. end;
  798. { methods need to be exported }
  799. if assigned(aclass) and
  800. (
  801. (symtablestack.symtabletype=objectsymtable) or
  802. (symtablestack.symtablelevel=main_program_level)
  803. ) then
  804. include(pd.procoptions,po_global);
  805. { symbol options that need to be kept per procdef }
  806. pd.fileinfo:=procstartfilepos;
  807. pd.symoptions:=current_object_option;
  808. { parse parameters }
  809. if token=_LKLAMMER then
  810. begin
  811. { Add objectsymtable to be able to find generic type definitions }
  812. oldsymtablestack:=symtablestack;
  813. if assigned(pd._class) and
  814. (pd.parast.symtablelevel=normal_function_level) and
  815. (symtablestack.symtabletype<>objectsymtable) then
  816. begin
  817. pd._class.symtable.next:=symtablestack;
  818. symtablestack:=pd._class.symtable;
  819. end;
  820. { Add parameter symtable }
  821. if pd.parast.symtabletype<>staticsymtable then
  822. begin
  823. pd.parast.next:=symtablestack;
  824. symtablestack:=pd.parast;
  825. end;
  826. parse_parameter_dec(pd);
  827. symtablestack:=oldsymtablestack;
  828. end;
  829. result:=true;
  830. end;
  831. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  832. var
  833. pd : tprocdef;
  834. isclassmethod : boolean;
  835. locationstr: string;
  836. begin
  837. locationstr:='';
  838. pd:=nil;
  839. isclassmethod:=false;
  840. { read class method }
  841. if try_to_consume(_CLASS) then
  842. begin
  843. { class method only allowed for procedures and functions }
  844. if not(token in [_FUNCTION,_PROCEDURE]) then
  845. Message(parser_e_procedure_or_function_expected);
  846. if is_interface(aclass) then
  847. Message(parser_e_no_static_method_in_interfaces)
  848. else
  849. isclassmethod:=true;
  850. end;
  851. case token of
  852. _FUNCTION :
  853. begin
  854. consume(_FUNCTION);
  855. if parse_proc_head(aclass,potype_function,pd) then
  856. begin
  857. { pd=nil when it is a interface mapping }
  858. if assigned(pd) then
  859. begin
  860. if try_to_consume(_COLON) then
  861. begin
  862. inc(testcurobject);
  863. single_type(pd.rettype,false);
  864. pd.test_if_fpu_result;
  865. dec(testcurobject);
  866. if (target_info.system in [system_m68k_amiga]) then
  867. begin
  868. if (idtoken=_LOCATION) then
  869. begin
  870. if po_explicitparaloc in pd.procoptions then
  871. begin
  872. consume(_LOCATION);
  873. locationstr:=pattern;
  874. consume(_CSTRING);
  875. end
  876. else
  877. { I guess this needs a new message... (KB) }
  878. Message(parser_e_paraloc_all_paras);
  879. end
  880. else
  881. begin
  882. if po_explicitparaloc in pd.procoptions then
  883. { assign default locationstr, if none specified }
  884. { and we've arguments with explicit paraloc }
  885. locationstr:='D0';
  886. end;
  887. end;
  888. end
  889. else
  890. begin
  891. if (
  892. parse_only and
  893. not(is_interface(pd._class))
  894. ) or
  895. (m_repeat_forward in aktmodeswitches) then
  896. begin
  897. consume(_COLON);
  898. consume_all_until(_SEMICOLON);
  899. end;
  900. end;
  901. if isclassmethod then
  902. include(pd.procoptions,po_classmethod);
  903. end;
  904. end
  905. else
  906. begin
  907. { recover }
  908. consume(_COLON);
  909. consume_all_until(_SEMICOLON);
  910. end;
  911. end;
  912. _PROCEDURE :
  913. begin
  914. consume(_PROCEDURE);
  915. if parse_proc_head(aclass,potype_procedure,pd) then
  916. begin
  917. { pd=nil when it is a interface mapping }
  918. if assigned(pd) then
  919. begin
  920. pd.rettype:=voidtype;
  921. if isclassmethod then
  922. include(pd.procoptions,po_classmethod);
  923. end;
  924. end;
  925. end;
  926. _CONSTRUCTOR :
  927. begin
  928. consume(_CONSTRUCTOR);
  929. parse_proc_head(aclass,potype_constructor,pd);
  930. if assigned(pd) and
  931. assigned(pd._class) then
  932. begin
  933. { Set return type, class constructors return the
  934. created instance, object constructors return boolean }
  935. if is_class(pd._class) then
  936. pd.rettype.setdef(pd._class)
  937. else
  938. pd.rettype:=booltype;
  939. end;
  940. end;
  941. _DESTRUCTOR :
  942. begin
  943. consume(_DESTRUCTOR);
  944. parse_proc_head(aclass,potype_destructor,pd);
  945. if assigned(pd) then
  946. pd.rettype:=voidtype;
  947. end;
  948. _OPERATOR :
  949. begin
  950. consume(_OPERATOR);
  951. if (token in [first_overloaded..last_overloaded]) then
  952. begin
  953. optoken:=token;
  954. end
  955. else
  956. begin
  957. Message(parser_e_overload_operator_failed);
  958. { Use the dummy NOTOKEN that is also declared
  959. for the overloaded_operator[] }
  960. optoken:=NOTOKEN;
  961. end;
  962. consume(token);
  963. parse_proc_head(aclass,potype_operator,pd);
  964. if assigned(pd) then
  965. begin
  966. if pd.parast.symtablelevel>normal_function_level then
  967. Message(parser_e_no_local_operator);
  968. if token<>_ID then
  969. begin
  970. if not(m_result in aktmodeswitches) then
  971. consume(_ID);
  972. end
  973. else
  974. begin
  975. pd.resultname:=orgpattern;
  976. consume(_ID);
  977. end;
  978. if not try_to_consume(_COLON) then
  979. begin
  980. consume(_COLON);
  981. pd.rettype:=generrortype;
  982. consume_all_until(_SEMICOLON);
  983. end
  984. else
  985. begin
  986. single_type(pd.rettype,false);
  987. pd.test_if_fpu_result;
  988. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  989. ((pd.rettype.def.deftype<>orddef) or
  990. (torddef(pd.rettype.def).typ<>bool8bit)) then
  991. Message(parser_e_comparative_operator_return_boolean);
  992. if (optoken=_ASSIGNMENT) and
  993. equal_defs(pd.rettype.def,
  994. tparavarsym(pd.parast.symindex.first).vartype.def) then
  995. message(parser_e_no_such_assignment)
  996. else if not isoperatoracceptable(pd,optoken) then
  997. Message(parser_e_overload_impossible);
  998. end;
  999. end
  1000. else
  1001. begin
  1002. { recover }
  1003. try_to_consume(_ID);
  1004. consume(_COLON);
  1005. consume_all_until(_SEMICOLON);
  1006. end;
  1007. end;
  1008. end;
  1009. { support procedure proc stdcall export; }
  1010. if not(check_proc_directive(false)) then
  1011. consume(_SEMICOLON);
  1012. result:=pd;
  1013. if locationstr<>'' then
  1014. begin
  1015. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1016. { I guess this needs a new message... (KB) }
  1017. message(parser_e_illegal_explicit_paraloc);
  1018. end;
  1019. end;
  1020. {****************************************************************************
  1021. Procedure directive handlers
  1022. ****************************************************************************}
  1023. procedure pd_far(pd:tabstractprocdef);
  1024. begin
  1025. Message1(parser_w_proc_directive_ignored,'FAR');
  1026. end;
  1027. procedure pd_near(pd:tabstractprocdef);
  1028. begin
  1029. Message1(parser_w_proc_directive_ignored,'NEAR');
  1030. end;
  1031. procedure pd_export(pd:tabstractprocdef);
  1032. begin
  1033. if pd.deftype<>procdef then
  1034. internalerror(200304264);
  1035. if assigned(tprocdef(pd)._class) then
  1036. Message(parser_e_methods_dont_be_export);
  1037. if pd.parast.symtablelevel>normal_function_level then
  1038. Message(parser_e_dont_nest_export);
  1039. end;
  1040. procedure pd_forward(pd:tabstractprocdef);
  1041. begin
  1042. if pd.deftype<>procdef then
  1043. internalerror(200304265);
  1044. tprocdef(pd).forwarddef:=true;
  1045. end;
  1046. procedure pd_alias(pd:tabstractprocdef);
  1047. begin
  1048. if pd.deftype<>procdef then
  1049. internalerror(200304266);
  1050. consume(_COLON);
  1051. tprocdef(pd).aliasnames.insert(get_stringconst);
  1052. include(pd.procoptions,po_has_public_name);
  1053. end;
  1054. procedure pd_public(pd:tabstractprocdef);
  1055. begin
  1056. if pd.deftype<>procdef then
  1057. internalerror(200304266);
  1058. if try_to_consume(_NAME) then
  1059. begin
  1060. tprocdef(pd).aliasnames.insert(get_stringconst);
  1061. include(pd.procoptions,po_has_public_name);
  1062. end;
  1063. end;
  1064. procedure pd_asmname(pd:tabstractprocdef);
  1065. begin
  1066. if pd.deftype<>procdef then
  1067. internalerror(200304267);
  1068. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1069. if token=_CCHAR then
  1070. consume(_CCHAR)
  1071. else
  1072. consume(_CSTRING);
  1073. { we don't need anything else }
  1074. tprocdef(pd).forwarddef:=false;
  1075. end;
  1076. procedure pd_inline(pd:tabstractprocdef);
  1077. begin
  1078. { Check if there are parameters that can't be inlined }
  1079. pd.parast.foreach_static(@check_inline_para,pd);
  1080. end;
  1081. procedure pd_internconst(pd:tabstractprocdef);
  1082. begin
  1083. if pd.deftype<>procdef then
  1084. internalerror(200304268);
  1085. consume(_COLON);
  1086. tprocdef(pd).extnumber:=get_intconst;
  1087. end;
  1088. procedure pd_internproc(pd:tabstractprocdef);
  1089. begin
  1090. if pd.deftype<>procdef then
  1091. internalerror(200304268);
  1092. consume(_COLON);
  1093. tprocdef(pd).extnumber:=get_intconst;
  1094. { the proc is defined }
  1095. tprocdef(pd).forwarddef:=false;
  1096. end;
  1097. procedure pd_interrupt(pd:tabstractprocdef);
  1098. begin
  1099. if pd.parast.symtablelevel>normal_function_level then
  1100. Message(parser_e_dont_nest_interrupt);
  1101. end;
  1102. procedure pd_abstract(pd:tabstractprocdef);
  1103. begin
  1104. if pd.deftype<>procdef then
  1105. internalerror(200304269);
  1106. if (po_virtualmethod in pd.procoptions) then
  1107. include(pd.procoptions,po_abstractmethod)
  1108. else
  1109. Message(parser_e_only_virtual_methods_abstract);
  1110. { the method is defined }
  1111. tprocdef(pd).forwarddef:=false;
  1112. end;
  1113. procedure pd_virtual(pd:tabstractprocdef);
  1114. {$ifdef WITHDMT}
  1115. var
  1116. pt : tnode;
  1117. {$endif WITHDMT}
  1118. begin
  1119. if pd.deftype<>procdef then
  1120. internalerror(2003042610);
  1121. if (pd.proctypeoption=potype_constructor) and
  1122. is_object(tprocdef(pd)._class) then
  1123. Message(parser_e_constructor_cannot_be_not_virtual);
  1124. {$ifdef WITHDMT}
  1125. if is_object(tprocdef(pd)._class) and
  1126. (token<>_SEMICOLON) then
  1127. begin
  1128. { any type of parameter is allowed here! }
  1129. pt:=comp_expr(true);
  1130. if is_constintnode(pt) then
  1131. begin
  1132. include(pd.procoptions,po_msgint);
  1133. pd.messageinf.i:=pt^.value;
  1134. end
  1135. else
  1136. Message(parser_e_ill_msg_expr);
  1137. disposetree(pt);
  1138. end;
  1139. {$endif WITHDMT}
  1140. end;
  1141. procedure pd_static(pd:tabstractprocdef);
  1142. begin
  1143. if (cs_static_keyword in aktmoduleswitches) then
  1144. begin
  1145. if pd.deftype=procdef then
  1146. include(tprocdef(pd).procsym.symoptions,sp_static);
  1147. include(pd.procoptions,po_staticmethod);
  1148. end;
  1149. end;
  1150. procedure pd_override(pd:tabstractprocdef);
  1151. begin
  1152. if pd.deftype<>procdef then
  1153. internalerror(2003042611);
  1154. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1155. Message(parser_e_no_object_override);
  1156. end;
  1157. procedure pd_overload(pd:tabstractprocdef);
  1158. begin
  1159. if pd.deftype<>procdef then
  1160. internalerror(2003042612);
  1161. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1162. end;
  1163. procedure pd_message(pd:tabstractprocdef);
  1164. var
  1165. pt : tnode;
  1166. paracnt : longint;
  1167. begin
  1168. if pd.deftype<>procdef then
  1169. internalerror(2003042613);
  1170. if not is_class(tprocdef(pd)._class) then
  1171. Message(parser_e_msg_only_for_classes);
  1172. { check parameter type }
  1173. paracnt:=0;
  1174. pd.parast.foreach_static(@check_msg_para,@paracnt);
  1175. if paracnt<>1 then
  1176. Message(parser_e_ill_msg_param);
  1177. pt:=comp_expr(true);
  1178. if pt.nodetype=stringconstn then
  1179. begin
  1180. include(pd.procoptions,po_msgstr);
  1181. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1182. end
  1183. else
  1184. if is_constintnode(pt) then
  1185. begin
  1186. include(pd.procoptions,po_msgint);
  1187. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1188. end
  1189. else
  1190. Message(parser_e_ill_msg_expr);
  1191. pt.free;
  1192. end;
  1193. procedure pd_reintroduce(pd:tabstractprocdef);
  1194. begin
  1195. if pd.deftype<>procdef then
  1196. internalerror(200401211);
  1197. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1198. Message(parser_e_no_object_reintroduce);
  1199. end;
  1200. procedure pd_syscall(pd:tabstractprocdef);
  1201. {$if defined(powerpc) or defined(m68k)}
  1202. var
  1203. vs : tparavarsym;
  1204. sym : tsym;
  1205. symtable : tsymtable;
  1206. {$endif defined(powerpc) or defined(m68k)}
  1207. begin
  1208. if pd.deftype<>procdef then
  1209. internalerror(2003042614);
  1210. tprocdef(pd).forwarddef:=false;
  1211. {$ifdef m68k}
  1212. if target_info.system in [system_m68k_amiga] then
  1213. begin
  1214. include(pd.procoptions,po_syscall_legacy);
  1215. if consume_sym(sym,symtable) then
  1216. begin
  1217. if (sym.typ=globalvarsym) and
  1218. (
  1219. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1220. is_32bitint(tabstractvarsym(sym).vartype.def)
  1221. ) then
  1222. begin
  1223. tprocdef(pd).libsym:=sym;
  1224. if po_syscall_legacy in tprocdef(pd).procoptions then
  1225. begin
  1226. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1227. paramanager.parseparaloc(vs,'A6');
  1228. pd.parast.insert(vs);
  1229. end
  1230. end
  1231. else
  1232. Message(parser_e_32bitint_or_pointer_variable_expected);
  1233. end;
  1234. (paramanager as tm68kparamanager).create_funcretloc_info(pd,calleeside);
  1235. (paramanager as tm68kparamanager).create_funcretloc_info(pd,callerside);
  1236. end;
  1237. {$endif m68k}
  1238. {$ifdef powerpc}
  1239. if target_info.system in [system_powerpc_morphos] then
  1240. begin
  1241. if idtoken=_LEGACY then
  1242. begin
  1243. consume(_LEGACY);
  1244. include(pd.procoptions,po_syscall_legacy);
  1245. end
  1246. else if idtoken=_SYSV then
  1247. begin
  1248. consume(_SYSV);
  1249. include(pd.procoptions,po_syscall_sysv);
  1250. end
  1251. else if idtoken=_BASESYSV then
  1252. begin
  1253. consume(_BASESYSV);
  1254. include(pd.procoptions,po_syscall_basesysv);
  1255. end
  1256. else if idtoken=_SYSVBASE then
  1257. begin
  1258. consume(_SYSVBASE);
  1259. include(pd.procoptions,po_syscall_sysvbase);
  1260. end
  1261. else if idtoken=_R12BASE then
  1262. begin
  1263. consume(_R12BASE);
  1264. include(pd.procoptions,po_syscall_r12base);
  1265. end
  1266. else
  1267. if syscall_convention='LEGACY' then
  1268. include(pd.procoptions,po_syscall_legacy)
  1269. else if syscall_convention='SYSV' then
  1270. include(pd.procoptions,po_syscall_sysv)
  1271. else if syscall_convention='BASESYSV' then
  1272. include(pd.procoptions,po_syscall_basesysv)
  1273. else if syscall_convention='SYSVBASE' then
  1274. include(pd.procoptions,po_syscall_sysvbase)
  1275. else if syscall_convention='R12BASE' then
  1276. include(pd.procoptions,po_syscall_r12base)
  1277. else
  1278. internalerror(2005010404);
  1279. if consume_sym(sym,symtable) then
  1280. begin
  1281. if (sym.typ=globalvarsym) and
  1282. (
  1283. (tabstractvarsym(sym).vartype.def.deftype=pointerdef) or
  1284. is_32bitint(tabstractvarsym(sym).vartype.def)
  1285. ) then
  1286. begin
  1287. tprocdef(pd).libsym:=sym;
  1288. if po_syscall_legacy in tprocdef(pd).procoptions then
  1289. begin
  1290. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1291. paramanager.parseparaloc(vs,'A6');
  1292. pd.parast.insert(vs);
  1293. end
  1294. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1295. begin
  1296. { Nothing to be done for sysv here for now, but this might change }
  1297. end
  1298. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1299. begin
  1300. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1301. pd.parast.insert(vs);
  1302. end
  1303. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1304. begin
  1305. vs:=tparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para]);
  1306. pd.parast.insert(vs);
  1307. end
  1308. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1309. begin
  1310. vs:=tparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vartype,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1311. paramanager.parseparaloc(vs,'R12');
  1312. pd.parast.insert(vs);
  1313. end
  1314. else
  1315. internalerror(2005010501);
  1316. end
  1317. else
  1318. Message(parser_e_32bitint_or_pointer_variable_expected);
  1319. end;
  1320. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1321. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1322. end;
  1323. {$endif powerpc}
  1324. tprocdef(pd).extnumber:=get_intconst;
  1325. end;
  1326. procedure pd_external(pd:tabstractprocdef);
  1327. {
  1328. If import_dll=nil the procedure is assumed to be in another
  1329. object file. In that object file it should have the name to
  1330. which import_name is pointing to. Otherwise, the procedure is
  1331. assumed to be in the DLL to which import_dll is pointing to. In
  1332. that case either import_nr<>0 or import_name<>nil is true, so
  1333. the procedure is either imported by number or by name. (DM)
  1334. }
  1335. begin
  1336. if pd.deftype<>procdef then
  1337. internalerror(2003042615);
  1338. with tprocdef(pd) do
  1339. begin
  1340. forwarddef:=false;
  1341. { forbid local external procedures }
  1342. if parast.symtablelevel>normal_function_level then
  1343. Message(parser_e_no_local_proc_external);
  1344. { If the procedure should be imported from a DLL, a constant string follows.
  1345. This isn't really correct, an contant string expression follows
  1346. so we check if an semicolon follows, else a string constant have to
  1347. follow (FK) }
  1348. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1349. begin
  1350. import_dll:=stringdup(get_stringconst);
  1351. if (idtoken=_NAME) then
  1352. begin
  1353. consume(_NAME);
  1354. import_name:=stringdup(get_stringconst);
  1355. if import_name^='' then
  1356. message(parser_e_empty_import_name);
  1357. end;
  1358. if (idtoken=_INDEX) then
  1359. begin
  1360. {After the word index follows the index number in the DLL.}
  1361. consume(_INDEX);
  1362. import_nr:=get_intconst;
  1363. end;
  1364. { default is to used the realname of the procedure }
  1365. if (import_nr=0) and not assigned(import_name) then
  1366. import_name:=stringdup(procsym.realname);
  1367. end
  1368. else
  1369. begin
  1370. if (idtoken=_NAME) then
  1371. begin
  1372. consume(_NAME);
  1373. import_name:=stringdup(get_stringconst);
  1374. if import_name^='' then
  1375. message(parser_e_empty_import_name);
  1376. end;
  1377. end;
  1378. end;
  1379. end;
  1380. type
  1381. pd_handler=procedure(pd:tabstractprocdef);
  1382. proc_dir_rec=record
  1383. idtok : ttoken;
  1384. pd_flags : tpdflags;
  1385. handler : pd_handler;
  1386. pocall : tproccalloption;
  1387. pooption : tprocoptions;
  1388. mutexclpocall : tproccalloptions;
  1389. mutexclpotype : tproctypeoptions;
  1390. mutexclpo : tprocoptions;
  1391. end;
  1392. const
  1393. {Should contain the number of procedure directives we support.}
  1394. num_proc_directives=37;
  1395. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1396. (
  1397. (
  1398. idtok:_ABSTRACT;
  1399. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1400. handler : @pd_abstract;
  1401. pocall : pocall_none;
  1402. pooption : [po_abstractmethod];
  1403. mutexclpocall : [pocall_internproc];
  1404. mutexclpotype : [];
  1405. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  1406. ),(
  1407. idtok:_ALIAS;
  1408. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1409. handler : @pd_alias;
  1410. pocall : pocall_none;
  1411. pooption : [];
  1412. mutexclpocall : [];
  1413. mutexclpotype : [];
  1414. mutexclpo : [po_external,po_inline]
  1415. ),(
  1416. idtok:_ASMNAME;
  1417. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1418. handler : @pd_asmname;
  1419. pocall : pocall_cdecl;
  1420. pooption : [po_external];
  1421. mutexclpocall : [pocall_internproc];
  1422. mutexclpotype : [];
  1423. mutexclpo : [po_external,po_inline]
  1424. ),(
  1425. idtok:_ASSEMBLER;
  1426. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1427. handler : nil;
  1428. pocall : pocall_none;
  1429. pooption : [po_assembler];
  1430. mutexclpocall : [];
  1431. mutexclpotype : [];
  1432. mutexclpo : [po_external]
  1433. ),(
  1434. idtok:_C; {same as cdecl for mode mac}
  1435. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1436. handler : nil;
  1437. pocall : pocall_cdecl;
  1438. pooption : [];
  1439. mutexclpocall : [];
  1440. mutexclpotype : [potype_constructor,potype_destructor];
  1441. mutexclpo : [po_assembler,po_external]
  1442. ),(
  1443. idtok:_CDECL;
  1444. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1445. handler : nil;
  1446. pocall : pocall_cdecl;
  1447. pooption : [];
  1448. mutexclpocall : [];
  1449. mutexclpotype : [potype_constructor,potype_destructor];
  1450. mutexclpo : [po_assembler,po_external]
  1451. ),(
  1452. idtok:_DYNAMIC;
  1453. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1454. handler : @pd_virtual;
  1455. pocall : pocall_none;
  1456. pooption : [po_virtualmethod];
  1457. mutexclpocall : [pocall_internproc];
  1458. mutexclpotype : [];
  1459. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  1460. ),(
  1461. idtok:_EXPORT;
  1462. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1463. handler : @pd_export;
  1464. pocall : pocall_none;
  1465. pooption : [po_exports,po_global];
  1466. mutexclpocall : [pocall_internproc];
  1467. mutexclpotype : [potype_constructor,potype_destructor];
  1468. mutexclpo : [po_external,po_interrupt,po_inline]
  1469. ),(
  1470. idtok:_EXTERNAL;
  1471. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1472. handler : @pd_external;
  1473. pocall : pocall_none;
  1474. pooption : [po_external];
  1475. mutexclpocall : [pocall_internproc,pocall_syscall];
  1476. mutexclpotype : [potype_constructor,potype_destructor];
  1477. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  1478. ),(
  1479. idtok:_FAR;
  1480. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1481. handler : @pd_far;
  1482. pocall : pocall_none;
  1483. pooption : [];
  1484. mutexclpocall : [pocall_internproc];
  1485. mutexclpotype : [];
  1486. mutexclpo : [po_inline]
  1487. ),(
  1488. idtok:_FAR16;
  1489. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1490. handler : nil;
  1491. pocall : pocall_far16;
  1492. pooption : [];
  1493. mutexclpocall : [];
  1494. mutexclpotype : [];
  1495. mutexclpo : [po_external]
  1496. ),(
  1497. idtok:_FORWARD;
  1498. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1499. handler : @pd_forward;
  1500. pocall : pocall_none;
  1501. pooption : [];
  1502. mutexclpocall : [pocall_internproc];
  1503. mutexclpotype : [];
  1504. mutexclpo : [po_external,po_inline]
  1505. ),(
  1506. idtok:_OLDFPCCALL;
  1507. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1508. handler : nil;
  1509. pocall : pocall_oldfpccall;
  1510. pooption : [];
  1511. mutexclpocall : [];
  1512. mutexclpotype : [];
  1513. mutexclpo : []
  1514. ),(
  1515. idtok:_INLINE;
  1516. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1517. handler : @pd_inline;
  1518. pocall : pocall_none;
  1519. pooption : [po_inline];
  1520. mutexclpocall : [];
  1521. mutexclpotype : [potype_constructor,potype_destructor];
  1522. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1523. ),(
  1524. idtok:_INTERNCONST;
  1525. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf];
  1526. handler : @pd_internconst;
  1527. pocall : pocall_none;
  1528. pooption : [po_internconst];
  1529. mutexclpocall : [];
  1530. mutexclpotype : [potype_operator];
  1531. mutexclpo : []
  1532. ),(
  1533. idtok:_INTERNPROC;
  1534. pd_flags : [pd_interface,pd_notobject,pd_notobjintf];
  1535. handler : @pd_internproc;
  1536. pocall : pocall_internproc;
  1537. pooption : [];
  1538. mutexclpocall : [];
  1539. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1540. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1541. ),(
  1542. idtok:_INTERRUPT;
  1543. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1544. handler : @pd_interrupt;
  1545. pocall : pocall_none;
  1546. pooption : [po_interrupt];
  1547. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1548. pocall_pascal,pocall_far16,pocall_oldfpccall];
  1549. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1550. mutexclpo : [po_external,po_inline]
  1551. ),(
  1552. idtok:_IOCHECK;
  1553. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1554. handler : nil;
  1555. pocall : pocall_none;
  1556. pooption : [po_iocheck];
  1557. mutexclpocall : [pocall_internproc];
  1558. mutexclpotype : [];
  1559. mutexclpo : [po_external]
  1560. ),(
  1561. idtok:_MESSAGE;
  1562. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1563. handler : @pd_message;
  1564. pocall : pocall_none;
  1565. pooption : []; { can be po_msgstr or po_msgint }
  1566. mutexclpocall : [pocall_internproc];
  1567. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1568. mutexclpo : [po_interrupt,po_external,po_inline]
  1569. ),(
  1570. idtok:_MWPASCAL;
  1571. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1572. handler : nil;
  1573. pocall : pocall_mwpascal;
  1574. pooption : [];
  1575. mutexclpocall : [];
  1576. mutexclpotype : [];
  1577. mutexclpo : []
  1578. ),(
  1579. idtok:_NEAR;
  1580. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1581. handler : @pd_near;
  1582. pocall : pocall_none;
  1583. pooption : [];
  1584. mutexclpocall : [pocall_internproc];
  1585. mutexclpotype : [];
  1586. mutexclpo : []
  1587. ),(
  1588. idtok:_NOSTACKFRAME;
  1589. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1590. handler : nil;
  1591. pocall : pocall_none;
  1592. pooption : [po_nostackframe];
  1593. mutexclpocall : [pocall_internproc];
  1594. mutexclpotype : [];
  1595. mutexclpo : []
  1596. ),(
  1597. idtok:_OVERLOAD;
  1598. pd_flags : [pd_implemen,pd_interface,pd_body];
  1599. handler : @pd_overload;
  1600. pocall : pocall_none;
  1601. pooption : [po_overload];
  1602. mutexclpocall : [pocall_internproc];
  1603. mutexclpotype : [];
  1604. mutexclpo : []
  1605. ),(
  1606. idtok:_OVERRIDE;
  1607. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1608. handler : @pd_override;
  1609. pocall : pocall_none;
  1610. pooption : [po_overridingmethod,po_virtualmethod];
  1611. mutexclpocall : [pocall_internproc];
  1612. mutexclpotype : [];
  1613. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_inline]
  1614. ),(
  1615. idtok:_PASCAL;
  1616. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1617. handler : nil;
  1618. pocall : pocall_pascal;
  1619. pooption : [];
  1620. mutexclpocall : [];
  1621. mutexclpotype : [potype_constructor,potype_destructor];
  1622. mutexclpo : [po_external]
  1623. ),(
  1624. idtok:_PUBLIC;
  1625. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1626. handler : @pd_public;
  1627. pocall : pocall_none;
  1628. pooption : [po_public,po_global];
  1629. mutexclpocall : [pocall_internproc];
  1630. mutexclpotype : [];
  1631. mutexclpo : [po_external,po_inline]
  1632. ),(
  1633. idtok:_REGISTER;
  1634. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1635. handler : nil;
  1636. pocall : pocall_register;
  1637. pooption : [];
  1638. mutexclpocall : [];
  1639. mutexclpotype : [potype_constructor,potype_destructor];
  1640. mutexclpo : [po_external]
  1641. ),(
  1642. idtok:_REINTRODUCE;
  1643. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1644. handler : @pd_reintroduce;
  1645. pocall : pocall_none;
  1646. pooption : [po_reintroduce];
  1647. mutexclpocall : [pocall_internproc];
  1648. mutexclpotype : [];
  1649. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1650. ),(
  1651. idtok:_SAFECALL;
  1652. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1653. handler : nil;
  1654. pocall : pocall_safecall;
  1655. pooption : [];
  1656. mutexclpocall : [];
  1657. mutexclpotype : [potype_constructor,potype_destructor];
  1658. mutexclpo : [po_external]
  1659. ),(
  1660. idtok:_SOFTFLOAT;
  1661. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1662. handler : nil;
  1663. pocall : pocall_softfloat;
  1664. pooption : [];
  1665. mutexclpocall : [];
  1666. mutexclpotype : [potype_constructor,potype_destructor];
  1667. { it's available with po_external because the libgcc floating point routines on the arm
  1668. uses this calling convention }
  1669. mutexclpo : []
  1670. ),(
  1671. idtok:_STATIC;
  1672. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1673. handler : @pd_static;
  1674. pocall : pocall_none;
  1675. pooption : [po_staticmethod];
  1676. mutexclpocall : [pocall_internproc];
  1677. mutexclpotype : [potype_constructor,potype_destructor];
  1678. mutexclpo : [po_external,po_interrupt,po_exports,po_inline]
  1679. ),(
  1680. idtok:_STDCALL;
  1681. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1682. handler : nil;
  1683. pocall : pocall_stdcall;
  1684. pooption : [];
  1685. mutexclpocall : [];
  1686. mutexclpotype : [potype_constructor,potype_destructor];
  1687. mutexclpo : [po_external]
  1688. ),(
  1689. idtok:_SYSCALL;
  1690. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf];
  1691. handler : @pd_syscall;
  1692. pocall : pocall_syscall;
  1693. pooption : [];
  1694. mutexclpocall : [];
  1695. mutexclpotype : [potype_constructor,potype_destructor];
  1696. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1697. ),(
  1698. idtok:_VIRTUAL;
  1699. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1700. handler : @pd_virtual;
  1701. pocall : pocall_none;
  1702. pooption : [po_virtualmethod];
  1703. mutexclpocall : [pocall_internproc];
  1704. mutexclpotype : [];
  1705. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1706. ),(
  1707. idtok:_CPPDECL;
  1708. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1709. handler : nil;
  1710. pocall : pocall_cppdecl;
  1711. pooption : [];
  1712. mutexclpocall : [];
  1713. mutexclpotype : [potype_constructor,potype_destructor];
  1714. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1715. ),(
  1716. idtok:_VARARGS;
  1717. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1718. handler : nil;
  1719. pocall : pocall_none;
  1720. pooption : [po_varargs];
  1721. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1722. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  1723. mutexclpotype : [];
  1724. mutexclpo : [po_assembler,po_interrupt,po_inline]
  1725. ),(
  1726. idtok:_COMPILERPROC;
  1727. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1728. handler : nil;
  1729. pocall : pocall_none;
  1730. pooption : [po_compilerproc];
  1731. mutexclpocall : [];
  1732. mutexclpotype : [potype_constructor,potype_destructor];
  1733. mutexclpo : [po_interrupt]
  1734. )
  1735. );
  1736. function check_proc_directive(isprocvar:boolean):boolean;
  1737. var
  1738. i : longint;
  1739. begin
  1740. result:=false;
  1741. for i:=1 to num_proc_directives do
  1742. if proc_direcdata[i].idtok=idtoken then
  1743. begin
  1744. if ((not isprocvar) or
  1745. (pd_procvar in proc_direcdata[i].pd_flags)) and
  1746. { don't eat a public directive in classes }
  1747. not((idtoken=_PUBLIC) and (symtablestack.symtabletype=objectsymtable)) then
  1748. result:=true;
  1749. exit;
  1750. end;
  1751. end;
  1752. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1753. {
  1754. Parse the procedure directive, returns true if a correct directive is found
  1755. }
  1756. var
  1757. p : longint;
  1758. found : boolean;
  1759. name : stringid;
  1760. begin
  1761. parse_proc_direc:=false;
  1762. name:=tokeninfo^[idtoken].str;
  1763. found:=false;
  1764. { Hint directive? Then exit immediatly }
  1765. if (m_hintdirective in aktmodeswitches) then
  1766. begin
  1767. case idtoken of
  1768. _LIBRARY,
  1769. _PLATFORM,
  1770. _UNIMPLEMENTED,
  1771. _DEPRECATED :
  1772. exit;
  1773. end;
  1774. end;
  1775. { C directive is MAC only, because it breaks too much existing code
  1776. on other platforms (PFV) }
  1777. if (idtoken=_C) and
  1778. not(m_mac in aktmodeswitches) then
  1779. exit;
  1780. { retrieve data for directive if found }
  1781. for p:=1 to num_proc_directives do
  1782. if proc_direcdata[p].idtok=idtoken then
  1783. begin
  1784. found:=true;
  1785. break;
  1786. end;
  1787. { Check if the procedure directive is known }
  1788. if not found then
  1789. begin
  1790. { parsing a procvar type the name can be any
  1791. next variable !! }
  1792. if ((pdflags * [pd_procvar,pd_object])=[]) and
  1793. not(idtoken=_PROPERTY) then
  1794. Message1(parser_w_unknown_proc_directive_ignored,name);
  1795. exit;
  1796. end;
  1797. { static needs a special treatment }
  1798. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1799. exit;
  1800. { check if method and directive not for object, like public.
  1801. This needs to be checked also for procvars }
  1802. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1803. (symtablestack.symtabletype=objectsymtable) then
  1804. exit;
  1805. { Conflicts between directives ? }
  1806. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1807. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1808. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1809. begin
  1810. Message1(parser_e_proc_dir_conflict,name);
  1811. exit;
  1812. end;
  1813. { set calling convention }
  1814. if proc_direcdata[p].pocall<>pocall_none then
  1815. begin
  1816. if (po_hascallingconvention in pd.procoptions) then
  1817. begin
  1818. Message2(parser_w_proc_overriding_calling,
  1819. proccalloptionStr[pd.proccalloption],
  1820. proccalloptionStr[proc_direcdata[p].pocall]);
  1821. end;
  1822. { check if the target processor supports this calling convention }
  1823. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1824. begin
  1825. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1826. { recover }
  1827. proc_direcdata[p].pocall:=pocall_stdcall;
  1828. end;
  1829. pd.proccalloption:=proc_direcdata[p].pocall;
  1830. include(pd.procoptions,po_hascallingconvention);
  1831. end;
  1832. if pd.deftype=procdef then
  1833. begin
  1834. { Check if the directive is only for objects }
  1835. if (pd_object in proc_direcdata[p].pd_flags) and
  1836. not assigned(tprocdef(pd)._class) then
  1837. exit;
  1838. { check if method and directive not for interface }
  1839. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1840. is_interface(tprocdef(pd)._class) then
  1841. exit;
  1842. end;
  1843. { consume directive, and turn flag on }
  1844. consume(token);
  1845. parse_proc_direc:=true;
  1846. { Check the pd_flags if the directive should be allowed }
  1847. if (pd_interface in pdflags) and
  1848. not(pd_interface in proc_direcdata[p].pd_flags) then
  1849. begin
  1850. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1851. exit;
  1852. end;
  1853. if (pd_implemen in pdflags) and
  1854. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1855. begin
  1856. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1857. exit;
  1858. end;
  1859. if (pd_procvar in pdflags) and
  1860. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1861. begin
  1862. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1863. exit;
  1864. end;
  1865. { Return the new pd_flags }
  1866. if not(pd_body in proc_direcdata[p].pd_flags) then
  1867. exclude(pdflags,pd_body);
  1868. { Add the correct flag }
  1869. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1870. { Call the handler }
  1871. if pointer(proc_direcdata[p].handler)<>nil then
  1872. proc_direcdata[p].handler(pd);
  1873. end;
  1874. function proc_get_importname(pd:tprocdef):string;
  1875. begin
  1876. result:='';
  1877. if not(po_external in pd.procoptions) then
  1878. internalerror(200412151);
  1879. { import by number? }
  1880. if pd.import_nr<>0 then
  1881. begin
  1882. { Nothing to do }
  1883. end
  1884. else
  1885. { external name specified }
  1886. if assigned(pd.import_name) then
  1887. begin
  1888. { Win32 imports need to use the normal name since to functions
  1889. can refer to the same DLL function. This is also needed for compatability
  1890. with Delphi and TP7 }
  1891. if not(
  1892. assigned(pd.import_dll) and
  1893. (target_info.system in [system_i386_win32,system_i386_wdosx,
  1894. system_i386_emx,system_i386_os2,system_arm_wince,system_i386_wince])
  1895. ) then
  1896. begin
  1897. if not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1898. result:=pd.import_name^
  1899. else
  1900. result:=target_info.Cprefix+pd.import_name^;
  1901. end;
  1902. end
  1903. else
  1904. begin
  1905. { Default names when importing variables }
  1906. case pd.proccalloption of
  1907. pocall_cdecl :
  1908. begin
  1909. if assigned(pd._class) then
  1910. result:=target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname
  1911. else
  1912. result:=target_info.Cprefix+pd.procsym.realname;
  1913. end;
  1914. pocall_cppdecl :
  1915. begin
  1916. result:=target_info.Cprefix+pd.cplusplusmangledname;
  1917. end;
  1918. else
  1919. begin
  1920. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  1921. if (m_mac in aktmodeswitches) then
  1922. result:=tprocdef(pd).procsym.realname;
  1923. end;
  1924. end;
  1925. end;
  1926. end;
  1927. procedure proc_set_mangledname(pd:tprocdef);
  1928. var
  1929. s : string;
  1930. begin
  1931. { When the mangledname is already set we aren't allowed to change
  1932. it because it can already be used somewhere (PFV) }
  1933. if not(po_has_mangledname in pd.procoptions) then
  1934. begin
  1935. if (po_external in pd.procoptions) then
  1936. begin
  1937. { External Procedures are only allowed to change the mangledname
  1938. in their first declaration }
  1939. if (pd.forwarddef or (not pd.hasforward)) then
  1940. begin
  1941. s:=proc_get_importname(pd);
  1942. if s<>'' then
  1943. pd.setmangledname(s);
  1944. end;
  1945. end
  1946. else
  1947. { Normal procedures }
  1948. begin
  1949. if (po_compilerproc in pd.procoptions) then
  1950. begin
  1951. pd.setmangledname(lower(pd.procsym.name));
  1952. end;
  1953. end;
  1954. end;
  1955. { Public/exported alias names }
  1956. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  1957. not(po_has_public_name in pd.procoptions) then
  1958. begin
  1959. case pd.proccalloption of
  1960. pocall_cdecl :
  1961. begin
  1962. if assigned(pd._class) then
  1963. pd.aliasnames.insert(target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname)
  1964. else
  1965. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  1966. end;
  1967. pocall_cppdecl :
  1968. begin
  1969. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  1970. end;
  1971. end;
  1972. { prevent adding the alias a second time }
  1973. include(pd.procoptions,po_has_public_name);
  1974. end;
  1975. end;
  1976. procedure handle_calling_convention(pd:tabstractprocdef);
  1977. begin
  1978. { set the default calling convention if none provided }
  1979. if not(po_hascallingconvention in pd.procoptions) then
  1980. pd.proccalloption:=aktdefproccall
  1981. else
  1982. begin
  1983. if pd.proccalloption=pocall_none then
  1984. internalerror(200309081);
  1985. end;
  1986. { handle proccall specific settings }
  1987. case pd.proccalloption of
  1988. pocall_cdecl,
  1989. pocall_cppdecl :
  1990. begin
  1991. { check C cdecl para types }
  1992. pd.parast.foreach_static(@check_c_para,nil);
  1993. end;
  1994. pocall_far16 :
  1995. begin
  1996. { Temporary stub, must be rewritten to support OS/2 far16 }
  1997. Message1(parser_w_proc_directive_ignored,'FAR16');
  1998. end;
  1999. end;
  2000. if (po_inline in pd.procoptions) then
  2001. begin
  2002. if not(cs_support_inline in aktmoduleswitches) then
  2003. begin
  2004. Message(parser_e_proc_inline_not_supported);
  2005. exclude(pd.procoptions,po_inline);
  2006. end;
  2007. end;
  2008. { For varargs directive also cdecl and external must be defined }
  2009. if (po_varargs in pd.procoptions) then
  2010. begin
  2011. { check first for external in the interface, if available there
  2012. then the cdecl must also be there since there is no implementation
  2013. available to contain it }
  2014. if parse_only then
  2015. begin
  2016. { if external is available, then cdecl must also be available,
  2017. procvars don't need external }
  2018. if not((po_external in pd.procoptions) or
  2019. (pd.deftype=procvardef)) and
  2020. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2021. Message(parser_e_varargs_need_cdecl_and_external);
  2022. end
  2023. else
  2024. begin
  2025. { both must be defined now }
  2026. if not((po_external in pd.procoptions) or
  2027. (pd.deftype=procvardef)) or
  2028. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2029. Message(parser_e_varargs_need_cdecl_and_external);
  2030. end;
  2031. end;
  2032. { insert hidden high parameters }
  2033. pd.parast.foreach_static(@insert_hidden_para,pd);
  2034. { insert hidden self parameter }
  2035. insert_self_and_vmt_para(pd);
  2036. { insert funcret parameter if required }
  2037. insert_funcret_para(pd);
  2038. { Make var parameters regable, this must be done after the calling
  2039. convention is set. }
  2040. { this must be done before parentfp is insert, because getting all cases
  2041. where parentfp must be in a memory location isn't catched properly so
  2042. we put parentfp never in a register }
  2043. pd.parast.foreach_static(@set_addr_param_regable,pd);
  2044. { insert parentfp parameter if required }
  2045. insert_parentfp_para(pd);
  2046. { Calculate parameter tlist }
  2047. pd.calcparas;
  2048. end;
  2049. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2050. {
  2051. Parse the procedure directives. It does not matter if procedure directives
  2052. are written using ;procdir; or ['procdir'] syntax.
  2053. }
  2054. var
  2055. res : boolean;
  2056. begin
  2057. if (m_mac in aktmodeswitches) and (cs_externally_visible in aktlocalswitches) then
  2058. begin
  2059. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  2060. include(pd.procoptions,po_public);
  2061. include(pd.procoptions,po_has_public_name);
  2062. include(pd.procoptions,po_global);
  2063. end;
  2064. while token in [_ID,_LECKKLAMMER] do
  2065. begin
  2066. if try_to_consume(_LECKKLAMMER) then
  2067. begin
  2068. repeat
  2069. parse_proc_direc(pd,pdflags);
  2070. until not try_to_consume(_COMMA);
  2071. consume(_RECKKLAMMER);
  2072. { we always expect at least '[];' }
  2073. res:=true;
  2074. end
  2075. else
  2076. begin
  2077. res:=parse_proc_direc(pd,pdflags);
  2078. end;
  2079. { A procedure directive normally followed by a semicolon, but in
  2080. a const section or reading a type we should stop when _EQUAL is found,
  2081. because a constant/default value follows }
  2082. if res then
  2083. begin
  2084. if (block_type in [bt_const,bt_type]) and
  2085. (token=_EQUAL) then
  2086. break;
  2087. { support procedure proc;stdcall export; }
  2088. if not(check_proc_directive((pd.deftype=procvardef))) then
  2089. begin
  2090. { support "record p : procedure stdcall end;" and
  2091. "var p : procedure stdcall = nil;" }
  2092. if (pd_procvar in pdflags) and
  2093. (token in [_END,_RKLAMMER,_EQUAL]) then
  2094. break
  2095. else
  2096. consume(_SEMICOLON);
  2097. end;
  2098. end
  2099. else
  2100. break;
  2101. end;
  2102. end;
  2103. procedure parse_var_proc_directives(sym:tsym);
  2104. var
  2105. pdflags : tpdflags;
  2106. pd : tabstractprocdef;
  2107. begin
  2108. pdflags:=[pd_procvar];
  2109. pd:=nil;
  2110. case sym.typ of
  2111. fieldvarsym,
  2112. globalvarsym,
  2113. localvarsym,
  2114. paravarsym :
  2115. pd:=tabstractprocdef(tabstractvarsym(sym).vartype.def);
  2116. typedconstsym :
  2117. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  2118. typesym :
  2119. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  2120. else
  2121. internalerror(2003042617);
  2122. end;
  2123. if pd.deftype<>procvardef then
  2124. internalerror(2003042618);
  2125. { names should never be used anyway }
  2126. parse_proc_directives(pd,pdflags);
  2127. end;
  2128. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2129. var
  2130. pdflags : tpdflags;
  2131. begin
  2132. pdflags:=[pd_object];
  2133. parse_proc_directives(pd,pdflags);
  2134. end;
  2135. function proc_add_definition(var pd:tprocdef):boolean;
  2136. {
  2137. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2138. forwarddef is found and reused it returns true
  2139. }
  2140. var
  2141. hd : tprocdef;
  2142. ad,fd : tsym;
  2143. s1,s2 : stringid;
  2144. i : cardinal;
  2145. forwardfound : boolean;
  2146. po_comp : tprocoptions;
  2147. aprocsym : tprocsym;
  2148. begin
  2149. forwardfound:=false;
  2150. aprocsym:=tprocsym(pd.procsym);
  2151. { check overloaded functions if the same function already exists }
  2152. for i:=1 to aprocsym.procdef_count do
  2153. begin
  2154. hd:=aprocsym.procdef[i];
  2155. { Skip overloaded definitions that are declared in other
  2156. units }
  2157. if hd.procsym<>aprocsym then
  2158. continue;
  2159. { check the parameters, for delphi/tp it is possible to
  2160. leave the parameters away in the implementation (forwarddef=false).
  2161. But for an overload declared function this is not allowed }
  2162. if { check if empty implementation arguments match is allowed }
  2163. (
  2164. not(m_repeat_forward in aktmodeswitches) and
  2165. not(pd.forwarddef) and
  2166. (pd.maxparacount=0) and
  2167. not(po_overload in hd.procoptions)
  2168. ) or
  2169. { check arguments }
  2170. (
  2171. (compare_paras(pd.paras,hd.paras,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  2172. { for operators equal_paras is not enough !! }
  2173. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  2174. { be careful here, equal_defs doesn't take care of unique }
  2175. (hd.rettype.def=pd.rettype.def) or
  2176. (equal_defs(hd.rettype.def,pd.rettype.def) and
  2177. not(df_unique in hd.rettype.def.defoptions) and not(df_unique in pd.rettype.def.defoptions)
  2178. )
  2179. )
  2180. ) then
  2181. begin
  2182. { Check if we've found the forwarddef, if found then
  2183. we need to update the forward def with the current
  2184. implementation settings }
  2185. if hd.forwarddef then
  2186. begin
  2187. forwardfound:=true;
  2188. { Check if the procedure type and return type are correct,
  2189. also the parameters must match also with the type }
  2190. if (hd.proctypeoption<>pd.proctypeoption) or
  2191. (
  2192. (m_repeat_forward in aktmodeswitches) and
  2193. (not((pd.maxparacount=0) or
  2194. (compare_paras(pd.paras,hd.paras,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  2195. ) or
  2196. (
  2197. ((m_repeat_forward in aktmodeswitches) or
  2198. not(is_void(pd.rettype.def))) and
  2199. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  2200. begin
  2201. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2202. pd.fullprocname(false));
  2203. aprocsym.write_parameter_lists(pd);
  2204. break;
  2205. end;
  2206. { Check if both are declared forward }
  2207. if hd.forwarddef and pd.forwarddef then
  2208. begin
  2209. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  2210. pd.fullprocname(false));
  2211. end;
  2212. { internconst or internproc only need to be defined once }
  2213. if (hd.proccalloption=pocall_internproc) then
  2214. pd.proccalloption:=hd.proccalloption
  2215. else
  2216. if (pd.proccalloption=pocall_internproc) then
  2217. hd.proccalloption:=pd.proccalloption;
  2218. { Check calling convention }
  2219. if (hd.proccalloption<>pd.proccalloption) then
  2220. begin
  2221. { In delphi it is possible to specify the calling
  2222. convention in the interface or implementation if
  2223. there was no convention specified in the other
  2224. part }
  2225. if (m_delphi in aktmodeswitches) then
  2226. begin
  2227. if not(po_hascallingconvention in pd.procoptions) then
  2228. pd.proccalloption:=hd.proccalloption
  2229. else
  2230. if not(po_hascallingconvention in hd.procoptions) then
  2231. hd.proccalloption:=pd.proccalloption
  2232. else
  2233. begin
  2234. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2235. aprocsym.write_parameter_lists(pd);
  2236. { restore interface settings }
  2237. pd.proccalloption:=hd.proccalloption;
  2238. end;
  2239. end
  2240. else
  2241. begin
  2242. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  2243. aprocsym.write_parameter_lists(pd);
  2244. { restore interface settings }
  2245. pd.proccalloption:=hd.proccalloption;
  2246. end;
  2247. end;
  2248. { Check procedure options, Delphi requires that class is
  2249. repeated in the implementation for class methods }
  2250. if (m_fpc in aktmodeswitches) then
  2251. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  2252. else
  2253. po_comp:=[po_classmethod,po_methodpointer];
  2254. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  2255. begin
  2256. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  2257. pd.fullprocname(false));
  2258. aprocsym.write_parameter_lists(pd);
  2259. { This error is non-fatal, we can recover }
  2260. end;
  2261. { Forward declaration is external? }
  2262. if (po_external in hd.procoptions) then
  2263. MessagePos(pd.fileinfo,parser_e_proc_already_external);
  2264. { Check parameters }
  2265. if (m_repeat_forward in aktmodeswitches) or
  2266. (pd.minparacount>0) then
  2267. begin
  2268. { If mangled names are equal then they have the same amount of arguments }
  2269. { We can check the names of the arguments }
  2270. { both symtables are in the same order from left to right }
  2271. ad:=tsym(hd.parast.symindex.first);
  2272. fd:=tsym(pd.parast.symindex.first);
  2273. repeat
  2274. { skip default parameter constsyms }
  2275. while assigned(ad) and (ad.typ<>paravarsym) do
  2276. ad:=tsym(ad.indexnext);
  2277. while assigned(fd) and (fd.typ<>paravarsym) do
  2278. fd:=tsym(fd.indexnext);
  2279. { stop when one of the two lists is at the end }
  2280. if not assigned(ad) or not assigned(fd) then
  2281. break;
  2282. { retrieve names, remove reg for register parameters }
  2283. if not(sp_implicitrename in ad.symoptions) and
  2284. not(sp_implicitrename in fd.symoptions) then
  2285. begin
  2286. s1:=ad.name;
  2287. s2:=fd.name;
  2288. { compare names }
  2289. if (s1<>s2) then
  2290. begin
  2291. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  2292. aprocsym.name,s1,s2);
  2293. break;
  2294. end;
  2295. end;
  2296. ad:=tsym(ad.indexnext);
  2297. fd:=tsym(fd.indexnext);
  2298. until false;
  2299. if assigned(ad) xor assigned(fd) then
  2300. internalerror(200204178);
  2301. end;
  2302. { Everything is checked, now we can update the forward declaration
  2303. with the new data from the implementation }
  2304. hd.forwarddef:=pd.forwarddef;
  2305. hd.hasforward:=true;
  2306. hd.procoptions:=hd.procoptions+pd.procoptions;
  2307. if hd.extnumber=65535 then
  2308. hd.extnumber:=pd.extnumber;
  2309. while not pd.aliasnames.empty do
  2310. hd.aliasnames.insert(pd.aliasnames.getfirst);
  2311. { update fileinfo so position references the implementation,
  2312. also update funcretsym if it is already generated }
  2313. hd.fileinfo:=pd.fileinfo;
  2314. if assigned(hd.funcretsym) then
  2315. hd.funcretsym.fileinfo:=pd.fileinfo;
  2316. { import names }
  2317. if assigned(pd.import_dll) then
  2318. begin
  2319. stringdispose(hd.import_dll);
  2320. hd.import_dll:=stringdup(pd.import_dll^);
  2321. end;
  2322. if assigned(pd.import_name) then
  2323. begin
  2324. stringdispose(hd.import_name);
  2325. hd.import_name:=stringdup(pd.import_name^);
  2326. end;
  2327. hd.import_nr:=pd.import_nr;
  2328. { for compilerproc defines we need to rename and update the
  2329. symbolname to lowercase }
  2330. if (po_compilerproc in pd.procoptions) then
  2331. begin
  2332. { rename to lowercase so users can't access it }
  2333. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  2334. { also update the realname that is stored in the ppu }
  2335. stringdispose(aprocsym._realname);
  2336. aprocsym._realname:=stringdup('$'+aprocsym.name);
  2337. { the mangeled name is already changed by the pd_compilerproc }
  2338. { handler. It must be done immediately because if we have a }
  2339. { call to a compilerproc before it's implementation is }
  2340. { encountered, it must already use the new mangled name (JM) }
  2341. end;
  2342. { the procdef will be released by the symtable, we release
  2343. at least the parast }
  2344. pd.releasemem;
  2345. pd:=hd;
  2346. end
  2347. else
  2348. begin
  2349. { abstract methods aren't forward defined, but this }
  2350. { needs another error message }
  2351. if (po_abstractmethod in hd.procoptions) then
  2352. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  2353. else
  2354. begin
  2355. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  2356. aprocsym.write_parameter_lists(pd);
  2357. end;
  2358. end;
  2359. { we found one proc with the same arguments, there are no others
  2360. so we can stop }
  2361. break;
  2362. end;
  2363. { check for allowing overload directive }
  2364. if not(m_fpc in aktmodeswitches) then
  2365. begin
  2366. { overload directive turns on overloading }
  2367. if ((po_overload in pd.procoptions) or
  2368. (po_overload in hd.procoptions)) then
  2369. begin
  2370. { check if all procs have overloading, but not if the proc is a method or
  2371. already declared forward, then the check is already done }
  2372. if not(hd.hasforward or
  2373. assigned(pd._class) or
  2374. (pd.forwarddef<>hd.forwarddef) or
  2375. ((po_overload in pd.procoptions) and
  2376. (po_overload in hd.procoptions))) then
  2377. begin
  2378. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2379. break;
  2380. end;
  2381. end
  2382. else
  2383. begin
  2384. if not(hd.forwarddef) then
  2385. begin
  2386. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2387. break;
  2388. end;
  2389. end;
  2390. end; { equal arguments }
  2391. end;
  2392. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2393. list }
  2394. if not forwardfound then
  2395. aprocsym.addprocdef(pd);
  2396. proc_add_definition:=forwardfound;
  2397. end;
  2398. end.