pdecl.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Does declaration (but not type) parsing 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 pdecl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,
  25. { symtable }
  26. symsym,symdef,
  27. { pass_1 }
  28. node;
  29. function readconstant(const orgname:string;const filepos:tfileposinfo):tconstsym;
  30. procedure const_dec;
  31. procedure consts_dec(in_structure: boolean);
  32. procedure label_dec;
  33. procedure type_dec;
  34. procedure types_dec(in_structure: boolean);
  35. procedure var_dec;
  36. procedure threadvar_dec;
  37. procedure property_dec(is_classpropery: boolean);
  38. procedure resourcestring_dec;
  39. implementation
  40. uses
  41. SysUtils,
  42. { common }
  43. cutils,
  44. { global }
  45. globals,tokens,verbose,widestr,constexp,
  46. systems,
  47. { aasm }
  48. aasmbase,aasmtai,aasmdata,fmodule,
  49. { symtable }
  50. symconst,symbase,symtype,symtable,paramgr,defutil,
  51. { pass 1 }
  52. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,nobj,
  53. { codegen }
  54. ncgutil,
  55. { parser }
  56. scanner,
  57. pbase,pexpr,ptype,ptconst,pdecsub,pdecvar,pdecobj,pgenutil,
  58. { cpu-information }
  59. cpuinfo
  60. ;
  61. function readconstant(const orgname:string;const filepos:tfileposinfo):tconstsym;
  62. var
  63. hp : tconstsym;
  64. p : tnode;
  65. ps : pconstset;
  66. pd : pbestreal;
  67. pg : pguid;
  68. sp : pchar;
  69. pw : pcompilerwidestring;
  70. storetokenpos : tfileposinfo;
  71. begin
  72. readconstant:=nil;
  73. if orgname='' then
  74. internalerror(9584582);
  75. hp:=nil;
  76. p:=comp_expr(true,false);
  77. storetokenpos:=current_tokenpos;
  78. current_tokenpos:=filepos;
  79. case p.nodetype of
  80. ordconstn:
  81. begin
  82. if p.resultdef.typ=pointerdef then
  83. hp:=tconstsym.create_ordptr(orgname,constpointer,tordconstnode(p).value.uvalue,p.resultdef)
  84. else
  85. hp:=tconstsym.create_ord(orgname,constord,tordconstnode(p).value,p.resultdef);
  86. end;
  87. stringconstn:
  88. begin
  89. if is_wide_or_unicode_string(p.resultdef) then
  90. begin
  91. initwidestring(pw);
  92. copywidestring(pcompilerwidestring(tstringconstnode(p).value_str),pw);
  93. hp:=tconstsym.create_wstring(orgname,constwstring,pw);
  94. end
  95. else
  96. begin
  97. getmem(sp,tstringconstnode(p).len+1);
  98. move(tstringconstnode(p).value_str^,sp^,tstringconstnode(p).len+1);
  99. hp:=tconstsym.create_string(orgname,conststring,sp,tstringconstnode(p).len);
  100. end;
  101. end;
  102. realconstn :
  103. begin
  104. new(pd);
  105. pd^:=trealconstnode(p).value_real;
  106. hp:=tconstsym.create_ptr(orgname,constreal,pd,p.resultdef);
  107. end;
  108. setconstn :
  109. begin
  110. new(ps);
  111. ps^:=tsetconstnode(p).value_set^;
  112. hp:=tconstsym.create_ptr(orgname,constset,ps,p.resultdef);
  113. end;
  114. pointerconstn :
  115. begin
  116. hp:=tconstsym.create_ordptr(orgname,constpointer,tpointerconstnode(p).value,p.resultdef);
  117. end;
  118. niln :
  119. begin
  120. hp:=tconstsym.create_ord(orgname,constnil,0,p.resultdef);
  121. end;
  122. typen :
  123. begin
  124. if is_interface(p.resultdef) then
  125. begin
  126. if assigned(tobjectdef(p.resultdef).iidguid) then
  127. begin
  128. new(pg);
  129. pg^:=tobjectdef(p.resultdef).iidguid^;
  130. hp:=tconstsym.create_ptr(orgname,constguid,pg,p.resultdef);
  131. end
  132. else
  133. Message1(parser_e_interface_has_no_guid,tobjectdef(p.resultdef).objrealname^);
  134. end
  135. else
  136. Message(parser_e_illegal_expression);
  137. end;
  138. else
  139. Message(parser_e_illegal_expression);
  140. end;
  141. current_tokenpos:=storetokenpos;
  142. p.free;
  143. readconstant:=hp;
  144. end;
  145. procedure const_dec;
  146. begin
  147. consume(_CONST);
  148. consts_dec(false);
  149. end;
  150. procedure consts_dec(in_structure: boolean);
  151. var
  152. orgname : TIDString;
  153. hdef : tdef;
  154. sym, tmp : tsym;
  155. dummysymoptions : tsymoptions;
  156. deprecatedmsg : pshortstring;
  157. storetokenpos,filepos : tfileposinfo;
  158. old_block_type : tblock_type;
  159. skipequal : boolean;
  160. tclist : tasmlist;
  161. varspez : tvarspez;
  162. static_name : string;
  163. sl : tpropaccesslist;
  164. begin
  165. old_block_type:=block_type;
  166. block_type:=bt_const;
  167. repeat
  168. orgname:=orgpattern;
  169. filepos:=current_tokenpos;
  170. consume(_ID);
  171. case token of
  172. _EQ:
  173. begin
  174. consume(_EQ);
  175. sym:=readconstant(orgname,filepos);
  176. { Support hint directives }
  177. dummysymoptions:=[];
  178. deprecatedmsg:=nil;
  179. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  180. if assigned(sym) then
  181. begin
  182. sym.symoptions:=sym.symoptions+dummysymoptions;
  183. sym.deprecatedmsg:=deprecatedmsg;
  184. sym.visibility:=symtablestack.top.currentvisibility;
  185. symtablestack.top.insert(sym);
  186. end
  187. else
  188. stringdispose(deprecatedmsg);
  189. consume(_SEMICOLON);
  190. end;
  191. _COLON:
  192. begin
  193. { set the blocktype first so a consume also supports a
  194. caret, to support const s : ^string = nil }
  195. block_type:=bt_const_type;
  196. consume(_COLON);
  197. read_anon_type(hdef,false);
  198. block_type:=bt_const;
  199. skipequal:=false;
  200. { create symbol }
  201. storetokenpos:=current_tokenpos;
  202. current_tokenpos:=filepos;
  203. if not (cs_typed_const_writable in current_settings.localswitches) then
  204. varspez:=vs_const
  205. else
  206. varspez:=vs_value;
  207. { if we are dealing with structure const then we need to handle it as a
  208. structure static variable: create a symbol in unit symtable and a reference
  209. to it from the structure or linking will fail }
  210. if symtablestack.top.symtabletype in [recordsymtable,ObjectSymtable] then
  211. begin
  212. { generate the symbol which reserves the space }
  213. static_name:=lower(generate_nested_name(symtablestack.top,'_'))+'_'+orgname;
  214. sym:=tstaticvarsym.create('$_static_'+static_name,varspez,hdef,[]);
  215. include(sym.symoptions,sp_internal);
  216. tabstractrecordsymtable(symtablestack.top).get_unit_symtable.insert(sym);
  217. { generate the symbol for the access }
  218. sl:=tpropaccesslist.create;
  219. sl.addsym(sl_load,sym);
  220. tmp:=tabsolutevarsym.create_ref(orgname,hdef,sl);
  221. tmp.visibility:=symtablestack.top.currentvisibility;
  222. symtablestack.top.insert(tmp);
  223. end
  224. else
  225. begin
  226. sym:=tstaticvarsym.create(orgname,varspez,hdef,[]);
  227. sym.visibility:=symtablestack.top.currentvisibility;
  228. symtablestack.top.insert(sym);
  229. end;
  230. current_tokenpos:=storetokenpos;
  231. { procvar can have proc directives, but not type references }
  232. if (hdef.typ=procvardef) and
  233. (hdef.typesym=nil) then
  234. begin
  235. { support p : procedure;stdcall=nil; }
  236. if try_to_consume(_SEMICOLON) then
  237. begin
  238. if check_proc_directive(true) then
  239. parse_var_proc_directives(sym)
  240. else
  241. begin
  242. Message(parser_e_proc_directive_expected);
  243. skipequal:=true;
  244. end;
  245. end
  246. else
  247. { support p : procedure stdcall=nil; }
  248. begin
  249. if check_proc_directive(true) then
  250. parse_var_proc_directives(sym);
  251. end;
  252. { add default calling convention }
  253. handle_calling_convention(tabstractprocdef(hdef));
  254. end;
  255. if not skipequal then
  256. begin
  257. { get init value }
  258. consume(_EQ);
  259. if (cs_typed_const_writable in current_settings.localswitches) then
  260. tclist:=current_asmdata.asmlists[al_rotypedconsts]
  261. else
  262. tclist:=current_asmdata.asmlists[al_typedconsts];
  263. read_typed_const(tclist,tstaticvarsym(sym),in_structure);
  264. end;
  265. end;
  266. else
  267. { generate an error }
  268. consume(_EQ);
  269. end;
  270. until (token<>_ID)or(in_structure and (idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]));
  271. block_type:=old_block_type;
  272. end;
  273. procedure label_dec;
  274. var
  275. labelsym : tlabelsym;
  276. begin
  277. consume(_LABEL);
  278. if not(cs_support_goto in current_settings.moduleswitches) then
  279. Message(sym_e_goto_and_label_not_supported);
  280. repeat
  281. if not(token in [_ID,_INTCONST]) then
  282. consume(_ID)
  283. else
  284. begin
  285. if token=_ID then
  286. labelsym:=tlabelsym.create(orgpattern)
  287. else
  288. labelsym:=tlabelsym.create(pattern);
  289. symtablestack.top.insert(labelsym);
  290. if m_non_local_goto in current_settings.modeswitches then
  291. begin
  292. if symtablestack.top.symtabletype=localsymtable then
  293. begin
  294. labelsym.jumpbuf:=tlocalvarsym.create('LABEL$_'+labelsym.name,vs_value,rec_jmp_buf,[]);
  295. symtablestack.top.insert(labelsym.jumpbuf);
  296. end
  297. else
  298. begin
  299. labelsym.jumpbuf:=tstaticvarsym.create('LABEL$_'+labelsym.name,vs_value,rec_jmp_buf,[]);
  300. symtablestack.top.insert(labelsym.jumpbuf);
  301. insertbssdata(tstaticvarsym(labelsym.jumpbuf));
  302. end;
  303. include(labelsym.jumpbuf.symoptions,sp_internal);
  304. { the buffer will be setup later, but avoid a hint }
  305. tabstractvarsym(labelsym.jumpbuf).varstate:=vs_written;
  306. end;
  307. consume(token);
  308. end;
  309. if token<>_SEMICOLON then consume(_COMMA);
  310. until not(token in [_ID,_INTCONST]);
  311. consume(_SEMICOLON);
  312. end;
  313. procedure types_dec(in_structure: boolean);
  314. procedure finalize_objc_class_or_protocol_external_status(od: tobjectdef);
  315. begin
  316. if [oo_is_external,oo_is_forward] <= od.objectoptions then
  317. begin
  318. { formal definition: x = objcclass external; }
  319. exclude(od.objectoptions,oo_is_forward);
  320. include(od.objectoptions,oo_is_formal);
  321. end;
  322. end;
  323. var
  324. typename,orgtypename : TIDString;
  325. newtype : ttypesym;
  326. sym : tsym;
  327. hdef : tdef;
  328. defpos,storetokenpos : tfileposinfo;
  329. old_block_type : tblock_type;
  330. old_checkforwarddefs: TFPObjectList;
  331. objecttype : tobjecttyp;
  332. isgeneric,
  333. isunique,
  334. istyperenaming : boolean;
  335. generictypelist : TFPObjectList;
  336. generictokenbuf : tdynamicarray;
  337. vmtbuilder : TVMTBuilder;
  338. i : integer;
  339. begin
  340. old_block_type:=block_type;
  341. { save unit container of forward declarations -
  342. we can be inside nested class type block }
  343. old_checkforwarddefs:=current_module.checkforwarddefs;
  344. current_module.checkforwarddefs:=TFPObjectList.Create(false);
  345. block_type:=bt_type;
  346. repeat
  347. defpos:=current_tokenpos;
  348. istyperenaming:=false;
  349. generictypelist:=nil;
  350. generictokenbuf:=nil;
  351. { fpc generic declaration? }
  352. isgeneric:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_GENERIC);
  353. typename:=pattern;
  354. orgtypename:=orgpattern;
  355. consume(_ID);
  356. { delphi generic declaration? }
  357. if (m_delphi in current_settings.modeswitches) then
  358. isgeneric:=token=_LSHARPBRACKET;
  359. { Generic type declaration? }
  360. if isgeneric then
  361. begin
  362. if assigned(current_genericdef) then
  363. Message(parser_f_no_generic_inside_generic);
  364. consume(_LSHARPBRACKET);
  365. generictypelist:=parse_generic_parameters;
  366. consume(_RSHARPBRACKET);
  367. end;
  368. consume(_EQ);
  369. { support 'ttype=type word' syntax }
  370. isunique:=try_to_consume(_TYPE);
  371. { MacPas object model is more like Delphi's than like TP's, but }
  372. { uses the object keyword instead of class }
  373. if (m_mac in current_settings.modeswitches) and
  374. (token = _OBJECT) then
  375. token := _CLASS;
  376. { Start recording a generic template }
  377. if assigned(generictypelist) then
  378. begin
  379. generictokenbuf:=tdynamicarray.create(256);
  380. current_scanner.startrecordtokens(generictokenbuf);
  381. end;
  382. { is the type already defined? -- must be in the current symtable,
  383. not in a nested symtable or one higher up the stack -> don't
  384. use searchsym & frinds! }
  385. sym:=tsym(symtablestack.top.find(typename));
  386. newtype:=nil;
  387. { found a symbol with this name? }
  388. if assigned(sym) then
  389. begin
  390. if (sym.typ=typesym) then
  391. begin
  392. if isgeneric then
  393. begin
  394. { overloading types is only allowed in mode Delphi }
  395. if not (m_delphi in current_settings.modeswitches) then
  396. Message1(sym_e_duplicate_id,orgtypename);
  397. for i:=0 to ttypesym(sym).gendeflist.Count-1 do
  398. { TODO : check whether the count of one of the defs is
  399. the same as that of the current declaration and
  400. print an error if so }
  401. ;
  402. end
  403. else
  404. if ((token=_CLASS) or
  405. (token=_INTERFACE) or
  406. (token=_DISPINTERFACE) or
  407. (token=_OBJCCLASS) or
  408. (token=_OBJCPROTOCOL) or
  409. (token=_OBJCCATEGORY)) and
  410. (assigned(ttypesym(sym).typedef)) and
  411. is_implicit_pointer_object_type(ttypesym(sym).typedef) and
  412. (oo_is_forward in tobjectdef(ttypesym(sym).typedef).objectoptions) then
  413. begin
  414. case token of
  415. _CLASS :
  416. objecttype:=odt_class;
  417. _INTERFACE :
  418. if current_settings.interfacetype=it_interfacecom then
  419. objecttype:=odt_interfacecom
  420. else
  421. objecttype:=odt_interfacecorba;
  422. _DISPINTERFACE :
  423. objecttype:=odt_dispinterface;
  424. _OBJCCLASS,
  425. _OBJCCATEGORY :
  426. objecttype:=odt_objcclass;
  427. _OBJCPROTOCOL :
  428. objecttype:=odt_objcprotocol;
  429. else
  430. internalerror(200811072);
  431. end;
  432. consume(token);
  433. { we can ignore the result, the definition is modified }
  434. object_dec(objecttype,orgtypename,nil,nil,tobjectdef(ttypesym(sym).typedef),ht_none);
  435. newtype:=ttypesym(sym);
  436. hdef:=newtype.typedef;
  437. end
  438. else
  439. if not (m_delphi in current_settings.modeswitches) and
  440. (ttypesym(sym).typedef.typ=undefineddef) and
  441. (ttypesym(sym).gendeflist.Count>0) then
  442. message1(sym_e_duplicate_id,orgtypename)
  443. else
  444. message1(parser_h_type_redef,orgtypename);
  445. end;
  446. end;
  447. { no old type reused ? Then insert this new type }
  448. if not assigned(newtype) then
  449. begin
  450. { insert the new type first with an errordef, so that
  451. referencing the type before it's really set it
  452. will give an error (PFV) }
  453. hdef:=generrordef;
  454. storetokenpos:=current_tokenpos;
  455. if isgeneric then
  456. begin
  457. if assigned(sym) then
  458. newtype:=ttypesym(sym)
  459. else
  460. begin
  461. { add the symbol with a undefineddef, so typesym can point
  462. to this symbol }
  463. newtype:=ttypesym.create(orgtypename,tundefineddef.create);
  464. newtype.typedef.typesym:=newtype;
  465. newtype.visibility:=symtablestack.top.currentvisibility;
  466. symtablestack.top.insert(newtype);
  467. newtype.typedef.owner:=newtype.owner;
  468. end;
  469. end
  470. else
  471. if assigned(sym) then
  472. newtype:=ttypesym(sym)
  473. else
  474. begin
  475. newtype:=ttypesym.create(orgtypename,hdef);
  476. newtype.visibility:=symtablestack.top.currentvisibility;
  477. symtablestack.top.insert(newtype);
  478. end;
  479. current_tokenpos:=defpos;
  480. current_tokenpos:=storetokenpos;
  481. { read the type definition }
  482. read_named_type(hdef,orgtypename,nil,generictypelist,false);
  483. { update the definition of the type }
  484. if assigned(hdef) then
  485. begin
  486. if assigned(hdef.typesym) then
  487. istyperenaming:=true;
  488. if isunique then
  489. begin
  490. if is_objc_class_or_protocol(hdef) then
  491. Message(parser_e_no_objc_unique);
  492. hdef:=tstoreddef(hdef).getcopy;
  493. { fix name, it is used e.g. for tables }
  494. if is_class_or_interface_or_dispinterface(hdef) then
  495. with tobjectdef(hdef) do
  496. begin
  497. stringdispose(objname);
  498. stringdispose(objrealname);
  499. objrealname:=stringdup(orgtypename);
  500. objname:=stringdup(upper(orgtypename));
  501. end;
  502. include(hdef.defoptions,df_unique);
  503. if (hdef.typ in [pointerdef,classrefdef]) and
  504. (tabstractpointerdef(hdef).pointeddef.typ=forwarddef) then
  505. current_module.checkforwarddefs.add(hdef);
  506. end;
  507. if not assigned(hdef.typesym) then
  508. hdef.typesym:=newtype;
  509. end;
  510. if isgeneric then begin
  511. newtype.Owner.includeoption(sto_has_generic);
  512. newtype.gendeflist.Add(hdef)
  513. end else
  514. newtype.typedef:=hdef;
  515. { KAZ: handle TGUID declaration in system unit }
  516. if (cs_compilesystem in current_settings.moduleswitches) and not assigned(rec_tguid) and
  517. (typename='TGUID') and { name: TGUID and size=16 bytes that is 128 bits }
  518. assigned(hdef) and (hdef.typ=recorddef) and (hdef.size=16) then
  519. rec_tguid:=trecorddef(hdef);
  520. end;
  521. if assigned(hdef) then
  522. begin
  523. case hdef.typ of
  524. pointerdef :
  525. begin
  526. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  527. consume(_SEMICOLON);
  528. if try_to_consume(_FAR) then
  529. begin
  530. tpointerdef(hdef).is_far:=true;
  531. consume(_SEMICOLON);
  532. end;
  533. end;
  534. procvardef :
  535. begin
  536. { in case of type renaming, don't parse proc directives }
  537. if istyperenaming then
  538. begin
  539. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  540. consume(_SEMICOLON);
  541. end
  542. else
  543. begin
  544. if not check_proc_directive(true) then
  545. begin
  546. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  547. consume(_SEMICOLON);
  548. end;
  549. parse_var_proc_directives(tsym(newtype));
  550. handle_calling_convention(tprocvardef(hdef));
  551. if try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg) then
  552. consume(_SEMICOLON);
  553. end;
  554. end;
  555. objectdef :
  556. begin
  557. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  558. consume(_SEMICOLON);
  559. { change a forward and external objcclass declaration into
  560. formal external definition, so the compiler does not
  561. expect an real definition later }
  562. if is_objc_class_or_protocol(hdef) then
  563. finalize_objc_class_or_protocol_external_status(tobjectdef(hdef));
  564. { Build VMT indexes, skip for type renaming and forward classes }
  565. if (hdef.typesym=newtype) and
  566. not(oo_is_forward in tobjectdef(hdef).objectoptions) and
  567. not(df_generic in hdef.defoptions) then
  568. begin
  569. vmtbuilder:=TVMTBuilder.Create(tobjectdef(hdef));
  570. vmtbuilder.generate_vmt;
  571. vmtbuilder.free;
  572. end;
  573. { In case of an objcclass, verify that all methods have a message
  574. name set. We only check this now, because message names can be set
  575. during the protocol (interface) mapping. At the same time, set the
  576. mangled names (these depend on the "external" name of the class),
  577. and mark private fields of external classes as "used" (to avoid
  578. bogus notes about them being unused)
  579. }
  580. { watch out for crashes in case of errors }
  581. if is_objc_class_or_protocol(hdef) and
  582. (not is_objccategory(hdef) or
  583. assigned(tobjectdef(hdef).childof)) then
  584. tobjectdef(hdef).finish_objc_data;
  585. if is_cppclass(hdef) then
  586. tobjectdef(hdef).finish_cpp_data;
  587. end;
  588. recorddef :
  589. begin
  590. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  591. consume(_SEMICOLON);
  592. end;
  593. else
  594. begin
  595. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  596. consume(_SEMICOLON);
  597. end;
  598. end;
  599. end;
  600. if isgeneric and (not(hdef.typ in [objectdef,recorddef,arraydef,procvardef])
  601. or is_objectpascal_helper(hdef)) then
  602. message(parser_e_cant_create_generics_of_this_type);
  603. { Stop recording a generic template }
  604. if assigned(generictypelist) then
  605. begin
  606. current_scanner.stoprecordtokens;
  607. tstoreddef(hdef).generictokenbuf:=generictokenbuf;
  608. { Generic is never a type renaming }
  609. hdef.typesym:=newtype;
  610. generictypelist.free;
  611. end;
  612. until (token<>_ID)or(in_structure and (idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]));
  613. { resolve type block forward declarations and restore a unit
  614. container for them }
  615. resolve_forward_types;
  616. current_module.checkforwarddefs.free;
  617. current_module.checkforwarddefs:=old_checkforwarddefs;
  618. block_type:=old_block_type;
  619. end;
  620. { reads a type declaration to the symbol table }
  621. procedure type_dec;
  622. begin
  623. consume(_TYPE);
  624. types_dec(false);
  625. end;
  626. procedure var_dec;
  627. { parses variable declarations and inserts them in }
  628. { the top symbol table of symtablestack }
  629. begin
  630. consume(_VAR);
  631. read_var_decls([]);
  632. end;
  633. procedure property_dec(is_classpropery: boolean);
  634. var
  635. old_block_type : tblock_type;
  636. begin
  637. consume(_PROPERTY);
  638. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  639. message(parser_e_resourcestring_only_sg);
  640. old_block_type:=block_type;
  641. block_type:=bt_const;
  642. repeat
  643. read_property_dec(is_classpropery, nil);
  644. consume(_SEMICOLON);
  645. until token<>_ID;
  646. block_type:=old_block_type;
  647. end;
  648. procedure threadvar_dec;
  649. { parses thread variable declarations and inserts them in }
  650. { the top symbol table of symtablestack }
  651. begin
  652. consume(_THREADVAR);
  653. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  654. message(parser_e_threadvars_only_sg);
  655. read_var_decls([vd_threadvar]);
  656. end;
  657. procedure resourcestring_dec;
  658. var
  659. orgname : TIDString;
  660. p : tnode;
  661. dummysymoptions : tsymoptions;
  662. deprecatedmsg : pshortstring;
  663. storetokenpos,filepos : tfileposinfo;
  664. old_block_type : tblock_type;
  665. sp : pchar;
  666. sym : tsym;
  667. begin
  668. consume(_RESOURCESTRING);
  669. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  670. message(parser_e_resourcestring_only_sg);
  671. old_block_type:=block_type;
  672. block_type:=bt_const;
  673. repeat
  674. orgname:=orgpattern;
  675. filepos:=current_tokenpos;
  676. consume(_ID);
  677. case token of
  678. _EQ:
  679. begin
  680. consume(_EQ);
  681. p:=comp_expr(true,false);
  682. storetokenpos:=current_tokenpos;
  683. current_tokenpos:=filepos;
  684. sym:=nil;
  685. case p.nodetype of
  686. ordconstn:
  687. begin
  688. if is_constcharnode(p) then
  689. begin
  690. getmem(sp,2);
  691. sp[0]:=chr(tordconstnode(p).value.svalue);
  692. sp[1]:=#0;
  693. sym:=tconstsym.create_string(orgname,constresourcestring,sp,1);
  694. end
  695. else
  696. Message(parser_e_illegal_expression);
  697. end;
  698. stringconstn:
  699. with Tstringconstnode(p) do
  700. begin
  701. getmem(sp,len+1);
  702. move(value_str^,sp^,len+1);
  703. sym:=tconstsym.create_string(orgname,constresourcestring,sp,len);
  704. end;
  705. else
  706. Message(parser_e_illegal_expression);
  707. end;
  708. current_tokenpos:=storetokenpos;
  709. { Support hint directives }
  710. dummysymoptions:=[];
  711. deprecatedmsg:=nil;
  712. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  713. if assigned(sym) then
  714. begin
  715. sym.symoptions:=sym.symoptions+dummysymoptions;
  716. sym.deprecatedmsg:=deprecatedmsg;
  717. symtablestack.top.insert(sym);
  718. end
  719. else
  720. stringdispose(deprecatedmsg);
  721. consume(_SEMICOLON);
  722. p.free;
  723. end;
  724. else consume(_EQ);
  725. end;
  726. until token<>_ID;
  727. block_type:=old_block_type;
  728. end;
  729. end.