pdecl.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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_class: boolean);
  30. procedure label_dec;
  31. procedure type_dec;
  32. procedure types_dec(in_class: 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);
  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_class: boolean);
  149. var
  150. orgname : TIDString;
  151. hdef : tdef;
  152. sym : 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. begin
  161. old_block_type:=block_type;
  162. block_type:=bt_const;
  163. repeat
  164. orgname:=orgpattern;
  165. filepos:=current_tokenpos;
  166. consume(_ID);
  167. case token of
  168. _EQUAL:
  169. begin
  170. consume(_EQUAL);
  171. sym:=readconstant(orgname,filepos);
  172. { Support hint directives }
  173. dummysymoptions:=[];
  174. deprecatedmsg:=nil;
  175. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  176. if assigned(sym) then
  177. begin
  178. sym.symoptions:=sym.symoptions+dummysymoptions;
  179. sym.deprecatedmsg:=deprecatedmsg;
  180. sym.visibility:=symtablestack.top.currentvisibility;
  181. symtablestack.top.insert(sym);
  182. end
  183. else
  184. stringdispose(deprecatedmsg);
  185. consume(_SEMICOLON);
  186. end;
  187. _COLON:
  188. begin
  189. { set the blocktype first so a consume also supports a
  190. caret, to support const s : ^string = nil }
  191. block_type:=bt_const_type;
  192. consume(_COLON);
  193. read_anon_type(hdef,false);
  194. block_type:=bt_const;
  195. skipequal:=false;
  196. { create symbol }
  197. storetokenpos:=current_tokenpos;
  198. current_tokenpos:=filepos;
  199. if not (cs_typed_const_writable in current_settings.localswitches) then
  200. varspez:=vs_const
  201. else
  202. varspez:=vs_value;
  203. sym:=tstaticvarsym.create(orgname,varspez,hdef,[]);
  204. sym.visibility:=symtablestack.top.currentvisibility;
  205. current_tokenpos:=storetokenpos;
  206. symtablestack.top.insert(sym);
  207. { procvar can have proc directives, but not type references }
  208. if (hdef.typ=procvardef) and
  209. (hdef.typesym=nil) then
  210. begin
  211. { support p : procedure;stdcall=nil; }
  212. if try_to_consume(_SEMICOLON) then
  213. begin
  214. if check_proc_directive(true) then
  215. parse_var_proc_directives(sym)
  216. else
  217. begin
  218. Message(parser_e_proc_directive_expected);
  219. skipequal:=true;
  220. end;
  221. end
  222. else
  223. { support p : procedure stdcall=nil; }
  224. begin
  225. if check_proc_directive(true) then
  226. parse_var_proc_directives(sym);
  227. end;
  228. { add default calling convention }
  229. handle_calling_convention(tabstractprocdef(hdef));
  230. end;
  231. if not skipequal then
  232. begin
  233. { get init value }
  234. consume(_EQUAL);
  235. if (cs_typed_const_writable in current_settings.localswitches) then
  236. tclist:=current_asmdata.asmlists[al_rotypedconsts]
  237. else
  238. tclist:=current_asmdata.asmlists[al_typedconsts];
  239. read_typed_const(tclist,tstaticvarsym(sym),in_class);
  240. end;
  241. end;
  242. else
  243. { generate an error }
  244. consume(_EQUAL);
  245. end;
  246. until (token<>_ID)or(in_class and (idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]));
  247. block_type:=old_block_type;
  248. end;
  249. procedure label_dec;
  250. begin
  251. consume(_LABEL);
  252. if not(cs_support_goto in current_settings.moduleswitches) then
  253. Message(sym_e_goto_and_label_not_supported);
  254. repeat
  255. if not(token in [_ID,_INTCONST]) then
  256. consume(_ID)
  257. else
  258. begin
  259. if token=_ID then
  260. symtablestack.top.insert(tlabelsym.create(orgpattern))
  261. else
  262. symtablestack.top.insert(tlabelsym.create(pattern));
  263. consume(token);
  264. end;
  265. if token<>_SEMICOLON then consume(_COMMA);
  266. until not(token in [_ID,_INTCONST]);
  267. consume(_SEMICOLON);
  268. end;
  269. procedure types_dec(in_class: boolean);
  270. procedure get_cpp_class_external_status(od: tobjectdef);
  271. var
  272. hs: string;
  273. begin
  274. { C++ classes can be external -> all methods inside are external
  275. (defined at the class level instead of per method, so that you cannot
  276. define some methods as external and some not)
  277. }
  278. if (token=_ID) and
  279. (idtoken=_EXTERNAL) then
  280. begin
  281. consume(_EXTERNAL);
  282. { copied from pdecsub.pd_external }
  283. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  284. begin
  285. { Always add library prefix and suffix to create an uniform name }
  286. hs:=get_stringconst;
  287. if ExtractFileExt(hs)='' then
  288. hs:=ChangeFileExt(hs,target_info.sharedlibext);
  289. if Copy(hs,1,length(target_info.sharedlibprefix))<>target_info.sharedlibprefix then
  290. hs:=target_info.sharedlibprefix+hs;
  291. od.import_lib:=stringdup(hs);
  292. end;
  293. include(od.objectoptions, oo_is_external);
  294. { check if we shall use another name for the class }
  295. if (token=_ID) and
  296. (idtoken=_NAME) then
  297. begin
  298. consume(_NAME);
  299. od.objextname:=stringdup(get_stringconst);
  300. end
  301. else
  302. od.objextname:=stringdup(od.objrealname^);
  303. consume(_SEMICOLON);
  304. { now all methods need to be external }
  305. od.make_all_methods_external;
  306. include(od.objectoptions,oo_is_external);
  307. end
  308. else
  309. od.objextname:=stringdup(od.objrealname^);
  310. { ToDo: read the namespace of the class (influences the mangled name)}
  311. end;
  312. procedure get_objc_class_or_protocol_external_status(od: tobjectdef);
  313. begin
  314. { Objective-C classes can be external -> all messages inside are
  315. external (defined at the class level instead of per method, so
  316. that you cannot define some methods as external and some not)
  317. }
  318. if (token=_ID) and
  319. (idtoken=_EXTERNAL) then
  320. begin
  321. consume(_EXTERNAL);
  322. if (token=_ID) and
  323. (idtoken=_NAME) and
  324. not(oo_is_forward in od.objectoptions) then
  325. begin
  326. consume(_NAME);
  327. od.objextname:=stringdup(get_stringconst);
  328. end
  329. else
  330. { the external name doesn't matter for formally declared
  331. classes, and allowing to specify one would mean that we would
  332. have to check it for consistency with the actual definition
  333. later on }
  334. od.objextname:=stringdup(od.objrealname^);
  335. consume(_SEMICOLON);
  336. od.make_all_methods_external;
  337. include(od.objectoptions,oo_is_external);
  338. if (oo_is_forward in od.objectoptions) then
  339. begin
  340. { formal definition: x = objcclass; external; }
  341. exclude(od.objectoptions,oo_is_forward);
  342. include(od.objectoptions,oo_is_formal);
  343. end;
  344. end
  345. else { or also allow "public name 'x'"? }
  346. od.objextname:=stringdup(od.objrealname^);
  347. end;
  348. function parse_generic_parameters:TFPObjectList;
  349. var
  350. generictype : ttypesym;
  351. begin
  352. result:=TFPObjectList.Create(false);
  353. repeat
  354. if token=_ID then
  355. begin
  356. generictype:=ttypesym.create(orgpattern,cundefinedtype);
  357. include(generictype.symoptions,sp_generic_para);
  358. result.add(generictype);
  359. end;
  360. consume(_ID);
  361. until not try_to_consume(_COMMA) ;
  362. end;
  363. var
  364. typename,orgtypename : TIDString;
  365. newtype : ttypesym;
  366. sym : tsym;
  367. srsymtable : TSymtable;
  368. hdef : tdef;
  369. defpos,storetokenpos : tfileposinfo;
  370. old_block_type : tblock_type;
  371. objecttype : tobjecttyp;
  372. isgeneric,
  373. isunique,
  374. istyperenaming : boolean;
  375. generictypelist : TFPObjectList;
  376. generictokenbuf : tdynamicarray;
  377. vmtbuilder : TVMTBuilder;
  378. begin
  379. old_block_type:=block_type;
  380. block_type:=bt_type;
  381. repeat
  382. defpos:=current_tokenpos;
  383. istyperenaming:=false;
  384. generictypelist:=nil;
  385. generictokenbuf:=nil;
  386. { generic declaration? }
  387. isgeneric:=try_to_consume(_GENERIC);
  388. typename:=pattern;
  389. orgtypename:=orgpattern;
  390. consume(_ID);
  391. { Generic type declaration? }
  392. if isgeneric then
  393. begin
  394. consume(_LSHARPBRACKET);
  395. generictypelist:=parse_generic_parameters;
  396. consume(_RSHARPBRACKET);
  397. end;
  398. consume(_EQUAL);
  399. { support 'ttype=type word' syntax }
  400. isunique:=try_to_consume(_TYPE);
  401. { MacPas object model is more like Delphi's than like TP's, but }
  402. { uses the object keyword instead of class }
  403. if (m_mac in current_settings.modeswitches) and
  404. (token = _OBJECT) then
  405. token := _CLASS;
  406. { Start recording a generic template }
  407. if assigned(generictypelist) then
  408. begin
  409. generictokenbuf:=tdynamicarray.create(256);
  410. current_scanner.startrecordtokens(generictokenbuf);
  411. end;
  412. { is the type already defined? }
  413. searchsym(typename,sym,srsymtable);
  414. newtype:=nil;
  415. { found a symbol with this name? }
  416. if assigned(sym) then
  417. begin
  418. if (sym.typ=typesym) then
  419. begin
  420. if ((token=_CLASS) or
  421. (token=_INTERFACE) or
  422. (token=_DISPINTERFACE) or
  423. (token=_OBJCCLASS) or
  424. (token=_OBJCPROTOCOL) or
  425. (token=_OBJCCATEGORY)) and
  426. (assigned(ttypesym(sym).typedef)) and
  427. is_class_or_interface_or_dispinterface_or_objc(ttypesym(sym).typedef) and
  428. (oo_is_forward in tobjectdef(ttypesym(sym).typedef).objectoptions) then
  429. begin
  430. case token of
  431. _CLASS :
  432. objecttype:=odt_class;
  433. _INTERFACE :
  434. if current_settings.interfacetype=it_interfacecom then
  435. objecttype:=odt_interfacecom
  436. else
  437. objecttype:=odt_interfacecorba;
  438. _DISPINTERFACE :
  439. objecttype:=odt_dispinterface;
  440. _OBJCCLASS,
  441. _OBJCCATEGORY :
  442. objecttype:=odt_objcclass;
  443. _OBJCPROTOCOL :
  444. objecttype:=odt_objcprotocol;
  445. else
  446. internalerror(200811072);
  447. end;
  448. consume(token);
  449. { we can ignore the result, the definition is modified }
  450. object_dec(objecttype,orgtypename,nil,nil,tobjectdef(ttypesym(sym).typedef));
  451. newtype:=ttypesym(sym);
  452. hdef:=newtype.typedef;
  453. end
  454. else
  455. message1(parser_h_type_redef,orgtypename);
  456. end;
  457. end;
  458. { no old type reused ? Then insert this new type }
  459. if not assigned(newtype) then
  460. begin
  461. { insert the new type first with an errordef, so that
  462. referencing the type before it's really set it
  463. will give an error (PFV) }
  464. hdef:=generrordef;
  465. storetokenpos:=current_tokenpos;
  466. newtype:=ttypesym.create(orgtypename,hdef);
  467. newtype.visibility:=symtablestack.top.currentvisibility;
  468. symtablestack.top.insert(newtype);
  469. current_tokenpos:=defpos;
  470. current_tokenpos:=storetokenpos;
  471. { read the type definition }
  472. read_named_type(hdef,orgtypename,nil,generictypelist,false);
  473. { update the definition of the type }
  474. if assigned(hdef) then
  475. begin
  476. if assigned(hdef.typesym) then
  477. istyperenaming:=true;
  478. if isunique then
  479. begin
  480. if is_objc_class_or_protocol(hdef) then
  481. Message(parser_e_no_objc_unique);
  482. hdef:=tstoreddef(hdef).getcopy;
  483. { fix name, it is used e.g. for tables }
  484. if is_class_or_interface_or_dispinterface(hdef) then
  485. with tobjectdef(hdef) do
  486. begin
  487. stringdispose(objname);
  488. stringdispose(objrealname);
  489. objrealname:=stringdup(orgtypename);
  490. objname:=stringdup(upper(orgtypename));
  491. end;
  492. include(hdef.defoptions,df_unique);
  493. end;
  494. if not assigned(hdef.typesym) then
  495. hdef.typesym:=newtype;
  496. end;
  497. newtype.typedef:=hdef;
  498. { KAZ: handle TGUID declaration in system unit }
  499. if (cs_compilesystem in current_settings.moduleswitches) and not assigned(rec_tguid) and
  500. (typename='TGUID') and { name: TGUID and size=16 bytes that is 128 bits }
  501. assigned(hdef) and (hdef.typ=recorddef) and (hdef.size=16) then
  502. rec_tguid:=trecorddef(hdef);
  503. end;
  504. if assigned(hdef) then
  505. begin
  506. case hdef.typ of
  507. pointerdef :
  508. begin
  509. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  510. consume(_SEMICOLON);
  511. if try_to_consume(_FAR) then
  512. begin
  513. tpointerdef(hdef).is_far:=true;
  514. consume(_SEMICOLON);
  515. end;
  516. end;
  517. procvardef :
  518. begin
  519. { in case of type renaming, don't parse proc directives }
  520. if istyperenaming then
  521. begin
  522. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  523. consume(_SEMICOLON);
  524. end
  525. else
  526. begin
  527. if not check_proc_directive(true) then
  528. begin
  529. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  530. consume(_SEMICOLON);
  531. end;
  532. parse_var_proc_directives(tsym(newtype));
  533. handle_calling_convention(tprocvardef(hdef));
  534. if try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg) then
  535. consume(_SEMICOLON);
  536. end;
  537. end;
  538. objectdef :
  539. begin
  540. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  541. consume(_SEMICOLON);
  542. { we have to know whether the class or protocol is
  543. external before the vmt is built, because some errors/
  544. hints depend on this }
  545. if is_objc_class_or_protocol(hdef) then
  546. get_objc_class_or_protocol_external_status(tobjectdef(hdef));
  547. if is_cppclass(hdef) then
  548. get_cpp_class_external_status(tobjectdef(hdef));
  549. { Build VMT indexes, skip for type renaming and forward classes }
  550. if (hdef.typesym=newtype) and
  551. not(oo_is_forward in tobjectdef(hdef).objectoptions) and
  552. not(df_generic in hdef.defoptions) then
  553. begin
  554. vmtbuilder:=TVMTBuilder.Create(tobjectdef(hdef));
  555. vmtbuilder.generate_vmt;
  556. vmtbuilder.free;
  557. end;
  558. { In case of an objcclass, verify that all methods have a message
  559. name set. We only check this now, because message names can be set
  560. during the protocol (interface) mapping. At the same time, set the
  561. mangled names (these depend on the "external" name of the class),
  562. and mark private fields of external classes as "used" (to avoid
  563. bogus notes about them being unused)
  564. }
  565. { watch out for crashes in case of errors }
  566. if is_objc_class_or_protocol(hdef) and
  567. (not is_objccategory(hdef) or
  568. assigned(tobjectdef(hdef).childof)) then
  569. tobjectdef(hdef).finish_objc_data;
  570. if is_cppclass(hdef) then
  571. tobjectdef(hdef).finish_cpp_data;
  572. end;
  573. recorddef :
  574. begin
  575. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  576. consume(_SEMICOLON);
  577. end;
  578. else
  579. begin
  580. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  581. consume(_SEMICOLON);
  582. end;
  583. end;
  584. end;
  585. if isgeneric and not(hdef.typ in [objectdef,recorddef]) then
  586. message(parser_e_cant_create_generics_of_this_type);
  587. { Stop recording a generic template }
  588. if assigned(generictypelist) then
  589. begin
  590. current_scanner.stoprecordtokens;
  591. tstoreddef(hdef).generictokenbuf:=generictokenbuf;
  592. { Generic is never a type renaming }
  593. hdef.typesym:=newtype;
  594. end;
  595. if assigned(generictypelist) then
  596. generictypelist.free;
  597. until (token<>_ID)or(in_class and (idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]));
  598. resolve_forward_types;
  599. block_type:=old_block_type;
  600. end;
  601. { reads a type declaration to the symbol table }
  602. procedure type_dec;
  603. begin
  604. consume(_TYPE);
  605. types_dec(false);
  606. end;
  607. procedure var_dec;
  608. { parses variable declarations and inserts them in }
  609. { the top symbol table of symtablestack }
  610. begin
  611. consume(_VAR);
  612. read_var_decls([]);
  613. end;
  614. procedure property_dec(is_classpropery: boolean);
  615. var
  616. old_block_type : tblock_type;
  617. begin
  618. consume(_PROPERTY);
  619. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  620. message(parser_e_resourcestring_only_sg);
  621. old_block_type:=block_type;
  622. block_type:=bt_const;
  623. repeat
  624. read_property_dec(is_classpropery, nil);
  625. consume(_SEMICOLON);
  626. until token<>_ID;
  627. block_type:=old_block_type;
  628. end;
  629. procedure threadvar_dec;
  630. { parses thread variable declarations and inserts them in }
  631. { the top symbol table of symtablestack }
  632. begin
  633. consume(_THREADVAR);
  634. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  635. message(parser_e_threadvars_only_sg);
  636. read_var_decls([vd_threadvar]);
  637. end;
  638. procedure resourcestring_dec;
  639. var
  640. orgname : TIDString;
  641. p : tnode;
  642. dummysymoptions : tsymoptions;
  643. deprecatedmsg : pshortstring;
  644. storetokenpos,filepos : tfileposinfo;
  645. old_block_type : tblock_type;
  646. sp : pchar;
  647. sym : tsym;
  648. begin
  649. consume(_RESOURCESTRING);
  650. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  651. message(parser_e_resourcestring_only_sg);
  652. old_block_type:=block_type;
  653. block_type:=bt_const;
  654. repeat
  655. orgname:=orgpattern;
  656. filepos:=current_tokenpos;
  657. consume(_ID);
  658. case token of
  659. _EQUAL:
  660. begin
  661. consume(_EQUAL);
  662. p:=comp_expr(true);
  663. storetokenpos:=current_tokenpos;
  664. current_tokenpos:=filepos;
  665. sym:=nil;
  666. case p.nodetype of
  667. ordconstn:
  668. begin
  669. if is_constcharnode(p) then
  670. begin
  671. getmem(sp,2);
  672. sp[0]:=chr(tordconstnode(p).value.svalue);
  673. sp[1]:=#0;
  674. sym:=tconstsym.create_string(orgname,constresourcestring,sp,1);
  675. end
  676. else
  677. Message(parser_e_illegal_expression);
  678. end;
  679. stringconstn:
  680. with Tstringconstnode(p) do
  681. begin
  682. getmem(sp,len+1);
  683. move(value_str^,sp^,len+1);
  684. sym:=tconstsym.create_string(orgname,constresourcestring,sp,len);
  685. end;
  686. else
  687. Message(parser_e_illegal_expression);
  688. end;
  689. current_tokenpos:=storetokenpos;
  690. { Support hint directives }
  691. dummysymoptions:=[];
  692. deprecatedmsg:=nil;
  693. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  694. if assigned(sym) then
  695. begin
  696. sym.symoptions:=sym.symoptions+dummysymoptions;
  697. sym.deprecatedmsg:=deprecatedmsg;
  698. symtablestack.top.insert(sym);
  699. end
  700. else
  701. stringdispose(deprecatedmsg);
  702. consume(_SEMICOLON);
  703. p.free;
  704. end;
  705. else consume(_EQUAL);
  706. end;
  707. until token<>_ID;
  708. block_type:=old_block_type;
  709. end;
  710. end.