pdecsub.pas 130 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482
  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.localswitches) 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. function handle_generic_interface:boolean;
  660. var
  661. i : longint;
  662. sym : ttypesym;
  663. typesrsym : tsym;
  664. typesrsymtable : tsymtable;
  665. specializename,
  666. prettyname: ansistring;
  667. error : boolean;
  668. genname,
  669. ugenname : tidstring;
  670. module : tmodule;
  671. begin
  672. result:=false;
  673. if not assigned(genericparams) then
  674. exit;
  675. specializename:='$';
  676. prettyname:='';
  677. error:=false;
  678. for i:=0 to genericparams.count-1 do
  679. begin
  680. sym:=ttypesym(genericparams[i]);
  681. { ToDo: position }
  682. if not searchsym(upper(sym.RealName),typesrsym,typesrsymtable) then
  683. begin
  684. message1(sym_e_id_not_found,sym.name);
  685. error:=true;
  686. continue;
  687. end;
  688. if typesrsym.typ<>typesym then
  689. begin
  690. message(type_e_type_id_expected);
  691. error:=true;
  692. continue;
  693. end;
  694. module:=find_module_from_symtable(ttypesym(typesrsym).typedef.owner);
  695. if not assigned(module) then
  696. internalerror(2016112803);
  697. specializename:=specializename+'_$'+hexstr(module.moduleid,8)+'$$'+ttypesym(typesrsym).typedef.unique_id_str;
  698. if i>0 then
  699. prettyname:=prettyname+',';
  700. prettyname:=prettyname+ttypesym(typesrsym).prettyname;
  701. end;
  702. result:=true;
  703. if error then
  704. begin
  705. srsym:=generrorsym;
  706. exit;
  707. end;
  708. if not searchsym(sp,typesrsym,typesrsymtable) or (typesrsym.typ<>typesym) then
  709. begin
  710. identifier_not_found(sp);
  711. srsym:=generrorsym;
  712. exit;
  713. end;
  714. genname:=generate_generic_name(sp,specializename,ttypesym(typesrsym).typedef.ownerhierarchyname);
  715. ugenname:=upper(genname);
  716. srsym:=search_object_name(ugenname,false);
  717. if not assigned(srsym) then
  718. begin
  719. Message1(type_e_generic_declaration_does_not_match,sp+'<'+prettyname+'>');
  720. srsym:=generrorsym;
  721. end;
  722. end;
  723. procedure specialize_generic_interface;
  724. var
  725. node : tnode;
  726. begin
  727. node:=factor(false,[ef_type_only,ef_had_specialize]);
  728. if node.nodetype=typen then
  729. begin
  730. sp:=ttypenode(node).typedef.typesym.name;
  731. end
  732. else
  733. sp:='';
  734. end;
  735. function check_generic_parameters(def:tstoreddef):boolean;
  736. var
  737. i : longint;
  738. declsym,
  739. implsym : tsym;
  740. impltype : ttypesym absolute implsym;
  741. implname : tsymstr;
  742. fileinfo : tfileposinfo;
  743. begin
  744. result:=true;
  745. if not assigned(def.genericparas) then
  746. internalerror(2018090102);
  747. if not assigned(genericparams) then
  748. internalerror(2018090103);
  749. if def.genericparas.count<>genericparams.count then
  750. internalerror(2018090104);
  751. for i:=0 to def.genericparas.count-1 do
  752. begin
  753. declsym:=tsym(def.genericparas[i]);
  754. implsym:=tsym(genericparams[i]);
  755. implname:=upper(genericparams.nameofindex(i));
  756. if declsym.name<>implname then
  757. begin
  758. messagepos1(implsym.fileinfo,sym_e_generic_type_param_mismatch,implsym.realname);
  759. messagepos1(declsym.fileinfo,sym_e_generic_type_param_decl,declsym.realname);
  760. result:=false;
  761. end;
  762. if ((implsym.typ=typesym) and (df_genconstraint in impltype.typedef.defoptions)) or
  763. (implsym.typ=constsym) then
  764. begin
  765. if implsym.typ=constsym then
  766. fileinfo:=impltype.fileinfo
  767. else
  768. fileinfo:=tstoreddef(impltype.typedef).genconstraintdata.fileinfo;
  769. messagepos(fileinfo,parser_e_generic_constraints_not_allowed_here);
  770. result:=false;
  771. end;
  772. end;
  773. end;
  774. begin
  775. sp:='';
  776. orgsp:='';
  777. spnongen:='';
  778. orgspnongen:='';
  779. { Save the position where this procedure really starts }
  780. procstartfilepos:=current_tokenpos;
  781. old_parse_generic:=parse_generic;
  782. firstpart:=true;
  783. result:=false;
  784. pd:=nil;
  785. aprocsym:=nil;
  786. srsym:=nil;
  787. genericparams:=nil;
  788. hadspecialize:=false;
  789. addgendummy:=false;
  790. if not assigned(genericdef) then
  791. begin
  792. if ppf_anonymous in flags then
  793. begin
  794. checkstack:=symtablestack.stack;
  795. while checkstack^.symtable.symtabletype in [withsymtable] do
  796. checkstack:=checkstack^.next;
  797. if not (checkstack^.symtable.symtabletype in [localsymtable,staticsymtable]) then
  798. internalerror(2021050101);
  799. { generate a unique name for the anonymous function; don't use
  800. something like file position however as this might be inside
  801. an include file that's included multiple times }
  802. str(checkstack^.symtable.symlist.count,orgsp);
  803. orgsp:='__FPCINTERNAL__Anonymous_'+orgsp;
  804. sp:=upper(orgsp);
  805. spnongen:=sp;
  806. orgspnongen:=orgsp;
  807. end
  808. else
  809. consume_proc_name;
  810. { examine interface map: function/procedure iname.functionname=locfuncname }
  811. if assigned(astruct) and
  812. (astruct.typ=objectdef) and
  813. assigned(tobjectdef(astruct).ImplementedInterfaces) and
  814. (tobjectdef(astruct).ImplementedInterfaces.count>0) and
  815. (
  816. (token=_POINT) or
  817. (
  818. hadspecialize and
  819. (token=_ID)
  820. )
  821. ) then
  822. begin
  823. if hadspecialize and (token=_ID) then
  824. specialize_generic_interface;
  825. consume(_POINT);
  826. if hadspecialize or not handle_generic_interface then
  827. srsym:=search_object_name(sp,true);
  828. { qualifier is interface? }
  829. ImplIntf:=nil;
  830. if assigned(srsym) and
  831. (srsym.typ=typesym) and
  832. (ttypesym(srsym).typedef.typ=objectdef) then
  833. ImplIntf:=find_implemented_interface(tobjectdef(astruct),tobjectdef(ttypesym(srsym).typedef));
  834. if ImplIntf=nil then
  835. begin
  836. Message(parser_e_interface_id_expected);
  837. { error recovery }
  838. consume(_ID);
  839. if try_to_consume(_EQ) then
  840. consume(_ID);
  841. exit;
  842. end
  843. else
  844. { in case of a generic or specialized interface we need to use the
  845. name of the def instead of the symbol, so that always the correct
  846. name is used }
  847. if [df_generic,df_specialization]*ttypesym(srsym).typedef.defoptions<>[] then
  848. sp:=tobjectdef(ttypesym(srsym).typedef).objname^;
  849. { must be a directly implemented interface }
  850. if Assigned(ImplIntf.ImplementsGetter) then
  851. Message2(parser_e_implements_no_mapping,ImplIntf.IntfDef.typename,astruct.objrealname^);
  852. consume(_ID);
  853. { Create unique name <interface>.<method> }
  854. hs:=sp+'.'+pattern;
  855. consume(_EQ);
  856. if assigned(ImplIntf) and
  857. (token=_ID) then
  858. ImplIntf.AddMapping(hs,pattern);
  859. consume(_ID);
  860. result:=true;
  861. exit;
  862. end;
  863. if assigned(genericparams) and assigned(current_genericdef) then
  864. Message(parser_f_no_generic_inside_generic);
  865. { method ? }
  866. srsym:=nil;
  867. if not assigned(astruct) and
  868. (symtablestack.top.symtablelevel=main_program_level) and
  869. try_to_consume(_POINT) then
  870. begin
  871. repeat
  872. classstartfilepos:=procstartfilepos;
  873. searchagain:=false;
  874. { throw the error at the right location }
  875. oldfilepos:=current_filepos;
  876. current_filepos:=procstartfilepos;
  877. if not assigned(astruct) and not assigned(srsym) then
  878. srsym:=search_object_name(sp,true);
  879. current_filepos:=oldfilepos;
  880. { we need to check whether the names of the generic parameter
  881. types match with the one in the declaration of a class/record,
  882. but we need to do this before consume_proc_name frees the
  883. type parameters of the class part }
  884. if (srsym.typ=typesym) and
  885. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) and
  886. tstoreddef(ttypesym(srsym).typedef).is_generic and
  887. assigned(genericparams) then
  888. { this is recoverable, so no further action necessary }
  889. check_generic_parameters(tstoreddef(ttypesym(srsym).typedef));
  890. { consume proc name }
  891. procstartfilepos:=current_tokenpos;
  892. consume_proc_name;
  893. { qualifier is class name ? }
  894. if (srsym.typ=typesym) and
  895. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) then
  896. begin
  897. astruct:=tabstractrecorddef(ttypesym(srsym).typedef);
  898. if (token<>_POINT) then
  899. if (potype in [potype_class_constructor,potype_class_destructor]) then
  900. sp:=lower(sp)
  901. else
  902. if (potype=potype_operator) and (optoken=NOTOKEN) then
  903. parse_operator_name;
  904. srsym:=tsym(astruct.symtable.Find(sp));
  905. if assigned(srsym) then
  906. begin
  907. if srsym.typ=procsym then
  908. aprocsym:=tprocsym(srsym)
  909. else
  910. if (srsym.typ=typesym) and
  911. (ttypesym(srsym).typedef.typ in [objectdef,recorddef]) then
  912. begin
  913. searchagain:=true;
  914. consume(_POINT);
  915. end
  916. else
  917. begin
  918. { we use a different error message for tp7 so it looks more compatible }
  919. if (m_fpc in current_settings.modeswitches) then
  920. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  921. else
  922. Message(parser_e_methode_id_expected);
  923. { rename the name to an unique name to avoid an
  924. error when inserting the symbol in the symtable }
  925. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  926. end;
  927. end
  928. else
  929. begin
  930. MessagePos(procstartfilepos,parser_e_methode_id_expected);
  931. { recover by making it a normal procedure instead of method }
  932. astruct:=nil;
  933. end;
  934. end
  935. else
  936. MessagePos(classstartfilepos,parser_e_class_id_expected);
  937. until not searchagain;
  938. end
  939. else
  940. begin
  941. { check for constructor/destructor/class operators which are not allowed here }
  942. if (not parse_only) and
  943. ((potype in [potype_constructor,potype_destructor,
  944. potype_class_constructor,potype_class_destructor]) or
  945. ((potype=potype_operator) and (m_delphi in current_settings.modeswitches))) then
  946. Message(parser_e_only_methods_allowed);
  947. repeat
  948. { only 1 class constructor and destructor is allowed in the class and
  949. the check was already done with oo_has_class_constructor or
  950. oo_has_class_destructor -> skip searching
  951. (bug #28801) }
  952. if (potype in [potype_class_constructor,potype_class_destructor]) then
  953. break;
  954. searchagain:=false;
  955. current_tokenpos:=procstartfilepos;
  956. if (potype=potype_operator)and(optoken=NOTOKEN) then
  957. parse_operator_name;
  958. srsym:=tsym(symtablestack.top.Find(sp));
  959. { Also look in the globalsymtable if we didn't found
  960. the symbol in the localsymtable }
  961. if not assigned(srsym) and
  962. not(parse_only) and
  963. (symtablestack.top=current_module.localsymtable) and
  964. assigned(current_module.globalsymtable) then
  965. srsym:=tsym(current_module.globalsymtable.Find(sp));
  966. { Check if overloaded is a procsym }
  967. if assigned(srsym) then
  968. begin
  969. if srsym.typ=procsym then
  970. aprocsym:=tprocsym(srsym)
  971. else
  972. begin
  973. { when the other symbol is a unit symbol then hide the unit
  974. symbol, this is not supported in tp7 }
  975. if not(m_tp7 in current_settings.modeswitches) and
  976. (srsym.typ=unitsym) then
  977. begin
  978. HideSym(srsym);
  979. searchagain:=true;
  980. end
  981. else
  982. if (m_delphi in current_settings.modeswitches) and
  983. (srsym.typ=absolutevarsym) and
  984. ([vo_is_funcret,vo_is_result]*tabstractvarsym(srsym).varoptions=[vo_is_funcret]) then
  985. begin
  986. HideSym(srsym);
  987. searchagain:=true;
  988. end
  989. else if (srsym.typ=typesym) and
  990. (sp_generic_dummy in srsym.symoptions) and
  991. (ttypesym(srsym).typedef.typ=undefineddef) and
  992. not assigned(genericparams) then
  993. begin
  994. { this is a generic dummy symbol that has not yet
  995. been used; so we rename the dummy symbol and continue
  996. as if nothing happened }
  997. hidesym(srsym);
  998. searchagain:=true;
  999. addgendummy:=true;
  1000. end
  1001. else
  1002. begin
  1003. { we use a different error message for tp7 so it looks more compatible }
  1004. if (m_fpc in current_settings.modeswitches) then
  1005. Message1(parser_e_overloaded_no_procedure,srsym.realname)
  1006. else
  1007. Message1(sym_e_duplicate_id,srsym.realname);
  1008. { rename the name to an unique name to avoid an
  1009. error when inserting the symbol in the symtable }
  1010. orgsp:=orgsp+'$'+tostr(current_filepos.line);
  1011. end;
  1012. end;
  1013. end;
  1014. until not searchagain;
  1015. end;
  1016. { test again if assigned, it can be reset to recover }
  1017. if not assigned(aprocsym) then
  1018. begin
  1019. { create a new procsym and set the real filepos }
  1020. current_tokenpos:=procstartfilepos;
  1021. { for operator we have only one procsym for each overloaded
  1022. operation }
  1023. if (potype=potype_operator) then
  1024. begin
  1025. aprocsym:=Tprocsym(symtablestack.top.Find(sp));
  1026. if aprocsym=nil then
  1027. aprocsym:=cprocsym.create('$'+sp);
  1028. end
  1029. else
  1030. if (potype in [potype_class_constructor,potype_class_destructor]) then
  1031. aprocsym:=cprocsym.create('$'+lower(sp))
  1032. else
  1033. aprocsym:=cprocsym.create(orgsp);
  1034. if ppf_anonymous in flags then
  1035. include(aprocsym.symoptions,sp_internal);
  1036. if addgendummy then
  1037. include(aprocsym.symoptions,sp_generic_dummy);
  1038. symtablestack.top.insertsym(aprocsym);
  1039. end;
  1040. end;
  1041. { to get the correct symtablelevel we must ignore ObjectSymtables }
  1042. st:=nil;
  1043. checkstack:=symtablestack.stack;
  1044. while assigned(checkstack) do
  1045. begin
  1046. st:=checkstack^.symtable;
  1047. if st.symtabletype in [staticsymtable,globalsymtable,localsymtable] then
  1048. break;
  1049. checkstack:=checkstack^.next;
  1050. end;
  1051. pd:=cprocdef.create(st.symtablelevel+1,not assigned(genericdef));
  1052. pd.struct:=astruct;
  1053. pd.procsym:=aprocsym;
  1054. pd.proctypeoption:=potype;
  1055. if ppf_anonymous in flags then
  1056. include(pd.procoptions,po_anonymous);
  1057. if assigned(genericparams) then
  1058. begin
  1059. if potype=potype_constructor then
  1060. begin
  1061. Message(parser_e_constructurs_cannot_take_type_parameters);
  1062. genericparams.free;
  1063. genericparams:=nil;
  1064. end
  1065. else
  1066. begin
  1067. include(pd.defoptions,df_generic);
  1068. { push the parameter symtable so that constraint definitions are added
  1069. there and not in the owner symtable }
  1070. symtablestack.push(pd.parast);
  1071. { register the parameters }
  1072. for i:=0 to genericparams.count-1 do
  1073. begin
  1074. tsym(genericparams[i]).register_sym;
  1075. if tsym(genericparams[i]).typ=typesym then
  1076. tstoreddef(ttypesym(genericparams[i]).typedef).register_def;
  1077. end;
  1078. insert_generic_parameter_types(pd,nil,genericparams,false);
  1079. { the list is no longer required }
  1080. genericparams.free;
  1081. genericparams:=nil;
  1082. symtablestack.pop(pd.parast);
  1083. parse_generic:=true;
  1084. { also generate a dummy symbol if none exists already }
  1085. if assigned(astruct) then
  1086. dummysym:=tsym(astruct.symtable.find(spnongen))
  1087. else
  1088. begin
  1089. dummysym:=tsym(symtablestack.top.find(spnongen));
  1090. if not assigned(dummysym) and
  1091. (symtablestack.top=current_module.localsymtable) and
  1092. assigned(current_module.globalsymtable) then
  1093. dummysym:=tsym(current_module.globalsymtable.find(spnongen));
  1094. end;
  1095. if not assigned(dummysym) then
  1096. begin
  1097. { overloading generic routines with non-generic types is not
  1098. allowed, so we create a procsym as dummy }
  1099. dummysym:=cprocsym.create(orgspnongen);
  1100. if assigned(astruct) then
  1101. astruct.symtable.insertsym(dummysym)
  1102. else
  1103. symtablestack.top.insertsym(dummysym);
  1104. end
  1105. else if (dummysym.typ<>procsym) and
  1106. (
  1107. { show error only for the declaration, not also the implementation }
  1108. not assigned(astruct) or
  1109. (symtablestack.top.symtablelevel<>main_program_level)
  1110. ) then
  1111. Message1(sym_e_duplicate_id,dummysym.realname);
  1112. if not (sp_generic_dummy in dummysym.symoptions) then
  1113. begin
  1114. include(dummysym.symoptions,sp_generic_dummy);
  1115. add_generic_dummysym(dummysym);
  1116. end;
  1117. if dummysym.typ=procsym then
  1118. tprocsym(dummysym).add_generic_overload(aprocsym);
  1119. { start token recorder for the declaration }
  1120. pd.init_genericdecl;
  1121. current_scanner.startrecordtokens(pd.genericdecltokenbuf);
  1122. end;
  1123. end
  1124. else if assigned(genericdef) then
  1125. insert_generic_parameter_types(pd,tstoreddef(genericdef),generictypelist,false);
  1126. { methods inherit df_generic or df_specialization from the objectdef }
  1127. if assigned(pd.struct) and
  1128. (pd.parast.symtablelevel=normal_function_level) then
  1129. begin
  1130. if (df_generic in pd.struct.defoptions) then
  1131. begin
  1132. include(pd.defoptions,df_generic);
  1133. parse_generic:=true;
  1134. end;
  1135. if (df_specialization in pd.struct.defoptions) then
  1136. begin
  1137. if assigned(current_specializedef) then
  1138. begin
  1139. include(pd.defoptions,df_specialization);
  1140. { Find corresponding genericdef, we need it later to
  1141. replay the tokens to generate the body }
  1142. if not assigned(pd.struct.genericdef) then
  1143. internalerror(200512113);
  1144. genericst:=pd.struct.genericdef.GetSymtable(gs_record);
  1145. if not assigned(genericst) then
  1146. internalerror(200512114);
  1147. { when searching for the correct procdef to use as genericdef we need to ignore
  1148. everything except procdefs so that we can find the correct indices }
  1149. index:=0;
  1150. found:=false;
  1151. for i:=0 to pd.owner.deflist.count-1 do
  1152. begin
  1153. if tdef(pd.owner.deflist[i]).typ<>procdef then
  1154. continue;
  1155. if pd.owner.deflist[i]=pd then
  1156. begin
  1157. found:=true;
  1158. break;
  1159. end;
  1160. inc(index);
  1161. end;
  1162. if not found then
  1163. internalerror(2014052301);
  1164. for i:=0 to genericst.deflist.count-1 do
  1165. begin
  1166. if tdef(genericst.deflist[i]).typ<>procdef then
  1167. continue;
  1168. if index=0 then
  1169. pd.genericdef:=tstoreddef(genericst.deflist[i]);
  1170. dec(index);
  1171. end;
  1172. if not assigned(pd.genericdef) or
  1173. (pd.genericdef.typ<>procdef) then
  1174. internalerror(200512115);
  1175. end
  1176. else
  1177. Message(parser_e_explicit_method_implementation_for_specializations_not_allowed);
  1178. end;
  1179. end;
  1180. { methods need to be exported }
  1181. if assigned(astruct) and
  1182. (
  1183. (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) or
  1184. (symtablestack.top.symtablelevel=main_program_level)
  1185. ) then
  1186. include(pd.procoptions,po_global);
  1187. { symbol options that need to be kept per procdef }
  1188. pd.fileinfo:=procstartfilepos;
  1189. pd.visibility:=symtablestack.top.currentvisibility;
  1190. if symtablestack.top.currentlyoptional then
  1191. include(pd.procoptions,po_optional);
  1192. { parse parameters }
  1193. if token=_LKLAMMER then
  1194. begin
  1195. old_current_structdef:=nil;
  1196. old_current_genericdef:=current_genericdef;
  1197. old_current_specializedef:=nil;
  1198. { Add ObjectSymtable to be able to find nested type definitions }
  1199. popclass:=0;
  1200. if assigned(pd.struct) and
  1201. (pd.parast.symtablelevel>=normal_function_level) and
  1202. not(symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1203. begin
  1204. popclass:=push_nested_hierarchy(pd.struct);
  1205. old_current_structdef:=current_structdef;
  1206. old_current_specializedef:=current_specializedef;
  1207. current_structdef:=pd.struct;
  1208. if assigned(current_structdef) and (df_generic in current_structdef.defoptions) then
  1209. current_genericdef:=current_structdef;
  1210. if assigned(current_structdef) and (df_specialization in current_structdef.defoptions) then
  1211. current_specializedef:=current_structdef;
  1212. end;
  1213. if pd.is_generic then
  1214. current_genericdef:=pd;
  1215. { Add parameter symtable }
  1216. if pd.parast.symtabletype<>staticsymtable then
  1217. symtablestack.push(pd.parast);
  1218. parse_parameter_dec(pd);
  1219. if pd.parast.symtabletype<>staticsymtable then
  1220. symtablestack.pop(pd.parast);
  1221. current_genericdef:=old_current_genericdef;
  1222. if popclass>0 then
  1223. begin
  1224. current_structdef:=old_current_structdef;
  1225. current_specializedef:=old_current_specializedef;
  1226. dec(popclass,pop_nested_hierarchy(pd.struct));
  1227. if popclass<>0 then
  1228. internalerror(201011260); // 11 nov 2010 index 0
  1229. end;
  1230. end;
  1231. parse_generic:=old_parse_generic;
  1232. result:=true;
  1233. end;
  1234. procedure parse_proc_dec_finish(pd:tprocdef;flags:tparse_proc_flags;astruct:tabstractrecorddef);
  1235. var
  1236. locationstr: string;
  1237. i: integer;
  1238. found: boolean;
  1239. procedure read_returndef(pd: tprocdef);
  1240. var
  1241. popclass: integer;
  1242. old_parse_generic: boolean;
  1243. old_current_structdef: tabstractrecorddef;
  1244. old_current_genericdef,
  1245. old_current_specializedef: tstoreddef;
  1246. begin
  1247. old_parse_generic:=parse_generic;
  1248. { Add ObjectSymtable to be able to find generic type definitions }
  1249. popclass:=0;
  1250. old_current_structdef:=nil;
  1251. old_current_genericdef:=current_genericdef;
  1252. old_current_specializedef:=current_specializedef;
  1253. current_genericdef:=nil;
  1254. current_specializedef:=nil;
  1255. if assigned(pd.struct) and
  1256. (pd.parast.symtablelevel>=normal_function_level) and
  1257. not (symtablestack.top.symtabletype in [ObjectSymtable,recordsymtable]) then
  1258. begin
  1259. popclass:=push_nested_hierarchy(pd.struct);
  1260. old_current_structdef:=current_structdef;
  1261. current_structdef:=pd.struct;
  1262. end;
  1263. if df_generic in pd.defoptions then
  1264. begin
  1265. if pd.is_generic then
  1266. current_genericdef:=pd
  1267. else if assigned(pd.struct) then
  1268. current_genericdef:=pd.struct
  1269. else
  1270. internalerror(2016090202);
  1271. end;
  1272. if df_specialization in pd.defoptions then
  1273. begin
  1274. if pd.is_specialization then
  1275. current_specializedef:=pd
  1276. else if assigned(pd.struct) then
  1277. current_specializedef:=pd.struct
  1278. else
  1279. internalerror(2016090203);
  1280. end;
  1281. parse_generic:=(df_generic in pd.defoptions);
  1282. if pd.is_generic or pd.is_specialization then
  1283. symtablestack.push(pd.parast);
  1284. pd.returndef:=result_type([stoAllowSpecialization]);
  1285. // Issue #24863, enabled only for the main progra commented out for now because it breaks building of RTL and needs extensive
  1286. // testing and/or RTL patching.
  1287. {
  1288. if ((pd.returndef=cvarianttype) or (pd.returndef=colevarianttype)) and
  1289. not(cs_compilesystem in current_settings.moduleswitches) then
  1290. include(current_module.moduleflags,mf_uses_variants);
  1291. }
  1292. if is_dispinterface(pd.struct) and not is_automatable(pd.returndef) then
  1293. Message1(type_e_not_automatable,pd.returndef.typename);
  1294. if pd.is_generic or pd.is_specialization then
  1295. symtablestack.pop(pd.parast);
  1296. if popclass>0 then
  1297. begin
  1298. current_structdef:=old_current_structdef;
  1299. dec(popclass,pop_nested_hierarchy(pd.struct));
  1300. if popclass<>0 then
  1301. internalerror(201012020);
  1302. end;
  1303. current_genericdef:=old_current_genericdef;
  1304. current_specializedef:=old_current_specializedef;
  1305. parse_generic:=old_parse_generic;
  1306. end;
  1307. begin
  1308. locationstr:='';
  1309. case pd.proctypeoption of
  1310. potype_procedure:
  1311. begin
  1312. pd.returndef:=voidtype;
  1313. if ppf_classmethod in flags then
  1314. include(pd.procoptions,po_classmethod);
  1315. end;
  1316. potype_function:
  1317. begin
  1318. if po_anonymous in pd.procoptions then
  1319. begin
  1320. { allow a different result name for anonymous functions (especially
  1321. for modes without Result modeswitch), but for consistency with
  1322. operators we allow this in other modes as well }
  1323. if token<>_ID then
  1324. begin
  1325. if not(m_result in current_settings.modeswitches) then
  1326. consume(_ID);
  1327. end
  1328. else
  1329. begin
  1330. pd.resultname:=stringdup(orgpattern);
  1331. consume(_ID);
  1332. end;
  1333. end;
  1334. if try_to_consume(_COLON) then
  1335. begin
  1336. read_returndef(pd);
  1337. if (target_info.system in [system_m68k_amiga]) then
  1338. begin
  1339. if (idtoken=_LOCATION) then
  1340. begin
  1341. if po_explicitparaloc in pd.procoptions then
  1342. begin
  1343. consume(_LOCATION);
  1344. locationstr:=cstringpattern;
  1345. consume(_CSTRING);
  1346. end
  1347. else
  1348. { I guess this needs a new message... (KB) }
  1349. Message(parser_e_paraloc_all_paras);
  1350. end
  1351. else
  1352. begin
  1353. if po_explicitparaloc in pd.procoptions then
  1354. { assign default locationstr, if none specified }
  1355. { and we've arguments with explicit paraloc }
  1356. locationstr:='D0';
  1357. end;
  1358. end;
  1359. end
  1360. else
  1361. begin
  1362. if (
  1363. parse_only and
  1364. not(is_interface(pd.struct))
  1365. ) or
  1366. (m_repeat_forward in current_settings.modeswitches) then
  1367. begin
  1368. consume(_COLON);
  1369. consume_all_until(_SEMICOLON);
  1370. end;
  1371. end;
  1372. if ppf_classmethod in flags then
  1373. include(pd.procoptions,po_classmethod);
  1374. end;
  1375. potype_constructor,
  1376. potype_class_constructor:
  1377. begin
  1378. if not (ppf_classmethod in flags) and
  1379. assigned(pd) and
  1380. assigned(pd.struct) then
  1381. begin
  1382. { Set return type, class constructors return the
  1383. created instance, object constructors return boolean }
  1384. if is_class(pd.struct) or
  1385. is_record(pd.struct) or
  1386. is_javaclass(pd.struct) then
  1387. pd.returndef:=pd.struct
  1388. else
  1389. if is_objectpascal_helper(pd.struct) then
  1390. pd.returndef:=tobjectdef(pd.struct).extendeddef
  1391. else
  1392. {$ifdef CPU64bitaddr}
  1393. pd.returndef:=bool64type;
  1394. {$else CPU64bitaddr}
  1395. pd.returndef:=bool32type;
  1396. {$endif CPU64bitaddr}
  1397. end
  1398. else
  1399. pd.returndef:=voidtype;
  1400. end;
  1401. potype_class_destructor,
  1402. potype_destructor:
  1403. begin
  1404. if assigned(pd) then
  1405. pd.returndef:=voidtype;
  1406. end;
  1407. potype_operator:
  1408. begin
  1409. { operators always need to be searched in all units (that
  1410. contain operators) }
  1411. include(pd.procoptions,po_overload);
  1412. pd.procsym.owner.includeoption(sto_has_operator);
  1413. if pd.parast.symtablelevel>normal_function_level then
  1414. Message(parser_e_no_local_operator);
  1415. if ppf_classmethod in flags then
  1416. begin
  1417. include(pd.procoptions,po_classmethod);
  1418. { any class operator is also static }
  1419. include(pd.procoptions,po_staticmethod);
  1420. end;
  1421. if token<>_ID then
  1422. begin
  1423. if not(m_result in current_settings.modeswitches) then
  1424. consume(_ID);
  1425. end
  1426. else
  1427. begin
  1428. pd.resultname:=stringdup(orgpattern);
  1429. consume(_ID);
  1430. end;
  1431. { operators without result (management operators) }
  1432. if optoken in [_OP_INITIALIZE, _OP_FINALIZE, _OP_ADDREF, _OP_COPY] then
  1433. begin
  1434. { single var parameter to point the record }
  1435. if (optoken in [_OP_INITIALIZE, _OP_FINALIZE, _OP_ADDREF]) and
  1436. (
  1437. (pd.parast.SymList.Count<>1) or
  1438. (tparavarsym(pd.parast.SymList[0]).vardef<>pd.struct) or
  1439. (tparavarsym(pd.parast.SymList[0]).varspez<>vs_var)
  1440. ) then
  1441. Message(parser_e_overload_impossible)
  1442. { constref (source) and var (dest) parameter to point the records }
  1443. else if (optoken=_OP_COPY) and
  1444. (
  1445. (pd.parast.SymList.Count<>2) or
  1446. (tparavarsym(pd.parast.SymList[0]).vardef<>pd.struct) or
  1447. (tparavarsym(pd.parast.SymList[0]).varspez<>vs_constref) or
  1448. (tparavarsym(pd.parast.SymList[1]).vardef<>pd.struct) or
  1449. (tparavarsym(pd.parast.SymList[1]).varspez<>vs_var)
  1450. ) then
  1451. Message(parser_e_overload_impossible);
  1452. trecordsymtable(pd.procsym.Owner).includemanagementoperator(
  1453. token2managementoperator(optoken));
  1454. pd.returndef:=voidtype
  1455. end
  1456. else
  1457. if not try_to_consume(_COLON) then
  1458. begin
  1459. consume(_COLON);
  1460. pd.returndef:=generrordef;
  1461. consume_all_until(_SEMICOLON);
  1462. end
  1463. else
  1464. begin
  1465. read_returndef(pd);
  1466. { check that class operators have either return type of structure or }
  1467. { at least one argument of that type }
  1468. if (po_classmethod in pd.procoptions) and
  1469. (pd.returndef <> pd.struct) then
  1470. begin
  1471. found:=false;
  1472. for i := 0 to pd.parast.SymList.Count - 1 do
  1473. if tparavarsym(pd.parast.SymList[i]).vardef=pd.struct then
  1474. begin
  1475. found:=true;
  1476. break;
  1477. end;
  1478. if not found then
  1479. if assigned(pd.struct) then
  1480. Message1(parser_e_at_least_one_argument_must_be_of_type,pd.struct.RttiName)
  1481. else
  1482. MessagePos(pd.fileinfo,type_e_type_id_expected);
  1483. end;
  1484. if not assigned(pd.struct) or assigned(astruct) then
  1485. begin
  1486. if (optoken in [_ASSIGNMENT,_OP_EXPLICIT]) and
  1487. equal_defs(pd.returndef,tparavarsym(pd.parast.SymList[0]).vardef) and
  1488. (pd.returndef.typ<>undefineddef) and (tparavarsym(pd.parast.SymList[0]).vardef.typ<>undefineddef) then
  1489. message(parser_e_no_such_assignment)
  1490. else if not isoperatoracceptable(pd,optoken) then
  1491. Message(parser_e_overload_impossible);
  1492. end;
  1493. end;
  1494. end;
  1495. else
  1496. internalerror(2015052202);
  1497. end;
  1498. if (pd.proccalloption in cdecl_pocalls) and
  1499. (pd.paras.count>0) and
  1500. is_array_of_const(tparavarsym(pd.paras[pd.paras.count-1]).vardef) then
  1501. begin
  1502. include(pd.procoptions,po_variadic);
  1503. end;
  1504. { support procedure proc stdcall export; }
  1505. if not(check_proc_directive(false)) then
  1506. begin
  1507. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1508. begin
  1509. message(parser_e_field_not_allowed_here);
  1510. consume_all_until(_SEMICOLON);
  1511. end;
  1512. if not (ppf_anonymous in flags) then
  1513. consume(_SEMICOLON);
  1514. end;
  1515. if locationstr<>'' then
  1516. begin
  1517. if not(paramanager.parsefuncretloc(pd,upper(locationstr))) then
  1518. { I guess this needs a new message... (KB) }
  1519. message(parser_e_illegal_explicit_paraloc);
  1520. end;
  1521. end;
  1522. function parse_proc_dec(flags:tparse_proc_flags;astruct:tabstractrecorddef):tprocdef;
  1523. var
  1524. pd : tprocdef;
  1525. old_block_type : tblock_type;
  1526. recover : boolean;
  1527. procedure finish_intf_mapping;
  1528. begin
  1529. if token=_COLON then
  1530. begin
  1531. message(parser_e_field_not_allowed_here);
  1532. consume_all_until(_SEMICOLON);
  1533. end;
  1534. consume(_SEMICOLON);
  1535. end;
  1536. begin
  1537. pd:=nil;
  1538. recover:=false;
  1539. case token of
  1540. _FUNCTION :
  1541. begin
  1542. consume(_FUNCTION);
  1543. if parse_proc_head(astruct,potype_function,flags,nil,nil,pd) then
  1544. begin
  1545. { pd=nil when it is a interface mapping }
  1546. if assigned(pd) then
  1547. parse_proc_dec_finish(pd,flags,astruct)
  1548. else
  1549. finish_intf_mapping;
  1550. end
  1551. else
  1552. begin
  1553. { recover }
  1554. consume(_COLON);
  1555. consume_all_until(_SEMICOLON);
  1556. recover:=true;
  1557. end;
  1558. end;
  1559. _PROCEDURE :
  1560. begin
  1561. consume(_PROCEDURE);
  1562. if parse_proc_head(astruct,potype_procedure,flags,nil,nil,pd) then
  1563. begin
  1564. { pd=nil when it is an interface mapping }
  1565. if assigned(pd) then
  1566. parse_proc_dec_finish(pd,flags,astruct)
  1567. else
  1568. finish_intf_mapping;
  1569. end
  1570. else
  1571. recover:=true;
  1572. end;
  1573. _CONSTRUCTOR :
  1574. begin
  1575. consume(_CONSTRUCTOR);
  1576. if ppf_classmethod in flags then
  1577. recover:=not parse_proc_head(astruct,potype_class_constructor,[],nil,nil,pd)
  1578. else
  1579. recover:=not parse_proc_head(astruct,potype_constructor,[],nil,nil,pd);
  1580. if not recover then
  1581. parse_proc_dec_finish(pd,flags,astruct);
  1582. end;
  1583. _DESTRUCTOR :
  1584. begin
  1585. consume(_DESTRUCTOR);
  1586. if ppf_classmethod in flags then
  1587. recover:=not parse_proc_head(astruct,potype_class_destructor,[],nil,nil,pd)
  1588. else
  1589. recover:=not parse_proc_head(astruct,potype_destructor,[],nil,nil,pd);
  1590. if not recover then
  1591. parse_proc_dec_finish(pd,flags,astruct);
  1592. end;
  1593. else
  1594. if (token=_OPERATOR) or
  1595. ((ppf_classmethod in flags) and (idtoken=_OPERATOR)) then
  1596. begin
  1597. { we need to set the block type to bt_body, so that operator names
  1598. like ">", "=>" or "<>" are parsed correctly instead of e.g.
  1599. _LSHARPBRACKET and _RSHARPBRACKET for "<>" }
  1600. old_block_type:=block_type;
  1601. block_type:=bt_body;
  1602. consume(_OPERATOR);
  1603. parse_proc_head(astruct,potype_operator,[],nil,nil,pd);
  1604. block_type:=old_block_type;
  1605. if assigned(pd) then
  1606. parse_proc_dec_finish(pd,flags,astruct)
  1607. else
  1608. begin
  1609. { recover }
  1610. try_to_consume(_ID);
  1611. consume(_COLON);
  1612. consume_all_until(_SEMICOLON);
  1613. recover:=true;
  1614. end;
  1615. end;
  1616. end;
  1617. if recover and not(check_proc_directive(false)) then
  1618. begin
  1619. if (token=_COLON) and not(Assigned(pd) and is_void(pd.returndef)) then
  1620. begin
  1621. message(parser_e_field_not_allowed_here);
  1622. consume_all_until(_SEMICOLON);
  1623. end;
  1624. if not (ppf_anonymous in flags) then
  1625. consume(_SEMICOLON);
  1626. end;
  1627. { we've parsed the final semicolon, so stop recording tokens }
  1628. if assigned(pd) and
  1629. (df_generic in pd.defoptions) and
  1630. assigned(pd.genericdecltokenbuf) then
  1631. current_scanner.stoprecordtokens;
  1632. result:=pd;
  1633. end;
  1634. function parse_record_method_dec(astruct: tabstractrecorddef; is_classdef: boolean;hadgeneric:boolean): tprocdef;
  1635. var
  1636. oldparse_only: boolean;
  1637. flags : tparse_proc_flags;
  1638. begin
  1639. oldparse_only:=parse_only;
  1640. parse_only:=true;
  1641. flags:=[];
  1642. if is_classdef then
  1643. include(flags,ppf_classmethod);
  1644. if hadgeneric then
  1645. include(flags,ppf_generic);
  1646. result:=parse_proc_dec(flags,astruct);
  1647. { this is for error recovery as well as forward }
  1648. { interface mappings, i.e. mapping to a method }
  1649. { which isn't declared yet }
  1650. if assigned(result) then
  1651. begin
  1652. parse_record_proc_directives(result);
  1653. { since records have no inheritance, don't allow non-static
  1654. class methods. Delphi does the same. }
  1655. if (result.proctypeoption<>potype_operator) and
  1656. is_classdef and
  1657. not (po_staticmethod in result.procoptions) then
  1658. MessagePos(result.fileinfo, parser_e_class_methods_only_static_in_records);
  1659. // we can't add hidden params here because record is not yet defined
  1660. // and therefore record size which has influence on parameter passing rules may change too
  1661. // look at record_dec to see where calling conventions are applied (issue #0021044)
  1662. handle_calling_convention(result,hcc_default_actions_intf_struct);
  1663. { add definition to procsym }
  1664. proc_add_definition(result);
  1665. if result.is_generic then
  1666. astruct.symtable.includeoption(sto_has_generic);
  1667. end;
  1668. maybe_parse_hint_directives(result);
  1669. parse_only:=oldparse_only;
  1670. end;
  1671. {****************************************************************************
  1672. Procedure directive handlers
  1673. ****************************************************************************}
  1674. procedure pd_compilerproc(pd:tabstractprocdef);
  1675. var
  1676. v : Tconstexprint;
  1677. begin
  1678. { check for optional syssym index }
  1679. if try_to_consume(_COLON) then
  1680. begin
  1681. v:=get_intconst;
  1682. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1683. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1684. else if not assigned(tsyssym.find_by_number(longint(v.svalue))) then
  1685. message1(parser_e_invalid_internal_function_index,tostr(v))
  1686. else
  1687. tprocdef(pd).extnumber:=longint(v.svalue);
  1688. end;
  1689. end;
  1690. procedure pd_far(pd:tabstractprocdef);
  1691. begin
  1692. pd.declared_far;
  1693. end;
  1694. procedure pd_near(pd:tabstractprocdef);
  1695. begin
  1696. pd.declared_near;
  1697. end;
  1698. procedure pd_export(pd:tabstractprocdef);
  1699. begin
  1700. if pd.typ<>procdef then
  1701. internalerror(200304264);
  1702. if assigned(tprocdef(pd).struct) then
  1703. Message(parser_e_methods_dont_be_export);
  1704. if pd.parast.symtablelevel>normal_function_level then
  1705. Message(parser_e_dont_nest_export);
  1706. end;
  1707. procedure pd_forward(pd:tabstractprocdef);
  1708. begin
  1709. if pd.typ<>procdef then
  1710. internalerror(200304265);
  1711. tprocdef(pd).forwarddef:=true;
  1712. end;
  1713. procedure pd_alias(pd:tabstractprocdef);
  1714. begin
  1715. if pd.typ<>procdef then
  1716. internalerror(200304266);
  1717. consume(_COLON);
  1718. tprocdef(pd).aliasnames.insert(get_stringconst);
  1719. include(pd.procoptions,po_has_public_name);
  1720. end;
  1721. procedure pd_public(pd:tabstractprocdef);
  1722. begin
  1723. if pd.typ<>procdef then
  1724. internalerror(2003042601);
  1725. if try_to_consume(_NAME) then
  1726. begin
  1727. tprocdef(pd).aliasnames.insert(get_stringconst);
  1728. include(pd.procoptions,po_has_public_name);
  1729. end;
  1730. end;
  1731. procedure pd_asmname(pd:tabstractprocdef);
  1732. begin
  1733. if pd.typ<>procdef then
  1734. internalerror(200304267);
  1735. if token=_CCHAR then
  1736. begin
  1737. tprocdef(pd).aliasnames.insert(target_info.Cprefix+pattern);
  1738. consume(_CCHAR)
  1739. end
  1740. else
  1741. begin
  1742. tprocdef(pd).aliasnames.insert(target_info.Cprefix+cstringpattern);
  1743. consume(_CSTRING);
  1744. end;
  1745. { we don't need anything else }
  1746. tprocdef(pd).forwarddef:=false;
  1747. end;
  1748. procedure pd_internconst(pd:tabstractprocdef);
  1749. var v:Tconstexprint;
  1750. begin
  1751. if pd.typ<>procdef then
  1752. internalerror(200304268);
  1753. consume(_COLON);
  1754. v:=get_intconst;
  1755. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1756. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1757. else
  1758. Tprocdef(pd).extnumber:=longint(v.svalue);
  1759. end;
  1760. procedure pd_internproc(pd:tabstractprocdef);
  1761. var v:Tconstexprint;
  1762. begin
  1763. if pd.typ<>procdef then
  1764. internalerror(2003042602);
  1765. consume(_COLON);
  1766. v:=get_intconst;
  1767. if (v<int64(low(longint))) or (v>int64(high(longint))) then
  1768. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(longint)),tostr(high(longint)))
  1769. else
  1770. Tprocdef(pd).extnumber:=longint(v.svalue);
  1771. { the proc is defined }
  1772. tprocdef(pd).forwarddef:=false;
  1773. end;
  1774. procedure pd_interrupt(pd:tabstractprocdef);
  1775. begin
  1776. if pd.parast.symtablelevel>normal_function_level then
  1777. Message(parser_e_dont_nest_interrupt);
  1778. end;
  1779. procedure pd_abstract(pd:tabstractprocdef);
  1780. begin
  1781. if pd.typ<>procdef then
  1782. internalerror(200304269);
  1783. if is_objectpascal_helper(tprocdef(pd).struct) then
  1784. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_ABSTRACT].str);
  1785. if assigned(tprocdef(pd).struct) and
  1786. (oo_is_sealed in tprocdef(pd).struct.objectoptions) then
  1787. Message(parser_e_sealed_class_cannot_have_abstract_methods)
  1788. else if (po_virtualmethod in pd.procoptions) then
  1789. begin
  1790. include(pd.procoptions,po_abstractmethod);
  1791. { one more abstract method }
  1792. inc(tobjectdef(pd.owner.defowner).abstractcnt);
  1793. end
  1794. else
  1795. Message(parser_e_only_virtual_methods_abstract);
  1796. { the method is defined }
  1797. tprocdef(pd).forwarddef:=false;
  1798. end;
  1799. procedure pd_final(pd:tabstractprocdef);
  1800. begin
  1801. if pd.typ<>procdef then
  1802. internalerror(200910170);
  1803. if is_objectpascal_helper(tprocdef(pd).struct) and
  1804. (m_objfpc in current_settings.modeswitches) then
  1805. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_FINAL].str);
  1806. if (po_virtualmethod in pd.procoptions) or
  1807. (is_javaclass(tprocdef(pd).struct) and
  1808. (po_classmethod in pd.procoptions)) then
  1809. include(pd.procoptions,po_finalmethod)
  1810. else
  1811. Message(parser_e_only_virtual_methods_final);
  1812. end;
  1813. procedure pd_enumerator(pd:tabstractprocdef);
  1814. begin
  1815. if pd.typ<>procdef then
  1816. internalerror(200910250);
  1817. if (token = _ID) then
  1818. begin
  1819. if pattern='MOVENEXT' then
  1820. begin
  1821. if oo_has_enumerator_movenext in tprocdef(pd).struct.objectoptions then
  1822. message(parser_e_only_one_enumerator_movenext);
  1823. pd.calcparas;
  1824. if (pd.proctypeoption = potype_function) and is_boolean(pd.returndef) and
  1825. (pd.minparacount = 0) then
  1826. begin
  1827. include(tprocdef(pd).struct.objectoptions, oo_has_enumerator_movenext);
  1828. include(pd.procoptions,po_enumerator_movenext);
  1829. end
  1830. else
  1831. Message(parser_e_enumerator_movenext_is_not_valid)
  1832. end
  1833. else
  1834. Message1(parser_e_invalid_enumerator_identifier, pattern);
  1835. consume(token);
  1836. end
  1837. else
  1838. Message(parser_e_enumerator_identifier_required);
  1839. end;
  1840. procedure pd_virtual(pd:tabstractprocdef);
  1841. {$ifdef WITHDMT}
  1842. var
  1843. pt : tnode;
  1844. {$endif WITHDMT}
  1845. begin
  1846. if assigned(pd.owner) and
  1847. (not assigned(pd.owner.defowner) or
  1848. not is_java_class_or_interface(tdef(pd.owner.defowner))) and
  1849. (po_external in pd.procoptions) then
  1850. Message2(parser_e_proc_dir_conflict,'EXTERNAL','"VIRTUAL"');
  1851. if pd.typ<>procdef then
  1852. internalerror(2003042610);
  1853. if (pd.proctypeoption=potype_constructor) and
  1854. is_object(tprocdef(pd).struct) then
  1855. Message(parser_e_constructor_cannot_be_not_virtual);
  1856. if pd.is_generic then
  1857. message(parser_e_genfuncs_cannot_be_virtual);
  1858. if is_objectpascal_helper(tprocdef(pd).struct) and
  1859. (m_objfpc in current_settings.modeswitches) then
  1860. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_VIRTUAL].str);
  1861. {$ifdef WITHDMT}
  1862. if is_object(tprocdef(pd).struct) and
  1863. (token<>_SEMICOLON) then
  1864. begin
  1865. { any type of parameter is allowed here! }
  1866. pt:=comp_expr(true);
  1867. if is_constintnode(pt) then
  1868. begin
  1869. include(pd.procoptions,po_msgint);
  1870. pd.messageinf.i:=pt.value;
  1871. end
  1872. else
  1873. Message(parser_e_ill_msg_expr);
  1874. disposetree(pt);
  1875. end;
  1876. {$endif WITHDMT}
  1877. end;
  1878. procedure pd_dispid(pd:tabstractprocdef);
  1879. var pt:Tnode;
  1880. begin
  1881. if pd.typ<>procdef then
  1882. internalerror(200604301);
  1883. pt:=comp_expr([ef_accept_equal]);
  1884. if is_constintnode(pt) then
  1885. if (Tordconstnode(pt).value<int64(low(longint))) or (Tordconstnode(pt).value>int64(high(longint))) then
  1886. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(longint)),tostr(high(longint)))
  1887. else
  1888. Tprocdef(pd).dispid:=Tordconstnode(pt).value.svalue
  1889. else
  1890. message(parser_e_dispid_must_be_ord_const);
  1891. pt.free;
  1892. end;
  1893. procedure pd_static(pd:tabstractprocdef);
  1894. begin
  1895. if pd.typ<>procdef then
  1896. internalerror(2013032001);
  1897. if not assigned(tprocdef(pd).struct) then
  1898. internalerror(2013032002);
  1899. include(tprocdef(pd).procsym.symoptions,sp_static);
  1900. { "static" is not allowed for operators or normal methods (except in objects) }
  1901. if (pd.proctypeoption=potype_operator) or
  1902. (
  1903. not (po_classmethod in pd.procoptions) and
  1904. not is_object(tprocdef(pd).struct)
  1905. )
  1906. then
  1907. Message1(parser_e_dir_not_allowed,arraytokeninfo[_STATIC].str);
  1908. include(pd.procoptions,po_staticmethod);
  1909. end;
  1910. procedure pd_override(pd:tabstractprocdef);
  1911. begin
  1912. if pd.typ<>procdef then
  1913. internalerror(2003042611);
  1914. if is_objectpascal_helper(tprocdef(pd).struct) then
  1915. begin
  1916. if m_objfpc in current_settings.modeswitches then
  1917. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_OVERRIDE].str)
  1918. end
  1919. else if not(is_class_or_interface_or_objc_or_java(tprocdef(pd).struct)) then
  1920. Message(parser_e_no_object_override)
  1921. else if is_objccategory(tprocdef(pd).struct) then
  1922. Message(parser_e_no_category_override)
  1923. else if (po_external in pd.procoptions) and
  1924. not is_objc_class_or_protocol(tprocdef(pd).struct) and
  1925. not is_cppclass(tprocdef(pd).struct) and
  1926. not is_java_class_or_interface(tprocdef(pd).struct) then
  1927. Message2(parser_e_proc_dir_conflict,'OVERRIDE','"EXTERNAL"');
  1928. end;
  1929. procedure pd_overload(pd:tabstractprocdef);
  1930. begin
  1931. if pd.typ<>procdef then
  1932. internalerror(2003042612);
  1933. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1934. end;
  1935. procedure pd_message(pd:tabstractprocdef);
  1936. var
  1937. pt : tnode;
  1938. paracnt : longint;
  1939. begin
  1940. if pd.typ<>procdef then
  1941. internalerror(2003042613);
  1942. if is_objectpascal_helper(tprocdef(pd).struct) then
  1943. begin
  1944. if m_objfpc in current_settings.modeswitches then
  1945. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_MESSAGE].str);
  1946. end
  1947. else
  1948. if not is_class(tprocdef(pd).struct) and
  1949. not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1950. Message(parser_e_msg_only_for_classes);
  1951. if ([po_msgstr,po_msgint]*pd.procoptions)<>[] then
  1952. Message(parser_e_multiple_messages);
  1953. { check parameter type }
  1954. if not is_objc_class_or_protocol(tprocdef(pd).struct) then
  1955. begin
  1956. if po_external in pd.procoptions then
  1957. Message2(parser_e_proc_dir_conflict,'MESSAGE','"EXTERNAL"');
  1958. paracnt:=0;
  1959. pd.parast.SymList.ForEachCall(@check_msg_para,@paracnt);
  1960. if paracnt<>1 then
  1961. Message(parser_e_ill_msg_param);
  1962. end;
  1963. pt:=comp_expr([ef_accept_equal]);
  1964. { message is 1-character long }
  1965. if is_constcharnode(pt) then
  1966. begin
  1967. include(pd.procoptions,po_msgstr);
  1968. tprocdef(pd).messageinf.str:=stringdup(chr(byte(tordconstnode(pt).value.uvalue and $FF)));
  1969. end
  1970. else if pt.nodetype=stringconstn then
  1971. begin
  1972. include(pd.procoptions,po_msgstr);
  1973. if (tstringconstnode(pt).len>255) then
  1974. Message(parser_e_message_string_too_long);
  1975. tprocdef(pd).messageinf.str:=stringdup(tstringconstnode(pt).value_str);
  1976. end
  1977. else
  1978. if is_constintnode(pt) and
  1979. (is_class(tprocdef(pd).struct) or
  1980. is_objectpascal_helper(tprocdef(pd).struct)) then
  1981. begin
  1982. include(pd.procoptions,po_msgint);
  1983. if (Tordconstnode(pt).value<int64(low(Tprocdef(pd).messageinf.i))) or
  1984. (Tordconstnode(pt).value>int64(high(Tprocdef(pd).messageinf.i))) then
  1985. message3(type_e_range_check_error_bounds,tostr(Tordconstnode(pt).value),tostr(low(Tprocdef(pd).messageinf.i)),tostr(high(Tprocdef(pd).messageinf.i)))
  1986. else
  1987. Tprocdef(pd).messageinf.i:=tordconstnode(pt).value.svalue;
  1988. end
  1989. else
  1990. Message(parser_e_ill_msg_expr);
  1991. { check whether the selector name is valid in case of Objective-C }
  1992. if (po_msgstr in pd.procoptions) and
  1993. is_objc_class_or_protocol(tprocdef(pd).struct) and
  1994. not objcvalidselectorname(@tprocdef(pd).messageinf.str^[1],length(tprocdef(pd).messageinf.str^)) then
  1995. Message1(type_e_invalid_objc_selector_name,tprocdef(pd).messageinf.str^);
  1996. pt.free;
  1997. end;
  1998. procedure pd_reintroduce(pd:tabstractprocdef);
  1999. begin
  2000. if pd.typ<>procdef then
  2001. internalerror(200401211);
  2002. if is_objectpascal_helper(tprocdef(pd).struct) then
  2003. begin
  2004. if m_objfpc in current_settings.modeswitches then
  2005. Message1(parser_e_not_allowed_in_helper, arraytokeninfo[_REINTRODUCE].str);
  2006. end
  2007. else
  2008. if not(is_class_or_interface_or_object(tprocdef(pd).struct)) and
  2009. not(is_objccategory(tprocdef(pd).struct)) and
  2010. not(is_javaclass(tprocdef(pd).struct)) then
  2011. Message(parser_e_no_object_reintroduce);
  2012. end;
  2013. procedure pd_syscall(pd:tabstractprocdef);
  2014. procedure include_po_syscall;
  2015. var
  2016. syscall: psyscallinfo;
  2017. begin
  2018. case target_info.system of
  2019. system_arm_palmos,
  2020. system_m68k_palmos,
  2021. system_m68k_atari,
  2022. system_m68k_amiga,
  2023. system_powerpc_amiga:
  2024. include(pd.procoptions,get_default_syscall);
  2025. system_powerpc_morphos,
  2026. system_arm_aros,
  2027. system_i386_aros,
  2028. system_x86_64_aros:
  2029. begin
  2030. syscall:=get_syscall_by_token(idtoken);
  2031. if assigned(syscall) then
  2032. begin
  2033. if target_info.system in syscall^.validon then
  2034. begin
  2035. consume(idtoken);
  2036. include(pd.procoptions,syscall^.procoption);
  2037. end
  2038. end
  2039. else
  2040. include(pd.procoptions,get_default_syscall);
  2041. end;
  2042. else
  2043. Message(parser_e_syscall_format_not_support);
  2044. end;
  2045. end;
  2046. function po_syscall_to_varoptions: tvaroptions;
  2047. begin
  2048. result:=[vo_is_syscall_lib,vo_is_hidden_para];
  2049. if ([po_syscall_legacy,po_syscall_basereg,po_syscall_basenone] * tprocdef(pd).procoptions) <> [] then
  2050. include(result,vo_has_explicit_paraloc);
  2051. end;
  2052. function po_syscall_to_regname: string;
  2053. begin
  2054. if po_syscall_legacy in tprocdef(pd).procoptions then
  2055. result:='a6'
  2056. { let nobase on MorphOS store the libbase in r12 as well, because
  2057. we will need the libbase anyway during the call generation }
  2058. else if (po_syscall_basenone in tprocdef(pd).procoptions) and
  2059. (target_info.system = system_powerpc_morphos) then
  2060. result:='r12'
  2061. else if po_syscall_basereg in tprocdef(pd).procoptions then
  2062. begin
  2063. case target_info.system of
  2064. system_i386_aros:
  2065. result:='eax';
  2066. system_x86_64_aros:
  2067. result:='r12';
  2068. system_powerpc_morphos:
  2069. result:='r12';
  2070. else
  2071. internalerror(2016090201);
  2072. end;
  2073. end
  2074. else
  2075. internalerror(2016090101);
  2076. end;
  2077. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2078. const
  2079. syscall_paranr: array[boolean] of aint =
  2080. ( paranr_syscall_lib_last, paranr_syscall_lib_first );
  2081. var
  2082. vs : tparavarsym;
  2083. sym : tsym;
  2084. symtable : TSymtable;
  2085. v: Tconstexprint;
  2086. vo: tvaroptions;
  2087. paranr: aint;
  2088. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2089. begin
  2090. if (pd.typ<>procdef) and (target_info.system <> system_powerpc_amiga) then
  2091. internalerror(2003042614);
  2092. tprocdef(pd).forwarddef:=false;
  2093. {$if defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2094. include_po_syscall;
  2095. if target_info.system in [system_arm_palmos, system_m68k_palmos] then
  2096. begin
  2097. v:=get_intconst;
  2098. tprocdef(pd).extnumber:=longint(v.svalue);
  2099. if ((v<0) or (v>high(word))) then
  2100. message(parser_e_range_check_error);
  2101. if try_to_consume(_COMMA) then
  2102. begin
  2103. v:=get_intconst;
  2104. if ((v<0) or (v>high(word))) then
  2105. message(parser_e_range_check_error);
  2106. tprocdef(pd).import_nr:=longint(v.svalue);
  2107. include(pd.procoptions,po_syscall_has_importnr);
  2108. end;
  2109. exit;
  2110. end;
  2111. if target_info.system = system_m68k_atari then
  2112. begin
  2113. v:=get_intconst;
  2114. if ((v<0) or (v>15)) then
  2115. message(parser_e_range_check_error)
  2116. else
  2117. tprocdef(pd).extnumber:=longint(v.svalue);
  2118. v:=get_intconst;
  2119. if ((v<0) or (v>high(smallint))) then
  2120. message(parser_e_range_check_error)
  2121. else
  2122. tprocdef(pd).import_nr:=longint(v.svalue);
  2123. exit;
  2124. end;
  2125. if consume_sym(sym,symtable) then
  2126. if ((sym.typ=staticvarsym) or
  2127. (sym.typ=absolutevarsym) and (tabsolutevarsym(sym).abstyp=toaddr)) and
  2128. ((tabstractvarsym(sym).vardef.typ=pointerdef) or
  2129. is_32bitint(tabstractvarsym(sym).vardef)) then
  2130. begin
  2131. include(pd.procoptions,po_syscall_has_libsym);
  2132. tcpuprocdef(pd).libsym:=sym;
  2133. vo:=po_syscall_to_varoptions;
  2134. paranr:=syscall_paranr[po_syscall_basefirst in tprocdef(pd).procoptions];
  2135. vs:=cparavarsym.create('$syscalllib',paranr,vs_value,tabstractvarsym(sym).vardef,vo);
  2136. if vo_has_explicit_paraloc in vo then
  2137. if not paramanager.parseparaloc(vs,po_syscall_to_regname) then
  2138. internalerror(2016120301);
  2139. pd.parast.insertsym(vs);
  2140. end
  2141. else
  2142. Message(parser_e_32bitint_or_pointer_variable_expected);
  2143. paramanager.create_funcretloc_info(pd,calleeside);
  2144. paramanager.create_funcretloc_info(pd,callerside);
  2145. v:=get_intconst;
  2146. if (v<low(Tprocdef(pd).extnumber)) or (v>high(Tprocdef(pd).extnumber)) then
  2147. message3(type_e_range_check_error_bounds,tostr(v),tostr(low(Tprocdef(pd).extnumber)),tostr(high(Tprocdef(pd).extnumber)))
  2148. else
  2149. if target_info.system in [system_arm_aros,system_i386_aros,system_x86_64_aros] then
  2150. Tprocdef(pd).extnumber:=v.uvalue * sizeof(pint)
  2151. else
  2152. Tprocdef(pd).extnumber:=v.uvalue;
  2153. {$endif defined(powerpc) or defined(m68k) or defined(i386) or defined(x86_64) or defined(arm)}
  2154. end;
  2155. procedure pd_external(pd:tabstractprocdef);
  2156. {
  2157. If import_dll=nil the procedure is assumed to be in another
  2158. object file. In that object file it should have the name to
  2159. which import_name is pointing to. Otherwise, the procedure is
  2160. assumed to be in the DLL to which import_dll is pointing to. In
  2161. that case either import_nr<>0 or import_name<>nil is true, so
  2162. the procedure is either imported by number or by name. (DM)
  2163. }
  2164. var
  2165. hs : string;
  2166. v:Tconstexprint;
  2167. is_java_external: boolean;
  2168. begin
  2169. if pd.typ<>procdef then
  2170. internalerror(2003042615);
  2171. { Allow specifying a separate external name for methods in external Java
  2172. because its identifier naming constraints are laxer than FPC's
  2173. (e.g., case sensitive).
  2174. Limitation: only allows specifying the symbol name and not the package name,
  2175. and only for external classes/interfaces }
  2176. is_java_external:=
  2177. (pd.typ=procdef) and
  2178. is_java_class_or_interface(tdef(pd.owner.defowner)) and
  2179. (oo_is_external in tobjectdef(pd.owner.defowner).objectoptions);
  2180. with tprocdef(pd) do
  2181. begin
  2182. forwarddef:=false;
  2183. { forbid local external procedures }
  2184. if parast.symtablelevel>normal_function_level then
  2185. Message(parser_e_no_local_proc_external);
  2186. { If the procedure should be imported from a DLL, a constant string follows.
  2187. This isn't really correct, an contant string expression follows
  2188. so we check if an semicolon follows, else a string constant have to
  2189. follow (FK) }
  2190. if not is_java_external and
  2191. not(token=_SEMICOLON) and not(idtoken=_NAME) then
  2192. begin
  2193. { Always add library prefix and suffix to create an uniform name }
  2194. hs:=get_stringconst;
  2195. if ExtractFileExt(hs)='' then
  2196. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  2197. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  2198. hs:=target_info.sharedlibprefix+hs;
  2199. { the JVM expects java/lang/Object rather than java.lang.Object }
  2200. if target_info.system in systems_jvm then
  2201. Replace(hs,'.','/');
  2202. import_dll:=stringdup(hs);
  2203. include(procoptions,po_has_importdll);
  2204. if (idtoken=_NAME) then
  2205. begin
  2206. consume(_NAME);
  2207. import_name:=stringdup(get_stringconst);
  2208. include(procoptions,po_has_importname);
  2209. if import_name^='' then
  2210. message(parser_e_empty_import_name);
  2211. end;
  2212. if (idtoken=_INDEX) then
  2213. begin
  2214. {After the word index follows the index number in the DLL.}
  2215. consume(_INDEX);
  2216. v:=get_intconst;
  2217. if (v<int64(low(import_nr))) or (v>int64(high(import_nr))) then
  2218. message(parser_e_range_check_error)
  2219. else
  2220. import_nr:=longint(v.svalue);
  2221. end;
  2222. { default is to used the realname of the procedure }
  2223. if (import_nr=0) and not assigned(import_name) then
  2224. begin
  2225. import_name:=stringdup(procsym.realname);
  2226. include(procoptions,po_has_importname);
  2227. end;
  2228. end
  2229. else
  2230. begin
  2231. if (idtoken=_NAME) or
  2232. is_java_external then
  2233. begin
  2234. consume(_NAME);
  2235. import_name:=stringdup(get_stringconst);
  2236. include(procoptions,po_has_importname);
  2237. if import_name^='' then
  2238. message(parser_e_empty_import_name);
  2239. end;
  2240. end;
  2241. end;
  2242. end;
  2243. procedure pd_weakexternal(pd:tabstractprocdef);
  2244. begin
  2245. if not(target_info.system in systems_weak_linking) then
  2246. message(parser_e_weak_external_not_supported)
  2247. else
  2248. pd_external(pd);
  2249. end;
  2250. procedure pd_winapi(pd:tabstractprocdef);
  2251. begin
  2252. if not(target_info.system in systems_all_windows+[system_i386_nativent]) then
  2253. pd.proccalloption:=pocall_cdecl
  2254. else
  2255. pd.proccalloption:=pocall_stdcall;
  2256. include(pd.procoptions,po_hascallingconvention);
  2257. end;
  2258. procedure pd_hardfloat(pd:tabstractprocdef);
  2259. begin
  2260. if
  2261. {$if defined(arm)}
  2262. (current_settings.fputype=fpu_soft) or
  2263. {$endif defined(arm)}
  2264. (cs_fp_emulation in current_settings.moduleswitches) then
  2265. message(parser_e_cannot_use_hardfloat_in_a_softfloat_environment);
  2266. end;
  2267. procedure pd_section(pd:tabstractprocdef);
  2268. begin
  2269. if pd.typ<>procdef then
  2270. internalerror(2021032801);
  2271. if not (target_info.system in systems_allow_section) then
  2272. Message(parser_e_section_directive_not_allowed_for_target);
  2273. {$ifdef symansistr}
  2274. tprocdef(pd).section:=get_stringconst;
  2275. {$else symansistr}
  2276. tprocdef(pd).section:=stringdup(get_stringconst);
  2277. {$endif}
  2278. end;
  2279. type
  2280. pd_handler=procedure(pd:tabstractprocdef);
  2281. proc_dir_rec=record
  2282. idtok : ttoken;
  2283. pd_flags : tpdflags;
  2284. handler : pd_handler;
  2285. pocall : tproccalloption;
  2286. pooption : tprocoptions;
  2287. mutexclpocall : tproccalloptions;
  2288. mutexclpotype : tproctypeoptions;
  2289. mutexclpo : tprocoptions;
  2290. end;
  2291. const
  2292. {Should contain the number of procedure directives we support.}
  2293. num_proc_directives=54;
  2294. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  2295. (
  2296. (
  2297. idtok:_ABSTRACT;
  2298. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2299. handler : @pd_abstract;
  2300. pocall : pocall_none;
  2301. pooption : [po_abstractmethod];
  2302. mutexclpocall : [pocall_internproc];
  2303. mutexclpotype : [];
  2304. mutexclpo : [po_exports,po_interrupt,po_inline]
  2305. ),(
  2306. idtok:_ALIAS;
  2307. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2308. handler : @pd_alias;
  2309. pocall : pocall_none;
  2310. pooption : [];
  2311. mutexclpocall : [];
  2312. mutexclpotype : [];
  2313. mutexclpo : [po_external,po_inline]
  2314. ),(
  2315. idtok:_ASMNAME;
  2316. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  2317. handler : @pd_asmname;
  2318. pocall : pocall_cdecl;
  2319. pooption : [po_external];
  2320. mutexclpocall : [pocall_internproc];
  2321. mutexclpotype : [];
  2322. mutexclpo : [po_external,po_inline]
  2323. ),(
  2324. idtok:_ASSEMBLER;
  2325. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2326. handler : nil;
  2327. pocall : pocall_none;
  2328. pooption : [po_assembler];
  2329. mutexclpocall : [];
  2330. mutexclpotype : [];
  2331. mutexclpo : [po_external]
  2332. ),(
  2333. idtok:_C; {same as cdecl for mode mac}
  2334. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2335. handler : nil;
  2336. pocall : pocall_cdecl;
  2337. pooption : [];
  2338. mutexclpocall : [];
  2339. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2340. mutexclpo : [po_assembler,po_external]
  2341. ),(
  2342. idtok:_CBLOCK;
  2343. pd_flags : [pd_procvar];
  2344. handler : nil;
  2345. pocall : pocall_none;
  2346. pooption : [po_is_block];
  2347. mutexclpocall : [];
  2348. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2349. mutexclpo : [po_assembler,po_external]
  2350. ),(
  2351. idtok:_CDECL;
  2352. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2353. handler : nil;
  2354. pocall : pocall_cdecl;
  2355. pooption : [];
  2356. mutexclpocall : [];
  2357. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2358. mutexclpo : [po_assembler,po_external]
  2359. ),(
  2360. idtok:_DISPID;
  2361. pd_flags : [pd_dispinterface];
  2362. handler : @pd_dispid;
  2363. pocall : pocall_none;
  2364. pooption : [po_dispid];
  2365. mutexclpocall : [pocall_internproc];
  2366. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2367. mutexclpo : [po_interrupt,po_external,po_inline]
  2368. ),(
  2369. idtok:_DYNAMIC;
  2370. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord];
  2371. handler : @pd_virtual;
  2372. pocall : pocall_none;
  2373. pooption : [po_virtualmethod];
  2374. mutexclpocall : [pocall_internproc];
  2375. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2376. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod,po_inline]
  2377. ),(
  2378. idtok:_EXPORT;
  2379. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf,pd_notrecord,pd_nothelper];
  2380. handler : @pd_export;
  2381. pocall : pocall_none;
  2382. pooption : [po_exports,po_global];
  2383. mutexclpocall : [pocall_internproc];
  2384. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2385. mutexclpo : [po_external,po_interrupt,po_inline]
  2386. ),(
  2387. idtok:_EXTERNAL;
  2388. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper,pd_javaclass,pd_intfjava];
  2389. handler : @pd_external;
  2390. pocall : pocall_none;
  2391. pooption : [po_external];
  2392. mutexclpocall : [pocall_syscall];
  2393. { allowed for external cpp classes }
  2394. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2395. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2396. ),(
  2397. idtok:_FAR;
  2398. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2399. handler : @pd_far;
  2400. pocall : pocall_none;
  2401. pooption : [];
  2402. mutexclpocall : [pocall_internproc];
  2403. mutexclpotype : [];
  2404. mutexclpo : [po_inline]
  2405. ),(
  2406. idtok:_FAR16;
  2407. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject,pd_notrecord,pd_nothelper];
  2408. handler : nil;
  2409. pocall : pocall_far16;
  2410. pooption : [];
  2411. mutexclpocall : [];
  2412. mutexclpotype : [];
  2413. mutexclpo : [po_external]
  2414. ),(
  2415. idtok:_FINAL;
  2416. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2417. handler : @pd_final;
  2418. pocall : pocall_none;
  2419. pooption : [po_finalmethod];
  2420. mutexclpocall : [pocall_internproc];
  2421. mutexclpotype : [];
  2422. mutexclpo : [po_exports,po_interrupt,po_inline]
  2423. ),(
  2424. idtok:_FORWARD;
  2425. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2426. handler : @pd_forward;
  2427. pocall : pocall_none;
  2428. pooption : [];
  2429. mutexclpocall : [pocall_internproc];
  2430. mutexclpotype : [];
  2431. mutexclpo : [po_external,po_inline]
  2432. ),(
  2433. idtok:_OLDFPCCALL;
  2434. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2435. handler : nil;
  2436. pocall : pocall_oldfpccall;
  2437. pooption : [];
  2438. mutexclpocall : [];
  2439. mutexclpotype : [];
  2440. mutexclpo : []
  2441. ),(
  2442. idtok:_INLINE;
  2443. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2444. handler : nil;
  2445. pocall : pocall_none;
  2446. pooption : [po_inline];
  2447. mutexclpocall : [pocall_safecall];
  2448. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2449. mutexclpo : [po_noinline,po_exports,po_external,po_interrupt,po_virtualmethod,po_iocheck]
  2450. ),(
  2451. idtok:_NOINLINE;
  2452. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2453. handler : nil;
  2454. pocall : pocall_none;
  2455. pooption : [po_noinline];
  2456. mutexclpocall : [];
  2457. mutexclpotype : [];
  2458. mutexclpo : [po_inline,po_external]
  2459. ),(
  2460. idtok:_INTERNCONST;
  2461. pd_flags : [pd_interface,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2462. handler : @pd_internconst;
  2463. pocall : pocall_none;
  2464. pooption : [po_internconst];
  2465. mutexclpocall : [];
  2466. mutexclpotype : [potype_operator];
  2467. mutexclpo : []
  2468. ),(
  2469. idtok:_INTERNPROC;
  2470. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2471. handler : @pd_internproc;
  2472. pocall : pocall_internproc;
  2473. pooption : [];
  2474. mutexclpocall : [];
  2475. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2476. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  2477. ),(
  2478. idtok:_INTERRUPT;
  2479. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2480. handler : @pd_interrupt;
  2481. {$ifdef i386}
  2482. pocall : pocall_oldfpccall;
  2483. {$else i386}
  2484. pocall : pocall_stdcall;
  2485. {$endif i386}
  2486. pooption : [po_interrupt];
  2487. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,pocall_mwpascal,
  2488. pocall_pascal,pocall_far16,pocall_oldfpccall,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  2489. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2490. mutexclpo : [po_external,po_inline,po_exports]
  2491. ),(
  2492. idtok:_IOCHECK;
  2493. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  2494. handler : nil;
  2495. pocall : pocall_none;
  2496. pooption : [po_iocheck];
  2497. mutexclpocall : [pocall_internproc];
  2498. mutexclpotype : [];
  2499. mutexclpo : [po_external]
  2500. ),(
  2501. idtok:_LOCAL;
  2502. pd_flags : [pd_implemen,pd_body];
  2503. handler : nil;
  2504. pocall : pocall_none;
  2505. pooption : [po_kylixlocal];
  2506. mutexclpocall : [pocall_internproc,pocall_far16];
  2507. mutexclpotype : [];
  2508. mutexclpo : [po_external,po_exports]
  2509. ),(
  2510. idtok:_MESSAGE;
  2511. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_objcprot,pd_notrecord];
  2512. handler : @pd_message;
  2513. pocall : pocall_none;
  2514. pooption : []; { can be po_msgstr or po_msgint }
  2515. mutexclpocall : [pocall_internproc];
  2516. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2517. mutexclpo : [po_interrupt,po_inline]
  2518. ),(
  2519. idtok:_MWPASCAL;
  2520. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2521. handler : nil;
  2522. pocall : pocall_mwpascal;
  2523. pooption : [];
  2524. mutexclpocall : [];
  2525. mutexclpotype : [];
  2526. mutexclpo : []
  2527. ),(
  2528. idtok:_NEAR;
  2529. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf,pd_notrecord,pd_nothelper];
  2530. handler : @pd_near;
  2531. pocall : pocall_none;
  2532. pooption : [];
  2533. mutexclpocall : [pocall_internproc];
  2534. mutexclpotype : [];
  2535. mutexclpo : []
  2536. ),(
  2537. idtok:_NORETURN;
  2538. pd_flags : [pd_implemen,pd_interface,pd_body,pd_notobjintf];
  2539. handler : nil;
  2540. pocall : pocall_none;
  2541. pooption : [po_noreturn];
  2542. mutexclpocall : [];
  2543. mutexclpotype : [potype_constructor,potype_destructor,potype_operator,potype_class_constructor,potype_class_destructor];
  2544. mutexclpo : [po_interrupt,po_virtualmethod,po_iocheck]
  2545. ),(
  2546. idtok:_NOSTACKFRAME;
  2547. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  2548. handler : nil;
  2549. pocall : pocall_none;
  2550. pooption : [po_nostackframe];
  2551. mutexclpocall : [pocall_internproc];
  2552. mutexclpotype : [];
  2553. mutexclpo : []
  2554. ),(
  2555. idtok:_OVERLOAD;
  2556. pd_flags : [pd_implemen,pd_interface,pd_body,pd_javaclass,pd_intfjava,pd_objcclass,pd_objcprot];
  2557. handler : @pd_overload;
  2558. pocall : pocall_none;
  2559. pooption : [po_overload];
  2560. mutexclpocall : [pocall_internproc];
  2561. mutexclpotype : [];
  2562. mutexclpo : []
  2563. ),(
  2564. idtok:_OVERRIDE;
  2565. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_javaclass,pd_intfjava,pd_notrecord];
  2566. handler : @pd_override;
  2567. pocall : pocall_none;
  2568. pooption : [po_overridingmethod,po_virtualmethod];
  2569. mutexclpocall : [pocall_internproc];
  2570. mutexclpotype : [];
  2571. mutexclpo : [po_exports,po_interrupt,po_virtualmethod,po_inline]
  2572. ),(
  2573. idtok:_PASCAL;
  2574. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2575. handler : nil;
  2576. pocall : pocall_pascal;
  2577. pooption : [];
  2578. mutexclpocall : [];
  2579. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2580. mutexclpo : [po_external]
  2581. ),(
  2582. idtok:_PUBLIC;
  2583. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2584. handler : @pd_public;
  2585. pocall : pocall_none;
  2586. pooption : [po_public,po_global];
  2587. mutexclpocall : [pocall_internproc];
  2588. mutexclpotype : [];
  2589. mutexclpo : [po_external,po_inline]
  2590. ),(
  2591. idtok:_REGISTER;
  2592. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2593. handler : nil;
  2594. pocall : pocall_register;
  2595. pooption : [];
  2596. mutexclpocall : [];
  2597. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2598. mutexclpo : [po_external]
  2599. ),(
  2600. idtok:_REINTRODUCE;
  2601. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_objcclass,pd_notrecord,pd_javaclass];
  2602. handler : @pd_reintroduce;
  2603. pocall : pocall_none;
  2604. pooption : [po_reintroduce];
  2605. mutexclpocall : [pocall_internproc];
  2606. mutexclpotype : [];
  2607. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod,po_inline]
  2608. ),(
  2609. idtok:_SAFECALL;
  2610. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2611. handler : nil;
  2612. pocall : pocall_safecall;
  2613. pooption : [];
  2614. mutexclpocall : [];
  2615. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2616. mutexclpo : [po_external]
  2617. ),(
  2618. idtok:_SECTION;
  2619. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobject,pd_notobjintf,pd_notrecord,pd_nothelper];
  2620. handler : @pd_section;
  2621. pocall : pocall_none;
  2622. pooption : [po_public,po_global];
  2623. mutexclpocall : [pocall_internproc];
  2624. mutexclpotype : [];
  2625. mutexclpo : [po_external,po_inline,po_interrupt]
  2626. ),(
  2627. idtok:_SOFTFLOAT;
  2628. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2629. handler : nil;
  2630. pocall : pocall_softfloat;
  2631. pooption : [];
  2632. mutexclpocall : [];
  2633. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2634. { it's available with po_external because the libgcc floating point routines on the arm
  2635. uses this calling convention }
  2636. mutexclpo : []
  2637. ),(
  2638. idtok:_STATIC;
  2639. pd_flags : [pd_interface,pd_implemen,pd_body,pd_object,pd_record,pd_javaclass,pd_notobjintf];
  2640. handler : @pd_static;
  2641. pocall : pocall_none;
  2642. pooption : [po_staticmethod];
  2643. mutexclpocall : [pocall_internproc];
  2644. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2645. mutexclpo : [po_interrupt,po_exports,po_virtualmethod]
  2646. ),(
  2647. idtok:_STDCALL;
  2648. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2649. handler : nil;
  2650. pocall : pocall_stdcall;
  2651. pooption : [];
  2652. mutexclpocall : [];
  2653. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2654. mutexclpo : [po_external]
  2655. ),(
  2656. idtok:_SYSCALL;
  2657. { Different kind of syscalls are valid for AOS68k, AOSPPC and MOS. }
  2658. { FIX ME!!! MorphOS/AOS68k pd_flags should be:
  2659. pd_interface, pd_implemen, pd_notobject, pd_notobjintf (KB) }
  2660. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  2661. handler : @pd_syscall;
  2662. pocall : pocall_syscall;
  2663. pooption : [];
  2664. mutexclpocall : [];
  2665. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2666. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  2667. ),(
  2668. idtok:_VIRTUAL;
  2669. pd_flags : [pd_interface,pd_object,pd_notobjintf,pd_notrecord,pd_javaclass];
  2670. handler : @pd_virtual;
  2671. pocall : pocall_none;
  2672. pooption : [po_virtualmethod];
  2673. mutexclpocall : [pocall_internproc];
  2674. mutexclpotype : [potype_class_constructor,potype_class_destructor];
  2675. mutexclpo : PD_VIRTUAL_MUTEXCLPO
  2676. ),(
  2677. idtok:_CPPDECL;
  2678. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2679. handler : nil;
  2680. pocall : pocall_cppdecl;
  2681. pooption : [];
  2682. mutexclpocall : [];
  2683. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2684. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  2685. ),(
  2686. idtok:_VARARGS;
  2687. pd_flags : [pd_interface,pd_implemen,pd_procvar,pd_objcclass,pd_objcprot];
  2688. handler : nil;
  2689. pocall : pocall_none;
  2690. pooption : [po_varargs];
  2691. mutexclpocall : [pocall_internproc,pocall_register,
  2692. pocall_far16,pocall_oldfpccall,pocall_mwpascal];
  2693. mutexclpotype : [];
  2694. mutexclpo : [po_assembler,po_interrupt,po_inline]
  2695. ),(
  2696. idtok:_COMPILERPROC;
  2697. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2698. handler : @pd_compilerproc;
  2699. pocall : pocall_none;
  2700. pooption : [po_compilerproc];
  2701. mutexclpocall : [];
  2702. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2703. mutexclpo : [po_interrupt]
  2704. ),(
  2705. idtok:_WEAKEXTERNAL;
  2706. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf,pd_cppobject,pd_notrecord,pd_nothelper];
  2707. handler : @pd_weakexternal;
  2708. pocall : pocall_none;
  2709. { mark it both external and weak external, so we don't have to
  2710. adapt all code for external symbols to also check for weak external
  2711. }
  2712. pooption : [po_external,po_weakexternal];
  2713. mutexclpocall : [pocall_internproc,pocall_syscall];
  2714. { allowed for external cpp classes }
  2715. mutexclpotype : [{potype_constructor,potype_destructor}potype_class_constructor,potype_class_destructor];
  2716. mutexclpo : [po_public,po_exports,po_interrupt,po_assembler,po_inline]
  2717. ),(
  2718. idtok:_WINAPI;
  2719. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2720. handler : @pd_winapi;
  2721. pocall : pocall_none;
  2722. pooption : [];
  2723. mutexclpocall : [pocall_stdcall,pocall_cdecl,pocall_mwpascal,pocall_sysv_abi_cdecl,pocall_ms_abi_cdecl];
  2724. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2725. mutexclpo : [po_external]
  2726. ),(
  2727. idtok:_ENUMERATOR;
  2728. pd_flags : [pd_interface,pd_object,pd_record];
  2729. handler : @pd_enumerator;
  2730. pocall : pocall_none;
  2731. pooption : [];
  2732. mutexclpocall : [pocall_internproc];
  2733. mutexclpotype : [];
  2734. mutexclpo : [po_exports,po_interrupt,po_external,po_inline]
  2735. ),(
  2736. idtok:_RTLPROC;
  2737. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  2738. handler : nil;
  2739. pocall : pocall_none;
  2740. pooption : [po_rtlproc];
  2741. mutexclpocall : [];
  2742. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2743. mutexclpo : [po_interrupt]
  2744. ),(
  2745. idtok:_HARDFLOAT;
  2746. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2747. handler : @pd_hardfloat;
  2748. pocall : pocall_hardfloat;
  2749. pooption : [];
  2750. mutexclpocall : [];
  2751. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2752. { it's available with po_external because the libgcc floating point routines on the arm
  2753. uses this calling convention }
  2754. mutexclpo : []
  2755. ),(
  2756. idtok:_SYSV_ABI_DEFAULT;
  2757. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2758. handler : nil;
  2759. pocall : pocall_sysv_abi_default;
  2760. pooption : [];
  2761. mutexclpocall : [];
  2762. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2763. mutexclpo : [po_interrupt]
  2764. ),(
  2765. idtok:_SYSV_ABI_CDECL;
  2766. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2767. handler : nil;
  2768. pocall : pocall_sysv_abi_cdecl;
  2769. pooption : [];
  2770. mutexclpocall : [];
  2771. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2772. mutexclpo : [po_interrupt]
  2773. ),(
  2774. idtok:_MS_ABI_DEFAULT;
  2775. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2776. handler : nil;
  2777. pocall : pocall_ms_abi_default;
  2778. pooption : [];
  2779. mutexclpocall : [];
  2780. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2781. mutexclpo : [po_interrupt]
  2782. ),(
  2783. idtok:_MS_ABI_CDECL;
  2784. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2785. handler : nil;
  2786. pocall : pocall_ms_abi_cdecl;
  2787. pooption : [];
  2788. mutexclpocall : [];
  2789. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2790. mutexclpo : [po_interrupt]
  2791. ),(
  2792. idtok:_VECTORCALL;
  2793. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  2794. handler : nil;
  2795. pocall : pocall_vectorcall;
  2796. pooption : [];
  2797. mutexclpocall : [];
  2798. mutexclpotype : [potype_constructor,potype_destructor,potype_class_constructor,potype_class_destructor];
  2799. mutexclpo : [po_interrupt]
  2800. )
  2801. );
  2802. function check_proc_directive(isprocvar:boolean):boolean;
  2803. var
  2804. i : longint;
  2805. begin
  2806. result:=false;
  2807. for i:=1 to num_proc_directives do
  2808. if proc_direcdata[i].idtok=idtoken then
  2809. begin
  2810. if ((not isprocvar) or
  2811. (pd_procvar in proc_direcdata[i].pd_flags)) and
  2812. { don't eat a public directive in classes }
  2813. not((idtoken=_PUBLIC) and (symtablestack.top.symtabletype=ObjectSymtable)) then
  2814. result:=true;
  2815. exit;
  2816. end;
  2817. end;
  2818. function find_proc_directive_index(tok: ttoken): longint; inline;
  2819. begin
  2820. result:=-1;
  2821. for result:=1 to num_proc_directives do
  2822. if proc_direcdata[result].idtok=tok then
  2823. exit;
  2824. result:=-1;
  2825. end;
  2826. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  2827. {
  2828. Parse the procedure directive, returns true if a correct directive is found
  2829. }
  2830. var
  2831. p : longint;
  2832. name : TIDString;
  2833. po_comp : tprocoptions;
  2834. tokenloc : TFilePosInfo;
  2835. begin
  2836. parse_proc_direc:=false;
  2837. name:=tokeninfo^[idtoken].str;
  2838. { Hint directive? Then exit immediatly }
  2839. if (m_hintdirective in current_settings.modeswitches) then
  2840. begin
  2841. case idtoken of
  2842. _LIBRARY,
  2843. _PLATFORM,
  2844. _UNIMPLEMENTED,
  2845. _EXPERIMENTAL,
  2846. _DEPRECATED :
  2847. if (m_delphi in current_settings.modeswitches) and (pd.typ=procdef) then
  2848. begin
  2849. maybe_parse_hint_directives(tprocdef(pd));
  2850. { could the new token still be a directive? }
  2851. if token<>_ID then
  2852. exit;
  2853. end
  2854. else
  2855. exit;
  2856. else
  2857. ;
  2858. end;
  2859. end;
  2860. { C directive is MacPas only, because it breaks too much existing code
  2861. on other platforms (PFV) }
  2862. if (idtoken=_C) and
  2863. not(m_mac in current_settings.modeswitches) then
  2864. exit;
  2865. { retrieve data for directive if found }
  2866. p:=find_proc_directive_index(idtoken);
  2867. { Check if the procedure directive is known }
  2868. if p=-1 then
  2869. begin
  2870. { parsing a procvar type the name can be any
  2871. next variable !! }
  2872. if ((pdflags * [pd_procvar,pd_object,pd_record,pd_objcclass,pd_objcprot])=[]) and
  2873. not(idtoken in [_PROPERTY,_GENERIC]) then
  2874. Message1(parser_w_unknown_proc_directive_ignored,pattern);
  2875. exit;
  2876. end;
  2877. { check if method and directive not for object, like public.
  2878. This needs to be checked also for procvars }
  2879. if (pd_notobject in proc_direcdata[p].pd_flags) and
  2880. (symtablestack.top.symtabletype=ObjectSymtable) and
  2881. { directive allowed for cpp classes? }
  2882. not((pd_cppobject in proc_direcdata[p].pd_flags) and is_cppclass(tdef(symtablestack.top.defowner))) and
  2883. not((pd_javaclass in proc_direcdata[p].pd_flags) and is_javaclass(tdef(symtablestack.top.defowner))) and
  2884. not((pd_intfjava in proc_direcdata[p].pd_flags) and is_javainterface(tdef(symtablestack.top.defowner))) then
  2885. exit;
  2886. if (pd_notrecord in proc_direcdata[p].pd_flags) and
  2887. (symtablestack.top.symtabletype=recordsymtable) then
  2888. exit;
  2889. { check if method and directive not for java class }
  2890. if not(pd_javaclass in proc_direcdata[p].pd_flags) and
  2891. is_javaclass(tdef(symtablestack.top.defowner)) then
  2892. exit;
  2893. { check if method and directive not for java interface }
  2894. if not(pd_intfjava in proc_direcdata[p].pd_flags) and
  2895. is_javainterface(tdef(symtablestack.top.defowner)) then
  2896. exit;
  2897. { Keep track of the token's position in the file so it's correctly indicated if an error occurs. }
  2898. tokenloc := current_tokenpos;
  2899. { consume directive, and turn flag on }
  2900. consume(token);
  2901. parse_proc_direc:=true;
  2902. { Conflicts between directives? }
  2903. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) then
  2904. begin
  2905. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,ProcTypeOptionKeywords[pd.proctypeoption]);
  2906. exit;
  2907. end;
  2908. if (pd.proccalloption in proc_direcdata[p].mutexclpocall) then
  2909. begin
  2910. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,'"' + UpCase(proccalloptionStr[pd.proccalloption]) + '"');
  2911. exit;
  2912. end;
  2913. po_comp := (pd.procoptions*proc_direcdata[p].mutexclpo);
  2914. if (po_comp<>[]) then
  2915. begin
  2916. MessagePos2(tokenloc, parser_e_proc_dir_conflict,name,get_first_proc_str(po_comp));
  2917. exit;
  2918. end;
  2919. { set calling convention }
  2920. if proc_direcdata[p].pocall<>pocall_none then
  2921. begin
  2922. if (po_hascallingconvention in pd.procoptions) then
  2923. begin
  2924. MessagePos2(tokenloc, parser_w_proc_overriding_calling,
  2925. proccalloptionStr[pd.proccalloption],
  2926. proccalloptionStr[proc_direcdata[p].pocall]);
  2927. end;
  2928. { check if the target processor supports this calling convention }
  2929. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  2930. begin
  2931. MessagePos1(tokenloc, parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  2932. { recover }
  2933. proc_direcdata[p].pocall:=pocall_stdcall;
  2934. end;
  2935. pd.proccalloption:=proc_direcdata[p].pocall;
  2936. include(pd.procoptions,po_hascallingconvention);
  2937. end;
  2938. if pd.typ=procdef then
  2939. begin
  2940. { Check if the directive is only for objects }
  2941. if (pd_object in proc_direcdata[p].pd_flags) and
  2942. not assigned(tprocdef(pd).struct) then
  2943. exit;
  2944. { Check if the directive is only for records }
  2945. if (pd_record in proc_direcdata[p].pd_flags) and
  2946. not assigned(tprocdef(pd).struct) then
  2947. exit;
  2948. { check if method and directive not for interface }
  2949. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  2950. is_interface(tprocdef(pd).struct) then
  2951. exit;
  2952. { check if method and directive not for interface }
  2953. if is_dispinterface(tprocdef(pd).struct) and
  2954. not(pd_dispinterface in proc_direcdata[p].pd_flags) then
  2955. exit;
  2956. { check if method and directive not for objcclass }
  2957. if is_objcclass(tprocdef(pd).struct) and
  2958. not(pd_objcclass in proc_direcdata[p].pd_flags) then
  2959. exit;
  2960. { check if method and directive not for objcprotocol }
  2961. if is_objcprotocol(tprocdef(pd).struct) and
  2962. not(pd_objcprot in proc_direcdata[p].pd_flags) then
  2963. exit;
  2964. { check if method and directive not for record/class helper }
  2965. if is_objectpascal_helper(tprocdef(pd).struct) and
  2966. (pd_nothelper in proc_direcdata[p].pd_flags) then
  2967. exit;
  2968. end;
  2969. { Check the pd_flags if the directive should be allowed }
  2970. if (pd_interface in pdflags) and
  2971. not(pd_interface in proc_direcdata[p].pd_flags) then
  2972. begin
  2973. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_interface,name);
  2974. exit;
  2975. end;
  2976. if (pd_implemen in pdflags) and
  2977. not(pd_implemen in proc_direcdata[p].pd_flags) then
  2978. begin
  2979. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_implementation,name);
  2980. exit;
  2981. end;
  2982. if (pd_procvar in pdflags) and
  2983. not(pd_procvar in proc_direcdata[p].pd_flags) then
  2984. begin
  2985. MessagePos1(tokenloc, parser_e_proc_dir_not_allowed_in_procvar,name);
  2986. exit;
  2987. end;
  2988. { Return the new pd_flags }
  2989. if not(pd_body in proc_direcdata[p].pd_flags) then
  2990. exclude(pdflags,pd_body);
  2991. { Add the correct flag }
  2992. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  2993. { Call the handler }
  2994. if pointer(proc_direcdata[p].handler)<>nil then
  2995. proc_direcdata[p].handler(pd);
  2996. end;
  2997. function proc_get_importname(pd:tprocdef):string;
  2998. var
  2999. dllname, importname : string;
  3000. begin
  3001. result:='';
  3002. if not(po_external in pd.procoptions) then
  3003. internalerror(200412151);
  3004. { external name or number is specified }
  3005. if assigned(pd.import_name) or (pd.import_nr<>0) then
  3006. begin
  3007. if assigned(pd.import_dll) then
  3008. dllname:=pd.import_dll^
  3009. else
  3010. dllname:='';
  3011. if assigned(pd.import_name) then
  3012. importname:=pd.import_name^
  3013. else
  3014. importname:='';
  3015. proc_get_importname:=make_dllmangledname(dllname,
  3016. importname,pd.import_nr,pd.proccalloption);
  3017. end
  3018. else
  3019. begin
  3020. { Default names when importing variables }
  3021. case pd.proccalloption of
  3022. pocall_cdecl,
  3023. pocall_sysv_abi_cdecl,
  3024. pocall_ms_abi_cdecl:
  3025. begin
  3026. if assigned(pd.struct) then
  3027. result:=target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname
  3028. else
  3029. result:=target_info.Cprefix+pd.procsym.realname;
  3030. end;
  3031. pocall_cppdecl :
  3032. begin
  3033. result:=target_info.Cprefix+pd.cplusplusmangledname;
  3034. end;
  3035. else
  3036. begin
  3037. {In MacPas a single "external" has the same effect as "external name 'xxx'" }
  3038. { but according to MacPas mode description
  3039. Cprefix should still be used PM }
  3040. if (m_mac in current_settings.modeswitches) then
  3041. result:=target_info.Cprefix+tprocdef(pd).procsym.realname
  3042. else
  3043. result:=pd.procsym.realname;
  3044. {$ifdef i8086}
  3045. { Turbo Pascal expects names of external routines
  3046. to be all uppercase }
  3047. if (target_info.system=system_i8086_msdos) and
  3048. (m_tp7 in current_settings.modeswitches) and
  3049. (pd.proccalloption=pocall_pascal) then
  3050. result:=UpCase(result);
  3051. {$endif i8086}
  3052. end;
  3053. end;
  3054. end;
  3055. end;
  3056. procedure proc_set_mangledname(pd:tprocdef);
  3057. var
  3058. s : string;
  3059. begin
  3060. { When the mangledname is already set we aren't allowed to change
  3061. it because it can already be used somewhere (PFV) }
  3062. if not(po_has_mangledname in pd.procoptions) then
  3063. begin
  3064. if (po_external in pd.procoptions) then
  3065. begin
  3066. { External Procedures are only allowed to change the mangledname
  3067. in their first declaration }
  3068. if (pd.forwarddef or (not pd.hasforward)) then
  3069. begin
  3070. s:=proc_get_importname(pd);
  3071. if s<>'' then
  3072. begin
  3073. pd.setmangledname(s);
  3074. end;
  3075. { since this is an external declaration, there won't be an
  3076. implementation that needs to match the original symbol
  3077. again -> immediately convert here }
  3078. if po_compilerproc in pd.procoptions then
  3079. pd.setcompilerprocname;
  3080. end
  3081. end
  3082. else
  3083. { Normal procedures }
  3084. begin
  3085. if (po_compilerproc in pd.procoptions) then
  3086. begin
  3087. pd.setmangledname(lower(pd.procsym.name));
  3088. end;
  3089. end;
  3090. end;
  3091. { Public/exported alias names }
  3092. if (([po_public,po_exports]*pd.procoptions)<>[]) and
  3093. not(po_has_public_name in pd.procoptions) then
  3094. begin
  3095. case pd.proccalloption of
  3096. pocall_cdecl,
  3097. pocall_sysv_abi_cdecl,
  3098. pocall_ms_abi_cdecl:
  3099. begin
  3100. if assigned(pd.struct) then
  3101. pd.aliasnames.insert(target_info.Cprefix+pd.struct.objrealname^+'_'+pd.procsym.realname)
  3102. else
  3103. begin
  3104. { Export names are not mangled on Windows and OS/2, see also pexports.pas }
  3105. if (target_info.system in (systems_all_windows+[system_i386_emx, system_i386_os2])) and
  3106. (po_exports in pd.procoptions) then
  3107. pd.aliasnames.insert(pd.procsym.realname)
  3108. else
  3109. pd.aliasnames.insert(target_info.Cprefix+pd.procsym.realname);
  3110. end;
  3111. end;
  3112. pocall_cppdecl :
  3113. begin
  3114. pd.aliasnames.insert(target_info.Cprefix+pd.cplusplusmangledname);
  3115. end;
  3116. else
  3117. ;
  3118. end;
  3119. { prevent adding the alias a second time }
  3120. include(pd.procoptions,po_has_public_name);
  3121. end;
  3122. end;
  3123. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  3124. {
  3125. Parse the procedure directives. It does not matter if procedure directives
  3126. are written using ;procdir; or ['procdir'] syntax.
  3127. }
  3128. var
  3129. stoprecording,
  3130. res : boolean;
  3131. begin
  3132. if (m_mac in current_settings.modeswitches) and (cs_externally_visible in current_settings.localswitches) then
  3133. begin
  3134. tprocdef(pd).aliasnames.insert(target_info.Cprefix+tprocdef(pd).procsym.realname);
  3135. include(pd.procoptions,po_public);
  3136. include(pd.procoptions,po_has_public_name);
  3137. include(pd.procoptions,po_global);
  3138. end;
  3139. { methods from external class definitions are all external themselves }
  3140. if (pd.typ=procdef) and
  3141. assigned(tprocdef(pd).struct) and
  3142. (tprocdef(pd).struct.typ=objectdef) and
  3143. (oo_is_external in tobjectdef(tprocdef(pd).struct).objectoptions) then
  3144. tprocdef(pd).make_external;
  3145. { Class constructors and destructor are static class methods in real. }
  3146. { There are many places in the compiler where either class or static }
  3147. { method flag changes the behavior. It is simplier to add them to }
  3148. { the class constructors/destructors options than to fix all the }
  3149. { occurencies. (Paul) }
  3150. if pd.proctypeoption in [potype_class_constructor,potype_class_destructor] then
  3151. begin
  3152. include(pd.procoptions,po_classmethod);
  3153. include(pd.procoptions,po_staticmethod);
  3154. end;
  3155. { for a generic routine we also need to record the procedure }
  3156. { directives, but only if we aren't already recording for a }
  3157. { surrounding generic }
  3158. if pd.is_generic and (pd.typ=procdef) and not current_scanner.is_recording_tokens then
  3159. begin
  3160. current_scanner.startrecordtokens(tprocdef(pd).genericdecltokenbuf);
  3161. stoprecording:=true;
  3162. end
  3163. else
  3164. stoprecording:=false;
  3165. while (token=_ID) or
  3166. (
  3167. not (m_prefixed_attributes in current_settings.modeswitches) and
  3168. (token=_LECKKLAMMER)
  3169. ) do
  3170. begin
  3171. if not (m_prefixed_attributes in current_settings.modeswitches) and
  3172. try_to_consume(_LECKKLAMMER) then
  3173. begin
  3174. repeat
  3175. parse_proc_direc(pd,pdflags);
  3176. until not try_to_consume(_COMMA);
  3177. consume(_RECKKLAMMER);
  3178. { we always expect at least '[];' }
  3179. res:=true;
  3180. end
  3181. else
  3182. begin
  3183. res:=parse_proc_direc(pd,pdflags);
  3184. end;
  3185. { A procedure directive normally followed by a semicolon, but in
  3186. a const section or reading a type we should stop when _EQ is found,
  3187. because a constant/default value follows }
  3188. if res then
  3189. begin
  3190. if (block_type=bt_const_type) and
  3191. (token=_EQ) then
  3192. break;
  3193. { support procedure proc;stdcall export; }
  3194. if not(check_proc_directive((pd.typ=procvardef))) then
  3195. begin
  3196. { support "record p : procedure stdcall end;" and
  3197. "var p : procedure stdcall = nil;" }
  3198. if (
  3199. (pd_procvar in pdflags) and
  3200. (token in [_END,_RKLAMMER,_EQ])
  3201. ) or (
  3202. (po_anonymous in pd.procoptions) and
  3203. (token in [_BEGIN,_VAR,_CONST,_TYPE,_LABEL,_FUNCTION,_PROCEDURE,_OPERATOR])
  3204. ) then
  3205. break
  3206. else
  3207. begin
  3208. if (token=_COLON) then
  3209. begin
  3210. Message(parser_e_field_not_allowed_here);
  3211. consume_all_until(_SEMICOLON);
  3212. end;
  3213. consume(_SEMICOLON)
  3214. end;
  3215. end;
  3216. end
  3217. else
  3218. break;
  3219. end;
  3220. if stoprecording then
  3221. current_scanner.stoprecordtokens;
  3222. { nostackframe requires assembler, but assembler
  3223. may be specified in the implementation part only,
  3224. and in not required if the function is first forward declared
  3225. if it is a procdef that has forwardef set to true
  3226. we postpone the possible error message to the real implementation
  3227. parse_only does not need to be considered as po_nostackframe
  3228. is an implementation only directive }
  3229. if (po_nostackframe in pd.procoptions) and
  3230. not (po_assembler in pd.procoptions) and
  3231. ((pd.typ<>procdef) or not tprocdef(pd).forwarddef) then
  3232. message(parser_e_nostackframe_without_assembler);
  3233. end;
  3234. procedure parse_proctype_directives(pd_or_invkdef:tdef);
  3235. var
  3236. pdflags : tpdflags;
  3237. pd : tabstractprocdef;
  3238. begin
  3239. if is_funcref(pd_or_invkdef) then
  3240. pd:=get_invoke_procdef(tobjectdef(pd_or_invkdef))
  3241. else if pd_or_invkdef.typ=procvardef then
  3242. pd:=tprocvardef(pd_or_invkdef)
  3243. else
  3244. internalerror(2022012501);
  3245. pdflags:=[pd_procvar];
  3246. parse_proc_directives(pd,pdflags);
  3247. end;
  3248. procedure parse_object_proc_directives(pd:tprocdef);
  3249. var
  3250. pdflags : tpdflags;
  3251. begin
  3252. pdflags:=[pd_object];
  3253. parse_proc_directives(pd,pdflags);
  3254. end;
  3255. procedure parse_record_proc_directives(pd:tprocdef);
  3256. var
  3257. pdflags : tpdflags;
  3258. begin
  3259. pdflags:=[pd_record];
  3260. parse_proc_directives(pd,pdflags);
  3261. end;
  3262. end.