pdecsub.pas 114 KB

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