pdecl.pas 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Does declaration parsing 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 pdecl;
  19. interface
  20. uses
  21. globals,symtable;
  22. var
  23. { pointer to the last read type symbol, (for "forward" }
  24. { types) }
  25. lasttypesym : ptypesym;
  26. { hack, which allows to use the current parsed }
  27. { object type as function argument type }
  28. testcurobject : byte;
  29. curobjectname : stringid;
  30. { reads a string type with optional length }
  31. { and returns a pointer to the string }
  32. { definition }
  33. function stringtype : pdef;
  34. { reads a string, file type or a type id and returns a name and }
  35. { pdef }
  36. function single_type(var s : string) : pdef;
  37. { reads the declaration blocks }
  38. procedure read_declarations(islibrary : boolean);
  39. { reads declarations in the interface part of a unit }
  40. procedure read_interface_declarations;
  41. implementation
  42. uses
  43. cobjects,scanner,aasm,tree,pass_1,
  44. types,hcodegen,verbose,systems
  45. {$ifdef GDB}
  46. ,gdb
  47. {$endif GDB}
  48. { parser specific stuff }
  49. ,pbase,ptconst,pexpr,psub,pexports
  50. { processor specific stuff }
  51. {$ifdef i386}
  52. ,i386
  53. {$endif}
  54. {$ifdef m68k}
  55. ,m68k
  56. {$endif}
  57. ;
  58. function read_type(const name : stringid) : pdef;forward;
  59. procedure read_var_decs(is_record : boolean;do_absolute : boolean);forward;
  60. procedure const_dec;
  61. var
  62. name : stringid;
  63. p : ptree;
  64. def : pdef;
  65. ps : pconstset;
  66. pd : pdouble;
  67. begin
  68. consume(_CONST);
  69. repeat
  70. name:=pattern;
  71. consume(ID);
  72. case token of
  73. EQUAL:
  74. begin
  75. consume(EQUAL);
  76. p:=expr;
  77. do_firstpass(p);
  78. case p^.treetype of
  79. ordconstn:
  80. begin
  81. if is_constintnode(p) then
  82. symtablestack^.insert(new(pconstsym,init(name,constint,p^.value,nil)))
  83. else if is_constcharnode(p) then
  84. symtablestack^.insert(new(pconstsym,init(name,constchar,p^.value,nil)))
  85. else if is_constboolnode(p) then
  86. symtablestack^.insert(new(pconstsym,init(name,constbool,p^.value,nil)))
  87. else if p^.resulttype^.deftype=enumdef then
  88. symtablestack^.insert(new(pconstsym,init(name,constord,p^.value,p^.resulttype)))
  89. else internalerror(111);
  90. end;
  91. stringconstn:
  92. {values is disposed with p so I need a copy !}
  93. symtablestack^.insert(new(pconstsym,init(name,conststring,longint(stringdup(p^.values^)),nil)));
  94. realconstn : begin
  95. new(pd);
  96. pd^:=p^.valued;
  97. symtablestack^.insert(new(pconstsym,init(name,constreal,longint(pd),nil)));
  98. end;
  99. setconstrn : begin
  100. new(ps);
  101. ps^:=p^.constset^;
  102. symtablestack^.insert(new(pconstsym,init(name,
  103. constseta,longint(ps),p^.resulttype)));
  104. end;
  105. else Message(cg_e_illegal_expression);
  106. end;
  107. consume(SEMICOLON);
  108. end;
  109. COLON:
  110. begin
  111. { this was missed, so const s : ^string = nil gives an
  112. error (FK)
  113. }
  114. parse_types:=true;
  115. consume(COLON);
  116. def:=read_type('');
  117. symtablestack^.insert(new(ptypedconstsym,init(name,def)));
  118. parse_types:=false;
  119. consume(EQUAL);
  120. readtypedconst(def);
  121. consume(SEMICOLON);
  122. end;
  123. else consume(EQUAL);
  124. end;
  125. until token<>ID;
  126. end;
  127. procedure label_dec;
  128. var
  129. hl : plabel;
  130. begin
  131. consume(_LABEL);
  132. if not(cs_support_goto in aktswitches) then
  133. Message(sym_e_goto_and_label_not_supported);
  134. repeat
  135. if not(token in [ID,INTCONST]) then
  136. consume(ID)
  137. else
  138. begin
  139. getlabel(hl);
  140. symtablestack^.insert(new(plabelsym,init(pattern,hl)));
  141. consume(token);
  142. end;
  143. if token<>SEMICOLON then consume(COMMA);
  144. until not(token in [ID,INTCONST]);
  145. consume(SEMICOLON);
  146. end;
  147. { reads a string type with optional length }
  148. { and returns a pointer to the string }
  149. { definition }
  150. function stringtype : pdef;
  151. var
  152. p : ptree;
  153. d : pdef;
  154. begin
  155. consume(_STRING);
  156. if token=LECKKLAMMER then
  157. begin
  158. consume(LECKKLAMMER);
  159. p:=expr;
  160. do_firstpass(p);
  161. if not is_constintnode(p) then
  162. Message(cg_e_illegal_expression);
  163. {$ifndef UseLongString}
  164. if (p^.value<1) or (p^.value>255) then
  165. begin
  166. Message(parser_e_string_too_long);
  167. p^.value:=255;
  168. end;
  169. consume(RECKKLAMMER);
  170. if p^.value<>255 then
  171. d:=new(pstringdef,init(p^.value))
  172. {$ifndef GDB}
  173. else d:=new(pstringdef,init(255));
  174. {$else * GDB *}
  175. else d:=globaldef('SYSTEM.STRING');
  176. {$endif * GDB *}
  177. {$else UseLongString}
  178. if p^.value>255 then
  179. d:=new(pstringdef,longinit(p^.value)
  180. else if p^.value<>255 then
  181. d:=new(pstringdef,init(p^.value))
  182. {$ifndef GDB}
  183. else d:=new(pstringdef,init(255));
  184. {$else * GDB *}
  185. else d:=globaldef('SYSTEM.STRING');
  186. {$endif * GDB *}
  187. {$endif UseLongString}
  188. disposetree(p);
  189. end
  190. {$ifndef GDB}
  191. else d:=new(pstringdef,init(255));
  192. {$else * GDB *}
  193. else d:=globaldef('SYSTEM.STRING');
  194. {$endif * GDB *}
  195. stringtype:=d;
  196. end;
  197. { reads a type definition and returns a pointer }
  198. { to a appropriating pdef, s gets the name of }
  199. { the type to allow name mangling }
  200. function id_type(var s : string) : pdef;
  201. begin
  202. s:=pattern;
  203. consume(ID);
  204. if (testcurobject=2) and (curobjectname=pattern) then
  205. begin
  206. id_type:=aktobjectdef;
  207. exit;
  208. end;
  209. getsym(s,true);
  210. if assigned(srsym) then
  211. begin
  212. if srsym^.typ=unitsym then
  213. begin
  214. consume(POINT);
  215. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  216. s:=pattern;
  217. consume(ID);
  218. end;
  219. if srsym^.typ<>typesym then
  220. begin
  221. Message(sym_e_type_id_expected);
  222. lasttypesym:=ptypesym(srsym);
  223. id_type:=generrordef;
  224. exit;
  225. end;
  226. end;
  227. lasttypesym:=ptypesym(srsym);
  228. id_type:=ptypesym(srsym)^.definition;
  229. end;
  230. { reads a string, file type or a type id and returns a name and }
  231. { pdef }
  232. function single_type(var s : string) : pdef;
  233. var
  234. hs : string;
  235. begin
  236. case token of
  237. _STRING:
  238. begin
  239. single_type:=stringtype;
  240. s:='STRING';
  241. lasttypesym:=nil;
  242. end;
  243. _FILE:
  244. begin
  245. consume(_FILE);
  246. if token=_OF then
  247. begin
  248. consume(_OF);
  249. single_type:=new(pfiledef,init(ft_typed,single_type(hs)));
  250. s:='FILE$OF$'+hs;
  251. end
  252. else
  253. begin
  254. { single_type:=new(pfiledef,init(ft_untyped,nil));}
  255. single_type:=cfiledef;
  256. s:='FILE';
  257. end;
  258. lasttypesym:=nil;
  259. end;
  260. else single_type:=id_type(s);
  261. end;
  262. end;
  263. { this function parses an object or class declaration }
  264. function object_dec(const n : stringid;fd : pobjectdef) : pdef;
  265. var
  266. actmembertype : symprop;
  267. there_is_a_destructor : boolean;
  268. is_a_class : boolean;
  269. childof : pobjectdef;
  270. aktclass : pobjectdef;
  271. procedure constructor_head;
  272. begin
  273. consume(_CONSTRUCTOR);
  274. { must be at same level as in implementation }
  275. _proc_head(poconstructor);
  276. if (cs_checkconsname in aktswitches) and (aktprocsym^.name<>'INIT') then
  277. Message(parser_e_constructorname_must_be_init);
  278. consume(SEMICOLON);
  279. begin
  280. if (aktclass^.options and oois_class)<>0 then
  281. begin
  282. { CLASS constructors return the created instance }
  283. aktprocsym^.definition^.retdef:=aktclass;
  284. end
  285. else
  286. begin
  287. { OBJECT constructors return a boolean }
  288. {$IfDef GDB}
  289. {GDB doesn't like unnamed types !}
  290. aktprocsym^.definition^.retdef:=
  291. globaldef('boolean');
  292. {$Else * GDB *}
  293. aktprocsym^.definition^.retdef:=
  294. new(porddef,init(bool8bit,0,1));
  295. {$Endif * GDB *}
  296. end;
  297. end;
  298. end;
  299. procedure property_dec;
  300. var
  301. sym : psym;
  302. propertyparas : pdefcoll;
  303. { returns the matching procedure to access a property }
  304. function get_procdef : pprocdef;
  305. var
  306. p : pprocdef;
  307. begin
  308. p:=pprocsym(sym)^.definition;
  309. get_procdef:=nil;
  310. while assigned(p) do
  311. begin
  312. if equal_paras(p^.para1,propertyparas) then
  313. break;
  314. p:=p^.nextoverloaded;
  315. end;
  316. get_procdef:=p;
  317. end;
  318. var
  319. hp2,datacoll : pdefcoll;
  320. p,p2 : ppropertysym;
  321. overriden : psym;
  322. hs : string;
  323. code : word;
  324. varspez : tvarspez;
  325. sc : pstringcontainer;
  326. hp : pdef;
  327. s : string;
  328. begin
  329. { check for a class }
  330. if (aktclass^.options and oois_class=0) then
  331. Message(parser_e_syntax_error);
  332. consume(_PROPERTY);
  333. if token=ID then
  334. begin
  335. p:=new(ppropertysym,init(pattern));
  336. consume(ID);
  337. propertyparas:=nil;
  338. datacoll:=nil;
  339. { property parameters ? }
  340. if token=LECKKLAMMER then
  341. begin
  342. { create a list of the parameters in propertyparas }
  343. consume(LECKKLAMMER);
  344. inc(testcurobject);
  345. repeat
  346. if token=_VAR then
  347. begin
  348. consume(_VAR);
  349. varspez:=vs_var;
  350. end
  351. else if token=_CONST then
  352. begin
  353. consume(_CONST);
  354. varspez:=vs_const;
  355. end
  356. else varspez:=vs_value;
  357. sc:=idlist;
  358. if token=COLON then
  359. begin
  360. consume(COLON);
  361. if token=_ARRAY then
  362. begin
  363. if (varspez<>vs_const) and
  364. (varspez<>vs_var) then
  365. begin
  366. varspez:=vs_const;
  367. Message(parser_e_illegal_open_parameter);
  368. end;
  369. consume(_ARRAY);
  370. consume(_OF);
  371. { define range and type of range }
  372. hp:=new(parraydef,init(0,-1,s32bitdef));
  373. { define field type }
  374. parraydef(hp)^.definition:=single_type(s);
  375. end
  376. else
  377. hp:=single_type(s);
  378. end
  379. else
  380. hp:=new(pformaldef,init);
  381. s:=sc^.get;
  382. while s<>'' do
  383. begin
  384. new(hp2);
  385. hp2^.paratyp:=varspez;
  386. hp2^.data:=hp;
  387. hp2^.next:=propertyparas;
  388. propertyparas:=hp2;
  389. s:=sc^.get;
  390. end;
  391. dispose(sc,done);
  392. if token=SEMICOLON then consume(SEMICOLON)
  393. else break;
  394. until false;
  395. dec(testcurobject);
  396. consume(RECKKLAMMER);
  397. end;
  398. { overriden property ? }
  399. { force property interface, if there is a property parameter }
  400. if (token=COLON) or assigned(propertyparas) then
  401. begin
  402. consume(COLON);
  403. p^.proptype:=single_type(hs);
  404. if (token=ID) and (pattern='INDEX') then
  405. begin
  406. consume(ID);
  407. p^.options:=p^.options or ppo_indexed;
  408. if token=INTCONST then
  409. val(pattern,p^.index,code);
  410. consume(INTCONST);
  411. { concat a longint to the para template }
  412. new(hp2);
  413. hp2^.paratyp:=vs_value;
  414. hp2^.data:=s32bitdef;
  415. hp2^.next:=propertyparas;
  416. propertyparas:=hp2;
  417. end;
  418. end
  419. else
  420. begin
  421. { do an property override }
  422. overriden:=search_class_member(aktclass,pattern);
  423. if assigned(overriden) and (overriden^.typ=propertysym) then
  424. begin
  425. { take the whole info: }
  426. p^.options:=ppropertysym(overriden)^.options;
  427. p^.index:=ppropertysym(overriden)^.index;
  428. p^.writeaccesssym:=ppropertysym(overriden)^.writeaccesssym;
  429. p^.readaccesssym:=ppropertysym(overriden)^.readaccesssym;
  430. end
  431. else
  432. begin
  433. p^.proptype:=generrordef;
  434. message(parser_e_no_property_found_to_override);
  435. end;
  436. end;
  437. if (token=ID) and (pattern='READ') then
  438. begin
  439. consume(ID);
  440. sym:=search_class_member(aktclass,pattern);
  441. if not(assigned(sym)) then
  442. Message1(sym_e_unknown_id,pattern)
  443. else
  444. begin
  445. { !!!! check sym }
  446. { varsym aren't allowed for an indexed property
  447. or an property with parameters }
  448. if ((sym^.typ=varsym) and
  449. (((p^.options and ppo_indexed)<>0) or
  450. assigned(propertyparas))) or
  451. not(sym^.typ in [varsym,procsym]) then
  452. Message(parser_e_ill_property_access_sym);
  453. { search the matching definition }
  454. if sym^.typ=procsym then
  455. begin
  456. { !!!!!! }
  457. end;
  458. p^.readaccesssym:=sym;
  459. end;
  460. consume(ID);
  461. end;
  462. if (token=ID) and (pattern='WRITE') then
  463. begin
  464. consume(ID);
  465. sym:=search_class_member(aktclass,pattern);
  466. if not(assigned(sym)) then
  467. Message1(sym_e_unknown_id,pattern)
  468. else
  469. begin
  470. { !!!! check sym }
  471. if ((sym^.typ=varsym) and
  472. (((p^.options and ppo_indexed)<>0)
  473. { or property paras })) or
  474. not(sym^.typ in [varsym,procsym]) then
  475. Message(parser_e_ill_property_access_sym);
  476. { search the matching definition }
  477. if sym^.typ=procsym then
  478. begin
  479. { !!!!!! }
  480. end;
  481. p^.writeaccesssym:=sym;
  482. end;
  483. consume(ID);
  484. end;
  485. if (token=ID) and (pattern='STORED') then
  486. begin
  487. consume(ID);
  488. { !!!!!!!! }
  489. end;
  490. if (token=ID) and (pattern='DEFAULT') then
  491. begin
  492. consume(ID);
  493. if token=SEMICOLON then
  494. begin
  495. p2:=search_default_property(aktclass);
  496. if assigned(p2) then
  497. message1(parser_e_only_one_default_property,
  498. pobjectdef(p2^.owner^.defowner)^.name^)
  499. else
  500. begin
  501. p^.options:=p^.options and ppo_defaultproperty;
  502. if not(assigned(propertyparas)) then
  503. message(parser_e_property_need_paras);
  504. end;
  505. end
  506. else
  507. begin
  508. { !!!!!!! storage }
  509. end;
  510. consume(SEMICOLON);
  511. end
  512. else if (token=ID) and (pattern='NODEFAULT') then
  513. begin
  514. consume(ID);
  515. { !!!!!!!! }
  516. end;
  517. symtablestack^.insert(p);
  518. { clean up }
  519. if assigned(datacoll) then
  520. dispose(datacoll);
  521. end
  522. else
  523. consume(ID);
  524. consume(SEMICOLON);
  525. end;
  526. procedure destructor_head;
  527. begin
  528. consume(_DESTRUCTOR);
  529. if (cs_checkconsname in aktswitches) and (aktprocsym^.name<>'DONE') then
  530. Message(parser_e_destructorname_must_be_done);
  531. _proc_head(podestructor);
  532. consume(SEMICOLON);
  533. if assigned(aktprocsym^.definition^.para1) then
  534. Message(parser_e_no_paras_for_destructor);
  535. { no return value }
  536. aktprocsym^.definition^.retdef:=voiddef;
  537. end;
  538. procedure object_komponenten;
  539. var
  540. oldparse_only : boolean;
  541. begin
  542. repeat
  543. case token of
  544. ID:
  545. begin
  546. if (pattern='PUBLIC') or
  547. (pattern='PUBLISHED') or
  548. (pattern='PROTECTED') or
  549. (pattern='PRIVATE') then
  550. exit;
  551. read_var_decs(false,false);
  552. end;
  553. _PROPERTY:
  554. property_dec;
  555. _PROCEDURE,_FUNCTION,_CLASS:
  556. begin
  557. oldparse_only:=parse_only;
  558. parse_only:=true;
  559. proc_head;
  560. parse_only:=oldparse_only;
  561. if (token=ID) and
  562. ((pattern='VIRTUAL') or (pattern='DYNAMIC')) then
  563. begin
  564. if actmembertype=sp_private then
  565. Message(parser_w_priv_meth_not_virtual);
  566. consume(ID);
  567. consume(SEMICOLON);
  568. aktprocsym^.definition^.options:=
  569. aktprocsym^.definition^.options or povirtualmethod;
  570. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  571. end
  572. else if (token=ID) and (pattern='OVERRIDE') then
  573. begin
  574. consume(ID);
  575. consume(SEMICOLON);
  576. aktprocsym^.definition^.options:=
  577. aktprocsym^.definition^.options or pooverridingmethod or povirtualmethod;
  578. end;
  579. { Delphi II extension }
  580. if (token=ID) and (pattern='ABSTRACT') then
  581. begin
  582. consume(ID);
  583. consume(SEMICOLON);
  584. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  585. begin
  586. aktprocsym^.definition^.options:=
  587. aktprocsym^.definition^.options or
  588. poabstractmethod;
  589. end
  590. else
  591. Message(parser_e_only_virtual_methods_abstract);
  592. { the method is defined }
  593. aktprocsym^.definition^.forwarddef:=false;
  594. end;
  595. if (token=ID) and (pattern='STATIC') and
  596. (cs_static_keyword in aktswitches) then
  597. begin
  598. consume(ID);
  599. consume(SEMICOLON);
  600. aktprocsym^.properties:=
  601. aktprocsym^.properties or
  602. sp_static;
  603. aktprocsym^.definition^.options:=
  604. aktprocsym^.definition^.options or
  605. postaticmethod;
  606. end;
  607. end;
  608. _CONSTRUCTOR:
  609. begin
  610. if actmembertype<>sp_public then
  611. Message(parser_e_constructor_cannot_be_private);
  612. oldparse_only:=parse_only;
  613. parse_only:=true;
  614. constructor_head;
  615. parse_only:=oldparse_only;
  616. end;
  617. _DESTRUCTOR:
  618. begin
  619. if there_is_a_destructor then
  620. Message(parser_n_only_one_destructor);
  621. there_is_a_destructor:=true;
  622. if actmembertype<>sp_public then
  623. Message(parser_e_destructor_cannot_be_private);
  624. oldparse_only:=parse_only;
  625. parse_only:=true;
  626. destructor_head;
  627. parse_only:=oldparse_only;
  628. if (token=ID) and
  629. ((pattern='VIRTUAL') or (pattern='DYNAMIC')) then
  630. begin
  631. consume(ID);
  632. consume(SEMICOLON);
  633. aktprocsym^.definition^.options:=
  634. aktprocsym^.definition^.options or povirtualmethod;
  635. end
  636. else if (token=ID) and (pattern='OVERRIDE') then
  637. begin
  638. consume(ID);
  639. consume(SEMICOLON);
  640. aktprocsym^.definition^.options:=
  641. aktprocsym^.definition^.options or pooverridingmethod or povirtualmethod;
  642. end;
  643. end;
  644. _END : exit;
  645. else Message(parser_e_syntax_error);
  646. end;
  647. until false;
  648. end;
  649. var
  650. hs : string;
  651. pcrd : pclassrefdef;
  652. hp1 : pdef;
  653. oldprocsym:Pprocsym;
  654. begin
  655. {Nowadays aktprocsym may already have a value, so we need to save
  656. it.}
  657. oldprocsym:=aktprocsym;
  658. { forward is resolved }
  659. if assigned(fd) then
  660. fd^.options:=fd^.options and not(oo_isforward);
  661. there_is_a_destructor:=false;
  662. actmembertype:=sp_public;
  663. { objects and class types can't be declared local }
  664. if (symtablestack^.symtabletype<>globalsymtable) and
  665. (symtablestack^.symtabletype<>staticsymtable) then
  666. Message(parser_e_no_local_objects);
  667. { distinguish classes and objects }
  668. if token=_OBJECT then
  669. begin
  670. is_a_class:=false;
  671. consume(_OBJECT)
  672. end
  673. else
  674. begin
  675. is_a_class:=true;
  676. consume(_CLASS);
  677. if not(assigned(fd)) and (token=_OF) then
  678. begin
  679. { a hack, but it's easy to handle }
  680. { class reference type }
  681. consume(_OF);
  682. if typecanbeforward then
  683. forwardsallowed:=true;
  684. hp1:=single_type(hs);
  685. { accept hp1, if is a forward def ...}
  686. if ((lasttypesym<>nil)
  687. and ((lasttypesym^.properties and sp_forwarddef)<>0)) or
  688. { or a class
  689. (if the foward defined type is a class is checked, when
  690. the forward is resolved)
  691. }
  692. ((hp1^.deftype=objectdef) and (
  693. (pobjectdef(hp1)^.options and oois_class)<>0)) then
  694. begin
  695. pcrd:=new(pclassrefdef,init(hp1));
  696. object_dec:=pcrd;
  697. {I add big troubles here
  698. with var p : ^byte in graph.putimage
  699. because a save_forward was called and
  700. no resolve forward
  701. => so the definition was rewritten after
  702. having been disposed !!
  703. Strange problems appeared !!!!}
  704. {Anyhow forwards should only be allowed
  705. inside a type statement ??
  706. don't you think so }
  707. if (lasttypesym<>nil)
  708. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  709. lasttypesym^.forwardpointer:=ppointerdef(pcrd);
  710. forwardsallowed:=false;
  711. end
  712. else
  713. begin
  714. Message(parser_e_class_type_expected);
  715. object_dec:=new(perrordef,init);
  716. end;
  717. exit;
  718. end
  719. { forward class }
  720. else if not(assigned(fd)) and (token=SEMICOLON) then
  721. begin
  722. { also anonym objects aren't allow (o : object a : longint; end;) }
  723. if n='' then
  724. Message(parser_e_no_anonym_objects);
  725. if n='TOBJECT' then
  726. begin
  727. aktclass:=new(pobjectdef,init(n,nil));
  728. class_tobject:=aktclass;
  729. end
  730. else
  731. aktclass:=new(pobjectdef,init(n,class_tobject));
  732. aktclass^.options:=aktclass^.options or oois_class or oo_isforward;
  733. object_dec:=aktclass;
  734. exit;
  735. end;
  736. end;
  737. { also anonym objects aren't allow (o : object a : longint; end;) }
  738. if n='' then
  739. Message(parser_e_no_anonym_objects);
  740. { read the parent class }
  741. if token=LKLAMMER then
  742. begin
  743. consume(LKLAMMER);
  744. { does not allow objects.tobject !! }
  745. {if token<>ID then
  746. consume(ID);
  747. getsym(pattern,true);}
  748. childof:=pobjectdef(id_type(pattern));
  749. if (childof^.deftype<>objectdef) then
  750. begin
  751. Message(parser_e_class_type_expected);
  752. childof:=nil;
  753. end;
  754. { a mix of class and object isn't allowed }
  755. if (((childof^.options and oois_class)<>0) and not is_a_class) or
  756. (((childof^.options and oois_class)=0) and is_a_class) then
  757. Message(parser_e_mix_of_classes_and_objects);
  758. consume(RKLAMMER);
  759. if assigned(fd) then
  760. begin
  761. fd^.childof:=childof;
  762. aktclass:=fd;
  763. end
  764. else
  765. aktclass:=new(pobjectdef,init(n,childof));
  766. end
  767. { if no parent class, then a class get tobject as parent }
  768. else if is_a_class then
  769. begin
  770. { is the current class tobject? }
  771. { so you could define your own tobject }
  772. if n='TOBJECT' then
  773. begin
  774. if assigned(fd) then
  775. aktclass:=fd
  776. else
  777. aktclass:=new(pobjectdef,init(n,nil));
  778. class_tobject:=aktclass;
  779. end
  780. else
  781. begin
  782. childof:=class_tobject;
  783. if assigned(fd) then
  784. begin
  785. aktclass:=fd;
  786. aktclass^.childof:=childof;
  787. end
  788. else
  789. aktclass:=new(pobjectdef,init(n,childof));
  790. end;
  791. end
  792. else aktclass:=new(pobjectdef,init(n,nil));
  793. { set the class attribute }
  794. if is_a_class then
  795. aktclass^.options:=aktclass^.options or oois_class;
  796. aktobjectdef:=aktclass;
  797. { default access is public }
  798. actmembertype:=sp_public;
  799. aktclass^.publicsyms^.next:=symtablestack;
  800. symtablestack:=aktclass^.publicsyms;
  801. procinfo._class:=aktclass;
  802. testcurobject:=1;
  803. curobjectname:=n;
  804. while token<>_END do
  805. begin
  806. if (token=ID) and (pattern='PRIVATE') then
  807. begin
  808. consume(ID);
  809. actmembertype:=sp_private;
  810. current_object_option:=sp_private;
  811. end;
  812. if (token=ID) and (pattern='PROTECTED') then
  813. begin
  814. consume(ID);
  815. current_object_option:=sp_protected;
  816. actmembertype:=sp_protected;
  817. end;
  818. if (token=ID) and (pattern='PUBLIC') then
  819. begin
  820. consume(ID);
  821. current_object_option:=sp_public;
  822. actmembertype:=sp_public;
  823. end;
  824. if (token=ID) and (pattern='PUBLISHED') then
  825. begin
  826. consume(ID);
  827. current_object_option:=sp_public;
  828. actmembertype:=sp_public;
  829. end;
  830. object_komponenten;
  831. end;
  832. current_object_option:=sp_public;
  833. consume(_END);
  834. testcurobject:=0;
  835. curobjectname:='';
  836. {$ifdef MAKELIB}
  837. datasegment^.concat(new(pai_cut,init));
  838. {$endif MAKELIB}
  839. {$ifdef GDB}
  840. { generate the VMT }
  841. if cs_debuginfo in aktswitches then
  842. begin
  843. do_count_dbx:=true;
  844. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  845. debuglist^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  846. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  847. end;
  848. {$endif * GDB *}
  849. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  850. { determine the size with publicsyms^.datasize, because }
  851. { size gives back 4 for CLASSes }
  852. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  853. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  854. { write pointer to parent VMT, this isn't implemented in TP }
  855. { but this is not used in FPC ? (PM) }
  856. { it's not used yet, but the delphi-operators as and is need it (FK) }
  857. if assigned(aktclass^.childof) then
  858. begin
  859. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  860. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  861. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  862. end
  863. else
  864. datasegment^.concat(new(pai_const,init_32bit(0)));
  865. { this generates the entries }
  866. genvmt(aktclass);
  867. { restore old state }
  868. symtablestack:=symtablestack^.next;
  869. procinfo._class:=nil;
  870. {Restore the aktprocsym.}
  871. aktprocsym:=oldprocsym;
  872. object_dec:=aktclass;
  873. end;
  874. { reads a record declaration }
  875. function record_dec : pdef;
  876. var
  877. symtable : psymtable;
  878. begin
  879. symtable:=new(psymtable,init(recordsymtable));
  880. symtable^.next:=symtablestack;
  881. symtablestack:=symtable;
  882. consume(_RECORD);
  883. read_var_decs(true,false);
  884. { may be scale record size to a size of n*4 ? }
  885. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  886. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  887. consume(_END);
  888. symtablestack:=symtable^.next;
  889. record_dec:=new(precdef,init(symtable));
  890. end;
  891. { reads a type definition and returns a pointer to it }
  892. function read_type(const name : stringid) : pdef;
  893. function handle_procvar:Pprocvardef;
  894. var
  895. sc : pstringcontainer;
  896. s : string;
  897. p : pdef;
  898. varspez : tvarspez;
  899. procvardef : pprocvardef;
  900. begin
  901. procvardef:=new(pprocvardef,init);
  902. if token=LKLAMMER then
  903. begin
  904. consume(LKLAMMER);
  905. inc(testcurobject);
  906. repeat
  907. if token=_VAR then
  908. begin
  909. consume(_VAR);
  910. varspez:=vs_var;
  911. end
  912. else if token=_CONST then
  913. begin
  914. consume(_CONST);
  915. varspez:=vs_const;
  916. end
  917. else varspez:=vs_value;
  918. sc:=idlist;
  919. if token=COLON then
  920. begin
  921. consume(COLON);
  922. if token=_ARRAY then
  923. begin
  924. if (varspez<>vs_const) and
  925. (varspez<>vs_var) then
  926. begin
  927. varspez:=vs_const;
  928. Message(parser_e_illegal_open_parameter);
  929. end;
  930. consume(_ARRAY);
  931. consume(_OF);
  932. { define range and type of range }
  933. p:=new(parraydef,init(0,-1,s32bitdef));
  934. { define field type }
  935. parraydef(p)^.definition:=single_type(s);
  936. end
  937. else
  938. p:=single_type(s);
  939. end
  940. else
  941. p:=new(pformaldef,init);
  942. s:=sc^.get;
  943. while s<>'' do
  944. begin
  945. procvardef^.concatdef(p,varspez);
  946. s:=sc^.get;
  947. end;
  948. dispose(sc,done);
  949. if token=SEMICOLON then consume(SEMICOLON)
  950. else break;
  951. until false;
  952. dec(testcurobject);
  953. consume(RKLAMMER);
  954. end;
  955. handle_procvar:=procvardef;
  956. end;
  957. var
  958. hp1,p : pdef;
  959. pt : ptree;
  960. aufdef : penumdef;
  961. aufsym : penumsym;
  962. ap : parraydef;
  963. s : stringid;
  964. l,v,oldaktpackrecords : longint;
  965. hs : string;
  966. procedure range_type;
  967. begin
  968. { it can be only a range type }
  969. pt:=expr;
  970. do_firstpass(pt);
  971. { valid expression ? }
  972. if (pt^.treetype<>rangen) or
  973. (pt^.left^.treetype<>ordconstn) then
  974. Begin
  975. Message(sym_e_error_in_type_def);
  976. { Here we create a node type with a range of 0 }
  977. { To make sure that no crashes will occur later }
  978. { on in the compiler. }
  979. p:=new(porddef,init(uauto,0,0));
  980. end
  981. else
  982. p:=new(porddef,init(uauto,pt^.left^.value,pt^.right^.value));
  983. disposetree(pt);
  984. end;
  985. begin
  986. case token of
  987. ID,_STRING,_FILE:
  988. p:=single_type(hs);
  989. LKLAMMER:
  990. begin
  991. consume(LKLAMMER);
  992. l:=-1;
  993. aufsym := Nil;
  994. aufdef:=new(penumdef,init);
  995. repeat
  996. s:=pattern;
  997. consume(ID);
  998. if token=ASSIGNMENT then
  999. begin
  1000. consume(ASSIGNMENT);
  1001. v:=get_intconst;
  1002. { please leave that a note, allows type save }
  1003. { declarations in the win32 units ! }
  1004. if v<=l then
  1005. Message(parser_n_duplicate_enum);
  1006. l:=v;
  1007. end
  1008. else
  1009. inc(l);
  1010. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1011. if token=COMMA then
  1012. consume(COMMA)
  1013. else
  1014. break;
  1015. until false;
  1016. aufdef^.max:=l;
  1017. p:=aufdef;
  1018. consume(RKLAMMER);
  1019. end;
  1020. _ARRAY:
  1021. begin
  1022. consume(_ARRAY);
  1023. consume(LECKKLAMMER);
  1024. p:=nil;
  1025. repeat
  1026. { read the expression and check it }
  1027. pt:=expr;
  1028. if pt^.treetype=typen then
  1029. begin
  1030. if pt^.resulttype^.deftype=enumdef then
  1031. begin
  1032. if p=nil then
  1033. begin
  1034. ap:=new(parraydef,
  1035. init(0,penumdef(pt^.resulttype)^.max,pt^.resulttype));
  1036. p:=ap;
  1037. end
  1038. else
  1039. begin
  1040. ap^.definition:=new(parraydef,
  1041. init(0,penumdef(pt^.resulttype)^.max,pt^.resulttype));
  1042. ap:=parraydef(ap^.definition);
  1043. end;
  1044. end
  1045. else if pt^.resulttype^.deftype=orddef then
  1046. begin
  1047. case porddef(pt^.resulttype)^.typ of
  1048. s8bit,u8bit,s16bit,u16bit,s32bit :
  1049. begin
  1050. if p=nil then
  1051. begin
  1052. ap:=new(parraydef,init(porddef(pt^.resulttype)^.von,
  1053. porddef(pt^.resulttype)^.bis,pt^.resulttype));
  1054. p:=ap;
  1055. end
  1056. else
  1057. begin
  1058. ap^.definition:=new(parraydef,init(porddef(pt^.resulttype)^.von,
  1059. porddef(pt^.resulttype)^.bis,pt^.resulttype));
  1060. ap:=parraydef(ap^.definition);
  1061. end;
  1062. end;
  1063. bool8bit:
  1064. begin
  1065. if p=nil then
  1066. begin
  1067. ap:=new(parraydef,init(0,1,pt^.resulttype));
  1068. p:=ap;
  1069. end
  1070. else
  1071. begin
  1072. ap^.definition:=new(parraydef,init(0,1,pt^.resulttype));
  1073. ap:=parraydef(ap^.definition);
  1074. end;
  1075. end;
  1076. uchar:
  1077. begin
  1078. if p=nil then
  1079. begin
  1080. ap:=new(parraydef,init(0,255,pt^.resulttype));
  1081. p:=ap;
  1082. end
  1083. else
  1084. begin
  1085. ap^.definition:=new(parraydef,init(0,255,pt^.resulttype));
  1086. ap:=parraydef(ap^.definition);
  1087. end;
  1088. end;
  1089. else Message(sym_e_error_in_type_def);
  1090. end;
  1091. end
  1092. else Message(sym_e_error_in_type_def);
  1093. end
  1094. else
  1095. begin
  1096. do_firstpass(pt);
  1097. if (pt^.treetype<>rangen) or
  1098. (pt^.left^.treetype<>ordconstn) then
  1099. Message(sym_e_error_in_type_def);
  1100. { Registrierung der Grenzen erzwingen: }
  1101. {$IfNdef GDB}
  1102. if pt^.right^.resulttype=pdef(s32bitdef) then
  1103. pt^.right^.resulttype:=new(porddef,init(
  1104. s32bit,$80000000,$7fffffff));
  1105. {$EndIf GDB}
  1106. if p=nil then
  1107. begin
  1108. ap:=new(parraydef,init(pt^.left^.value,pt^.right^.value,pt^.right^.resulttype));
  1109. p:=ap;
  1110. end
  1111. else
  1112. begin
  1113. ap^.definition:=new(parraydef,init(pt^.left^.value,pt^.right^.value,pt^.right^.resulttype));
  1114. ap:=parraydef(ap^.definition);
  1115. end;
  1116. end;
  1117. disposetree(pt);
  1118. if token=COMMA then consume(COMMA)
  1119. else break;
  1120. until false;
  1121. consume(RECKKLAMMER);
  1122. consume(_OF);
  1123. hp1:=read_type('');
  1124. { if no error, set element type }
  1125. if assigned(ap) then
  1126. ap^.definition:=hp1;
  1127. end;
  1128. _SET:
  1129. begin
  1130. consume(_SET);
  1131. consume(_OF);
  1132. hp1:=read_type('');
  1133. case hp1^.deftype of
  1134. enumdef : p:=new(psetdef,init(hp1,penumdef(hp1)^.max));
  1135. orddef : begin
  1136. case porddef(hp1)^.typ of
  1137. uchar : p:=new(psetdef,init(hp1,255));
  1138. u8bit,s8bit,u16bit,s16bit,s32bit :
  1139. begin
  1140. if (porddef(hp1)^.von>=0) then
  1141. p:=new(psetdef,init(hp1,porddef(hp1)^.bis))
  1142. else Message(sym_e_ill_type_decl_set);
  1143. end;
  1144. else Message(sym_e_ill_type_decl_set);
  1145. end;
  1146. end;
  1147. else Message(sym_e_ill_type_decl_set);
  1148. end;
  1149. end;
  1150. CARET:
  1151. begin
  1152. consume(CARET);
  1153. { forwards allowed only inside TYPE statements }
  1154. if typecanbeforward then
  1155. forwardsallowed:=true;
  1156. hp1:=single_type(hs);
  1157. p:=new(ppointerdef,init(hp1));
  1158. {$ifndef GDB}
  1159. if lasttypesym<>nil then
  1160. save_forward(ppointerdef(p),lasttypesym);
  1161. {$else * GDB *}
  1162. {I add big troubles here
  1163. with var p : ^byte in graph.putimage
  1164. because a save_forward was called and
  1165. no resolve forward
  1166. => so the definition was rewritten after
  1167. having been disposed !!
  1168. Strange problems appeared !!!!}
  1169. {Anyhow forwards should only be allowed
  1170. inside a type statement ??
  1171. don't you think so }
  1172. if (lasttypesym<>nil)
  1173. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1174. lasttypesym^.forwardpointer:=ppointerdef(p);
  1175. {$endif * GDB *}
  1176. forwardsallowed:=false;
  1177. end;
  1178. _RECORD:
  1179. p:=record_dec;
  1180. _PACKED:
  1181. begin
  1182. consume(_PACKED);
  1183. oldaktpackrecords:=aktpackrecords;
  1184. aktpackrecords:=1;
  1185. p:=record_dec;
  1186. aktpackrecords:=oldaktpackrecords;
  1187. end;
  1188. _CLASS,
  1189. _OBJECT:
  1190. p:=object_dec(name,nil);
  1191. _PROCEDURE:
  1192. begin
  1193. consume(_PROCEDURE);
  1194. p:=handle_procvar;
  1195. end;
  1196. _FUNCTION:
  1197. begin
  1198. consume(_FUNCTION);
  1199. p:=handle_procvar;
  1200. consume(COLON);
  1201. pprocvardef(p)^.retdef:=single_type(hs);
  1202. end;
  1203. else
  1204. range_type;
  1205. end;
  1206. read_type:=p;
  1207. end;
  1208. { search in symtablestack used, but not defined type }
  1209. procedure testforward_types(p : psym);{$ifndef FPC}far;{$endif}
  1210. begin
  1211. if (p^.typ=typesym) and ((p^.properties and sp_forwarddef)<>0) then
  1212. Message(sym_e_type_id_not_defined);
  1213. end;
  1214. { reads a type declaration to the symbol table }
  1215. procedure type_dec;
  1216. var
  1217. typename : stringid;
  1218. {$ifdef dummy}
  1219. olddef,newdef : pdef;
  1220. s : string;
  1221. {$endif dummy}
  1222. begin
  1223. parse_types:=true;
  1224. consume(_TYPE);
  1225. typecanbeforward:=true;
  1226. repeat
  1227. typename:=pattern;
  1228. consume(ID);
  1229. consume(EQUAL);
  1230. { here you loose the strictness of pascal
  1231. for which a redefinition like
  1232. childtype = parenttype;
  1233. child2type = parenttype;
  1234. does not make the two child types equal !!
  1235. here all vars from childtype and child2type
  1236. get the definition of parenttype !! }
  1237. {$ifdef testequaltype}
  1238. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1239. begin
  1240. olddef := single_type(s);
  1241. { make a clone of olddef }
  1242. { is that ok ??? }
  1243. getmem(newdef,SizeOf(olddef));
  1244. move(olddef^,newdef^,SizeOf(olddef));
  1245. symtablestack^.insert(new(ptypesym,init(typename,newdef)));
  1246. end
  1247. else
  1248. {$endif testequaltype}
  1249. begin
  1250. getsym(typename,false);
  1251. { check if it is the definition of a forward defined class }
  1252. if assigned(srsym) and (token=_CLASS) and
  1253. (srsym^.typ=typesym) and
  1254. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1255. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1256. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oois_class)<>0) then
  1257. begin
  1258. { we can ignore the result }
  1259. { the definition is modified }
  1260. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1261. end
  1262. else
  1263. symtablestack^.insert(new(ptypesym,init(typename,read_type(typename))));
  1264. end;
  1265. consume(SEMICOLON);
  1266. until token<>ID;
  1267. typecanbeforward:=false;
  1268. {$ifdef tp}
  1269. symtablestack^.foreach(testforward_types);
  1270. {$else}
  1271. symtablestack^.foreach(@testforward_types);
  1272. {$endif}
  1273. resolve_forwards;
  1274. parse_types:=false;
  1275. end;
  1276. { parses varaible declarations and inserts them in }
  1277. { the top symbol table of symtablestack }
  1278. procedure var_dec;
  1279. {var
  1280. p : pdef;
  1281. sc : pstringcontainer; }
  1282. begin
  1283. consume(_VAR);
  1284. read_var_decs(false,true);
  1285. end;
  1286. { reads the filed of a record into a }
  1287. { symtablestack, if record=false }
  1288. { variants are forbidden, so this procedure }
  1289. { can be used to read object fields }
  1290. { if absolute is true, ABSOLUTE and file }
  1291. { types are allowed }
  1292. { => the procedure is also used to read }
  1293. { a sequence of variable declaration }
  1294. procedure read_var_decs(is_record : boolean;do_absolute : boolean);
  1295. var
  1296. sc : pstringcontainer;
  1297. s : stringid;
  1298. l : longint;
  1299. code : word;
  1300. hs : string;
  1301. p,casedef : pdef;
  1302. { maxsize contains the max. size of a variant }
  1303. { startvarrec contains the start of the variant part of a record }
  1304. maxsize,startvarrec : longint;
  1305. pt : ptree;
  1306. old_parse_types : boolean;
  1307. { to handle absolute }
  1308. abssym : pabsolutesym;
  1309. begin
  1310. hs:='';
  1311. old_parse_types:=parse_types;
  1312. parse_types:=true;
  1313. while (token=ID) and
  1314. (pattern<>'PUBLIC') and
  1315. (pattern<>'PRIVATE') and
  1316. (pattern<>'PUBLISHED') and
  1317. (pattern<>'PROTECTED') do
  1318. begin
  1319. sc:=idlist;
  1320. consume(COLON);
  1321. p:=read_type('');
  1322. if do_absolute and (token=ID) and (pattern='ABSOLUTE') then
  1323. begin
  1324. s:=sc^.get;
  1325. if sc^.get<>'' then
  1326. Message(parser_e_absolute_only_one_var);
  1327. dispose(sc,done);
  1328. consume(ID);
  1329. if token=ID then
  1330. begin
  1331. getsym(pattern,true);
  1332. consume(ID);
  1333. { we should check the result type of srsym }
  1334. if not (srsym^.typ in [varsym,typedconstsym]) then
  1335. Message(parser_e_absolute_only_to_var_or_const);
  1336. abssym:=new(pabsolutesym,init(s,p));
  1337. abssym^.typ:=absolutesym;
  1338. abssym^.abstyp:=tovar;
  1339. abssym^.ref:=srsym;
  1340. symtablestack^.insert(abssym);
  1341. end
  1342. else
  1343. if token=CSTRING then
  1344. begin
  1345. abssym:=new(pabsolutesym,init(s,p));
  1346. s:=pattern;
  1347. consume(CSTRING);
  1348. abssym^.typ:=absolutesym;
  1349. abssym^.abstyp:=toasm;
  1350. abssym^.asmname:=stringdup(s);
  1351. symtablestack^.insert(abssym);
  1352. end
  1353. else
  1354. { absolute address ?!? }
  1355. if token=INTCONST then
  1356. begin
  1357. if (target_info.target=target_GO32V2) then
  1358. begin
  1359. abssym:=new(pabsolutesym,init(s,p));
  1360. abssym^.typ:=absolutesym;
  1361. abssym^.abstyp:=toaddr;
  1362. abssym^.absseg:=false;
  1363. s:=pattern;
  1364. consume(INTCONST);
  1365. val(s,abssym^.address,code);
  1366. if token=COLON then
  1367. begin
  1368. consume(token);
  1369. s:=pattern;
  1370. consume(INTCONST);
  1371. val(s,l,code);
  1372. abssym^.address:=abssym^.address shl 4+l;
  1373. abssym^.absseg:=true;
  1374. end;
  1375. symtablestack^.insert(abssym);
  1376. end
  1377. else
  1378. Message(parser_e_absolute_only_to_var_or_const);
  1379. end
  1380. else
  1381. Message(parser_e_absolute_only_to_var_or_const);
  1382. end
  1383. else
  1384. begin
  1385. if token=SEMICOLON then
  1386. begin
  1387. if (symtablestack^.symtabletype=objectsymtable) then
  1388. begin
  1389. consume(SEMICOLON);
  1390. if (token=ID) and (pattern='STATIC') and
  1391. (cs_static_keyword in aktswitches) then
  1392. begin
  1393. current_object_option:=current_object_option or sp_static;
  1394. insert_syms(symtablestack,sc,p);
  1395. current_object_option:=current_object_option - sp_static;
  1396. consume(ID);
  1397. consume(SEMICOLON);
  1398. end
  1399. else
  1400. { this will still be a the wrong line !! }
  1401. insert_syms(symtablestack,sc,p);
  1402. end
  1403. else
  1404. begin
  1405. { at the right line }
  1406. insert_syms(symtablestack,sc,p);
  1407. consume(SEMICOLON);
  1408. end
  1409. end
  1410. else
  1411. begin
  1412. insert_syms(symtablestack,sc,p);
  1413. if not(is_record) then
  1414. consume(SEMICOLON);
  1415. end;
  1416. end;
  1417. while token=SEMICOLON do
  1418. consume(SEMICOLON);
  1419. end;
  1420. if (token=_CASE) and is_record then
  1421. begin
  1422. maxsize:=0;
  1423. consume(_CASE);
  1424. s:=pattern;
  1425. getsym(s,false);
  1426. { may be only a type: }
  1427. if assigned(srsym) and ((srsym^.typ=typesym) or
  1428. { and with unit qualifier: }
  1429. (srsym^.typ=unitsym)) then
  1430. begin
  1431. casedef:=read_type('');
  1432. end
  1433. else
  1434. begin
  1435. consume(ID);
  1436. consume(COLON);
  1437. casedef:=read_type('');
  1438. symtablestack^.insert(new(pvarsym,init(s,casedef)));
  1439. end;
  1440. if not is_ordinal(casedef) then
  1441. Message(parser_e_ordinal_expected);
  1442. consume(_OF);
  1443. startvarrec:=symtablestack^.datasize;
  1444. repeat
  1445. repeat
  1446. pt:=expr;
  1447. do_firstpass(pt);
  1448. if not(pt^.treetype=ordconstn) then
  1449. Message(cg_e_illegal_expression);
  1450. disposetree(pt);
  1451. if token=COMMA then consume(COMMA)
  1452. else break;
  1453. until false;
  1454. consume(COLON);
  1455. consume(LKLAMMER);
  1456. if token<>RKLAMMER then
  1457. read_var_decs(true,false);
  1458. { calculates maximal variant size }
  1459. maxsize:=max(maxsize,symtablestack^.datasize);
  1460. { the items of the next variant are overlayed }
  1461. symtablestack^.datasize:=startvarrec;
  1462. consume(RKLAMMER);
  1463. if token<>SEMICOLON then
  1464. break
  1465. else
  1466. consume(SEMICOLON);
  1467. while token=SEMICOLON do
  1468. consume(SEMICOLON);
  1469. until (token=_END) or (token=RKLAMMER);
  1470. { at last set the record size to that of the biggest variant }
  1471. symtablestack^.datasize:=maxsize;
  1472. end;
  1473. parse_types:=old_parse_types;
  1474. end;
  1475. procedure read_declarations(islibrary : boolean);
  1476. begin
  1477. repeat
  1478. case token of
  1479. _LABEL : label_dec;
  1480. _CONST : const_dec;
  1481. _TYPE : type_dec;
  1482. _VAR : var_dec;
  1483. _CONSTRUCTOR,_DESTRUCTOR,
  1484. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS : unter_dec;
  1485. _EXPORTS : if islibrary then
  1486. read_exports
  1487. else
  1488. break;
  1489. else break;
  1490. end;
  1491. until false;
  1492. end;
  1493. procedure read_interface_declarations;
  1494. begin
  1495. {Since the body is now parsed at lexlevel 1, and the declarations
  1496. must be parsed at the same lexlevel we increase the lexlevel.}
  1497. inc(lexlevel);
  1498. repeat
  1499. case token of
  1500. _CONST : const_dec;
  1501. _TYPE : type_dec;
  1502. _VAR : var_dec;
  1503. { should we allow operator in interface ? }
  1504. { of course otherwise you cannot }
  1505. { declare an operator usable by other }
  1506. { units or progs PM }
  1507. _FUNCTION,_PROCEDURE,_OPERATOR : unter_dec;
  1508. else
  1509. break;
  1510. end;
  1511. until false;
  1512. dec(lexlevel);
  1513. end;
  1514. end.
  1515. {
  1516. $Log$
  1517. Revision 1.1 1998-03-25 11:18:14 root
  1518. Initial revision
  1519. Revision 1.31 1998/03/24 21:48:33 florian
  1520. * just a couple of fixes applied:
  1521. - problem with fixed16 solved
  1522. - internalerror 10005 problem fixed
  1523. - patch for assembler reading
  1524. - small optimizer fix
  1525. - mem is now supported
  1526. Revision 1.30 1998/03/21 23:59:39 florian
  1527. * indexed properties fixed
  1528. * ppu i/o of properties fixed
  1529. * field can be also used for write access
  1530. * overriding of properties
  1531. Revision 1.29 1998/03/18 22:50:11 florian
  1532. + fstp/fld optimization
  1533. * routines which contains asm aren't longer optimzed
  1534. * wrong ifdef TEST_FUNCRET corrected
  1535. * wrong data generation for array[0..n] of char = '01234'; fixed
  1536. * bug0097 is fixed partial
  1537. * bug0116 fixed (-Og doesn't use enter of the stack frame is greater than
  1538. 65535)
  1539. Revision 1.28 1998/03/10 16:27:41 pierre
  1540. * better line info in stabs debug
  1541. * symtabletype and lexlevel separated into two fields of tsymtable
  1542. + ifdef MAKELIB for direct library output, not complete
  1543. + ifdef CHAINPROCSYMS for overloaded seach across units, not fully
  1544. working
  1545. + ifdef TESTFUNCRET for setting func result in underfunction, not
  1546. working
  1547. Revision 1.27 1998/03/10 01:17:23 peter
  1548. * all files have the same header
  1549. * messages are fully implemented, EXTDEBUG uses Comment()
  1550. + AG... files for the Assembler generation
  1551. Revision 1.26 1998/03/06 00:52:41 peter
  1552. * replaced all old messages from errore.msg, only ExtDebug and some
  1553. Comment() calls are left
  1554. * fixed options.pas
  1555. Revision 1.25 1998/03/05 22:43:49 florian
  1556. * some win32 support stuff added
  1557. Revision 1.24 1998/03/04 17:33:49 michael
  1558. + Changed ifdef FPK to ifdef FPC
  1559. Revision 1.23 1998/03/04 01:35:06 peter
  1560. * messages for unit-handling and assembler/linker
  1561. * the compiler compiles without -dGDB, but doesn't work yet
  1562. + -vh for Hint
  1563. Revision 1.22 1998/03/02 01:49:00 peter
  1564. * renamed target_DOS to target_GO32V1
  1565. + new verbose system, merged old errors and verbose units into one new
  1566. verbose.pas, so errors.pas is obsolete
  1567. Revision 1.21 1998/02/28 14:43:47 florian
  1568. * final implemenation of win32 imports
  1569. * extended tai_align to allow 8 and 16 byte aligns
  1570. Revision 1.20 1998/02/19 00:11:07 peter
  1571. * fixed -g to work again
  1572. * fixed some typos with the scriptobject
  1573. Revision 1.19 1998/02/13 10:35:23 daniel
  1574. * Made Motorola version compilable.
  1575. * Fixed optimizer
  1576. Revision 1.18 1998/02/12 17:19:19 florian
  1577. * fixed to get remake3 work, but needs additional fixes (output, I don't like
  1578. also that aktswitches isn't a pointer)
  1579. Revision 1.17 1998/02/12 11:50:25 daniel
  1580. Yes! Finally! After three retries, my patch!
  1581. Changes:
  1582. Complete rewrite of psub.pas.
  1583. Added support for DLL's.
  1584. Compiler requires less memory.
  1585. Platform units for each platform.
  1586. Revision 1.16 1998/02/11 21:56:36 florian
  1587. * bugfixes: bug0093, bug0053, bug0088, bug0087, bug0089
  1588. Revision 1.15 1998/02/06 10:34:25 florian
  1589. * bug0082 and bug0084 fixed
  1590. Revision 1.14 1998/02/02 11:56:49 pierre
  1591. * better line info for var statement
  1592. Revision 1.13 1998/01/30 21:25:31 carl
  1593. * bugfix #86 + checking of all other macros for crashes, fixed typeof
  1594. partly among others.
  1595. Revision 1.12 1998/01/23 17:12:19 pierre
  1596. * added some improvements for as and ld :
  1597. - doserror and dosexitcode treated separately
  1598. - PATH searched if doserror=2
  1599. + start of long and ansi string (far from complete)
  1600. in conditionnal UseLongString and UseAnsiString
  1601. * options.pas cleaned (some variables shifted to globals)gl
  1602. Revision 1.11 1998/01/21 21:25:46 florian
  1603. * small problem with variante records fixed:
  1604. case a : (x,y,z) of
  1605. ...
  1606. is now allowed
  1607. Revision 1.10 1998/01/13 23:11:13 florian
  1608. + class methods
  1609. Revision 1.9 1998/01/12 13:03:31 florian
  1610. + parsing of class methods implemented
  1611. Revision 1.8 1998/01/11 10:54:23 florian
  1612. + generic library support
  1613. Revision 1.7 1998/01/09 23:08:32 florian
  1614. + C++/Delphi styled //-comments
  1615. * some bugs in Delphi object model fixed
  1616. + override directive
  1617. Revision 1.6 1998/01/09 18:01:16 florian
  1618. * VIRTUAL isn't anymore a common keyword
  1619. + DYNAMIC is equal to VIRTUAL
  1620. Revision 1.5 1998/01/09 16:08:23 florian
  1621. * abstract methods call now abstracterrorproc if they are called
  1622. a class with an abstract method can be create with a class reference else
  1623. the compiler forbides this
  1624. Revision 1.4 1998/01/09 13:39:55 florian
  1625. * public, protected and private aren't anymore key words
  1626. + published is equal to public
  1627. Revision 1.3 1998/01/09 13:18:12 florian
  1628. + "forward" class declarations (type tclass = class; )
  1629. Revision 1.2 1998/01/09 09:09:58 michael
  1630. + Initial implementation, second try
  1631. }