2
0

ptype.pas 62 KB

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