pdecl.pas 29 KB

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