ptype.pas 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  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 : 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. { overriding a default propertyp is allowed
  616. p2:=search_default_property(aktclass);
  617. if assigned(p2) then
  618. message1(parser_e_only_one_default_property,
  619. pobjectdef(p2^.owner^.defowner)^.objname^)
  620. else
  621. }
  622. begin
  623. include(p^.propoptions,ppo_defaultproperty);
  624. if propertyparas^.empty then
  625. message(parser_e_property_need_paras);
  626. end;
  627. consume(_SEMICOLON);
  628. end;
  629. { clean up }
  630. if assigned(datacoll) then
  631. dispose(datacoll,done);
  632. end
  633. else
  634. begin
  635. consume(_ID);
  636. consume(_SEMICOLON);
  637. end;
  638. dispose(propertyparas,done);
  639. end;
  640. procedure destructor_head;
  641. begin
  642. consume(_DESTRUCTOR);
  643. inc(lexlevel);
  644. parse_proc_head(potype_destructor);
  645. dec(lexlevel);
  646. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  647. Message(parser_e_destructorname_must_be_done);
  648. {$ifdef INCLUDEOK}
  649. include(aktclass^.objectoptions,oo_has_destructor);
  650. {$else}
  651. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_destructor];
  652. {$endif}
  653. consume(_SEMICOLON);
  654. if not(aktprocsym^.definition^.para^.empty) then
  655. Message(parser_e_no_paras_for_destructor);
  656. { no return value }
  657. aktprocsym^.definition^.rettype.def:=voiddef;
  658. end;
  659. var
  660. hs : string;
  661. pcrd : pclassrefdef;
  662. tt : ttype;
  663. oldprocinfo : pprocinfo;
  664. oldprocsym : pprocsym;
  665. oldparse_only : boolean;
  666. methodnametable,intmessagetable,
  667. strmessagetable,classnamelabel : pasmlabel;
  668. storetypecanbeforward : boolean;
  669. vmtlist : taasmoutput;
  670. {$ifdef WITHDMT}
  671. dmtlabel : pasmlabel;
  672. {$endif WITHDMT}
  673. begin
  674. {Nowadays aktprocsym may already have a value, so we need to save
  675. it.}
  676. oldprocsym:=aktprocsym;
  677. { forward is resolved }
  678. if assigned(fd) then
  679. exclude(fd^.objectoptions,oo_is_forward);
  680. there_is_a_destructor:=false;
  681. actmembertype:=[sp_public];
  682. { objects and class types can't be declared local }
  683. if (symtablestack^.symtabletype<>globalsymtable) and
  684. (symtablestack^.symtabletype<>staticsymtable) then
  685. Message(parser_e_no_local_objects);
  686. storetypecanbeforward:=typecanbeforward;
  687. { for tp mode don't allow forward types }
  688. if m_tp in aktmodeswitches then
  689. typecanbeforward:=false;
  690. { distinguish classes and objects }
  691. if token=_OBJECT then
  692. begin
  693. is_a_class:=false;
  694. consume(_OBJECT)
  695. end
  696. else
  697. begin
  698. is_a_class:=true;
  699. consume(_CLASS);
  700. if not(assigned(fd)) and (token=_OF) then
  701. begin
  702. { a hack, but it's easy to handle }
  703. { class reference type }
  704. consume(_OF);
  705. single_type(tt,hs,typecanbeforward);
  706. { accept hp1, if is a forward def or a class }
  707. if (tt.def^.deftype=forwarddef) or
  708. ((tt.def^.deftype=objectdef) and pobjectdef(tt.def)^.is_class) then
  709. begin
  710. pcrd:=new(pclassrefdef,init(tt.def));
  711. object_dec:=pcrd;
  712. end
  713. else
  714. begin
  715. object_dec:=generrordef;
  716. Message1(type_e_class_type_expected,generrordef^.typename);
  717. end;
  718. typecanbeforward:=storetypecanbeforward;
  719. exit;
  720. end
  721. { forward class }
  722. else if not(assigned(fd)) and (token=_SEMICOLON) then
  723. begin
  724. { also anonym objects aren't allow (o : object a : longint; end;) }
  725. if n='' then
  726. begin
  727. Message(parser_f_no_anonym_objects)
  728. end;
  729. if n='TOBJECT' then
  730. begin
  731. aktclass:=new(pobjectdef,init(n,nil));
  732. class_tobject:=aktclass;
  733. end
  734. else
  735. aktclass:=new(pobjectdef,init(n,nil));
  736. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_is_class,oo_is_forward];
  737. { all classes must have a vmt !! at offset zero }
  738. if not(oo_has_vmt in aktclass^.objectoptions) then
  739. aktclass^.insertvmt;
  740. object_dec:=aktclass;
  741. typecanbeforward:=storetypecanbeforward;
  742. exit;
  743. end;
  744. end;
  745. { also anonym objects aren't allow (o : object a : longint; end;) }
  746. if n='' then
  747. Message(parser_f_no_anonym_objects);
  748. { read the parent class }
  749. if token=_LKLAMMER then
  750. begin
  751. consume(_LKLAMMER);
  752. id_type(tt,pattern,false);
  753. childof:=pobjectdef(tt.def);
  754. if (childof^.deftype<>objectdef) then
  755. begin
  756. Message1(type_e_class_type_expected,childof^.typename);
  757. childof:=nil;
  758. aktclass:=new(pobjectdef,init(n,nil));
  759. end
  760. else
  761. begin
  762. { a mix of class and object isn't allowed }
  763. if (childof^.is_class and not is_a_class) or
  764. (not childof^.is_class and is_a_class) then
  765. Message(parser_e_mix_of_classes_and_objects);
  766. { the forward of the child must be resolved to get
  767. correct field addresses }
  768. if assigned(fd) then
  769. begin
  770. if (oo_is_forward in childof^.objectoptions) then
  771. Message1(parser_e_forward_declaration_must_be_resolved,childof^.objname^);
  772. aktclass:=fd;
  773. { we must inherit several options !!
  774. this was missing !!
  775. all is now done in set_parent
  776. including symtable datasize setting PM }
  777. fd^.set_parent(childof);
  778. end
  779. else
  780. aktclass:=new(pobjectdef,init(n,childof));
  781. end;
  782. consume(_RKLAMMER);
  783. end
  784. { if no parent class, then a class get tobject as parent }
  785. else if is_a_class then
  786. begin
  787. { is the current class tobject? }
  788. { so you could define your own tobject }
  789. if n='TOBJECT' then
  790. begin
  791. if assigned(fd) then
  792. aktclass:=fd
  793. else
  794. aktclass:=new(pobjectdef,init(n,nil));
  795. class_tobject:=aktclass;
  796. end
  797. else
  798. begin
  799. childof:=class_tobject;
  800. if assigned(fd) then
  801. begin
  802. { the forward of the child must be resolved to get
  803. correct field addresses
  804. }
  805. if (oo_is_forward in childof^.objectoptions) then
  806. Message1(parser_e_forward_declaration_must_be_resolved,childof^.objname^);
  807. aktclass:=fd;
  808. aktclass^.set_parent(childof);
  809. end
  810. else
  811. begin
  812. aktclass:=new(pobjectdef,init(n,childof));
  813. aktclass^.set_parent(childof);
  814. end;
  815. end;
  816. end
  817. else
  818. aktclass:=new(pobjectdef,init(n,nil));
  819. { default access is public }
  820. actmembertype:=[sp_public];
  821. { set the class attribute }
  822. if is_a_class then
  823. begin
  824. {$ifdef INCLUDEOK}
  825. include(aktclass^.objectoptions,oo_is_class);
  826. {$else}
  827. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_is_class];
  828. {$endif}
  829. if (cs_generate_rtti in aktlocalswitches) or
  830. (assigned(aktclass^.childof) and
  831. (oo_can_have_published in aktclass^.childof^.objectoptions)) then
  832. begin
  833. include(aktclass^.objectoptions,oo_can_have_published);
  834. { in "publishable" classes the default access type is published }
  835. actmembertype:=[sp_published];
  836. { don't know if this is necessary (FK) }
  837. current_object_option:=[sp_published];
  838. end;
  839. end;
  840. aktobjectdef:=aktclass;
  841. aktclass^.symtable^.next:=symtablestack;
  842. symtablestack:=aktclass^.symtable;
  843. testcurobject:=1;
  844. curobjectname:=n;
  845. { new procinfo }
  846. oldprocinfo:=procinfo;
  847. new(procinfo,init);
  848. procinfo^._class:=aktclass;
  849. { short class declaration ? }
  850. if (not is_a_class) or (token<>_SEMICOLON) then
  851. begin
  852. { Parse componenten }
  853. repeat
  854. if (sp_private in actmembertype) then
  855. {$ifdef INCLUDEOK}
  856. include(aktclass^.objectoptions,oo_has_private);
  857. {$else}
  858. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_private];
  859. {$endif}
  860. if (sp_protected in actmembertype) then
  861. {$ifdef INCLUDEOK}
  862. include(aktclass^.objectoptions,oo_has_protected);
  863. {$else}
  864. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_protected];
  865. {$endif}
  866. case token of
  867. _ID : begin
  868. case idtoken of
  869. _PRIVATE : begin
  870. consume(_PRIVATE);
  871. actmembertype:=[sp_private];
  872. current_object_option:=[sp_private];
  873. end;
  874. _PROTECTED : begin
  875. consume(_PROTECTED);
  876. current_object_option:=[sp_protected];
  877. actmembertype:=[sp_protected];
  878. end;
  879. _PUBLIC : begin
  880. consume(_PUBLIC);
  881. current_object_option:=[sp_public];
  882. actmembertype:=[sp_public];
  883. end;
  884. _PUBLISHED : begin
  885. if not(oo_can_have_published in aktclass^.objectoptions) then
  886. Message(parser_e_cant_have_published);
  887. consume(_PUBLISHED);
  888. current_object_option:=[sp_published];
  889. actmembertype:=[sp_published];
  890. end;
  891. else
  892. read_var_decs(false,true,false);
  893. end;
  894. end;
  895. _PROPERTY : property_dec;
  896. _PROCEDURE,
  897. _FUNCTION,
  898. _CLASS : begin
  899. oldparse_only:=parse_only;
  900. parse_only:=true;
  901. parse_proc_dec;
  902. {$ifndef newcg}
  903. parse_object_proc_directives(aktprocsym);
  904. {$endif newcg}
  905. if (po_msgint in aktprocsym^.definition^.procoptions) then
  906. {$ifdef INCLUDEOK}
  907. include(aktclass^.objectoptions,oo_has_msgint);
  908. {$else}
  909. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_msgint];
  910. {$endif}
  911. if (po_msgstr in aktprocsym^.definition^.procoptions) then
  912. {$ifdef INCLUDEOK}
  913. include(aktclass^.objectoptions,oo_has_msgstr);
  914. {$else}
  915. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_msgstr];
  916. {$endif}
  917. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  918. {$ifdef INCLUDEOK}
  919. include(aktclass^.objectoptions,oo_has_virtual);
  920. {$else}
  921. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  922. {$endif}
  923. parse_only:=oldparse_only;
  924. end;
  925. _CONSTRUCTOR : begin
  926. if not(sp_public in actmembertype) then
  927. Message(parser_w_constructor_should_be_public);
  928. oldparse_only:=parse_only;
  929. parse_only:=true;
  930. constructor_head;
  931. {$ifndef newcg}
  932. parse_object_proc_directives(aktprocsym);
  933. {$endif newcg}
  934. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  935. {$ifdef INCLUDEOK}
  936. include(aktclass^.objectoptions,oo_has_virtual);
  937. {$else}
  938. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  939. {$endif}
  940. parse_only:=oldparse_only;
  941. end;
  942. _DESTRUCTOR : begin
  943. if there_is_a_destructor then
  944. Message(parser_n_only_one_destructor);
  945. there_is_a_destructor:=true;
  946. if not(sp_public in actmembertype) then
  947. Message(parser_w_destructor_should_be_public);
  948. oldparse_only:=parse_only;
  949. parse_only:=true;
  950. destructor_head;
  951. {$ifndef newcg}
  952. parse_object_proc_directives(aktprocsym);
  953. {$endif newcg}
  954. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  955. {$ifdef INCLUDEOK}
  956. include(aktclass^.objectoptions,oo_has_virtual);
  957. {$else}
  958. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  959. {$endif}
  960. parse_only:=oldparse_only;
  961. end;
  962. _END : begin
  963. consume(_END);
  964. break;
  965. end;
  966. else
  967. consume(_ID); { Give a ident expected message, like tp7 }
  968. end;
  969. until false;
  970. current_object_option:=[sp_public];
  971. end;
  972. testcurobject:=0;
  973. curobjectname:='';
  974. typecanbeforward:=storetypecanbeforward;
  975. { generate vmt space if needed }
  976. if not(oo_has_vmt in aktclass^.objectoptions) and
  977. ([oo_has_virtual,oo_has_constructor,oo_has_destructor,oo_is_class]*aktclass^.objectoptions<>[]) then
  978. aktclass^.insertvmt;
  979. if (cs_create_smart in aktmoduleswitches) then
  980. datasegment^.concat(new(pai_cut,init));
  981. { Write the start of the VMT, wich is equal for classes and objects }
  982. if (oo_has_vmt in aktclass^.objectoptions) then
  983. begin
  984. {$ifdef WITHDMT}
  985. dmtlabel:=gendmt(aktclass);
  986. {$endif WITHDMT}
  987. { this generates the entries }
  988. vmtlist.init;
  989. genvmt(@vmtlist,aktclass);
  990. { write tables for classes, this must be done before the actual
  991. class is written, because we need the labels defined }
  992. if is_a_class then
  993. begin
  994. methodnametable:=genpublishedmethodstable(aktclass);
  995. { rtti }
  996. if (oo_can_have_published in aktclass^.objectoptions) then
  997. aktclass^.generate_rtti;
  998. { write class name }
  999. getdatalabel(classnamelabel);
  1000. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1001. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.objname^))));
  1002. datasegment^.concat(new(pai_string,init(aktclass^.objname^)));
  1003. { generate message and dynamic tables }
  1004. if (oo_has_msgstr in aktclass^.objectoptions) then
  1005. strmessagetable:=genstrmsgtab(aktclass);
  1006. if (oo_has_msgint in aktclass^.objectoptions) then
  1007. intmessagetable:=genintmsgtab(aktclass)
  1008. else
  1009. datasegment^.concat(new(pai_const,init_32bit(0)));
  1010. end;
  1011. { write debug info }
  1012. {$ifdef GDB}
  1013. if (cs_debuginfo in aktmoduleswitches) then
  1014. begin
  1015. do_count_dbx:=true;
  1016. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1017. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1018. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1019. end;
  1020. {$endif GDB}
  1021. datasegment^.concat(new(pai_symbol,initname_global(aktclass^.vmt_mangledname,0)));
  1022. { determine the size with symtable^.datasize, because }
  1023. { size gives back 4 for classes }
  1024. datasegment^.concat(new(pai_const,init_32bit(aktclass^.symtable^.datasize)));
  1025. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.symtable^.datasize)));
  1026. {$ifdef WITHDMT}
  1027. if not(is_a_class) then
  1028. begin
  1029. if assigned(dmtlabel) then
  1030. datasegment^.concat(new(pai_const_symbol,init(dmtlabel)))
  1031. else
  1032. datasegment^.concat(new(pai_const,init_32bit(0)));
  1033. end;
  1034. {$endif WITHDMT}
  1035. { write pointer to parent VMT, this isn't implemented in TP }
  1036. { but this is not used in FPC ? (PM) }
  1037. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1038. { it is not written for parents that don't have any vmt !! }
  1039. if assigned(aktclass^.childof) and
  1040. (oo_has_vmt in aktclass^.childof^.objectoptions) then
  1041. datasegment^.concat(new(pai_const_symbol,initname(aktclass^.childof^.vmt_mangledname)))
  1042. else
  1043. datasegment^.concat(new(pai_const,init_32bit(0)));
  1044. { write extended info for classes, for the order see rtl/inc/objpash.inc }
  1045. if is_a_class then
  1046. begin
  1047. { pointer to class name string }
  1048. datasegment^.concat(new(pai_const_symbol,init(classnamelabel)));
  1049. { pointer to dynamic table }
  1050. if (oo_has_msgint in aktclass^.objectoptions) then
  1051. datasegment^.concat(new(pai_const_symbol,init(intmessagetable)))
  1052. else
  1053. datasegment^.concat(new(pai_const,init_32bit(0)));
  1054. { pointer to method table }
  1055. if assigned(methodnametable) then
  1056. datasegment^.concat(new(pai_const_symbol,init(methodnametable)))
  1057. else
  1058. datasegment^.concat(new(pai_const,init_32bit(0)));
  1059. { pointer to field table }
  1060. datasegment^.concat(new(pai_const,init_32bit(0)));
  1061. { pointer to type info of published section }
  1062. if (oo_can_have_published in aktclass^.objectoptions) then
  1063. datasegment^.concat(new(pai_const_symbol,initname(aktclass^.rtti_name)))
  1064. else
  1065. datasegment^.concat(new(pai_const,init_32bit(0)));
  1066. { inittable for con-/destruction }
  1067. {
  1068. if aktclass^.needs_inittable then
  1069. }
  1070. { we generate the init table for classes always, because needs_inittable }
  1071. { for classes is always false, it applies only for objects }
  1072. datasegment^.concat(new(pai_const_symbol,init(aktclass^.get_inittable_label)));
  1073. {
  1074. else
  1075. datasegment^.concat(new(pai_const,init_32bit(0)));
  1076. }
  1077. { auto table }
  1078. datasegment^.concat(new(pai_const,init_32bit(0)));
  1079. { interface table }
  1080. datasegment^.concat(new(pai_const,init_32bit(0)));
  1081. { table for string messages }
  1082. if (oo_has_msgstr in aktclass^.objectoptions) then
  1083. datasegment^.concat(new(pai_const_symbol,init(strmessagetable)))
  1084. else
  1085. datasegment^.concat(new(pai_const,init_32bit(0)));
  1086. end;
  1087. datasegment^.concatlist(@vmtlist);
  1088. vmtlist.done;
  1089. { write the size of the VMT }
  1090. datasegment^.concat(new(pai_symbol_end,initname(aktclass^.vmt_mangledname)));
  1091. end;
  1092. { restore old state }
  1093. symtablestack:=symtablestack^.next;
  1094. aktobjectdef:=nil;
  1095. {Restore procinfo}
  1096. dispose(procinfo,done);
  1097. procinfo:=oldprocinfo;
  1098. {Restore the aktprocsym.}
  1099. aktprocsym:=oldprocsym;
  1100. object_dec:=aktclass;
  1101. end;
  1102. { reads a record declaration }
  1103. function record_dec : pdef;
  1104. var
  1105. symtable : psymtable;
  1106. storetypecanbeforward : boolean;
  1107. begin
  1108. { create recdef }
  1109. symtable:=new(psymtable,init(recordsymtable));
  1110. record_dec:=new(precorddef,init(symtable));
  1111. { update symtable stack }
  1112. symtable^.next:=symtablestack;
  1113. symtablestack:=symtable;
  1114. { parse record }
  1115. consume(_RECORD);
  1116. storetypecanbeforward:=typecanbeforward;
  1117. { for tp mode don't allow forward types }
  1118. if m_tp in aktmodeswitches then
  1119. typecanbeforward:=false;
  1120. read_var_decs(true,false,false);
  1121. consume(_END);
  1122. typecanbeforward:=storetypecanbeforward;
  1123. { may be scale record size to a size of n*4 ? }
  1124. symtablestack^.datasize:=align(symtablestack^.datasize,symtablestack^.dataalignment);
  1125. { restore symtable stack }
  1126. symtablestack:=symtable^.next;
  1127. end;
  1128. { reads a type definition and returns a pointer to it }
  1129. procedure read_type(var tt : ttype;const name : stringid);
  1130. var
  1131. pt : ptree;
  1132. tt2 : ttype;
  1133. aufdef : penumdef;
  1134. {aufsym : penumsym;}
  1135. ap : parraydef;
  1136. s : stringid;
  1137. l,v : longint;
  1138. oldaktpackrecords : tpackrecords;
  1139. hs : string;
  1140. defpos,storepos : tfileposinfo;
  1141. procedure expr_type;
  1142. var
  1143. pt1,pt2 : ptree;
  1144. begin
  1145. { use of current parsed object ? }
  1146. if (token=_ID) and (testcurobject=2) and (curobjectname=pattern) then
  1147. begin
  1148. consume(_ID);
  1149. tt.setdef(aktobjectdef);
  1150. exit;
  1151. end;
  1152. { classes can be used also in classes }
  1153. if (curobjectname=pattern) and aktobjectdef^.is_class then
  1154. begin
  1155. tt.setdef(aktobjectdef);
  1156. consume(_ID);
  1157. exit;
  1158. end;
  1159. { we can't accept a equal in type }
  1160. pt1:=comp_expr(not(ignore_equal));
  1161. do_firstpass(pt1);
  1162. if (token=_POINTPOINT) then
  1163. begin
  1164. consume(_POINTPOINT);
  1165. { get high value of range }
  1166. pt2:=comp_expr(not(ignore_equal));
  1167. do_firstpass(pt2);
  1168. { both must be evaluated to constants now }
  1169. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1170. Message(sym_e_error_in_type_def)
  1171. else
  1172. begin
  1173. { check types }
  1174. if CheckTypes(pt1^.resulttype,pt2^.resulttype) then
  1175. begin
  1176. { Check bounds }
  1177. if pt2^.value<pt1^.value then
  1178. Message(cg_e_upper_lower_than_lower)
  1179. else
  1180. begin
  1181. { All checks passed, create the new def }
  1182. case pt1^.resulttype^.deftype of
  1183. enumdef : tt.setdef(new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value)));
  1184. orddef : begin
  1185. if is_char(pt1^.resulttype) then
  1186. tt.setdef(new(porddef,init(uchar,pt1^.value,pt2^.value)))
  1187. else
  1188. if is_boolean(pt1^.resulttype) then
  1189. tt.setdef(new(porddef,init(bool8bit,pt1^.value,pt2^.value)))
  1190. else
  1191. tt.setdef(new(porddef,init(uauto,pt1^.value,pt2^.value)));
  1192. end;
  1193. end;
  1194. end;
  1195. end;
  1196. end;
  1197. disposetree(pt2);
  1198. end
  1199. else
  1200. begin
  1201. { a simple type renaming }
  1202. if (pt1^.treetype=typen) then
  1203. begin
  1204. if assigned(pt1^.typenodesym) then
  1205. tt.setsym(pt1^.typenodesym)
  1206. else
  1207. tt.setdef(pt1^.resulttype);
  1208. end
  1209. else
  1210. Message(sym_e_error_in_type_def);
  1211. end;
  1212. disposetree(pt1);
  1213. end;
  1214. procedure array_dec;
  1215. var
  1216. lowval,
  1217. highval : longint;
  1218. arraytype : pdef;
  1219. begin
  1220. consume(_ARRAY);
  1221. consume(_LECKKLAMMER);
  1222. { defaults }
  1223. arraytype:=generrordef;
  1224. lowval:=$80000000;
  1225. highval:=$7fffffff;
  1226. tt.reset;
  1227. repeat
  1228. { read the expression and check it }
  1229. pt:=expr;
  1230. if pt^.treetype=typen then
  1231. begin
  1232. case pt^.resulttype^.deftype of
  1233. enumdef :
  1234. begin
  1235. lowval:=penumdef(pt^.resulttype)^.min;
  1236. highval:=penumdef(pt^.resulttype)^.max;
  1237. arraytype:=pt^.resulttype;
  1238. end;
  1239. orddef :
  1240. begin
  1241. lowval:=porddef(pt^.resulttype)^.low;
  1242. highval:=porddef(pt^.resulttype)^.high;
  1243. arraytype:=pt^.resulttype;
  1244. end;
  1245. else
  1246. Message(sym_e_error_in_type_def);
  1247. end;
  1248. end
  1249. else
  1250. begin
  1251. do_firstpass(pt);
  1252. if (pt^.treetype=rangen) then
  1253. begin
  1254. if (pt^.left^.treetype=ordconstn) and
  1255. (pt^.right^.treetype=ordconstn) then
  1256. begin
  1257. lowval:=pt^.left^.value;
  1258. highval:=pt^.right^.value;
  1259. if highval<lowval then
  1260. begin
  1261. Message(parser_e_array_lower_less_than_upper_bound);
  1262. highval:=lowval;
  1263. end;
  1264. arraytype:=pt^.right^.resulttype;
  1265. end
  1266. else
  1267. Message(type_e_cant_eval_constant_expr);
  1268. end
  1269. else
  1270. Message(sym_e_error_in_type_def)
  1271. end;
  1272. disposetree(pt);
  1273. { create arraydef }
  1274. if not assigned(tt.def) then
  1275. begin
  1276. ap:=new(parraydef,init(lowval,highval,arraytype));
  1277. tt.setdef(ap);
  1278. end
  1279. else
  1280. begin
  1281. ap^.elementtype.setdef(new(parraydef,init(lowval,highval,arraytype)));
  1282. ap:=parraydef(ap^.elementtype.def);
  1283. end;
  1284. if token=_COMMA then
  1285. consume(_COMMA)
  1286. else
  1287. break;
  1288. until false;
  1289. consume(_RECKKLAMMER);
  1290. consume(_OF);
  1291. read_type(tt2,'');
  1292. { if no error, set element type }
  1293. if assigned(ap) then
  1294. ap^.elementtype:=tt2;
  1295. end;
  1296. begin
  1297. tt.reset;
  1298. case token of
  1299. _STRING,_FILE:
  1300. begin
  1301. single_type(tt,hs,false);
  1302. end;
  1303. _LKLAMMER:
  1304. begin
  1305. consume(_LKLAMMER);
  1306. { allow negativ value_str }
  1307. l:=-1;
  1308. {aufsym := Nil;}
  1309. aufdef:=new(penumdef,init);
  1310. repeat
  1311. s:=pattern;
  1312. defpos:=tokenpos;
  1313. consume(_ID);
  1314. if token=_ASSIGNMENT then
  1315. begin
  1316. consume(_ASSIGNMENT);
  1317. v:=get_intconst;
  1318. { please leave that a note, allows type save }
  1319. { declarations in the win32 units ! }
  1320. if v<=l then
  1321. Message(parser_n_duplicate_enum);
  1322. l:=v;
  1323. end
  1324. else
  1325. inc(l);
  1326. storepos:=tokenpos;
  1327. tokenpos:=defpos;
  1328. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1329. tokenpos:=storepos;
  1330. if token=_COMMA then
  1331. consume(_COMMA)
  1332. else
  1333. break;
  1334. until false;
  1335. {aufdef^.max:=l;
  1336. if we allow unordered enums
  1337. this can be wrong
  1338. min and max are now set in tenumsym.init PM }
  1339. tt.setdef(aufdef);
  1340. consume(_RKLAMMER);
  1341. end;
  1342. _ARRAY:
  1343. begin
  1344. array_dec;
  1345. end;
  1346. _SET:
  1347. begin
  1348. consume(_SET);
  1349. consume(_OF);
  1350. read_type(tt2,'');
  1351. if assigned(tt2.def) then
  1352. begin
  1353. case tt2.def^.deftype of
  1354. { don't forget that min can be negativ PM }
  1355. enumdef :
  1356. if penumdef(tt2.def)^.min>=0 then
  1357. tt.setdef(new(psetdef,init(tt2.def,penumdef(tt2.def)^.max)))
  1358. else
  1359. Message(sym_e_ill_type_decl_set);
  1360. orddef :
  1361. begin
  1362. case porddef(tt2.def)^.typ of
  1363. uchar :
  1364. tt.setdef(new(psetdef,init(tt2.def,255)));
  1365. u8bit,u16bit,u32bit,
  1366. s8bit,s16bit,s32bit :
  1367. begin
  1368. if (porddef(tt2.def)^.low>=0) then
  1369. tt.setdef(new(psetdef,init(tt2.def,porddef(tt2.def)^.high)))
  1370. else
  1371. Message(sym_e_ill_type_decl_set);
  1372. end;
  1373. else
  1374. Message(sym_e_ill_type_decl_set);
  1375. end;
  1376. end;
  1377. else
  1378. Message(sym_e_ill_type_decl_set);
  1379. end;
  1380. end
  1381. else
  1382. tt.setdef(generrordef);
  1383. end;
  1384. _CARET:
  1385. begin
  1386. consume(_CARET);
  1387. single_type(tt2,hs,typecanbeforward);
  1388. tt.setdef(new(ppointerdef,init(tt2)));
  1389. end;
  1390. _RECORD:
  1391. begin
  1392. tt.setdef(record_dec);
  1393. end;
  1394. _PACKED:
  1395. begin
  1396. consume(_PACKED);
  1397. if token=_ARRAY then
  1398. array_dec
  1399. else
  1400. begin
  1401. oldaktpackrecords:=aktpackrecords;
  1402. aktpackrecords:=packrecord_1;
  1403. if token in [_CLASS,_OBJECT] then
  1404. tt.setdef(object_dec(name,nil))
  1405. else
  1406. tt.setdef(record_dec);
  1407. aktpackrecords:=oldaktpackrecords;
  1408. end;
  1409. end;
  1410. _CLASS,
  1411. _OBJECT:
  1412. begin
  1413. tt.setdef(object_dec(name,nil));
  1414. end;
  1415. _PROCEDURE:
  1416. begin
  1417. consume(_PROCEDURE);
  1418. tt.setdef(new(pprocvardef,init));
  1419. if token=_LKLAMMER then
  1420. parameter_dec(pprocvardef(tt.def));
  1421. if token=_OF then
  1422. begin
  1423. consume(_OF);
  1424. consume(_OBJECT);
  1425. {$ifdef INCLUDEOK}
  1426. include(pprocvardef(tt.def)^.procoptions,po_methodpointer);
  1427. {$else}
  1428. pprocvardef(tt.def)^.procoptions:=pprocvardef(tt.def)^.procoptions+[po_methodpointer];
  1429. {$endif}
  1430. end;
  1431. end;
  1432. _FUNCTION:
  1433. begin
  1434. consume(_FUNCTION);
  1435. tt.def:=new(pprocvardef,init);
  1436. if token=_LKLAMMER then
  1437. parameter_dec(pprocvardef(tt.def));
  1438. consume(_COLON);
  1439. single_type(pprocvardef(tt.def)^.rettype,hs,false);
  1440. if token=_OF then
  1441. begin
  1442. consume(_OF);
  1443. consume(_OBJECT);
  1444. {$ifdef INCLUDEOK}
  1445. include(pprocvardef(tt.def)^.procoptions,po_methodpointer);
  1446. {$else}
  1447. pprocvardef(tt.def)^.procoptions:=pprocvardef(tt.def)^.procoptions+[po_methodpointer];
  1448. {$endif}
  1449. end;
  1450. end;
  1451. else
  1452. expr_type;
  1453. end;
  1454. if tt.def=nil then
  1455. tt.setdef(generrordef);
  1456. end;
  1457. end.
  1458. {
  1459. $Log$
  1460. Revision 1.20 2000-02-24 18:41:39 peter
  1461. * removed warnings/notes
  1462. Revision 1.19 2000/02/21 22:17:49 florian
  1463. * fixed 819
  1464. Revision 1.18 2000/02/09 13:23:01 peter
  1465. * log truncated
  1466. Revision 1.17 2000/02/05 14:33:32 florian
  1467. * fixed init table generation for classes and arrays
  1468. Revision 1.16 2000/01/28 23:17:53 florian
  1469. * virtual XXXX; support for objects, only if -dWITHDMT is defined
  1470. Revision 1.15 2000/01/27 16:31:40 florian
  1471. * bug 738 fixed
  1472. Revision 1.14 2000/01/11 17:16:06 jonas
  1473. * removed a lot of memory leaks when an error is encountered (caused by
  1474. procinfo and pstringcontainers). There are still plenty left though :)
  1475. Revision 1.13 2000/01/07 01:14:34 peter
  1476. * updated copyright to 2000
  1477. Revision 1.12 1999/11/30 10:40:52 peter
  1478. + ttype, tsymlist
  1479. Revision 1.11 1999/11/26 00:19:12 peter
  1480. * property overriding dereference fix, but it need a bigger redesign
  1481. which i'll do tomorrow. This quick hack is for the lazarus ppl so
  1482. they can hack on mwcustomedit.
  1483. Revision 1.10 1999/11/17 17:05:03 pierre
  1484. * Notes/hints changes
  1485. Revision 1.9 1999/11/11 00:56:54 pierre
  1486. * Enum element reference location corrected
  1487. Revision 1.8 1999/11/09 23:43:09 pierre
  1488. * better browser info
  1489. Revision 1.7 1999/11/08 14:02:16 florian
  1490. * problem with "index X"-properties solved
  1491. * typed constants of class references are now allowed
  1492. Revision 1.6 1999/11/07 23:16:49 florian
  1493. * finally bug 517 solved ...
  1494. Revision 1.5 1999/10/27 16:04:06 peter
  1495. * fixed property reading
  1496. Revision 1.4 1999/10/27 14:17:08 florian
  1497. * property overriding fixed
  1498. Revision 1.3 1999/10/26 12:30:45 peter
  1499. * const parameter is now checked
  1500. * better and generic check if a node can be used for assigning
  1501. * export fixes
  1502. * procvar equal works now (it never had worked at least from 0.99.8)
  1503. * defcoll changed to linkedlist with pparaitem so it can easily be
  1504. walked both directions
  1505. Revision 1.2 1999/10/22 14:37:30 peter
  1506. * error when properties are passed to var parameters
  1507. Revision 1.1 1999/10/22 10:39:35 peter
  1508. * split type reading from pdecl to ptype unit
  1509. * parameter_dec routine is now used for procedure and procvars
  1510. }