pdecsub.pas 136 KB

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