ptype.pas 61 KB

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