ptype.pas 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  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. if token=_COLON then
  299. begin
  300. consume(_COLON);
  301. if token=_ARRAY then
  302. begin
  303. {
  304. if (varspez<>vs_const) and
  305. (varspez<>vs_var) then
  306. begin
  307. varspez:=vs_const;
  308. Message(parser_e_illegal_open_parameter);
  309. end;
  310. }
  311. consume(_ARRAY);
  312. consume(_OF);
  313. { define range and type of range }
  314. tt.setdef(new(parraydef,init(0,-1,s32bitdef)));
  315. { define field type }
  316. single_type(parraydef(tt.def)^.elementtype,s,false);
  317. end
  318. else
  319. single_type(tt,s,false);
  320. end
  321. else
  322. tt.setdef(cformaldef);
  323. repeat
  324. s:=sc^.get_with_tokeninfo(declarepos);
  325. if s='' then
  326. break;
  327. new(hp2,init);
  328. hp2^.paratyp:=varspez;
  329. hp2^.paratype:=tt;
  330. propertyparas^.insert(hp2);
  331. until false;
  332. dispose(sc,done);
  333. until not try_to_consume(_SEMICOLON);
  334. dec(testcurobject);
  335. consume(_RECKKLAMMER);
  336. end;
  337. { overriden property ? }
  338. { force property interface, if there is a property parameter }
  339. if (token=_COLON) or not(propertyparas^.empty) then
  340. begin
  341. consume(_COLON);
  342. single_type(p^.proptype,hs,false);
  343. if (idtoken=_INDEX) then
  344. begin
  345. consume(_INDEX);
  346. pt:=comp_expr(true);
  347. do_firstpass(pt);
  348. if not(is_ordinal(pt^.resulttype)) or
  349. is_64bitint(pt^.resulttype) then
  350. Message(parser_e_invalid_property_index_value);
  351. p^.index:=pt^.value;
  352. p^.indextype.setdef(pt^.resulttype);
  353. include(p^.propoptions,ppo_indexed);
  354. { concat a longint to the para template }
  355. new(hp2,init);
  356. hp2^.paratyp:=vs_value;
  357. hp2^.paratype:=p^.indextype;
  358. propertyparas^.insert(hp2);
  359. disposetree(pt);
  360. end;
  361. { the parser need to know if a property has parameters }
  362. if not(propertyparas^.empty) then
  363. p^.propoptions:=p^.propoptions+[ppo_hasparameters];
  364. end
  365. else
  366. begin
  367. { do an property override }
  368. overriden:=search_class_member(aktclass,propname);
  369. if assigned(overriden) and (overriden^.typ=propertysym) then
  370. begin
  371. p^.dooverride(ppropertysym(overriden));
  372. end
  373. else
  374. begin
  375. p^.proptype.setdef(generrordef);
  376. message(parser_e_no_property_found_to_override);
  377. end;
  378. end;
  379. if (sp_published in current_object_option) and
  380. not(p^.proptype.def^.is_publishable) then
  381. Message(parser_e_cant_publish_that_property);
  382. { create data defcoll to allow correct parameter checks }
  383. new(datacoll,init);
  384. datacoll^.paratyp:=vs_value;
  385. datacoll^.paratype:=p^.proptype;
  386. if (idtoken=_READ) then
  387. begin
  388. p^.readaccess^.clear;
  389. consume(_READ);
  390. sym:=search_class_member(aktclass,pattern);
  391. if not(assigned(sym)) then
  392. begin
  393. Message1(sym_e_unknown_id,pattern);
  394. consume(_ID);
  395. end
  396. else
  397. begin
  398. consume(_ID);
  399. while (token=_POINT) and
  400. ((sym^.typ=varsym) and
  401. (pvarsym(sym)^.vartype.def^.deftype=recorddef)) do
  402. begin
  403. p^.readaccess^.addsym(sym);
  404. consume(_POINT);
  405. getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
  406. if not assigned(srsym) then
  407. Message1(sym_e_illegal_field,pattern);
  408. sym:=srsym;
  409. consume(_ID);
  410. end;
  411. end;
  412. if assigned(sym) then
  413. begin
  414. { search the matching definition }
  415. case sym^.typ of
  416. procsym :
  417. begin
  418. pp:=get_procdef;
  419. if not(assigned(pp)) or
  420. not(is_equal(pp^.rettype.def,p^.proptype.def)) then
  421. Message(parser_e_ill_property_access_sym);
  422. p^.readaccess^.setdef(pp);
  423. end;
  424. varsym :
  425. begin
  426. if not(propertyparas^.empty) or
  427. not(is_equal(pvarsym(sym)^.vartype.def,p^.proptype.def)) then
  428. Message(parser_e_ill_property_access_sym);
  429. end;
  430. else
  431. Message(parser_e_ill_property_access_sym);
  432. end;
  433. p^.readaccess^.addsym(sym);
  434. end;
  435. end;
  436. if (idtoken=_WRITE) then
  437. begin
  438. p^.writeaccess^.clear;
  439. consume(_WRITE);
  440. sym:=search_class_member(aktclass,pattern);
  441. if not(assigned(sym)) then
  442. begin
  443. Message1(sym_e_unknown_id,pattern);
  444. consume(_ID);
  445. end
  446. else
  447. begin
  448. consume(_ID);
  449. while (token=_POINT) and
  450. ((sym^.typ=varsym) and
  451. (pvarsym(sym)^.vartype.def^.deftype=recorddef)) do
  452. begin
  453. p^.writeaccess^.addsym(sym);
  454. consume(_POINT);
  455. getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
  456. if not assigned(srsym) then
  457. Message1(sym_e_illegal_field,pattern);
  458. sym:=srsym;
  459. consume(_ID);
  460. end;
  461. end;
  462. if assigned(sym) then
  463. begin
  464. { search the matching definition }
  465. case sym^.typ of
  466. procsym :
  467. begin
  468. { insert data entry to check access method }
  469. propertyparas^.insert(datacoll);
  470. pp:=get_procdef;
  471. { ... and remove it }
  472. propertyparas^.remove(datacoll);
  473. if not(assigned(pp)) then
  474. Message(parser_e_ill_property_access_sym);
  475. p^.writeaccess^.setdef(pp);
  476. end;
  477. varsym :
  478. begin
  479. if not(propertyparas^.empty) or
  480. not(is_equal(pvarsym(sym)^.vartype.def,p^.proptype.def)) then
  481. Message(parser_e_ill_property_access_sym);
  482. end
  483. else
  484. Message(parser_e_ill_property_access_sym);
  485. end;
  486. p^.writeaccess^.addsym(sym);
  487. end;
  488. end;
  489. include(p^.propoptions,ppo_stored);
  490. if (idtoken=_STORED) then
  491. begin
  492. consume(_STORED);
  493. p^.storedaccess^.clear;
  494. case token of
  495. _ID:
  496. { in the case that idtoken=_DEFAULT }
  497. { we have to do nothing except }
  498. { setting ppo_stored, it's the same }
  499. { as stored true }
  500. if idtoken<>_DEFAULT then
  501. begin
  502. sym:=search_class_member(aktclass,pattern);
  503. if not(assigned(sym)) then
  504. begin
  505. Message1(sym_e_unknown_id,pattern);
  506. consume(_ID);
  507. end
  508. else
  509. begin
  510. consume(_ID);
  511. while (token=_POINT) and
  512. ((sym^.typ=varsym) and
  513. (pvarsym(sym)^.vartype.def^.deftype=recorddef)) do
  514. begin
  515. p^.storedaccess^.addsym(sym);
  516. consume(_POINT);
  517. getsymonlyin(precorddef(pvarsym(sym)^.vartype.def)^.symtable,pattern);
  518. if not assigned(srsym) then
  519. Message1(sym_e_illegal_field,pattern);
  520. sym:=srsym;
  521. consume(_ID);
  522. end;
  523. end;
  524. if assigned(sym) then
  525. begin
  526. { only non array properties can be stored }
  527. case sym^.typ of
  528. procsym :
  529. begin
  530. pp:=pprocsym(sym)^.definition;
  531. while assigned(pp) do
  532. begin
  533. { the stored function shouldn't have any parameters }
  534. if pp^.para^.empty then
  535. break;
  536. pp:=pp^.nextoverloaded;
  537. end;
  538. { found we a procedure and does it really return a bool? }
  539. if not(assigned(pp)) or
  540. not(is_equal(pp^.rettype.def,booldef)) then
  541. Message(parser_e_ill_property_storage_sym);
  542. p^.storedaccess^.setdef(pp);
  543. end;
  544. varsym :
  545. begin
  546. if not(propertyparas^.empty) or
  547. not(is_equal(pvarsym(sym)^.vartype.def,booldef)) then
  548. Message(parser_e_stored_property_must_be_boolean);
  549. end;
  550. else
  551. Message(parser_e_ill_property_storage_sym);
  552. end;
  553. p^.storedaccess^.addsym(sym);
  554. end;
  555. end;
  556. _FALSE:
  557. begin
  558. consume(_FALSE);
  559. exclude(p^.propoptions,ppo_stored);
  560. end;
  561. _TRUE:
  562. consume(_TRUE);
  563. end;
  564. end;
  565. if (idtoken=_DEFAULT) then
  566. begin
  567. consume(_DEFAULT);
  568. if not(is_ordinal(p^.proptype.def) or
  569. is_64bitint(p^.proptype.def) or
  570. ((p^.proptype.def^.deftype=setdef) and
  571. (psetdef(p^.proptype.def)^.settype=smallset)) or
  572. not(propertyparas^.empty)
  573. ) then
  574. Message(parser_e_property_cant_have_a_default_value);
  575. { Get the result of the default, the firstpass is
  576. needed to support values like -1 }
  577. pt:=comp_expr(true);
  578. do_firstpass(pt);
  579. if p^.proptype.def^.deftype=setdef then
  580. begin
  581. {$ifndef newcg}
  582. {!!!!!!!!!!}
  583. arrayconstructor_to_set(pt);
  584. {$endif newcg}
  585. do_firstpass(pt);
  586. end;
  587. pt:=gentypeconvnode(pt,p^.proptype.def);
  588. do_firstpass(pt);
  589. if not(is_constnode(pt)) then
  590. Message(parser_e_property_default_value_must_const);
  591. if pt^.treetype=setconstn then
  592. p^.default:=plongint(pt^.value_set)^
  593. else
  594. p^.default:=pt^.value;
  595. disposetree(pt);
  596. end
  597. else if (idtoken=_NODEFAULT) then
  598. begin
  599. consume(_NODEFAULT);
  600. p^.default:=0;
  601. end;
  602. symtablestack^.insert(p);
  603. { default property ? }
  604. consume(_SEMICOLON);
  605. if (idtoken=_DEFAULT) then
  606. begin
  607. consume(_DEFAULT);
  608. p2:=search_default_property(aktclass);
  609. if assigned(p2) then
  610. message1(parser_e_only_one_default_property,
  611. pobjectdef(p2^.owner^.defowner)^.objname^)
  612. else
  613. begin
  614. {$ifdef INCLUDEOK}
  615. include(p^.propoptions,ppo_defaultproperty);
  616. {$else}
  617. p^.propoptions:=p^.propoptions+[ppo_defaultproperty];
  618. {$endif}
  619. if propertyparas^.empty then
  620. message(parser_e_property_need_paras);
  621. end;
  622. consume(_SEMICOLON);
  623. end;
  624. { clean up }
  625. if assigned(datacoll) then
  626. dispose(datacoll,done);
  627. end
  628. else
  629. begin
  630. consume(_ID);
  631. consume(_SEMICOLON);
  632. end;
  633. dispose(propertyparas,done);
  634. end;
  635. procedure destructor_head;
  636. begin
  637. consume(_DESTRUCTOR);
  638. inc(lexlevel);
  639. parse_proc_head(potype_destructor);
  640. dec(lexlevel);
  641. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  642. Message(parser_e_destructorname_must_be_done);
  643. {$ifdef INCLUDEOK}
  644. include(aktclass^.objectoptions,oo_has_destructor);
  645. {$else}
  646. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_destructor];
  647. {$endif}
  648. consume(_SEMICOLON);
  649. if not(aktprocsym^.definition^.para^.empty) then
  650. Message(parser_e_no_paras_for_destructor);
  651. { no return value }
  652. aktprocsym^.definition^.rettype.def:=voiddef;
  653. end;
  654. var
  655. hs : string;
  656. pcrd : pclassrefdef;
  657. tt : ttype;
  658. oldprocinfo : pprocinfo;
  659. oldprocsym : pprocsym;
  660. oldparse_only : boolean;
  661. methodnametable,intmessagetable,
  662. strmessagetable,classnamelabel : pasmlabel;
  663. storetypecanbeforward : boolean;
  664. vmtlist : taasmoutput;
  665. begin
  666. {Nowadays aktprocsym may already have a value, so we need to save
  667. it.}
  668. oldprocsym:=aktprocsym;
  669. { forward is resolved }
  670. if assigned(fd) then
  671. {$ifdef INCLUDEOK}
  672. exclude(fd^.objectoptions,oo_is_forward);
  673. {$else}
  674. fd^.objectoptions:=fd^.objectoptions-[oo_is_forward];
  675. {$endif}
  676. there_is_a_destructor:=false;
  677. actmembertype:=[sp_public];
  678. { objects and class types can't be declared local }
  679. if (symtablestack^.symtabletype<>globalsymtable) and
  680. (symtablestack^.symtabletype<>staticsymtable) then
  681. Message(parser_e_no_local_objects);
  682. storetypecanbeforward:=typecanbeforward;
  683. { for tp mode don't allow forward types }
  684. if m_tp in aktmodeswitches then
  685. typecanbeforward:=false;
  686. { distinguish classes and objects }
  687. if token=_OBJECT then
  688. begin
  689. is_a_class:=false;
  690. consume(_OBJECT)
  691. end
  692. else
  693. begin
  694. is_a_class:=true;
  695. consume(_CLASS);
  696. if not(assigned(fd)) and (token=_OF) then
  697. begin
  698. { a hack, but it's easy to handle }
  699. { class reference type }
  700. consume(_OF);
  701. single_type(tt,hs,typecanbeforward);
  702. { accept hp1, if is a forward def or a class }
  703. if (tt.def^.deftype=forwarddef) or
  704. ((tt.def^.deftype=objectdef) and pobjectdef(tt.def)^.is_class) then
  705. begin
  706. pcrd:=new(pclassrefdef,init(tt.def));
  707. object_dec:=pcrd;
  708. end
  709. else
  710. begin
  711. object_dec:=generrordef;
  712. Message1(type_e_class_type_expected,generrordef^.typename);
  713. end;
  714. typecanbeforward:=storetypecanbeforward;
  715. exit;
  716. end
  717. { forward class }
  718. else if not(assigned(fd)) and (token=_SEMICOLON) then
  719. begin
  720. { also anonym objects aren't allow (o : object a : longint; end;) }
  721. if n='' then
  722. begin
  723. Message(parser_f_no_anonym_objects)
  724. end;
  725. if n='TOBJECT' then
  726. begin
  727. aktclass:=new(pobjectdef,init(n,nil));
  728. class_tobject:=aktclass;
  729. end
  730. else
  731. aktclass:=new(pobjectdef,init(n,nil));
  732. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_is_class,oo_is_forward];
  733. { all classes must have a vmt !! at offset zero }
  734. if not(oo_has_vmt in aktclass^.objectoptions) then
  735. aktclass^.insertvmt;
  736. object_dec:=aktclass;
  737. typecanbeforward:=storetypecanbeforward;
  738. exit;
  739. end;
  740. end;
  741. { also anonym objects aren't allow (o : object a : longint; end;) }
  742. if n='' then
  743. Message(parser_f_no_anonym_objects);
  744. { read the parent class }
  745. if token=_LKLAMMER then
  746. begin
  747. consume(_LKLAMMER);
  748. id_type(tt,pattern,false);
  749. childof:=pobjectdef(tt.def);
  750. if (childof^.deftype<>objectdef) then
  751. begin
  752. Message1(type_e_class_type_expected,childof^.typename);
  753. childof:=nil;
  754. aktclass:=new(pobjectdef,init(n,nil));
  755. end
  756. else
  757. begin
  758. { a mix of class and object isn't allowed }
  759. if (childof^.is_class and not is_a_class) or
  760. (not childof^.is_class and is_a_class) then
  761. Message(parser_e_mix_of_classes_and_objects);
  762. { the forward of the child must be resolved to get
  763. correct field addresses }
  764. if assigned(fd) then
  765. begin
  766. if (oo_is_forward in childof^.objectoptions) then
  767. Message1(parser_e_forward_declaration_must_be_resolved,childof^.objname^);
  768. aktclass:=fd;
  769. { we must inherit several options !!
  770. this was missing !!
  771. all is now done in set_parent
  772. including symtable datasize setting PM }
  773. fd^.set_parent(childof);
  774. end
  775. else
  776. aktclass:=new(pobjectdef,init(n,childof));
  777. end;
  778. consume(_RKLAMMER);
  779. end
  780. { if no parent class, then a class get tobject as parent }
  781. else if is_a_class then
  782. begin
  783. { is the current class tobject? }
  784. { so you could define your own tobject }
  785. if n='TOBJECT' then
  786. begin
  787. if assigned(fd) then
  788. aktclass:=fd
  789. else
  790. aktclass:=new(pobjectdef,init(n,nil));
  791. class_tobject:=aktclass;
  792. end
  793. else
  794. begin
  795. childof:=class_tobject;
  796. if assigned(fd) then
  797. begin
  798. { the forward of the child must be resolved to get
  799. correct field addresses
  800. }
  801. if (oo_is_forward in childof^.objectoptions) then
  802. Message1(parser_e_forward_declaration_must_be_resolved,childof^.objname^);
  803. aktclass:=fd;
  804. aktclass^.set_parent(childof);
  805. end
  806. else
  807. begin
  808. aktclass:=new(pobjectdef,init(n,childof));
  809. aktclass^.set_parent(childof);
  810. end;
  811. end;
  812. end
  813. else
  814. aktclass:=new(pobjectdef,init(n,nil));
  815. { default access is public }
  816. actmembertype:=[sp_public];
  817. { set the class attribute }
  818. if is_a_class then
  819. begin
  820. {$ifdef INCLUDEOK}
  821. include(aktclass^.objectoptions,oo_is_class);
  822. {$else}
  823. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_is_class];
  824. {$endif}
  825. if (cs_generate_rtti in aktlocalswitches) or
  826. (assigned(aktclass^.childof) and
  827. (oo_can_have_published in aktclass^.childof^.objectoptions)) then
  828. begin
  829. include(aktclass^.objectoptions,oo_can_have_published);
  830. { in "publishable" classes the default access type is published }
  831. actmembertype:=[sp_published];
  832. { don't know if this is necessary (FK) }
  833. current_object_option:=[sp_published];
  834. end;
  835. end;
  836. aktobjectdef:=aktclass;
  837. aktclass^.symtable^.next:=symtablestack;
  838. symtablestack:=aktclass^.symtable;
  839. testcurobject:=1;
  840. curobjectname:=n;
  841. { new procinfo }
  842. oldprocinfo:=procinfo;
  843. new(procinfo,init);
  844. procinfo^._class:=aktclass;
  845. { short class declaration ? }
  846. if (not is_a_class) or (token<>_SEMICOLON) then
  847. begin
  848. { Parse componenten }
  849. repeat
  850. if (sp_private in actmembertype) then
  851. {$ifdef INCLUDEOK}
  852. include(aktclass^.objectoptions,oo_has_private);
  853. {$else}
  854. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_private];
  855. {$endif}
  856. if (sp_protected in actmembertype) then
  857. {$ifdef INCLUDEOK}
  858. include(aktclass^.objectoptions,oo_has_protected);
  859. {$else}
  860. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_protected];
  861. {$endif}
  862. case token of
  863. _ID : begin
  864. case idtoken of
  865. _PRIVATE : begin
  866. consume(_PRIVATE);
  867. actmembertype:=[sp_private];
  868. current_object_option:=[sp_private];
  869. end;
  870. _PROTECTED : begin
  871. consume(_PROTECTED);
  872. current_object_option:=[sp_protected];
  873. actmembertype:=[sp_protected];
  874. end;
  875. _PUBLIC : begin
  876. consume(_PUBLIC);
  877. current_object_option:=[sp_public];
  878. actmembertype:=[sp_public];
  879. end;
  880. _PUBLISHED : begin
  881. if not(oo_can_have_published in aktclass^.objectoptions) then
  882. Message(parser_e_cant_have_published);
  883. consume(_PUBLISHED);
  884. current_object_option:=[sp_published];
  885. actmembertype:=[sp_published];
  886. end;
  887. else
  888. read_var_decs(false,true,false);
  889. end;
  890. end;
  891. _PROPERTY : property_dec;
  892. _PROCEDURE,
  893. _FUNCTION,
  894. _CLASS : begin
  895. oldparse_only:=parse_only;
  896. parse_only:=true;
  897. parse_proc_dec;
  898. {$ifndef newcg}
  899. parse_object_proc_directives(aktprocsym);
  900. {$endif newcg}
  901. if (po_msgint in aktprocsym^.definition^.procoptions) then
  902. {$ifdef INCLUDEOK}
  903. include(aktclass^.objectoptions,oo_has_msgint);
  904. {$else}
  905. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_msgint];
  906. {$endif}
  907. if (po_msgstr in aktprocsym^.definition^.procoptions) then
  908. {$ifdef INCLUDEOK}
  909. include(aktclass^.objectoptions,oo_has_msgstr);
  910. {$else}
  911. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_msgstr];
  912. {$endif}
  913. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  914. {$ifdef INCLUDEOK}
  915. include(aktclass^.objectoptions,oo_has_virtual);
  916. {$else}
  917. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  918. {$endif}
  919. parse_only:=oldparse_only;
  920. end;
  921. _CONSTRUCTOR : begin
  922. if not(sp_public in actmembertype) then
  923. Message(parser_w_constructor_should_be_public);
  924. oldparse_only:=parse_only;
  925. parse_only:=true;
  926. constructor_head;
  927. {$ifndef newcg}
  928. parse_object_proc_directives(aktprocsym);
  929. {$endif newcg}
  930. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  931. {$ifdef INCLUDEOK}
  932. include(aktclass^.objectoptions,oo_has_virtual);
  933. {$else}
  934. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  935. {$endif}
  936. parse_only:=oldparse_only;
  937. end;
  938. _DESTRUCTOR : begin
  939. if there_is_a_destructor then
  940. Message(parser_n_only_one_destructor);
  941. there_is_a_destructor:=true;
  942. if not(sp_public in actmembertype) then
  943. Message(parser_w_destructor_should_be_public);
  944. oldparse_only:=parse_only;
  945. parse_only:=true;
  946. destructor_head;
  947. {$ifndef newcg}
  948. parse_object_proc_directives(aktprocsym);
  949. {$endif newcg}
  950. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  951. {$ifdef INCLUDEOK}
  952. include(aktclass^.objectoptions,oo_has_virtual);
  953. {$else}
  954. aktclass^.objectoptions:=aktclass^.objectoptions+[oo_has_virtual];
  955. {$endif}
  956. parse_only:=oldparse_only;
  957. end;
  958. _END : begin
  959. consume(_END);
  960. break;
  961. end;
  962. else
  963. consume(_ID); { Give a ident expected message, like tp7 }
  964. end;
  965. until false;
  966. current_object_option:=[sp_public];
  967. end;
  968. testcurobject:=0;
  969. curobjectname:='';
  970. typecanbeforward:=storetypecanbeforward;
  971. { generate vmt space if needed }
  972. if not(oo_has_vmt in aktclass^.objectoptions) and
  973. ([oo_has_virtual,oo_has_constructor,oo_has_destructor,oo_is_class]*aktclass^.objectoptions<>[]) then
  974. aktclass^.insertvmt;
  975. if (cs_create_smart in aktmoduleswitches) then
  976. datasegment^.concat(new(pai_cut,init));
  977. { Write the start of the VMT, wich is equal for classes and objects }
  978. if (oo_has_vmt in aktclass^.objectoptions) then
  979. begin
  980. { this generates the entries }
  981. vmtlist.init;
  982. genvmt(@vmtlist,aktclass);
  983. { write tables for classes, this must be done before the actual
  984. class is written, because we need the labels defined }
  985. if is_a_class then
  986. begin
  987. methodnametable:=genpublishedmethodstable(aktclass);
  988. { rtti }
  989. if (oo_can_have_published in aktclass^.objectoptions) then
  990. aktclass^.generate_rtti;
  991. { write class name }
  992. getdatalabel(classnamelabel);
  993. datasegment^.concat(new(pai_label,init(classnamelabel)));
  994. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.objname^))));
  995. datasegment^.concat(new(pai_string,init(aktclass^.objname^)));
  996. { generate message and dynamic tables }
  997. if (oo_has_msgstr in aktclass^.objectoptions) then
  998. strmessagetable:=genstrmsgtab(aktclass);
  999. if (oo_has_msgint in aktclass^.objectoptions) then
  1000. intmessagetable:=genintmsgtab(aktclass)
  1001. else
  1002. datasegment^.concat(new(pai_const,init_32bit(0)));
  1003. end;
  1004. { write debug info }
  1005. {$ifdef GDB}
  1006. if (cs_debuginfo in aktmoduleswitches) then
  1007. begin
  1008. do_count_dbx:=true;
  1009. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1010. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1011. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1012. end;
  1013. {$endif GDB}
  1014. datasegment^.concat(new(pai_symbol,initname_global(aktclass^.vmt_mangledname,0)));
  1015. { determine the size with symtable^.datasize, because }
  1016. { size gives back 4 for classes }
  1017. datasegment^.concat(new(pai_const,init_32bit(aktclass^.symtable^.datasize)));
  1018. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.symtable^.datasize)));
  1019. { write pointer to parent VMT, this isn't implemented in TP }
  1020. { but this is not used in FPC ? (PM) }
  1021. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1022. { it is not written for parents that don't have any vmt !! }
  1023. if assigned(aktclass^.childof) and
  1024. (oo_has_vmt in aktclass^.childof^.objectoptions) then
  1025. datasegment^.concat(new(pai_const_symbol,initname(aktclass^.childof^.vmt_mangledname)))
  1026. else
  1027. datasegment^.concat(new(pai_const,init_32bit(0)));
  1028. { write extended info for classes, for the order see rtl/inc/objpash.inc }
  1029. if is_a_class then
  1030. begin
  1031. { pointer to class name string }
  1032. datasegment^.concat(new(pai_const_symbol,init(classnamelabel)));
  1033. { pointer to dynamic table }
  1034. if (oo_has_msgint in aktclass^.objectoptions) then
  1035. datasegment^.concat(new(pai_const_symbol,init(intmessagetable)))
  1036. else
  1037. datasegment^.concat(new(pai_const,init_32bit(0)));
  1038. { pointer to method table }
  1039. if assigned(methodnametable) then
  1040. datasegment^.concat(new(pai_const_symbol,init(methodnametable)))
  1041. else
  1042. datasegment^.concat(new(pai_const,init_32bit(0)));
  1043. { pointer to field table }
  1044. datasegment^.concat(new(pai_const,init_32bit(0)));
  1045. { pointer to type info of published section }
  1046. if (oo_can_have_published in aktclass^.objectoptions) then
  1047. datasegment^.concat(new(pai_const_symbol,initname(aktclass^.rtti_name)))
  1048. else
  1049. datasegment^.concat(new(pai_const,init_32bit(0)));
  1050. { inittable for con-/destruction }
  1051. if aktclass^.needs_inittable then
  1052. datasegment^.concat(new(pai_const_symbol,init(aktclass^.get_inittable_label)))
  1053. else
  1054. datasegment^.concat(new(pai_const,init_32bit(0)));
  1055. { auto table }
  1056. datasegment^.concat(new(pai_const,init_32bit(0)));
  1057. { interface table }
  1058. datasegment^.concat(new(pai_const,init_32bit(0)));
  1059. { table for string messages }
  1060. if (oo_has_msgstr in aktclass^.objectoptions) then
  1061. datasegment^.concat(new(pai_const_symbol,init(strmessagetable)))
  1062. else
  1063. datasegment^.concat(new(pai_const,init_32bit(0)));
  1064. end;
  1065. datasegment^.concatlist(@vmtlist);
  1066. vmtlist.done;
  1067. { write the size of the VMT }
  1068. datasegment^.concat(new(pai_symbol_end,initname(aktclass^.vmt_mangledname)));
  1069. end;
  1070. { restore old state }
  1071. symtablestack:=symtablestack^.next;
  1072. aktobjectdef:=nil;
  1073. {Restore procinfo}
  1074. dispose(procinfo,done);
  1075. procinfo:=oldprocinfo;
  1076. {Restore the aktprocsym.}
  1077. aktprocsym:=oldprocsym;
  1078. object_dec:=aktclass;
  1079. end;
  1080. { reads a record declaration }
  1081. function record_dec : pdef;
  1082. var
  1083. symtable : psymtable;
  1084. storetypecanbeforward : boolean;
  1085. begin
  1086. { create recdef }
  1087. symtable:=new(psymtable,init(recordsymtable));
  1088. record_dec:=new(precorddef,init(symtable));
  1089. { update symtable stack }
  1090. symtable^.next:=symtablestack;
  1091. symtablestack:=symtable;
  1092. { parse record }
  1093. consume(_RECORD);
  1094. storetypecanbeforward:=typecanbeforward;
  1095. { for tp mode don't allow forward types }
  1096. if m_tp in aktmodeswitches then
  1097. typecanbeforward:=false;
  1098. read_var_decs(true,false,false);
  1099. consume(_END);
  1100. typecanbeforward:=storetypecanbeforward;
  1101. { may be scale record size to a size of n*4 ? }
  1102. symtablestack^.datasize:=align(symtablestack^.datasize,symtablestack^.dataalignment);
  1103. { restore symtable stack }
  1104. symtablestack:=symtable^.next;
  1105. end;
  1106. { reads a type definition and returns a pointer to it }
  1107. procedure read_type(var tt : ttype;const name : stringid);
  1108. var
  1109. pt : ptree;
  1110. tt2 : ttype;
  1111. aufdef : penumdef;
  1112. {aufsym : penumsym;}
  1113. ap : parraydef;
  1114. s : stringid;
  1115. l,v : longint;
  1116. oldaktpackrecords : tpackrecords;
  1117. hs : string;
  1118. defpos,storepos : tfileposinfo;
  1119. procedure expr_type;
  1120. var
  1121. pt1,pt2 : ptree;
  1122. begin
  1123. { use of current parsed object ? }
  1124. if (token=_ID) and (testcurobject=2) and (curobjectname=pattern) then
  1125. begin
  1126. consume(_ID);
  1127. tt.setdef(aktobjectdef);
  1128. exit;
  1129. end;
  1130. { we can't accept a equal in type }
  1131. pt1:=comp_expr(not(ignore_equal));
  1132. do_firstpass(pt1);
  1133. if (token=_POINTPOINT) then
  1134. begin
  1135. consume(_POINTPOINT);
  1136. { get high value of range }
  1137. pt2:=comp_expr(not(ignore_equal));
  1138. do_firstpass(pt2);
  1139. { both must be evaluated to constants now }
  1140. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1141. Message(sym_e_error_in_type_def)
  1142. else
  1143. begin
  1144. { check types }
  1145. if CheckTypes(pt1^.resulttype,pt2^.resulttype) then
  1146. begin
  1147. { Check bounds }
  1148. if pt2^.value<pt1^.value then
  1149. Message(cg_e_upper_lower_than_lower)
  1150. else
  1151. begin
  1152. { All checks passed, create the new def }
  1153. case pt1^.resulttype^.deftype of
  1154. enumdef : tt.setdef(new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value)));
  1155. orddef : begin
  1156. if is_char(pt1^.resulttype) then
  1157. tt.setdef(new(porddef,init(uchar,pt1^.value,pt2^.value)))
  1158. else
  1159. if is_boolean(pt1^.resulttype) then
  1160. tt.setdef(new(porddef,init(bool8bit,pt1^.value,pt2^.value)))
  1161. else
  1162. tt.setdef(new(porddef,init(uauto,pt1^.value,pt2^.value)));
  1163. end;
  1164. end;
  1165. end;
  1166. end;
  1167. end;
  1168. disposetree(pt2);
  1169. end
  1170. else
  1171. begin
  1172. { a simple type renaming }
  1173. if (pt1^.treetype=typen) then
  1174. begin
  1175. if assigned(pt1^.typenodesym) then
  1176. tt.setsym(pt1^.typenodesym)
  1177. else
  1178. tt.setdef(pt1^.resulttype);
  1179. end
  1180. else
  1181. Message(sym_e_error_in_type_def);
  1182. end;
  1183. disposetree(pt1);
  1184. end;
  1185. procedure array_dec;
  1186. var
  1187. lowval,
  1188. highval : longint;
  1189. arraytype : pdef;
  1190. begin
  1191. consume(_ARRAY);
  1192. consume(_LECKKLAMMER);
  1193. { defaults }
  1194. arraytype:=generrordef;
  1195. lowval:=$80000000;
  1196. highval:=$7fffffff;
  1197. tt.reset;
  1198. repeat
  1199. { read the expression and check it }
  1200. pt:=expr;
  1201. if pt^.treetype=typen then
  1202. begin
  1203. case pt^.resulttype^.deftype of
  1204. enumdef :
  1205. begin
  1206. lowval:=penumdef(pt^.resulttype)^.min;
  1207. highval:=penumdef(pt^.resulttype)^.max;
  1208. arraytype:=pt^.resulttype;
  1209. end;
  1210. orddef :
  1211. begin
  1212. lowval:=porddef(pt^.resulttype)^.low;
  1213. highval:=porddef(pt^.resulttype)^.high;
  1214. arraytype:=pt^.resulttype;
  1215. end;
  1216. else
  1217. Message(sym_e_error_in_type_def);
  1218. end;
  1219. end
  1220. else
  1221. begin
  1222. do_firstpass(pt);
  1223. if (pt^.treetype=rangen) then
  1224. begin
  1225. if (pt^.left^.treetype=ordconstn) and
  1226. (pt^.right^.treetype=ordconstn) then
  1227. begin
  1228. lowval:=pt^.left^.value;
  1229. highval:=pt^.right^.value;
  1230. if highval<lowval then
  1231. begin
  1232. Message(parser_e_array_lower_less_than_upper_bound);
  1233. highval:=lowval;
  1234. end;
  1235. arraytype:=pt^.right^.resulttype;
  1236. end
  1237. else
  1238. Message(type_e_cant_eval_constant_expr);
  1239. end
  1240. else
  1241. Message(sym_e_error_in_type_def)
  1242. end;
  1243. disposetree(pt);
  1244. { create arraydef }
  1245. if not assigned(tt.def) then
  1246. begin
  1247. ap:=new(parraydef,init(lowval,highval,arraytype));
  1248. tt.setdef(ap);
  1249. end
  1250. else
  1251. begin
  1252. ap^.elementtype.setdef(new(parraydef,init(lowval,highval,arraytype)));
  1253. ap:=parraydef(ap^.elementtype.def);
  1254. end;
  1255. if token=_COMMA then
  1256. consume(_COMMA)
  1257. else
  1258. break;
  1259. until false;
  1260. consume(_RECKKLAMMER);
  1261. consume(_OF);
  1262. read_type(tt2,'');
  1263. { if no error, set element type }
  1264. if assigned(ap) then
  1265. ap^.elementtype:=tt2;
  1266. end;
  1267. begin
  1268. tt.reset;
  1269. case token of
  1270. _STRING,_FILE:
  1271. begin
  1272. single_type(tt,hs,false);
  1273. end;
  1274. _LKLAMMER:
  1275. begin
  1276. consume(_LKLAMMER);
  1277. { allow negativ value_str }
  1278. l:=-1;
  1279. {aufsym := Nil;}
  1280. aufdef:=new(penumdef,init);
  1281. repeat
  1282. s:=pattern;
  1283. defpos:=tokenpos;
  1284. consume(_ID);
  1285. if token=_ASSIGNMENT then
  1286. begin
  1287. consume(_ASSIGNMENT);
  1288. v:=get_intconst;
  1289. { please leave that a note, allows type save }
  1290. { declarations in the win32 units ! }
  1291. if v<=l then
  1292. Message(parser_n_duplicate_enum);
  1293. l:=v;
  1294. end
  1295. else
  1296. inc(l);
  1297. storepos:=tokenpos;
  1298. tokenpos:=defpos;
  1299. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1300. tokenpos:=storepos;
  1301. if token=_COMMA then
  1302. consume(_COMMA)
  1303. else
  1304. break;
  1305. until false;
  1306. {aufdef^.max:=l;
  1307. if we allow unordered enums
  1308. this can be wrong
  1309. min and max are now set in tenumsym.init PM }
  1310. tt.setdef(aufdef);
  1311. consume(_RKLAMMER);
  1312. end;
  1313. _ARRAY:
  1314. begin
  1315. array_dec;
  1316. end;
  1317. _SET:
  1318. begin
  1319. consume(_SET);
  1320. consume(_OF);
  1321. read_type(tt2,'');
  1322. if assigned(tt2.def) then
  1323. begin
  1324. case tt2.def^.deftype of
  1325. { don't forget that min can be negativ PM }
  1326. enumdef :
  1327. if penumdef(tt2.def)^.min>=0 then
  1328. tt.setdef(new(psetdef,init(tt2.def,penumdef(tt2.def)^.max)))
  1329. else
  1330. Message(sym_e_ill_type_decl_set);
  1331. orddef :
  1332. begin
  1333. case porddef(tt2.def)^.typ of
  1334. uchar :
  1335. tt.setdef(new(psetdef,init(tt2.def,255)));
  1336. u8bit,u16bit,u32bit,
  1337. s8bit,s16bit,s32bit :
  1338. begin
  1339. if (porddef(tt2.def)^.low>=0) then
  1340. tt.setdef(new(psetdef,init(tt2.def,porddef(tt2.def)^.high)))
  1341. else
  1342. Message(sym_e_ill_type_decl_set);
  1343. end;
  1344. else
  1345. Message(sym_e_ill_type_decl_set);
  1346. end;
  1347. end;
  1348. else
  1349. Message(sym_e_ill_type_decl_set);
  1350. end;
  1351. end
  1352. else
  1353. tt.setdef(generrordef);
  1354. end;
  1355. _CARET:
  1356. begin
  1357. consume(_CARET);
  1358. single_type(tt2,hs,typecanbeforward);
  1359. tt.setdef(new(ppointerdef,init(tt2)));
  1360. end;
  1361. _RECORD:
  1362. begin
  1363. tt.setdef(record_dec);
  1364. end;
  1365. _PACKED:
  1366. begin
  1367. consume(_PACKED);
  1368. if token=_ARRAY then
  1369. array_dec
  1370. else
  1371. begin
  1372. oldaktpackrecords:=aktpackrecords;
  1373. aktpackrecords:=packrecord_1;
  1374. if token in [_CLASS,_OBJECT] then
  1375. tt.setdef(object_dec(name,nil))
  1376. else
  1377. tt.setdef(record_dec);
  1378. aktpackrecords:=oldaktpackrecords;
  1379. end;
  1380. end;
  1381. _CLASS,
  1382. _OBJECT:
  1383. begin
  1384. tt.setdef(object_dec(name,nil));
  1385. end;
  1386. _PROCEDURE:
  1387. begin
  1388. consume(_PROCEDURE);
  1389. tt.setdef(new(pprocvardef,init));
  1390. if token=_LKLAMMER then
  1391. parameter_dec(pprocvardef(tt.def));
  1392. if token=_OF then
  1393. begin
  1394. consume(_OF);
  1395. consume(_OBJECT);
  1396. {$ifdef INCLUDEOK}
  1397. include(pprocvardef(tt.def)^.procoptions,po_methodpointer);
  1398. {$else}
  1399. pprocvardef(tt.def)^.procoptions:=pprocvardef(tt.def)^.procoptions+[po_methodpointer];
  1400. {$endif}
  1401. end;
  1402. end;
  1403. _FUNCTION:
  1404. begin
  1405. consume(_FUNCTION);
  1406. tt.def:=new(pprocvardef,init);
  1407. if token=_LKLAMMER then
  1408. parameter_dec(pprocvardef(tt.def));
  1409. consume(_COLON);
  1410. single_type(pprocvardef(tt.def)^.rettype,hs,false);
  1411. if token=_OF then
  1412. begin
  1413. consume(_OF);
  1414. consume(_OBJECT);
  1415. {$ifdef INCLUDEOK}
  1416. include(pprocvardef(tt.def)^.procoptions,po_methodpointer);
  1417. {$else}
  1418. pprocvardef(tt.def)^.procoptions:=pprocvardef(tt.def)^.procoptions+[po_methodpointer];
  1419. {$endif}
  1420. end;
  1421. end;
  1422. else
  1423. expr_type;
  1424. end;
  1425. if tt.def=nil then
  1426. tt.setdef(generrordef);
  1427. end;
  1428. end.
  1429. {
  1430. $Log$
  1431. Revision 1.13 2000-01-07 01:14:34 peter
  1432. * updated copyright to 2000
  1433. Revision 1.12 1999/11/30 10:40:52 peter
  1434. + ttype, tsymlist
  1435. Revision 1.11 1999/11/26 00:19:12 peter
  1436. * property overriding dereference fix, but it need a bigger redesign
  1437. which i'll do tomorrow. This quick hack is for the lazarus ppl so
  1438. they can hack on mwcustomedit.
  1439. Revision 1.10 1999/11/17 17:05:03 pierre
  1440. * Notes/hints changes
  1441. Revision 1.9 1999/11/11 00:56:54 pierre
  1442. * Enum element reference location corrected
  1443. Revision 1.8 1999/11/09 23:43:09 pierre
  1444. * better browser info
  1445. Revision 1.7 1999/11/08 14:02:16 florian
  1446. * problem with "index X"-properties solved
  1447. * typed constants of class references are now allowed
  1448. Revision 1.6 1999/11/07 23:16:49 florian
  1449. * finally bug 517 solved ...
  1450. Revision 1.5 1999/10/27 16:04:06 peter
  1451. * fixed property reading
  1452. Revision 1.4 1999/10/27 14:17:08 florian
  1453. * property overriding fixed
  1454. Revision 1.3 1999/10/26 12:30:45 peter
  1455. * const parameter is now checked
  1456. * better and generic check if a node can be used for assigning
  1457. * export fixes
  1458. * procvar equal works now (it never had worked at least from 0.99.8)
  1459. * defcoll changed to linkedlist with pparaitem so it can easily be
  1460. walked both directions
  1461. Revision 1.2 1999/10/22 14:37:30 peter
  1462. * error when properties are passed to var parameters
  1463. Revision 1.1 1999/10/22 10:39:35 peter
  1464. * split type reading from pdecl to ptype unit
  1465. * parameter_dec routine is now used for procedure and procvars
  1466. }