pdecsub.pas 154 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013
  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. {$ifdef i386}
  2438. pocall : pocall_oldfpccall;
  2439. {$else i386}
  2440. pocall : pocall_stdcall;
  2441. {$endif i386}
  2442. pooption : [po_interrupt];
  2443. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,pocall_mwpascal,
  2444. pocall_pascal,pocall_far16,pocall_oldfpccall,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  2445. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2446. mutexclpo : [po_external,po_inline,po_exports]
  2447. ),(
  2448. idtok:_IOCHECK;
  2449. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2450. handler : nil;
  2451. pocall : pocall_none;
  2452. pooption : [po_iocheck];
  2453. mutexclpocall : [pocall_internproc];
  2454. mutexclpotype : [];
  2455. mutexclpo : [po_external]
  2456. ),(
  2457. idtok:_LOCAL;
  2458. pd_flags : [pd_implemen,pd_body];
  2459. handler : nil;
  2460. pocall : pocall_none;
  2461. pooption : [po_kylixlocal];
  2462. mutexclpocall : [pocall_internproc,pocall_far16];
  2463. mutexclpotype : [];
  2464. mutexclpo : [po_external,po_exports]
  2465. ),(
  2466. idtok:_MESSAGE;
  2467. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_objcprot,pd_notrecord];
  2468. handler : @pd_message;
  2469. pocall : pocall_none;
  2470. pooption : []; { can be po_msgstr or po_msgint }
  2471. mutexclpocall : [pocall_internproc];
  2472. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2473. mutexclpo : [po_interrupt,po_inline]
  2474. ),(
  2475. idtok:_MWPASCAL;
  2476. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2477. handler : nil;
  2478. pocall : pocall_mwpascal;
  2479. pooption : [];
  2480. mutexclpocall : [];
  2481. mutexclpotype : [];
  2482. mutexclpo : []
  2483. ),(
  2484. idtok:_NEAR;
  2485. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf,pd_notrecord,pd_nothelper];
  2486. handler : @pd_near;
  2487. pocall : pocall_none;
  2488. pooption : [];
  2489. mutexclpocall : [pocall_internproc];
  2490. mutexclpotype : [];
  2491. mutexclpo : []
  2492. ),(
  2493. idtok:_NORETURN;
  2494. pd_flags : [pd_implemen,pd_interface,pd_body,pd_notobjintf];
  2495. handler : nil;
  2496. pocall : pocall_none;
  2497. pooption : [po_noreturn];
  2498. mutexclpocall : [];
  2499. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2500. mutexclpo : [po_interrupt,po_virtualmethod,po_iocheck]
  2501. ),(
  2502. idtok:_NOSTACKFRAME;
  2503. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  2504. handler : nil;
  2505. pocall : pocall_none;
  2506. pooption : [po_nostackframe];
  2507. mutexclpocall : [pocall_internproc];
  2508. mutexclpotype : [];
  2509. mutexclpo : []
  2510. ),(
  2511. idtok:_OVERLOAD;
  2512. pd_flags : [pd_implemen,pd_interface,pd_body,pd_javaclass,pd_intfjava,pd_objcclass,pd_objcprot];
  2513. handler : @pd_overload;
  2514. pocall : pocall_none;
  2515. pooption : [po_overload];
  2516. mutexclpocall : [pocall_internproc];
  2517. mutexclpotype : [];
  2518. mutexclpo : []
  2519. ),(
  2520. idtok:_OVERRIDE;
  2521. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_javaclass,pd_intfjava,pd_notrecord];
  2522. handler : @pd_override;
  2523. pocall : pocall_none;
  2524. pooption : [po_overridingmethod,po_virtualmethod];
  2525. mutexclpocall : [pocall_internproc];
  2526. mutexclpotype : [];
  2527. mutexclpo : [po_exports,po_interrupt,po_virtualmethod,po_inline]
  2528. ),(
  2529. idtok:_PASCAL;
  2530. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2531. handler : nil;
  2532. pocall : pocall_pascal;
  2533. pooption : [];
  2534. mutexclpocall : [];
  2535. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2536. mutexclpo : [po_external]
  2537. ),(
  2538. idtok:_PUBLIC;
  2539. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2540. handler : @pd_public;
  2541. pocall : pocall_none;
  2542. pooption : [po_public,po_global];
  2543. mutexclpocall : [pocall_internproc];
  2544. mutexclpotype : [];
  2545. mutexclpo : [po_external,po_inline]
  2546. ),(
  2547. idtok:_REGISTER;
  2548. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2549. handler : nil;
  2550. pocall : pocall_register;
  2551. pooption : [];
  2552. mutexclpocall : [];
  2553. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2554. mutexclpo : [po_external]
  2555. ),(
  2556. idtok:_REINTRODUCE;
  2557. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_notrecord,pd_javaclass];
  2558. handler : @pd_reintroduce;
  2559. pocall : pocall_none;
  2560. pooption : [po_reintroduce];
  2561. mutexclpocall : [pocall_internproc];
  2562. mutexclpotype : [];
  2563. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  2564. ),(
  2565. idtok:_SAFECALL;
  2566. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2567. handler : nil;
  2568. pocall : pocall_safecall;
  2569. pooption : [];
  2570. mutexclpocall : [];
  2571. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2572. mutexclpo : [po_external]
  2573. ),(
  2574. idtok:_SOFTFLOAT;
  2575. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2576. handler : nil;
  2577. pocall : pocall_softfloat;
  2578. pooption : [];
  2579. mutexclpocall : [];
  2580. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2581. { it's available with po_external because the libgcc floating point routines on the arm
  2582. uses this calling convention }
  2583. mutexclpo : []
  2584. ),(
  2585. idtok:_STATIC;
  2586. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_record,pd_javaclass,pd_notobjintf];
  2587. handler : @pd_static;
  2588. pocall : pocall_none;
  2589. pooption : [po_staticmethod];
  2590. mutexclpocall : [pocall_internproc];
  2591. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2592. mutexclpo : [po_interrupt,po_exports,po_virtualmethod]
  2593. ),(
  2594. idtok:_STDCALL;
  2595. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2596. handler : nil;
  2597. pocall : pocall_stdcall;
  2598. pooption : [];
  2599. mutexclpocall : [];
  2600. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2601. mutexclpo : [po_external]
  2602. ),(
  2603. idtok:_SYSCALL;
  2604. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  2605. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  2606. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  2607. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  2608. handler : @pd_syscall;
  2609. pocall : pocall_syscall;
  2610. pooption : [];
  2611. mutexclpocall : [];
  2612. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2613. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  2614. ),(
  2615. idtok:_VIRTUAL;
  2616. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2617. handler : @pd_virtual;
  2618. pocall : pocall_none;
  2619. pooption : [po_virtualmethod];
  2620. mutexclpocall : [pocall_internproc];
  2621. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2622. mutexclpo : [po_interrupt,po_exports,po_overridingmethod,po_inline,po_staticmethod]
  2623. ),(
  2624. idtok:_CPPDECL;
  2625. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2626. handler : nil;
  2627. pocall : pocall_cppdecl;
  2628. pooption : [];
  2629. mutexclpocall : [];
  2630. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2631. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  2632. ),(
  2633. idtok:_VARARGS;
  2634. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass,pd_objcprot];
  2635. handler : nil;
  2636. pocall : pocall_none;
  2637. pooption : [po_varargs];
  2638. mutexclpocall : [pocall_internproc,pocall_register,
  2639. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  2640. mutexclpotype : [];
  2641. mutexclpo : [po_assembler,po_interrupt,po_inline]
  2642. ),(
  2643. idtok:_COMPILERPROC;
  2644. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2645. handler : @pd_compilerproc;
  2646. pocall : pocall_none;
  2647. pooption : [po_compilerproc];
  2648. mutexclpocall : [];
  2649. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2650. mutexclpo : [po_interrupt]
  2651. ),(
  2652. idtok:_WEAKEXTERNAL;
  2653. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper];
  2654. handler : @pd_weakexternal;
  2655. pocall : pocall_none;
  2656. { mark it both external and weak external, so we don't have to
  2657. adapt all code for external symbols to also check for weak external
  2658. }
  2659. pooption : [po_external,po_weakexternal];
  2660. mutexclpocall : [pocall_internproc,pocall_syscall];
  2661. { allowed for external cpp classes }
  2662. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2663. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2664. ),(
  2665. idtok:_WINAPI;
  2666. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2667. handler : @pd_winapi;
  2668. pocall : pocall_none;
  2669. pooption : [];
  2670. mutexclpocall : [pocall_stdcall,pocall_cdecl,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  2671. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2672. mutexclpo : [po_external]
  2673. ),(
  2674. idtok:_ENUMERATOR;
  2675. pd_flags : [pd_interface,pd_object,pd_record];
  2676. handler : @pd_enumerator;
  2677. pocall : pocall_none;
  2678. pooption : [];
  2679. mutexclpocall : [pocall_internproc];
  2680. mutexclpotype : [];
  2681. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2682. ),(
  2683. idtok:_RTLPROC;
  2684. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2685. handler : nil;
  2686. pocall : pocall_none;
  2687. pooption : [po_rtlproc];
  2688. mutexclpocall : [];
  2689. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2690. mutexclpo : [po_interrupt]
  2691. ),(
  2692. idtok:_HARDFLOAT;
  2693. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2694. handler : @pd_hardfloat;
  2695. pocall : pocall_hardfloat;
  2696. pooption : [];
  2697. mutexclpocall : [];
  2698. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2699. { it's available with po_external because the libgcc floating point routines on the arm
  2700. uses this calling convention }
  2701. mutexclpo : []
  2702. ),(
  2703. idtok:_SYSV_ABI_DEFAULT;
  2704. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2705. handler : nil;
  2706. pocall : pocall_sysv_abi_default;
  2707. pooption : [];
  2708. mutexclpocall : [];
  2709. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2710. mutexclpo : [po_interrupt]
  2711. ),(
  2712. idtok:_SYSV_ABI_CDECL;
  2713. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2714. handler : nil;
  2715. pocall : pocall_sysv_abi_cdecl;
  2716. pooption : [];
  2717. mutexclpocall : [];
  2718. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2719. mutexclpo : [po_interrupt]
  2720. ),(
  2721. idtok:_MS_ABI_DEFAULT;
  2722. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2723. handler : nil;
  2724. pocall : pocall_ms_abi_default;
  2725. pooption : [];
  2726. mutexclpocall : [];
  2727. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2728. mutexclpo : [po_interrupt]
  2729. ),(
  2730. idtok:_MS_ABI_CDECL;
  2731. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2732. handler : nil;
  2733. pocall : pocall_ms_abi_cdecl;
  2734. pooption : [];
  2735. mutexclpocall : [];
  2736. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2737. mutexclpo : [po_interrupt]
  2738. ),(
  2739. idtok:_VECTORCALL;
  2740. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2741. handler : nil;
  2742. pocall : pocall_vectorcall;
  2743. pooption : [];
  2744. mutexclpocall : [];
  2745. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2746. mutexclpo : [po_interrupt]
  2747. )
  2748. );
  2749. function check_proc_directive(isprocvar:boolean):boolean;
  2750. var
  2751. i : longint;
  2752. begin
  2753. result:=false;
  2754. for i:=1 to num_proc_directives do
  2755. if proc_direcdata[i].idtok=idtoken then
  2756. begin
  2757. if ((not isprocvar) or
  2758. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2759. { don't eat a public directive in classes }
  2760. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2761. result:=true;
  2762. exit;
  2763. end;
  2764. end;
  2765. function find_proc_directive_index(tok: ttoken): longint; inline;
  2766. begin
  2767. result:=-1;
  2768. for result:=1 to num_proc_directives do
  2769. if proc_direcdata[result].idtok=tok then
  2770. exit;
  2771. result:=-1;
  2772. end;
  2773. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2774. {
  2775. Parse the procedure directive, returns true if a correct directive is found
  2776. }
  2777. var
  2778. p : longint;
  2779. name : TIDString;
  2780. po_comp : tprocoptions;
  2781. tokenloc : TFilePosInfo;
  2782. begin
  2783. parse_proc_direc:=false;
  2784. name:=tokeninfo^[idtoken].str;
  2785. { Hint directive? Then exit immediatly }
  2786. if (m_hintdirective in current_settings.modeswitches) then
  2787. begin
  2788. case idtoken of
  2789. _LIBRARY,
  2790. _PLATFORM,
  2791. _UNIMPLEMENTED,
  2792. _EXPERIMENTAL,
  2793. _DEPRECATED :
  2794. if (m_delphi in current_settings.modeswitches) and (pd.typ=procdef) then
  2795. begin
  2796. maybe_parse_hint_directives(tprocdef(pd));
  2797. { could the new token still be a directive? }
  2798. if token<>_ID then
  2799. exit;
  2800. end
  2801. else
  2802. exit;
  2803. end;
  2804. end;
  2805. { C directive is MacPas only, because it breaks too much existing code
  2806. on other platforms (PFV) }
  2807. if (idtoken=_C) and
  2808. not(m_mac in current_settings.modeswitches) then
  2809. exit;
  2810. { retrieve data for directive if found }
  2811. p:=find_proc_directive_index(idtoken);
  2812. { Check if the procedure directive is known }
  2813. if p=-1 then
  2814. begin
  2815. { parsing a procvar type the name can be any
  2816. next variable !! }
  2817. if ((pdflags * [pd_procvar,pd_object,pd_record,pd_objcclass,pd_objcprot])=[]) and
  2818. not(idtoken in [_PROPERTY,_GENERIC]) then
  2819. Message1(parser_w_unknown_proc_directive_ignored,pattern);
  2820. exit;
  2821. end;
  2822. { check if method and directive not for object, like public.
  2823. This needs to be checked also for procvars }
  2824. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2825. (symtablestack.top.symtabletype=ObjectSymtable) and
  2826. { directive allowed for cpp classes? }
  2827. not((pd_cppobject in proc_direcdata[p].pd_flags) and is_cppclass(tdef(symtablestack.top.defowner))) and
  2828. not((pd_javaclass in proc_direcdata[p].pd_flags) and is_javaclass(tdef(symtablestack.top.defowner))) and
  2829. not((pd_intfjava in proc_direcdata[p].pd_flags) and is_javainterface(tdef(symtablestack.top.defowner))) then
  2830. exit;
  2831. if (pd_notrecord in proc_direcdata[p].pd_flags) and
  2832. (symtablestack.top.symtabletype=recordsymtable) then
  2833. exit;
  2834. { check if method and directive not for java class }
  2835. if not(pd_javaclass in proc_direcdata[p].pd_flags) and
  2836. is_javaclass(tdef(symtablestack.top.defowner)) then
  2837. exit;
  2838. { check if method and directive not for java interface }
  2839. if not(pd_intfjava in proc_direcdata[p].pd_flags) and
  2840. is_javainterface(tdef(symtablestack.top.defowner)) then
  2841. exit;
  2842. { Keep track of the token's position in the file so it's correctly indicated if an error occurs. }
  2843. tokenloc := current_tokenpos;
  2844. { consume directive, and turn flag on }
  2845. consume(token);
  2846. parse_proc_direc:=true;
  2847. { Conflicts between directives? }
  2848. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) then
  2849. begin
  2850. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,ProcTypeOptionKeywords[pd.proctypeoption]);
  2851. exit;
  2852. end;
  2853. if (pd.proccalloption in proc_direcdata[p].mutexclpocall) then
  2854. begin
  2855. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,'"' + UpCase(proccalloptionStr[pd.proccalloption]) + '"');
  2856. exit;
  2857. end;
  2858. po_comp := (pd.procoptions*proc_direcdata[p].mutexclpo);
  2859. if (po_comp<>[]) then
  2860. begin
  2861. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,get_first_proc_str(po_comp));
  2862. exit;
  2863. end;
  2864. { set calling convention }
  2865. if proc_direcdata[p].pocall<>pocall_none then
  2866. begin
  2867. if (po_hascallingconvention in pd.procoptions) then
  2868. begin
  2869. MessagePos2(tokenloc, parser_w_proc_overriding_calling,
  2870. proccalloptionStr[pd.proccalloption],
  2871. proccalloptionStr[proc_direcdata[p].pocall]);
  2872. end;
  2873. { check if the target processor supports this calling convention }
  2874. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2875. begin
  2876. MessagePos1(tokenloc, parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2877. { recover }
  2878. proc_direcdata[p].pocall:=pocall_stdcall;
  2879. end;
  2880. pd.proccalloption:=proc_direcdata[p].pocall;
  2881. include(pd.procoptions,po_hascallingconvention);
  2882. end;
  2883. if pd.typ=procdef then
  2884. begin
  2885. { Check if the directive is only for objects }
  2886. if (pd_object in proc_direcdata[p].pd_flags) and
  2887. not assigned(tprocdef(pd).struct) then
  2888. exit;
  2889. { Check if the directive is only for records }
  2890. if (pd_record in proc_direcdata[p].pd_flags) and
  2891. not assigned(tprocdef(pd).struct) then
  2892. exit;
  2893. { check if method and directive not for interface }
  2894. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2895. is_interface(tprocdef(pd).struct) then
  2896. exit;
  2897. { check if method and directive not for interface }
  2898. if is_dispinterface(tprocdef(pd).struct) and
  2899. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2900. exit;
  2901. { check if method and directive not for objcclass }
  2902. if is_objcclass(tprocdef(pd).struct) and
  2903. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2904. exit;
  2905. { check if method and directive not for objcprotocol }
  2906. if is_objcprotocol(tprocdef(pd).struct) and
  2907. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2908. exit;
  2909. { check if method and directive not for record/class helper }
  2910. if is_objectpascal_helper(tprocdef(pd).struct) and
  2911. (pd_nothelper in proc_direcdata[p].pd_flags) then
  2912. exit;
  2913. end;
  2914. { Check the pd_flags if the directive should be allowed }
  2915. if (pd_interface in pdflags) and
  2916. not(pd_interface in proc_direcdata[p].pd_flags) then
  2917. begin
  2918. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_interface,name);
  2919. exit;
  2920. end;
  2921. if (pd_implemen in pdflags) and
  2922. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2923. begin
  2924. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_implementation,name);
  2925. exit;
  2926. end;
  2927. if (pd_procvar in pdflags) and
  2928. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2929. begin
  2930. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_procvar,name);
  2931. exit;
  2932. end;
  2933. { Return the new pd_flags }
  2934. if not(pd_body in proc_direcdata[p].pd_flags) then
  2935. exclude(pdflags,pd_body);
  2936. { Add the correct flag }
  2937. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2938. { Call the handler }
  2939. if pointer(proc_direcdata[p].handler)<>nil then
  2940. proc_direcdata[p].handler(pd);
  2941. end;
  2942. function proc_get_importname(pd:tprocdef):string;
  2943. var
  2944. dllname, importname : string;
  2945. begin
  2946. result:='';
  2947. if not(po_external in pd.procoptions) then
  2948. internalerror(200412151);
  2949. { external name or number is specified }
  2950. if assigned(pd.import_name) or (pd.import_nr<>0) then
  2951. begin
  2952. if assigned(pd.import_dll) then
  2953. dllname:=pd.import_dll^
  2954. else
  2955. dllname:='';
  2956. if assigned(pd.import_name) then
  2957. importname:=pd.import_name^
  2958. else
  2959. importname:='';
  2960. proc_get_importname:=make_dllmangledname(dllname,
  2961. importname,pd.import_nr,pd.proccalloption);
  2962. end
  2963. else
  2964. begin
  2965. { Default names when importing variables }
  2966. case pd.proccalloption of
  2967. pocall_cdecl,
  2968. pocall_sysv_abi_cdecl,
  2969. pocall_ms_abi_cdecl:
  2970. begin
  2971. if assigned(pd.struct) then
  2972. result:=target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname
  2973. else
  2974. result:=target_info.Cprefix+pd.procsym.realname;
  2975. end;
  2976. pocall_cppdecl :
  2977. begin
  2978. result:=target_info.Cprefix+pd.cplusplusmangledname;
  2979. end;
  2980. else
  2981. begin
  2982. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  2983. { but according to MacPas mode description
  2984. Cprefix should still be used PM }
  2985. if (m_mac in current_settings.modeswitches) then
  2986. result:=target_info.Cprefix+tprocdef(pd).procsym.realname
  2987. else
  2988. result:=pd.procsym.realname;
  2989. end;
  2990. end;
  2991. end;
  2992. end;
  2993. procedure compilerproc_set_symbol_name(pd: tprocdef);
  2994. begin
  2995. pd.procsym.realname:='$'+lower(pd.procsym.name);
  2996. end;
  2997. procedure proc_set_mangledname(pd:tprocdef);
  2998. var
  2999. s : string;
  3000. begin
  3001. { When the mangledname is already set we aren't allowed to change
  3002. it because it can already be used somewhere (PFV) }
  3003. if not(po_has_mangledname in pd.procoptions) then
  3004. begin
  3005. if (po_external in pd.procoptions) then
  3006. begin
  3007. { External Procedures are only allowed to change the mangledname
  3008. in their first declaration }
  3009. if (pd.forwarddef or (not pd.hasforward)) then
  3010. begin
  3011. s:=proc_get_importname(pd);
  3012. if s<>'' then
  3013. begin
  3014. pd.setmangledname(s);
  3015. end;
  3016. { since this is an external declaration, there won't be an
  3017. implementation that needs to match the original symbol
  3018. again -> immediately convert here }
  3019. if po_compilerproc in pd.procoptions then
  3020. compilerproc_set_symbol_name(pd);
  3021. end
  3022. end
  3023. else
  3024. { Normal procedures }
  3025. begin
  3026. if (po_compilerproc in pd.procoptions) then
  3027. begin
  3028. pd.setmangledname(lower(pd.procsym.name));
  3029. end;
  3030. end;
  3031. end;
  3032. { Public/exported alias names }
  3033. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  3034. not(po_has_public_name in pd.procoptions) then
  3035. begin
  3036. case pd.proccalloption of
  3037. pocall_cdecl,
  3038. pocall_sysv_abi_cdecl,
  3039. pocall_ms_abi_cdecl:
  3040. begin
  3041. if assigned(pd.struct) then
  3042. pd.aliasnames.insert(target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname)
  3043. else
  3044. begin
  3045. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  3046. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  3047. (po_exports in pd.procoptions) then
  3048. pd.aliasnames.insert(pd.procsym.realname)
  3049. else
  3050. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  3051. end;
  3052. end;
  3053. pocall_cppdecl :
  3054. begin
  3055. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  3056. end;
  3057. end;
  3058. { prevent adding the alias a second time }
  3059. include(pd.procoptions,po_has_public_name);
  3060. end;
  3061. end;
  3062. procedure handle_calling_convention(pd:tabstractprocdef;flags:thccflags=hcc_all);
  3063. begin
  3064. if hcc_check in flags then
  3065. begin
  3066. { set the default calling convention if none provided }
  3067. if (pd.typ=procdef) and
  3068. (is_objc_class_or_protocol(tprocdef(pd).struct) or
  3069. is_cppclass(tprocdef(pd).struct)) then
  3070. begin
  3071. { none of the explicit calling conventions should be allowed }
  3072. if (po_hascallingconvention in pd.procoptions) then
  3073. internalerror(2009032501);
  3074. if is_cppclass(tprocdef(pd).struct) then
  3075. pd.proccalloption:=pocall_cppdecl
  3076. else
  3077. pd.proccalloption:=pocall_cdecl;
  3078. end
  3079. else if not(po_hascallingconvention in pd.procoptions) then
  3080. pd.proccalloption:=current_settings.defproccall
  3081. else
  3082. begin
  3083. if pd.proccalloption=pocall_none then
  3084. internalerror(200309081);
  3085. end;
  3086. { handle proccall specific settings }
  3087. case pd.proccalloption of
  3088. pocall_cdecl,
  3089. pocall_cppdecl,
  3090. pocall_sysv_abi_cdecl,
  3091. pocall_ms_abi_cdecl:
  3092. begin
  3093. { check C cdecl para types }
  3094. check_c_para(pd);
  3095. end;
  3096. pocall_far16 :
  3097. begin
  3098. { Temporary stub, must be rewritten to support OS/2 far16 }
  3099. Message1(parser_w_proc_directive_ignored,'FAR16');
  3100. end;
  3101. end;
  3102. { Inlining is enabled and supported? }
  3103. if (po_inline in pd.procoptions) and
  3104. not(cs_do_inline in current_settings.localswitches) then
  3105. begin
  3106. { Give an error if inline is not supported by the compiler mode,
  3107. otherwise only give a hint that this procedure will not be inlined }
  3108. if not(m_default_inline in current_settings.modeswitches) then
  3109. Message(parser_e_proc_inline_not_supported)
  3110. else
  3111. Message(parser_h_inlining_disabled);
  3112. exclude(pd.procoptions,po_inline);
  3113. end;
  3114. { For varargs directive also cdecl and external must be defined }
  3115. if (po_varargs in pd.procoptions) then
  3116. begin
  3117. { check first for external in the interface, if available there
  3118. then the cdecl must also be there since there is no implementation
  3119. available to contain it }
  3120. if parse_only then
  3121. begin
  3122. { if external is available, then cdecl must also be available,
  3123. procvars don't need external }
  3124. if not((po_external in pd.procoptions) or
  3125. (pd.typ=procvardef) or
  3126. { for objcclasses this is checked later, because the entire
  3127. class may be external. }
  3128. is_objc_class_or_protocol(tprocdef(pd).struct)) and
  3129. not(pd.proccalloption in (cdecl_pocalls + [pocall_stdcall])) then
  3130. Message(parser_e_varargs_need_cdecl_and_external);
  3131. end
  3132. else
  3133. begin
  3134. { both must be defined now }
  3135. if not((po_external in pd.procoptions) or
  3136. (pd.typ=procvardef)) or
  3137. not(pd.proccalloption in (cdecl_pocalls + [pocall_stdcall])) then
  3138. Message(parser_e_varargs_need_cdecl_and_external);
  3139. end;
  3140. end;
  3141. end;
  3142. if hcc_insert_hidden_paras in flags then
  3143. begin
  3144. { insert hidden high parameters }
  3145. pd.parast.SymList.ForEachCall(@insert_hidden_para,pd);
  3146. { insert hidden self parameter }
  3147. insert_self_and_vmt_para(pd);
  3148. { insert funcret parameter if required }
  3149. insert_funcret_para(pd);
  3150. { Make var parameters regable, this must be done after the calling
  3151. convention is set. }
  3152. { this must be done before parentfp is insert, because getting all cases
  3153. where parentfp must be in a memory location isn't catched properly so
  3154. we put parentfp never in a register }
  3155. pd.parast.SymList.ForEachCall(@set_addr_param_regable,pd);
  3156. { insert parentfp parameter if required }
  3157. insert_parentfp_para(pd);
  3158. end;
  3159. { Calculate parameter tlist }
  3160. pd.calcparas;
  3161. end;
  3162. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  3163. {
  3164. Parse the procedure directives. It does not matter if procedure directives
  3165. are written using ;procdir; or ['procdir'] syntax.
  3166. }
  3167. var
  3168. stoprecording,
  3169. res : boolean;
  3170. begin
  3171. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  3172. begin
  3173. tprocdef(pd).aliasnames.insert(target_info.Cprefix+tprocdef(pd).procsym.realname);
  3174. include(pd.procoptions,po_public);
  3175. include(pd.procoptions,po_has_public_name);
  3176. include(pd.procoptions,po_global);
  3177. end;
  3178. { methods from external class definitions are all external themselves }
  3179. if (pd.typ=procdef) and
  3180. assigned(tprocdef(pd).struct) and
  3181. (tprocdef(pd).struct.typ=objectdef) and
  3182. (oo_is_external in tobjectdef(tprocdef(pd).struct).objectoptions) then
  3183. tprocdef(pd).make_external;
  3184. { Class constructors and destructor are static class methods in real. }
  3185. { There are many places in the compiler where either class or static }
  3186. { method flag changes the behavior. It is simplier to add them to }
  3187. { the class constructors/destructors options than to fix all the }
  3188. { occurencies. (Paul) }
  3189. if pd.proctypeoption in [potype_class_constructor,potype_class_destructor] then
  3190. begin
  3191. include(pd.procoptions,po_classmethod);
  3192. include(pd.procoptions,po_staticmethod);
  3193. end;
  3194. { for a generic routine we also need to record the procedure }
  3195. { directives, but only if we aren't already recording for a }
  3196. { surrounding generic }
  3197. if pd.is_generic and (pd.typ=procdef) and not current_scanner.is_recording_tokens then
  3198. begin
  3199. current_scanner.startrecordtokens(tprocdef(pd).genericdecltokenbuf);
  3200. stoprecording:=true;
  3201. end
  3202. else
  3203. stoprecording:=false;
  3204. while token in [_ID,_LECKKLAMMER] do
  3205. begin
  3206. if try_to_consume(_LECKKLAMMER) then
  3207. begin
  3208. repeat
  3209. parse_proc_direc(pd,pdflags);
  3210. until not try_to_consume(_COMMA);
  3211. consume(_RECKKLAMMER);
  3212. { we always expect at least '[];' }
  3213. res:=true;
  3214. end
  3215. else
  3216. begin
  3217. res:=parse_proc_direc(pd,pdflags);
  3218. end;
  3219. { A procedure directive normally followed by a semicolon, but in
  3220. a const section or reading a type we should stop when _EQ is found,
  3221. because a constant/default value follows }
  3222. if res then
  3223. begin
  3224. if (block_type=bt_const_type) and
  3225. (token=_EQ) then
  3226. break;
  3227. { support procedure proc;stdcall export; }
  3228. if not(check_proc_directive((pd.typ=procvardef))) then
  3229. begin
  3230. { support "record p : procedure stdcall end;" and
  3231. "var p : procedure stdcall = nil;" }
  3232. if (pd_procvar in pdflags) and
  3233. (token in [_END,_RKLAMMER,_EQ]) then
  3234. break
  3235. else
  3236. begin
  3237. if (token=_COLON) then
  3238. begin
  3239. Message(parser_e_field_not_allowed_here);
  3240. consume_all_until(_SEMICOLON);
  3241. end;
  3242. consume(_SEMICOLON)
  3243. end;
  3244. end;
  3245. end
  3246. else
  3247. break;
  3248. end;
  3249. if stoprecording then
  3250. current_scanner.stoprecordtokens;
  3251. { nostackframe requires assembler, but assembler
  3252. may be specified in the implementation part only,
  3253. and in not required if the function is first forward declared
  3254. if it is a procdef that has forwardef set to true
  3255. we postpone the possible error message to the real implementation
  3256. parse_only does not need to be considered as po_nostackframe
  3257. is an implementation only directive }
  3258. if (po_nostackframe in pd.procoptions) and
  3259. not (po_assembler in pd.procoptions) and
  3260. ((pd.typ<>procdef) or not tprocdef(pd).forwarddef) then
  3261. message(parser_e_nostackframe_without_assembler);
  3262. end;
  3263. procedure parse_var_proc_directives(sym:tsym);
  3264. var
  3265. pdflags : tpdflags;
  3266. pd : tabstractprocdef;
  3267. begin
  3268. pdflags:=[pd_procvar];
  3269. pd:=nil;
  3270. case sym.typ of
  3271. fieldvarsym,
  3272. staticvarsym,
  3273. localvarsym,
  3274. paravarsym :
  3275. pd:=tabstractprocdef(tabstractvarsym(sym).vardef);
  3276. typesym :
  3277. pd:=tabstractprocdef(ttypesym(sym).typedef);
  3278. else
  3279. internalerror(2003042617);
  3280. end;
  3281. if pd.typ<>procvardef then
  3282. internalerror(2003042618);
  3283. { names should never be used anyway }
  3284. parse_proc_directives(pd,pdflags);
  3285. end;
  3286. procedure parse_object_proc_directives(pd:tabstractprocdef);
  3287. var
  3288. pdflags : tpdflags;
  3289. begin
  3290. pdflags:=[pd_object];
  3291. parse_proc_directives(pd,pdflags);
  3292. end;
  3293. procedure parse_record_proc_directives(pd:tabstractprocdef);
  3294. var
  3295. pdflags : tpdflags;
  3296. begin
  3297. pdflags:=[pd_record];
  3298. parse_proc_directives(pd,pdflags);
  3299. end;
  3300. function proc_add_definition(var currpd:tprocdef):boolean;
  3301. function check_generic_parameters(fwpd,currpd:tprocdef):boolean;
  3302. var
  3303. i : longint;
  3304. fwtype,
  3305. currtype : ttypesym;
  3306. begin
  3307. result:=true;
  3308. if fwpd.genericparas.count<>currpd.genericparas.count then
  3309. internalerror(2018090101);
  3310. for i:=0 to fwpd.genericparas.count-1 do
  3311. begin
  3312. fwtype:=ttypesym(fwpd.genericparas[i]);
  3313. currtype:=ttypesym(currpd.genericparas[i]);
  3314. if fwtype.name<>currtype.name then
  3315. begin
  3316. messagepos1(currtype.fileinfo,sym_e_generic_type_param_mismatch,currtype.realname);
  3317. messagepos1(fwtype.fileinfo,sym_e_generic_type_param_decl,fwtype.realname);
  3318. result:=false;
  3319. end;
  3320. end;
  3321. end;
  3322. function equal_generic_procdefs(fwpd,currpd:tprocdef):boolean;
  3323. var
  3324. i : longint;
  3325. fwtype,
  3326. currtype : ttypesym;
  3327. foundretdef : boolean;
  3328. begin
  3329. result:=false;
  3330. if fwpd.genericparas.count<>currpd.genericparas.count then
  3331. exit;
  3332. { comparing generic declarations is a bit more cumbersome as the
  3333. defs of the generic parameter types are not equal, especially if the
  3334. declaration contains constraints; essentially we have two cases:
  3335. - proc declared in interface of unit (or in class/record/object)
  3336. and defined in implementation; here the fwpd might contain
  3337. constraints while currpd must only contain undefineddefs
  3338. - forward declaration in implementation }
  3339. foundretdef:=false;
  3340. for i:=0 to fwpd.genericparas.count-1 do
  3341. begin
  3342. fwtype:=ttypesym(fwpd.genericparas[i]);
  3343. currtype:=ttypesym(currpd.genericparas[i]);
  3344. { if the type in the currpd isn't a pure undefineddef, then we can
  3345. stop right there }
  3346. if (currtype.typedef.typ<>undefineddef) or (df_genconstraint in currtype.typedef.defoptions) then
  3347. exit;
  3348. if not foundretdef then
  3349. begin
  3350. { if the returndef is the same as this parameter's def then this
  3351. needs to be the case for both procdefs }
  3352. foundretdef:=fwpd.returndef=fwtype.typedef;
  3353. if foundretdef xor (currpd.returndef=currtype.typedef) then
  3354. exit;
  3355. end;
  3356. end;
  3357. if compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv,cpo_generic])<>te_exact then
  3358. exit;
  3359. if not foundretdef then
  3360. begin
  3361. if (df_specialization in tstoreddef(fwpd.returndef).defoptions) and (df_specialization in tstoreddef(currpd.returndef).defoptions) then
  3362. { for specializations we're happy with equal defs instead of exactly the same defs }
  3363. result:=equal_defs(fwpd.returndef,currpd.returndef)
  3364. else
  3365. { the returndef isn't a type parameter, so compare as usual }
  3366. result:=compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact;
  3367. end
  3368. else
  3369. result:=true;
  3370. end;
  3371. {
  3372. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  3373. forwarddef is found and reused it returns true
  3374. }
  3375. var
  3376. fwpd : tprocdef;
  3377. currparasym,
  3378. fwparasym : tsym;
  3379. currparacnt,
  3380. fwparacnt,
  3381. curridx,
  3382. fwidx,
  3383. virtualdirinfo,
  3384. i : longint;
  3385. po_comp : tprocoptions;
  3386. paracompopt: tcompare_paras_options;
  3387. forwardfound : boolean;
  3388. symentry: TSymEntry;
  3389. item : tlinkedlistitem;
  3390. begin
  3391. virtualdirinfo:=-1;
  3392. forwardfound:=false;
  3393. { check overloaded functions if the same function already exists }
  3394. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  3395. begin
  3396. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  3397. { can happen for internally generated routines }
  3398. if (fwpd=currpd) then
  3399. begin
  3400. result:=true;
  3401. exit;
  3402. end;
  3403. { Skip overloaded definitions that are declared in other units }
  3404. if fwpd.procsym<>currpd.procsym then
  3405. continue;
  3406. { check the parameters, for delphi/tp it is possible to
  3407. leave the parameters away in the implementation (forwarddef=false).
  3408. But for an overload declared function this is not allowed }
  3409. if { check if empty implementation arguments match is allowed }
  3410. (
  3411. not(m_repeat_forward in current_settings.modeswitches) and
  3412. not(currpd.forwarddef) and
  3413. is_bareprocdef(currpd) and
  3414. not(po_overload in fwpd.procoptions)
  3415. ) or
  3416. (
  3417. fwpd.is_generic and
  3418. currpd.is_generic and
  3419. equal_generic_procdefs(fwpd,currpd)
  3420. ) or
  3421. { check arguments, we need to check only the user visible parameters. The hidden parameters
  3422. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV)
  3423. don't check default values here, because routines that are the same except for their default
  3424. values should be reported as mismatches (since you can't overload based on different default
  3425. parameter values) }
  3426. (
  3427. (compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact) and
  3428. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact)
  3429. ) then
  3430. begin
  3431. { Check if we've found the forwarddef, if found then
  3432. we need to update the forward def with the current
  3433. implementation settings }
  3434. if fwpd.forwarddef then
  3435. begin
  3436. forwardfound:=true;
  3437. if not(m_repeat_forward in current_settings.modeswitches) and
  3438. (fwpd.proccalloption<>currpd.proccalloption) then
  3439. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv]
  3440. else
  3441. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv];
  3442. { Check calling convention }
  3443. if (fwpd.proccalloption<>currpd.proccalloption) then
  3444. begin
  3445. { In delphi it is possible to specify the calling
  3446. convention in the interface or implementation if
  3447. there was no convention specified in the other
  3448. part }
  3449. if (m_delphi in current_settings.modeswitches) then
  3450. begin
  3451. if not(po_hascallingconvention in currpd.procoptions) then
  3452. currpd.proccalloption:=fwpd.proccalloption
  3453. else
  3454. if not(po_hascallingconvention in fwpd.procoptions) then
  3455. fwpd.proccalloption:=currpd.proccalloption
  3456. else
  3457. begin
  3458. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  3459. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3460. { restore interface settings }
  3461. currpd.proccalloption:=fwpd.proccalloption;
  3462. end;
  3463. end
  3464. else
  3465. begin
  3466. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  3467. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3468. { restore interface settings }
  3469. currpd.proccalloption:=fwpd.proccalloption;
  3470. end;
  3471. end;
  3472. { Check static }
  3473. if (po_staticmethod in fwpd.procoptions) then
  3474. begin
  3475. if not (po_staticmethod in currpd.procoptions) then
  3476. begin
  3477. include(currpd.procoptions, po_staticmethod);
  3478. if (po_classmethod in currpd.procoptions) then
  3479. begin
  3480. { remove self from the hidden paras }
  3481. symentry:=currpd.parast.Find('self');
  3482. if symentry<>nil then
  3483. begin
  3484. currpd.parast.Delete(symentry);
  3485. currpd.calcparas;
  3486. end;
  3487. end;
  3488. end;
  3489. end;
  3490. { Check if the procedure type and return type are correct,
  3491. also the parameters must match also with the type and that
  3492. if the implementation has default parameters, the interface
  3493. also has them and that if they both have them, that they
  3494. have the same value }
  3495. if ((m_repeat_forward in current_settings.modeswitches) or
  3496. not is_bareprocdef(currpd)) and
  3497. (
  3498. (
  3499. fwpd.is_generic and
  3500. currpd.is_generic and
  3501. not equal_generic_procdefs(fwpd,currpd)
  3502. ) or
  3503. (
  3504. (
  3505. not fwpd.is_generic or
  3506. not currpd.is_generic
  3507. ) and
  3508. (
  3509. (compare_paras(fwpd.paras,currpd.paras,cp_all,paracompopt)<>te_exact) or
  3510. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)<>te_exact)
  3511. )
  3512. )
  3513. ) then
  3514. begin
  3515. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3516. fwpd.fullprocname(false));
  3517. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3518. break;
  3519. end;
  3520. { Check if both are declared forward }
  3521. if fwpd.forwarddef and currpd.forwarddef then
  3522. begin
  3523. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  3524. currpd.fullprocname(false));
  3525. end;
  3526. { internconst or internproc only need to be defined once }
  3527. if (fwpd.proccalloption=pocall_internproc) then
  3528. currpd.proccalloption:=fwpd.proccalloption
  3529. else
  3530. if (currpd.proccalloption=pocall_internproc) then
  3531. fwpd.proccalloption:=currpd.proccalloption;
  3532. { Check procedure options, Delphi requires that class is
  3533. repeated in the implementation for class methods }
  3534. if (m_fpc in current_settings.modeswitches) then
  3535. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  3536. else
  3537. po_comp:=[po_classmethod,po_methodpointer];
  3538. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  3539. (fwpd.proctypeoption <> currpd.proctypeoption) or
  3540. { if the implementation version has an "overload" modifier,
  3541. the interface version must also have it (otherwise we can
  3542. get annoying crashes due to interface crc changes) }
  3543. (not(po_overload in fwpd.procoptions) and
  3544. (po_overload in currpd.procoptions)) then
  3545. begin
  3546. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3547. fwpd.fullprocname(false));
  3548. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  3549. { This error is non-fatal, we can recover }
  3550. end;
  3551. { Forward declaration is external? }
  3552. if (po_external in fwpd.procoptions) then
  3553. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  3554. { check for conflicts with "virtual" if this is a virtual
  3555. method, as "virtual" cannot be repeated in the
  3556. implementation and hence does not get checked against }
  3557. if (po_virtualmethod in fwpd.procoptions) then
  3558. begin
  3559. if virtualdirinfo=-1 then
  3560. begin
  3561. virtualdirinfo:=find_proc_directive_index(_VIRTUAL);
  3562. if virtualdirinfo=-1 then
  3563. internalerror(2018010101);
  3564. end;
  3565. po_comp := (proc_direcdata[virtualdirinfo].mutexclpo * currpd.procoptions);
  3566. if po_comp<>[] then
  3567. MessagePos2(currpd.fileinfo,parser_e_proc_dir_conflict,tokeninfo^[_VIRTUAL].str,get_first_proc_str(po_comp));
  3568. end;
  3569. { Check parameters }
  3570. if (m_repeat_forward in current_settings.modeswitches) or
  3571. (currpd.minparacount>0) then
  3572. begin
  3573. { If mangled names are equal then they have the same amount of arguments }
  3574. { We can check the names of the arguments }
  3575. { both symtables are in the same order from left to right }
  3576. curridx:=0;
  3577. fwidx:=0;
  3578. currparacnt:=currpd.parast.SymList.Count;
  3579. fwparacnt:=fwpd.parast.SymList.Count;
  3580. repeat
  3581. { skip default parameter constsyms }
  3582. while (curridx<currparacnt) and
  3583. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  3584. inc(curridx);
  3585. while (fwidx<fwparacnt) and
  3586. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  3587. inc(fwidx);
  3588. { stop when one of the two lists is at the end }
  3589. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  3590. break;
  3591. { compare names of parameters, ignore implictly
  3592. renamed parameters }
  3593. currparasym:=tsym(currpd.parast.SymList[curridx]);
  3594. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  3595. if not(sp_implicitrename in currparasym.symoptions) and
  3596. not(sp_implicitrename in fwparasym.symoptions) then
  3597. begin
  3598. if (currparasym.name<>fwparasym.name) then
  3599. begin
  3600. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  3601. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  3602. break;
  3603. end;
  3604. end;
  3605. { next parameter }
  3606. inc(curridx);
  3607. inc(fwidx);
  3608. until false;
  3609. end;
  3610. { check that the type parameter names for generic methods match;
  3611. we check this here and not in equal_generic_procdefs as the defs
  3612. might still be different due to their parameters, so we'd generate
  3613. errors without any need }
  3614. if currpd.is_generic and fwpd.is_generic then
  3615. { an error here is recoverable, so we simply continue }
  3616. check_generic_parameters(fwpd,currpd);
  3617. { Everything is checked, now we can update the forward declaration
  3618. with the new data from the implementation }
  3619. fwpd.forwarddef:=currpd.forwarddef;
  3620. fwpd.hasforward:=true;
  3621. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  3622. { marked as local but exported from unit? }
  3623. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  3624. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  3625. if fwpd.extnumber=$ffff then
  3626. fwpd.extnumber:=currpd.extnumber;
  3627. while not currpd.aliasnames.empty do
  3628. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  3629. { update fileinfo so position references the implementation,
  3630. also update funcretsym if it is already generated }
  3631. fwpd.fileinfo:=currpd.fileinfo;
  3632. if assigned(fwpd.funcretsym) then
  3633. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  3634. if assigned(currpd.deprecatedmsg) then
  3635. begin
  3636. stringdispose(fwpd.deprecatedmsg);
  3637. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  3638. end;
  3639. { import names }
  3640. if assigned(currpd.import_dll) then
  3641. begin
  3642. stringdispose(fwpd.import_dll);
  3643. fwpd.import_dll:=stringdup(currpd.import_dll^);
  3644. end;
  3645. if assigned(currpd.import_name) then
  3646. begin
  3647. stringdispose(fwpd.import_name);
  3648. fwpd.import_name:=stringdup(currpd.import_name^);
  3649. end;
  3650. fwpd.import_nr:=currpd.import_nr;
  3651. { for compilerproc defines we need to rename and update the
  3652. symbolname to lowercase so users can' access it (can't do
  3653. it immediately, because then the implementation symbol
  3654. won't be matched) }
  3655. if po_compilerproc in fwpd.procoptions then
  3656. begin
  3657. compilerproc_set_symbol_name(fwpd);
  3658. current_module.add_public_asmsym(fwpd.procsym.realname,AB_GLOBAL,AT_FUNCTION);
  3659. end;
  3660. if po_public in fwpd.procoptions then
  3661. begin
  3662. item:=fwpd.aliasnames.first;
  3663. while assigned(item) do
  3664. begin
  3665. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  3666. item:=item.next;
  3667. end;
  3668. end;
  3669. { Release current procdef }
  3670. currpd.owner.deletedef(currpd);
  3671. currpd:=fwpd;
  3672. end
  3673. else
  3674. begin
  3675. { abstract methods aren't forward defined, but this }
  3676. { needs another error message }
  3677. if (po_abstractmethod in fwpd.procoptions) then
  3678. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  3679. else
  3680. begin
  3681. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  3682. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3683. end;
  3684. end;
  3685. { we found one proc with the same arguments, there are no others
  3686. so we can stop }
  3687. break;
  3688. end;
  3689. { check for allowing overload directive }
  3690. if not(m_fpc in current_settings.modeswitches) then
  3691. begin
  3692. { overload directive turns on overloading }
  3693. if ((po_overload in currpd.procoptions) or
  3694. (po_overload in fwpd.procoptions)) then
  3695. begin
  3696. { check if all procs have overloading, but not if the proc is a method or
  3697. already declared forward, then the check is already done }
  3698. if not(fwpd.hasforward or
  3699. assigned(currpd.struct) or
  3700. (currpd.forwarddef<>fwpd.forwarddef) or
  3701. ((po_overload in currpd.procoptions) and
  3702. (po_overload in fwpd.procoptions))) then
  3703. begin
  3704. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3705. break;
  3706. end
  3707. end
  3708. else
  3709. begin
  3710. if not(fwpd.forwarddef) then
  3711. begin
  3712. if (m_tp7 in current_settings.modeswitches) then
  3713. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  3714. else
  3715. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3716. break;
  3717. end;
  3718. end;
  3719. end; { equal arguments }
  3720. end;
  3721. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  3722. list }
  3723. if not forwardfound then
  3724. begin
  3725. { can happen in Delphi mode }
  3726. if (currpd.proctypeoption = potype_function) and
  3727. is_void(currpd.returndef) then
  3728. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  3729. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  3730. if not currpd.forwarddef and (po_public in currpd.procoptions) then
  3731. begin
  3732. item:=currpd.aliasnames.first;
  3733. while assigned(item) do
  3734. begin
  3735. current_module.add_public_asmsym(TCmdStrListItem(item).str,AB_GLOBAL,AT_FUNCTION);
  3736. item:=item.next;
  3737. end;
  3738. end;
  3739. end;
  3740. proc_add_definition:=forwardfound;
  3741. end;
  3742. end.