pdecsub.pas 131 KB

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