pdecl.pas 69 KB

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