2
0

pdecsub.pas 131 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449
  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);
  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);
  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. include(pd.defoptions,df_specialization);
  926. { Find corresponding genericdef, we need it later to
  927. replay the tokens to generate the body }
  928. if not assigned(pd.struct.genericdef) then
  929. internalerror(200512113);
  930. genericst:=pd.struct.genericdef.GetSymtable(gs_record);
  931. if not assigned(genericst) then
  932. internalerror(200512114);
  933. { when searching for the correct procdef to use as genericdef we need to ignore
  934. everything except procdefs so that we can find the correct indices }
  935. index:=0;
  936. found:=false;
  937. for i:=0 to pd.owner.deflist.count-1 do
  938. begin
  939. if tdef(pd.owner.deflist[i]).typ<>procdef then
  940. continue;
  941. if pd.owner.deflist[i]=pd then
  942. begin
  943. found:=true;
  944. break;
  945. end;
  946. inc(index);
  947. end;
  948. if not found then
  949. internalerror(2014052301);
  950. for i:=0 to genericst.deflist.count-1 do
  951. begin
  952. if tdef(genericst.deflist[i]).typ<>procdef then
  953. continue;
  954. if index=0 then
  955. pd.genericdef:=tstoreddef(genericst.deflist[i]);
  956. dec(index);
  957. end;
  958. if not assigned(pd.genericdef) or
  959. (pd.genericdef.typ<>procdef) then
  960. internalerror(200512115);
  961. end;
  962. end;
  963. { methods need to be exported }
  964. if assigned(astruct) and
  965. (
  966. (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) or
  967. (symtablestack.top.symtablelevel=main_program_level)
  968. ) then
  969. include(pd.procoptions,po_global);
  970. { symbol options that need to be kept per procdef }
  971. pd.fileinfo:=procstartfilepos;
  972. pd.visibility:=symtablestack.top.currentvisibility;
  973. if symtablestack.top.currentlyoptional then
  974. include(pd.procoptions,po_optional);
  975. { parse parameters }
  976. if token=_LKLAMMER then
  977. begin
  978. old_current_structdef:=nil;
  979. old_current_genericdef:=nil;
  980. old_current_specializedef:=nil;
  981. { Add ObjectSymtable to be able to find nested type definitions }
  982. popclass:=0;
  983. if assigned(pd.struct) and
  984. (pd.parast.symtablelevel>=normal_function_level) and
  985. not(symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  986. begin
  987. popclass:=push_nested_hierarchy(pd.struct);
  988. old_current_structdef:=current_structdef;
  989. old_current_genericdef:=current_genericdef;
  990. old_current_specializedef:=current_specializedef;
  991. current_structdef:=pd.struct;
  992. if assigned(current_structdef) and (df_generic in current_structdef.defoptions) then
  993. current_genericdef:=current_structdef;
  994. if assigned(current_structdef) and (df_specialization in current_structdef.defoptions) then
  995. current_specializedef:=current_structdef;
  996. end;
  997. { Add parameter symtable }
  998. if pd.parast.symtabletype<>staticsymtable then
  999. symtablestack.push(pd.parast);
  1000. parse_parameter_dec(pd);
  1001. if pd.parast.symtabletype<>staticsymtable then
  1002. symtablestack.pop(pd.parast);
  1003. if popclass>0 then
  1004. begin
  1005. current_structdef:=old_current_structdef;
  1006. current_genericdef:=old_current_genericdef;
  1007. current_specializedef:=old_current_specializedef;
  1008. dec(popclass,pop_nested_hierarchy(pd.struct));
  1009. if popclass<>0 then
  1010. internalerror(201011260); // 11 nov 2010 index 0
  1011. end;
  1012. end;
  1013. parse_generic:=old_parse_generic;
  1014. result:=true;
  1015. end;
  1016. function parse_proc_dec(isclassmethod:boolean;astruct:tabstractrecorddef):tprocdef;
  1017. var
  1018. pd: tprocdef;
  1019. locationstr: string;
  1020. i: integer;
  1021. found: boolean;
  1022. old_block_type: tblock_type;
  1023. procedure read_returndef(pd: tprocdef);
  1024. var
  1025. popclass: integer;
  1026. old_parse_generic: boolean;
  1027. old_current_structdef: tabstractrecorddef;
  1028. old_current_genericdef,
  1029. old_current_specializedef: tstoreddef;
  1030. begin
  1031. old_parse_generic:=parse_generic;
  1032. { Add ObjectSymtable to be able to find generic type definitions }
  1033. popclass:=0;
  1034. old_current_structdef:=nil;
  1035. old_current_genericdef:=nil;
  1036. old_current_specializedef:=nil;
  1037. if assigned(pd.struct) and
  1038. (pd.parast.symtablelevel>=normal_function_level) and
  1039. not (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1040. begin
  1041. popclass:=push_nested_hierarchy(pd.struct);
  1042. parse_generic:=(df_generic in pd.struct.defoptions);
  1043. old_current_structdef:=current_structdef;
  1044. old_current_genericdef:=current_genericdef;
  1045. old_current_specializedef:=current_specializedef;
  1046. current_structdef:=pd.struct;
  1047. if assigned(current_structdef) and (df_generic in current_structdef.defoptions) then
  1048. current_genericdef:=current_structdef;
  1049. if assigned(current_structdef) and (df_specialization in current_structdef.defoptions) then
  1050. current_specializedef:=current_structdef;
  1051. end;
  1052. single_type(pd.returndef,[stoAllowSpecialization]);
  1053. // Issue #24863, enabled only for the main progra commented out for now because it breaks building of RTL and needs extensive
  1054. // testing and/or RTL patching.
  1055. {
  1056. if ((pd.returndef=cvarianttype) or (pd.returndef=colevarianttype)) and
  1057. not(cs_compilesystem in current_settings.moduleswitches) then
  1058. current_module.flags:=current_module.flags or uf_uses_variants;
  1059. }
  1060. if is_dispinterface(pd.struct) and not is_automatable(pd.returndef) then
  1061. Message1(type_e_not_automatable,pd.returndef.typename);
  1062. if popclass>0 then
  1063. begin
  1064. current_structdef:=old_current_structdef;
  1065. current_genericdef:=old_current_genericdef;
  1066. current_specializedef:=old_current_specializedef;
  1067. dec(popclass,pop_nested_hierarchy(pd.struct));
  1068. if popclass<>0 then
  1069. internalerror(201012020);
  1070. end;
  1071. parse_generic:=old_parse_generic;
  1072. end;
  1073. begin
  1074. locationstr:='';
  1075. pd:=nil;
  1076. case token of
  1077. _FUNCTION :
  1078. begin
  1079. consume(_FUNCTION);
  1080. if parse_proc_head(astruct,potype_function,pd) then
  1081. begin
  1082. { pd=nil when it is a interface mapping }
  1083. if assigned(pd) then
  1084. begin
  1085. if try_to_consume(_COLON) then
  1086. begin
  1087. read_returndef(pd);
  1088. if (target_info.system in [system_m68k_amiga]) then
  1089. begin
  1090. if (idtoken=_LOCATION) then
  1091. begin
  1092. if po_explicitparaloc in pd.procoptions then
  1093. begin
  1094. consume(_LOCATION);
  1095. locationstr:=cstringpattern;
  1096. consume(_CSTRING);
  1097. end
  1098. else
  1099. { I guess this needs a new message... (KB) }
  1100. Message(parser_e_paraloc_all_paras);
  1101. end
  1102. else
  1103. begin
  1104. if po_explicitparaloc in pd.procoptions then
  1105. { assign default locationstr, if none specified }
  1106. { and we've arguments with explicit paraloc }
  1107. locationstr:='D0';
  1108. end;
  1109. end;
  1110. end
  1111. else
  1112. begin
  1113. if (
  1114. parse_only and
  1115. not(is_interface(pd.struct))
  1116. ) or
  1117. (m_repeat_forward in current_settings.modeswitches) then
  1118. begin
  1119. consume(_COLON);
  1120. consume_all_until(_SEMICOLON);
  1121. end;
  1122. end;
  1123. if isclassmethod then
  1124. include(pd.procoptions,po_classmethod);
  1125. end;
  1126. end
  1127. else
  1128. begin
  1129. { recover }
  1130. consume(_COLON);
  1131. consume_all_until(_SEMICOLON);
  1132. end;
  1133. end;
  1134. _PROCEDURE :
  1135. begin
  1136. consume(_PROCEDURE);
  1137. if parse_proc_head(astruct,potype_procedure,pd) then
  1138. begin
  1139. { pd=nil when it is an interface mapping }
  1140. if assigned(pd) then
  1141. begin
  1142. pd.returndef:=voidtype;
  1143. if isclassmethod then
  1144. include(pd.procoptions,po_classmethod);
  1145. end;
  1146. end;
  1147. end;
  1148. _CONSTRUCTOR :
  1149. begin
  1150. consume(_CONSTRUCTOR);
  1151. if isclassmethod then
  1152. parse_proc_head(astruct,potype_class_constructor,pd)
  1153. else
  1154. parse_proc_head(astruct,potype_constructor,pd);
  1155. if not isclassmethod and
  1156. assigned(pd) and
  1157. assigned(pd.struct) then
  1158. begin
  1159. { Set return type, class constructors return the
  1160. created instance, object constructors return boolean }
  1161. if is_class(pd.struct) or
  1162. is_record(pd.struct) or
  1163. is_javaclass(pd.struct) then
  1164. pd.returndef:=pd.struct
  1165. else
  1166. if is_objectpascal_helper(pd.struct) then
  1167. pd.returndef:=tobjectdef(pd.struct).extendeddef
  1168. else
  1169. {$ifdef CPU64bitaddr}
  1170. pd.returndef:=bool64type;
  1171. {$else CPU64bitaddr}
  1172. pd.returndef:=bool32type;
  1173. {$endif CPU64bitaddr}
  1174. end
  1175. else
  1176. pd.returndef:=voidtype;
  1177. end;
  1178. _DESTRUCTOR :
  1179. begin
  1180. consume(_DESTRUCTOR);
  1181. if isclassmethod then
  1182. parse_proc_head(astruct,potype_class_destructor,pd)
  1183. else
  1184. parse_proc_head(astruct,potype_destructor,pd);
  1185. if assigned(pd) then
  1186. pd.returndef:=voidtype;
  1187. end;
  1188. else
  1189. if (token=_OPERATOR) or
  1190. (isclassmethod and (idtoken=_OPERATOR)) then
  1191. begin
  1192. { we need to set the block type to bt_body, so that operator names
  1193. like ">", "=>" or "<>" are parsed correctly instead of e.g.
  1194. _LSHARPBRACKET and _RSHARPBRACKET for "<>" }
  1195. old_block_type:=block_type;
  1196. block_type:=bt_body;
  1197. consume(_OPERATOR);
  1198. parse_proc_head(astruct,potype_operator,pd);
  1199. block_type:=old_block_type;
  1200. if assigned(pd) then
  1201. begin
  1202. { operators always need to be searched in all units (that
  1203. contain operators) }
  1204. include(pd.procoptions,po_overload);
  1205. pd.procsym.owner.includeoption(sto_has_operator);
  1206. if pd.parast.symtablelevel>normal_function_level then
  1207. Message(parser_e_no_local_operator);
  1208. if isclassmethod then
  1209. include(pd.procoptions,po_classmethod);
  1210. if token<>_ID then
  1211. begin
  1212. if not(m_result in current_settings.modeswitches) then
  1213. consume(_ID);
  1214. end
  1215. else
  1216. begin
  1217. pd.resultname:=stringdup(orgpattern);
  1218. consume(_ID);
  1219. end;
  1220. if not try_to_consume(_COLON) then
  1221. begin
  1222. consume(_COLON);
  1223. pd.returndef:=generrordef;
  1224. consume_all_until(_SEMICOLON);
  1225. end
  1226. else
  1227. begin
  1228. read_returndef(pd);
  1229. { check that class operators have either return type of structure or }
  1230. { at least one argument of that type }
  1231. if (po_classmethod in pd.procoptions) and
  1232. (pd.returndef <> pd.struct) then
  1233. begin
  1234. found:=false;
  1235. for i := 0 to pd.parast.SymList.Count - 1 do
  1236. if tparavarsym(pd.parast.SymList[i]).vardef=pd.struct then
  1237. begin
  1238. found:=true;
  1239. break;
  1240. end;
  1241. if not found then
  1242. if assigned(pd.struct) then
  1243. Message1(parser_e_at_least_one_argument_must_be_of_type,pd.struct.RttiName)
  1244. else
  1245. MessagePos(pd.fileinfo,type_e_type_id_expected);
  1246. end;
  1247. if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and
  1248. equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and
  1249. (pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then
  1250. message(parser_e_no_such_assignment)
  1251. else if not isoperatoracceptable(pd,optoken) then
  1252. Message(parser_e_overload_impossible);
  1253. end;
  1254. end
  1255. else
  1256. begin
  1257. { recover }
  1258. try_to_consume(_ID);
  1259. consume(_COLON);
  1260. consume_all_until(_SEMICOLON);
  1261. end;
  1262. end;
  1263. end;
  1264. { file types can't be function results }
  1265. if assigned(pd) and
  1266. (pd.returndef.typ=filedef) then
  1267. message(parser_e_illegal_function_result);
  1268. { support procedure proc stdcall export; }
  1269. if not(check_proc_directive(false)) then
  1270. begin
  1271. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1272. begin
  1273. message(parser_e_field_not_allowed_here);
  1274. consume_all_until(_SEMICOLON);
  1275. end;
  1276. consume(_SEMICOLON);
  1277. end;
  1278. result:=pd;
  1279. if locationstr<>'' then
  1280. begin
  1281. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1282. { I guess this needs a new message... (KB) }
  1283. message(parser_e_illegal_explicit_paraloc);
  1284. end;
  1285. end;
  1286. function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean): tprocdef;
  1287. var
  1288. oldparse_only: boolean;
  1289. begin
  1290. oldparse_only:=parse_only;
  1291. parse_only:=true;
  1292. result:=parse_proc_dec(is_classdef,astruct);
  1293. { this is for error recovery as well as forward }
  1294. { interface mappings, i.e. mapping to a method }
  1295. { which isn't declared yet }
  1296. if assigned(result) then
  1297. begin
  1298. parse_record_proc_directives(result);
  1299. { since records have no inheritance, don't allow non-static
  1300. class methods. Selphi does the same. }
  1301. if (result.proctypeoption<>potype_operator) and
  1302. is_classdef and
  1303. not (po_staticmethod in result.procoptions) then
  1304. MessagePos(result.fileinfo, parser_e_class_methods_only_static_in_records);
  1305. // we can't add hidden params here because record is not yet defined
  1306. // and therefore record size which has influence on paramter passing rules may change too
  1307. // look at record_dec to see where calling conventions are applied (issue #0021044)
  1308. handle_calling_convention(result,[hcc_check]);
  1309. { add definition to procsym }
  1310. proc_add_definition(result);
  1311. end;
  1312. maybe_parse_hint_directives(result);
  1313. parse_only:=oldparse_only;
  1314. end;
  1315. procedure insert_record_hidden_paras(astruct: trecorddef);
  1316. var
  1317. pd: tdef;
  1318. i: longint;
  1319. oldpos : tfileposinfo;
  1320. oldparse_only: boolean;
  1321. begin
  1322. // handle calling conventions of record methods
  1323. oldpos:=current_filepos;
  1324. oldparse_only:=parse_only;
  1325. parse_only:=true;
  1326. { don't keep track of procdefs in a separate list, because the
  1327. compiler may add additional procdefs (e.g. property wrappers for
  1328. the jvm backend) }
  1329. for i := 0 to astruct.symtable.deflist.count - 1 do
  1330. begin
  1331. pd:=tdef(astruct.symtable.deflist[i]);
  1332. if pd.typ<>procdef then
  1333. continue;
  1334. current_filepos:=tprocdef(pd).fileinfo;
  1335. handle_calling_convention(tprocdef(pd),[hcc_insert_hidden_paras]);
  1336. end;
  1337. parse_only:=oldparse_only;
  1338. current_filepos:=oldpos;
  1339. end;
  1340. {****************************************************************************
  1341. Procedure directive handlers
  1342. ****************************************************************************}
  1343. procedure pd_far(pd:tabstractprocdef);
  1344. begin
  1345. pd.declared_far;
  1346. end;
  1347. procedure pd_near(pd:tabstractprocdef);
  1348. begin
  1349. pd.declared_near;
  1350. end;
  1351. procedure pd_export(pd:tabstractprocdef);
  1352. begin
  1353. if pd.typ<>procdef then
  1354. internalerror(200304264);
  1355. if assigned(tprocdef(pd).struct) then
  1356. Message(parser_e_methods_dont_be_export);
  1357. if pd.parast.symtablelevel>normal_function_level then
  1358. Message(parser_e_dont_nest_export);
  1359. end;
  1360. procedure pd_forward(pd:tabstractprocdef);
  1361. begin
  1362. if pd.typ<>procdef then
  1363. internalerror(200304265);
  1364. tprocdef(pd).forwarddef:=true;
  1365. end;
  1366. procedure pd_alias(pd:tabstractprocdef);
  1367. begin
  1368. if pd.typ<>procdef then
  1369. internalerror(200304266);
  1370. consume(_COLON);
  1371. tprocdef(pd).aliasnames.insert(get_stringconst);
  1372. include(pd.procoptions,po_has_public_name);
  1373. end;
  1374. procedure pd_public(pd:tabstractprocdef);
  1375. begin
  1376. if pd.typ<>procdef then
  1377. internalerror(200304266);
  1378. if try_to_consume(_NAME) then
  1379. begin
  1380. tprocdef(pd).aliasnames.insert(get_stringconst);
  1381. include(pd.procoptions,po_has_public_name);
  1382. end;
  1383. end;
  1384. procedure pd_asmname(pd:tabstractprocdef);
  1385. begin
  1386. if pd.typ<>procdef then
  1387. internalerror(200304267);
  1388. if token=_CCHAR then
  1389. begin
  1390. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1391. consume(_CCHAR)
  1392. end
  1393. else
  1394. begin
  1395. tprocdef(pd).aliasnames.insert(target_info.Cprefix+cstringpattern);
  1396. consume(_CSTRING);
  1397. end;
  1398. { we don't need anything else }
  1399. tprocdef(pd).forwarddef:=false;
  1400. end;
  1401. procedure pd_internconst(pd:tabstractprocdef);
  1402. var v:Tconstexprint;
  1403. begin
  1404. if pd.typ<>procdef then
  1405. internalerror(200304268);
  1406. consume(_COLON);
  1407. v:=get_intconst;
  1408. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1409. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1410. else
  1411. Tprocdef(pd).extnumber:=longint(v.svalue);
  1412. end;
  1413. procedure pd_internproc(pd:tabstractprocdef);
  1414. var v:Tconstexprint;
  1415. begin
  1416. if pd.typ<>procdef then
  1417. internalerror(200304268);
  1418. consume(_COLON);
  1419. v:=get_intconst;
  1420. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1421. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1422. else
  1423. Tprocdef(pd).extnumber:=longint(v.svalue);
  1424. { the proc is defined }
  1425. tprocdef(pd).forwarddef:=false;
  1426. end;
  1427. procedure pd_interrupt(pd:tabstractprocdef);
  1428. begin
  1429. if pd.parast.symtablelevel>normal_function_level then
  1430. Message(parser_e_dont_nest_interrupt);
  1431. end;
  1432. procedure pd_abstract(pd:tabstractprocdef);
  1433. begin
  1434. if pd.typ<>procdef then
  1435. internalerror(200304269);
  1436. if is_objectpascal_helper(tprocdef(pd).struct) then
  1437. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_ABSTRACT].str);
  1438. if assigned(tprocdef(pd).struct) and
  1439. (oo_is_sealed in tprocdef(pd).struct.objectoptions) then
  1440. Message(parser_e_sealed_class_cannot_have_abstract_methods)
  1441. else if (po_virtualmethod in pd.procoptions) then
  1442. begin
  1443. include(pd.procoptions,po_abstractmethod);
  1444. { one more abstract method }
  1445. inc(tobjectdef(pd.owner.defowner).abstractcnt);
  1446. end
  1447. else
  1448. Message(parser_e_only_virtual_methods_abstract);
  1449. { the method is defined }
  1450. tprocdef(pd).forwarddef:=false;
  1451. end;
  1452. procedure pd_final(pd:tabstractprocdef);
  1453. begin
  1454. if pd.typ<>procdef then
  1455. internalerror(200910170);
  1456. if is_objectpascal_helper(tprocdef(pd).struct) and
  1457. (m_objfpc in current_settings.modeswitches) then
  1458. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_FINAL].str);
  1459. if (po_virtualmethod in pd.procoptions) or
  1460. (is_javaclass(tprocdef(pd).struct) and
  1461. (po_classmethod in pd.procoptions)) then
  1462. include(pd.procoptions,po_finalmethod)
  1463. else
  1464. Message(parser_e_only_virtual_methods_final);
  1465. end;
  1466. procedure pd_enumerator(pd:tabstractprocdef);
  1467. begin
  1468. if pd.typ<>procdef then
  1469. internalerror(200910250);
  1470. if (token = _ID) then
  1471. begin
  1472. if pattern='MOVENEXT' then
  1473. begin
  1474. if oo_has_enumerator_movenext in tprocdef(pd).struct.objectoptions then
  1475. message(parser_e_only_one_enumerator_movenext);
  1476. pd.calcparas;
  1477. if (pd.proctypeoption = potype_function) and is_boolean(pd.returndef) and
  1478. (pd.minparacount = 0) then
  1479. begin
  1480. include(tprocdef(pd).struct.objectoptions, oo_has_enumerator_movenext);
  1481. include(pd.procoptions,po_enumerator_movenext);
  1482. end
  1483. else
  1484. Message(parser_e_enumerator_movenext_is_not_valid)
  1485. end
  1486. else
  1487. Message1(parser_e_invalid_enumerator_identifier, pattern);
  1488. consume(token);
  1489. end
  1490. else
  1491. Message(parser_e_enumerator_identifier_required);
  1492. end;
  1493. procedure pd_virtual(pd:tabstractprocdef);
  1494. {$ifdef WITHDMT}
  1495. var
  1496. pt : tnode;
  1497. {$endif WITHDMT}
  1498. begin
  1499. if (not assigned(pd.owner.defowner) or
  1500. not is_java_class_or_interface(tdef(pd.owner.defowner))) and
  1501. (po_external in pd.procoptions) then
  1502. Message1(parser_e_proc_dir_conflict,'EXTERNAL');
  1503. if pd.typ<>procdef then
  1504. internalerror(2003042610);
  1505. if (pd.proctypeoption=potype_constructor) and
  1506. is_object(tprocdef(pd).struct) then
  1507. Message(parser_e_constructor_cannot_be_not_virtual);
  1508. if is_objectpascal_helper(tprocdef(pd).struct) and
  1509. (m_objfpc in current_settings.modeswitches) then
  1510. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_VIRTUAL].str);
  1511. {$ifdef WITHDMT}
  1512. if is_object(tprocdef(pd).struct) and
  1513. (token<>_SEMICOLON) then
  1514. begin
  1515. { any type of parameter is allowed here! }
  1516. pt:=comp_expr(true);
  1517. if is_constintnode(pt) then
  1518. begin
  1519. include(pd.procoptions,po_msgint);
  1520. pd.messageinf.i:=pt.value;
  1521. end
  1522. else
  1523. Message(parser_e_ill_msg_expr);
  1524. disposetree(pt);
  1525. end;
  1526. {$endif WITHDMT}
  1527. end;
  1528. procedure pd_dispid(pd:tabstractprocdef);
  1529. var pt:Tnode;
  1530. begin
  1531. if pd.typ<>procdef then
  1532. internalerror(200604301);
  1533. pt:=comp_expr(true,false);
  1534. if is_constintnode(pt) then
  1535. if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
  1536. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
  1537. else
  1538. Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
  1539. else
  1540. message(parser_e_dispid_must_be_ord_const);
  1541. pt.free;
  1542. end;
  1543. procedure pd_static(pd:tabstractprocdef);
  1544. begin
  1545. if pd.typ<>procdef then
  1546. internalerror(2013032001);
  1547. if not assigned(tprocdef(pd).struct) then
  1548. internalerror(2013032002);
  1549. include(tprocdef(pd).procsym.symoptions,sp_static);
  1550. { "static" is not allowed for operators or normal methods (except in objects) }
  1551. if (pd.proctypeoption=potype_operator) or
  1552. (
  1553. not (po_classmethod in pd.procoptions) and
  1554. not is_object(tprocdef(pd).struct)
  1555. )
  1556. then
  1557. Message1(parser_e_dir_not_allowed,arraytokeninfo[_STATIC].str);
  1558. include(pd.procoptions,po_staticmethod);
  1559. end;
  1560. procedure pd_override(pd:tabstractprocdef);
  1561. begin
  1562. if pd.typ<>procdef then
  1563. internalerror(2003042611);
  1564. if is_objectpascal_helper(tprocdef(pd).struct) then
  1565. begin
  1566. if m_objfpc in current_settings.modeswitches then
  1567. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_OVERRIDE].str)
  1568. end
  1569. else if not(is_class_or_interface_or_objc_or_java(tprocdef(pd).struct)) then
  1570. Message(parser_e_no_object_override)
  1571. else if is_objccategory(tprocdef(pd).struct) then
  1572. Message(parser_e_no_category_override)
  1573. else if (po_external in pd.procoptions) and
  1574. not is_objc_class_or_protocol(tprocdef(pd).struct) and
  1575. not is_cppclass(tprocdef(pd).struct) and
  1576. not is_java_class_or_interface(tprocdef(pd).struct) then
  1577. Message1(parser_e_proc_dir_conflict,'OVERRIDE');
  1578. end;
  1579. procedure pd_overload(pd:tabstractprocdef);
  1580. begin
  1581. if pd.typ<>procdef then
  1582. internalerror(2003042612);
  1583. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1584. end;
  1585. procedure pd_message(pd:tabstractprocdef);
  1586. var
  1587. pt : tnode;
  1588. paracnt : longint;
  1589. begin
  1590. if pd.typ<>procdef then
  1591. internalerror(2003042613);
  1592. if is_objectpascal_helper(tprocdef(pd).struct) then
  1593. begin
  1594. if m_objfpc in current_settings.modeswitches then
  1595. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_MESSAGE].str);
  1596. end
  1597. else
  1598. if not is_class(tprocdef(pd).struct) and
  1599. not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1600. Message(parser_e_msg_only_for_classes);
  1601. if ([po_msgstr,po_msgint]*pd.procoptions)<>[] then
  1602. Message(parser_e_multiple_messages);
  1603. { check parameter type }
  1604. if not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1605. begin
  1606. if po_external in pd.procoptions then
  1607. Message1(parser_e_proc_dir_conflict,'MESSAGE');
  1608. paracnt:=0;
  1609. pd.parast.SymList.ForEachCall(@check_msg_para,@paracnt);
  1610. if paracnt<>1 then
  1611. Message(parser_e_ill_msg_param);
  1612. end;
  1613. pt:=comp_expr(true,false);
  1614. { message is 1-character long }
  1615. if is_constcharnode(pt) then
  1616. begin
  1617. include(pd.procoptions,po_msgstr);
  1618. tprocdef(pd).messageinf.str:=stringdup(chr(byte(tordconstnode(pt).value.uvalue and $FF)));
  1619. end
  1620. else if pt.nodetype=stringconstn then
  1621. begin
  1622. include(pd.procoptions,po_msgstr);
  1623. if (tstringconstnode(pt).len>255) then
  1624. Message(parser_e_message_string_too_long);
  1625. tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
  1626. end
  1627. else
  1628. if is_constintnode(pt) and
  1629. (is_class(tprocdef(pd).struct) or
  1630. is_objectpascal_helper(tprocdef(pd).struct)) then
  1631. begin
  1632. include(pd.procoptions,po_msgint);
  1633. if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
  1634. (Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
  1635. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(Tprocdef(pd).messageinf.i)),tostr(high(Tprocdef(pd).messageinf.i)))
  1636. else
  1637. Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
  1638. end
  1639. else
  1640. Message(parser_e_ill_msg_expr);
  1641. { check whether the selector name is valid in case of Objective-C }
  1642. if (po_msgstr in pd.procoptions) and
  1643. is_objc_class_or_protocol(tprocdef(pd).struct) and
  1644. not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
  1645. Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
  1646. pt.free;
  1647. end;
  1648. procedure pd_reintroduce(pd:tabstractprocdef);
  1649. begin
  1650. if pd.typ<>procdef then
  1651. internalerror(200401211);
  1652. if is_objectpascal_helper(tprocdef(pd).struct) then
  1653. begin
  1654. if m_objfpc in current_settings.modeswitches then
  1655. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_REINTRODUCE].str);
  1656. end
  1657. else
  1658. if not(is_class_or_interface_or_object(tprocdef(pd).struct)) and
  1659. not(is_objccategory(tprocdef(pd).struct)) and
  1660. not(is_javaclass(tprocdef(pd).struct)) then
  1661. Message(parser_e_no_object_reintroduce);
  1662. end;
  1663. procedure pd_syscall(pd:tabstractprocdef);
  1664. {$if defined(powerpc) or defined(m68k) or defined(i386)}
  1665. var
  1666. vs : tparavarsym;
  1667. sym : tsym;
  1668. symtable : TSymtable;
  1669. v: Tconstexprint;
  1670. {$endif defined(powerpc) or defined(m68k) or defined(i386)}
  1671. begin
  1672. if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
  1673. internalerror(2003042614);
  1674. tprocdef(pd).forwarddef:=false;
  1675. {$ifdef m68k}
  1676. if target_info.system in [system_m68k_amiga] then
  1677. begin
  1678. include(pd.procoptions,po_syscall_legacy);
  1679. if consume_sym(sym,symtable) then
  1680. begin
  1681. if (sym.typ=staticvarsym) and
  1682. (
  1683. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1684. is_32bitint(tabstractvarsym(sym).vardef)
  1685. ) then
  1686. begin
  1687. include(pd.procoptions,po_syscall_has_libsym);
  1688. tcpuprocdef(pd).libsym:=sym;
  1689. if po_syscall_legacy in tprocdef(pd).procoptions then
  1690. begin
  1691. vs:=cparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1692. paramanager.parseparaloc(vs,'A6');
  1693. pd.parast.insert(vs);
  1694. end
  1695. end
  1696. else
  1697. Message(parser_e_32bitint_or_pointer_variable_expected);
  1698. end;
  1699. paramanager.create_funcretloc_info(pd,calleeside);
  1700. paramanager.create_funcretloc_info(pd,callerside);
  1701. v:=get_intconst;
  1702. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1703. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(Tprocdef(pd).extnumber)),tostr(high(Tprocdef(pd).extnumber)))
  1704. else
  1705. Tprocdef(pd).extnumber:=v.uvalue;
  1706. end;
  1707. {$endif m68k}
  1708. {$ifdef powerpc}
  1709. if target_info.system = system_powerpc_amiga then
  1710. begin
  1711. include(pd.procoptions,po_syscall_basesysv);
  1712. if consume_sym(sym,symtable) then
  1713. begin
  1714. if (sym.typ=staticvarsym) and
  1715. (
  1716. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1717. is_32bitint(tabstractvarsym(sym).vardef)
  1718. ) then
  1719. begin
  1720. include(pd.procoptions,po_syscall_has_libsym);
  1721. tcpuprocdef(pd).libsym:=sym;
  1722. vs:=cparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1723. pd.parast.insert(vs);
  1724. end
  1725. else
  1726. Message(parser_e_32bitint_or_pointer_variable_expected);
  1727. end;
  1728. paramanager.create_funcretloc_info(pd,calleeside);
  1729. paramanager.create_funcretloc_info(pd,callerside);
  1730. v:=get_intconst;
  1731. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1732. message(parser_e_range_check_error)
  1733. else
  1734. Tprocdef(pd).extnumber:=v.uvalue;
  1735. end else
  1736. if target_info.system = system_powerpc_morphos then
  1737. begin
  1738. if idtoken=_LEGACY then
  1739. begin
  1740. consume(_LEGACY);
  1741. include(pd.procoptions,po_syscall_legacy);
  1742. end
  1743. else if idtoken=_SYSV then
  1744. begin
  1745. consume(_SYSV);
  1746. include(pd.procoptions,po_syscall_sysv);
  1747. end
  1748. else if idtoken=_BASESYSV then
  1749. begin
  1750. consume(_BASESYSV);
  1751. include(pd.procoptions,po_syscall_basesysv);
  1752. end
  1753. else if idtoken=_SYSVBASE then
  1754. begin
  1755. consume(_SYSVBASE);
  1756. include(pd.procoptions,po_syscall_sysvbase);
  1757. end
  1758. else if idtoken=_R12BASE then
  1759. begin
  1760. consume(_R12BASE);
  1761. include(pd.procoptions,po_syscall_r12base);
  1762. end
  1763. else
  1764. if syscall_convention='LEGACY' then
  1765. include(pd.procoptions,po_syscall_legacy)
  1766. else if syscall_convention='SYSV' then
  1767. include(pd.procoptions,po_syscall_sysv)
  1768. else if syscall_convention='BASESYSV' then
  1769. include(pd.procoptions,po_syscall_basesysv)
  1770. else if syscall_convention='SYSVBASE' then
  1771. include(pd.procoptions,po_syscall_sysvbase)
  1772. else if syscall_convention='R12BASE' then
  1773. include(pd.procoptions,po_syscall_r12base)
  1774. else
  1775. internalerror(2005010404);
  1776. if consume_sym(sym,symtable) then
  1777. begin
  1778. if (sym.typ=staticvarsym) and
  1779. (
  1780. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1781. is_32bitint(tabstractvarsym(sym).vardef)
  1782. ) then
  1783. begin
  1784. include(pd.procoptions,po_syscall_has_libsym);
  1785. tcpuprocdef(pd).libsym:=sym;
  1786. if po_syscall_legacy in tprocdef(pd).procoptions then
  1787. begin
  1788. vs:=cparavarsym.create('$syscalllib',paranr_syscall_legacy,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1789. paramanager.parseparaloc(vs,'A6');
  1790. pd.parast.insert(vs);
  1791. end
  1792. else if po_syscall_sysv in tprocdef(pd).procoptions then
  1793. begin
  1794. { Nothing to be done for sysv here for now, but this might change }
  1795. end
  1796. else if po_syscall_basesysv in tprocdef(pd).procoptions then
  1797. begin
  1798. vs:=cparavarsym.create('$syscalllib',paranr_syscall_basesysv,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1799. pd.parast.insert(vs);
  1800. end
  1801. else if po_syscall_sysvbase in tprocdef(pd).procoptions then
  1802. begin
  1803. vs:=cparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1804. pd.parast.insert(vs);
  1805. end
  1806. else if po_syscall_r12base in tprocdef(pd).procoptions then
  1807. begin
  1808. vs:=cparavarsym.create('$syscalllib',paranr_syscall_r12base,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para,vo_has_explicit_paraloc]);
  1809. paramanager.parseparaloc(vs,'R12');
  1810. pd.parast.insert(vs);
  1811. end
  1812. else
  1813. internalerror(2005010501);
  1814. end
  1815. else
  1816. Message(parser_e_32bitint_or_pointer_variable_expected);
  1817. end;
  1818. paramanager.create_funcretloc_info(pd,calleeside);
  1819. paramanager.create_funcretloc_info(pd,callerside);
  1820. v:=get_intconst;
  1821. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1822. message(parser_e_range_check_error)
  1823. else
  1824. Tprocdef(pd).extnumber:=v.uvalue;
  1825. end;
  1826. {$endif powerpc}
  1827. {$ifdef i386}
  1828. if target_info.system = system_i386_aros then
  1829. begin
  1830. include(pd.procoptions,po_syscall_sysvbase);
  1831. if consume_sym(sym,symtable) then
  1832. begin
  1833. if (sym.typ=staticvarsym) and
  1834. (
  1835. (tabstractvarsym(sym).vardef.typ=pointerdef) or
  1836. is_32bitint(tabstractvarsym(sym).vardef)
  1837. ) then
  1838. begin
  1839. include(pd.procoptions,po_syscall_has_libsym);
  1840. tcpuprocdef(pd).libsym:=sym;
  1841. vs:=cparavarsym.create('$syscalllib',paranr_syscall_sysvbase,vs_value,tabstractvarsym(sym).vardef,[vo_is_syscall_lib,vo_is_hidden_para]);
  1842. pd.parast.insert(vs);
  1843. end
  1844. else
  1845. Message(parser_e_32bitint_or_pointer_variable_expected);
  1846. end;
  1847. paramanager.create_funcretloc_info(pd,calleeside);
  1848. paramanager.create_funcretloc_info(pd,callerside);
  1849. v:=get_intconst;
  1850. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  1851. message(parser_e_range_check_error)
  1852. else
  1853. Tprocdef(pd).extnumber:=v.uvalue * 4; { sizeof Pointer for the target }
  1854. end;
  1855. {$endif}
  1856. end;
  1857. procedure pd_external(pd:tabstractprocdef);
  1858. {
  1859. If import_dll=nil the procedure is assumed to be in another
  1860. object file. In that object file it should have the name to
  1861. which import_name is pointing to. Otherwise, the procedure is
  1862. assumed to be in the DLL to which import_dll is pointing to. In
  1863. that case either import_nr<>0 or import_name<>nil is true, so
  1864. the procedure is either imported by number or by name. (DM)
  1865. }
  1866. var
  1867. hs : string;
  1868. v:Tconstexprint;
  1869. is_java_external: boolean;
  1870. begin
  1871. if pd.typ<>procdef then
  1872. internalerror(2003042615);
  1873. { Allow specifying a separate external name for methods in external Java
  1874. because its identifier naming constraints are laxer than FPC's
  1875. (e.g., case sensitive).
  1876. Limitation: only allows specifying the symbol name and not the package name,
  1877. and only for external classes/interfaces }
  1878. is_java_external:=
  1879. (pd.typ=procdef) and
  1880. is_java_class_or_interface(tdef(pd.owner.defowner)) and
  1881. (oo_is_external in tobjectdef(pd.owner.defowner).objectoptions);
  1882. with tprocdef(pd) do
  1883. begin
  1884. forwarddef:=false;
  1885. { forbid local external procedures }
  1886. if parast.symtablelevel>normal_function_level then
  1887. Message(parser_e_no_local_proc_external);
  1888. { If the procedure should be imported from a DLL, a constant string follows.
  1889. This isn't really correct, an contant string expression follows
  1890. so we check if an semicolon follows, else a string constant have to
  1891. follow (FK) }
  1892. if not is_java_external and
  1893. not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1894. begin
  1895. { Always add library prefix and suffix to create an uniform name }
  1896. hs:=get_stringconst;
  1897. if ExtractFileExt(hs)='' then
  1898. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  1899. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  1900. hs:=target_info.sharedlibprefix+hs;
  1901. { the JVM expects java/lang/Object rather than java.lang.Object }
  1902. if target_info.system in systems_jvm then
  1903. Replace(hs,'.','/');
  1904. import_dll:=stringdup(hs);
  1905. include(procoptions,po_has_importdll);
  1906. if (idtoken=_NAME) then
  1907. begin
  1908. consume(_NAME);
  1909. import_name:=stringdup(get_stringconst);
  1910. include(procoptions,po_has_importname);
  1911. if import_name^='' then
  1912. message(parser_e_empty_import_name);
  1913. end;
  1914. if (idtoken=_INDEX) then
  1915. begin
  1916. {After the word index follows the index number in the DLL.}
  1917. consume(_INDEX);
  1918. v:=get_intconst;
  1919. if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
  1920. message(parser_e_range_check_error)
  1921. else
  1922. import_nr:=longint(v.svalue);
  1923. end;
  1924. { default is to used the realname of the procedure }
  1925. if (import_nr=0) and not assigned(import_name) then
  1926. begin
  1927. import_name:=stringdup(procsym.realname);
  1928. include(procoptions,po_has_importname);
  1929. end;
  1930. end
  1931. else
  1932. begin
  1933. if (idtoken=_NAME) or
  1934. is_java_external then
  1935. begin
  1936. consume(_NAME);
  1937. import_name:=stringdup(get_stringconst);
  1938. include(procoptions,po_has_importname);
  1939. if import_name^='' then
  1940. message(parser_e_empty_import_name);
  1941. end;
  1942. end;
  1943. end;
  1944. end;
  1945. procedure pd_weakexternal(pd:tabstractprocdef);
  1946. begin
  1947. if not(target_info.system in systems_weak_linking) then
  1948. message(parser_e_weak_external_not_supported)
  1949. else
  1950. pd_external(pd);
  1951. end;
  1952. procedure pd_winapi(pd:tabstractprocdef);
  1953. begin
  1954. if not(target_info.system in systems_wince) then
  1955. pd.proccalloption:=pocall_cdecl
  1956. else
  1957. pd.proccalloption:=pocall_stdcall;
  1958. end;
  1959. type
  1960. pd_handler=procedure(pd:tabstractprocdef);
  1961. proc_dir_rec=record
  1962. idtok : ttoken;
  1963. pd_flags : tpdflags;
  1964. handler : pd_handler;
  1965. pocall : tproccalloption;
  1966. pooption : tprocoptions;
  1967. mutexclpocall : tproccalloptions;
  1968. mutexclpotype : tproctypeoptions;
  1969. mutexclpo : tprocoptions;
  1970. end;
  1971. const
  1972. {Should contain the number of procedure directives we support.}
  1973. num_proc_directives=45;
  1974. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1975. (
  1976. (
  1977. idtok:_ABSTRACT;
  1978. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  1979. handler : @pd_abstract;
  1980. pocall : pocall_none;
  1981. pooption : [po_abstractmethod];
  1982. mutexclpocall : [pocall_internproc];
  1983. mutexclpotype : [];
  1984. mutexclpo : [po_exports,po_interrupt,po_inline]
  1985. ),(
  1986. idtok:_ALIAS;
  1987. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1988. handler : @pd_alias;
  1989. pocall : pocall_none;
  1990. pooption : [];
  1991. mutexclpocall : [];
  1992. mutexclpotype : [];
  1993. mutexclpo : [po_external,po_inline]
  1994. ),(
  1995. idtok:_ASMNAME;
  1996. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1997. handler : @pd_asmname;
  1998. pocall : pocall_cdecl;
  1999. pooption : [po_external];
  2000. mutexclpocall : [pocall_internproc];
  2001. mutexclpotype : [];
  2002. mutexclpo : [po_external,po_inline]
  2003. ),(
  2004. idtok:_ASSEMBLER;
  2005. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2006. handler : nil;
  2007. pocall : pocall_none;
  2008. pooption : [po_assembler];
  2009. mutexclpocall : [];
  2010. mutexclpotype : [];
  2011. mutexclpo : [po_external]
  2012. ),(
  2013. idtok:_C; {same as cdecl for mode mac}
  2014. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2015. handler : nil;
  2016. pocall : pocall_cdecl;
  2017. pooption : [];
  2018. mutexclpocall : [];
  2019. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2020. mutexclpo : [po_assembler,po_external]
  2021. ),(
  2022. idtok:_CDECL;
  2023. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2024. handler : nil;
  2025. pocall : pocall_cdecl;
  2026. pooption : [];
  2027. mutexclpocall : [];
  2028. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2029. mutexclpo : [po_assembler,po_external]
  2030. ),(
  2031. idtok:_DISPID;
  2032. pd_flags : [pd_dispinterface];
  2033. handler : @pd_dispid;
  2034. pocall : pocall_none;
  2035. pooption : [po_dispid];
  2036. mutexclpocall : [pocall_internproc];
  2037. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2038. mutexclpo : [po_interrupt,po_external,po_inline]
  2039. ),(
  2040. idtok:_DYNAMIC;
  2041. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord];
  2042. handler : @pd_virtual;
  2043. pocall : pocall_none;
  2044. pooption : [po_virtualmethod];
  2045. mutexclpocall : [pocall_internproc];
  2046. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2047. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  2048. ),(
  2049. idtok:_EXPORT;
  2050. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf,pd_notrecord,pd_nothelper];
  2051. handler : @pd_export;
  2052. pocall : pocall_none;
  2053. pooption : [po_exports,po_global];
  2054. mutexclpocall : [pocall_internproc];
  2055. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2056. mutexclpo : [po_external,po_interrupt,po_inline]
  2057. ),(
  2058. idtok:_EXTERNAL;
  2059. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper,pd_javaclass,pd_intfjava];
  2060. handler : @pd_external;
  2061. pocall : pocall_none;
  2062. pooption : [po_external];
  2063. mutexclpocall : [pocall_syscall];
  2064. { allowed for external cpp classes }
  2065. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2066. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2067. ),(
  2068. idtok:_FAR;
  2069. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2070. handler : @pd_far;
  2071. pocall : pocall_none;
  2072. pooption : [];
  2073. mutexclpocall : [pocall_internproc];
  2074. mutexclpotype : [];
  2075. mutexclpo : [po_inline]
  2076. ),(
  2077. idtok:_FAR16;
  2078. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject,pd_notrecord,pd_nothelper];
  2079. handler : nil;
  2080. pocall : pocall_far16;
  2081. pooption : [];
  2082. mutexclpocall : [];
  2083. mutexclpotype : [];
  2084. mutexclpo : [po_external]
  2085. ),(
  2086. idtok:_FINAL;
  2087. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2088. handler : @pd_final;
  2089. pocall : pocall_none;
  2090. pooption : [po_finalmethod];
  2091. mutexclpocall : [pocall_internproc];
  2092. mutexclpotype : [];
  2093. mutexclpo : [po_exports,po_interrupt,po_inline]
  2094. ),(
  2095. idtok:_FORWARD;
  2096. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2097. handler : @pd_forward;
  2098. pocall : pocall_none;
  2099. pooption : [];
  2100. mutexclpocall : [pocall_internproc];
  2101. mutexclpotype : [];
  2102. mutexclpo : [po_external,po_inline]
  2103. ),(
  2104. idtok:_OLDFPCCALL;
  2105. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2106. handler : nil;
  2107. pocall : pocall_oldfpccall;
  2108. pooption : [];
  2109. mutexclpocall : [];
  2110. mutexclpotype : [];
  2111. mutexclpo : []
  2112. ),(
  2113. idtok:_INLINE;
  2114. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2115. handler : nil;
  2116. pocall : pocall_none;
  2117. pooption : [po_inline];
  2118. mutexclpocall : [pocall_safecall];
  2119. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2120. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod,po_iocheck]
  2121. ),(
  2122. idtok:_INTERNCONST;
  2123. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2124. handler : @pd_internconst;
  2125. pocall : pocall_none;
  2126. pooption : [po_internconst];
  2127. mutexclpocall : [];
  2128. mutexclpotype : [potype_operator];
  2129. mutexclpo : []
  2130. ),(
  2131. idtok:_INTERNPROC;
  2132. pd_flags : [pd_interface,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2133. handler : @pd_internproc;
  2134. pocall : pocall_internproc;
  2135. pooption : [];
  2136. mutexclpocall : [];
  2137. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2138. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  2139. ),(
  2140. idtok:_INTERRUPT;
  2141. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2142. handler : @pd_interrupt;
  2143. pocall : pocall_oldfpccall;
  2144. pooption : [po_interrupt];
  2145. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,pocall_mwpascal,
  2146. pocall_pascal,pocall_far16,pocall_oldfpccall];
  2147. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2148. mutexclpo : [po_external,po_inline]
  2149. ),(
  2150. idtok:_IOCHECK;
  2151. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2152. handler : nil;
  2153. pocall : pocall_none;
  2154. pooption : [po_iocheck];
  2155. mutexclpocall : [pocall_internproc];
  2156. mutexclpotype : [];
  2157. mutexclpo : [po_external]
  2158. ),(
  2159. idtok:_LOCAL;
  2160. pd_flags : [pd_implemen,pd_body];
  2161. handler : nil;
  2162. pocall : pocall_none;
  2163. pooption : [po_kylixlocal];
  2164. mutexclpocall : [pocall_internproc,pocall_far16];
  2165. mutexclpotype : [];
  2166. mutexclpo : [po_external,po_exports]
  2167. ),(
  2168. idtok:_MESSAGE;
  2169. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_objcprot,pd_notrecord];
  2170. handler : @pd_message;
  2171. pocall : pocall_none;
  2172. pooption : []; { can be po_msgstr or po_msgint }
  2173. mutexclpocall : [pocall_internproc];
  2174. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2175. mutexclpo : [po_interrupt,po_inline]
  2176. ),(
  2177. idtok:_MWPASCAL;
  2178. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2179. handler : nil;
  2180. pocall : pocall_mwpascal;
  2181. pooption : [];
  2182. mutexclpocall : [];
  2183. mutexclpotype : [];
  2184. mutexclpo : []
  2185. ),(
  2186. idtok:_NEAR;
  2187. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf,pd_notrecord,pd_nothelper];
  2188. handler : @pd_near;
  2189. pocall : pocall_none;
  2190. pooption : [];
  2191. mutexclpocall : [pocall_internproc];
  2192. mutexclpotype : [];
  2193. mutexclpo : []
  2194. ),(
  2195. idtok:_NORETURN;
  2196. pd_flags : [pd_implemen,pd_interface,pd_body,pd_notobjintf];
  2197. handler : nil;
  2198. pocall : pocall_none;
  2199. pooption : [po_noreturn];
  2200. mutexclpocall : [];
  2201. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2202. mutexclpo : [po_interrupt,po_virtualmethod,po_iocheck]
  2203. ),(
  2204. idtok:_NOSTACKFRAME;
  2205. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  2206. handler : nil;
  2207. pocall : pocall_none;
  2208. pooption : [po_nostackframe];
  2209. mutexclpocall : [pocall_internproc];
  2210. mutexclpotype : [];
  2211. mutexclpo : []
  2212. ),(
  2213. idtok:_OVERLOAD;
  2214. pd_flags : [pd_implemen,pd_interface,pd_body,pd_javaclass,pd_intfjava,pd_objcclass,pd_objcprot];
  2215. handler : @pd_overload;
  2216. pocall : pocall_none;
  2217. pooption : [po_overload];
  2218. mutexclpocall : [pocall_internproc];
  2219. mutexclpotype : [];
  2220. mutexclpo : []
  2221. ),(
  2222. idtok:_OVERRIDE;
  2223. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_javaclass,pd_intfjava,pd_notrecord];
  2224. handler : @pd_override;
  2225. pocall : pocall_none;
  2226. pooption : [po_overridingmethod,po_virtualmethod];
  2227. mutexclpocall : [pocall_internproc];
  2228. mutexclpotype : [];
  2229. mutexclpo : [po_exports,po_interrupt,po_virtualmethod,po_inline]
  2230. ),(
  2231. idtok:_PASCAL;
  2232. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2233. handler : nil;
  2234. pocall : pocall_pascal;
  2235. pooption : [];
  2236. mutexclpocall : [];
  2237. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2238. mutexclpo : [po_external]
  2239. ),(
  2240. idtok:_PUBLIC;
  2241. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2242. handler : @pd_public;
  2243. pocall : pocall_none;
  2244. pooption : [po_public,po_global];
  2245. mutexclpocall : [pocall_internproc];
  2246. mutexclpotype : [];
  2247. mutexclpo : [po_external,po_inline]
  2248. ),(
  2249. idtok:_REGISTER;
  2250. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2251. handler : nil;
  2252. pocall : pocall_register;
  2253. pooption : [];
  2254. mutexclpocall : [];
  2255. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2256. mutexclpo : [po_external]
  2257. ),(
  2258. idtok:_REINTRODUCE;
  2259. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_notrecord,pd_javaclass];
  2260. handler : @pd_reintroduce;
  2261. pocall : pocall_none;
  2262. pooption : [po_reintroduce];
  2263. mutexclpocall : [pocall_internproc];
  2264. mutexclpotype : [];
  2265. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  2266. ),(
  2267. idtok:_SAFECALL;
  2268. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2269. handler : nil;
  2270. pocall : pocall_safecall;
  2271. pooption : [];
  2272. mutexclpocall : [];
  2273. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2274. mutexclpo : [po_external]
  2275. ),(
  2276. idtok:_SOFTFLOAT;
  2277. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2278. handler : nil;
  2279. pocall : pocall_softfloat;
  2280. pooption : [];
  2281. mutexclpocall : [];
  2282. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2283. { it's available with po_external because the libgcc floating point routines on the arm
  2284. uses this calling convention }
  2285. mutexclpo : []
  2286. ),(
  2287. idtok:_STATIC;
  2288. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_record,pd_javaclass,pd_notobjintf];
  2289. handler : @pd_static;
  2290. pocall : pocall_none;
  2291. pooption : [po_staticmethod];
  2292. mutexclpocall : [pocall_internproc];
  2293. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2294. mutexclpo : [po_interrupt,po_exports]
  2295. ),(
  2296. idtok:_STDCALL;
  2297. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2298. handler : nil;
  2299. pocall : pocall_stdcall;
  2300. pooption : [];
  2301. mutexclpocall : [];
  2302. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2303. mutexclpo : [po_external]
  2304. ),(
  2305. idtok:_SYSCALL;
  2306. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  2307. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  2308. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  2309. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  2310. handler : @pd_syscall;
  2311. pocall : pocall_syscall;
  2312. pooption : [];
  2313. mutexclpocall : [];
  2314. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2315. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  2316. ),(
  2317. idtok:_VIRTUAL;
  2318. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2319. handler : @pd_virtual;
  2320. pocall : pocall_none;
  2321. pooption : [po_virtualmethod];
  2322. mutexclpocall : [pocall_internproc];
  2323. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2324. mutexclpo : [po_interrupt,po_exports,po_overridingmethod,po_inline]
  2325. ),(
  2326. idtok:_CPPDECL;
  2327. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2328. handler : nil;
  2329. pocall : pocall_cppdecl;
  2330. pooption : [];
  2331. mutexclpocall : [];
  2332. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2333. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  2334. ),(
  2335. idtok:_VARARGS;
  2336. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass,pd_objcprot];
  2337. handler : nil;
  2338. pocall : pocall_none;
  2339. pooption : [po_varargs];
  2340. mutexclpocall : [pocall_internproc,pocall_register,
  2341. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  2342. mutexclpotype : [];
  2343. mutexclpo : [po_assembler,po_interrupt,po_inline]
  2344. ),(
  2345. idtok:_COMPILERPROC;
  2346. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2347. handler : nil;
  2348. pocall : pocall_none;
  2349. pooption : [po_compilerproc];
  2350. mutexclpocall : [];
  2351. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2352. mutexclpo : [po_interrupt]
  2353. ),(
  2354. idtok:_WEAKEXTERNAL;
  2355. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper];
  2356. handler : @pd_weakexternal;
  2357. pocall : pocall_none;
  2358. { mark it both external and weak external, so we don't have to
  2359. adapt all code for external symbols to also check for weak external
  2360. }
  2361. pooption : [po_external,po_weakexternal];
  2362. mutexclpocall : [pocall_internproc,pocall_syscall];
  2363. { allowed for external cpp classes }
  2364. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2365. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2366. ),(
  2367. idtok:_WINAPI;
  2368. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2369. handler : @pd_winapi;
  2370. pocall : pocall_none;
  2371. pooption : [];
  2372. mutexclpocall : [pocall_stdcall,pocall_cdecl];
  2373. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2374. mutexclpo : [po_external]
  2375. ),(
  2376. idtok:_ENUMERATOR;
  2377. pd_flags : [pd_interface,pd_object,pd_record];
  2378. handler : @pd_enumerator;
  2379. pocall : pocall_none;
  2380. pooption : [];
  2381. mutexclpocall : [pocall_internproc];
  2382. mutexclpotype : [];
  2383. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2384. ),(
  2385. idtok:_RTLPROC;
  2386. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2387. handler : nil;
  2388. pocall : pocall_none;
  2389. pooption : [po_rtlproc];
  2390. mutexclpocall : [];
  2391. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2392. mutexclpo : [po_interrupt]
  2393. )
  2394. );
  2395. function check_proc_directive(isprocvar:boolean):boolean;
  2396. var
  2397. i : longint;
  2398. begin
  2399. result:=false;
  2400. for i:=1 to num_proc_directives do
  2401. if proc_direcdata[i].idtok=idtoken then
  2402. begin
  2403. if ((not isprocvar) or
  2404. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2405. { don't eat a public directive in classes }
  2406. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2407. result:=true;
  2408. exit;
  2409. end;
  2410. end;
  2411. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2412. {
  2413. Parse the procedure directive, returns true if a correct directive is found
  2414. }
  2415. var
  2416. p : longint;
  2417. found : boolean;
  2418. name : TIDString;
  2419. begin
  2420. parse_proc_direc:=false;
  2421. name:=tokeninfo^[idtoken].str;
  2422. found:=false;
  2423. { Hint directive? Then exit immediatly }
  2424. if (m_hintdirective in current_settings.modeswitches) then
  2425. begin
  2426. case idtoken of
  2427. _LIBRARY,
  2428. _PLATFORM,
  2429. _UNIMPLEMENTED,
  2430. _EXPERIMENTAL,
  2431. _DEPRECATED :
  2432. if (m_delphi in current_settings.modeswitches) and (pd.typ=procdef) then
  2433. begin
  2434. maybe_parse_hint_directives(tprocdef(pd));
  2435. { could the new token still be a directive? }
  2436. if token<>_ID then
  2437. exit;
  2438. name:=tokeninfo^[idtoken].str;
  2439. end
  2440. else
  2441. exit;
  2442. end;
  2443. end;
  2444. { C directive is MacPas only, because it breaks too much existing code
  2445. on other platforms (PFV) }
  2446. if (idtoken=_C) and
  2447. not(m_mac in current_settings.modeswitches) then
  2448. exit;
  2449. { retrieve data for directive if found }
  2450. for p:=1 to num_proc_directives do
  2451. if proc_direcdata[p].idtok=idtoken then
  2452. begin
  2453. found:=true;
  2454. break;
  2455. end;
  2456. { Check if the procedure directive is known }
  2457. if not found then
  2458. begin
  2459. { parsing a procvar type the name can be any
  2460. next variable !! }
  2461. if ((pdflags * [pd_procvar,pd_object,pd_record,pd_objcclass,pd_objcprot])=[]) and
  2462. not(idtoken=_PROPERTY) then
  2463. Message1(parser_w_unknown_proc_directive_ignored,pattern);
  2464. exit;
  2465. end;
  2466. { check if method and directive not for object, like public.
  2467. This needs to be checked also for procvars }
  2468. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2469. (symtablestack.top.symtabletype=ObjectSymtable) and
  2470. { directive allowed for cpp classes? }
  2471. not((pd_cppobject in proc_direcdata[p].pd_flags) and is_cppclass(tdef(symtablestack.top.defowner))) and
  2472. not((pd_javaclass in proc_direcdata[p].pd_flags) and is_javaclass(tdef(symtablestack.top.defowner))) and
  2473. not((pd_intfjava in proc_direcdata[p].pd_flags) and is_javainterface(tdef(symtablestack.top.defowner))) then
  2474. exit;
  2475. if (pd_notrecord in proc_direcdata[p].pd_flags) and
  2476. (symtablestack.top.symtabletype=recordsymtable) then
  2477. exit;
  2478. { check if method and directive not for java class }
  2479. if not(pd_javaclass in proc_direcdata[p].pd_flags) and
  2480. is_javaclass(tdef(symtablestack.top.defowner)) then
  2481. exit;
  2482. { check if method and directive not for java interface }
  2483. if not(pd_intfjava in proc_direcdata[p].pd_flags) and
  2484. is_javainterface(tdef(symtablestack.top.defowner)) then
  2485. exit;
  2486. { Conflicts between directives ? }
  2487. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  2488. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  2489. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  2490. begin
  2491. Message1(parser_e_proc_dir_conflict,name);
  2492. exit;
  2493. end;
  2494. { set calling convention }
  2495. if proc_direcdata[p].pocall<>pocall_none then
  2496. begin
  2497. if (po_hascallingconvention in pd.procoptions) then
  2498. begin
  2499. Message2(parser_w_proc_overriding_calling,
  2500. proccalloptionStr[pd.proccalloption],
  2501. proccalloptionStr[proc_direcdata[p].pocall]);
  2502. end;
  2503. { check if the target processor supports this calling convention }
  2504. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2505. begin
  2506. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2507. { recover }
  2508. proc_direcdata[p].pocall:=pocall_stdcall;
  2509. end;
  2510. pd.proccalloption:=proc_direcdata[p].pocall;
  2511. include(pd.procoptions,po_hascallingconvention);
  2512. end;
  2513. if pd.typ=procdef then
  2514. begin
  2515. { Check if the directive is only for objects }
  2516. if (pd_object in proc_direcdata[p].pd_flags) and
  2517. not assigned(tprocdef(pd).struct) then
  2518. exit;
  2519. { Check if the directive is only for records }
  2520. if (pd_record in proc_direcdata[p].pd_flags) and
  2521. not assigned(tprocdef(pd).struct) then
  2522. exit;
  2523. { check if method and directive not for interface }
  2524. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2525. is_interface(tprocdef(pd).struct) then
  2526. exit;
  2527. { check if method and directive not for interface }
  2528. if is_dispinterface(tprocdef(pd).struct) and
  2529. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2530. exit;
  2531. { check if method and directive not for objcclass }
  2532. if is_objcclass(tprocdef(pd).struct) and
  2533. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2534. exit;
  2535. { check if method and directive not for objcprotocol }
  2536. if is_objcprotocol(tprocdef(pd).struct) and
  2537. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2538. exit;
  2539. { check if method and directive not for record/class helper }
  2540. if is_objectpascal_helper(tprocdef(pd).struct) and
  2541. (pd_nothelper in proc_direcdata[p].pd_flags) then
  2542. end;
  2543. { consume directive, and turn flag on }
  2544. consume(token);
  2545. parse_proc_direc:=true;
  2546. { Check the pd_flags if the directive should be allowed }
  2547. if (pd_interface in pdflags) and
  2548. not(pd_interface in proc_direcdata[p].pd_flags) then
  2549. begin
  2550. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  2551. exit;
  2552. end;
  2553. if (pd_implemen in pdflags) and
  2554. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2555. begin
  2556. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  2557. exit;
  2558. end;
  2559. if (pd_procvar in pdflags) and
  2560. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2561. begin
  2562. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  2563. exit;
  2564. end;
  2565. { Return the new pd_flags }
  2566. if not(pd_body in proc_direcdata[p].pd_flags) then
  2567. exclude(pdflags,pd_body);
  2568. { Add the correct flag }
  2569. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2570. { Call the handler }
  2571. if pointer(proc_direcdata[p].handler)<>nil then
  2572. proc_direcdata[p].handler(pd);
  2573. end;
  2574. function proc_get_importname(pd:tprocdef):string;
  2575. var
  2576. dllname, importname : string;
  2577. begin
  2578. result:='';
  2579. if not(po_external in pd.procoptions) then
  2580. internalerror(200412151);
  2581. { external name or number is specified }
  2582. if assigned(pd.import_name) or (pd.import_nr<>0) then
  2583. begin
  2584. if assigned(pd.import_dll) then
  2585. dllname:=pd.import_dll^
  2586. else
  2587. dllname:='';
  2588. if assigned(pd.import_name) then
  2589. importname:=pd.import_name^
  2590. else
  2591. importname:='';
  2592. proc_get_importname:=make_dllmangledname(dllname,
  2593. importname,pd.import_nr,pd.proccalloption);
  2594. end
  2595. else
  2596. begin
  2597. { Default names when importing variables }
  2598. case pd.proccalloption of
  2599. pocall_cdecl :
  2600. begin
  2601. if assigned(pd.struct) then
  2602. result:=target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname
  2603. else
  2604. result:=target_info.Cprefix+pd.procsym.realname;
  2605. end;
  2606. pocall_cppdecl :
  2607. begin
  2608. result:=target_info.Cprefix+pd.cplusplusmangledname;
  2609. end;
  2610. else
  2611. begin
  2612. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  2613. { but according to MacPas mode description
  2614. Cprefix should still be used PM }
  2615. if (m_mac in current_settings.modeswitches) then
  2616. result:=target_info.Cprefix+tprocdef(pd).procsym.realname;
  2617. end;
  2618. end;
  2619. end;
  2620. end;
  2621. procedure proc_set_mangledname(pd:tprocdef);
  2622. var
  2623. s : string;
  2624. begin
  2625. { When the mangledname is already set we aren't allowed to change
  2626. it because it can already be used somewhere (PFV) }
  2627. if not(po_has_mangledname in pd.procoptions) then
  2628. begin
  2629. if (po_external in pd.procoptions) then
  2630. begin
  2631. { External Procedures are only allowed to change the mangledname
  2632. in their first declaration }
  2633. if (pd.forwarddef or (not pd.hasforward)) then
  2634. begin
  2635. s:=proc_get_importname(pd);
  2636. if s<>'' then
  2637. begin
  2638. pd.setmangledname(s);
  2639. end;
  2640. end;
  2641. end
  2642. else
  2643. { Normal procedures }
  2644. begin
  2645. if (po_compilerproc in pd.procoptions) then
  2646. begin
  2647. pd.setmangledname(lower(pd.procsym.name));
  2648. end;
  2649. end;
  2650. end;
  2651. { Public/exported alias names }
  2652. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  2653. not(po_has_public_name in pd.procoptions) then
  2654. begin
  2655. case pd.proccalloption of
  2656. pocall_cdecl :
  2657. begin
  2658. if assigned(pd.struct) then
  2659. pd.aliasnames.insert(target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname)
  2660. else
  2661. begin
  2662. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  2663. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  2664. (po_exports in pd.procoptions) then
  2665. pd.aliasnames.insert(pd.procsym.realname)
  2666. else
  2667. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  2668. end;
  2669. end;
  2670. pocall_cppdecl :
  2671. begin
  2672. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  2673. end;
  2674. end;
  2675. { prevent adding the alias a second time }
  2676. include(pd.procoptions,po_has_public_name);
  2677. end;
  2678. end;
  2679. procedure handle_calling_convention(pd:tabstractprocdef;flags:thccflags=hcc_all);
  2680. begin
  2681. if hcc_check in flags then
  2682. begin
  2683. { set the default calling convention if none provided }
  2684. if (pd.typ=procdef) and
  2685. (is_objc_class_or_protocol(tprocdef(pd).struct) or
  2686. is_cppclass(tprocdef(pd).struct)) then
  2687. begin
  2688. { none of the explicit calling conventions should be allowed }
  2689. if (po_hascallingconvention in pd.procoptions) then
  2690. internalerror(2009032501);
  2691. if is_cppclass(tprocdef(pd).struct) then
  2692. pd.proccalloption:=pocall_cppdecl
  2693. else
  2694. pd.proccalloption:=pocall_cdecl;
  2695. end
  2696. else if not(po_hascallingconvention in pd.procoptions) then
  2697. pd.proccalloption:=current_settings.defproccall
  2698. else
  2699. begin
  2700. if pd.proccalloption=pocall_none then
  2701. internalerror(200309081);
  2702. end;
  2703. { handle proccall specific settings }
  2704. case pd.proccalloption of
  2705. pocall_cdecl,
  2706. pocall_cppdecl :
  2707. begin
  2708. { check C cdecl para types }
  2709. check_c_para(pd);
  2710. end;
  2711. pocall_far16 :
  2712. begin
  2713. { Temporary stub, must be rewritten to support OS/2 far16 }
  2714. Message1(parser_w_proc_directive_ignored,'FAR16');
  2715. end;
  2716. end;
  2717. { Inlining is enabled and supported? }
  2718. if (po_inline in pd.procoptions) and
  2719. not(cs_do_inline in current_settings.localswitches) then
  2720. begin
  2721. { Give an error if inline is not supported by the compiler mode,
  2722. otherwise only give a hint that this procedure will not be inlined }
  2723. if not(m_default_inline in current_settings.modeswitches) then
  2724. Message(parser_e_proc_inline_not_supported)
  2725. else
  2726. Message(parser_h_inlining_disabled);
  2727. exclude(pd.procoptions,po_inline);
  2728. end;
  2729. { For varargs directive also cdecl and external must be defined }
  2730. if (po_varargs in pd.procoptions) then
  2731. begin
  2732. { check first for external in the interface, if available there
  2733. then the cdecl must also be there since there is no implementation
  2734. available to contain it }
  2735. if parse_only then
  2736. begin
  2737. { if external is available, then cdecl must also be available,
  2738. procvars don't need external }
  2739. if not((po_external in pd.procoptions) or
  2740. (pd.typ=procvardef) or
  2741. { for objcclasses this is checked later, because the entire
  2742. class may be external. }
  2743. is_objc_class_or_protocol(tprocdef(pd).struct)) and
  2744. not(pd.proccalloption in (cdecl_pocalls + [pocall_mwpascal,pocall_stdcall])) then
  2745. Message(parser_e_varargs_need_cdecl_and_external);
  2746. end
  2747. else
  2748. begin
  2749. { both must be defined now }
  2750. if not((po_external in pd.procoptions) or
  2751. (pd.typ=procvardef)) or
  2752. not(pd.proccalloption in (cdecl_pocalls + [pocall_mwpascal,pocall_stdcall])) then
  2753. Message(parser_e_varargs_need_cdecl_and_external);
  2754. end;
  2755. end;
  2756. end;
  2757. if hcc_insert_hidden_paras in flags then
  2758. begin
  2759. { insert hidden high parameters }
  2760. pd.parast.SymList.ForEachCall(@insert_hidden_para,pd);
  2761. { insert hidden self parameter }
  2762. insert_self_and_vmt_para(pd);
  2763. { insert funcret parameter if required }
  2764. insert_funcret_para(pd);
  2765. { Make var parameters regable, this must be done after the calling
  2766. convention is set. }
  2767. { this must be done before parentfp is insert, because getting all cases
  2768. where parentfp must be in a memory location isn't catched properly so
  2769. we put parentfp never in a register }
  2770. pd.parast.SymList.ForEachCall(@set_addr_param_regable,pd);
  2771. { insert parentfp parameter if required }
  2772. insert_parentfp_para(pd);
  2773. end;
  2774. { Calculate parameter tlist }
  2775. pd.calcparas;
  2776. end;
  2777. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  2778. {
  2779. Parse the procedure directives. It does not matter if procedure directives
  2780. are written using ;procdir; or ['procdir'] syntax.
  2781. }
  2782. var
  2783. res : boolean;
  2784. begin
  2785. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  2786. begin
  2787. tprocdef(pd).aliasnames.insert(target_info.Cprefix+tprocdef(pd).procsym.realname);
  2788. include(pd.procoptions,po_public);
  2789. include(pd.procoptions,po_has_public_name);
  2790. include(pd.procoptions,po_global);
  2791. end;
  2792. { methods from external class definitions are all external themselves }
  2793. if (pd.typ=procdef) and
  2794. assigned(tprocdef(pd).struct) and
  2795. (tprocdef(pd).struct.typ=objectdef) and
  2796. (oo_is_external in tobjectdef(tprocdef(pd).struct).objectoptions) then
  2797. tprocdef(pd).make_external;
  2798. { Class constructors and destructor are static class methods in real. }
  2799. { There are many places in the compiler where either class or static }
  2800. { method flag changes the behavior. It is simplier to add them to }
  2801. { the class constructors/destructors options than to fix all the }
  2802. { occurencies. (Paul) }
  2803. if pd.proctypeoption in [potype_class_constructor,potype_class_destructor] then
  2804. begin
  2805. include(pd.procoptions,po_classmethod);
  2806. include(pd.procoptions,po_staticmethod);
  2807. end;
  2808. while token in [_ID,_LECKKLAMMER] do
  2809. begin
  2810. if try_to_consume(_LECKKLAMMER) then
  2811. begin
  2812. repeat
  2813. parse_proc_direc(pd,pdflags);
  2814. until not try_to_consume(_COMMA);
  2815. consume(_RECKKLAMMER);
  2816. { we always expect at least '[];' }
  2817. res:=true;
  2818. end
  2819. else
  2820. begin
  2821. res:=parse_proc_direc(pd,pdflags);
  2822. end;
  2823. { A procedure directive normally followed by a semicolon, but in
  2824. a const section or reading a type we should stop when _EQ is found,
  2825. because a constant/default value follows }
  2826. if res then
  2827. begin
  2828. if (block_type=bt_const_type) and
  2829. (token=_EQ) then
  2830. break;
  2831. { support procedure proc;stdcall export; }
  2832. if not(check_proc_directive((pd.typ=procvardef))) then
  2833. begin
  2834. { support "record p : procedure stdcall end;" and
  2835. "var p : procedure stdcall = nil;" }
  2836. if (pd_procvar in pdflags) and
  2837. (token in [_END,_RKLAMMER,_EQ]) then
  2838. break
  2839. else
  2840. begin
  2841. if (token=_COLON) then
  2842. begin
  2843. Message(parser_e_field_not_allowed_here);
  2844. consume_all_until(_SEMICOLON);
  2845. end;
  2846. consume(_SEMICOLON)
  2847. end;
  2848. end;
  2849. end
  2850. else
  2851. break;
  2852. end;
  2853. { nostackframe requires assembler, but assembler
  2854. may be specified in the implementation part only,
  2855. and in not required if the function is first forward declared
  2856. if it is a procdef that has forwardef set to true
  2857. we postpone the possible error message to the real implementation
  2858. parse_only does not need to be considered as po_nostackframe
  2859. is an implementation only directive }
  2860. if (po_nostackframe in pd.procoptions) and
  2861. not (po_assembler in pd.procoptions) and
  2862. ((pd.typ<>procdef) or not tprocdef(pd).forwarddef) then
  2863. message(parser_e_nostackframe_without_assembler);
  2864. end;
  2865. procedure parse_var_proc_directives(sym:tsym);
  2866. var
  2867. pdflags : tpdflags;
  2868. pd : tabstractprocdef;
  2869. begin
  2870. pdflags:=[pd_procvar];
  2871. pd:=nil;
  2872. case sym.typ of
  2873. fieldvarsym,
  2874. staticvarsym,
  2875. localvarsym,
  2876. paravarsym :
  2877. pd:=tabstractprocdef(tabstractvarsym(sym).vardef);
  2878. typesym :
  2879. pd:=tabstractprocdef(ttypesym(sym).typedef);
  2880. else
  2881. internalerror(2003042617);
  2882. end;
  2883. if pd.typ<>procvardef then
  2884. internalerror(2003042618);
  2885. { names should never be used anyway }
  2886. parse_proc_directives(pd,pdflags);
  2887. end;
  2888. procedure parse_object_proc_directives(pd:tabstractprocdef);
  2889. var
  2890. pdflags : tpdflags;
  2891. begin
  2892. pdflags:=[pd_object];
  2893. parse_proc_directives(pd,pdflags);
  2894. end;
  2895. procedure parse_record_proc_directives(pd:tabstractprocdef);
  2896. var
  2897. pdflags : tpdflags;
  2898. begin
  2899. pdflags:=[pd_record];
  2900. parse_proc_directives(pd,pdflags);
  2901. end;
  2902. function proc_add_definition(var currpd:tprocdef):boolean;
  2903. {
  2904. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  2905. forwarddef is found and reused it returns true
  2906. }
  2907. var
  2908. fwpd : tprocdef;
  2909. currparasym,
  2910. fwparasym : tsym;
  2911. currparacnt,
  2912. fwparacnt,
  2913. curridx,
  2914. fwidx,
  2915. i : longint;
  2916. po_comp : tprocoptions;
  2917. paracompopt: tcompare_paras_options;
  2918. forwardfound : boolean;
  2919. symentry: TSymEntry;
  2920. begin
  2921. forwardfound:=false;
  2922. { check overloaded functions if the same function already exists }
  2923. for i:=0 to tprocsym(currpd.procsym).ProcdefList.Count-1 do
  2924. begin
  2925. fwpd:=tprocdef(tprocsym(currpd.procsym).ProcdefList[i]);
  2926. { can happen for internally generated routines }
  2927. if (fwpd=currpd) then
  2928. begin
  2929. result:=true;
  2930. exit;
  2931. end;
  2932. { Skip overloaded definitions that are declared in other units }
  2933. if fwpd.procsym<>currpd.procsym then
  2934. continue;
  2935. { check the parameters, for delphi/tp it is possible to
  2936. leave the parameters away in the implementation (forwarddef=false).
  2937. But for an overload declared function this is not allowed }
  2938. if { check if empty implementation arguments match is allowed }
  2939. (
  2940. not(m_repeat_forward in current_settings.modeswitches) and
  2941. not(currpd.forwarddef) and
  2942. is_bareprocdef(currpd) and
  2943. not(po_overload in fwpd.procoptions)
  2944. ) or
  2945. { check arguments, we need to check only the user visible parameters. The hidden parameters
  2946. can be in a different location because of the calling convention, eg. L-R vs. R-L order (PFV)
  2947. don't check default values here, because routines that are the same except for their default
  2948. values should be reported as mismatches (since you can't overload based on different default
  2949. parameter values) }
  2950. (
  2951. (compare_paras(fwpd.paras,currpd.paras,cp_none,[cpo_ignorehidden,cpo_openequalisexact,cpo_ignoreuniv])=te_exact) and
  2952. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)=te_exact)
  2953. ) then
  2954. begin
  2955. { Check if we've found the forwarddef, if found then
  2956. we need to update the forward def with the current
  2957. implementation settings }
  2958. if fwpd.forwarddef then
  2959. begin
  2960. forwardfound:=true;
  2961. if not(m_repeat_forward in current_settings.modeswitches) and
  2962. (fwpd.proccalloption<>currpd.proccalloption) then
  2963. paracompopt:=[cpo_ignorehidden,cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv]
  2964. else
  2965. paracompopt:=[cpo_comparedefaultvalue,cpo_openequalisexact,cpo_ignoreuniv];
  2966. { Check calling convention }
  2967. if (fwpd.proccalloption<>currpd.proccalloption) then
  2968. begin
  2969. { In delphi it is possible to specify the calling
  2970. convention in the interface or implementation if
  2971. there was no convention specified in the other
  2972. part }
  2973. if (m_delphi in current_settings.modeswitches) then
  2974. begin
  2975. if not(po_hascallingconvention in currpd.procoptions) then
  2976. currpd.proccalloption:=fwpd.proccalloption
  2977. else
  2978. if not(po_hascallingconvention in fwpd.procoptions) then
  2979. fwpd.proccalloption:=currpd.proccalloption
  2980. else
  2981. begin
  2982. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  2983. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  2984. { restore interface settings }
  2985. currpd.proccalloption:=fwpd.proccalloption;
  2986. end;
  2987. end
  2988. else
  2989. begin
  2990. MessagePos(currpd.fileinfo,parser_e_call_convention_dont_match_forward);
  2991. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  2992. { restore interface settings }
  2993. currpd.proccalloption:=fwpd.proccalloption;
  2994. end;
  2995. end;
  2996. { Check static }
  2997. if (po_staticmethod in fwpd.procoptions) then
  2998. begin
  2999. if not (po_staticmethod in currpd.procoptions) then
  3000. begin
  3001. include(currpd.procoptions, po_staticmethod);
  3002. if (po_classmethod in currpd.procoptions) then
  3003. begin
  3004. { remove self from the hidden paras }
  3005. symentry:=currpd.parast.Find('self');
  3006. if symentry<>nil then
  3007. begin
  3008. currpd.parast.Delete(symentry);
  3009. currpd.calcparas;
  3010. end;
  3011. end;
  3012. end;
  3013. end;
  3014. { Check if the procedure type and return type are correct,
  3015. also the parameters must match also with the type and that
  3016. if the implementation has default parameters, the interface
  3017. also has them and that if they both have them, that they
  3018. have the same value }
  3019. if ((m_repeat_forward in current_settings.modeswitches) or
  3020. not is_bareprocdef(currpd)) and
  3021. ((compare_paras(fwpd.paras,currpd.paras,cp_all,paracompopt)<>te_exact) or
  3022. (compare_defs(fwpd.returndef,currpd.returndef,nothingn)<>te_exact)) then
  3023. begin
  3024. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3025. fwpd.fullprocname(false));
  3026. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3027. break;
  3028. end;
  3029. { Check if both are declared forward }
  3030. if fwpd.forwarddef and currpd.forwarddef then
  3031. begin
  3032. MessagePos1(currpd.fileinfo,parser_e_function_already_declared_public_forward,
  3033. currpd.fullprocname(false));
  3034. end;
  3035. { internconst or internproc only need to be defined once }
  3036. if (fwpd.proccalloption=pocall_internproc) then
  3037. currpd.proccalloption:=fwpd.proccalloption
  3038. else
  3039. if (currpd.proccalloption=pocall_internproc) then
  3040. fwpd.proccalloption:=currpd.proccalloption;
  3041. { Check procedure options, Delphi requires that class is
  3042. repeated in the implementation for class methods }
  3043. if (m_fpc in current_settings.modeswitches) then
  3044. po_comp:=[po_classmethod,po_varargs,po_methodpointer,po_interrupt]
  3045. else
  3046. po_comp:=[po_classmethod,po_methodpointer];
  3047. if ((po_comp * fwpd.procoptions)<>(po_comp * currpd.procoptions)) or
  3048. (fwpd.proctypeoption <> currpd.proctypeoption) or
  3049. { if the implementation version has an "overload" modifier,
  3050. the interface version must also have it (otherwise we can
  3051. get annoying crashes due to interface crc changes) }
  3052. (not(po_overload in fwpd.procoptions) and
  3053. (po_overload in currpd.procoptions)) then
  3054. begin
  3055. MessagePos1(currpd.fileinfo,parser_e_header_dont_match_forward,
  3056. fwpd.fullprocname(false));
  3057. tprocsym(fwpd.procsym).write_parameter_lists(fwpd);
  3058. { This error is non-fatal, we can recover }
  3059. end;
  3060. { Forward declaration is external? }
  3061. if (po_external in fwpd.procoptions) then
  3062. MessagePos(currpd.fileinfo,parser_e_proc_already_external);
  3063. { Check parameters }
  3064. if (m_repeat_forward in current_settings.modeswitches) or
  3065. (currpd.minparacount>0) then
  3066. begin
  3067. { If mangled names are equal then they have the same amount of arguments }
  3068. { We can check the names of the arguments }
  3069. { both symtables are in the same order from left to right }
  3070. curridx:=0;
  3071. fwidx:=0;
  3072. currparacnt:=currpd.parast.SymList.Count;
  3073. fwparacnt:=fwpd.parast.SymList.Count;
  3074. repeat
  3075. { skip default parameter constsyms }
  3076. while (curridx<currparacnt) and
  3077. (tsym(currpd.parast.SymList[curridx]).typ<>paravarsym) do
  3078. inc(curridx);
  3079. while (fwidx<fwparacnt) and
  3080. (tsym(fwpd.parast.SymList[fwidx]).typ<>paravarsym) do
  3081. inc(fwidx);
  3082. { stop when one of the two lists is at the end }
  3083. if (fwidx>=fwparacnt) or (curridx>=currparacnt) then
  3084. break;
  3085. { compare names of parameters, ignore implictly
  3086. renamed parameters }
  3087. currparasym:=tsym(currpd.parast.SymList[curridx]);
  3088. fwparasym:=tsym(fwpd.parast.SymList[fwidx]);
  3089. if not(sp_implicitrename in currparasym.symoptions) and
  3090. not(sp_implicitrename in fwparasym.symoptions) then
  3091. begin
  3092. if (currparasym.name<>fwparasym.name) then
  3093. begin
  3094. MessagePos3(currpd.fileinfo,parser_e_header_different_var_names,
  3095. tprocsym(currpd.procsym).realname,fwparasym.realname,currparasym.realname);
  3096. break;
  3097. end;
  3098. end;
  3099. { next parameter }
  3100. inc(curridx);
  3101. inc(fwidx);
  3102. until false;
  3103. end;
  3104. { Everything is checked, now we can update the forward declaration
  3105. with the new data from the implementation }
  3106. fwpd.forwarddef:=currpd.forwarddef;
  3107. fwpd.hasforward:=true;
  3108. fwpd.procoptions:=fwpd.procoptions+currpd.procoptions;
  3109. { marked as local but exported from unit? }
  3110. if (po_kylixlocal in fwpd.procoptions) and (fwpd.owner.symtabletype=globalsymtable) then
  3111. MessagePos(fwpd.fileinfo,type_e_cant_export_local);
  3112. if fwpd.extnumber=$ffff then
  3113. fwpd.extnumber:=currpd.extnumber;
  3114. while not currpd.aliasnames.empty do
  3115. fwpd.aliasnames.insert(currpd.aliasnames.getfirst);
  3116. { update fileinfo so position references the implementation,
  3117. also update funcretsym if it is already generated }
  3118. fwpd.fileinfo:=currpd.fileinfo;
  3119. if assigned(fwpd.funcretsym) then
  3120. fwpd.funcretsym.fileinfo:=currpd.fileinfo;
  3121. if assigned(currpd.deprecatedmsg) then
  3122. begin
  3123. stringdispose(fwpd.deprecatedmsg);
  3124. fwpd.deprecatedmsg:=stringdup(currpd.deprecatedmsg^);
  3125. end;
  3126. { import names }
  3127. if assigned(currpd.import_dll) then
  3128. begin
  3129. stringdispose(fwpd.import_dll);
  3130. fwpd.import_dll:=stringdup(currpd.import_dll^);
  3131. end;
  3132. if assigned(currpd.import_name) then
  3133. begin
  3134. stringdispose(fwpd.import_name);
  3135. fwpd.import_name:=stringdup(currpd.import_name^);
  3136. end;
  3137. fwpd.import_nr:=currpd.import_nr;
  3138. { for compilerproc defines we need to rename and update the
  3139. symbolname to lowercase }
  3140. if (po_compilerproc in fwpd.procoptions) then
  3141. begin
  3142. { rename to lowercase so users can't access it }
  3143. fwpd.procsym.realname:='$'+lower(fwpd.procsym.name);
  3144. { the mangeled name is already changed by the pd_compilerproc }
  3145. { handler. It must be done immediately because if we have a }
  3146. { call to a compilerproc before it's implementation is }
  3147. { encountered, it must already use the new mangled name (JM) }
  3148. end;
  3149. { Release current procdef }
  3150. currpd.owner.deletedef(currpd);
  3151. currpd:=fwpd;
  3152. end
  3153. else
  3154. begin
  3155. { abstract methods aren't forward defined, but this }
  3156. { needs another error message }
  3157. if (po_abstractmethod in fwpd.procoptions) then
  3158. MessagePos(currpd.fileinfo,parser_e_abstract_no_definition)
  3159. else
  3160. begin
  3161. MessagePos(currpd.fileinfo,parser_e_overloaded_have_same_parameters);
  3162. tprocsym(currpd.procsym).write_parameter_lists(currpd);
  3163. end;
  3164. end;
  3165. { we found one proc with the same arguments, there are no others
  3166. so we can stop }
  3167. break;
  3168. end;
  3169. { check for allowing overload directive }
  3170. if not(m_fpc in current_settings.modeswitches) then
  3171. begin
  3172. { overload directive turns on overloading }
  3173. if ((po_overload in currpd.procoptions) or
  3174. (po_overload in fwpd.procoptions)) then
  3175. begin
  3176. { check if all procs have overloading, but not if the proc is a method or
  3177. already declared forward, then the check is already done }
  3178. if not(fwpd.hasforward or
  3179. assigned(currpd.struct) or
  3180. (currpd.forwarddef<>fwpd.forwarddef) or
  3181. ((po_overload in currpd.procoptions) and
  3182. (po_overload in fwpd.procoptions))) then
  3183. begin
  3184. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3185. break;
  3186. end
  3187. end
  3188. else
  3189. begin
  3190. if not(fwpd.forwarddef) then
  3191. begin
  3192. if (m_tp7 in current_settings.modeswitches) then
  3193. MessagePos(currpd.fileinfo,parser_e_procedure_overloading_is_off)
  3194. else
  3195. MessagePos1(currpd.fileinfo,parser_e_no_overload_for_all_procs,currpd.procsym.realname);
  3196. break;
  3197. end;
  3198. end;
  3199. end; { equal arguments }
  3200. end;
  3201. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  3202. list }
  3203. if not forwardfound then
  3204. begin
  3205. { can happen in Delphi mode }
  3206. if (currpd.proctypeoption = potype_function) and
  3207. is_void(currpd.returndef) then
  3208. MessagePos1(currpd.fileinfo,parser_e_no_funcret_specified,currpd.procsym.realname);
  3209. tprocsym(currpd.procsym).ProcdefList.Add(currpd);
  3210. end;
  3211. proc_add_definition:=forwardfound;
  3212. end;
  3213. end.