pdecsub.pas 111 KB

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