ptype.pas 77 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does parsing types for Free Pascal
  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 ptype;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,cclasses,
  22. symtype,symdef,symbase;
  23. type
  24. TSingleTypeOption=(
  25. stoIsForwardDef, { foward declaration }
  26. stoAllowTypeDef, { allow type definitions }
  27. stoAllowSpecialization, { allow type specialization }
  28. stoParseClassParent { parse of parent class type }
  29. );
  30. TSingleTypeOptions=set of TSingleTypeOption;
  31. procedure resolve_forward_types;
  32. { reads a string, file type or a type identifier }
  33. procedure single_type(var def:tdef;options:TSingleTypeOptions);
  34. { reads any type declaration, where the resulting type will get name as type identifier }
  35. procedure read_named_type(var def:tdef;const newsym:tsym;genericdef:tstoreddef;genericlist:tfphashobjectlist;parseprocvardir:boolean;var hadtypetoken:boolean);
  36. { reads any type declaration }
  37. procedure read_anon_type(var def : tdef;parseprocvardir:boolean);
  38. { parse nested type declaration of the def (typedef) }
  39. procedure parse_nested_types(var def: tdef; isforwarddef: boolean; currentstructstack: tfpobjectlist);
  40. { add a definition for a method to a record/objectdef that will contain
  41. all code for initialising typed constants (only for targets in
  42. systems.systems_typed_constants_node_init) }
  43. procedure add_typedconst_init_routine(def: tabstractrecorddef);
  44. { parse hint directives (platform, deprecated, ...) for a procdef }
  45. procedure maybe_parse_hint_directives(pd:tprocdef);
  46. implementation
  47. uses
  48. { common }
  49. cutils,
  50. { global }
  51. globals,tokens,verbose,constexp,
  52. systems,
  53. { target }
  54. paramgr,procinfo,
  55. { symtable }
  56. symconst,symsym,symtable,symcreat,
  57. defutil,defcmp,
  58. {$ifdef jvm}
  59. jvmdef,
  60. {$endif}
  61. { modules }
  62. fmodule,
  63. { pass 1 }
  64. node,
  65. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  66. { parser }
  67. scanner,
  68. pbase,pexpr,pdecsub,pdecvar,pdecobj,pdecl,pgenutil
  69. {$ifdef jvm}
  70. ,pjvm
  71. {$endif}
  72. ;
  73. procedure maybe_parse_hint_directives(pd:tprocdef);
  74. var
  75. dummysymoptions : tsymoptions;
  76. deprecatedmsg : pshortstring;
  77. begin
  78. if assigned(pd) then
  79. begin
  80. dummysymoptions:=pd.symoptions;
  81. deprecatedmsg:=pd.deprecatedmsg;
  82. end
  83. else
  84. begin
  85. dummysymoptions:=[];
  86. deprecatedmsg:=nil;
  87. end;
  88. while try_consume_hintdirective(dummysymoptions,deprecatedmsg) do
  89. consume(_SEMICOLON);
  90. if assigned(pd) then
  91. begin
  92. pd.symoptions:=pd.symoptions+dummysymoptions;
  93. if sp_has_deprecated_msg in dummysymoptions then
  94. pd.deprecatedmsg:=deprecatedmsg;
  95. end
  96. else
  97. stringdispose(deprecatedmsg);
  98. end;
  99. procedure resolve_forward_types;
  100. var
  101. i: longint;
  102. hpd,
  103. def : tdef;
  104. srsym : tsym;
  105. srsymtable : TSymtable;
  106. hs : string;
  107. begin
  108. for i:=0 to current_module.checkforwarddefs.Count-1 do
  109. begin
  110. def:=tdef(current_module.checkforwarddefs[i]);
  111. case def.typ of
  112. pointerdef,
  113. classrefdef :
  114. begin
  115. { classrefdef inherits from pointerdef }
  116. hpd:=tabstractpointerdef(def).pointeddef;
  117. { still a forward def ? }
  118. if hpd.typ=forwarddef then
  119. begin
  120. { try to resolve the forward }
  121. if not assigned(tforwarddef(hpd).tosymname) then
  122. internalerror(200211201);
  123. hs:=tforwarddef(hpd).tosymname^;
  124. searchsym(upper(hs),srsym,srsymtable);
  125. { we don't need the forwarddef anymore, dispose it }
  126. hpd.free;
  127. tabstractpointerdef(def).pointeddef:=nil; { if error occurs }
  128. { was a type sym found ? }
  129. if assigned(srsym) and
  130. (srsym.typ=typesym) then
  131. begin
  132. tabstractpointerdef(def).pointeddef:=ttypesym(srsym).typedef;
  133. { avoid wrong unused warnings web bug 801 PM }
  134. inc(ttypesym(srsym).refs);
  135. { we need a class type for classrefdef }
  136. if (def.typ=classrefdef) and
  137. not(is_class(ttypesym(srsym).typedef)) and
  138. not(is_objcclass(ttypesym(srsym).typedef)) and
  139. not(is_javaclass(ttypesym(srsym).typedef)) then
  140. MessagePos1(def.typesym.fileinfo,type_e_class_type_expected,ttypesym(srsym).typedef.typename);
  141. { this could also be a generic dummy that was not
  142. overridden with a specific type }
  143. if (sp_generic_dummy in srsym.symoptions) and
  144. (
  145. (ttypesym(srsym).typedef.typ=undefineddef) or
  146. (
  147. { or an unspecialized generic symbol, which is
  148. the case for generics defined in non-Delphi
  149. modes }
  150. tstoreddef(ttypesym(srsym).typedef).is_generic and
  151. not parse_generic
  152. )
  153. ) then
  154. MessagePos(def.typesym.fileinfo,parser_e_no_generics_as_types);
  155. end
  156. else
  157. begin
  158. Message1(sym_e_forward_type_not_resolved,hs);
  159. { try to recover }
  160. tabstractpointerdef(def).pointeddef:=generrordef;
  161. end;
  162. end;
  163. end;
  164. objectdef :
  165. begin
  166. { give an error as the implementation may follow in an
  167. other type block which is allowed by FPC modes }
  168. if not(m_fpc in current_settings.modeswitches) and
  169. (oo_is_forward in tobjectdef(def).objectoptions) then
  170. MessagePos1(def.typesym.fileinfo,type_e_type_is_not_completly_defined,def.typename);
  171. end;
  172. else
  173. internalerror(200811071);
  174. end;
  175. end;
  176. current_module.checkforwarddefs.clear;
  177. end;
  178. procedure id_type(var def : tdef;isforwarddef,checkcurrentrecdef,allowgenericsyms:boolean;out srsym:tsym;out srsymtable:tsymtable); forward;
  179. { def is the outermost type in which other types have to be searched
  180. isforward indicates whether the current definition can be a forward definition
  181. if assigned, currentstructstack is a list of tabstractrecorddefs that, from
  182. last to first, are child types of def that are not yet visible via the
  183. normal symtable searching routines because they are types that are currently
  184. being parsed (so using id_type on them after pushing def on the
  185. symtablestack would result in errors because they'd come back as errordef)
  186. }
  187. procedure parse_nested_types(var def: tdef; isforwarddef: boolean; currentstructstack: tfpobjectlist);
  188. var
  189. t2: tdef;
  190. structstackindex: longint;
  191. srsym: tsym;
  192. srsymtable: tsymtable;
  193. oldsymtablestack: TSymtablestack;
  194. begin
  195. if assigned(currentstructstack) then
  196. structstackindex:=currentstructstack.count-1
  197. else
  198. structstackindex:=-1;
  199. { handle types inside classes, e.g. TNode.TLongint }
  200. while (token=_POINT) do
  201. begin
  202. if is_class_or_object(def) or is_record(def) or is_java_class_or_interface(def) then
  203. begin
  204. if (def.typ=objectdef) then
  205. def:=find_real_class_definition(tobjectdef(def),false);
  206. consume(_POINT);
  207. if (structstackindex>=0) and
  208. (tabstractrecorddef(currentstructstack[structstackindex]).objname^=pattern) then
  209. begin
  210. def:=tdef(currentstructstack[structstackindex]);
  211. dec(structstackindex);
  212. consume(_ID);
  213. end
  214. else
  215. begin
  216. structstackindex:=-1;
  217. oldsymtablestack:=symtablestack;
  218. symtablestack:=TSymtablestack.create;
  219. symtablestack.push(tabstractrecorddef(def).symtable);
  220. t2:=generrordef;
  221. id_type(t2,isforwarddef,false,false,srsym,srsymtable);
  222. symtablestack.pop(tabstractrecorddef(def).symtable);
  223. symtablestack.free;
  224. symtablestack:=oldsymtablestack;
  225. def:=t2;
  226. end;
  227. end
  228. else
  229. break;
  230. end;
  231. end;
  232. function try_parse_structdef_nested_type(out def: tdef; basedef: tabstractrecorddef; isfowarddef: boolean): boolean;
  233. var
  234. structdef : tdef;
  235. structdefstack : tfpobjectlist;
  236. begin
  237. def:=nil;
  238. { use of current parsed object:
  239. classes, objects, records can be used also in themself }
  240. structdef:=basedef;
  241. structdefstack:=nil;
  242. while assigned(structdef) and (structdef.typ in [objectdef,recorddef]) do
  243. begin
  244. if (tabstractrecorddef(structdef).objname^=pattern) then
  245. begin
  246. consume(_ID);
  247. def:=structdef;
  248. { we found the top-most match, now check how far down we can
  249. follow }
  250. structdefstack:=tfpobjectlist.create(false);
  251. structdef:=basedef;
  252. while (structdef<>def) do
  253. begin
  254. structdefstack.add(structdef);
  255. structdef:=tabstractrecorddef(structdef.owner.defowner);
  256. end;
  257. parse_nested_types(def,isfowarddef,structdefstack);
  258. structdefstack.free;
  259. result:=true;
  260. exit;
  261. end;
  262. structdef:=tdef(tabstractrecorddef(structdef).owner.defowner);
  263. end;
  264. result:=false;
  265. end;
  266. procedure id_type(var def : tdef;isforwarddef,checkcurrentrecdef,allowgenericsyms:boolean;out srsym:tsym;out srsymtable:tsymtable);
  267. { reads a type definition }
  268. { to a appropriating tdef, s gets the name of }
  269. { the type to allow name mangling }
  270. var
  271. is_unit_specific,not_a_type : boolean;
  272. pos : tfileposinfo;
  273. s,sorg : TIDString;
  274. t : ttoken;
  275. begin
  276. srsym:=nil;
  277. srsymtable:=nil;
  278. s:=pattern;
  279. sorg:=orgpattern;
  280. pos:=current_tokenpos;
  281. { use of current parsed object:
  282. classes, objects, records can be used also in themself }
  283. if checkcurrentrecdef and
  284. try_parse_structdef_nested_type(def,current_structdef,isforwarddef) then
  285. exit;
  286. { Use the special searchsym_type that search only types }
  287. if not searchsym_type(s,srsym,srsymtable) then
  288. { for a good error message we need to know whether the symbol really did not exist or
  289. whether we found a non-type one }
  290. not_a_type:=searchsym(s,srsym,srsymtable)
  291. else
  292. not_a_type:=false;
  293. { handle unit specification like System.Writeln }
  294. is_unit_specific:=try_consume_unitsym(srsym,srsymtable,t,true);
  295. consume(t);
  296. if not_a_type then
  297. begin
  298. { reset the symbol and symtable to not leak any unexpected values }
  299. srsym:=nil;
  300. srsymtable:=nil;
  301. end;
  302. { Types are first defined with an error def before assigning
  303. the real type so check if it's an errordef. if so then
  304. give an error. Only check for typesyms in the current symbol
  305. table as forwarddef are not resolved directly }
  306. if assigned(srsym) and
  307. (srsym.typ=typesym) and
  308. ((ttypesym(srsym).typedef.typ=errordef) or
  309. (not allowgenericsyms and
  310. (ttypesym(srsym).typedef.typ=undefineddef) and
  311. not (sp_generic_para in srsym.symoptions))) then
  312. begin
  313. Message1(type_e_type_is_not_completly_defined,ttypesym(srsym).realname);
  314. def:=generrordef;
  315. exit;
  316. end;
  317. { are we parsing a possible forward def ? }
  318. if isforwarddef and
  319. not(is_unit_specific) then
  320. begin
  321. def:=cforwarddef.create(sorg,pos);
  322. exit;
  323. end;
  324. { unknown sym ? }
  325. if not assigned(srsym) and not not_a_type then
  326. begin
  327. Message1(sym_e_id_not_found,sorg);
  328. def:=generrordef;
  329. exit;
  330. end;
  331. { type sym ? }
  332. if not_a_type or (srsym.typ<>typesym) then
  333. begin
  334. Message(type_e_type_id_expected);
  335. def:=generrordef;
  336. exit;
  337. end;
  338. { Give an error when referring to an errordef }
  339. if (ttypesym(srsym).typedef.typ=errordef) then
  340. begin
  341. Message(sym_e_error_in_type_def);
  342. def:=generrordef;
  343. exit;
  344. end;
  345. { In non-Delphi modes the class/record name of a generic might be used
  346. in the declaration of sub types without type parameters; in that case
  347. we need to check by name as the link from the dummy symbol to the
  348. current type is not yet established }
  349. if (sp_generic_dummy in srsym.symoptions) and
  350. assigned(current_structdef) and
  351. (df_generic in current_structdef.defoptions) and
  352. (ttypesym(srsym).typedef.typ=undefineddef) and
  353. not (m_delphi in current_settings.modeswitches) then
  354. begin
  355. def:=get_generic_in_hierarchy_by_name(srsym,current_structdef);
  356. if assigned(def) then
  357. exit;
  358. end;
  359. def:=ttypesym(srsym).typedef;
  360. end;
  361. procedure single_type(var def:tdef;options:TSingleTypeOptions);
  362. var
  363. t2 : tdef;
  364. dospecialize,
  365. again : boolean;
  366. srsym : tsym;
  367. srsymtable : tsymtable;
  368. begin
  369. dospecialize:=false;
  370. srsym:=nil;
  371. repeat
  372. again:=false;
  373. case token of
  374. _STRING:
  375. string_dec(def,stoAllowTypeDef in options);
  376. _FILE:
  377. begin
  378. consume(_FILE);
  379. if (token=_OF) then
  380. begin
  381. if not(stoAllowTypeDef in options) then
  382. Message(parser_e_no_local_para_def);
  383. consume(_OF);
  384. single_type(t2,[stoAllowTypeDef]);
  385. if is_managed_type(t2) then
  386. Message(parser_e_no_refcounted_typed_file);
  387. def:=cfiledef.createtyped(t2);
  388. end
  389. else
  390. def:=cfiletype;
  391. end;
  392. _ID:
  393. begin
  394. if try_to_consume(_SPECIALIZE) then
  395. begin
  396. if ([stoAllowSpecialization,stoAllowTypeDef] * options = []) then
  397. begin
  398. Message(parser_e_no_local_para_def);
  399. { try to recover }
  400. while token<>_SEMICOLON do
  401. consume(token);
  402. def:=generrordef;
  403. end
  404. else
  405. begin
  406. dospecialize:=true;
  407. again:=true;
  408. end;
  409. end
  410. else
  411. begin
  412. id_type(def,stoIsForwardDef in options,true,true,srsym,srsymtable);
  413. parse_nested_types(def,stoIsForwardDef in options,nil);
  414. end;
  415. end;
  416. else
  417. begin
  418. message(type_e_type_id_expected);
  419. def:=generrordef;
  420. end;
  421. end;
  422. until not again;
  423. if ([stoAllowSpecialization,stoAllowTypeDef] * options <> []) and
  424. (m_delphi in current_settings.modeswitches) then
  425. dospecialize:=token in [_LSHARPBRACKET,_LT];
  426. if dospecialize and
  427. (def.typ=forwarddef) then
  428. begin
  429. if not assigned(srsym) or not (srsym.typ=typesym) then
  430. begin
  431. Message1(type_e_type_is_not_completly_defined,def.typename);
  432. def:=generrordef;
  433. dospecialize:=false;
  434. end;
  435. end;
  436. if dospecialize then
  437. begin
  438. if def.typ=forwarddef then
  439. def:=ttypesym(srsym).typedef;
  440. generate_specialization(def,stoParseClassParent in options,'');
  441. parse_nested_types(def,stoIsForwardDef in options,nil);
  442. end
  443. else
  444. begin
  445. if assigned(current_specializedef) and (def=current_specializedef.genericdef) then
  446. begin
  447. def:=current_specializedef
  448. end
  449. else if (def=current_genericdef) then
  450. begin
  451. def:=current_genericdef
  452. end
  453. { when parsing a nested specialization in non-Delphi mode it might
  454. use the name of the topmost generic without type paramaters, thus
  455. def will contain the generic definition, but we need a reference
  456. to the specialization of that generic }
  457. { TODO : only in non-Delphi modes? }
  458. else if assigned(current_structdef) and
  459. (df_specialization in current_structdef.defoptions) and
  460. return_specialization_of_generic(current_structdef,def,t2) then
  461. begin
  462. def:=t2
  463. end
  464. else if tstoreddef(def).is_generic and
  465. not
  466. (
  467. parse_generic and
  468. (
  469. { if this is a generic parameter than it has already been checked that this is
  470. a valid usage of a generic }
  471. (sp_generic_para in srsym.symoptions) or
  472. (
  473. (current_genericdef.typ in [recorddef,objectdef]) and
  474. (
  475. { if both defs belong to the same generic (e.g. both are
  476. subtypes) then we must allow the usage }
  477. defs_belong_to_same_generic(def,current_genericdef) or
  478. { this is needed to correctly resolve "type Foo=SomeGeneric<T>"
  479. declarations inside a generic }
  480. sym_is_owned_by(srsym,tabstractrecorddef(current_genericdef).symtable)
  481. )
  482. )
  483. )
  484. )
  485. then
  486. begin
  487. srsym:=resolve_generic_dummysym(srsym.name);
  488. if assigned(srsym) and
  489. not (sp_generic_dummy in srsym.symoptions) and
  490. (srsym.typ=typesym) then
  491. def:=ttypesym(srsym).typedef
  492. else
  493. begin
  494. Message(parser_e_no_generics_as_types);
  495. def:=generrordef;
  496. end;
  497. end
  498. else if (def.typ=undefineddef) and
  499. (sp_generic_dummy in srsym.symoptions) and
  500. parse_generic and
  501. (current_genericdef.typ in [recorddef,objectdef]) and
  502. (Pos(upper(srsym.realname),tabstractrecorddef(current_genericdef).objname^)=1) then
  503. begin
  504. if m_delphi in current_settings.modeswitches then
  505. begin
  506. srsym:=resolve_generic_dummysym(srsym.name);
  507. if assigned(srsym) and
  508. not (sp_generic_dummy in srsym.symoptions) and
  509. (srsym.typ=typesym) then
  510. def:=ttypesym(srsym).typedef
  511. else
  512. begin
  513. Message(parser_e_no_generics_as_types);
  514. def:=generrordef;
  515. end;
  516. end
  517. else
  518. def:=current_genericdef;
  519. end
  520. else if is_classhelper(def) and
  521. not (stoParseClassParent in options) then
  522. begin
  523. Message(parser_e_no_category_as_types);
  524. def:=generrordef
  525. end
  526. end;
  527. end;
  528. procedure parse_record_members(recsym:tsym);
  529. function IsAnonOrLocal: Boolean;
  530. begin
  531. result:=(current_structdef.objname^='') or
  532. not(symtablestack.stack^.next^.symtable.symtabletype in [globalsymtable,staticsymtable,objectsymtable,recordsymtable]);
  533. end;
  534. var
  535. olddef : tdef;
  536. procedure set_typesym;
  537. begin
  538. if not assigned(recsym) then
  539. exit;
  540. if ttypesym(recsym).typedef=current_structdef then
  541. exit;
  542. ttypesym(recsym).typedef:=current_structdef;
  543. current_structdef.typesym:=recsym;
  544. end;
  545. procedure reset_typesym;
  546. begin
  547. if not assigned(recsym) then
  548. exit;
  549. if ttypesym(recsym).typedef<>current_structdef then
  550. exit;
  551. ttypesym(recsym).typedef:=olddef;
  552. current_structdef.typesym:=nil;
  553. end;
  554. var
  555. pd : tprocdef;
  556. oldparse_only: boolean;
  557. member_blocktype : tblock_type;
  558. fields_allowed, is_classdef, classfields: boolean;
  559. vdoptions: tvar_dec_options;
  560. begin
  561. { empty record declaration ? }
  562. if (token=_SEMICOLON) then
  563. Exit;
  564. { the correct typesym<->def relationship is needed for example when
  565. parsing parameters that are specializations of the record or when
  566. using nested constants and such }
  567. if assigned(recsym) then
  568. olddef:=ttypesym(recsym).typedef
  569. else
  570. olddef:=nil;
  571. set_typesym;
  572. current_structdef.symtable.currentvisibility:=vis_public;
  573. fields_allowed:=true;
  574. is_classdef:=false;
  575. classfields:=false;
  576. member_blocktype:=bt_general;
  577. repeat
  578. case token of
  579. _TYPE :
  580. begin
  581. consume(_TYPE);
  582. member_blocktype:=bt_type;
  583. { local and anonymous records can not have inner types. skip top record symtable }
  584. if IsAnonOrLocal then
  585. Message(parser_e_no_types_in_local_anonymous_records);
  586. end;
  587. _VAR :
  588. begin
  589. consume(_VAR);
  590. fields_allowed:=true;
  591. member_blocktype:=bt_general;
  592. classfields:=is_classdef;
  593. is_classdef:=false;
  594. end;
  595. _CONST:
  596. begin
  597. consume(_CONST);
  598. member_blocktype:=bt_const;
  599. { local and anonymous records can not have constants. skip top record symtable }
  600. if IsAnonOrLocal then
  601. Message(parser_e_no_consts_in_local_anonymous_records);
  602. end;
  603. _ID, _CASE, _OPERATOR :
  604. begin
  605. case idtoken of
  606. _PRIVATE :
  607. begin
  608. consume(_PRIVATE);
  609. current_structdef.symtable.currentvisibility:=vis_private;
  610. include(current_structdef.objectoptions,oo_has_private);
  611. fields_allowed:=true;
  612. is_classdef:=false;
  613. classfields:=false;
  614. member_blocktype:=bt_general;
  615. end;
  616. _PROTECTED :
  617. begin
  618. Message1(parser_e_not_allowed_in_record,tokeninfo^[_PROTECTED].str);
  619. consume(_PROTECTED);
  620. current_structdef.symtable.currentvisibility:=vis_protected;
  621. include(current_structdef.objectoptions,oo_has_protected);
  622. fields_allowed:=true;
  623. is_classdef:=false;
  624. classfields:=false;
  625. member_blocktype:=bt_general;
  626. end;
  627. _PUBLIC :
  628. begin
  629. consume(_PUBLIC);
  630. current_structdef.symtable.currentvisibility:=vis_public;
  631. fields_allowed:=true;
  632. is_classdef:=false;
  633. classfields:=false;
  634. member_blocktype:=bt_general;
  635. end;
  636. _PUBLISHED :
  637. begin
  638. Message(parser_e_no_record_published);
  639. consume(_PUBLISHED);
  640. current_structdef.symtable.currentvisibility:=vis_published;
  641. fields_allowed:=true;
  642. is_classdef:=false;
  643. classfields:=false;
  644. member_blocktype:=bt_general;
  645. end;
  646. _STRICT :
  647. begin
  648. consume(_STRICT);
  649. if token=_ID then
  650. begin
  651. case idtoken of
  652. _PRIVATE:
  653. begin
  654. consume(_PRIVATE);
  655. current_structdef.symtable.currentvisibility:=vis_strictprivate;
  656. include(current_structdef.objectoptions,oo_has_strictprivate);
  657. end;
  658. _PROTECTED:
  659. begin
  660. { "strict protected" is not allowed for records }
  661. Message1(parser_e_not_allowed_in_record,tokeninfo^[_STRICT].str+' '+tokeninfo^[_PROTECTED].str);
  662. consume(_PROTECTED);
  663. current_structdef.symtable.currentvisibility:=vis_strictprotected;
  664. include(current_structdef.objectoptions,oo_has_strictprotected);
  665. end;
  666. else
  667. message(parser_e_protected_or_private_expected);
  668. end;
  669. end
  670. else
  671. message(parser_e_protected_or_private_expected);
  672. fields_allowed:=true;
  673. is_classdef:=false;
  674. classfields:=false;
  675. member_blocktype:=bt_general;
  676. end
  677. else
  678. if is_classdef and (idtoken=_OPERATOR) then
  679. begin
  680. pd:=parse_record_method_dec(current_structdef,is_classdef);
  681. fields_allowed:=false;
  682. is_classdef:=false;
  683. end
  684. else
  685. begin
  686. if member_blocktype=bt_general then
  687. begin
  688. if (not fields_allowed)and(idtoken<>_CASE) then
  689. Message(parser_e_field_not_allowed_here);
  690. vdoptions:=[vd_record];
  691. if classfields then
  692. include(vdoptions,vd_class);
  693. read_record_fields(vdoptions,nil,nil);
  694. end
  695. else if member_blocktype=bt_type then
  696. types_dec(true)
  697. else if member_blocktype=bt_const then
  698. consts_dec(true,true)
  699. else
  700. internalerror(201001110);
  701. end;
  702. end;
  703. end;
  704. _PROPERTY :
  705. begin
  706. if IsAnonOrLocal then
  707. Message(parser_e_no_properties_in_local_anonymous_records);
  708. struct_property_dec(is_classdef);
  709. fields_allowed:=false;
  710. is_classdef:=false;
  711. end;
  712. _CLASS:
  713. begin
  714. is_classdef:=false;
  715. { read class method/field/property }
  716. consume(_CLASS);
  717. { class modifier is only allowed for procedures, functions, }
  718. { constructors, destructors, fields and properties }
  719. if not(token in [_FUNCTION,_PROCEDURE,_PROPERTY,_VAR,_CONSTRUCTOR,_DESTRUCTOR,_OPERATOR]) and
  720. not((token=_ID) and (idtoken=_OPERATOR)) then
  721. Message(parser_e_procedure_or_function_expected);
  722. if IsAnonOrLocal then
  723. Message(parser_e_no_class_in_local_anonymous_records);
  724. is_classdef:=true;
  725. end;
  726. _PROCEDURE,
  727. _FUNCTION:
  728. begin
  729. if IsAnonOrLocal then
  730. Message(parser_e_no_methods_in_local_anonymous_records);
  731. pd:=parse_record_method_dec(current_structdef,is_classdef);
  732. fields_allowed:=false;
  733. is_classdef:=false;
  734. end;
  735. _CONSTRUCTOR :
  736. begin
  737. if IsAnonOrLocal then
  738. Message(parser_e_no_methods_in_local_anonymous_records);
  739. if not is_classdef and (current_structdef.symtable.currentvisibility <> vis_public) then
  740. Message(parser_w_constructor_should_be_public);
  741. { only 1 class constructor is allowed }
  742. if is_classdef and (oo_has_class_constructor in current_structdef.objectoptions) then
  743. Message1(parser_e_only_one_class_constructor_allowed, current_structdef.objrealname^);
  744. oldparse_only:=parse_only;
  745. parse_only:=true;
  746. if is_classdef then
  747. pd:=class_constructor_head(current_structdef)
  748. else
  749. begin
  750. pd:=constructor_head;
  751. if pd.minparacount = 0 then
  752. MessagePos(pd.procsym.fileinfo,parser_e_no_parameterless_constructor_in_records);
  753. end;
  754. parse_only:=oldparse_only;
  755. fields_allowed:=false;
  756. is_classdef:=false;
  757. end;
  758. _DESTRUCTOR :
  759. begin
  760. if IsAnonOrLocal then
  761. Message(parser_e_no_methods_in_local_anonymous_records);
  762. if not is_classdef then
  763. Message(parser_e_no_destructor_in_records);
  764. { only 1 class destructor is allowed }
  765. if is_classdef and (oo_has_class_destructor in current_structdef.objectoptions) then
  766. Message1(parser_e_only_one_class_destructor_allowed, current_structdef.objrealname^);
  767. oldparse_only:=parse_only;
  768. parse_only:=true;
  769. if is_classdef then
  770. pd:=class_destructor_head(current_structdef)
  771. else
  772. pd:=destructor_head;
  773. parse_only:=oldparse_only;
  774. fields_allowed:=false;
  775. is_classdef:=false;
  776. end;
  777. _END :
  778. begin
  779. {$ifdef jvm}
  780. add_java_default_record_methods_intf(trecorddef(current_structdef));
  781. {$endif}
  782. if target_info.system in systems_typed_constants_node_init then
  783. add_typedconst_init_routine(current_structdef);
  784. consume(_END);
  785. break;
  786. end;
  787. else
  788. consume(_ID); { Give a ident expected message, like tp7 }
  789. end;
  790. until false;
  791. reset_typesym;
  792. end;
  793. { reads a record declaration }
  794. function record_dec(const n:tidstring;recsym:tsym;genericdef:tstoreddef;genericlist:tfphashobjectlist):tdef;
  795. var
  796. old_current_structdef: tabstractrecorddef;
  797. old_current_genericdef,
  798. old_current_specializedef: tstoreddef;
  799. old_parse_generic: boolean;
  800. recst: trecordsymtable;
  801. begin
  802. old_current_structdef:=current_structdef;
  803. old_current_genericdef:=current_genericdef;
  804. old_current_specializedef:=current_specializedef;
  805. old_parse_generic:=parse_generic;
  806. current_genericdef:=nil;
  807. current_specializedef:=nil;
  808. { create recdef }
  809. if (n<>'') or
  810. not(target_info.system in systems_jvm) then
  811. begin
  812. recst:=trecordsymtable.create(n,current_settings.packrecords);
  813. { can't use recst.realname^ instead of n, because recst.realname is
  814. nil in case of an empty name }
  815. current_structdef:=crecorddef.create(n,recst);
  816. end
  817. else
  818. begin
  819. { for the JVM target records always need a name, because they are
  820. represented by a class }
  821. recst:=trecordsymtable.create(current_module.realmodulename^+'__fpc_intern_recname_'+tostr(current_module.deflist.count),current_settings.packrecords);
  822. current_structdef:=crecorddef.create(recst.name^,recst);
  823. end;
  824. result:=current_structdef;
  825. { insert in symtablestack }
  826. symtablestack.push(recst);
  827. { usage of specialized type inside its generic template }
  828. if assigned(genericdef) then
  829. current_specializedef:=current_structdef
  830. { reject declaration of generic class inside generic class }
  831. else if assigned(genericlist) then
  832. current_genericdef:=current_structdef;
  833. { nested types of specializations are specializations as well }
  834. if assigned(old_current_structdef) and
  835. (df_specialization in old_current_structdef.defoptions) then
  836. include(current_structdef.defoptions,df_specialization);
  837. if assigned(old_current_structdef) and
  838. (df_generic in old_current_structdef.defoptions) then
  839. begin
  840. include(current_structdef.defoptions,df_generic);
  841. current_genericdef:=current_structdef;
  842. end;
  843. insert_generic_parameter_types(current_structdef,genericdef,genericlist);
  844. { when we are parsing a generic already then this is a generic as
  845. well }
  846. if old_parse_generic then
  847. include(current_structdef.defoptions, df_generic);
  848. parse_generic:=(df_generic in current_structdef.defoptions);
  849. { in non-Delphi modes we need a strict private symbol without type
  850. count and type parameters in the name to simply resolving }
  851. maybe_insert_generic_rename_symbol(n,genericlist);
  852. if m_advanced_records in current_settings.modeswitches then
  853. begin
  854. parse_record_members(recsym);
  855. end
  856. else
  857. begin
  858. read_record_fields([vd_record],nil,nil);
  859. {$ifdef jvm}
  860. { we need a constructor to create temps, a deep copy helper, ... }
  861. add_java_default_record_methods_intf(trecorddef(current_structdef));
  862. {$endif}
  863. if target_info.system in systems_typed_constants_node_init then
  864. add_typedconst_init_routine(current_structdef);
  865. consume(_END);
  866. end;
  867. { make the record size aligned (has to be done before inserting the
  868. parameters, because that may depend on the record's size) }
  869. recst.addalignmentpadding;
  870. { don't keep track of procdefs in a separate list, because the
  871. compiler may add additional procdefs (e.g. property wrappers for
  872. the jvm backend) }
  873. insert_record_hidden_paras(trecorddef(current_structdef));
  874. { restore symtable stack }
  875. symtablestack.pop(recst);
  876. if trecorddef(current_structdef).is_packed and is_managed_type(current_structdef) then
  877. Message(type_e_no_packed_inittable);
  878. { restore old state }
  879. parse_generic:=old_parse_generic;
  880. current_structdef:=old_current_structdef;
  881. current_genericdef:=old_current_genericdef;
  882. current_specializedef:=old_current_specializedef;
  883. end;
  884. { reads a type definition and returns a pointer to it }
  885. procedure read_named_type(var def:tdef;const newsym:tsym;genericdef:tstoreddef;genericlist:tfphashobjectlist;parseprocvardir:boolean;var hadtypetoken:boolean);
  886. var
  887. pt : tnode;
  888. tt2 : tdef;
  889. aktenumdef : tenumdef;
  890. s : TIDString;
  891. l,v : TConstExprInt;
  892. oldpackrecords : longint;
  893. defpos,storepos : tfileposinfo;
  894. name: TIDString;
  895. procedure expr_type;
  896. var
  897. pt1,pt2 : tnode;
  898. lv,hv : TConstExprInt;
  899. old_block_type : tblock_type;
  900. dospecialize : boolean;
  901. newdef : tdef;
  902. sym : tsym;
  903. genstr : string;
  904. gencount : longint;
  905. begin
  906. old_block_type:=block_type;
  907. dospecialize:=false;
  908. { use of current parsed object:
  909. classes, objects, records can be used also in themself }
  910. if (token=_ID) then
  911. if try_parse_structdef_nested_type(def,current_structdef,false) then
  912. exit;
  913. { Generate a specialization in FPC mode? }
  914. dospecialize:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_SPECIALIZE);
  915. { we can't accept a equal in type }
  916. pt1:=comp_expr(false,true);
  917. if not dospecialize and
  918. try_to_consume(_POINTPOINT) then
  919. begin
  920. { get high value of range }
  921. pt2:=comp_expr(false,false);
  922. { make both the same type or give an error. This is not
  923. done when both are integer values, because typecasting
  924. between -3200..3200 will result in a signed-unsigned
  925. conflict and give a range check error (PFV) }
  926. if not(is_integer(pt1.resultdef) and is_integer(pt2.resultdef)) then
  927. inserttypeconv(pt1,pt2.resultdef);
  928. { both must be evaluated to constants now }
  929. if (pt1.nodetype=ordconstn) and
  930. (pt2.nodetype=ordconstn) then
  931. begin
  932. lv:=tordconstnode(pt1).value;
  933. hv:=tordconstnode(pt2).value;
  934. { Check bounds }
  935. if hv<lv then
  936. message(parser_e_upper_lower_than_lower)
  937. else if (lv.signed and (lv.svalue<0)) and (not hv.signed and (hv.uvalue>qword(high(int64)))) then
  938. message(type_e_cant_eval_constant_expr)
  939. else
  940. begin
  941. { All checks passed, create the new def }
  942. case pt1.resultdef.typ of
  943. enumdef :
  944. def:=cenumdef.create_subrange(tenumdef(pt1.resultdef),lv.svalue,hv.svalue);
  945. orddef :
  946. begin
  947. if is_char(pt1.resultdef) then
  948. def:=corddef.create(uchar,lv,hv)
  949. else
  950. if is_boolean(pt1.resultdef) then
  951. def:=corddef.create(pasbool8,lv,hv)
  952. else if is_signed(pt1.resultdef) then
  953. def:=corddef.create(range_to_basetype(lv,hv),lv,hv)
  954. else
  955. def:=corddef.create(range_to_basetype(lv,hv),lv,hv);
  956. end;
  957. end;
  958. end;
  959. end
  960. else
  961. Message(sym_e_error_in_type_def);
  962. pt2.free;
  963. end
  964. else
  965. begin
  966. { a simple type renaming or generic specialization }
  967. if (pt1.nodetype=typen) then
  968. begin
  969. def:=ttypenode(pt1).resultdef;
  970. { Delphi mode specialization? }
  971. if (m_delphi in current_settings.modeswitches) then
  972. dospecialize:=token=_LSHARPBRACKET
  973. else
  974. { in non-Delphi modes we might get a inline specialization
  975. without "specialize" or "<T>" of the same type we're
  976. currently parsing, so we need to handle that special }
  977. newdef:=nil;
  978. if not dospecialize and
  979. assigned(ttypenode(pt1).typesym) and
  980. (ttypenode(pt1).typesym.typ=typesym) and
  981. (sp_generic_dummy in ttypenode(pt1).typesym.symoptions) and
  982. assigned(current_structdef) and
  983. (
  984. (
  985. not (m_delphi in current_settings.modeswitches) and
  986. (ttypesym(ttypenode(pt1).typesym).typedef.typ=undefineddef) and
  987. (df_generic in current_structdef.defoptions) and
  988. (ttypesym(ttypenode(pt1).typesym).typedef.owner=current_structdef.owner) and
  989. (upper(ttypenode(pt1).typesym.realname)=copy(current_structdef.objname^,1,pos('$',current_structdef.objname^)-1))
  990. ) or (
  991. { this could be a nested specialization which uses
  992. the type name of a surrounding generic to
  993. reference the specialization of said surrounding
  994. class }
  995. (df_specialization in current_structdef.defoptions) and
  996. return_specialization_of_generic(current_structdef,ttypesym(ttypenode(pt1).typesym).typedef,newdef)
  997. )
  998. )
  999. then
  1000. begin
  1001. if assigned(newdef) then
  1002. def:=newdef
  1003. else
  1004. def:=current_structdef;
  1005. if assigned(def) then
  1006. { handle nested types }
  1007. post_comp_expr_gendef(def)
  1008. else
  1009. def:=generrordef;
  1010. end;
  1011. if dospecialize then
  1012. begin
  1013. generate_specialization(def,false,name);
  1014. { handle nested types }
  1015. if assigned(def) then
  1016. post_comp_expr_gendef(def);
  1017. end
  1018. else
  1019. begin
  1020. if assigned(current_specializedef) and (def=current_specializedef.genericdef) then
  1021. begin
  1022. def:=current_specializedef
  1023. end
  1024. else if (def=current_genericdef) then
  1025. begin
  1026. def:=current_genericdef
  1027. end
  1028. else if tstoreddef(def).is_generic and
  1029. { TODO : check once nested generics are allowed }
  1030. not
  1031. (
  1032. parse_generic and
  1033. (current_genericdef.typ in [recorddef,objectdef]) and
  1034. (def.typ in [recorddef,objectdef]) and
  1035. (
  1036. { if both defs belong to the same generic (e.g. both are
  1037. subtypes) then we must allow the usage }
  1038. defs_belong_to_same_generic(def,current_genericdef) or
  1039. { this is needed to correctly resolve "type Foo=SomeGeneric<T>"
  1040. declarations inside a generic }
  1041. (
  1042. (ttypenode(pt1).typesym<>nil) and
  1043. sym_is_owned_by(ttypenode(pt1).typesym,tabstractrecorddef(current_genericdef).symtable)
  1044. )
  1045. )
  1046. )
  1047. then
  1048. begin
  1049. if assigned(def.typesym) then
  1050. begin
  1051. if ttypesym(def.typesym).typedef.typ<>undefineddef then
  1052. { non-Delphi modes... }
  1053. split_generic_name(def.typesym.name,genstr,gencount)
  1054. else
  1055. genstr:=def.typesym.name;
  1056. sym:=resolve_generic_dummysym(genstr);
  1057. end
  1058. else
  1059. sym:=nil;
  1060. if assigned(sym) and
  1061. not (sp_generic_dummy in sym.symoptions) and
  1062. (sym.typ=typesym) then
  1063. def:=ttypesym(sym).typedef
  1064. else
  1065. begin
  1066. Message(parser_e_no_generics_as_types);
  1067. def:=generrordef;
  1068. end;
  1069. end
  1070. else if is_classhelper(def) then
  1071. begin
  1072. Message(parser_e_no_category_as_types);
  1073. def:=generrordef
  1074. end
  1075. end;
  1076. end
  1077. else
  1078. Message(sym_e_error_in_type_def);
  1079. end;
  1080. pt1.free;
  1081. block_type:=old_block_type;
  1082. end;
  1083. procedure set_dec;
  1084. begin
  1085. consume(_SET);
  1086. consume(_OF);
  1087. read_anon_type(tt2,true);
  1088. if assigned(tt2) then
  1089. begin
  1090. case tt2.typ of
  1091. { don't forget that min can be negativ PM }
  1092. enumdef :
  1093. if (tenumdef(tt2).min>=0) and
  1094. (tenumdef(tt2).max<=255) then
  1095. // !! def:=csetdef.create(tt2,tenumdef(tt2.def).min,tenumdef(tt2.def).max))
  1096. def:=csetdef.create(tt2,tenumdef(tt2).min,tenumdef(tt2).max)
  1097. else
  1098. Message(sym_e_ill_type_decl_set);
  1099. orddef :
  1100. begin
  1101. if (torddef(tt2).ordtype<>uvoid) and
  1102. (torddef(tt2).ordtype<>uwidechar) and
  1103. (torddef(tt2).low>=0) then
  1104. // !! def:=csetdef.create(tt2,torddef(tt2.def).low,torddef(tt2.def).high))
  1105. if Torddef(tt2).high>int64(high(byte)) then
  1106. message(sym_e_ill_type_decl_set)
  1107. else
  1108. def:=csetdef.create(tt2,torddef(tt2).low.svalue,torddef(tt2).high.svalue)
  1109. else
  1110. Message(sym_e_ill_type_decl_set);
  1111. end;
  1112. else
  1113. Message(sym_e_ill_type_decl_set);
  1114. end;
  1115. end
  1116. else
  1117. def:=generrordef;
  1118. end;
  1119. procedure array_dec(is_packed:boolean;genericdef:tstoreddef;genericlist:tfphashobjectlist);
  1120. var
  1121. lowval,
  1122. highval : TConstExprInt;
  1123. indexdef : tdef;
  1124. hdef : tdef;
  1125. arrdef : tarraydef;
  1126. procedure setdefdecl(def:tdef);
  1127. begin
  1128. case def.typ of
  1129. enumdef :
  1130. begin
  1131. lowval:=tenumdef(def).min;
  1132. highval:=tenumdef(def).max;
  1133. if (m_fpc in current_settings.modeswitches) and
  1134. (tenumdef(def).has_jumps) then
  1135. Message(type_e_array_index_enums_with_assign_not_possible);
  1136. indexdef:=def;
  1137. end;
  1138. orddef :
  1139. begin
  1140. if torddef(def).ordtype in [uchar,
  1141. u8bit,
  1142. s8bit,s16bit,
  1143. {$if defined(cpu32bitaddr) or defined(cpu64bitaddr)}
  1144. u16bit,s32bit,
  1145. {$endif defined(cpu32bitaddr) or defined(cpu64bitaddr)}
  1146. {$ifdef cpu64bitaddr}
  1147. u32bit,s64bit,
  1148. {$endif cpu64bitaddr}
  1149. pasbool8,pasbool16,pasbool32,pasbool64,
  1150. bool8bit,bool16bit,bool32bit,bool64bit,
  1151. uwidechar] then
  1152. begin
  1153. lowval:=torddef(def).low;
  1154. highval:=torddef(def).high;
  1155. indexdef:=def;
  1156. end
  1157. else
  1158. Message1(parser_e_type_cant_be_used_in_array_index,def.typename);
  1159. end;
  1160. else
  1161. Message(sym_e_error_in_type_def);
  1162. end;
  1163. end;
  1164. var
  1165. old_current_genericdef,
  1166. old_current_specializedef: tstoreddef;
  1167. first,
  1168. old_parse_generic: boolean;
  1169. begin
  1170. old_current_genericdef:=current_genericdef;
  1171. old_current_specializedef:=current_specializedef;
  1172. old_parse_generic:=parse_generic;
  1173. current_genericdef:=nil;
  1174. current_specializedef:=nil;
  1175. first:=true;
  1176. arrdef:=carraydef.create(0,0,s32inttype);
  1177. consume(_ARRAY);
  1178. { usage of specialized type inside its generic template }
  1179. if assigned(genericdef) then
  1180. current_specializedef:=arrdef
  1181. { reject declaration of generic class inside generic class }
  1182. else if assigned(genericlist) then
  1183. current_genericdef:=arrdef;
  1184. symtablestack.push(arrdef.symtable);
  1185. insert_generic_parameter_types(arrdef,genericdef,genericlist);
  1186. { there are two possibilties for the following to be true:
  1187. * the array declaration itself is generic
  1188. * the array is declared inside a generic
  1189. in both cases we need "parse_generic" and "current_genericdef"
  1190. so that e.g. specializations of another generic inside the
  1191. current generic can be used (either inline ones or "type" ones) }
  1192. if old_parse_generic then
  1193. include(arrdef.defoptions,df_generic);
  1194. parse_generic:=(df_generic in arrdef.defoptions);
  1195. if parse_generic and not assigned(current_genericdef) then
  1196. current_genericdef:=old_current_genericdef;
  1197. { open array? }
  1198. if try_to_consume(_LECKKLAMMER) then
  1199. begin
  1200. { defaults }
  1201. indexdef:=generrordef;
  1202. { use defaults which don't overflow the compiler }
  1203. lowval:=0;
  1204. highval:=0;
  1205. repeat
  1206. { read the expression and check it, check apart if the
  1207. declaration is an enum declaration because that needs to
  1208. be parsed by readtype (PFV) }
  1209. if token=_LKLAMMER then
  1210. begin
  1211. read_anon_type(hdef,true);
  1212. setdefdecl(hdef);
  1213. end
  1214. else
  1215. begin
  1216. pt:=expr(true);
  1217. if pt.nodetype=typen then
  1218. setdefdecl(pt.resultdef)
  1219. else
  1220. begin
  1221. if pt.nodetype=rangen then
  1222. begin
  1223. { pure ordconstn expressions can be checked for
  1224. generics as well, but don't give an error in case
  1225. of parsing a generic if that isn't yet the case }
  1226. if (trangenode(pt).left.nodetype=ordconstn) and
  1227. (trangenode(pt).right.nodetype=ordconstn) then
  1228. begin
  1229. { make both the same type or give an error. This is not
  1230. done when both are integer values, because typecasting
  1231. between -3200..3200 will result in a signed-unsigned
  1232. conflict and give a range check error (PFV) }
  1233. if not(is_integer(trangenode(pt).left.resultdef) and is_integer(trangenode(pt).left.resultdef)) then
  1234. inserttypeconv(trangenode(pt).left,trangenode(pt).right.resultdef);
  1235. lowval:=tordconstnode(trangenode(pt).left).value;
  1236. highval:=tordconstnode(trangenode(pt).right).value;
  1237. if highval<lowval then
  1238. begin
  1239. Message(parser_e_array_lower_less_than_upper_bound);
  1240. highval:=lowval;
  1241. end
  1242. else if (lowval<int64(low(asizeint))) or
  1243. (highval>high(asizeint)) then
  1244. begin
  1245. Message(parser_e_array_range_out_of_bounds);
  1246. lowval :=0;
  1247. highval:=0;
  1248. end;
  1249. if is_integer(trangenode(pt).left.resultdef) then
  1250. range_to_type(lowval,highval,indexdef)
  1251. else
  1252. indexdef:=trangenode(pt).left.resultdef;
  1253. end
  1254. else
  1255. if not parse_generic then
  1256. Message(type_e_cant_eval_constant_expr)
  1257. else
  1258. { we need a valid range for debug information }
  1259. range_to_type(lowval,highval,indexdef);
  1260. end
  1261. else
  1262. Message(sym_e_error_in_type_def)
  1263. end;
  1264. pt.free;
  1265. end;
  1266. { if we are not at the first dimension, add the new arrray
  1267. as element of the existing array, otherwise modify the existing array }
  1268. if not(first) then
  1269. begin
  1270. arrdef.elementdef:=carraydef.create(lowval.svalue,highval.svalue,indexdef);
  1271. { push new symtable }
  1272. symtablestack.pop(arrdef.symtable);
  1273. arrdef:=tarraydef(arrdef.elementdef);
  1274. symtablestack.push(arrdef.symtable);
  1275. end
  1276. else
  1277. begin
  1278. arrdef.lowrange:=lowval.svalue;
  1279. arrdef.highrange:=highval.svalue;
  1280. arrdef.rangedef:=indexdef;
  1281. def:=arrdef;
  1282. first:=false;
  1283. end;
  1284. if is_packed then
  1285. include(arrdef.arrayoptions,ado_IsBitPacked);
  1286. if token=_COMMA then
  1287. consume(_COMMA)
  1288. else
  1289. break;
  1290. until false;
  1291. consume(_RECKKLAMMER);
  1292. end
  1293. else
  1294. begin
  1295. if is_packed then
  1296. Message(parser_e_packed_dynamic_open_array);
  1297. arrdef.lowrange:=0;
  1298. arrdef.highrange:=-1;
  1299. arrdef.rangedef:=s32inttype;
  1300. include(arrdef.arrayoptions,ado_IsDynamicArray);
  1301. def:=arrdef;
  1302. end;
  1303. consume(_OF);
  1304. read_anon_type(tt2,true);
  1305. { set element type of the last array definition }
  1306. if assigned(arrdef) then
  1307. begin
  1308. symtablestack.pop(arrdef.symtable);
  1309. arrdef.elementdef:=tt2;
  1310. if is_packed and
  1311. is_managed_type(tt2) then
  1312. Message(type_e_no_packed_inittable);
  1313. end;
  1314. { restore old state }
  1315. parse_generic:=old_parse_generic;
  1316. current_genericdef:=old_current_genericdef;
  1317. current_specializedef:=old_current_specializedef;
  1318. end;
  1319. function procvar_dec(genericdef:tstoreddef;genericlist:tfphashobjectlist):tdef;
  1320. var
  1321. is_func:boolean;
  1322. pd:tabstractprocdef;
  1323. newtype:ttypesym;
  1324. old_current_genericdef,
  1325. old_current_specializedef: tstoreddef;
  1326. old_parse_generic: boolean;
  1327. begin
  1328. old_current_genericdef:=current_genericdef;
  1329. old_current_specializedef:=current_specializedef;
  1330. old_parse_generic:=parse_generic;
  1331. current_genericdef:=nil;
  1332. current_specializedef:=nil;
  1333. is_func:=(token=_FUNCTION);
  1334. consume(token);
  1335. pd:=cprocvardef.create(normal_function_level);
  1336. { usage of specialized type inside its generic template }
  1337. if assigned(genericdef) then
  1338. current_specializedef:=pd
  1339. { reject declaration of generic class inside generic class }
  1340. else if assigned(genericlist) then
  1341. current_genericdef:=pd;
  1342. symtablestack.push(pd.parast);
  1343. insert_generic_parameter_types(pd,genericdef,genericlist);
  1344. { there are two possibilties for the following to be true:
  1345. * the procvar declaration itself is generic
  1346. * the procvar is declared inside a generic
  1347. in both cases we need "parse_generic" and "current_genericdef"
  1348. so that e.g. specializations of another generic inside the
  1349. current generic can be used (either inline ones or "type" ones) }
  1350. if old_parse_generic then
  1351. include(pd.defoptions,df_generic);
  1352. parse_generic:=(df_generic in pd.defoptions);
  1353. if parse_generic and not assigned(current_genericdef) then
  1354. current_genericdef:=old_current_genericdef;
  1355. { don't allow to add defs to the symtable - use it for type param search only }
  1356. tparasymtable(pd.parast).readonly:=true;
  1357. if token=_LKLAMMER then
  1358. parse_parameter_dec(pd);
  1359. if is_func then
  1360. begin
  1361. consume(_COLON);
  1362. single_type(pd.returndef,[]);
  1363. end;
  1364. if try_to_consume(_OF) then
  1365. begin
  1366. consume(_OBJECT);
  1367. include(pd.procoptions,po_methodpointer);
  1368. end
  1369. else if (m_nested_procvars in current_settings.modeswitches) and
  1370. try_to_consume(_IS) then
  1371. begin
  1372. consume(_NESTED);
  1373. pd.parast.symtablelevel:=normal_function_level+1;
  1374. pd.check_mark_as_nested;
  1375. end;
  1376. symtablestack.pop(pd.parast);
  1377. tparasymtable(pd.parast).readonly:=false;
  1378. result:=pd;
  1379. { possible proc directives }
  1380. if parseprocvardir then
  1381. begin
  1382. if check_proc_directive(true) then
  1383. begin
  1384. newtype:=ctypesym.create('unnamed',result);
  1385. parse_var_proc_directives(tsym(newtype));
  1386. newtype.typedef:=nil;
  1387. result.typesym:=nil;
  1388. newtype.free;
  1389. end;
  1390. { Add implicit hidden parameters and function result }
  1391. handle_calling_convention(pd);
  1392. end;
  1393. { restore old state }
  1394. parse_generic:=old_parse_generic;
  1395. current_genericdef:=old_current_genericdef;
  1396. current_specializedef:=old_current_specializedef;
  1397. end;
  1398. const
  1399. SingleTypeOptionsInTypeBlock:array[Boolean] of TSingleTypeOptions = ([],[stoIsForwardDef]);
  1400. SingleTypeOptionsIsDelphi:array[Boolean] of TSingleTypeOptions = ([],[stoAllowSpecialization]);
  1401. var
  1402. p : tnode;
  1403. hdef : tdef;
  1404. enumdupmsg, first, is_specialize : boolean;
  1405. oldlocalswitches : tlocalswitches;
  1406. bitpacking: boolean;
  1407. stitem: psymtablestackitem;
  1408. sym: tsym;
  1409. st: tsymtable;
  1410. begin
  1411. def:=nil;
  1412. v:=0;
  1413. l:=0;
  1414. if assigned(newsym) then
  1415. name:=newsym.RealName
  1416. else
  1417. name:='';
  1418. case token of
  1419. _STRING,_FILE:
  1420. begin
  1421. single_type(def,[stoAllowTypeDef]);
  1422. end;
  1423. _LKLAMMER:
  1424. begin
  1425. consume(_LKLAMMER);
  1426. first:=true;
  1427. { allow negativ value_str }
  1428. l:=int64(-1);
  1429. enumdupmsg:=false;
  1430. { check that we are not adding an enum from specialization
  1431. we can't just use current_specializedef because of inner types
  1432. like specialize array of record }
  1433. is_specialize:=false;
  1434. stitem:=symtablestack.stack;
  1435. while assigned(stitem) do
  1436. begin
  1437. { check records, classes and arrays because they can be specialized }
  1438. if stitem^.symtable.symtabletype in [recordsymtable,ObjectSymtable,arraysymtable] then
  1439. begin
  1440. is_specialize:=is_specialize or (df_specialization in tstoreddef(stitem^.symtable.defowner).defoptions);
  1441. stitem:=stitem^.next;
  1442. end
  1443. else
  1444. break;
  1445. end;
  1446. if not is_specialize then
  1447. aktenumdef:=cenumdef.create
  1448. else
  1449. aktenumdef:=nil;
  1450. repeat
  1451. { if it is a specialization then search the first enum member
  1452. and get the member owner instead of just created enumdef }
  1453. if not assigned(aktenumdef) then
  1454. begin
  1455. searchsym(pattern,sym,st);
  1456. if sym.typ=enumsym then
  1457. aktenumdef:=tenumsym(sym).definition
  1458. else
  1459. internalerror(201101021);
  1460. end;
  1461. s:=orgpattern;
  1462. defpos:=current_tokenpos;
  1463. consume(_ID);
  1464. { only allow assigning of specific numbers under fpc mode }
  1465. if not(m_tp7 in current_settings.modeswitches) and
  1466. (
  1467. { in fpc mode also allow := to be compatible
  1468. with previous 1.0.x versions }
  1469. ((m_fpc in current_settings.modeswitches) and
  1470. try_to_consume(_ASSIGNMENT)) or
  1471. try_to_consume(_EQ)
  1472. ) then
  1473. begin
  1474. oldlocalswitches:=current_settings.localswitches;
  1475. include(current_settings.localswitches,cs_allow_enum_calc);
  1476. p:=comp_expr(true,false);
  1477. current_settings.localswitches:=oldlocalswitches;
  1478. if (p.nodetype=ordconstn) then
  1479. begin
  1480. { we expect an integer or an enum of the
  1481. same type }
  1482. if is_integer(p.resultdef) or
  1483. is_char(p.resultdef) or
  1484. equal_defs(p.resultdef,aktenumdef) then
  1485. v:=tordconstnode(p).value
  1486. else
  1487. IncompatibleTypes(p.resultdef,s32inttype);
  1488. end
  1489. else
  1490. Message(parser_e_illegal_expression);
  1491. p.free;
  1492. { please leave that a note, allows type save }
  1493. { declarations in the win32 units ! }
  1494. if (not first) and (v<=l) and (not enumdupmsg) then
  1495. begin
  1496. Message(parser_n_duplicate_enum);
  1497. enumdupmsg:=true;
  1498. end;
  1499. l:=v;
  1500. end
  1501. else
  1502. inc(l.svalue);
  1503. first:=false;
  1504. { don't generate enum members is this is a specialization because aktenumdef is copied from the generic type }
  1505. if not is_specialize then
  1506. begin
  1507. storepos:=current_tokenpos;
  1508. current_tokenpos:=defpos;
  1509. tenumsymtable(aktenumdef.symtable).insert(cenumsym.create(s,aktenumdef,longint(l.svalue)));
  1510. if not (cs_scopedenums in current_settings.localswitches) then
  1511. tstoredsymtable(aktenumdef.owner).insert(cenumsym.create(s,aktenumdef,longint(l.svalue)));
  1512. current_tokenpos:=storepos;
  1513. end;
  1514. until not try_to_consume(_COMMA);
  1515. def:=aktenumdef;
  1516. consume(_RKLAMMER);
  1517. {$ifdef jvm}
  1518. jvm_maybe_create_enum_class(name,def);
  1519. {$endif}
  1520. end;
  1521. _ARRAY:
  1522. begin
  1523. array_dec(false,genericdef,genericlist);
  1524. end;
  1525. _SET:
  1526. begin
  1527. set_dec;
  1528. end;
  1529. _CARET:
  1530. begin
  1531. consume(_CARET);
  1532. single_type(tt2,
  1533. SingleTypeOptionsInTypeBlock[block_type=bt_type]+
  1534. SingleTypeOptionsIsDelphi[m_delphi in current_settings.modeswitches]
  1535. );
  1536. { in case of e.g. var or const sections we need to especially
  1537. check that we don't use a generic dummy symbol }
  1538. if (block_type<>bt_type) and
  1539. (tt2.typ=undefineddef) and
  1540. assigned(tt2.typesym) and
  1541. (sp_generic_dummy in tt2.typesym.symoptions) then
  1542. begin
  1543. sym:=resolve_generic_dummysym(tt2.typesym.name);
  1544. if assigned(sym) and
  1545. not (sp_generic_dummy in sym.symoptions) and
  1546. (sym.typ=typesym) then
  1547. tt2:=ttypesym(sym).typedef
  1548. else
  1549. Message(parser_e_no_generics_as_types);
  1550. end;
  1551. { don't use getpointerdef() here, since this is a type
  1552. declaration (-> must create new typedef) }
  1553. def:=cpointerdef.create(tt2);
  1554. if tt2.typ=forwarddef then
  1555. current_module.checkforwarddefs.add(def);
  1556. end;
  1557. _RECORD:
  1558. begin
  1559. consume(token);
  1560. if (idtoken=_HELPER) and (m_advanced_records in current_settings.modeswitches) then
  1561. begin
  1562. consume(_HELPER);
  1563. def:=object_dec(odt_helper,name,newsym,genericdef,genericlist,nil,ht_record);
  1564. end
  1565. else
  1566. def:=record_dec(name,newsym,genericdef,genericlist);
  1567. end;
  1568. _PACKED,
  1569. _BITPACKED:
  1570. begin
  1571. bitpacking :=
  1572. (cs_bitpacking in current_settings.localswitches) or
  1573. (token = _BITPACKED);
  1574. consume(token);
  1575. if token=_ARRAY then
  1576. array_dec(bitpacking,genericdef,genericlist)
  1577. else if token=_SET then
  1578. set_dec
  1579. else if token=_FILE then
  1580. single_type(def,[stoAllowTypeDef])
  1581. else
  1582. begin
  1583. oldpackrecords:=current_settings.packrecords;
  1584. if (not bitpacking) or
  1585. (token in [_CLASS,_OBJECT]) then
  1586. current_settings.packrecords:=1
  1587. else
  1588. current_settings.packrecords:=bit_alignment;
  1589. case token of
  1590. _CLASS :
  1591. begin
  1592. consume(_CLASS);
  1593. def:=object_dec(odt_class,name,newsym,genericdef,genericlist,nil,ht_none);
  1594. end;
  1595. _OBJECT :
  1596. begin
  1597. consume(_OBJECT);
  1598. def:=object_dec(odt_object,name,newsym,genericdef,genericlist,nil,ht_none);
  1599. end;
  1600. else begin
  1601. consume(_RECORD);
  1602. def:=record_dec(name,newsym,genericdef,genericlist);
  1603. end;
  1604. end;
  1605. current_settings.packrecords:=oldpackrecords;
  1606. end;
  1607. end;
  1608. _DISPINTERFACE :
  1609. begin
  1610. { need extra check here since interface is a keyword
  1611. in all pascal modes }
  1612. if not(m_class in current_settings.modeswitches) then
  1613. Message(parser_f_need_objfpc_or_delphi_mode);
  1614. consume(token);
  1615. def:=object_dec(odt_dispinterface,name,newsym,genericdef,genericlist,nil,ht_none);
  1616. end;
  1617. _CLASS :
  1618. begin
  1619. consume(token);
  1620. { Delphi only allows class of in type blocks }
  1621. if (token=_OF) and
  1622. (
  1623. not(m_delphi in current_settings.modeswitches) or
  1624. (block_type=bt_type)
  1625. ) then
  1626. begin
  1627. consume(_OF);
  1628. single_type(hdef,SingleTypeOptionsInTypeBlock[block_type=bt_type]);
  1629. if is_class(hdef) or
  1630. is_objcclass(hdef) or
  1631. is_javaclass(hdef) then
  1632. def:=cclassrefdef.create(hdef)
  1633. else
  1634. if hdef.typ=forwarddef then
  1635. begin
  1636. def:=cclassrefdef.create(hdef);
  1637. current_module.checkforwarddefs.add(def);
  1638. end
  1639. else
  1640. Message1(type_e_class_or_objcclass_type_expected,hdef.typename);
  1641. end
  1642. else
  1643. if (idtoken=_HELPER) then
  1644. begin
  1645. consume(_HELPER);
  1646. def:=object_dec(odt_helper,name,newsym,genericdef,genericlist,nil,ht_class);
  1647. end
  1648. else
  1649. def:=object_dec(default_class_type,name,newsym,genericdef,genericlist,nil,ht_none);
  1650. end;
  1651. _CPPCLASS :
  1652. begin
  1653. consume(token);
  1654. def:=object_dec(odt_cppclass,name,newsym,genericdef,genericlist,nil,ht_none);
  1655. end;
  1656. _OBJCCLASS :
  1657. begin
  1658. if not(m_objectivec1 in current_settings.modeswitches) then
  1659. Message(parser_f_need_objc);
  1660. consume(token);
  1661. def:=object_dec(odt_objcclass,name,newsym,genericdef,genericlist,nil,ht_none);
  1662. end;
  1663. _INTERFACE :
  1664. begin
  1665. { need extra check here since interface is a keyword
  1666. in all pascal modes }
  1667. if not(m_class in current_settings.modeswitches) then
  1668. Message(parser_f_need_objfpc_or_delphi_mode);
  1669. consume(token);
  1670. case current_settings.interfacetype of
  1671. it_interfacecom:
  1672. def:=object_dec(odt_interfacecom,name,newsym,genericdef,genericlist,nil,ht_none);
  1673. it_interfacecorba:
  1674. def:=object_dec(odt_interfacecorba,name,newsym,genericdef,genericlist,nil,ht_none);
  1675. it_interfacejava:
  1676. def:=object_dec(odt_interfacejava,name,newsym,genericdef,genericlist,nil,ht_none);
  1677. else
  1678. internalerror(2010122612);
  1679. end;
  1680. end;
  1681. _OBJCPROTOCOL :
  1682. begin
  1683. if not(m_objectivec1 in current_settings.modeswitches) then
  1684. Message(parser_f_need_objc);
  1685. consume(token);
  1686. def:=object_dec(odt_objcprotocol,name,newsym,genericdef,genericlist,nil,ht_none);
  1687. end;
  1688. _OBJCCATEGORY :
  1689. begin
  1690. if not(m_objectivec1 in current_settings.modeswitches) then
  1691. Message(parser_f_need_objc);
  1692. consume(token);
  1693. def:=object_dec(odt_objccategory,name,newsym,genericdef,genericlist,nil,ht_none);
  1694. end;
  1695. _OBJECT :
  1696. begin
  1697. consume(token);
  1698. def:=object_dec(odt_object,name,newsym,genericdef,genericlist,nil,ht_none);
  1699. end;
  1700. _PROCEDURE,
  1701. _FUNCTION:
  1702. begin
  1703. def:=procvar_dec(genericdef,genericlist);
  1704. {$ifdef jvm}
  1705. jvm_create_procvar_class(name,def);
  1706. {$endif}
  1707. end;
  1708. else
  1709. if (token=_KLAMMERAFFE) and (m_iso in current_settings.modeswitches) then
  1710. begin
  1711. consume(_KLAMMERAFFE);
  1712. single_type(tt2,SingleTypeOptionsInTypeBlock[block_type=bt_type]);
  1713. def:=cpointerdef.create(tt2);
  1714. if tt2.typ=forwarddef then
  1715. current_module.checkforwarddefs.add(def);
  1716. end
  1717. else
  1718. if hadtypetoken and
  1719. { don't allow "type helper" in mode delphi and require modeswitch typehelpers }
  1720. ([m_delphi,m_type_helpers]*current_settings.modeswitches=[m_type_helpers]) and
  1721. (token=_ID) and (idtoken=_HELPER) then
  1722. begin
  1723. { reset hadtypetoken, so that calling code knows that it should not be handled
  1724. as a "unique" type }
  1725. hadtypetoken:=false;
  1726. consume(_HELPER);
  1727. def:=object_dec(odt_helper,name,newsym,genericdef,genericlist,nil,ht_type);
  1728. end
  1729. else
  1730. expr_type;
  1731. end;
  1732. if def=nil then
  1733. def:=generrordef;
  1734. end;
  1735. procedure read_anon_type(var def : tdef;parseprocvardir:boolean);
  1736. var
  1737. hadtypetoken : boolean;
  1738. begin
  1739. hadtypetoken:=false;
  1740. read_named_type(def,nil,nil,nil,parseprocvardir,hadtypetoken);
  1741. end;
  1742. procedure add_typedconst_init_routine(def: tabstractrecorddef);
  1743. var
  1744. sstate: tscannerstate;
  1745. pd: tprocdef;
  1746. begin
  1747. replace_scanner('tcinit_routine',sstate);
  1748. { the typed constant initialization code is called from the class
  1749. constructor by tnodeutils.wrap_proc_body; at this point, we don't
  1750. know yet whether that will be necessary, because there may be
  1751. typed constants inside method bodies -> always force the addition
  1752. of a class constructor.
  1753. We cannot directly add the typed constant initialisations to the
  1754. class constructor, because when it's parsed not all method bodies
  1755. are necessarily already parsed }
  1756. pd:=def.find_procdef_bytype(potype_class_constructor);
  1757. { the class constructor }
  1758. if not assigned(pd) then
  1759. begin
  1760. if str_parse_method_dec('constructor fpc_init_typed_consts_class_constructor;',potype_class_constructor,true,def,pd) then
  1761. pd.synthetickind:=tsk_empty
  1762. else
  1763. internalerror(2011040206);
  1764. end;
  1765. { the initialisation helper }
  1766. if str_parse_method_dec('procedure fpc_init_typed_consts_helper; static;',potype_procedure,true,def,pd) then
  1767. pd.synthetickind:=tsk_tcinit
  1768. else
  1769. internalerror(2011040207);
  1770. restore_scanner(sstate);
  1771. end;
  1772. end.