ptype.pas 62 KB

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