pdecsub.pas 154 KB

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