ptype.pas 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Does parsing types for Free Pascal
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ptype;
  19. interface
  20. uses
  21. globtype,symtable;
  22. const
  23. { forward types should only be possible inside a TYPE statement }
  24. typecanbeforward : boolean = false;
  25. var
  26. { hack, which allows to use the current parsed }
  27. { object type as function argument type }
  28. testcurobject : byte;
  29. curobjectname : stringid;
  30. { parses a string declaration }
  31. function string_dec : pdef;
  32. { parses a object declaration }
  33. function object_dec(const n : stringid;fd : pobjectdef) : pdef;
  34. { reads a string, file type or a type id and returns a name and }
  35. { pdef }
  36. procedure single_type(var tt:ttype;var s : string;isforwarddef:boolean);
  37. procedure read_type(var tt:ttype;const name : stringid);
  38. implementation
  39. uses
  40. cobjects,globals,verbose,systems,tokens,
  41. aasm,symconst,types,
  42. {$ifdef GDB}
  43. gdb,
  44. {$endif}
  45. tree,hcodegen,hcgdata,
  46. scanner,pbase,pexpr,pdecl,psub,
  47. {$ifdef newcg}
  48. cgbase,
  49. {$else}
  50. tccnv,
  51. {$endif}
  52. pass_1;
  53. function string_dec : pdef;
  54. { reads a string type with optional length }
  55. { and returns a pointer to the string }
  56. { definition }
  57. var
  58. p : ptree;
  59. d : pdef;
  60. begin
  61. consume(_STRING);
  62. if token=_LECKKLAMMER then
  63. begin
  64. consume(_LECKKLAMMER);
  65. p:=comp_expr(true);
  66. do_firstpass(p);
  67. if not is_constintnode(p) then
  68. Message(cg_e_illegal_expression);
  69. if (p^.value<=0) then
  70. begin
  71. Message(parser_e_invalid_string_size);
  72. p^.value:=255;
  73. end;
  74. consume(_RECKKLAMMER);
  75. if p^.value>255 then
  76. d:=new(pstringdef,longinit(p^.value))
  77. else
  78. if p^.value<>255 then
  79. d:=new(pstringdef,shortinit(p^.value))
  80. else
  81. d:=cshortstringdef;
  82. disposetree(p);
  83. end
  84. else
  85. begin
  86. if cs_ansistrings in aktlocalswitches then
  87. d:=cansistringdef
  88. else
  89. d:=cshortstringdef;
  90. end;
  91. string_dec:=d;
  92. end;
  93. procedure id_type(var tt : ttype;var s : string;isforwarddef:boolean);
  94. { reads a type definition }
  95. { to a appropriating pdef, s gets the name of }
  96. { the type to allow name mangling }
  97. var
  98. is_unit_specific : boolean;
  99. pos : tfileposinfo;
  100. begin
  101. s:=pattern;
  102. pos:=tokenpos;
  103. { classes can be used also in classes }
  104. if (curobjectname=pattern) and aktobjectdef^.is_class then
  105. begin
  106. tt.setdef(aktobjectdef);
  107. consume(_ID);
  108. exit;
  109. end;
  110. { objects can be parameters }
  111. if (testcurobject=2) and (curobjectname=pattern) then
  112. begin
  113. tt.setdef(aktobjectdef);
  114. consume(_ID);
  115. exit;
  116. end;
  117. { try to load the symbol to see if it's a unitsym }
  118. is_unit_specific:=false;
  119. getsym(s,false);
  120. consume(_ID);
  121. if assigned(srsym) and
  122. (srsym^.typ=unitsym) then
  123. begin
  124. consume(_POINT);
  125. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  126. pos:=tokenpos;
  127. s:=pattern;
  128. consume(_ID);
  129. is_unit_specific:=true;
  130. end;
  131. { are we parsing a possible forward def ? }
  132. if isforwarddef and
  133. not(is_unit_specific) then
  134. begin
  135. tt.setdef(new(pforwarddef,init(s,pos)));
  136. exit;
  137. end;
  138. { unknown sym ? }
  139. if not assigned(srsym) then
  140. begin
  141. Message1(sym_e_id_not_found,s);
  142. tt.setdef(generrordef);
  143. exit;
  144. end;
  145. if (srsym^.typ<>typesym) then
  146. begin
  147. Message(type_e_type_id_expected);
  148. tt.setdef(generrordef);
  149. exit;
  150. end;
  151. { Only use the definitions for system/current unit, becuase
  152. they can be refered from the parameters and symbols are not
  153. loaded at that time. A symbol reference to an other unit
  154. is still possible, because it's already loaded (PFV)
  155. can't use in [] here, becuase unitid can be > 255 }
  156. if (ptypesym(srsym)^.owner^.unitid=0) or
  157. (ptypesym(srsym)^.owner^.unitid=1) then
  158. tt.setdef(ptypesym(srsym)^.restype.def)
  159. else
  160. tt.setsym(srsym);
  161. end;
  162. procedure single_type(var tt:ttype;var s : string;isforwarddef:boolean);
  163. { reads a string, file type or a type id and returns a name and }
  164. { pdef }
  165. var
  166. hs : string;
  167. t2 : ttype;
  168. begin
  169. case token of
  170. _STRING:
  171. begin
  172. tt.setdef(string_dec);
  173. s:='STRING';
  174. end;
  175. _FILE:
  176. begin
  177. consume(_FILE);
  178. if token=_OF then
  179. begin
  180. consume(_OF);
  181. single_type(t2,hs,false);
  182. tt.setdef(new(pfiledef,inittyped(t2)));
  183. s:='FILE$OF$'+hs;
  184. end
  185. else
  186. begin
  187. tt.setdef(cfiledef);
  188. s:='FILE';
  189. end;
  190. end;
  191. else
  192. begin
  193. id_type(tt,s,isforwarddef);
  194. end;
  195. end;
  196. end;
  197. function object_dec(const n : stringid;fd : pobjectdef) : pdef;
  198. { this function parses an object or class declaration }
  199. var
  200. actmembertype : tsymoptions;
  201. there_is_a_destructor : boolean;
  202. is_a_class : boolean;
  203. childof : pobjectdef;
  204. aktclass : pobjectdef;
  205. procedure constructor_head;
  206. begin
  207. consume(_CONSTRUCTOR);
  208. { must be at same level as in implementation }
  209. inc(lexlevel);
  210. parse_proc_head(potype_constructor);
  211. dec(lexlevel);
  212. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'INIT') then
  213. Message(parser_e_constructorname_must_be_init);
  214. {$ifdef INCLUDEOK}
  215. include(aktclass^.objectoptions,oo_has_constructor);
  216. {$else}
  217. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_constructor];
  218. {$endif}
  219. consume(_SEMICOLON);
  220. begin
  221. if (aktclass^.is_class) then
  222. begin
  223. { CLASS constructors return the created instance }
  224. aktprocsym^.definition^.rettype.def:=aktclass;
  225. end
  226. else
  227. begin
  228. { OBJECT constructors return a boolean }
  229. aktprocsym^.definition^.rettype.setdef(booldef);
  230. end;
  231. end;
  232. end;
  233. procedure property_dec;
  234. var
  235. sym : psym;
  236. propertyparas : plinkedlist;
  237. { returns the matching procedure to access a property }
  238. function get_procdef : pprocdef;
  239. var
  240. p : pprocdef;
  241. begin
  242. p:=pprocsym(sym)^.definition;
  243. get_procdef:=nil;
  244. while assigned(p) do
  245. begin
  246. if equal_paras(p^.para,propertyparas,true) then
  247. break;
  248. p:=p^.nextoverloaded;
  249. end;
  250. get_procdef:=p;
  251. end;
  252. var
  253. hp2,datacoll : pparaitem;
  254. p,p2 : ppropertysym;
  255. overriden : psym;
  256. hs : string;
  257. varspez : tvarspez;
  258. sc : pstringcontainer;
  259. s : string;
  260. tt : ttype;
  261. declarepos : tfileposinfo;
  262. pp : pprocdef;
  263. pt : ptree;
  264. propname : stringid;
  265. begin
  266. { check for a class }
  267. if not(aktclass^.is_class) then
  268. Message(parser_e_syntax_error);
  269. consume(_PROPERTY);
  270. new(propertyparas,init);
  271. datacoll:=nil;
  272. if token=_ID then
  273. begin
  274. p:=new(ppropertysym,init(pattern));
  275. propname:=pattern;
  276. consume(_ID);
  277. { property parameters ? }
  278. if token=_LECKKLAMMER then
  279. begin
  280. if (sp_published in current_object_option) then
  281. Message(parser_e_cant_publish_that_property);
  282. { create a list of the parameters in propertyparas }
  283. consume(_LECKKLAMMER);
  284. inc(testcurobject);
  285. repeat
  286. if token=_VAR then
  287. begin
  288. consume(_VAR);
  289. varspez:=vs_var;
  290. end
  291. else if token=_CONST then
  292. begin
  293. consume(_CONST);
  294. varspez:=vs_const;
  295. end
  296. else varspez:=vs_value;
  297. sc:=idlist;
  298. {$ifdef fixLeaksOnError}
  299. strContStack.push(sc);
  300. {$endif fixLeaksOnError}
  301. if token=_COLON then
  302. begin
  303. consume(_COLON);
  304. if token=_ARRAY then
  305. begin
  306. {
  307. if (varspez<>vs_const) and
  308. (varspez<>vs_var) then
  309. begin
  310. varspez:=vs_const;
  311. Message(parser_e_illegal_open_parameter);
  312. end;
  313. }
  314. consume(_ARRAY);
  315. consume(_OF);
  316. { define range and type of range }
  317. tt.setdef(new(parraydef,init(0,-1,s32bitdef)));
  318. { define field type }
  319. single_type(parraydef(tt.def)^.elementtype,s,false);
  320. end
  321. else
  322. single_type(tt,s,false);
  323. end
  324. else
  325. tt.setdef(cformaldef);
  326. repeat
  327. s:=sc^.get_with_tokeninfo(declarepos);
  328. if s='' then
  329. break;
  330. new(hp2,init);
  331. hp2^.paratyp:=varspez;
  332. hp2^.paratype:=tt;
  333. propertyparas^.insert(hp2);
  334. until false;
  335. {$ifdef fixLeaksOnError}
  336. if strContStack.pop <> sc then
  337. writeln('problem with strContStack in ptype');
  338. {$endif fixLeaksOnError}
  339. dispose(sc,done);
  340. until not try_to_consume(_SEMICOLON);
  341. dec(testcurobject);
  342. consume(_RECKKLAMMER);
  343. end;
  344. { overriden property ? }
  345. { force property interface, if there is a property parameter }
  346. if (token=_COLON) or not(propertyparas^.empty) then
  347. begin
  348. consume(_COLON);
  349. single_type(p^.proptype,hs,false);
  350. if (idtoken=_INDEX) then
  351. begin
  352. consume(_INDEX);
  353. pt:=comp_expr(true);
  354. do_firstpass(pt);
  355. if not(is_ordinal(pt^.resulttype)) or
  356. is_64bitint(pt^.resulttype) then
  357. Message(parser_e_invalid_property_index_value);
  358. p^.index:=pt^.value;
  359. p^.indextype.setdef(pt^.resulttype);
  360. include(p^.propoptions,ppo_indexed);
  361. { concat a longint to the para template }
  362. new(hp2,init);
  363. hp2^.paratyp:=vs_value;
  364. hp2^.paratype:=p^.indextype;
  365. propertyparas^.insert(hp2);
  366. disposetree(pt);
  367. end;
  368. { the parser need to know if a property has parameters }
  369. if not(propertyparas^.empty) then
  370. p^.propoptions:=p^.propoptions+[ppo_hasparameters];
  371. end
  372. else
  373. begin
  374. { do an property override }
  375. overriden:=search_class_member(aktclass,propname);
  376. if assigned(overriden) and (overriden^.typ=propertysym) then
  377. begin
  378. p^.dooverride(ppropertysym(overriden));
  379. end
  380. else
  381. begin
  382. p^.proptype.setdef(generrordef);
  383. message(parser_e_no_property_found_to_override);
  384. end;
  385. end;
  386. if (sp_published in current_object_option) and
  387. not(p^.proptype.def^.is_publishable) then
  388. Message(parser_e_cant_publish_that_property);
  389. { create data defcoll to allow correct parameter checks }
  390. new(datacoll,init);
  391. datacoll^.paratyp:=vs_value;
  392. datacoll^.paratype:=p^.proptype;
  393. if (idtoken=_READ) then
  394. begin
  395. p^.readaccess^.clear;
  396. consume(_READ);
  397. sym:=search_class_member(aktclass,pattern);
  398. if not(assigned(sym)) then
  399. begin
  400. Message1(sym_e_unknown_id,pattern);
  401. consume(_ID);
  402. end
  403. else
  404. begin
  405. consume(_ID);
  406. while (token=_POINT) and
  407. ((sym^.typ=varsym) and
  408. (pvarsym(sym)^.vartype.def^.deftype=recorddef)) do
  409. begin
  410. p^.readaccess^.addsym(sym);
  411. consume(_POINT);
  412. getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
  413. if not assigned(srsym) then
  414. Message1(sym_e_illegal_field,pattern);
  415. sym:=srsym;
  416. consume(_ID);
  417. end;
  418. end;
  419. if assigned(sym) then
  420. begin
  421. { search the matching definition }
  422. case sym^.typ of
  423. procsym :
  424. begin
  425. pp:=get_procdef;
  426. if not(assigned(pp)) or
  427. not(is_equal(pp^.rettype.def,p^.proptype.def)) then
  428. Message(parser_e_ill_property_access_sym);
  429. p^.readaccess^.setdef(pp);
  430. end;
  431. varsym :
  432. begin
  433. if not(propertyparas^.empty) or
  434. not(is_equal(pvarsym(sym)^.vartype.def,p^.proptype.def)) then
  435. Message(parser_e_ill_property_access_sym);
  436. end;
  437. else
  438. Message(parser_e_ill_property_access_sym);
  439. end;
  440. p^.readaccess^.addsym(sym);
  441. end;
  442. end;
  443. if (idtoken=_WRITE) then
  444. begin
  445. p^.writeaccess^.clear;
  446. consume(_WRITE);
  447. sym:=search_class_member(aktclass,pattern);
  448. if not(assigned(sym)) then
  449. begin
  450. Message1(sym_e_unknown_id,pattern);
  451. consume(_ID);
  452. end
  453. else
  454. begin
  455. consume(_ID);
  456. while (token=_POINT) and
  457. ((sym^.typ=varsym) and
  458. (pvarsym(sym)^.vartype.def^.deftype=recorddef)) do
  459. begin
  460. p^.writeaccess^.addsym(sym);
  461. consume(_POINT);
  462. getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
  463. if not assigned(srsym) then
  464. Message1(sym_e_illegal_field,pattern);
  465. sym:=srsym;
  466. consume(_ID);
  467. end;
  468. end;
  469. if assigned(sym) then
  470. begin
  471. { search the matching definition }
  472. case sym^.typ of
  473. procsym :
  474. begin
  475. { insert data entry to check access method }
  476. propertyparas^.insert(datacoll);
  477. pp:=get_procdef;
  478. { ... and remove it }
  479. propertyparas^.remove(datacoll);
  480. if not(assigned(pp)) then
  481. Message(parser_e_ill_property_access_sym);
  482. p^.writeaccess^.setdef(pp);
  483. end;
  484. varsym :
  485. begin
  486. if not(propertyparas^.empty) or
  487. not(is_equal(pvarsym(sym)^.vartype.def,p^.proptype.def)) then
  488. Message(parser_e_ill_property_access_sym);
  489. end
  490. else
  491. Message(parser_e_ill_property_access_sym);
  492. end;
  493. p^.writeaccess^.addsym(sym);
  494. end;
  495. end;
  496. include(p^.propoptions,ppo_stored);
  497. if (idtoken=_STORED) then
  498. begin
  499. consume(_STORED);
  500. p^.storedaccess^.clear;
  501. case token of
  502. _ID:
  503. { in the case that idtoken=_DEFAULT }
  504. { we have to do nothing except }
  505. { setting ppo_stored, it's the same }
  506. { as stored true }
  507. if idtoken<>_DEFAULT then
  508. begin
  509. sym:=search_class_member(aktclass,pattern);
  510. if not(assigned(sym)) then
  511. begin
  512. Message1(sym_e_unknown_id,pattern);
  513. consume(_ID);
  514. end
  515. else
  516. begin
  517. consume(_ID);
  518. while (token=_POINT) and
  519. ((sym^.typ=varsym) and
  520. (pvarsym(sym)^.vartype.def^.deftype=recorddef)) do
  521. begin
  522. p^.storedaccess^.addsym(sym);
  523. consume(_POINT);
  524. getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
  525. if not assigned(srsym) then
  526. Message1(sym_e_illegal_field,pattern);
  527. sym:=srsym;
  528. consume(_ID);
  529. end;
  530. end;
  531. if assigned(sym) then
  532. begin
  533. { only non array properties can be stored }
  534. case sym^.typ of
  535. procsym :
  536. begin
  537. pp:=pprocsym(sym)^.definition;
  538. while assigned(pp) do
  539. begin
  540. { the stored function shouldn't have any parameters }
  541. if pp^.para^.empty then
  542. break;
  543. pp:=pp^.nextoverloaded;
  544. end;
  545. { found we a procedure and does it really return a bool? }
  546. if not(assigned(pp)) or
  547. not(is_equal(pp^.rettype.def,booldef)) then
  548. Message(parser_e_ill_property_storage_sym);
  549. p^.storedaccess^.setdef(pp);
  550. end;
  551. varsym :
  552. begin
  553. if not(propertyparas^.empty) or
  554. not(is_equal(pvarsym(sym)^.vartype.def,booldef)) then
  555. Message(parser_e_stored_property_must_be_boolean);
  556. end;
  557. else
  558. Message(parser_e_ill_property_storage_sym);
  559. end;
  560. p^.storedaccess^.addsym(sym);
  561. end;
  562. end;
  563. _FALSE:
  564. begin
  565. consume(_FALSE);
  566. exclude(p^.propoptions,ppo_stored);
  567. end;
  568. _TRUE:
  569. consume(_TRUE);
  570. end;
  571. end;
  572. if (idtoken=_DEFAULT) then
  573. begin
  574. consume(_DEFAULT);
  575. if not(is_ordinal(p^.proptype.def) or
  576. is_64bitint(p^.proptype.def) or
  577. ((p^.proptype.def^.deftype=setdef) and
  578. (psetdef(p^.proptype.def)^.settype=smallset)) or
  579. not(propertyparas^.empty)
  580. ) then
  581. Message(parser_e_property_cant_have_a_default_value);
  582. { Get the result of the default, the firstpass is
  583. needed to support values like -1 }
  584. pt:=comp_expr(true);
  585. do_firstpass(pt);
  586. if p^.proptype.def^.deftype=setdef then
  587. begin
  588. {$ifndef newcg}
  589. {!!!!!!!!!!}
  590. arrayconstructor_to_set(pt);
  591. {$endif newcg}
  592. do_firstpass(pt);
  593. end;
  594. pt:=gentypeconvnode(pt,p^.proptype.def);
  595. do_firstpass(pt);
  596. if not(is_constnode(pt)) then
  597. Message(parser_e_property_default_value_must_const);
  598. if pt^.treetype=setconstn then
  599. p^.default:=plongint(pt^.value_set)^
  600. else
  601. p^.default:=pt^.value;
  602. disposetree(pt);
  603. end
  604. else if (idtoken=_NODEFAULT) then
  605. begin
  606. consume(_NODEFAULT);
  607. p^.default:=0;
  608. end;
  609. symtablestack^.insert(p);
  610. { default property ? }
  611. consume(_SEMICOLON);
  612. if (idtoken=_DEFAULT) then
  613. begin
  614. consume(_DEFAULT);
  615. p2:=search_default_property(aktclass);
  616. if assigned(p2) then
  617. message1(parser_e_only_one_default_property,
  618. pobjectdef(p2^.owner^.defowner)^.objname^)
  619. else
  620. begin
  621. {$ifdef INCLUDEOK}
  622. include(p^.propoptions,ppo_defaultproperty);
  623. {$else}
  624. p^.propoptions:=p^.propoptions+[ppo_defaultproperty];
  625. {$endif}
  626. if propertyparas^.empty then
  627. message(parser_e_property_need_paras);
  628. end;
  629. consume(_SEMICOLON);
  630. end;
  631. { clean up }
  632. if assigned(datacoll) then
  633. dispose(datacoll,done);
  634. end
  635. else
  636. begin
  637. consume(_ID);
  638. consume(_SEMICOLON);
  639. end;
  640. dispose(propertyparas,done);
  641. end;
  642. procedure destructor_head;
  643. begin
  644. consume(_DESTRUCTOR);
  645. inc(lexlevel);
  646. parse_proc_head(potype_destructor);
  647. dec(lexlevel);
  648. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  649. Message(parser_e_destructorname_must_be_done);
  650. {$ifdef INCLUDEOK}
  651. include(aktclass^.objectoptions,oo_has_destructor);
  652. {$else}
  653. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_destructor];
  654. {$endif}
  655. consume(_SEMICOLON);
  656. if not(aktprocsym^.definition^.para^.empty) then
  657. Message(parser_e_no_paras_for_destructor);
  658. { no return value }
  659. aktprocsym^.definition^.rettype.def:=voiddef;
  660. end;
  661. var
  662. hs : string;
  663. pcrd : pclassrefdef;
  664. tt : ttype;
  665. oldprocinfo : pprocinfo;
  666. oldprocsym : pprocsym;
  667. oldparse_only : boolean;
  668. methodnametable,intmessagetable,
  669. strmessagetable,classnamelabel : pasmlabel;
  670. storetypecanbeforward : boolean;
  671. vmtlist : taasmoutput;
  672. {$ifdef WITHDMT}
  673. dmtlabel : pasmlabel;
  674. {$endif WITHDMT}
  675. begin
  676. {Nowadays aktprocsym may already have a value, so we need to save
  677. it.}
  678. oldprocsym:=aktprocsym;
  679. { forward is resolved }
  680. if assigned(fd) then
  681. exclude(fd^.objectoptions,oo_is_forward);
  682. there_is_a_destructor:=false;
  683. actmembertype:=[sp_public];
  684. { objects and class types can't be declared local }
  685. if (symtablestack^.symtabletype<>globalsymtable) and
  686. (symtablestack^.symtabletype<>staticsymtable) then
  687. Message(parser_e_no_local_objects);
  688. storetypecanbeforward:=typecanbeforward;
  689. { for tp mode don't allow forward types }
  690. if m_tp in aktmodeswitches then
  691. typecanbeforward:=false;
  692. { distinguish classes and objects }
  693. if token=_OBJECT then
  694. begin
  695. is_a_class:=false;
  696. consume(_OBJECT)
  697. end
  698. else
  699. begin
  700. is_a_class:=true;
  701. consume(_CLASS);
  702. if not(assigned(fd)) and (token=_OF) then
  703. begin
  704. { a hack, but it's easy to handle }
  705. { class reference type }
  706. consume(_OF);
  707. single_type(tt,hs,typecanbeforward);
  708. { accept hp1, if is a forward def or a class }
  709. if (tt.def^.deftype=forwarddef) or
  710. ((tt.def^.deftype=objectdef) and pobjectdef(tt.def)^.is_class) then
  711. begin
  712. pcrd:=new(pclassrefdef,init(tt.def));
  713. object_dec:=pcrd;
  714. end
  715. else
  716. begin
  717. object_dec:=generrordef;
  718. Message1(type_e_class_type_expected,generrordef^.typename);
  719. end;
  720. typecanbeforward:=storetypecanbeforward;
  721. exit;
  722. end
  723. { forward class }
  724. else if not(assigned(fd)) and (token=_SEMICOLON) then
  725. begin
  726. { also anonym objects aren't allow (o : object a : longint; end;) }
  727. if n='' then
  728. begin
  729. Message(parser_f_no_anonym_objects)
  730. end;
  731. if n='TOBJECT' then
  732. begin
  733. aktclass:=new(pobjectdef,init(n,nil));
  734. class_tobject:=aktclass;
  735. end
  736. else
  737. aktclass:=new(pobjectdef,init(n,nil));
  738. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_is_class,oo_is_forward];
  739. { all classes must have a vmt !! at offset zero }
  740. if not(oo_has_vmt in aktclass^.objectoptions) then
  741. aktclass^.insertvmt;
  742. object_dec:=aktclass;
  743. typecanbeforward:=storetypecanbeforward;
  744. exit;
  745. end;
  746. end;
  747. { also anonym objects aren't allow (o : object a : longint; end;) }
  748. if n='' then
  749. Message(parser_f_no_anonym_objects);
  750. { read the parent class }
  751. if token=_LKLAMMER then
  752. begin
  753. consume(_LKLAMMER);
  754. id_type(tt,pattern,false);
  755. childof:=pobjectdef(tt.def);
  756. if (childof^.deftype<>objectdef) then
  757. begin
  758. Message1(type_e_class_type_expected,childof^.typename);
  759. childof:=nil;
  760. aktclass:=new(pobjectdef,init(n,nil));
  761. end
  762. else
  763. begin
  764. { a mix of class and object isn't allowed }
  765. if (childof^.is_class and not is_a_class) or
  766. (not childof^.is_class and is_a_class) then
  767. Message(parser_e_mix_of_classes_and_objects);
  768. { the forward of the child must be resolved to get
  769. correct field addresses }
  770. if assigned(fd) then
  771. begin
  772. if (oo_is_forward in childof^.objectoptions) then
  773. Message1(parser_e_forward_declaration_must_be_resolved,childof^.objname^);
  774. aktclass:=fd;
  775. { we must inherit several options !!
  776. this was missing !!
  777. all is now done in set_parent
  778. including symtable datasize setting PM }
  779. fd^.set_parent(childof);
  780. end
  781. else
  782. aktclass:=new(pobjectdef,init(n,childof));
  783. end;
  784. consume(_RKLAMMER);
  785. end
  786. { if no parent class, then a class get tobject as parent }
  787. else if is_a_class then
  788. begin
  789. { is the current class tobject? }
  790. { so you could define your own tobject }
  791. if n='TOBJECT' then
  792. begin
  793. if assigned(fd) then
  794. aktclass:=fd
  795. else
  796. aktclass:=new(pobjectdef,init(n,nil));
  797. class_tobject:=aktclass;
  798. end
  799. else
  800. begin
  801. childof:=class_tobject;
  802. if assigned(fd) then
  803. begin
  804. { the forward of the child must be resolved to get
  805. correct field addresses
  806. }
  807. if (oo_is_forward in childof^.objectoptions) then
  808. Message1(parser_e_forward_declaration_must_be_resolved,childof^.objname^);
  809. aktclass:=fd;
  810. aktclass^.set_parent(childof);
  811. end
  812. else
  813. begin
  814. aktclass:=new(pobjectdef,init(n,childof));
  815. aktclass^.set_parent(childof);
  816. end;
  817. end;
  818. end
  819. else
  820. aktclass:=new(pobjectdef,init(n,nil));
  821. { default access is public }
  822. actmembertype:=[sp_public];
  823. { set the class attribute }
  824. if is_a_class then
  825. begin
  826. {$ifdef INCLUDEOK}
  827. include(aktclass^.objectoptions,oo_is_class);
  828. {$else}
  829. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_is_class];
  830. {$endif}
  831. if (cs_generate_rtti in aktlocalswitches) or
  832. (assigned(aktclass^.childof) and
  833. (oo_can_have_published in aktclass^.childof^.objectoptions)) then
  834. begin
  835. include(aktclass^.objectoptions,oo_can_have_published);
  836. { in "publishable" classes the default access type is published }
  837. actmembertype:=[sp_published];
  838. { don't know if this is necessary (FK) }
  839. current_object_option:=[sp_published];
  840. end;
  841. end;
  842. aktobjectdef:=aktclass;
  843. aktclass^.symtable^.next:=symtablestack;
  844. symtablestack:=aktclass^.symtable;
  845. testcurobject:=1;
  846. curobjectname:=n;
  847. { new procinfo }
  848. oldprocinfo:=procinfo;
  849. new(procinfo,init);
  850. procinfo^._class:=aktclass;
  851. { short class declaration ? }
  852. if (not is_a_class) or (token<>_SEMICOLON) then
  853. begin
  854. { Parse componenten }
  855. repeat
  856. if (sp_private in actmembertype) then
  857. {$ifdef INCLUDEOK}
  858. include(aktclass^.objectoptions,oo_has_private);
  859. {$else}
  860. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_private];
  861. {$endif}
  862. if (sp_protected in actmembertype) then
  863. {$ifdef INCLUDEOK}
  864. include(aktclass^.objectoptions,oo_has_protected);
  865. {$else}
  866. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_protected];
  867. {$endif}
  868. case token of
  869. _ID : begin
  870. case idtoken of
  871. _PRIVATE : begin
  872. consume(_PRIVATE);
  873. actmembertype:=[sp_private];
  874. current_object_option:=[sp_private];
  875. end;
  876. _PROTECTED : begin
  877. consume(_PROTECTED);
  878. current_object_option:=[sp_protected];
  879. actmembertype:=[sp_protected];
  880. end;
  881. _PUBLIC : begin
  882. consume(_PUBLIC);
  883. current_object_option:=[sp_public];
  884. actmembertype:=[sp_public];
  885. end;
  886. _PUBLISHED : begin
  887. if not(oo_can_have_published in aktclass^.objectoptions) then
  888. Message(parser_e_cant_have_published);
  889. consume(_PUBLISHED);
  890. current_object_option:=[sp_published];
  891. actmembertype:=[sp_published];
  892. end;
  893. else
  894. read_var_decs(false,true,false);
  895. end;
  896. end;
  897. _PROPERTY : property_dec;
  898. _PROCEDURE,
  899. _FUNCTION,
  900. _CLASS : begin
  901. oldparse_only:=parse_only;
  902. parse_only:=true;
  903. parse_proc_dec;
  904. {$ifndef newcg}
  905. parse_object_proc_directives(aktprocsym);
  906. {$endif newcg}
  907. if (po_msgint in aktprocsym^.definition^.procoptions) then
  908. {$ifdef INCLUDEOK}
  909. include(aktclass^.objectoptions,oo_has_msgint);
  910. {$else}
  911. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_msgint];
  912. {$endif}
  913. if (po_msgstr in aktprocsym^.definition^.procoptions) then
  914. {$ifdef INCLUDEOK}
  915. include(aktclass^.objectoptions,oo_has_msgstr);
  916. {$else}
  917. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_msgstr];
  918. {$endif}
  919. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  920. {$ifdef INCLUDEOK}
  921. include(aktclass^.objectoptions,oo_has_virtual);
  922. {$else}
  923. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  924. {$endif}
  925. parse_only:=oldparse_only;
  926. end;
  927. _CONSTRUCTOR : begin
  928. if not(sp_public in actmembertype) then
  929. Message(parser_w_constructor_should_be_public);
  930. oldparse_only:=parse_only;
  931. parse_only:=true;
  932. constructor_head;
  933. {$ifndef newcg}
  934. parse_object_proc_directives(aktprocsym);
  935. {$endif newcg}
  936. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  937. {$ifdef INCLUDEOK}
  938. include(aktclass^.objectoptions,oo_has_virtual);
  939. {$else}
  940. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  941. {$endif}
  942. parse_only:=oldparse_only;
  943. end;
  944. _DESTRUCTOR : begin
  945. if there_is_a_destructor then
  946. Message(parser_n_only_one_destructor);
  947. there_is_a_destructor:=true;
  948. if not(sp_public in actmembertype) then
  949. Message(parser_w_destructor_should_be_public);
  950. oldparse_only:=parse_only;
  951. parse_only:=true;
  952. destructor_head;
  953. {$ifndef newcg}
  954. parse_object_proc_directives(aktprocsym);
  955. {$endif newcg}
  956. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  957. {$ifdef INCLUDEOK}
  958. include(aktclass^.objectoptions,oo_has_virtual);
  959. {$else}
  960. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  961. {$endif}
  962. parse_only:=oldparse_only;
  963. end;
  964. _END : begin
  965. consume(_END);
  966. break;
  967. end;
  968. else
  969. consume(_ID); { Give a ident expected message, like tp7 }
  970. end;
  971. until false;
  972. current_object_option:=[sp_public];
  973. end;
  974. testcurobject:=0;
  975. curobjectname:='';
  976. typecanbeforward:=storetypecanbeforward;
  977. { generate vmt space if needed }
  978. if not(oo_has_vmt in aktclass^.objectoptions) and
  979. ([oo_has_virtual,oo_has_constructor,oo_has_destructor,oo_is_class]*aktclass^.objectoptions<>[]) then
  980. aktclass^.insertvmt;
  981. if (cs_create_smart in aktmoduleswitches) then
  982. datasegment^.concat(new(pai_cut,init));
  983. { Write the start of the VMT, wich is equal for classes and objects }
  984. if (oo_has_vmt in aktclass^.objectoptions) then
  985. begin
  986. {$ifdef WITHDMT}
  987. dmtlabel:=gendmt(aktclass);
  988. {$endif WITHDMT}
  989. { this generates the entries }
  990. vmtlist.init;
  991. genvmt(@vmtlist,aktclass);
  992. { write tables for classes, this must be done before the actual
  993. class is written, because we need the labels defined }
  994. if is_a_class then
  995. begin
  996. methodnametable:=genpublishedmethodstable(aktclass);
  997. { rtti }
  998. if (oo_can_have_published in aktclass^.objectoptions) then
  999. aktclass^.generate_rtti;
  1000. { write class name }
  1001. getdatalabel(classnamelabel);
  1002. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1003. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.objname^))));
  1004. datasegment^.concat(new(pai_string,init(aktclass^.objname^)));
  1005. { generate message and dynamic tables }
  1006. if (oo_has_msgstr in aktclass^.objectoptions) then
  1007. strmessagetable:=genstrmsgtab(aktclass);
  1008. if (oo_has_msgint in aktclass^.objectoptions) then
  1009. intmessagetable:=genintmsgtab(aktclass)
  1010. else
  1011. datasegment^.concat(new(pai_const,init_32bit(0)));
  1012. end;
  1013. { write debug info }
  1014. {$ifdef GDB}
  1015. if (cs_debuginfo in aktmoduleswitches) then
  1016. begin
  1017. do_count_dbx:=true;
  1018. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1019. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1020. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1021. end;
  1022. {$endif GDB}
  1023. datasegment^.concat(new(pai_symbol,initname_global(aktclass^.vmt_mangledname,0)));
  1024. { determine the size with symtable^.datasize, because }
  1025. { size gives back 4 for classes }
  1026. datasegment^.concat(new(pai_const,init_32bit(aktclass^.symtable^.datasize)));
  1027. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.symtable^.datasize)));
  1028. {$ifdef WITHDMT}
  1029. if not(is_a_class) then
  1030. begin
  1031. if assigned(dmtlabel) then
  1032. datasegment^.concat(new(pai_const_symbol,init(dmtlabel)))
  1033. else
  1034. datasegment^.concat(new(pai_const,init_32bit(0)));
  1035. end;
  1036. {$endif WITHDMT}
  1037. { write pointer to parent VMT, this isn't implemented in TP }
  1038. { but this is not used in FPC ? (PM) }
  1039. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1040. { it is not written for parents that don't have any vmt !! }
  1041. if assigned(aktclass^.childof) and
  1042. (oo_has_vmt in aktclass^.childof^.objectoptions) then
  1043. datasegment^.concat(new(pai_const_symbol,initname(aktclass^.childof^.vmt_mangledname)))
  1044. else
  1045. datasegment^.concat(new(pai_const,init_32bit(0)));
  1046. { write extended info for classes, for the order see rtl/inc/objpash.inc }
  1047. if is_a_class then
  1048. begin
  1049. { pointer to class name string }
  1050. datasegment^.concat(new(pai_const_symbol,init(classnamelabel)));
  1051. { pointer to dynamic table }
  1052. if (oo_has_msgint in aktclass^.objectoptions) then
  1053. datasegment^.concat(new(pai_const_symbol,init(intmessagetable)))
  1054. else
  1055. datasegment^.concat(new(pai_const,init_32bit(0)));
  1056. { pointer to method table }
  1057. if assigned(methodnametable) then
  1058. datasegment^.concat(new(pai_const_symbol,init(methodnametable)))
  1059. else
  1060. datasegment^.concat(new(pai_const,init_32bit(0)));
  1061. { pointer to field table }
  1062. datasegment^.concat(new(pai_const,init_32bit(0)));
  1063. { pointer to type info of published section }
  1064. if (oo_can_have_published in aktclass^.objectoptions) then
  1065. datasegment^.concat(new(pai_const_symbol,initname(aktclass^.rtti_name)))
  1066. else
  1067. datasegment^.concat(new(pai_const,init_32bit(0)));
  1068. { inittable for con-/destruction }
  1069. {
  1070. if aktclass^.needs_inittable then
  1071. }
  1072. { we generate the init table for classes always, because needs_inittable }
  1073. { for classes is always false, it applies only for objects }
  1074. datasegment^.concat(new(pai_const_symbol,init(aktclass^.get_inittable_label)));
  1075. {
  1076. else
  1077. datasegment^.concat(new(pai_const,init_32bit(0)));
  1078. }
  1079. { auto table }
  1080. datasegment^.concat(new(pai_const,init_32bit(0)));
  1081. { interface table }
  1082. datasegment^.concat(new(pai_const,init_32bit(0)));
  1083. { table for string messages }
  1084. if (oo_has_msgstr in aktclass^.objectoptions) then
  1085. datasegment^.concat(new(pai_const_symbol,init(strmessagetable)))
  1086. else
  1087. datasegment^.concat(new(pai_const,init_32bit(0)));
  1088. end;
  1089. datasegment^.concatlist(@vmtlist);
  1090. vmtlist.done;
  1091. { write the size of the VMT }
  1092. datasegment^.concat(new(pai_symbol_end,initname(aktclass^.vmt_mangledname)));
  1093. end;
  1094. { restore old state }
  1095. symtablestack:=symtablestack^.next;
  1096. aktobjectdef:=nil;
  1097. {Restore procinfo}
  1098. dispose(procinfo,done);
  1099. procinfo:=oldprocinfo;
  1100. {Restore the aktprocsym.}
  1101. aktprocsym:=oldprocsym;
  1102. object_dec:=aktclass;
  1103. end;
  1104. { reads a record declaration }
  1105. function record_dec : pdef;
  1106. var
  1107. symtable : psymtable;
  1108. storetypecanbeforward : boolean;
  1109. begin
  1110. { create recdef }
  1111. symtable:=new(psymtable,init(recordsymtable));
  1112. record_dec:=new(precorddef,init(symtable));
  1113. { update symtable stack }
  1114. symtable^.next:=symtablestack;
  1115. symtablestack:=symtable;
  1116. { parse record }
  1117. consume(_RECORD);
  1118. storetypecanbeforward:=typecanbeforward;
  1119. { for tp mode don't allow forward types }
  1120. if m_tp in aktmodeswitches then
  1121. typecanbeforward:=false;
  1122. read_var_decs(true,false,false);
  1123. consume(_END);
  1124. typecanbeforward:=storetypecanbeforward;
  1125. { may be scale record size to a size of n*4 ? }
  1126. symtablestack^.datasize:=align(symtablestack^.datasize,symtablestack^.dataalignment);
  1127. { restore symtable stack }
  1128. symtablestack:=symtable^.next;
  1129. end;
  1130. { reads a type definition and returns a pointer to it }
  1131. procedure read_type(var tt : ttype;const name : stringid);
  1132. var
  1133. pt : ptree;
  1134. tt2 : ttype;
  1135. aufdef : penumdef;
  1136. {aufsym : penumsym;}
  1137. ap : parraydef;
  1138. s : stringid;
  1139. l,v : longint;
  1140. oldaktpackrecords : tpackrecords;
  1141. hs : string;
  1142. defpos,storepos : tfileposinfo;
  1143. procedure expr_type;
  1144. var
  1145. pt1,pt2 : ptree;
  1146. begin
  1147. { use of current parsed object ? }
  1148. if (token=_ID) and (testcurobject=2) and (curobjectname=pattern) then
  1149. begin
  1150. consume(_ID);
  1151. tt.setdef(aktobjectdef);
  1152. exit;
  1153. end;
  1154. { classes can be used also in classes }
  1155. if (curobjectname=pattern) and aktobjectdef^.is_class then
  1156. begin
  1157. tt.setdef(aktobjectdef);
  1158. consume(_ID);
  1159. exit;
  1160. end;
  1161. { we can't accept a equal in type }
  1162. pt1:=comp_expr(not(ignore_equal));
  1163. do_firstpass(pt1);
  1164. if (token=_POINTPOINT) then
  1165. begin
  1166. consume(_POINTPOINT);
  1167. { get high value of range }
  1168. pt2:=comp_expr(not(ignore_equal));
  1169. do_firstpass(pt2);
  1170. { both must be evaluated to constants now }
  1171. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1172. Message(sym_e_error_in_type_def)
  1173. else
  1174. begin
  1175. { check types }
  1176. if CheckTypes(pt1^.resulttype,pt2^.resulttype) then
  1177. begin
  1178. { Check bounds }
  1179. if pt2^.value<pt1^.value then
  1180. Message(cg_e_upper_lower_than_lower)
  1181. else
  1182. begin
  1183. { All checks passed, create the new def }
  1184. case pt1^.resulttype^.deftype of
  1185. enumdef : tt.setdef(new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value)));
  1186. orddef : begin
  1187. if is_char(pt1^.resulttype) then
  1188. tt.setdef(new(porddef,init(uchar,pt1^.value,pt2^.value)))
  1189. else
  1190. if is_boolean(pt1^.resulttype) then
  1191. tt.setdef(new(porddef,init(bool8bit,pt1^.value,pt2^.value)))
  1192. else
  1193. tt.setdef(new(porddef,init(uauto,pt1^.value,pt2^.value)));
  1194. end;
  1195. end;
  1196. end;
  1197. end;
  1198. end;
  1199. disposetree(pt2);
  1200. end
  1201. else
  1202. begin
  1203. { a simple type renaming }
  1204. if (pt1^.treetype=typen) then
  1205. begin
  1206. if assigned(pt1^.typenodesym) then
  1207. tt.setsym(pt1^.typenodesym)
  1208. else
  1209. tt.setdef(pt1^.resulttype);
  1210. end
  1211. else
  1212. Message(sym_e_error_in_type_def);
  1213. end;
  1214. disposetree(pt1);
  1215. end;
  1216. procedure array_dec;
  1217. var
  1218. lowval,
  1219. highval : longint;
  1220. arraytype : pdef;
  1221. begin
  1222. consume(_ARRAY);
  1223. consume(_LECKKLAMMER);
  1224. { defaults }
  1225. arraytype:=generrordef;
  1226. lowval:=$80000000;
  1227. highval:=$7fffffff;
  1228. tt.reset;
  1229. repeat
  1230. { read the expression and check it }
  1231. pt:=expr;
  1232. if pt^.treetype=typen then
  1233. begin
  1234. case pt^.resulttype^.deftype of
  1235. enumdef :
  1236. begin
  1237. lowval:=penumdef(pt^.resulttype)^.min;
  1238. highval:=penumdef(pt^.resulttype)^.max;
  1239. arraytype:=pt^.resulttype;
  1240. end;
  1241. orddef :
  1242. begin
  1243. lowval:=porddef(pt^.resulttype)^.low;
  1244. highval:=porddef(pt^.resulttype)^.high;
  1245. arraytype:=pt^.resulttype;
  1246. end;
  1247. else
  1248. Message(sym_e_error_in_type_def);
  1249. end;
  1250. end
  1251. else
  1252. begin
  1253. do_firstpass(pt);
  1254. if (pt^.treetype=rangen) then
  1255. begin
  1256. if (pt^.left^.treetype=ordconstn) and
  1257. (pt^.right^.treetype=ordconstn) then
  1258. begin
  1259. lowval:=pt^.left^.value;
  1260. highval:=pt^.right^.value;
  1261. if highval<lowval then
  1262. begin
  1263. Message(parser_e_array_lower_less_than_upper_bound);
  1264. highval:=lowval;
  1265. end;
  1266. arraytype:=pt^.right^.resulttype;
  1267. end
  1268. else
  1269. Message(type_e_cant_eval_constant_expr);
  1270. end
  1271. else
  1272. Message(sym_e_error_in_type_def)
  1273. end;
  1274. disposetree(pt);
  1275. { create arraydef }
  1276. if not assigned(tt.def) then
  1277. begin
  1278. ap:=new(parraydef,init(lowval,highval,arraytype));
  1279. tt.setdef(ap);
  1280. end
  1281. else
  1282. begin
  1283. ap^.elementtype.setdef(new(parraydef,init(lowval,highval,arraytype)));
  1284. ap:=parraydef(ap^.elementtype.def);
  1285. end;
  1286. if token=_COMMA then
  1287. consume(_COMMA)
  1288. else
  1289. break;
  1290. until false;
  1291. consume(_RECKKLAMMER);
  1292. consume(_OF);
  1293. read_type(tt2,'');
  1294. { if no error, set element type }
  1295. if assigned(ap) then
  1296. ap^.elementtype:=tt2;
  1297. end;
  1298. begin
  1299. tt.reset;
  1300. case token of
  1301. _STRING,_FILE:
  1302. begin
  1303. single_type(tt,hs,false);
  1304. end;
  1305. _LKLAMMER:
  1306. begin
  1307. consume(_LKLAMMER);
  1308. { allow negativ value_str }
  1309. l:=-1;
  1310. {aufsym := Nil;}
  1311. aufdef:=new(penumdef,init);
  1312. repeat
  1313. s:=pattern;
  1314. defpos:=tokenpos;
  1315. consume(_ID);
  1316. if token=_ASSIGNMENT then
  1317. begin
  1318. consume(_ASSIGNMENT);
  1319. v:=get_intconst;
  1320. { please leave that a note, allows type save }
  1321. { declarations in the win32 units ! }
  1322. if v<=l then
  1323. Message(parser_n_duplicate_enum);
  1324. l:=v;
  1325. end
  1326. else
  1327. inc(l);
  1328. storepos:=tokenpos;
  1329. tokenpos:=defpos;
  1330. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1331. tokenpos:=storepos;
  1332. if token=_COMMA then
  1333. consume(_COMMA)
  1334. else
  1335. break;
  1336. until false;
  1337. {aufdef^.max:=l;
  1338. if we allow unordered enums
  1339. this can be wrong
  1340. min and max are now set in tenumsym.init PM }
  1341. tt.setdef(aufdef);
  1342. consume(_RKLAMMER);
  1343. end;
  1344. _ARRAY:
  1345. begin
  1346. array_dec;
  1347. end;
  1348. _SET:
  1349. begin
  1350. consume(_SET);
  1351. consume(_OF);
  1352. read_type(tt2,'');
  1353. if assigned(tt2.def) then
  1354. begin
  1355. case tt2.def^.deftype of
  1356. { don't forget that min can be negativ PM }
  1357. enumdef :
  1358. if penumdef(tt2.def)^.min>=0 then
  1359. tt.setdef(new(psetdef,init(tt2.def,penumdef(tt2.def)^.max)))
  1360. else
  1361. Message(sym_e_ill_type_decl_set);
  1362. orddef :
  1363. begin
  1364. case porddef(tt2.def)^.typ of
  1365. uchar :
  1366. tt.setdef(new(psetdef,init(tt2.def,255)));
  1367. u8bit,u16bit,u32bit,
  1368. s8bit,s16bit,s32bit :
  1369. begin
  1370. if (porddef(tt2.def)^.low>=0) then
  1371. tt.setdef(new(psetdef,init(tt2.def,porddef(tt2.def)^.high)))
  1372. else
  1373. Message(sym_e_ill_type_decl_set);
  1374. end;
  1375. else
  1376. Message(sym_e_ill_type_decl_set);
  1377. end;
  1378. end;
  1379. else
  1380. Message(sym_e_ill_type_decl_set);
  1381. end;
  1382. end
  1383. else
  1384. tt.setdef(generrordef);
  1385. end;
  1386. _CARET:
  1387. begin
  1388. consume(_CARET);
  1389. single_type(tt2,hs,typecanbeforward);
  1390. tt.setdef(new(ppointerdef,init(tt2)));
  1391. end;
  1392. _RECORD:
  1393. begin
  1394. tt.setdef(record_dec);
  1395. end;
  1396. _PACKED:
  1397. begin
  1398. consume(_PACKED);
  1399. if token=_ARRAY then
  1400. array_dec
  1401. else
  1402. begin
  1403. oldaktpackrecords:=aktpackrecords;
  1404. aktpackrecords:=packrecord_1;
  1405. if token in [_CLASS,_OBJECT] then
  1406. tt.setdef(object_dec(name,nil))
  1407. else
  1408. tt.setdef(record_dec);
  1409. aktpackrecords:=oldaktpackrecords;
  1410. end;
  1411. end;
  1412. _CLASS,
  1413. _OBJECT:
  1414. begin
  1415. tt.setdef(object_dec(name,nil));
  1416. end;
  1417. _PROCEDURE:
  1418. begin
  1419. consume(_PROCEDURE);
  1420. tt.setdef(new(pprocvardef,init));
  1421. if token=_LKLAMMER then
  1422. parameter_dec(pprocvardef(tt.def));
  1423. if token=_OF then
  1424. begin
  1425. consume(_OF);
  1426. consume(_OBJECT);
  1427. {$ifdef INCLUDEOK}
  1428. include(pprocvardef(tt.def)^.procoptions,po_methodpointer);
  1429. {$else}
  1430. pprocvardef(tt.def)^.procoptions:=pprocvardef(tt.def)^.procoptions+[po_methodpointer];
  1431. {$endif}
  1432. end;
  1433. end;
  1434. _FUNCTION:
  1435. begin
  1436. consume(_FUNCTION);
  1437. tt.def:=new(pprocvardef,init);
  1438. if token=_LKLAMMER then
  1439. parameter_dec(pprocvardef(tt.def));
  1440. consume(_COLON);
  1441. single_type(pprocvardef(tt.def)^.rettype,hs,false);
  1442. if token=_OF then
  1443. begin
  1444. consume(_OF);
  1445. consume(_OBJECT);
  1446. {$ifdef INCLUDEOK}
  1447. include(pprocvardef(tt.def)^.procoptions,po_methodpointer);
  1448. {$else}
  1449. pprocvardef(tt.def)^.procoptions:=pprocvardef(tt.def)^.procoptions+[po_methodpointer];
  1450. {$endif}
  1451. end;
  1452. end;
  1453. else
  1454. expr_type;
  1455. end;
  1456. if tt.def=nil then
  1457. tt.setdef(generrordef);
  1458. end;
  1459. end.
  1460. {
  1461. $Log$
  1462. Revision 1.18 2000-02-09 13:23:01 peter
  1463. * log truncated
  1464. Revision 1.17 2000/02/05 14:33:32 florian
  1465. * fixed init table generation for classes and arrays
  1466. Revision 1.16 2000/01/28 23:17:53 florian
  1467. * virtual XXXX; support for objects, only if -dWITHDMT is defined
  1468. Revision 1.15 2000/01/27 16:31:40 florian
  1469. * bug 738 fixed
  1470. Revision 1.14 2000/01/11 17:16:06 jonas
  1471. * removed a lot of memory leaks when an error is encountered (caused by
  1472. procinfo and pstringcontainers). There are still plenty left though :)
  1473. Revision 1.13 2000/01/07 01:14:34 peter
  1474. * updated copyright to 2000
  1475. Revision 1.12 1999/11/30 10:40:52 peter
  1476. + ttype, tsymlist
  1477. Revision 1.11 1999/11/26 00:19:12 peter
  1478. * property overriding dereference fix, but it need a bigger redesign
  1479. which i'll do tomorrow. This quick hack is for the lazarus ppl so
  1480. they can hack on mwcustomedit.
  1481. Revision 1.10 1999/11/17 17:05:03 pierre
  1482. * Notes/hints changes
  1483. Revision 1.9 1999/11/11 00:56:54 pierre
  1484. * Enum element reference location corrected
  1485. Revision 1.8 1999/11/09 23:43:09 pierre
  1486. * better browser info
  1487. Revision 1.7 1999/11/08 14:02:16 florian
  1488. * problem with "index X"-properties solved
  1489. * typed constants of class references are now allowed
  1490. Revision 1.6 1999/11/07 23:16:49 florian
  1491. * finally bug 517 solved ...
  1492. Revision 1.5 1999/10/27 16:04:06 peter
  1493. * fixed property reading
  1494. Revision 1.4 1999/10/27 14:17:08 florian
  1495. * property overriding fixed
  1496. Revision 1.3 1999/10/26 12:30:45 peter
  1497. * const parameter is now checked
  1498. * better and generic check if a node can be used for assigning
  1499. * export fixes
  1500. * procvar equal works now (it never had worked at least from 0.99.8)
  1501. * defcoll changed to linkedlist with pparaitem so it can easily be
  1502. walked both directions
  1503. Revision 1.2 1999/10/22 14:37:30 peter
  1504. * error when properties are passed to var parameters
  1505. Revision 1.1 1999/10/22 10:39:35 peter
  1506. * split type reading from pdecl to ptype unit
  1507. * parameter_dec routine is now used for procedure and procvars
  1508. }