pdecsub.pas 93 KB

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