pdecl.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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,
  325. gentypename,genorgtypename : TIDString;
  326. newtype : ttypesym;
  327. sym : tsym;
  328. hdef : tdef;
  329. defpos,storetokenpos : tfileposinfo;
  330. old_block_type : tblock_type;
  331. old_checkforwarddefs: TFPObjectList;
  332. objecttype : tobjecttyp;
  333. isgeneric,
  334. isunique,
  335. istyperenaming : boolean;
  336. generictypelist : TFPObjectList;
  337. generictokenbuf : tdynamicarray;
  338. vmtbuilder : TVMTBuilder;
  339. i : integer;
  340. s : shortstring;
  341. begin
  342. old_block_type:=block_type;
  343. { save unit container of forward declarations -
  344. we can be inside nested class type block }
  345. old_checkforwarddefs:=current_module.checkforwarddefs;
  346. current_module.checkforwarddefs:=TFPObjectList.Create(false);
  347. block_type:=bt_type;
  348. repeat
  349. defpos:=current_tokenpos;
  350. istyperenaming:=false;
  351. generictypelist:=nil;
  352. generictokenbuf:=nil;
  353. { fpc generic declaration? }
  354. isgeneric:=not(m_delphi in current_settings.modeswitches) and try_to_consume(_GENERIC);
  355. typename:=pattern;
  356. orgtypename:=orgpattern;
  357. consume(_ID);
  358. { delphi generic declaration? }
  359. if (m_delphi in current_settings.modeswitches) then
  360. isgeneric:=token=_LSHARPBRACKET;
  361. { Generic type declaration? }
  362. if isgeneric then
  363. begin
  364. if assigned(current_genericdef) then
  365. Message(parser_f_no_generic_inside_generic);
  366. consume(_LSHARPBRACKET);
  367. generictypelist:=parse_generic_parameters;
  368. consume(_RSHARPBRACKET);
  369. str(generictypelist.Count,s);
  370. gentypename:=typename+'$'+s;
  371. genorgtypename:=orgtypename+'$'+s;
  372. end
  373. else
  374. begin
  375. gentypename:=typename;
  376. genorgtypename:=orgtypename;
  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? -- must be in the current symtable,
  393. not in a nested symtable or one higher up the stack -> don't
  394. use searchsym & frinds! }
  395. sym:=tsym(symtablestack.top.find(gentypename));
  396. newtype:=nil;
  397. { found a symbol with this name? }
  398. if assigned(sym) then
  399. begin
  400. if (sym.typ=typesym) and
  401. { this should not be a symbol that was created by a generic
  402. that was declared earlier }
  403. not (
  404. (ttypesym(sym).typedef.typ=undefineddef) and
  405. not (sp_generic_para in sym.symoptions)
  406. ) then
  407. begin
  408. if ((token=_CLASS) or
  409. (token=_INTERFACE) or
  410. (token=_DISPINTERFACE) or
  411. (token=_OBJCCLASS) or
  412. (token=_OBJCPROTOCOL) or
  413. (token=_OBJCCATEGORY)) and
  414. (assigned(ttypesym(sym).typedef)) and
  415. is_implicit_pointer_object_type(ttypesym(sym).typedef) and
  416. (oo_is_forward in tobjectdef(ttypesym(sym).typedef).objectoptions) then
  417. begin
  418. case token of
  419. _CLASS :
  420. objecttype:=odt_class;
  421. _INTERFACE :
  422. if current_settings.interfacetype=it_interfacecom then
  423. objecttype:=odt_interfacecom
  424. else
  425. objecttype:=odt_interfacecorba;
  426. _DISPINTERFACE :
  427. objecttype:=odt_dispinterface;
  428. _OBJCCLASS,
  429. _OBJCCATEGORY :
  430. objecttype:=odt_objcclass;
  431. _OBJCPROTOCOL :
  432. objecttype:=odt_objcprotocol;
  433. else
  434. internalerror(200811072);
  435. end;
  436. consume(token);
  437. { we can ignore the result, the definition is modified }
  438. object_dec(objecttype,genorgtypename,nil,nil,tobjectdef(ttypesym(sym).typedef),ht_none);
  439. newtype:=ttypesym(sym);
  440. hdef:=newtype.typedef;
  441. end
  442. else
  443. message1(parser_h_type_redef,genorgtypename);
  444. end;
  445. end;
  446. { no old type reused ? Then insert this new type }
  447. if not assigned(newtype) then
  448. begin
  449. { insert the new type first with an errordef, so that
  450. referencing the type before it's really set it
  451. will give an error (PFV) }
  452. hdef:=generrordef;
  453. storetokenpos:=current_tokenpos;
  454. if isgeneric then
  455. begin
  456. { for generics we need to check whether a non-generic type
  457. already exists and if not we need to insert a symbol with
  458. the non-generic name (available in (org)typename) that is a
  459. undefineddef, so that inline specializations can be used }
  460. sym:=tsym(symtablestack.top.Find(typename));
  461. if not assigned(sym) then
  462. begin
  463. sym:=ttypesym.create(orgtypename,tundefineddef.create);
  464. ttypesym(sym).typedef.typesym:=sym;
  465. sym.visibility:=symtablestack.top.currentvisibility;
  466. symtablestack.top.insert(sym);
  467. ttypesym(sym).typedef.owner:=sym.owner;
  468. end
  469. else
  470. { this is not allowed in non-Delphi modes }
  471. if not (m_delphi in current_settings.modeswitches) then
  472. Message1(sym_e_duplicate_id,genorgtypename);
  473. end
  474. else
  475. if assigned(sym) and (sym.typ=typesym) and
  476. (ttypesym(sym).typedef.typ=undefineddef) and
  477. not (sp_generic_para in sym.symoptions) then
  478. begin
  479. { this is a symbol that was added by an earlier generic
  480. declaration, reuse it }
  481. newtype:=ttypesym(sym);
  482. newtype.typedef:=hdef;
  483. end;
  484. { insert a newtype if we don't reuse an existing symbol }
  485. if not assigned(newtype) then
  486. begin
  487. newtype:=ttypesym.create(genorgtypename,hdef);
  488. newtype.visibility:=symtablestack.top.currentvisibility;
  489. symtablestack.top.insert(newtype);
  490. end;
  491. current_tokenpos:=defpos;
  492. current_tokenpos:=storetokenpos;
  493. { read the type definition }
  494. read_named_type(hdef,genorgtypename,nil,generictypelist,false);
  495. { update the definition of the type }
  496. if assigned(hdef) then
  497. begin
  498. if assigned(hdef.typesym) then
  499. istyperenaming:=true;
  500. if isunique then
  501. begin
  502. if is_objc_class_or_protocol(hdef) then
  503. Message(parser_e_no_objc_unique);
  504. hdef:=tstoreddef(hdef).getcopy;
  505. { fix name, it is used e.g. for tables }
  506. if is_class_or_interface_or_dispinterface(hdef) then
  507. with tobjectdef(hdef) do
  508. begin
  509. stringdispose(objname);
  510. stringdispose(objrealname);
  511. objrealname:=stringdup(genorgtypename);
  512. objname:=stringdup(upper(genorgtypename));
  513. end;
  514. include(hdef.defoptions,df_unique);
  515. if (hdef.typ in [pointerdef,classrefdef]) and
  516. (tabstractpointerdef(hdef).pointeddef.typ=forwarddef) then
  517. current_module.checkforwarddefs.add(hdef);
  518. end;
  519. if not assigned(hdef.typesym) then
  520. hdef.typesym:=newtype;
  521. end;
  522. { in non-Delphi modes we need a reference to the generic def
  523. without the generic suffix, so it can be found easily when
  524. parsing method implementations }
  525. if isgeneric and assigned(sym) and
  526. not (m_delphi in current_settings.modeswitches) and
  527. (ttypesym(sym).typedef.typ=undefineddef) then
  528. { TODO : check whether the undefined def needs to be freed }
  529. ttypesym(sym).typedef:=hdef;
  530. newtype.typedef:=hdef;
  531. { KAZ: handle TGUID declaration in system unit }
  532. if (cs_compilesystem in current_settings.moduleswitches) and not assigned(rec_tguid) and
  533. (gentypename='TGUID') and { name: TGUID and size=16 bytes that is 128 bits }
  534. assigned(hdef) and (hdef.typ=recorddef) and (hdef.size=16) then
  535. rec_tguid:=trecorddef(hdef);
  536. end;
  537. if assigned(hdef) then
  538. begin
  539. case hdef.typ of
  540. pointerdef :
  541. begin
  542. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  543. consume(_SEMICOLON);
  544. if try_to_consume(_FAR) then
  545. begin
  546. tpointerdef(hdef).is_far:=true;
  547. consume(_SEMICOLON);
  548. end;
  549. end;
  550. procvardef :
  551. begin
  552. { in case of type renaming, don't parse proc directives }
  553. if istyperenaming then
  554. begin
  555. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  556. consume(_SEMICOLON);
  557. end
  558. else
  559. begin
  560. if not check_proc_directive(true) then
  561. begin
  562. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  563. consume(_SEMICOLON);
  564. end;
  565. parse_var_proc_directives(tsym(newtype));
  566. handle_calling_convention(tprocvardef(hdef));
  567. if try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg) then
  568. consume(_SEMICOLON);
  569. end;
  570. end;
  571. objectdef :
  572. begin
  573. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  574. consume(_SEMICOLON);
  575. { change a forward and external objcclass declaration into
  576. formal external definition, so the compiler does not
  577. expect an real definition later }
  578. if is_objc_class_or_protocol(hdef) then
  579. finalize_objc_class_or_protocol_external_status(tobjectdef(hdef));
  580. { Build VMT indexes, skip for type renaming and forward classes }
  581. if (hdef.typesym=newtype) and
  582. not(oo_is_forward in tobjectdef(hdef).objectoptions) and
  583. not(df_generic in hdef.defoptions) then
  584. begin
  585. vmtbuilder:=TVMTBuilder.Create(tobjectdef(hdef));
  586. vmtbuilder.generate_vmt;
  587. vmtbuilder.free;
  588. end;
  589. { In case of an objcclass, verify that all methods have a message
  590. name set. We only check this now, because message names can be set
  591. during the protocol (interface) mapping. At the same time, set the
  592. mangled names (these depend on the "external" name of the class),
  593. and mark private fields of external classes as "used" (to avoid
  594. bogus notes about them being unused)
  595. }
  596. { watch out for crashes in case of errors }
  597. if is_objc_class_or_protocol(hdef) and
  598. (not is_objccategory(hdef) or
  599. assigned(tobjectdef(hdef).childof)) then
  600. tobjectdef(hdef).finish_objc_data;
  601. if is_cppclass(hdef) then
  602. tobjectdef(hdef).finish_cpp_data;
  603. end;
  604. recorddef :
  605. begin
  606. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  607. consume(_SEMICOLON);
  608. end;
  609. else
  610. begin
  611. try_consume_hintdirective(newtype.symoptions,newtype.deprecatedmsg);
  612. consume(_SEMICOLON);
  613. end;
  614. end;
  615. end;
  616. if isgeneric and (not(hdef.typ in [objectdef,recorddef,arraydef,procvardef])
  617. or is_objectpascal_helper(hdef)) then
  618. message(parser_e_cant_create_generics_of_this_type);
  619. { Stop recording a generic template }
  620. if assigned(generictypelist) then
  621. begin
  622. current_scanner.stoprecordtokens;
  623. tstoreddef(hdef).generictokenbuf:=generictokenbuf;
  624. { Generic is never a type renaming }
  625. hdef.typesym:=newtype;
  626. generictypelist.free;
  627. end;
  628. until (token<>_ID)or(in_structure and (idtoken in [_PRIVATE,_PROTECTED,_PUBLIC,_PUBLISHED,_STRICT]));
  629. { resolve type block forward declarations and restore a unit
  630. container for them }
  631. resolve_forward_types;
  632. current_module.checkforwarddefs.free;
  633. current_module.checkforwarddefs:=old_checkforwarddefs;
  634. block_type:=old_block_type;
  635. end;
  636. { reads a type declaration to the symbol table }
  637. procedure type_dec;
  638. begin
  639. consume(_TYPE);
  640. types_dec(false);
  641. end;
  642. procedure var_dec;
  643. { parses variable declarations and inserts them in }
  644. { the top symbol table of symtablestack }
  645. begin
  646. consume(_VAR);
  647. read_var_decls([]);
  648. end;
  649. procedure property_dec(is_classpropery: boolean);
  650. var
  651. old_block_type : tblock_type;
  652. begin
  653. consume(_PROPERTY);
  654. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  655. message(parser_e_resourcestring_only_sg);
  656. old_block_type:=block_type;
  657. block_type:=bt_const;
  658. repeat
  659. read_property_dec(is_classpropery, nil);
  660. consume(_SEMICOLON);
  661. until token<>_ID;
  662. block_type:=old_block_type;
  663. end;
  664. procedure threadvar_dec;
  665. { parses thread variable declarations and inserts them in }
  666. { the top symbol table of symtablestack }
  667. begin
  668. consume(_THREADVAR);
  669. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  670. message(parser_e_threadvars_only_sg);
  671. read_var_decls([vd_threadvar]);
  672. end;
  673. procedure resourcestring_dec;
  674. var
  675. orgname : TIDString;
  676. p : tnode;
  677. dummysymoptions : tsymoptions;
  678. deprecatedmsg : pshortstring;
  679. storetokenpos,filepos : tfileposinfo;
  680. old_block_type : tblock_type;
  681. sp : pchar;
  682. sym : tsym;
  683. begin
  684. consume(_RESOURCESTRING);
  685. if not(symtablestack.top.symtabletype in [staticsymtable,globalsymtable]) then
  686. message(parser_e_resourcestring_only_sg);
  687. old_block_type:=block_type;
  688. block_type:=bt_const;
  689. repeat
  690. orgname:=orgpattern;
  691. filepos:=current_tokenpos;
  692. consume(_ID);
  693. case token of
  694. _EQ:
  695. begin
  696. consume(_EQ);
  697. p:=comp_expr(true,false);
  698. storetokenpos:=current_tokenpos;
  699. current_tokenpos:=filepos;
  700. sym:=nil;
  701. case p.nodetype of
  702. ordconstn:
  703. begin
  704. if is_constcharnode(p) then
  705. begin
  706. getmem(sp,2);
  707. sp[0]:=chr(tordconstnode(p).value.svalue);
  708. sp[1]:=#0;
  709. sym:=tconstsym.create_string(orgname,constresourcestring,sp,1);
  710. end
  711. else
  712. Message(parser_e_illegal_expression);
  713. end;
  714. stringconstn:
  715. with Tstringconstnode(p) do
  716. begin
  717. getmem(sp,len+1);
  718. move(value_str^,sp^,len+1);
  719. sym:=tconstsym.create_string(orgname,constresourcestring,sp,len);
  720. end;
  721. else
  722. Message(parser_e_illegal_expression);
  723. end;
  724. current_tokenpos:=storetokenpos;
  725. { Support hint directives }
  726. dummysymoptions:=[];
  727. deprecatedmsg:=nil;
  728. try_consume_hintdirective(dummysymoptions,deprecatedmsg);
  729. if assigned(sym) then
  730. begin
  731. sym.symoptions:=sym.symoptions+dummysymoptions;
  732. sym.deprecatedmsg:=deprecatedmsg;
  733. symtablestack.top.insert(sym);
  734. end
  735. else
  736. stringdispose(deprecatedmsg);
  737. consume(_SEMICOLON);
  738. p.free;
  739. end;
  740. else consume(_EQ);
  741. end;
  742. until token<>_ID;
  743. block_type:=old_block_type;
  744. end;
  745. end.