pdecsub.pas 110 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996
  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. pd_dispinterface,{ directive can be used with dispinterface methods }
  33. pd_cppobject, { directive can be used with cppclass }
  34. pd_objcclass, { directive can be used with objcclass }
  35. pd_objcprot { directive can be used with objcprotocol }
  36. );
  37. tpdflags=set of tpdflag;
  38. function check_proc_directive(isprocvar:boolean):boolean;
  39. procedure insert_funcret_local(pd:tprocdef);
  40. function proc_add_definition(var currpd:tprocdef):boolean;
  41. function proc_get_importname(pd:tprocdef):string;
  42. procedure proc_set_mangledname(pd:tprocdef);
  43. procedure handle_calling_convention(pd:tabstractprocdef);
  44. procedure parse_parameter_dec(pd:tabstractprocdef);
  45. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  46. procedure parse_var_proc_directives(sym:tsym);
  47. procedure parse_object_proc_directives(pd:tabstractprocdef);
  48. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  49. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  50. implementation
  51. uses
  52. SysUtils,
  53. { common }
  54. cutils,cclasses,
  55. { global }
  56. globtype,globals,verbose,constexp,
  57. systems,
  58. cpuinfo,
  59. { symtable }
  60. symbase,symtable,defutil,defcmp,paramgr,cpupara,
  61. { pass 1 }
  62. fmodule,node,htypechk,
  63. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  64. objcutil,
  65. { parser }
  66. scanner,
  67. pbase,pexpr,ptype,pdecl
  68. ;
  69. const
  70. { Please leave this here, this module should NOT use
  71. these variables.
  72. Declaring it as string here results in an error when compiling (PFV) }
  73. current_procinfo = 'error';
  74. procedure insert_funcret_para(pd:tabstractprocdef);
  75. var
  76. storepos : tfileposinfo;
  77. vs : tparavarsym;
  78. paranr : word;
  79. begin
  80. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  81. not is_void(pd.returndef) and
  82. paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
  83. begin
  84. storepos:=current_tokenpos;
  85. if pd.typ=procdef then
  86. current_tokenpos:=tprocdef(pd).fileinfo;
  87. {$if defined(i386)}
  88. { For left to right add it at the end to be delphi compatible }
  89. if (target_info.system in systems_all_windows) and
  90. (pd.proccalloption in (pushleftright_pocalls+[pocall_safecall])) then
  91. paranr:=paranr_result_leftright
  92. else
  93. {$elseif defined(x86) or defined(arm)}
  94. { other platforms don't have a "safecall" convention,
  95. and never reverse the parameter pushing order
  96. }
  97. if (target_info.system in systems_all_windows) and
  98. (pd.proccalloption = pocall_safecall) then
  99. paranr:=paranr_result_leftright
  100. else
  101. {$endif}
  102. paranr:=paranr_result;
  103. { Generate result variable accessing function result }
  104. vs:=tparavarsym.create('$result',paranr,vs_var,pd.returndef,[vo_is_funcret,vo_is_hidden_para]);
  105. pd.parast.insert(vs);
  106. { Store the this symbol as funcretsym for procedures }
  107. if pd.typ=procdef then
  108. tprocdef(pd).funcretsym:=vs;
  109. current_tokenpos:=storepos;
  110. end;
  111. end;
  112. procedure insert_parentfp_para(pd:tabstractprocdef);
  113. var
  114. storepos : tfileposinfo;
  115. vs : tparavarsym;
  116. begin
  117. if pd.parast.symtablelevel>normal_function_level then
  118. begin
  119. storepos:=current_tokenpos;
  120. if pd.typ=procdef then
  121. current_tokenpos:=tprocdef(pd).fileinfo;
  122. { Generate result variable accessing function result, it
  123. can't be put in a register since it must be accessable
  124. from the framepointer }
  125. vs:=tparavarsym.create('$parentfp',paranr_parentfp,vs_value
  126. ,voidpointertype,[vo_is_parentfp,vo_is_hidden_para]);
  127. vs.varregable:=vr_none;
  128. pd.parast.insert(vs);
  129. current_tokenpos:=storepos;
  130. end;
  131. end;
  132. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  133. var
  134. storepos : tfileposinfo;
  135. vs : tparavarsym;
  136. hdef : tdef;
  137. vsp : tvarspez;
  138. aliasvs : tabsolutevarsym;
  139. sl : tpropaccesslist;
  140. begin
  141. if (pd.typ=procdef) and
  142. is_objc_class_or_protocol(tprocdef(pd)._class) and
  143. (pd.parast.symtablelevel=normal_function_level) then
  144. begin
  145. { insert Objective-C self and selector parameters }
  146. vs:=tparavarsym.create('$_cmd',paranr_objc_cmd,vs_value,objc_seltype,[vo_is_msgsel,vo_is_hidden_para]);
  147. pd.parast.insert(vs);
  148. { make accessible to code }
  149. sl:=tpropaccesslist.create;
  150. sl.addsym(sl_load,vs);
  151. aliasvs:=tabsolutevarsym.create_ref('_CMD',objc_seltype,sl);
  152. include(aliasvs.varoptions,vo_is_msgsel);
  153. tlocalsymtable(tprocdef(pd).localst).insert(aliasvs);
  154. if (po_classmethod in pd.procoptions) then
  155. { compatible with what gcc does }
  156. hdef:=objc_idtype
  157. else
  158. hdef:=tprocdef(pd)._class;
  159. vs:=tparavarsym.create('$self',paranr_objc_self,vs_value,hdef,[vo_is_self,vo_is_hidden_para]);
  160. pd.parast.insert(vs);
  161. end
  162. else if (pd.typ=procvardef) and
  163. pd.is_methodpointer then
  164. begin
  165. { Generate self variable }
  166. vs:=tparavarsym.create('$self',paranr_self,vs_value,voidpointertype,[vo_is_self,vo_is_hidden_para]);
  167. pd.parast.insert(vs);
  168. end
  169. else
  170. begin
  171. if (pd.typ=procdef) and
  172. assigned(tprocdef(pd)._class) and
  173. (pd.parast.symtablelevel=normal_function_level) then
  174. begin
  175. { static class methods have no hidden self/vmt pointer }
  176. if (po_staticmethod in pd.procoptions) and
  177. (po_classmethod in pd.procoptions) then
  178. exit;
  179. storepos:=current_tokenpos;
  180. current_tokenpos:=tprocdef(pd).fileinfo;
  181. { Generate VMT variable for constructor/destructor }
  182. if (pd.proctypeoption in [potype_constructor,potype_destructor]) and not(is_cppclass(tprocdef(pd)._class)) then
  183. begin
  184. { can't use classrefdef as type because inheriting
  185. will then always file because of a type mismatch }
  186. vs:=tparavarsym.create('$vmt',paranr_vmt,vs_value,voidpointertype,[vo_is_vmt,vo_is_hidden_para]);
  187. pd.parast.insert(vs);
  188. end;
  189. { Generate self variable, for classes we need
  190. to use the generic voidpointer to be compatible with
  191. methodpointers }
  192. vsp:=vs_value;
  193. if (po_staticmethod in pd.procoptions) or
  194. (po_classmethod in pd.procoptions) then
  195. hdef:=tclassrefdef.create(tprocdef(pd)._class)
  196. else
  197. begin
  198. if is_object(tprocdef(pd)._class) then
  199. vsp:=vs_var;
  200. hdef:=tprocdef(pd)._class;
  201. end;
  202. vs:=tparavarsym.create('$self',paranr_self,vsp,hdef,[vo_is_self,vo_is_hidden_para]);
  203. pd.parast.insert(vs);
  204. current_tokenpos:=storepos;
  205. end;
  206. end;
  207. end;
  208. procedure insert_funcret_local(pd:tprocdef);
  209. var
  210. storepos : tfileposinfo;
  211. vs : tlocalvarsym;
  212. aliasvs : tabsolutevarsym;
  213. sl : tpropaccesslist;
  214. hs : string;
  215. begin
  216. { The result from constructors and destructors can't be accessed directly }
  217. if not(pd.proctypeoption in [potype_constructor,potype_destructor]) and
  218. not is_void(pd.returndef) then
  219. begin
  220. storepos:=current_tokenpos;
  221. current_tokenpos:=pd.fileinfo;
  222. { We need to insert a varsym for the result in the localst
  223. when it is returning in a register }
  224. if not paramanager.ret_in_param(pd.returndef,pd.proccalloption) then
  225. begin
  226. vs:=tlocalvarsym.create('$result',vs_value,pd.returndef,[vo_is_funcret]);
  227. pd.localst.insert(vs);
  228. pd.funcretsym:=vs;
  229. end;
  230. { insert the name of the procedure as alias for the function result,
  231. we can't use realname because that will not work for compilerprocs
  232. as the name is lowercase and unreachable from the code }
  233. if assigned(pd.resultname) then
  234. hs:=pd.resultname^
  235. else
  236. hs:=pd.procsym.name;
  237. sl:=tpropaccesslist.create;
  238. sl.addsym(sl_load,pd.funcretsym);
  239. aliasvs:=tabsolutevarsym.create_ref(hs,pd.returndef,sl);
  240. include(aliasvs.varoptions,vo_is_funcret);
  241. tlocalsymtable(pd.localst).insert(aliasvs);
  242. { insert result also if support is on }
  243. if (m_result in current_settings.modeswitches) then
  244. begin
  245. sl:=tpropaccesslist.create;
  246. sl.addsym(sl_load,pd.funcretsym);
  247. aliasvs:=tabsolutevarsym.create_ref('RESULT',pd.returndef,sl);
  248. include(aliasvs.varoptions,vo_is_funcret);
  249. include(aliasvs.varoptions,vo_is_result);
  250. tlocalsymtable(pd.localst).insert(aliasvs);
  251. end;
  252. current_tokenpos:=storepos;
  253. end;
  254. end;
  255. procedure insert_hidden_para(p:TObject;arg:pointer);
  256. var
  257. hvs : tparavarsym;
  258. pd : tabstractprocdef absolute arg;
  259. begin
  260. if (tsym(p).typ<>paravarsym) then
  261. exit;
  262. with tparavarsym(p) do
  263. begin
  264. { We need a local copy for a value parameter when only the
  265. address is pushed. Open arrays and Array of Const are
  266. an exception because they are allocated at runtime and the
  267. address that is pushed is patched }
  268. if (varspez=vs_value) and
  269. paramanager.push_addr_param(varspez,vardef,pd.proccalloption) and
  270. not(is_open_array(vardef) or
  271. is_array_of_const(vardef)) then
  272. include(varoptions,vo_has_local_copy);
  273. { needs high parameter ? }
  274. if paramanager.push_high_param(varspez,vardef,pd.proccalloption) then
  275. begin
  276. hvs:=tparavarsym.create('$high'+name,paranr+1,vs_const,sinttype,[vo_is_high_para,vo_is_hidden_para]);
  277. hvs.symoptions:=[];
  278. owner.insert(hvs);
  279. end
  280. else
  281. begin
  282. { Give a warning that cdecl routines does not include high()
  283. support }
  284. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  285. paramanager.push_high_param(varspez,vardef,pocall_default) then
  286. begin
  287. if is_open_string(vardef) then
  288. MessagePos(fileinfo,parser_w_cdecl_no_openstring);
  289. if not(po_external in pd.procoptions) and
  290. (pd.typ<>procvardef) and
  291. not is_objc_class_or_protocol(tprocdef(pd)._class) then
  292. if is_array_of_const(vardef) then
  293. MessagePos(fileinfo,parser_e_varargs_need_cdecl_and_external)
  294. else
  295. MessagePos(fileinfo,parser_w_cdecl_has_no_high);
  296. end;
  297. if (vardef.typ=formaldef) and (Tformaldef(vardef).typed) then
  298. begin
  299. hvs:=tparavarsym.create('$typinfo'+name,paranr+1,vs_const,voidpointertype,
  300. [vo_is_typinfo_para,vo_is_hidden_para]);
  301. owner.insert(hvs);
  302. end;
  303. end;
  304. end;
  305. end;
  306. procedure check_c_para(pd:Tabstractprocdef);
  307. var
  308. i,
  309. lastparaidx : longint;
  310. sym : TSym;
  311. begin
  312. lastparaidx:=pd.parast.SymList.Count-1;
  313. for i:=0 to pd.parast.SymList.Count-1 do
  314. begin
  315. sym:=tsym(pd.parast.SymList[i]);
  316. if (sym.typ=paravarsym) and
  317. (tparavarsym(sym).vardef.typ=arraydef) then
  318. begin
  319. if not is_variant_array(tparavarsym(sym).vardef) and
  320. not is_array_of_const(tparavarsym(sym).vardef) and
  321. (tparavarsym(sym).varspez<>vs_var) then
  322. MessagePos(tparavarsym(sym).fileinfo,parser_h_c_arrays_are_references);
  323. if is_array_of_const(tparavarsym(sym).vardef) and
  324. (i<lastparaidx) and
  325. (tsym(pd.parast.SymList[i+1]).typ=paravarsym) and
  326. not(vo_is_high_para in tparavarsym(pd.parast.SymList[i+1]).varoptions) then
  327. MessagePos(tparavarsym(sym).fileinfo,parser_e_C_array_of_const_must_be_last);
  328. end;
  329. end;
  330. end;
  331. procedure check_msg_para(p:TObject;arg:pointer);
  332. begin
  333. if (tsym(p).typ<>paravarsym) then
  334. exit;
  335. with tparavarsym(p) do
  336. begin
  337. { Count parameters }
  338. if (paranr>=10) then
  339. inc(plongint(arg)^);
  340. { First parameter must be var }
  341. if (paranr=10) and
  342. (varspez<>vs_var) then
  343. MessagePos(fileinfo,parser_e_ill_msg_param);
  344. end;
  345. end;
  346. procedure set_addr_param_regable(p:TObject;arg:pointer);
  347. begin
  348. if (tsym(p).typ<>paravarsym) then
  349. exit;
  350. with tparavarsym(p) do
  351. begin
  352. if not vardef.needs_inittable and
  353. paramanager.push_addr_param(varspez,vardef,tprocdef(arg).proccalloption) then
  354. varregable:=vr_intreg;
  355. end;
  356. end;
  357. procedure parse_parameter_dec(pd:tabstractprocdef);
  358. {
  359. handle_procvar needs the same changes
  360. }
  361. type
  362. tppv = (pv_none,pv_proc,pv_func);
  363. var
  364. sc : TFPObjectList;
  365. hdef : tdef;
  366. arrayelementdef : tdef;
  367. vs : tparavarsym;
  368. i : longint;
  369. srsym : tsym;
  370. pv : tprocvardef;
  371. varspez : Tvarspez;
  372. defaultvalue : tconstsym;
  373. defaultrequired : boolean;
  374. old_block_type : tblock_type;
  375. currparast : tparasymtable;
  376. parseprocvar : tppv;
  377. locationstr : string;
  378. paranr : integer;
  379. dummytype : ttypesym;
  380. explicit_paraloc,
  381. need_array: boolean;
  382. begin
  383. old_block_type:=block_type;
  384. explicit_paraloc:=false;
  385. consume(_LKLAMMER);
  386. { Delphi/Kylix supports nonsense like }
  387. { procedure p(); }
  388. if try_to_consume(_RKLAMMER) and
  389. not(m_tp7 in current_settings.modeswitches) then
  390. exit;
  391. { parsing a proc or procvar ? }
  392. currparast:=tparasymtable(pd.parast);
  393. { reset }
  394. sc:=TFPObjectList.create(false);
  395. defaultrequired:=false;
  396. paranr:=0;
  397. inc(testcurobject);
  398. block_type:=bt_var;
  399. repeat
  400. parseprocvar:=pv_none;
  401. if try_to_consume(_VAR) then
  402. varspez:=vs_var
  403. else
  404. if try_to_consume(_CONST) then
  405. varspez:=vs_const
  406. else
  407. if (m_out in current_settings.modeswitches) and
  408. try_to_consume(_OUT) then
  409. varspez:=vs_out
  410. else
  411. if (m_mac in current_settings.modeswitches) and
  412. try_to_consume(_POINTPOINTPOINT) then
  413. begin
  414. include(pd.procoptions,po_varargs);
  415. break;
  416. end
  417. else
  418. if (m_mac in current_settings.modeswitches) and
  419. try_to_consume(_PROCEDURE) then
  420. begin
  421. parseprocvar:=pv_proc;
  422. varspez:=vs_const;
  423. end
  424. else
  425. if (m_mac in current_settings.modeswitches) and
  426. try_to_consume(_FUNCTION) then
  427. begin
  428. parseprocvar:=pv_func;
  429. varspez:=vs_const;
  430. end
  431. else
  432. varspez:=vs_value;
  433. defaultvalue:=nil;
  434. hdef:=nil;
  435. { read identifiers and insert with error type }
  436. sc.clear;
  437. repeat
  438. inc(paranr);
  439. vs:=tparavarsym.create(orgpattern,paranr*10,varspez,generrordef,[]);
  440. currparast.insert(vs);
  441. if assigned(vs.owner) then
  442. sc.add(vs)
  443. else
  444. vs.free;
  445. consume(_ID);
  446. until not try_to_consume(_COMMA);
  447. locationstr:='';
  448. { macpas anonymous procvar }
  449. if parseprocvar<>pv_none then
  450. begin
  451. pv:=tprocvardef.create(normal_function_level);
  452. if token=_LKLAMMER then
  453. parse_parameter_dec(pv);
  454. if parseprocvar=pv_func then
  455. begin
  456. block_type:=bt_var_type;
  457. consume(_COLON);
  458. single_type(pv.returndef,false,false);
  459. block_type:=bt_var;
  460. end;
  461. hdef:=pv;
  462. { possible proc directives }
  463. if check_proc_directive(true) then
  464. begin
  465. dummytype:=ttypesym.create('unnamed',hdef);
  466. parse_var_proc_directives(tsym(dummytype));
  467. dummytype.typedef:=nil;
  468. hdef.typesym:=nil;
  469. dummytype.free;
  470. end;
  471. { Add implicit hidden parameters and function result }
  472. handle_calling_convention(pv);
  473. end
  474. else
  475. { read type declaration, force reading for value and const paras }
  476. if (token=_COLON) or (varspez=vs_value) then
  477. begin
  478. consume(_COLON);
  479. { check for an open array }
  480. need_array:=false;
  481. { bitpacked open array are not yet supported }
  482. if (token=_PACKED) and
  483. not(cs_bitpacking in current_settings.localswitches) then
  484. begin
  485. consume(_PACKED);
  486. need_array:=true;
  487. end;
  488. if (token=_ARRAY) or
  489. need_array then
  490. begin
  491. consume(_ARRAY);
  492. consume(_OF);
  493. { define range and type of range }
  494. hdef:=tarraydef.create(0,-1,s32inttype);
  495. { array of const ? }
  496. if (token=_CONST) and (m_objpas in current_settings.modeswitches) then
  497. begin
  498. consume(_CONST);
  499. srsym:=search_system_type('TVARREC');
  500. tarraydef(hdef).elementdef:=ttypesym(srsym).typedef;
  501. include(tarraydef(hdef).arrayoptions,ado_IsArrayOfConst);
  502. end
  503. else
  504. begin
  505. { define field type }
  506. single_type(arrayelementdef,false,false);
  507. tarraydef(hdef).elementdef:=arrayelementdef;
  508. end;
  509. end
  510. else
  511. begin
  512. if (m_mac in current_settings.modeswitches) then
  513. try_to_consume(_UNIV); {currently does nothing}
  514. if try_to_consume(_TYPE) then
  515. hdef:=ctypedformaltype
  516. else
  517. begin
  518. block_type:=bt_var_type;
  519. single_type(hdef,false,false);
  520. block_type:=bt_var;
  521. end;
  522. { open string ? }
  523. if (varspez in [vs_out,vs_var]) and
  524. (cs_openstring in current_settings.moduleswitches) and
  525. is_shortstring(hdef) then
  526. hdef:=openshortstringtype;
  527. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  528. begin
  529. if (idtoken=_LOCATION) then
  530. begin
  531. consume(_LOCATION);
  532. locationstr:=pattern;
  533. consume(_CSTRING);
  534. end
  535. else
  536. begin
  537. if explicit_paraloc then
  538. Message(parser_e_paraloc_all_paras);
  539. locationstr:='';
  540. end;
  541. end
  542. else
  543. locationstr:='';
  544. { default parameter }
  545. if (m_default_para in current_settings.modeswitches) then
  546. begin
  547. if try_to_consume(_EQUAL) then
  548. begin
  549. vs:=tparavarsym(sc[0]);
  550. if sc.count>1 then
  551. Message(parser_e_default_value_only_one_para);
  552. { prefix 'def' to the parameter name }
  553. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  554. if assigned(defaultvalue) then
  555. begin
  556. include(defaultvalue.symoptions,sp_internal);
  557. pd.parast.insert(defaultvalue);
  558. end;
  559. defaultrequired:=true;
  560. end
  561. else
  562. begin
  563. if defaultrequired then
  564. Message1(parser_e_default_value_expected_for_para,vs.name);
  565. end;
  566. end;
  567. end;
  568. end
  569. else
  570. hdef:=cformaltype;
  571. { File types are only allowed for var and out parameters }
  572. if (hdef.typ=filedef) and
  573. not(varspez in [vs_out,vs_var]) then
  574. CGMessage(cg_e_file_must_call_by_reference);
  575. for i:=0 to sc.count-1 do
  576. begin
  577. vs:=tparavarsym(sc[i]);
  578. { update varsym }
  579. vs.vardef:=hdef;
  580. vs.defaultconstsym:=defaultvalue;
  581. if (target_info.system in [system_powerpc_morphos,system_m68k_amiga]) then
  582. begin
  583. if locationstr<>'' then
  584. begin
  585. if sc.count>1 then
  586. Message(parser_e_paraloc_only_one_para);
  587. if (paranr>1) and not(explicit_paraloc) then
  588. Message(parser_e_paraloc_all_paras);
  589. explicit_paraloc:=true;
  590. include(vs.varoptions,vo_has_explicit_paraloc);
  591. if not(paramanager.parseparaloc(vs,upper(locationstr))) then
  592. message(parser_e_illegal_explicit_paraloc);
  593. end
  594. else
  595. if explicit_paraloc then
  596. Message(parser_e_paraloc_all_paras);
  597. end;
  598. end;
  599. until not try_to_consume(_SEMICOLON);
  600. if explicit_paraloc then
  601. begin
  602. pd.has_paraloc_info:=true;
  603. include(pd.procoptions,po_explicitparaloc);
  604. end;
  605. { remove parasymtable from stack }
  606. sc.free;
  607. { reset object options }
  608. dec(testcurobject);
  609. block_type:=old_block_type;
  610. consume(_RKLAMMER);
  611. end;
  612. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  613. var
  614. hs : string;
  615. orgsp,sp : TIDString;
  616. srsym : tsym;
  617. srsymtable : TSymtable;
  618. checkstack : psymtablestackitem;
  619. storepos,
  620. procstartfilepos : tfileposinfo;
  621. searchagain : boolean;
  622. st,
  623. genericst : TSymtable;
  624. aprocsym : tprocsym;
  625. popclass : boolean;
  626. ImplIntf : TImplementedInterface;
  627. old_parse_generic : boolean;
  628. begin
  629. { Save the position where this procedure really starts }
  630. procstartfilepos:=current_tokenpos;
  631. old_parse_generic:=parse_generic;
  632. result:=false;
  633. pd:=nil;
  634. aprocsym:=nil;
  635. if (potype=potype_operator) then
  636. begin
  637. sp:=overloaded_names[optoken];
  638. orgsp:=sp;
  639. end
  640. else
  641. begin
  642. sp:=pattern;
  643. orgsp:=orgpattern;
  644. consume(_ID);
  645. end;
  646. { examine interface map: function/procedure iname.functionname=locfuncname }
  647. if assigned(aclass) and
  648. assigned(aclass.ImplementedInterfaces) and
  649. (aclass.ImplementedInterfaces.count>0) and
  650. try_to_consume(_POINT) then
  651. begin
  652. storepos:=current_tokenpos;
  653. current_tokenpos:=procstartfilepos;
  654. { get interface syms}
  655. searchsym(sp,srsym,srsymtable);
  656. if not assigned(srsym) then
  657. begin
  658. identifier_not_found(orgsp);
  659. srsym:=generrorsym;
  660. end;
  661. current_tokenpos:=storepos;
  662. { qualifier is interface? }
  663. ImplIntf:=nil;
  664. if (srsym.typ=typesym) and
  665. (ttypesym(srsym).typedef.typ=objectdef) then
  666. ImplIntf:=aclass.find_implemented_interface(tobjectdef(ttypesym(srsym).typedef));
  667. if ImplIntf=nil then
  668. Message(parser_e_interface_id_expected);
  669. consume(_ID);
  670. { Create unique name <interface>.<method> }
  671. hs:=sp+'.'+pattern;
  672. consume(_EQUAL);
  673. if assigned(ImplIntf) and
  674. (token=_ID) then
  675. ImplIntf.AddMapping(hs,pattern);
  676. consume(_ID);
  677. result:=true;
  678. exit;
  679. end;
  680. { method ? }
  681. if not assigned(aclass) and
  682. (potype<>potype_operator) and
  683. (symtablestack.top.symtablelevel=main_program_level) and
  684. try_to_consume(_POINT) then
  685. begin
  686. { search for object name }
  687. storepos:=current_tokenpos;
  688. current_tokenpos:=procstartfilepos;
  689. searchsym(sp,srsym,srsymtable);
  690. if not assigned(srsym) then
  691. begin
  692. identifier_not_found(orgsp);
  693. srsym:=generrorsym;
  694. end;
  695. current_tokenpos:=storepos;
  696. { consume proc name }
  697. sp:=pattern;
  698. orgsp:=orgpattern;
  699. procstartfilepos:=current_tokenpos;
  700. consume(_ID);
  701. { qualifier is class name ? }
  702. if (srsym.typ=typesym) and
  703. (ttypesym(srsym).typedef.typ=objectdef) then
  704. begin
  705. aclass:=tobjectdef(ttypesym(srsym).typedef);
  706. srsym:=tsym(aclass.symtable.Find(sp));
  707. if assigned(srsym) then
  708. begin
  709. if srsym.typ=procsym then
  710. aprocsym:=tprocsym(srsym)
  711. else
  712. begin
  713. { we use a different error message for tp7 so it looks more compatible }
  714. if (m_fpc in current_settings.modeswitches) then
  715. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  716. else
  717. Message(parser_e_methode_id_expected);
  718. { rename the name to an unique name to avoid an
  719. error when inserting the symbol in the symtable }
  720. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  721. end;
  722. end
  723. else
  724. begin
  725. Message(parser_e_methode_id_expected);
  726. { recover by making it a normal procedure instead of method }
  727. aclass:=nil;
  728. end;
  729. end
  730. else
  731. Message(parser_e_class_id_expected);
  732. end
  733. else
  734. begin
  735. { check for constructor/destructor which is not allowed here }
  736. if (not parse_only) and
  737. (potype in [potype_constructor,potype_destructor]) then
  738. Message(parser_e_constructors_always_objects);
  739. repeat
  740. searchagain:=false;
  741. current_tokenpos:=procstartfilepos;
  742. srsymtable:=symtablestack.top;
  743. srsym:=tsym(srsymtable.Find(sp));
  744. { Also look in the globalsymtable if we didn't found
  745. the symbol in the localsymtable }
  746. if not assigned(srsym) and
  747. not(parse_only) and
  748. (srsymtable=current_module.localsymtable) and
  749. assigned(current_module.globalsymtable) then
  750. srsym:=tsym(current_module.globalsymtable.Find(sp));
  751. { Check if overloaded is a procsym }
  752. if assigned(srsym) then
  753. begin
  754. if srsym.typ=procsym then
  755. aprocsym:=tprocsym(srsym)
  756. else
  757. begin
  758. { when the other symbol is a unit symbol then hide the unit
  759. symbol, this is not supported in tp7 }
  760. if not(m_tp7 in current_settings.modeswitches) and
  761. (srsym.typ=unitsym) then
  762. begin
  763. HideSym(srsym);
  764. searchagain:=true;
  765. end
  766. else
  767. begin
  768. { we use a different error message for tp7 so it looks more compatible }
  769. if (m_fpc in current_settings.modeswitches) then
  770. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  771. else
  772. Message1(sym_e_duplicate_id,srsym.realname);
  773. { rename the name to an unique name to avoid an
  774. error when inserting the symbol in the symtable }
  775. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  776. end;
  777. end;
  778. end;
  779. until not searchagain;
  780. end;
  781. { test again if assigned, it can be reset to recover }
  782. if not assigned(aprocsym) then
  783. begin
  784. { create a new procsym and set the real filepos }
  785. current_tokenpos:=procstartfilepos;
  786. { for operator we have only one procsym for each overloaded
  787. operation }
  788. if (potype=potype_operator) then
  789. begin
  790. Aprocsym:=Tprocsym(symtablestack.top.Find(sp));
  791. if Aprocsym=nil then
  792. Aprocsym:=tprocsym.create('$'+sp);
  793. end
  794. else
  795. aprocsym:=tprocsym.create(orgsp);
  796. symtablestack.top.insert(aprocsym);
  797. end;
  798. { to get the correct symtablelevel we must ignore ObjectSymtables }
  799. st:=nil;
  800. checkstack:=symtablestack.stack;
  801. while assigned(checkstack) do
  802. begin
  803. st:=checkstack^.symtable;
  804. if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
  805. break;
  806. checkstack:=checkstack^.next;
  807. end;
  808. pd:=tprocdef.create(st.symtablelevel+1);
  809. pd._class:=aclass;
  810. pd.procsym:=aprocsym;
  811. pd.proctypeoption:=potype;
  812. { methods inherit df_generic or df_specialization from the objectdef }
  813. if assigned(pd._class) and
  814. (pd.parast.symtablelevel=normal_function_level) then
  815. begin
  816. if (df_generic in pd._class.defoptions) then
  817. begin
  818. include(pd.defoptions,df_generic);
  819. parse_generic:=true;
  820. end;
  821. if (df_specialization in pd._class.defoptions) then
  822. begin
  823. include(pd.defoptions,df_specialization);
  824. { Find corresponding genericdef, we need it later to
  825. replay the tokens to generate the body }
  826. if not assigned(pd._class.genericdef) then
  827. internalerror(200512113);
  828. genericst:=pd._class.genericdef.GetSymtable(gs_record);
  829. if not assigned(genericst) then
  830. internalerror(200512114);
  831. { We are parsing the same objectdef, the def index numbers
  832. are the same }
  833. pd.genericdef:=tstoreddef(genericst.DefList[pd.owner.DefList.IndexOf(pd)]);
  834. if not assigned(pd.genericdef) or
  835. (pd.genericdef.typ<>procdef) then
  836. internalerror(200512115);
  837. end;
  838. end;
  839. { methods need to be exported }
  840. if assigned(aclass) and
  841. (
  842. (symtablestack.top.symtabletype=ObjectSymtable) or
  843. (symtablestack.top.symtablelevel=main_program_level)
  844. ) then
  845. include(pd.procoptions,po_global);
  846. { symbol options that need to be kept per procdef }
  847. pd.fileinfo:=procstartfilepos;
  848. pd.visibility:=symtablestack.top.currentvisibility;
  849. if symtablestack.top.currentlyoptional then
  850. include(pd.procoptions,po_optional);
  851. { parse parameters }
  852. if token=_LKLAMMER then
  853. begin
  854. { Add ObjectSymtable to be able to find generic type definitions }
  855. popclass:=false;
  856. if assigned(pd._class) and
  857. (pd.parast.symtablelevel=normal_function_level) and
  858. (symtablestack.top.symtabletype<>ObjectSymtable) then
  859. begin
  860. symtablestack.push(pd._class.symtable);
  861. popclass:=true;
  862. end;
  863. { Add parameter symtable }
  864. if pd.parast.symtabletype<>staticsymtable then
  865. symtablestack.push(pd.parast);
  866. parse_parameter_dec(pd);
  867. if pd.parast.symtabletype<>staticsymtable then
  868. symtablestack.pop(pd.parast);
  869. if popclass then
  870. symtablestack.pop(pd._class.symtable);
  871. end;
  872. parse_generic:=old_parse_generic;
  873. result:=true;
  874. end;
  875. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  876. var
  877. pd : tprocdef;
  878. isclassmethod : boolean;
  879. locationstr: string;
  880. old_parse_generic,
  881. popclass : boolean;
  882. begin
  883. locationstr:='';
  884. pd:=nil;
  885. isclassmethod:=false;
  886. { read class method }
  887. if try_to_consume(_CLASS) then
  888. begin
  889. { class method only allowed for procedures and functions }
  890. if not(token in [_FUNCTION,_PROCEDURE]) then
  891. Message(parser_e_procedure_or_function_expected);
  892. if is_interface(aclass) then
  893. Message(parser_e_no_static_method_in_interfaces)
  894. else
  895. { class methods are also allowed for Objective-C protocols }
  896. isclassmethod:=true;
  897. end;
  898. case token of
  899. _FUNCTION :
  900. begin
  901. consume(_FUNCTION);
  902. if parse_proc_head(aclass,potype_function,pd) then
  903. begin
  904. { pd=nil when it is a interface mapping }
  905. if assigned(pd) then
  906. begin
  907. if try_to_consume(_COLON) then
  908. begin
  909. old_parse_generic:=parse_generic;
  910. inc(testcurobject);
  911. { Add ObjectSymtable to be able to find generic type definitions }
  912. popclass:=false;
  913. if assigned(pd._class) and
  914. (pd.parast.symtablelevel=normal_function_level) and
  915. (symtablestack.top.symtabletype<>ObjectSymtable) then
  916. begin
  917. symtablestack.push(pd._class.symtable);
  918. popclass:=true;
  919. parse_generic:=(df_generic in pd._class.defoptions);
  920. end;
  921. single_type(pd.returndef,false,false);
  922. if popclass then
  923. symtablestack.pop(pd._class.symtable);
  924. dec(testcurobject);
  925. parse_generic:=old_parse_generic;
  926. if (target_info.system in [system_m68k_amiga]) then
  927. begin
  928. if (idtoken=_LOCATION) then
  929. begin
  930. if po_explicitparaloc in pd.procoptions then
  931. begin
  932. consume(_LOCATION);
  933. locationstr:=pattern;
  934. consume(_CSTRING);
  935. end
  936. else
  937. { I guess this needs a new message... (KB) }
  938. Message(parser_e_paraloc_all_paras);
  939. end
  940. else
  941. begin
  942. if po_explicitparaloc in pd.procoptions then
  943. { assign default locationstr, if none specified }
  944. { and we've arguments with explicit paraloc }
  945. locationstr:='D0';
  946. end;
  947. end;
  948. end
  949. else
  950. begin
  951. if (
  952. parse_only and
  953. not(is_interface(pd._class))
  954. ) or
  955. (m_repeat_forward in current_settings.modeswitches) then
  956. begin
  957. consume(_COLON);
  958. consume_all_until(_SEMICOLON);
  959. end;
  960. end;
  961. if isclassmethod then
  962. include(pd.procoptions,po_classmethod);
  963. end;
  964. end
  965. else
  966. begin
  967. { recover }
  968. consume(_COLON);
  969. consume_all_until(_SEMICOLON);
  970. end;
  971. end;
  972. _PROCEDURE :
  973. begin
  974. consume(_PROCEDURE);
  975. if parse_proc_head(aclass,potype_procedure,pd) then
  976. begin
  977. { pd=nil when it is an interface mapping }
  978. if assigned(pd) then
  979. begin
  980. pd.returndef:=voidtype;
  981. if isclassmethod then
  982. include(pd.procoptions,po_classmethod);
  983. end;
  984. end;
  985. end;
  986. _CONSTRUCTOR :
  987. begin
  988. consume(_CONSTRUCTOR);
  989. parse_proc_head(aclass,potype_constructor,pd);
  990. if assigned(pd) and
  991. assigned(pd._class) then
  992. begin
  993. { Set return type, class constructors return the
  994. created instance, object constructors return boolean }
  995. if is_class(pd._class) then
  996. pd.returndef:=pd._class
  997. else
  998. {$ifdef CPU64bitaddr}
  999. pd.returndef:=bool64type;
  1000. {$else CPU64bitaddr}
  1001. pd.returndef:=bool32type;
  1002. {$endif CPU64bitaddr}
  1003. end;
  1004. end;
  1005. _DESTRUCTOR :
  1006. begin
  1007. consume(_DESTRUCTOR);
  1008. parse_proc_head(aclass,potype_destructor,pd);
  1009. if assigned(pd) then
  1010. pd.returndef:=voidtype;
  1011. end;
  1012. _OPERATOR :
  1013. begin
  1014. consume(_OPERATOR);
  1015. if (token in [first_overloaded..last_overloaded]) then
  1016. begin
  1017. optoken:=token;
  1018. end
  1019. else
  1020. begin
  1021. { Use the dummy NOTOKEN that is also declared
  1022. for the overloaded_operator[] }
  1023. optoken:=NOTOKEN;
  1024. case token of
  1025. _CARET:
  1026. Message1(parser_e_overload_operator_failed,'**');
  1027. _ID:
  1028. if idtoken = _ENUMERATOR then
  1029. optoken := _OP_ENUMERATOR
  1030. else
  1031. Message1(parser_e_overload_operator_failed,'');
  1032. _UNEQUAL:
  1033. Message1(parser_e_overload_operator_failed,'=');
  1034. else
  1035. Message1(parser_e_overload_operator_failed,'');
  1036. end;
  1037. end;
  1038. consume(token);
  1039. parse_proc_head(aclass,potype_operator,pd);
  1040. if assigned(pd) then
  1041. begin
  1042. { operators always need to be searched in all units }
  1043. include(pd.procoptions,po_overload);
  1044. if pd.parast.symtablelevel>normal_function_level then
  1045. Message(parser_e_no_local_operator);
  1046. if token<>_ID then
  1047. begin
  1048. if not(m_result in current_settings.modeswitches) then
  1049. consume(_ID);
  1050. end
  1051. else
  1052. begin
  1053. pd.resultname:=stringdup(orgpattern);
  1054. consume(_ID);
  1055. end;
  1056. if not try_to_consume(_COLON) then
  1057. begin
  1058. consume(_COLON);
  1059. pd.returndef:=generrordef;
  1060. consume_all_until(_SEMICOLON);
  1061. end
  1062. else
  1063. begin
  1064. single_type(pd.returndef,false,false);
  1065. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  1066. ((pd.returndef.typ<>orddef) or
  1067. (torddef(pd.returndef).ordtype<>pasbool)) then
  1068. Message(parser_e_comparative_operator_return_boolean);
  1069. if (optoken=_ASSIGNMENT) and
  1070. equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) then
  1071. message(parser_e_no_such_assignment)
  1072. else if not isoperatoracceptable(pd,optoken) then
  1073. Message(parser_e_overload_impossible);
  1074. end;
  1075. end
  1076. else
  1077. begin
  1078. { recover }
  1079. try_to_consume(_ID);
  1080. consume(_COLON);
  1081. consume_all_until(_SEMICOLON);
  1082. end;
  1083. end;
  1084. end;
  1085. { file types can't be function results }
  1086. if assigned(pd) and
  1087. (pd.returndef.typ=filedef) then
  1088. message(parser_e_illegal_function_result);
  1089. { support procedure proc stdcall export; }
  1090. if not(check_proc_directive(false)) then
  1091. begin
  1092. if (token=_COLON) then
  1093. begin
  1094. message(parser_e_field_not_allowed_here);
  1095. consume_all_until(_SEMICOLON);
  1096. end;
  1097. consume(_SEMICOLON);
  1098. end;
  1099. result:=pd;
  1100. if locationstr<>'' then
  1101. begin
  1102. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1103. { I guess this needs a new message... (KB) }
  1104. message(parser_e_illegal_explicit_paraloc);
  1105. end;
  1106. end;
  1107. {****************************************************************************
  1108. Procedure directive handlers
  1109. ****************************************************************************}
  1110. procedure pd_far(pd:tabstractprocdef);
  1111. begin
  1112. Message1(parser_w_proc_directive_ignored,'FAR');
  1113. end;
  1114. procedure pd_near(pd:tabstractprocdef);
  1115. begin
  1116. Message1(parser_w_proc_directive_ignored,'NEAR');
  1117. end;
  1118. procedure pd_export(pd:tabstractprocdef);
  1119. begin
  1120. if pd.typ<>procdef then
  1121. internalerror(200304264);
  1122. if assigned(tprocdef(pd)._class) then
  1123. Message(parser_e_methods_dont_be_export);
  1124. if pd.parast.symtablelevel>normal_function_level then
  1125. Message(parser_e_dont_nest_export);
  1126. end;
  1127. procedure pd_forward(pd:tabstractprocdef);
  1128. begin
  1129. if pd.typ<>procdef then
  1130. internalerror(200304265);
  1131. tprocdef(pd).forwarddef:=true;
  1132. end;
  1133. procedure pd_alias(pd:tabstractprocdef);
  1134. begin
  1135. if pd.typ<>procdef then
  1136. internalerror(200304266);
  1137. consume(_COLON);
  1138. tprocdef(pd).aliasnames.insert(get_stringconst);
  1139. include(pd.procoptions,po_has_public_name);
  1140. end;
  1141. procedure pd_public(pd:tabstractprocdef);
  1142. begin
  1143. if pd.typ<>procdef then
  1144. internalerror(200304266);
  1145. if try_to_consume(_NAME) then
  1146. begin
  1147. tprocdef(pd).aliasnames.insert(get_stringconst);
  1148. include(pd.procoptions,po_has_public_name);
  1149. end;
  1150. end;
  1151. procedure pd_asmname(pd:tabstractprocdef);
  1152. begin
  1153. if pd.typ<>procdef then
  1154. internalerror(200304267);
  1155. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1156. if token=_CCHAR then
  1157. consume(_CCHAR)
  1158. else
  1159. consume(_CSTRING);
  1160. { we don't need anything else }
  1161. tprocdef(pd).forwarddef:=false;
  1162. end;
  1163. procedure pd_internconst(pd:tabstractprocdef);
  1164. var v:Tconstexprint;
  1165. begin
  1166. if pd.typ<>procdef then
  1167. internalerror(200304268);
  1168. consume(_COLON);
  1169. v:=get_intconst;
  1170. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1171. message(parser_e_range_check_error)
  1172. else
  1173. Tprocdef(pd).extnumber:=longint(v.svalue);
  1174. end;
  1175. procedure pd_internproc(pd:tabstractprocdef);
  1176. var v:Tconstexprint;
  1177. begin
  1178. if pd.typ<>procdef then
  1179. internalerror(200304268);
  1180. consume(_COLON);
  1181. v:=get_intconst;
  1182. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1183. message(parser_e_range_check_error)
  1184. else
  1185. Tprocdef(pd).extnumber:=longint(v.svalue);
  1186. { the proc is defined }
  1187. tprocdef(pd).forwarddef:=false;
  1188. end;
  1189. procedure pd_interrupt(pd:tabstractprocdef);
  1190. begin
  1191. if pd.parast.symtablelevel>normal_function_level then
  1192. Message(parser_e_dont_nest_interrupt);
  1193. end;
  1194. procedure pd_abstract(pd:tabstractprocdef);
  1195. begin
  1196. if pd.typ<>procdef then
  1197. internalerror(200304269);
  1198. if oo_is_sealed in tprocdef(pd)._class.objectoptions then
  1199. Message(parser_e_sealed_class_cannot_have_abstract_methods)
  1200. else
  1201. if (po_virtualmethod in pd.procoptions) then
  1202. include(pd.procoptions,po_abstractmethod)
  1203. else
  1204. Message(parser_e_only_virtual_methods_abstract);
  1205. { the method is defined }
  1206. tprocdef(pd).forwarddef:=false;
  1207. end;
  1208. procedure pd_final(pd:tabstractprocdef);
  1209. begin
  1210. if pd.typ<>procdef then
  1211. internalerror(200910170);
  1212. if (po_virtualmethod in pd.procoptions) then
  1213. include(pd.procoptions,po_finalmethod)
  1214. else
  1215. Message(parser_e_only_virtual_methods_final);
  1216. end;
  1217. procedure pd_enumerator(pd:tabstractprocdef);
  1218. begin
  1219. if pd.typ<>procdef then
  1220. internalerror(200910250);
  1221. if (token = _ID) then
  1222. begin
  1223. if pattern='MOVENEXT' then
  1224. begin
  1225. if oo_has_enumerator_movenext in tprocdef(pd)._class.objectoptions then
  1226. message(parser_e_only_one_enumerator_movenext);
  1227. pd.calcparas;
  1228. if (pd.proctypeoption = potype_function) and is_boolean(pd.returndef) and
  1229. (pd.minparacount = 0) then
  1230. begin
  1231. include(tprocdef(pd)._class.objectoptions, oo_has_enumerator_movenext);
  1232. include(pd.procoptions,po_enumerator_movenext);
  1233. end
  1234. else
  1235. Message(parser_e_enumerator_movenext_is_not_valid)
  1236. end
  1237. else
  1238. Message1(parser_e_invalid_enumerator_identifier, pattern);
  1239. consume(token);
  1240. end
  1241. else
  1242. Message(parser_e_enumerator_identifier_required);
  1243. end;
  1244. procedure pd_virtual(pd:tabstractprocdef);
  1245. {$ifdef WITHDMT}
  1246. var
  1247. pt : tnode;
  1248. {$endif WITHDMT}
  1249. begin
  1250. if pd.typ<>procdef then
  1251. internalerror(2003042610);
  1252. if (pd.proctypeoption=potype_constructor) and
  1253. is_object(tprocdef(pd)._class) then
  1254. Message(parser_e_constructor_cannot_be_not_virtual);
  1255. {$ifdef WITHDMT}
  1256. if is_object(tprocdef(pd)._class) and
  1257. (token<>_SEMICOLON) then
  1258. begin
  1259. { any type of parameter is allowed here! }
  1260. pt:=comp_expr(true);
  1261. if is_constintnode(pt) then
  1262. begin
  1263. include(pd.procoptions,po_msgint);
  1264. pd.messageinf.i:=pt.value;
  1265. end
  1266. else
  1267. Message(parser_e_ill_msg_expr);
  1268. disposetree(pt);
  1269. end;
  1270. {$endif WITHDMT}
  1271. end;
  1272. procedure pd_dispid(pd:tabstractprocdef);
  1273. var pt:Tnode;
  1274. begin
  1275. if pd.typ<>procdef then
  1276. internalerror(200604301);
  1277. pt:=comp_expr(true);
  1278. if is_constintnode(pt) then
  1279. if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
  1280. message(parser_e_range_check_error)
  1281. else
  1282. Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
  1283. else
  1284. message(parser_e_dispid_must_be_ord_const);
  1285. pt.free;
  1286. end;
  1287. procedure pd_static(pd:tabstractprocdef);
  1288. begin
  1289. if pd.typ=procdef then
  1290. include(tprocdef(pd).procsym.symoptions,sp_static);
  1291. include(pd.procoptions,po_staticmethod);
  1292. end;
  1293. procedure pd_override(pd:tabstractprocdef);
  1294. begin
  1295. if pd.typ<>procdef then
  1296. internalerror(2003042611);
  1297. if not(is_class_or_interface_or_objc(tprocdef(pd)._class)) then
  1298. Message(parser_e_no_object_override)
  1299. else if is_objccategory(tprocdef(pd)._class) then
  1300. Message(parser_e_no_category_override);
  1301. end;
  1302. procedure pd_overload(pd:tabstractprocdef);
  1303. begin
  1304. if pd.typ<>procdef then
  1305. internalerror(2003042612);
  1306. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1307. end;
  1308. procedure pd_message(pd:tabstractprocdef);
  1309. var
  1310. pt : tnode;
  1311. paracnt : longint;
  1312. begin
  1313. if pd.typ<>procdef then
  1314. internalerror(2003042613);
  1315. if not is_class(tprocdef(pd)._class) and
  1316. not is_objc_class_or_protocol(tprocdef(pd)._class) then
  1317. Message(parser_e_msg_only_for_classes);
  1318. if ([po_msgstr,po_msgint]*pd.procoptions)<>[] then
  1319. Message(parser_e_multiple_messages);
  1320. { check parameter type }
  1321. if not is_objc_class_or_protocol(tprocdef(pd)._class) then
  1322. begin
  1323. paracnt:=0;
  1324. pd.parast.SymList.ForEachCall(@check_msg_para,@paracnt);
  1325. if paracnt<>1 then
  1326. Message(parser_e_ill_msg_param);
  1327. end;
  1328. pt:=comp_expr(true);
  1329. { message is 1-character long }
  1330. if is_constcharnode(pt) then
  1331. begin
  1332. include(pd.procoptions,po_msgstr);
  1333. tprocdef(pd).messageinf.str:=stringdup(chr(byte(tordconstnode(pt).value.uvalue and $FF)));
  1334. end
  1335. else if pt.nodetype=stringconstn then
  1336. begin
  1337. include(pd.procoptions,po_msgstr);
  1338. if (tstringconstnode(pt).len>255) then
  1339. Message(parser_e_message_string_too_long);
  1340. tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
  1341. end
  1342. else
  1343. if is_constintnode(pt) and
  1344. is_class(tprocdef(pd)._class) then
  1345. begin
  1346. include(pd.procoptions,po_msgint);
  1347. if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
  1348. (Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
  1349. message(parser_e_range_check_error)
  1350. else
  1351. Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
  1352. end
  1353. else
  1354. Message(parser_e_ill_msg_expr);
  1355. { check whether the selector name is valid in case of Objective-C }
  1356. if (po_msgstr in pd.procoptions) and
  1357. is_objc_class_or_protocol(tprocdef(pd)._class) and
  1358. not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
  1359. Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
  1360. pt.free;
  1361. end;
  1362. procedure pd_reintroduce(pd:tabstractprocdef);
  1363. begin
  1364. if pd.typ<>procdef then
  1365. internalerror(200401211);
  1366. if not(is_class_or_interface_or_object(tprocdef(pd)._class)) and
  1367. not(is_objccategory(tprocdef(pd)._class)) then
  1368. Message(parser_e_no_object_reintroduce);
  1369. end;
  1370. procedure pd_syscall(pd:tabstractprocdef);
  1371. {$if defined(powerpc) or defined(m68k)}
  1372. var
  1373. vs : tparavarsym;
  1374. sym : tsym;
  1375. symtable : TSymtable;
  1376. v: Tconstexprint;
  1377. {$endif defined(powerpc) or defined(m68k)}
  1378. begin
  1379. if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
  1380. internalerror(2003042614);
  1381. tprocdef(pd).forwarddef:=false;
  1382. {$ifdef m68k}
  1383. if target_info.system in [system_m68k_amiga] then
  1384. begin
  1385. include(pd.procoptions,po_syscall_legacy);
  1386. if consume_sym(sym,symtable) then
  1387. begin
  1388. if (sym.typ=staticvarsym) and
  1389. (
  1390. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1391. is_32bitint(tabstractvarsym(sym).vardef)
  1392. ) then
  1393. begin
  1394. tprocdef(pd).libsym:=sym;
  1395. if po_syscall_legacy in tprocdef(pd).procoptions then
  1396. begin
  1397. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1398. paramanager.parseparaloc(vs,'A6');
  1399. pd.parast.insert(vs);
  1400. end
  1401. end
  1402. else
  1403. Message(parser_e_32bitint_or_pointer_variable_expected);
  1404. end;
  1405. (paramanager as tm68kparamanager).create_funcretloc_info(pd,calleeside);
  1406. (paramanager as tm68kparamanager).create_funcretloc_info(pd,callerside);
  1407. v:=get_intconst;
  1408. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1409. message(parser_e_range_check_error)
  1410. else
  1411. Tprocdef(pd).extnumber:=v.uvalue;
  1412. end;
  1413. {$endif m68k}
  1414. {$ifdef powerpc}
  1415. if target_info.system = system_powerpc_amiga then
  1416. begin
  1417. include(pd.procoptions,po_syscall_basesysv);
  1418. if consume_sym(sym,symtable) then
  1419. begin
  1420. if (sym.typ=staticvarsym) and
  1421. (
  1422. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1423. is_32bitint(tabstractvarsym(sym).vardef)
  1424. ) then
  1425. begin
  1426. tprocdef(pd).libsym:=sym;
  1427. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1428. pd.parast.insert(vs);
  1429. end
  1430. else
  1431. Message(parser_e_32bitint_or_pointer_variable_expected);
  1432. end;
  1433. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1434. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1435. v:=get_intconst;
  1436. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1437. message(parser_e_range_check_error)
  1438. else
  1439. Tprocdef(pd).extnumber:=v.uvalue;
  1440. end else
  1441. if target_info.system = system_powerpc_morphos then
  1442. begin
  1443. if idtoken=_LEGACY then
  1444. begin
  1445. consume(_LEGACY);
  1446. include(pd.procoptions,po_syscall_legacy);
  1447. end
  1448. else if idtoken=_SYSV then
  1449. begin
  1450. consume(_SYSV);
  1451. include(pd.procoptions,po_syscall_sysv);
  1452. end
  1453. else if idtoken=_BASESYSV then
  1454. begin
  1455. consume(_BASESYSV);
  1456. include(pd.procoptions,po_syscall_basesysv);
  1457. end
  1458. else if idtoken=_SYSVBASE then
  1459. begin
  1460. consume(_SYSVBASE);
  1461. include(pd.procoptions,po_syscall_sysvbase);
  1462. end
  1463. else if idtoken=_R12BASE then
  1464. begin
  1465. consume(_R12BASE);
  1466. include(pd.procoptions,po_syscall_r12base);
  1467. end
  1468. else
  1469. if syscall_convention='LEGACY' then
  1470. include(pd.procoptions,po_syscall_legacy)
  1471. else if syscall_convention='SYSV' then
  1472. include(pd.procoptions,po_syscall_sysv)
  1473. else if syscall_convention='BASESYSV' then
  1474. include(pd.procoptions,po_syscall_basesysv)
  1475. else if syscall_convention='SYSVBASE' then
  1476. include(pd.procoptions,po_syscall_sysvbase)
  1477. else if syscall_convention='R12BASE' then
  1478. include(pd.procoptions,po_syscall_r12base)
  1479. else
  1480. internalerror(2005010404);
  1481. if consume_sym(sym,symtable) then
  1482. begin
  1483. if (sym.typ=staticvarsym) and
  1484. (
  1485. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1486. is_32bitint(tabstractvarsym(sym).vardef)
  1487. ) then
  1488. begin
  1489. tprocdef(pd).libsym:=sym;
  1490. if po_syscall_legacy in tprocdef(pd).procoptions then
  1491. begin
  1492. vs:=tparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1493. paramanager.parseparaloc(vs,'A6');
  1494. pd.parast.insert(vs);
  1495. end
  1496. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1497. begin
  1498. { Nothing to be done for sysv here for now, but this might change }
  1499. end
  1500. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1501. begin
  1502. vs:=tparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1503. pd.parast.insert(vs);
  1504. end
  1505. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1506. begin
  1507. vs:=tparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1508. pd.parast.insert(vs);
  1509. end
  1510. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1511. begin
  1512. vs:=tparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1513. paramanager.parseparaloc(vs,'R12');
  1514. pd.parast.insert(vs);
  1515. end
  1516. else
  1517. internalerror(2005010501);
  1518. end
  1519. else
  1520. Message(parser_e_32bitint_or_pointer_variable_expected);
  1521. end;
  1522. (paramanager as tppcparamanager).create_funcretloc_info(pd,calleeside);
  1523. (paramanager as tppcparamanager).create_funcretloc_info(pd,callerside);
  1524. v:=get_intconst;
  1525. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1526. message(parser_e_range_check_error)
  1527. else
  1528. Tprocdef(pd).extnumber:=v.uvalue;
  1529. end;
  1530. {$endif powerpc}
  1531. end;
  1532. procedure pd_external(pd:tabstractprocdef);
  1533. {
  1534. If import_dll=nil the procedure is assumed to be in another
  1535. object file. In that object file it should have the name to
  1536. which import_name is pointing to. Otherwise, the procedure is
  1537. assumed to be in the DLL to which import_dll is pointing to. In
  1538. that case either import_nr<>0 or import_name<>nil is true, so
  1539. the procedure is either imported by number or by name. (DM)
  1540. }
  1541. var
  1542. hs : string;
  1543. v:Tconstexprint;
  1544. begin
  1545. if pd.typ<>procdef then
  1546. internalerror(2003042615);
  1547. with tprocdef(pd) do
  1548. begin
  1549. forwarddef:=false;
  1550. { forbid local external procedures }
  1551. if parast.symtablelevel>normal_function_level then
  1552. Message(parser_e_no_local_proc_external);
  1553. { If the procedure should be imported from a DLL, a constant string follows.
  1554. This isn't really correct, an contant string expression follows
  1555. so we check if an semicolon follows, else a string constant have to
  1556. follow (FK) }
  1557. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1558. begin
  1559. { Always add library prefix and suffix to create an uniform name }
  1560. hs:=get_stringconst;
  1561. if ExtractFileExt(hs)='' then
  1562. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  1563. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  1564. hs:=target_info.sharedlibprefix+hs;
  1565. import_dll:=stringdup(hs);
  1566. include(procoptions,po_has_importdll);
  1567. if (idtoken=_NAME) then
  1568. begin
  1569. consume(_NAME);
  1570. import_name:=stringdup(get_stringconst);
  1571. include(procoptions,po_has_importname);
  1572. if import_name^='' then
  1573. message(parser_e_empty_import_name);
  1574. end;
  1575. if (idtoken=_INDEX) then
  1576. begin
  1577. {After the word index follows the index number in the DLL.}
  1578. consume(_INDEX);
  1579. v:=get_intconst;
  1580. if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
  1581. message(parser_e_range_check_error)
  1582. else
  1583. import_nr:=longint(v.svalue);
  1584. end;
  1585. { default is to used the realname of the procedure }
  1586. if (import_nr=0) and not assigned(import_name) then
  1587. begin
  1588. import_name:=stringdup(procsym.realname);
  1589. include(procoptions,po_has_importname);
  1590. end;
  1591. end
  1592. else
  1593. begin
  1594. if (idtoken=_NAME) then
  1595. begin
  1596. consume(_NAME);
  1597. import_name:=stringdup(get_stringconst);
  1598. include(procoptions,po_has_importname);
  1599. if import_name^='' then
  1600. message(parser_e_empty_import_name);
  1601. end;
  1602. end;
  1603. end;
  1604. end;
  1605. procedure pd_weakexternal(pd:tabstractprocdef);
  1606. begin
  1607. if not(target_info.system in systems_weak_linking) then
  1608. message(parser_e_weak_external_not_supported)
  1609. else
  1610. pd_external(pd);
  1611. end;
  1612. type
  1613. pd_handler=procedure(pd:tabstractprocdef);
  1614. proc_dir_rec=record
  1615. idtok : ttoken;
  1616. pd_flags : tpdflags;
  1617. handler : pd_handler;
  1618. pocall : tproccalloption;
  1619. pooption : tprocoptions;
  1620. mutexclpocall : tproccalloptions;
  1621. mutexclpotype : tproctypeoptions;
  1622. mutexclpo : tprocoptions;
  1623. end;
  1624. const
  1625. {Should contain the number of procedure directives we support.}
  1626. num_proc_directives=42;
  1627. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1628. (
  1629. (
  1630. idtok:_ABSTRACT;
  1631. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1632. handler : @pd_abstract;
  1633. pocall : pocall_none;
  1634. pooption : [po_abstractmethod];
  1635. mutexclpocall : [pocall_internproc];
  1636. mutexclpotype : [];
  1637. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  1638. ),(
  1639. idtok:_ALIAS;
  1640. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1641. handler : @pd_alias;
  1642. pocall : pocall_none;
  1643. pooption : [];
  1644. mutexclpocall : [];
  1645. mutexclpotype : [];
  1646. mutexclpo : [po_external,po_inline]
  1647. ),(
  1648. idtok:_ASMNAME;
  1649. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1650. handler : @pd_asmname;
  1651. pocall : pocall_cdecl;
  1652. pooption : [po_external];
  1653. mutexclpocall : [pocall_internproc];
  1654. mutexclpotype : [];
  1655. mutexclpo : [po_external,po_inline]
  1656. ),(
  1657. idtok:_ASSEMBLER;
  1658. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1659. handler : nil;
  1660. pocall : pocall_none;
  1661. pooption : [po_assembler];
  1662. mutexclpocall : [];
  1663. mutexclpotype : [];
  1664. mutexclpo : [po_external]
  1665. ),(
  1666. idtok:_C; {same as cdecl for mode mac}
  1667. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1668. handler : nil;
  1669. pocall : pocall_cdecl;
  1670. pooption : [];
  1671. mutexclpocall : [];
  1672. mutexclpotype : [potype_constructor,potype_destructor];
  1673. mutexclpo : [po_assembler,po_external]
  1674. ),(
  1675. idtok:_CDECL;
  1676. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1677. handler : nil;
  1678. pocall : pocall_cdecl;
  1679. pooption : [];
  1680. mutexclpocall : [];
  1681. mutexclpotype : [potype_constructor,potype_destructor];
  1682. mutexclpo : [po_assembler,po_external]
  1683. ),(
  1684. idtok:_DISPID;
  1685. pd_flags : [pd_dispinterface];
  1686. handler : @pd_dispid;
  1687. pocall : pocall_none;
  1688. pooption : [po_dispid];
  1689. mutexclpocall : [pocall_internproc];
  1690. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1691. mutexclpo : [po_interrupt,po_external,po_inline]
  1692. ),(
  1693. idtok:_DYNAMIC;
  1694. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1695. handler : @pd_virtual;
  1696. pocall : pocall_none;
  1697. pooption : [po_virtualmethod];
  1698. mutexclpocall : [pocall_internproc];
  1699. mutexclpotype : [];
  1700. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  1701. ),(
  1702. idtok:_EXPORT;
  1703. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1704. handler : @pd_export;
  1705. pocall : pocall_none;
  1706. pooption : [po_exports,po_global];
  1707. mutexclpocall : [pocall_internproc];
  1708. mutexclpotype : [potype_constructor,potype_destructor];
  1709. mutexclpo : [po_external,po_interrupt,po_inline]
  1710. ),(
  1711. idtok:_EXTERNAL;
  1712. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject];
  1713. handler : @pd_external;
  1714. pocall : pocall_none;
  1715. pooption : [po_external];
  1716. mutexclpocall : [pocall_internproc,pocall_syscall];
  1717. { allowed for external cpp classes }
  1718. mutexclpotype : [{potype_constructor,potype_destructor}];
  1719. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  1720. ),(
  1721. idtok:_FAR;
  1722. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1723. handler : @pd_far;
  1724. pocall : pocall_none;
  1725. pooption : [];
  1726. mutexclpocall : [pocall_internproc];
  1727. mutexclpotype : [];
  1728. mutexclpo : [po_inline]
  1729. ),(
  1730. idtok:_FAR16;
  1731. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1732. handler : nil;
  1733. pocall : pocall_far16;
  1734. pooption : [];
  1735. mutexclpocall : [];
  1736. mutexclpotype : [];
  1737. mutexclpo : [po_external]
  1738. ),(
  1739. idtok:_FINAL;
  1740. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1741. handler : @pd_final;
  1742. pocall : pocall_none;
  1743. pooption : [po_finalmethod];
  1744. mutexclpocall : [pocall_internproc];
  1745. mutexclpotype : [];
  1746. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  1747. ),(
  1748. idtok:_FORWARD;
  1749. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1750. handler : @pd_forward;
  1751. pocall : pocall_none;
  1752. pooption : [];
  1753. mutexclpocall : [pocall_internproc];
  1754. mutexclpotype : [];
  1755. mutexclpo : [po_external,po_inline]
  1756. ),(
  1757. idtok:_OLDFPCCALL;
  1758. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1759. handler : nil;
  1760. pocall : pocall_oldfpccall;
  1761. pooption : [];
  1762. mutexclpocall : [];
  1763. mutexclpotype : [];
  1764. mutexclpo : []
  1765. ),(
  1766. idtok:_INLINE;
  1767. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1768. handler : nil;
  1769. pocall : pocall_none;
  1770. pooption : [po_inline];
  1771. mutexclpocall : [];
  1772. mutexclpotype : [potype_constructor,potype_destructor];
  1773. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1774. ),(
  1775. idtok:_INTERNCONST;
  1776. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf];
  1777. handler : @pd_internconst;
  1778. pocall : pocall_none;
  1779. pooption : [po_internconst];
  1780. mutexclpocall : [];
  1781. mutexclpotype : [potype_operator];
  1782. mutexclpo : []
  1783. ),(
  1784. idtok:_INTERNPROC;
  1785. pd_flags : [pd_interface,pd_notobject,pd_notobjintf];
  1786. handler : @pd_internproc;
  1787. pocall : pocall_internproc;
  1788. pooption : [];
  1789. mutexclpocall : [];
  1790. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1791. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1792. ),(
  1793. idtok:_INTERRUPT;
  1794. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1795. handler : @pd_interrupt;
  1796. pocall : pocall_oldfpccall;
  1797. pooption : [po_interrupt];
  1798. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1799. pocall_pascal,pocall_far16,pocall_oldfpccall];
  1800. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1801. mutexclpo : [po_external,po_inline]
  1802. ),(
  1803. idtok:_IOCHECK;
  1804. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1805. handler : nil;
  1806. pocall : pocall_none;
  1807. pooption : [po_iocheck];
  1808. mutexclpocall : [pocall_internproc];
  1809. mutexclpotype : [];
  1810. mutexclpo : [po_external]
  1811. ),(
  1812. idtok:_LOCAL;
  1813. pd_flags : [pd_implemen,pd_body];
  1814. handler : nil;
  1815. pocall : pocall_none;
  1816. pooption : [po_kylixlocal];
  1817. mutexclpocall : [pocall_internproc,pocall_far16];
  1818. mutexclpotype : [];
  1819. mutexclpo : [po_external,po_exports]
  1820. ),(
  1821. idtok:_MESSAGE;
  1822. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass, pd_objcprot];
  1823. handler : @pd_message;
  1824. pocall : pocall_none;
  1825. pooption : []; { can be po_msgstr or po_msgint }
  1826. mutexclpocall : [pocall_internproc];
  1827. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1828. mutexclpo : [po_interrupt,po_external,po_inline]
  1829. ),(
  1830. idtok:_MWPASCAL;
  1831. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1832. handler : nil;
  1833. pocall : pocall_mwpascal;
  1834. pooption : [];
  1835. mutexclpocall : [];
  1836. mutexclpotype : [];
  1837. mutexclpo : []
  1838. ),(
  1839. idtok:_NEAR;
  1840. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1841. handler : @pd_near;
  1842. pocall : pocall_none;
  1843. pooption : [];
  1844. mutexclpocall : [pocall_internproc];
  1845. mutexclpotype : [];
  1846. mutexclpo : []
  1847. ),(
  1848. idtok:_NOSTACKFRAME;
  1849. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1850. handler : nil;
  1851. pocall : pocall_none;
  1852. pooption : [po_nostackframe];
  1853. mutexclpocall : [pocall_internproc];
  1854. mutexclpotype : [];
  1855. mutexclpo : []
  1856. ),(
  1857. idtok:_OVERLOAD;
  1858. pd_flags : [pd_implemen,pd_interface,pd_body];
  1859. handler : @pd_overload;
  1860. pocall : pocall_none;
  1861. pooption : [po_overload];
  1862. mutexclpocall : [pocall_internproc];
  1863. mutexclpotype : [];
  1864. mutexclpo : []
  1865. ),(
  1866. idtok:_OVERRIDE;
  1867. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass];
  1868. handler : @pd_override;
  1869. pocall : pocall_none;
  1870. pooption : [po_overridingmethod,po_virtualmethod];
  1871. mutexclpocall : [pocall_internproc];
  1872. mutexclpotype : [];
  1873. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_inline]
  1874. ),(
  1875. idtok:_PASCAL;
  1876. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1877. handler : nil;
  1878. pocall : pocall_pascal;
  1879. pooption : [];
  1880. mutexclpocall : [];
  1881. mutexclpotype : [potype_constructor,potype_destructor];
  1882. mutexclpo : [po_external]
  1883. ),(
  1884. idtok:_PUBLIC;
  1885. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1886. handler : @pd_public;
  1887. pocall : pocall_none;
  1888. pooption : [po_public,po_global];
  1889. mutexclpocall : [pocall_internproc];
  1890. mutexclpotype : [];
  1891. mutexclpo : [po_external,po_inline]
  1892. ),(
  1893. idtok:_REGISTER;
  1894. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1895. handler : nil;
  1896. pocall : pocall_register;
  1897. pooption : [];
  1898. mutexclpocall : [];
  1899. mutexclpotype : [potype_constructor,potype_destructor];
  1900. mutexclpo : [po_external]
  1901. ),(
  1902. idtok:_REINTRODUCE;
  1903. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass];
  1904. handler : @pd_reintroduce;
  1905. pocall : pocall_none;
  1906. pooption : [po_reintroduce];
  1907. mutexclpocall : [pocall_internproc];
  1908. mutexclpotype : [];
  1909. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1910. ),(
  1911. idtok:_SAFECALL;
  1912. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1913. handler : nil;
  1914. pocall : pocall_safecall;
  1915. pooption : [];
  1916. mutexclpocall : [];
  1917. mutexclpotype : [potype_constructor,potype_destructor];
  1918. mutexclpo : [po_external]
  1919. ),(
  1920. idtok:_SOFTFLOAT;
  1921. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1922. handler : nil;
  1923. pocall : pocall_softfloat;
  1924. pooption : [];
  1925. mutexclpocall : [];
  1926. mutexclpotype : [potype_constructor,potype_destructor];
  1927. { it's available with po_external because the libgcc floating point routines on the arm
  1928. uses this calling convention }
  1929. mutexclpo : []
  1930. ),(
  1931. idtok:_STATIC;
  1932. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_notobjintf];
  1933. handler : @pd_static;
  1934. pocall : pocall_none;
  1935. pooption : [po_staticmethod];
  1936. mutexclpocall : [pocall_internproc];
  1937. mutexclpotype : [potype_constructor,potype_destructor];
  1938. mutexclpo : [po_external,po_interrupt,po_exports,po_inline]
  1939. ),(
  1940. idtok:_STDCALL;
  1941. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1942. handler : nil;
  1943. pocall : pocall_stdcall;
  1944. pooption : [];
  1945. mutexclpocall : [];
  1946. mutexclpotype : [potype_constructor,potype_destructor];
  1947. mutexclpo : [po_external]
  1948. ),(
  1949. idtok:_SYSCALL;
  1950. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  1951. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  1952. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  1953. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1954. handler : @pd_syscall;
  1955. pocall : pocall_syscall;
  1956. pooption : [];
  1957. mutexclpocall : [];
  1958. mutexclpotype : [potype_constructor,potype_destructor];
  1959. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1960. ),(
  1961. idtok:_VIRTUAL;
  1962. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1963. handler : @pd_virtual;
  1964. pocall : pocall_none;
  1965. pooption : [po_virtualmethod];
  1966. mutexclpocall : [pocall_internproc];
  1967. mutexclpotype : [];
  1968. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  1969. ),(
  1970. idtok:_CPPDECL;
  1971. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1972. handler : nil;
  1973. pocall : pocall_cppdecl;
  1974. pooption : [];
  1975. mutexclpocall : [];
  1976. mutexclpotype : [potype_constructor,potype_destructor];
  1977. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1978. ),(
  1979. idtok:_VARARGS;
  1980. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass, pd_objcprot];
  1981. handler : nil;
  1982. pocall : pocall_none;
  1983. pooption : [po_varargs];
  1984. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1985. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  1986. mutexclpotype : [];
  1987. mutexclpo : [po_assembler,po_interrupt,po_inline]
  1988. ),(
  1989. idtok:_COMPILERPROC;
  1990. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1991. handler : nil;
  1992. pocall : pocall_none;
  1993. pooption : [po_compilerproc];
  1994. mutexclpocall : [];
  1995. mutexclpotype : [potype_constructor,potype_destructor];
  1996. mutexclpo : [po_interrupt]
  1997. ),(
  1998. idtok:_WEAKEXTERNAL;
  1999. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject];
  2000. handler : @pd_weakexternal;
  2001. pocall : pocall_none;
  2002. { mark it both external and weak external, so we don't have to
  2003. adapt all code for external symbols to also check for weak external
  2004. }
  2005. pooption : [po_external,po_weakexternal];
  2006. mutexclpocall : [pocall_internproc,pocall_syscall];
  2007. { allowed for external cpp classes }
  2008. mutexclpotype : [{potype_constructor,potype_destructor}];
  2009. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2010. ),(
  2011. idtok:_ENUMERATOR;
  2012. pd_flags : [pd_interface,pd_object];
  2013. handler : @pd_enumerator;
  2014. pocall : pocall_none;
  2015. pooption : [];
  2016. mutexclpocall : [pocall_internproc];
  2017. mutexclpotype : [];
  2018. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2019. )
  2020. );
  2021. function check_proc_directive(isprocvar:boolean):boolean;
  2022. var
  2023. i : longint;
  2024. begin
  2025. result:=false;
  2026. for i:=1 to num_proc_directives do
  2027. if proc_direcdata[i].idtok=idtoken then
  2028. begin
  2029. if ((not isprocvar) or
  2030. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2031. { don't eat a public directive in classes }
  2032. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2033. result:=true;
  2034. exit;
  2035. end;
  2036. end;
  2037. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2038. {
  2039. Parse the procedure directive, returns true if a correct directive is found
  2040. }
  2041. var
  2042. p : longint;
  2043. found : boolean;
  2044. name : TIDString;
  2045. begin
  2046. parse_proc_direc:=false;
  2047. name:=tokeninfo^[idtoken].str;
  2048. found:=false;
  2049. { Hint directive? Then exit immediatly }
  2050. if (m_hintdirective in current_settings.modeswitches) then
  2051. begin
  2052. case idtoken of
  2053. _LIBRARY,
  2054. _PLATFORM,
  2055. _UNIMPLEMENTED,
  2056. _EXPERIMENTAL,
  2057. _DEPRECATED :
  2058. exit;
  2059. end;
  2060. end;
  2061. { C directive is MacPas only, because it breaks too much existing code
  2062. on other platforms (PFV) }
  2063. if (idtoken=_C) and
  2064. not(m_mac in current_settings.modeswitches) then
  2065. exit;
  2066. { retrieve data for directive if found }
  2067. for p:=1 to num_proc_directives do
  2068. if proc_direcdata[p].idtok=idtoken then
  2069. begin
  2070. found:=true;
  2071. break;
  2072. end;
  2073. { Check if the procedure directive is known }
  2074. if not found then
  2075. begin
  2076. { parsing a procvar type the name can be any
  2077. next variable !! }
  2078. if ((pdflags * [pd_procvar,pd_object,pd_objcclass,pd_objcprot])=[]) and
  2079. not(idtoken=_PROPERTY) then
  2080. Message1(parser_w_unknown_proc_directive_ignored,name);
  2081. exit;
  2082. end;
  2083. { check if method and directive not for object, like public.
  2084. This needs to be checked also for procvars }
  2085. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2086. (symtablestack.top.symtabletype=ObjectSymtable) and
  2087. { directive allowed for cpp classes? }
  2088. not(is_cppclass(tdef(symtablestack.top.defowner)) and (pd_cppobject in proc_direcdata[p].pd_flags)) then
  2089. exit;
  2090. { Conflicts between directives ? }
  2091. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  2092. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  2093. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  2094. begin
  2095. Message1(parser_e_proc_dir_conflict,name);
  2096. exit;
  2097. end;
  2098. { set calling convention }
  2099. if proc_direcdata[p].pocall<>pocall_none then
  2100. begin
  2101. if (po_hascallingconvention in pd.procoptions) then
  2102. begin
  2103. Message2(parser_w_proc_overriding_calling,
  2104. proccalloptionStr[pd.proccalloption],
  2105. proccalloptionStr[proc_direcdata[p].pocall]);
  2106. end;
  2107. { check if the target processor supports this calling convention }
  2108. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2109. begin
  2110. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2111. { recover }
  2112. proc_direcdata[p].pocall:=pocall_stdcall;
  2113. end;
  2114. pd.proccalloption:=proc_direcdata[p].pocall;
  2115. include(pd.procoptions,po_hascallingconvention);
  2116. end;
  2117. if pd.typ=procdef then
  2118. begin
  2119. { Check if the directive is only for objects }
  2120. if (pd_object in proc_direcdata[p].pd_flags) and
  2121. not assigned(tprocdef(pd)._class) then
  2122. exit;
  2123. { check if method and directive not for interface }
  2124. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2125. is_interface(tprocdef(pd)._class) then
  2126. exit;
  2127. { check if method and directive not for interface }
  2128. if is_dispinterface(tprocdef(pd)._class) and
  2129. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2130. exit;
  2131. { check if method and directive not for objcclass }
  2132. if is_objcclass(tprocdef(pd)._class) and
  2133. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2134. exit;
  2135. { check if method and directive not for objcprotocol }
  2136. if is_objcprotocol(tprocdef(pd)._class) and
  2137. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2138. exit;
  2139. end;
  2140. { consume directive, and turn flag on }
  2141. consume(token);
  2142. parse_proc_direc:=true;
  2143. { Check the pd_flags if the directive should be allowed }
  2144. if (pd_interface in pdflags) and
  2145. not(pd_interface in proc_direcdata[p].pd_flags) then
  2146. begin
  2147. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  2148. exit;
  2149. end;
  2150. if (pd_implemen in pdflags) and
  2151. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2152. begin
  2153. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  2154. exit;
  2155. end;
  2156. if (pd_procvar in pdflags) and
  2157. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2158. begin
  2159. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  2160. exit;
  2161. end;
  2162. { Return the new pd_flags }
  2163. if not(pd_body in proc_direcdata[p].pd_flags) then
  2164. exclude(pdflags,pd_body);
  2165. { Add the correct flag }
  2166. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2167. { Call the handler }
  2168. if pointer(proc_direcdata[p].handler)<>nil then
  2169. proc_direcdata[p].handler(pd);
  2170. end;
  2171. function proc_get_importname(pd:tprocdef):string;
  2172. function maybe_cprefix(const s:string):string;
  2173. begin
  2174. if not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  2175. result:=s
  2176. else
  2177. result:=target_info.Cprefix+s;
  2178. end;
  2179. begin
  2180. result:='';
  2181. if not(po_external in pd.procoptions) then
  2182. internalerror(200412151);
  2183. { external name or number is specified }
  2184. if assigned(pd.import_name) or (pd.import_nr<>0) then
  2185. begin
  2186. if assigned(pd.import_dll) then
  2187. begin
  2188. { If we are not using direct dll linking under win32 then imports
  2189. need to use the normal name since two functions can refer to the
  2190. same DLL function. This is also needed for compatability
  2191. with Delphi and TP7 }
  2192. (*
  2193. case target_info.system of
  2194. system_i386_emx,
  2195. system_i386_os2 :
  2196. begin
  2197. { keep normal mangledname }
  2198. if not (Assigned (PD.Import_Name)) then
  2199. Result := PD.MangledName;
  2200. end;
  2201. else
  2202. *)
  2203. if assigned(pd.import_name) then
  2204. begin
  2205. if target_info.system in (systems_all_windows + systems_nativent +
  2206. [system_i386_emx, system_i386_os2]) then
  2207. { cprefix is not used in DLL imports under Windows or OS/2 }
  2208. result:=pd.import_name^
  2209. else
  2210. result:=maybe_cprefix(pd.import_name^);
  2211. end
  2212. else
  2213. result:=ExtractFileName(pd.import_dll^)+'_index_'+tostr(pd.import_nr);
  2214. end
  2215. else
  2216. result:=maybe_cprefix(pd.import_name^);
  2217. end
  2218. else
  2219. begin
  2220. { Default names when importing variables }
  2221. case pd.proccalloption of
  2222. pocall_cdecl :
  2223. begin
  2224. if assigned(pd._class) then
  2225. result:=target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname
  2226. else
  2227. result:=target_info.Cprefix+pd.procsym.realname;
  2228. end;
  2229. pocall_cppdecl :
  2230. begin
  2231. result:=target_info.Cprefix+pd.cplusplusmangledname;
  2232. end;
  2233. else
  2234. begin
  2235. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  2236. if (m_mac in current_settings.modeswitches) then
  2237. result:=tprocdef(pd).procsym.realname;
  2238. end;
  2239. end;
  2240. end;
  2241. end;
  2242. procedure proc_set_mangledname(pd:tprocdef);
  2243. var
  2244. s : string;
  2245. begin
  2246. { When the mangledname is already set we aren't allowed to change
  2247. it because it can already be used somewhere (PFV) }
  2248. if not(po_has_mangledname in pd.procoptions) then
  2249. begin
  2250. if (po_external in pd.procoptions) then
  2251. begin
  2252. { External Procedures are only allowed to change the mangledname
  2253. in their first declaration }
  2254. if (pd.forwarddef or (not pd.hasforward)) then
  2255. begin
  2256. s:=proc_get_importname(pd);
  2257. if s<>'' then
  2258. begin
  2259. { Replace ? and @ in import name, since GNU AS does not allow these characters in symbol names. }
  2260. { This allows to import VC++ mangled names from DLLs. }
  2261. { Do not perform replacement, if external symbol is not imported from DLL. }
  2262. if (target_info.system in systems_all_windows) and (pd.import_dll<>nil) then
  2263. begin
  2264. Replace(s,'?','__q$$');
  2265. {$ifdef arm}
  2266. { @ symbol is not allowed in ARM assembler only }
  2267. Replace(s,'@','__a$$');
  2268. {$endif arm}
  2269. end;
  2270. pd.setmangledname(s);
  2271. end;
  2272. end;
  2273. end
  2274. else
  2275. { Normal procedures }
  2276. begin
  2277. if (po_compilerproc in pd.procoptions) then
  2278. begin
  2279. pd.setmangledname(lower(pd.procsym.name));
  2280. end;
  2281. end;
  2282. end;
  2283. { Public/exported alias names }
  2284. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  2285. not(po_has_public_name in pd.procoptions) then
  2286. begin
  2287. case pd.proccalloption of
  2288. pocall_cdecl :
  2289. begin
  2290. if assigned(pd._class) then
  2291. pd.aliasnames.insert(target_info.Cprefix+pd._class.objrealname^+'_'+pd.procsym.realname)
  2292. else
  2293. begin
  2294. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  2295. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  2296. (po_exports in pd.procoptions) then
  2297. pd.aliasnames.insert(pd.procsym.realname)
  2298. else
  2299. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  2300. end;
  2301. end;
  2302. pocall_cppdecl :
  2303. begin
  2304. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  2305. end;
  2306. end;
  2307. { prevent adding the alias a second time }
  2308. include(pd.procoptions,po_has_public_name);
  2309. end;
  2310. end;
  2311. procedure handle_calling_convention(pd:tabstractprocdef);
  2312. begin
  2313. { set the default calling convention if none provided }
  2314. if (pd.typ=procdef) and
  2315. (is_objc_class_or_protocol(tprocdef(pd)._class) or
  2316. is_cppclass(tprocdef(pd)._class)) then
  2317. begin
  2318. { none of the explicit calling conventions should be allowed }
  2319. if (po_hascallingconvention in pd.procoptions) then
  2320. internalerror(2009032501);
  2321. if is_cppclass(tprocdef(pd)._class) then
  2322. pd.proccalloption:=pocall_cppdecl
  2323. else
  2324. pd.proccalloption:=pocall_cdecl;
  2325. end
  2326. else if not(po_hascallingconvention in pd.procoptions) then
  2327. pd.proccalloption:=current_settings.defproccall
  2328. else
  2329. begin
  2330. if pd.proccalloption=pocall_none then
  2331. internalerror(200309081);
  2332. end;
  2333. { handle proccall specific settings }
  2334. case pd.proccalloption of
  2335. pocall_cdecl,
  2336. pocall_cppdecl :
  2337. begin
  2338. { check C cdecl para types }
  2339. check_c_para(pd);
  2340. end;
  2341. pocall_far16 :
  2342. begin
  2343. { Temporary stub, must be rewritten to support OS/2 far16 }
  2344. Message1(parser_w_proc_directive_ignored,'FAR16');
  2345. end;
  2346. end;
  2347. { Inlining is enabled and supported? }
  2348. if (po_inline in pd.procoptions) and
  2349. not(cs_do_inline in current_settings.localswitches) then
  2350. begin
  2351. { Give an error if inline is not supported by the compiler mode,
  2352. otherwise only give a warning that this procedure will not be inlined }
  2353. if not(m_default_inline in current_settings.modeswitches) then
  2354. Message(parser_e_proc_inline_not_supported)
  2355. else
  2356. Message(parser_w_inlining_disabled);
  2357. exclude(pd.procoptions,po_inline);
  2358. end;
  2359. { For varargs directive also cdecl and external must be defined }
  2360. if (po_varargs in pd.procoptions) then
  2361. begin
  2362. { check first for external in the interface, if available there
  2363. then the cdecl must also be there since there is no implementation
  2364. available to contain it }
  2365. if parse_only then
  2366. begin
  2367. { if external is available, then cdecl must also be available,
  2368. procvars don't need external }
  2369. if not((po_external in pd.procoptions) or
  2370. (pd.typ=procvardef) or
  2371. { for objcclasses this is checked later, because the entire
  2372. class may be external. }
  2373. is_objc_class_or_protocol(tprocdef(pd)._class)) and
  2374. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_mwpascal]) then
  2375. Message(parser_e_varargs_need_cdecl_and_external);
  2376. end
  2377. else
  2378. begin
  2379. { both must be defined now }
  2380. if not((po_external in pd.procoptions) or
  2381. (pd.typ=procvardef)) or
  2382. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl,pocall_mwpascal]) then
  2383. Message(parser_e_varargs_need_cdecl_and_external);
  2384. end;
  2385. end;
  2386. { insert hidden high parameters }
  2387. pd.parast.SymList.ForEachCall(@insert_hidden_para,pd);
  2388. { insert hidden self parameter }
  2389. insert_self_and_vmt_para(pd);
  2390. { insert funcret parameter if required }
  2391. insert_funcret_para(pd);
  2392. { Make var parameters regable, this must be done after the calling
  2393. convention is set. }
  2394. { this must be done before parentfp is insert, because getting all cases
  2395. where parentfp must be in a memory location isn't catched properly so
  2396. we put parentfp never in a register }
  2397. pd.parast.SymList.ForEachCall(@set_addr_param_regable,pd);
  2398. { insert parentfp parameter if required }
  2399. insert_parentfp_para(pd);
  2400. { Calculate parameter tlist }
  2401. pd.calcparas;
  2402. end;
  2403. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2404. {
  2405. Parse the procedure directives. It does not matter if procedure directives
  2406. are written using ;procdir; or ['procdir'] syntax.
  2407. }
  2408. var
  2409. res : boolean;
  2410. begin
  2411. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  2412. begin
  2413. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  2414. include(pd.procoptions,po_public);
  2415. include(pd.procoptions,po_has_public_name);
  2416. include(pd.procoptions,po_global);
  2417. end;
  2418. while token in [_ID,_LECKKLAMMER] do
  2419. begin
  2420. if try_to_consume(_LECKKLAMMER) then
  2421. begin
  2422. repeat
  2423. parse_proc_direc(pd,pdflags);
  2424. until not try_to_consume(_COMMA);
  2425. consume(_RECKKLAMMER);
  2426. { we always expect at least '[];' }
  2427. res:=true;
  2428. end
  2429. else
  2430. begin
  2431. res:=parse_proc_direc(pd,pdflags);
  2432. end;
  2433. { A procedure directive normally followed by a semicolon, but in
  2434. a const section or reading a type we should stop when _EQUAL is found,
  2435. because a constant/default value follows }
  2436. if res then
  2437. begin
  2438. if (block_type=bt_const_type) and
  2439. (token=_EQUAL) then
  2440. break;
  2441. { support procedure proc;stdcall export; }
  2442. if not(check_proc_directive((pd.typ=procvardef))) then
  2443. begin
  2444. { support "record p : procedure stdcall end;" and
  2445. "var p : procedure stdcall = nil;" }
  2446. if (pd_procvar in pdflags) and
  2447. (token in [_END,_RKLAMMER,_EQUAL]) then
  2448. break
  2449. else
  2450. begin
  2451. if (token=_COLON) then
  2452. begin
  2453. Message(parser_e_field_not_allowed_here);
  2454. consume_all_until(_SEMICOLON);
  2455. end;
  2456. consume(_SEMICOLON)
  2457. end;
  2458. end;
  2459. end
  2460. else
  2461. break;
  2462. end;
  2463. end;
  2464. procedure parse_var_proc_directives(sym:tsym);
  2465. var
  2466. pdflags : tpdflags;
  2467. pd : tabstractprocdef;
  2468. begin
  2469. pdflags:=[pd_procvar];
  2470. pd:=nil;
  2471. case sym.typ of
  2472. fieldvarsym,
  2473. staticvarsym,
  2474. localvarsym,
  2475. paravarsym :
  2476. pd:=tabstractprocdef(tabstractvarsym(sym).vardef);
  2477. typesym :
  2478. pd:=tabstractprocdef(ttypesym(sym).typedef);
  2479. else
  2480. internalerror(2003042617);
  2481. end;
  2482. if pd.typ<>procvardef then
  2483. internalerror(2003042618);
  2484. { names should never be used anyway }
  2485. parse_proc_directives(pd,pdflags);
  2486. end;
  2487. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2488. var
  2489. pdflags : tpdflags;
  2490. begin
  2491. pdflags:=[pd_object];
  2492. parse_proc_directives(pd,pdflags);
  2493. end;
  2494. function proc_add_definition(var currpd:tprocdef):boolean;
  2495. {
  2496. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2497. forwarddef is found and reused it returns true
  2498. }
  2499. var
  2500. fwpd : tprocdef;
  2501. currparasym,
  2502. fwparasym : tsym;
  2503. currparacnt,
  2504. fwparacnt,
  2505. curridx,
  2506. fwidx,
  2507. i : longint;
  2508. po_comp : tprocoptions;
  2509. paracompopt: tcompare_paras_options;
  2510. forwardfound : boolean;
  2511. symentry: TSymEntry;
  2512. begin
  2513. forwardfound:=false;
  2514. { check overloaded functions if the same function already exists }
  2515. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  2516. begin
  2517. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  2518. { Skip overloaded definitions that are declared in other units }
  2519. if fwpd.procsym<>currpd.procsym then
  2520. continue;
  2521. { check the parameters, for delphi/tp it is possible to
  2522. leave the parameters away in the implementation (forwarddef=false).
  2523. But for an overload declared function this is not allowed }
  2524. if { check if empty implementation arguments match is allowed }
  2525. (
  2526. not(m_repeat_forward in current_settings.modeswitches) and
  2527. not(currpd.forwarddef) and
  2528. is_bareprocdef(currpd) and
  2529. not(po_overload in fwpd.procoptions)
  2530. ) or
  2531. { check arguments, we need to check only the user visible parameters. The hidden parameters
  2532. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV) }
  2533. (
  2534. (compare_paras(currpd.paras,fwpd.paras,cp_none,[cpo_comparedefaultvalue,cpo_ignorehidden,cpo_openequalisexact])=te_exact) and
  2535. (fwpd.returndef=currpd.returndef)
  2536. ) then
  2537. begin
  2538. { Check if we've found the forwarddef, if found then
  2539. we need to update the forward def with the current
  2540. implementation settings }
  2541. if fwpd.forwarddef then
  2542. begin
  2543. forwardfound:=true;
  2544. if not(m_repeat_forward in current_settings.modeswitches) and
  2545. (fwpd.proccalloption<>currpd.proccalloption) then
  2546. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact]
  2547. else
  2548. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact];
  2549. { Check calling convention }
  2550. if (fwpd.proccalloption<>currpd.proccalloption) then
  2551. begin
  2552. { In delphi it is possible to specify the calling
  2553. convention in the interface or implementation if
  2554. there was no convention specified in the other
  2555. part }
  2556. if (m_delphi in current_settings.modeswitches) then
  2557. begin
  2558. if not(po_hascallingconvention in currpd.procoptions) then
  2559. currpd.proccalloption:=fwpd.proccalloption
  2560. else
  2561. if not(po_hascallingconvention in fwpd.procoptions) then
  2562. fwpd.proccalloption:=currpd.proccalloption
  2563. else
  2564. begin
  2565. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  2566. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  2567. { restore interface settings }
  2568. currpd.proccalloption:=fwpd.proccalloption;
  2569. end;
  2570. end
  2571. else
  2572. begin
  2573. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  2574. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  2575. { restore interface settings }
  2576. currpd.proccalloption:=fwpd.proccalloption;
  2577. end;
  2578. end;
  2579. { Check static }
  2580. if (po_staticmethod in fwpd.procoptions) then
  2581. begin
  2582. if not (po_staticmethod in currpd.procoptions) then
  2583. begin
  2584. include(currpd.procoptions, po_staticmethod);
  2585. if (po_classmethod in currpd.procoptions) then
  2586. begin
  2587. { remove self from the hidden paras }
  2588. symentry:=currpd.parast.Find('self');
  2589. if symentry<>nil then
  2590. begin
  2591. currpd.parast.Delete(symentry);
  2592. currpd.calcparas;
  2593. end;
  2594. end;
  2595. end;
  2596. end;
  2597. { Check if the procedure type and return type are correct,
  2598. also the parameters must match also with the type }
  2599. if ((m_repeat_forward in current_settings.modeswitches) or
  2600. not is_bareprocdef(currpd)) and
  2601. ((compare_paras(currpd.paras,fwpd.paras,cp_all,paracompopt)<>te_exact) or
  2602. (fwpd.returndef<>currpd.returndef)) then
  2603. begin
  2604. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  2605. fwpd.fullprocname(false));
  2606. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  2607. break;
  2608. end;
  2609. { Check if both are declared forward }
  2610. if fwpd.forwarddef and currpd.forwarddef then
  2611. begin
  2612. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  2613. currpd.fullprocname(false));
  2614. end;
  2615. { internconst or internproc only need to be defined once }
  2616. if (fwpd.proccalloption=pocall_internproc) then
  2617. currpd.proccalloption:=fwpd.proccalloption
  2618. else
  2619. if (currpd.proccalloption=pocall_internproc) then
  2620. fwpd.proccalloption:=currpd.proccalloption;
  2621. { Check procedure options, Delphi requires that class is
  2622. repeated in the implementation for class methods }
  2623. if (m_fpc in current_settings.modeswitches) then
  2624. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  2625. else
  2626. po_comp:=[po_classmethod,po_methodpointer];
  2627. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  2628. (fwpd.proctypeoption <> currpd.proctypeoption) then
  2629. begin
  2630. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  2631. fwpd.fullprocname(false));
  2632. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  2633. { This error is non-fatal, we can recover }
  2634. end;
  2635. { Forward declaration is external? }
  2636. if (po_external in fwpd.procoptions) then
  2637. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  2638. { Check parameters }
  2639. if (m_repeat_forward in current_settings.modeswitches) or
  2640. (currpd.minparacount>0) then
  2641. begin
  2642. { If mangled names are equal then they have the same amount of arguments }
  2643. { We can check the names of the arguments }
  2644. { both symtables are in the same order from left to right }
  2645. curridx:=0;
  2646. fwidx:=0;
  2647. currparacnt:=currpd.parast.SymList.Count;
  2648. fwparacnt:=fwpd.parast.SymList.Count;
  2649. repeat
  2650. { skip default parameter constsyms }
  2651. while (curridx<currparacnt) and
  2652. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  2653. inc(curridx);
  2654. while (fwidx<fwparacnt) and
  2655. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  2656. inc(fwidx);
  2657. { stop when one of the two lists is at the end }
  2658. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  2659. break;
  2660. { compare names of parameters, ignore implictly
  2661. renamed parameters }
  2662. currparasym:=tsym(currpd.parast.SymList[curridx]);
  2663. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  2664. if not(sp_implicitrename in currparasym.symoptions) and
  2665. not(sp_implicitrename in fwparasym.symoptions) then
  2666. begin
  2667. if (currparasym.name<>fwparasym.name) then
  2668. begin
  2669. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  2670. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  2671. break;
  2672. end;
  2673. end;
  2674. { next parameter }
  2675. inc(curridx);
  2676. inc(fwidx);
  2677. until false;
  2678. end;
  2679. { Everything is checked, now we can update the forward declaration
  2680. with the new data from the implementation }
  2681. fwpd.forwarddef:=currpd.forwarddef;
  2682. fwpd.hasforward:=true;
  2683. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  2684. { marked as local but exported from unit? }
  2685. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  2686. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  2687. if fwpd.extnumber=$ffff then
  2688. fwpd.extnumber:=currpd.extnumber;
  2689. while not currpd.aliasnames.empty do
  2690. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  2691. { update fileinfo so position references the implementation,
  2692. also update funcretsym if it is already generated }
  2693. fwpd.fileinfo:=currpd.fileinfo;
  2694. if assigned(fwpd.funcretsym) then
  2695. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  2696. if assigned(currpd.deprecatedmsg) then
  2697. begin
  2698. stringdispose(fwpd.deprecatedmsg);
  2699. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  2700. end;
  2701. { import names }
  2702. if assigned(currpd.import_dll) then
  2703. begin
  2704. stringdispose(fwpd.import_dll);
  2705. fwpd.import_dll:=stringdup(currpd.import_dll^);
  2706. end;
  2707. if assigned(currpd.import_name) then
  2708. begin
  2709. stringdispose(fwpd.import_name);
  2710. fwpd.import_name:=stringdup(currpd.import_name^);
  2711. end;
  2712. fwpd.import_nr:=currpd.import_nr;
  2713. { for compilerproc defines we need to rename and update the
  2714. symbolname to lowercase }
  2715. if (po_compilerproc in fwpd.procoptions) then
  2716. begin
  2717. { rename to lowercase so users can't access it }
  2718. fwpd.procsym.realname:='$'+lower(fwpd.procsym.name);
  2719. { the mangeled name is already changed by the pd_compilerproc }
  2720. { handler. It must be done immediately because if we have a }
  2721. { call to a compilerproc before it's implementation is }
  2722. { encountered, it must already use the new mangled name (JM) }
  2723. end;
  2724. { Release current procdef }
  2725. currpd.owner.deletedef(currpd);
  2726. currpd:=fwpd;
  2727. end
  2728. else
  2729. begin
  2730. { abstract methods aren't forward defined, but this }
  2731. { needs another error message }
  2732. if (po_abstractmethod in fwpd.procoptions) then
  2733. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  2734. else
  2735. begin
  2736. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  2737. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  2738. end;
  2739. end;
  2740. { we found one proc with the same arguments, there are no others
  2741. so we can stop }
  2742. break;
  2743. end;
  2744. { check for allowing overload directive }
  2745. if not(m_fpc in current_settings.modeswitches) then
  2746. begin
  2747. { overload directive turns on overloading }
  2748. if ((po_overload in currpd.procoptions) or
  2749. (po_overload in fwpd.procoptions)) then
  2750. begin
  2751. { check if all procs have overloading, but not if the proc is a method or
  2752. already declared forward, then the check is already done }
  2753. if not(fwpd.hasforward or
  2754. assigned(currpd._class) or
  2755. (currpd.forwarddef<>fwpd.forwarddef) or
  2756. ((po_overload in currpd.procoptions) and
  2757. (po_overload in fwpd.procoptions))) then
  2758. begin
  2759. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  2760. break;
  2761. end;
  2762. end
  2763. else
  2764. begin
  2765. if not(fwpd.forwarddef) then
  2766. begin
  2767. if (m_tp7 in current_settings.modeswitches) then
  2768. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  2769. else
  2770. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  2771. break;
  2772. end;
  2773. end;
  2774. end; { equal arguments }
  2775. end;
  2776. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2777. list }
  2778. if not forwardfound then
  2779. begin
  2780. { can happen in Delphi mode }
  2781. if (currpd.proctypeoption = potype_function) and
  2782. is_void(currpd.returndef) then
  2783. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  2784. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  2785. end;
  2786. proc_add_definition:=forwardfound;
  2787. end;
  2788. end.