pdecl.pas 31 KB

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