pdecsub.pas 112 KB

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