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