pdecsub.pas 131 KB

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