pdecl.pas 92 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458
  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. files,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. { search in symtablestack used, but not defined type }
  60. procedure testforward_type(p : psym);{$ifndef FPC}far;{$endif}
  61. var
  62. recsymtable : psymtable;
  63. oldaktfilepos : tfileposinfo;
  64. begin
  65. if not(p^.typ=typesym) then
  66. exit;
  67. if ((p^.properties and sp_forwarddef)<>0) then
  68. begin
  69. oldaktfilepos:=aktfilepos;
  70. aktfilepos:=p^.fileinfo;
  71. Message1(sym_e_forward_type_not_resolved,p^.name);
  72. aktfilepos:=oldaktfilepos;
  73. { try to recover }
  74. ptypesym(p)^.definition:=generrordef;
  75. p^.properties:=p^.properties and (not sp_forwarddef);
  76. end
  77. else
  78. if (ptypesym(p)^.definition^.deftype in [recorddef,objectdef]) then
  79. begin
  80. if (ptypesym(p)^.definition^.deftype=recorddef) then
  81. recsymtable:=precdef(ptypesym(p)^.definition)^.symtable
  82. else
  83. recsymtable:=pobjectdef(ptypesym(p)^.definition)^.publicsyms;
  84. {$ifdef tp}
  85. recsymtable^.foreach(testforward_type);
  86. {$else}
  87. recsymtable^.foreach(@testforward_type);
  88. {$endif}
  89. end;
  90. end;
  91. procedure const_dec;
  92. var
  93. name : stringid;
  94. p : ptree;
  95. def : pdef;
  96. sym : psym;
  97. storetokenpos,filepos : tfileposinfo;
  98. old_block_type : tblock_type;
  99. ps : pconstset;
  100. pd : pbestreal;
  101. sp : pstring;
  102. begin
  103. consume(_CONST);
  104. old_block_type:=block_type;
  105. block_type:=bt_const;
  106. repeat
  107. name:=pattern;
  108. filepos:=tokenpos;
  109. consume(ID);
  110. case token of
  111. EQUAL:
  112. begin
  113. consume(EQUAL);
  114. p:=comp_expr(true);
  115. do_firstpass(p);
  116. storetokenpos:=tokenpos;
  117. tokenpos:=filepos;
  118. case p^.treetype of
  119. ordconstn:
  120. begin
  121. if is_constintnode(p) then
  122. symtablestack^.insert(new(pconstsym,init(name,constint,p^.value,nil)))
  123. else if is_constcharnode(p) then
  124. symtablestack^.insert(new(pconstsym,init(name,constchar,p^.value,nil)))
  125. else if is_constboolnode(p) then
  126. symtablestack^.insert(new(pconstsym,init(name,constbool,p^.value,nil)))
  127. else if p^.resulttype^.deftype=enumdef then
  128. symtablestack^.insert(new(pconstsym,init(name,constord,p^.value,p^.resulttype)))
  129. else if p^.resulttype^.deftype=pointerdef then
  130. symtablestack^.insert(new(pconstsym,init(name,constord,p^.value,p^.resulttype)))
  131. else internalerror(111);
  132. end;
  133. stringconstn:
  134. begin
  135. { value_str is disposed with p so I need a copy }
  136. getmem(sp,p^.length+1);
  137. move(p^.value_str^,sp^[1],p^.length);
  138. {$ifndef TP}
  139. {$ifopt H+}
  140. setlength(sp^,p^.length);
  141. {$else}
  142. sp^[0]:=chr(p^.length);
  143. {$endif}
  144. {$else}
  145. sp^[0]:=chr(p^.length);
  146. {$endif}
  147. symtablestack^.insert(new(pconstsym,init(name,conststring,longint(sp),nil)));
  148. end;
  149. realconstn :
  150. begin
  151. new(pd);
  152. pd^:=p^.value_real;
  153. symtablestack^.insert(new(pconstsym,init(name,constreal,longint(pd),nil)));
  154. end;
  155. setconstn :
  156. begin
  157. new(ps);
  158. ps^:=p^.value_set^;
  159. symtablestack^.insert(new(pconstsym,init(name,constset,longint(ps),p^.resulttype)));
  160. end;
  161. niln :
  162. begin
  163. symtablestack^.insert(new(pconstsym,init(name,constnil,0,p^.resulttype)));
  164. end;
  165. else
  166. Message(cg_e_illegal_expression);
  167. end;
  168. tokenpos:=storetokenpos;
  169. consume(SEMICOLON);
  170. disposetree(p);
  171. end;
  172. COLON:
  173. begin
  174. consume(COLON);
  175. { this was missed, so const s : ^string = nil gives an
  176. error (FK)
  177. }
  178. block_type:=bt_type;
  179. ignore_equal:=true;
  180. def:=read_type('');
  181. ignore_equal:=false;
  182. block_type:=bt_const;
  183. storetokenpos:=tokenpos;
  184. tokenpos:=filepos;
  185. sym:=new(ptypedconstsym,init(name,def));
  186. tokenpos:=storetokenpos;
  187. symtablestack^.insert(sym);
  188. consume(EQUAL);
  189. readtypedconst(def,ptypedconstsym(sym));
  190. consume(SEMICOLON);
  191. end;
  192. else consume(EQUAL);
  193. end;
  194. until token<>ID;
  195. block_type:=old_block_type;
  196. end;
  197. procedure label_dec;
  198. var
  199. hl : plabel;
  200. begin
  201. consume(_LABEL);
  202. if not(cs_support_goto in aktmoduleswitches) then
  203. Message(sym_e_goto_and_label_not_supported);
  204. repeat
  205. if not(token in [ID,INTCONST]) then
  206. consume(ID)
  207. else
  208. begin
  209. getlabel(hl);
  210. symtablestack^.insert(new(plabelsym,init(pattern,hl)));
  211. consume(token);
  212. end;
  213. if token<>SEMICOLON then consume(COMMA);
  214. until not(token in [ID,INTCONST]);
  215. consume(SEMICOLON);
  216. end;
  217. procedure read_var_decs(is_record,is_object:boolean);
  218. { reads the filed of a record into a }
  219. { symtablestack, if record=false }
  220. { variants are forbidden, so this procedure }
  221. { can be used to read object fields }
  222. { if absolute is true, ABSOLUTE and file }
  223. { types are allowed }
  224. { => the procedure is also used to read }
  225. { a sequence of variable declaration }
  226. var
  227. sc : pstringcontainer;
  228. s : stringid;
  229. old_block_type : tblock_type;
  230. declarepos,storetokenpos : tfileposinfo;
  231. symdone : boolean;
  232. { to handle absolute }
  233. abssym : pabsolutesym;
  234. l : longint;
  235. code : word;
  236. { c var }
  237. Csym : pvarsym;
  238. newtype : ptypesym;
  239. is_gpc_name,is_cdecl,extern_Csym,export_Csym : boolean;
  240. C_name : string;
  241. { case }
  242. p,casedef : pdef;
  243. { maxsize contains the max. size of a variant }
  244. { startvarrec contains the start of the variant part of a record }
  245. maxsize,startvarrec : longint;
  246. pt : ptree;
  247. begin
  248. old_block_type:=block_type;
  249. block_type:=bt_type;
  250. is_gpc_name:=false;
  251. { Force an expected ID error message }
  252. if not (token in [ID,_CASE,_END]) then
  253. consume(ID);
  254. { read vars }
  255. while (token=ID) and
  256. not(is_object and (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED])) do
  257. begin
  258. C_name:=orgpattern;
  259. sc:=idlist;
  260. consume(COLON);
  261. if (m_gpc in aktmodeswitches) and
  262. not(is_record or is_object) and
  263. (token=ID) and (orgpattern='__asmname__') then
  264. begin
  265. consume(ID);
  266. C_name:=pattern;
  267. if token=CCHAR then
  268. consume(CCHAR)
  269. else
  270. consume(CSTRING);
  271. Is_gpc_name:=true;
  272. end;
  273. p:=read_type('');
  274. symdone:=false;
  275. if is_gpc_name then
  276. begin
  277. storetokenpos:=tokenpos;
  278. s:=sc^.get_with_tokeninfo(tokenpos);
  279. if not sc^.empty then
  280. Message(parser_e_absolute_only_one_var);
  281. dispose(sc,done);
  282. Csym:=new(pvarsym,init_C(s,target_os.Cprefix+C_name,p));
  283. tokenpos:=storetokenpos;
  284. Csym^.var_options:=Csym^.var_options or vo_is_external;
  285. externals^.concat(new(pai_external,init(Csym^.mangledname,EXT_NEAR)));
  286. symtablestack^.insert(Csym);
  287. symdone:=true;
  288. end;
  289. { check for absolute }
  290. if not symdone and
  291. (idtoken=_ABSOLUTE) and not(is_record or is_object) then
  292. begin
  293. consume(_ABSOLUTE);
  294. { only allowed for one var }
  295. s:=sc^.get_with_tokeninfo(declarepos);
  296. if not sc^.empty then
  297. Message(parser_e_absolute_only_one_var);
  298. dispose(sc,done);
  299. { parse the rest }
  300. if token=ID then
  301. begin
  302. getsym(pattern,true);
  303. consume(ID);
  304. { we should check the result type of srsym }
  305. if not (srsym^.typ in [varsym,typedconstsym]) then
  306. Message(parser_e_absolute_only_to_var_or_const);
  307. storetokenpos:=tokenpos;
  308. tokenpos:=declarepos;
  309. abssym:=new(pabsolutesym,init(s,p));
  310. abssym^.typ:=absolutesym;
  311. abssym^.abstyp:=tovar;
  312. abssym^.ref:=srsym;
  313. tokenpos:=storetokenpos;
  314. symtablestack^.insert(abssym);
  315. end
  316. else
  317. if (token=CSTRING) or (token=CCHAR) then
  318. begin
  319. storetokenpos:=tokenpos;
  320. tokenpos:=declarepos;
  321. abssym:=new(pabsolutesym,init(s,p));
  322. s:=pattern;
  323. consume(token);
  324. abssym^.typ:=absolutesym;
  325. abssym^.abstyp:=toasm;
  326. abssym^.asmname:=stringdup(s);
  327. tokenpos:=storetokenpos;
  328. symtablestack^.insert(abssym);
  329. end
  330. else
  331. { absolute address ?!? }
  332. if token=INTCONST then
  333. begin
  334. if (target_info.target=target_i386_go32v2) then
  335. begin
  336. storetokenpos:=tokenpos;
  337. tokenpos:=declarepos;
  338. abssym:=new(pabsolutesym,init(s,p));
  339. abssym^.typ:=absolutesym;
  340. abssym^.abstyp:=toaddr;
  341. abssym^.absseg:=false;
  342. tokenpos:=storetokenpos;
  343. s:=pattern;
  344. consume(INTCONST);
  345. val(s,abssym^.address,code);
  346. if token=COLON then
  347. begin
  348. consume(token);
  349. s:=pattern;
  350. consume(INTCONST);
  351. val(s,l,code);
  352. abssym^.address:=abssym^.address shl 4+l;
  353. abssym^.absseg:=true;
  354. end;
  355. symtablestack^.insert(abssym);
  356. end
  357. else
  358. Message(parser_e_absolute_only_to_var_or_const);
  359. end
  360. else
  361. Message(parser_e_absolute_only_to_var_or_const);
  362. symdone:=true;
  363. end;
  364. { for a record there doesn't need to be a ; before the END or ) }
  365. if not((is_record or is_object) and (token in [_END,RKLAMMER])) then
  366. consume(SEMICOLON);
  367. { procvar handling }
  368. if (p^.deftype=procvardef) and (p^.sym=nil) then
  369. begin
  370. newtype:=new(ptypesym,init('unnamed',p));
  371. parse_var_proc_directives(newtype);
  372. newtype^.definition:=nil;
  373. p^.sym:=nil;
  374. dispose(newtype,done);
  375. end;
  376. { Check for variable directives }
  377. if not symdone and (token=ID) then
  378. begin
  379. { Check for C Variable declarations }
  380. if (m_cvar_support in aktmodeswitches) and
  381. not(is_record or is_object) and
  382. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR]) then
  383. begin
  384. { only allowed for one var }
  385. s:=sc^.get_with_tokeninfo(declarepos);
  386. if not sc^.empty then
  387. Message(parser_e_absolute_only_one_var);
  388. dispose(sc,done);
  389. { defaults }
  390. is_cdecl:=false;
  391. extern_csym:=false;
  392. export_Csym:=false;
  393. { cdecl }
  394. if idtoken=_CVAR then
  395. begin
  396. consume(_CVAR);
  397. consume(SEMICOLON);
  398. is_cdecl:=true;
  399. C_name:=target_os.Cprefix+C_name;
  400. end;
  401. { external }
  402. if idtoken=_EXTERNAL then
  403. begin
  404. consume(_EXTERNAL);
  405. extern_csym:=true;
  406. end;
  407. { export }
  408. if idtoken in [_EXPORT,_PUBLIC] then
  409. begin
  410. consume(ID);
  411. if extern_csym then
  412. Message(parser_e_not_external_and_export)
  413. else
  414. export_Csym:=true;
  415. end;
  416. { external and export need a name after when no cdecl is used }
  417. if not is_cdecl then
  418. begin
  419. consume(_NAME);
  420. C_name:=pattern;
  421. { allow also char }
  422. if token=CCHAR then
  423. consume(CCHAR)
  424. else
  425. consume(CSTRING);
  426. end;
  427. { consume the ; when export or external is used }
  428. if extern_csym or export_csym then
  429. consume(SEMICOLON);
  430. { insert in the symtable }
  431. storetokenpos:=tokenpos;
  432. tokenpos:=declarepos;
  433. Csym:=new(pvarsym,init_C(s,C_name,p));
  434. tokenpos:=storetokenpos;
  435. if export_Csym then
  436. inc(Csym^.refs);
  437. if extern_Csym then
  438. begin
  439. Csym^.var_options:=Csym^.var_options or vo_is_external;
  440. { correct type ?? }
  441. externals^.concat(new(pai_external,init(Csym^.mangledname,EXT_NEAR)));
  442. end;
  443. symtablestack^.insert(Csym);
  444. symdone:=true;
  445. end
  446. else
  447. if (is_object) and (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  448. begin
  449. current_object_option:=current_object_option or sp_static;
  450. insert_syms(symtablestack,sc,p);
  451. current_object_option:=current_object_option - sp_static;
  452. consume(_STATIC);
  453. consume(SEMICOLON);
  454. symdone:=true;
  455. end;
  456. end;
  457. { insert it in the symtable, if not done yet }
  458. if not symdone then
  459. begin
  460. if (current_object_option=sp_published) and
  461. (not((p^.deftype=objectdef) and (pobjectdef(p)^.isclass))) then
  462. Message(parser_e_cant_publish_that);
  463. insert_syms(symtablestack,sc,p);
  464. end;
  465. end;
  466. { Check for Case }
  467. if is_record and (token=_CASE) then
  468. begin
  469. maxsize:=0;
  470. consume(_CASE);
  471. s:=pattern;
  472. getsym(s,false);
  473. { may be only a type: }
  474. if assigned(srsym) and (srsym^.typ in [typesym,unitsym]) then
  475. casedef:=read_type('')
  476. else
  477. begin
  478. consume(ID);
  479. consume(COLON);
  480. casedef:=read_type('');
  481. symtablestack^.insert(new(pvarsym,init(s,casedef)));
  482. end;
  483. if not is_ordinal(casedef) then
  484. Message(type_e_ordinal_expr_expected);
  485. consume(_OF);
  486. startvarrec:=symtablestack^.datasize;
  487. repeat
  488. repeat
  489. pt:=comp_expr(true);
  490. do_firstpass(pt);
  491. if not(pt^.treetype=ordconstn) then
  492. Message(cg_e_illegal_expression);
  493. disposetree(pt);
  494. if token=COMMA then
  495. consume(COMMA)
  496. else
  497. break;
  498. until false;
  499. consume(COLON);
  500. { read the vars }
  501. consume(LKLAMMER);
  502. if token<>RKLAMMER then
  503. read_var_decs(true,false);
  504. consume(RKLAMMER);
  505. { calculates maximal variant size }
  506. maxsize:=max(maxsize,symtablestack^.datasize);
  507. { the items of the next variant are overlayed }
  508. symtablestack^.datasize:=startvarrec;
  509. if (token<>_END) and (token<>RKLAMMER) then
  510. consume(SEMICOLON)
  511. else
  512. break;
  513. until (token=_END) or (token=RKLAMMER);
  514. { at last set the record size to that of the biggest variant }
  515. symtablestack^.datasize:=maxsize;
  516. end;
  517. block_type:=old_block_type;
  518. end;
  519. function stringtype : pdef;
  520. { reads a string type with optional length }
  521. { and returns a pointer to the string }
  522. { definition }
  523. var
  524. p : ptree;
  525. d : pdef;
  526. begin
  527. consume(_STRING);
  528. if token=LECKKLAMMER then
  529. begin
  530. consume(LECKKLAMMER);
  531. p:=comp_expr(true);
  532. do_firstpass(p);
  533. if not is_constintnode(p) then
  534. Message(cg_e_illegal_expression);
  535. if (p^.value<0) then
  536. begin
  537. Message(parser_e_string_too_long);
  538. p^.value:=255;
  539. end;
  540. consume(RECKKLAMMER);
  541. if p^.value>255 then
  542. d:=new(pstringdef,longinit(p^.value))
  543. else
  544. if p^.value<>255 then
  545. d:=new(pstringdef,shortinit(p^.value))
  546. else
  547. d:=cshortstringdef;
  548. disposetree(p);
  549. end
  550. else
  551. begin
  552. if cs_ansistrings in aktlocalswitches then
  553. d:=cansistringdef
  554. else
  555. d:=cshortstringdef;
  556. end;
  557. stringtype:=d;
  558. end;
  559. function id_type(var s : string) : pdef;
  560. { reads a type definition and returns a pointer }
  561. { to a appropriating pdef, s gets the name of }
  562. { the type to allow name mangling }
  563. begin
  564. s:=pattern;
  565. consume(ID);
  566. { classes can be used also in classes }
  567. if (curobjectname=pattern) and aktobjectdef^.isclass then
  568. begin
  569. id_type:=aktobjectdef;
  570. exit;
  571. end;
  572. { objects can be parameters }
  573. if (testcurobject=2) and (curobjectname=pattern) then
  574. begin
  575. id_type:=aktobjectdef;
  576. exit;
  577. end;
  578. getsym(s,true);
  579. if assigned(srsym) then
  580. begin
  581. if srsym^.typ=unitsym then
  582. begin
  583. consume(POINT);
  584. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  585. s:=pattern;
  586. consume(ID);
  587. end;
  588. if srsym^.typ<>typesym then
  589. begin
  590. Message(type_e_type_id_expected);
  591. lasttypesym:=ptypesym(srsym);
  592. id_type:=generrordef;
  593. exit;
  594. end;
  595. if not forwardsallowed then
  596. testforward_type(srsym);
  597. end;
  598. lasttypesym:=ptypesym(srsym);
  599. id_type:=ptypesym(srsym)^.definition;
  600. end;
  601. function single_type(var s : string) : pdef;
  602. { reads a string, file type or a type id and returns a name and }
  603. { pdef }
  604. var
  605. hs : string;
  606. begin
  607. case token of
  608. _STRING:
  609. begin
  610. single_type:=stringtype;
  611. s:='STRING';
  612. lasttypesym:=nil;
  613. end;
  614. _FILE:
  615. begin
  616. consume(_FILE);
  617. if token=_OF then
  618. begin
  619. consume(_OF);
  620. single_type:=new(pfiledef,init(ft_typed,single_type(hs)));
  621. s:='FILE$OF$'+hs;
  622. end
  623. else
  624. begin
  625. { single_type:=new(pfiledef,init(ft_untyped,nil));}
  626. single_type:=cfiledef;
  627. s:='FILE';
  628. end;
  629. lasttypesym:=nil;
  630. end;
  631. else single_type:=id_type(s);
  632. end;
  633. end;
  634. function object_dec(const n : stringid;fd : pobjectdef) : pdef;
  635. { this function parses an object or class declaration }
  636. var
  637. actmembertype : symprop;
  638. there_is_a_destructor : boolean;
  639. is_a_class : boolean;
  640. childof : pobjectdef;
  641. aktclass : pobjectdef;
  642. procedure constructor_head;
  643. begin
  644. consume(_CONSTRUCTOR);
  645. { must be at same level as in implementation }
  646. inc(lexlevel);
  647. parse_proc_head(poconstructor);
  648. dec(lexlevel);
  649. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'INIT') then
  650. Message(parser_e_constructorname_must_be_init);
  651. aktclass^.options:=aktclass^.options or oo_hasconstructor;
  652. consume(SEMICOLON);
  653. begin
  654. if (aktclass^.options and oo_is_class)<>0 then
  655. begin
  656. { CLASS constructors return the created instance }
  657. aktprocsym^.definition^.retdef:=aktclass;
  658. end
  659. else
  660. begin
  661. { OBJECT constructors return a boolean }
  662. {$IfDef GDB}
  663. {GDB doesn't like unnamed types !}
  664. aktprocsym^.definition^.retdef:=
  665. globaldef('boolean');
  666. {$Else GDB}
  667. aktprocsym^.definition^.retdef:=
  668. new(porddef,init(bool8bit,0,1));
  669. {$Endif GDB}
  670. end;
  671. end;
  672. end;
  673. procedure property_dec;
  674. var
  675. sym : psym;
  676. propertyparas : pdefcoll;
  677. { returns the matching procedure to access a property }
  678. function get_procdef : pprocdef;
  679. var
  680. p : pprocdef;
  681. begin
  682. p:=pprocsym(sym)^.definition;
  683. get_procdef:=nil;
  684. while assigned(p) do
  685. begin
  686. if equal_paras(p^.para1,propertyparas,true) then
  687. break;
  688. p:=p^.nextoverloaded;
  689. end;
  690. get_procdef:=p;
  691. end;
  692. var
  693. hp2,datacoll : pdefcoll;
  694. p,p2 : ppropertysym;
  695. overriden : psym;
  696. hs : string;
  697. code : word;
  698. varspez : tvarspez;
  699. sc : pstringcontainer;
  700. hp : pdef;
  701. s : string;
  702. declarepos : tfileposinfo;
  703. pp : pprocdef;
  704. pt : ptree;
  705. propname : stringid;
  706. begin
  707. { check for a class }
  708. if (aktclass^.options and oo_is_class=0) then
  709. Message(parser_e_syntax_error);
  710. consume(_PROPERTY);
  711. propertyparas:=nil;
  712. datacoll:=nil;
  713. if token=ID then
  714. begin
  715. p:=new(ppropertysym,init(pattern));
  716. propname:=pattern;
  717. consume(ID);
  718. { property parameters ? }
  719. if token=LECKKLAMMER then
  720. begin
  721. if current_object_option=sp_published then
  722. Message(parser_e_cant_publish_that_property);
  723. { create a list of the parameters in propertyparas }
  724. consume(LECKKLAMMER);
  725. inc(testcurobject);
  726. repeat
  727. if token=_VAR then
  728. begin
  729. consume(_VAR);
  730. varspez:=vs_var;
  731. end
  732. else if token=_CONST then
  733. begin
  734. consume(_CONST);
  735. varspez:=vs_const;
  736. end
  737. else varspez:=vs_value;
  738. sc:=idlist;
  739. if token=COLON then
  740. begin
  741. consume(COLON);
  742. if token=_ARRAY then
  743. begin
  744. {
  745. if (varspez<>vs_const) and
  746. (varspez<>vs_var) then
  747. begin
  748. varspez:=vs_const;
  749. Message(parser_e_illegal_open_parameter);
  750. end;
  751. }
  752. consume(_ARRAY);
  753. consume(_OF);
  754. { define range and type of range }
  755. hp:=new(parraydef,init(0,-1,s32bitdef));
  756. { define field type }
  757. parraydef(hp)^.definition:=single_type(s);
  758. end
  759. else
  760. hp:=single_type(s);
  761. end
  762. else
  763. hp:=new(pformaldef,init);
  764. s:=sc^.get_with_tokeninfo(declarepos);
  765. while s<>'' do
  766. begin
  767. new(hp2);
  768. hp2^.paratyp:=varspez;
  769. hp2^.data:=hp;
  770. hp2^.next:=propertyparas;
  771. propertyparas:=hp2;
  772. s:=sc^.get_with_tokeninfo(declarepos);
  773. end;
  774. dispose(sc,done);
  775. if token=SEMICOLON then consume(SEMICOLON)
  776. else break;
  777. until false;
  778. dec(testcurobject);
  779. consume(RECKKLAMMER);
  780. end;
  781. { overriden property ? }
  782. { force property interface, if there is a property parameter }
  783. if (token=COLON) or assigned(propertyparas) then
  784. begin
  785. consume(COLON);
  786. p^.proptype:=single_type(hs);
  787. if (idtoken=_INDEX) then
  788. begin
  789. consume(_INDEX);
  790. p^.options:=p^.options or ppo_indexed;
  791. if token=INTCONST then
  792. val(pattern,p^.index,code);
  793. consume(INTCONST);
  794. { concat a longint to the para template }
  795. new(hp2);
  796. hp2^.paratyp:=vs_value;
  797. hp2^.data:=s32bitdef;
  798. hp2^.next:=propertyparas;
  799. propertyparas:=hp2;
  800. end;
  801. end
  802. else
  803. begin
  804. { do an property override }
  805. overriden:=search_class_member(aktclass,propname);
  806. if assigned(overriden) and (overriden^.typ=propertysym) then
  807. begin
  808. { take the whole info: }
  809. p^.options:=ppropertysym(overriden)^.options;
  810. p^.index:=ppropertysym(overriden)^.index;
  811. p^.proptype:=ppropertysym(overriden)^.proptype;
  812. p^.writeaccesssym:=ppropertysym(overriden)^.writeaccesssym;
  813. p^.readaccesssym:=ppropertysym(overriden)^.readaccesssym;
  814. p^.writeaccessdef:=ppropertysym(overriden)^.writeaccessdef;
  815. p^.readaccessdef:=ppropertysym(overriden)^.readaccessdef;
  816. p^.storedsym:=ppropertysym(overriden)^.storedsym;
  817. p^.storeddef:=ppropertysym(overriden)^.storeddef;
  818. p^.default:=ppropertysym(overriden)^.default;
  819. end
  820. else
  821. begin
  822. p^.proptype:=generrordef;
  823. message(parser_e_no_property_found_to_override);
  824. end;
  825. end;
  826. if (current_object_option=sp_published) and
  827. not(p^.proptype^.is_publishable) then
  828. Message(parser_e_cant_publish_that_property);
  829. { create data defcoll to allow correct parameter checks }
  830. new(datacoll);
  831. datacoll^.paratyp:=vs_value;
  832. datacoll^.data:=p^.proptype;
  833. datacoll^.next:=nil;
  834. if (idtoken=_READ) then
  835. begin
  836. consume(_READ);
  837. sym:=search_class_member(aktclass,pattern);
  838. if not(assigned(sym)) then
  839. Message1(sym_e_unknown_id,pattern)
  840. else
  841. begin
  842. { varsym aren't allowed for an indexed property
  843. or an property with parameters }
  844. if ((sym^.typ=varsym) and
  845. { not necessary, an index forces propertyparas
  846. to be assigned
  847. }
  848. { (((p^.options and ppo_indexed)<>0) or }
  849. assigned(propertyparas)) or
  850. not(sym^.typ in [varsym,procsym]) then
  851. Message(parser_e_ill_property_access_sym);
  852. { search the matching definition }
  853. if sym^.typ=procsym then
  854. begin
  855. pp:=get_procdef;
  856. if not(assigned(pp)) or
  857. not(is_equal(pp^.retdef,p^.proptype)) then
  858. Message(parser_e_ill_property_access_sym);
  859. p^.readaccessdef:=pp;
  860. end
  861. else if sym^.typ=varsym then
  862. begin
  863. if not(is_equal(pvarsym(sym)^.definition,
  864. p^.proptype)) then
  865. Message(parser_e_ill_property_access_sym);
  866. end;
  867. p^.readaccesssym:=sym;
  868. end;
  869. consume(ID);
  870. end;
  871. if (idtoken=_WRITE) then
  872. begin
  873. consume(_WRITE);
  874. sym:=search_class_member(aktclass,pattern);
  875. if not(assigned(sym)) then
  876. Message1(sym_e_unknown_id,pattern)
  877. else
  878. begin
  879. if ((sym^.typ=varsym) and
  880. assigned(propertyparas)) or
  881. not(sym^.typ in [varsym,procsym]) then
  882. Message(parser_e_ill_property_access_sym);
  883. { search the matching definition }
  884. if sym^.typ=procsym then
  885. begin
  886. { insert data entry to check access method }
  887. datacoll^.next:=propertyparas;
  888. propertyparas:=datacoll;
  889. pp:=get_procdef;
  890. { ... and remove it }
  891. propertyparas:=propertyparas^.next;
  892. datacoll^.next:=nil;
  893. if not(assigned(pp)) then
  894. Message(parser_e_ill_property_access_sym);
  895. p^.writeaccessdef:=pp;
  896. end
  897. else if sym^.typ=varsym then
  898. begin
  899. if not(is_equal(pvarsym(sym)^.definition,
  900. p^.proptype)) then
  901. Message(parser_e_ill_property_access_sym);
  902. end;
  903. p^.writeaccesssym:=sym;
  904. end;
  905. consume(ID);
  906. end;
  907. if (idtoken=_STORED) then
  908. begin
  909. consume(_STORED);
  910. Message(parser_w_stored_not_implemented);
  911. { !!!!!!!! }
  912. end;
  913. if (idtoken=_DEFAULT) then
  914. begin
  915. consume(_DEFAULT);
  916. if not(is_ordinal(p^.proptype) or
  917. ((p^.proptype^.deftype=setdef) and
  918. (psetdef(p^.proptype)^.settype=smallset)
  919. ) or
  920. assigned(propertyparas)
  921. ) then
  922. Message(parser_e_property_cant_have_a_default_value);
  923. pt:=comp_expr(true);
  924. pt:=gentypeconvnode(pt,p^.proptype);
  925. do_firstpass(pt);
  926. if not(is_constnode(pt)) then
  927. Message(parser_e_property_default_value_must_const);
  928. if pt^.treetype=setconstn then
  929. p^.default:=plongint(pt^.value_set)^
  930. else
  931. p^.default:=pt^.value;
  932. disposetree(pt);
  933. end
  934. else if (idtoken=_NODEFAULT) then
  935. begin
  936. consume(_NODEFAULT);
  937. p^.default:=0;
  938. end;
  939. symtablestack^.insert(p);
  940. { default property ? }
  941. consume(SEMICOLON);
  942. if (idtoken=_DEFAULT) then
  943. begin
  944. consume(_DEFAULT);
  945. p2:=search_default_property(aktclass);
  946. if assigned(p2) then
  947. message1(parser_e_only_one_default_property,
  948. pobjectdef(p2^.owner^.defowner)^.name^)
  949. else
  950. begin
  951. p^.options:=p^.options or ppo_defaultproperty;
  952. if not(assigned(propertyparas)) then
  953. message(parser_e_property_need_paras);
  954. end;
  955. consume(SEMICOLON);
  956. end;
  957. { clean up }
  958. if assigned(datacoll) then
  959. disposepdefcoll(datacoll);
  960. end
  961. else
  962. begin
  963. consume(ID);
  964. consume(SEMICOLON);
  965. end;
  966. if assigned(propertyparas) then
  967. disposepdefcoll(propertyparas);
  968. end;
  969. procedure destructor_head;
  970. begin
  971. consume(_DESTRUCTOR);
  972. inc(lexlevel);
  973. parse_proc_head(podestructor);
  974. dec(lexlevel);
  975. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  976. Message(parser_e_destructorname_must_be_done);
  977. aktclass^.options:=aktclass^.options or oo_hasdestructor;
  978. consume(SEMICOLON);
  979. if assigned(aktprocsym^.definition^.para1) then
  980. Message(parser_e_no_paras_for_destructor);
  981. { no return value }
  982. aktprocsym^.definition^.retdef:=voiddef;
  983. end;
  984. var
  985. hs : string;
  986. pcrd : pclassrefdef;
  987. hp1 : pdef;
  988. oldprocsym : Pprocsym;
  989. oldparse_only : boolean;
  990. classnamelabel : plabel;
  991. storetypeforwardsallowed : boolean;
  992. begin
  993. {Nowadays aktprocsym may already have a value, so we need to save
  994. it.}
  995. oldprocsym:=aktprocsym;
  996. { forward is resolved }
  997. if assigned(fd) then
  998. fd^.options:=fd^.options and not(oo_isforward);
  999. there_is_a_destructor:=false;
  1000. actmembertype:=sp_public;
  1001. { objects and class types can't be declared local }
  1002. if (symtablestack^.symtabletype<>globalsymtable) and
  1003. (symtablestack^.symtabletype<>staticsymtable) then
  1004. Message(parser_e_no_local_objects);
  1005. storetypeforwardsallowed:=typecanbeforward;
  1006. if m_tp in aktmodeswitches then
  1007. typecanbeforward:=false;
  1008. { distinguish classes and objects }
  1009. if token=_OBJECT then
  1010. begin
  1011. is_a_class:=false;
  1012. consume(_OBJECT)
  1013. end
  1014. else
  1015. begin
  1016. is_a_class:=true;
  1017. consume(_CLASS);
  1018. if not(assigned(fd)) and (token=_OF) then
  1019. begin
  1020. { a hack, but it's easy to handle }
  1021. { class reference type }
  1022. consume(_OF);
  1023. if typecanbeforward then
  1024. forwardsallowed:=true;
  1025. hp1:=single_type(hs);
  1026. { accept hp1, if is a forward def ...}
  1027. if ((lasttypesym<>nil)
  1028. and ((lasttypesym^.properties and sp_forwarddef)<>0)) or
  1029. { or a class
  1030. (if the foward defined type is a class is checked, when
  1031. the forward is resolved)
  1032. }
  1033. ((hp1^.deftype=objectdef) and (
  1034. (pobjectdef(hp1)^.options and oo_is_class)<>0)) then
  1035. begin
  1036. pcrd:=new(pclassrefdef,init(hp1));
  1037. object_dec:=pcrd;
  1038. {I add big troubles here
  1039. with var p : ^byte in graph.putimage
  1040. because a save_forward was called and
  1041. no resolve forward
  1042. => so the definition was rewritten after
  1043. having been disposed !!
  1044. Strange problems appeared !!!!}
  1045. {Anyhow forwards should only be allowed
  1046. inside a type statement ??
  1047. don't you think so }
  1048. if (lasttypesym<>nil)
  1049. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1050. lasttypesym^.forwardpointer:=ppointerdef(pcrd);
  1051. forwardsallowed:=false;
  1052. end
  1053. else
  1054. begin
  1055. Message(type_e_class_type_expected);
  1056. object_dec:=new(perrordef,init);
  1057. end;
  1058. exit;
  1059. end
  1060. { forward class }
  1061. else if not(assigned(fd)) and (token=SEMICOLON) then
  1062. begin
  1063. { also anonym objects aren't allow (o : object a : longint; end;) }
  1064. if n='' then
  1065. begin
  1066. Message(parser_f_no_anonym_objects)
  1067. end;
  1068. if n='TOBJECT' then
  1069. begin
  1070. aktclass:=new(pobjectdef,init(n,nil));
  1071. class_tobject:=aktclass;
  1072. end
  1073. else
  1074. aktclass:=new(pobjectdef,init(n,nil));
  1075. aktclass^.options:=aktclass^.options or oo_is_class or oo_isforward;
  1076. { all classes must have a vmt !! at offset zero }
  1077. if (aktclass^.options and oo_hasvmt)=0 then
  1078. aktclass^.insertvmt;
  1079. object_dec:=aktclass;
  1080. exit;
  1081. end;
  1082. end;
  1083. { also anonym objects aren't allow (o : object a : longint; end;) }
  1084. if n='' then
  1085. Message(parser_f_no_anonym_objects);
  1086. { read the parent class }
  1087. if token=LKLAMMER then
  1088. begin
  1089. consume(LKLAMMER);
  1090. { does not allow objects.tobject !! }
  1091. {if token<>ID then
  1092. consume(ID);
  1093. getsym(pattern,true);}
  1094. childof:=pobjectdef(id_type(pattern));
  1095. if (childof^.deftype<>objectdef) then
  1096. begin
  1097. Message(type_e_class_type_expected);
  1098. childof:=nil;
  1099. end
  1100. else
  1101. begin
  1102. { a mix of class and object isn't allowed }
  1103. if (((childof^.options and oo_is_class)<>0) and not is_a_class) or
  1104. (((childof^.options and oo_is_class)=0) and is_a_class) then
  1105. Message(parser_e_mix_of_classes_and_objects);
  1106. end;
  1107. if assigned(fd) then
  1108. begin
  1109. { the forward of the child must be resolved to get
  1110. correct field addresses
  1111. }
  1112. if (childof^.options and oo_isforward)<>0 then
  1113. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1114. aktclass:=fd;
  1115. { we must inherit several options !!
  1116. this was missing !!
  1117. all is now done in set_parent
  1118. including symtable datasize setting PM }
  1119. fd^.set_parent(childof);
  1120. end
  1121. else
  1122. aktclass:=new(pobjectdef,init(n,childof));
  1123. consume(RKLAMMER);
  1124. end
  1125. { if no parent class, then a class get tobject as parent }
  1126. else if is_a_class then
  1127. begin
  1128. { is the current class tobject? }
  1129. { so you could define your own tobject }
  1130. if n='TOBJECT' then
  1131. begin
  1132. if assigned(fd) then
  1133. aktclass:=fd
  1134. else
  1135. aktclass:=new(pobjectdef,init(n,nil));
  1136. class_tobject:=aktclass;
  1137. end
  1138. else
  1139. begin
  1140. childof:=class_tobject;
  1141. if assigned(fd) then
  1142. begin
  1143. { the forward of the child must be resolved to get
  1144. correct field addresses
  1145. }
  1146. if (childof^.options and oo_isforward)<>0 then
  1147. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1148. aktclass:=fd;
  1149. aktclass^.set_parent(childof);
  1150. end
  1151. else
  1152. begin
  1153. aktclass:=new(pobjectdef,init(n,childof));
  1154. aktclass^.set_parent(childof);
  1155. end;
  1156. end;
  1157. end
  1158. else
  1159. aktclass:=new(pobjectdef,init(n,nil));
  1160. { set the class attribute }
  1161. if is_a_class then
  1162. begin
  1163. aktclass^.options:=aktclass^.options or oo_is_class;
  1164. if (cs_generate_rtti in aktlocalswitches) or
  1165. (assigned(aktclass^.childof) and
  1166. ((aktclass^.childof^.options and oo_can_have_published)<>0)
  1167. ) then
  1168. aktclass^.options:=aktclass^.options or oo_can_have_published;
  1169. end;
  1170. aktobjectdef:=aktclass;
  1171. { default access is public }
  1172. actmembertype:=sp_public;
  1173. aktclass^.publicsyms^.next:=symtablestack;
  1174. symtablestack:=aktclass^.publicsyms;
  1175. procinfo._class:=aktclass;
  1176. testcurobject:=1;
  1177. curobjectname:=n;
  1178. { short class declaration ? }
  1179. if (not is_a_class) or (token<>SEMICOLON) then
  1180. begin
  1181. { Parse componenten }
  1182. repeat
  1183. if actmembertype=sp_private then
  1184. aktclass^.options:=aktclass^.options or oo_hasprivate;
  1185. if actmembertype=sp_protected then
  1186. aktclass^.options:=aktclass^.options or oo_hasprotected;
  1187. case token of
  1188. ID : begin
  1189. case idtoken of
  1190. _PRIVATE : begin
  1191. consume(_PRIVATE);
  1192. actmembertype:=sp_private;
  1193. current_object_option:=sp_private;
  1194. end;
  1195. _PROTECTED : begin
  1196. consume(_PROTECTED);
  1197. current_object_option:=sp_protected;
  1198. actmembertype:=sp_protected;
  1199. end;
  1200. _PUBLIC : begin
  1201. consume(_PUBLIC);
  1202. current_object_option:=sp_public;
  1203. actmembertype:=sp_public;
  1204. end;
  1205. _PUBLISHED : begin
  1206. if (aktclass^.options and oo_can_have_published)=0 then
  1207. Message(parser_e_cant_have_published);
  1208. consume(_PUBLISHED);
  1209. current_object_option:=sp_published;
  1210. actmembertype:=sp_published;
  1211. end;
  1212. else
  1213. read_var_decs(false,true);
  1214. end;
  1215. end;
  1216. _PROPERTY : property_dec;
  1217. _PROCEDURE,
  1218. _FUNCTION,
  1219. _CLASS : begin
  1220. oldparse_only:=parse_only;
  1221. parse_only:=true;
  1222. parse_proc_dec;
  1223. parse_only:=oldparse_only;
  1224. case idtoken of
  1225. _DYNAMIC,
  1226. _VIRTUAL : begin
  1227. if actmembertype=sp_private then
  1228. Message(parser_w_priv_meth_not_virtual);
  1229. consume(idtoken);
  1230. consume(SEMICOLON);
  1231. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1232. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1233. end;
  1234. _OVERRIDE : begin
  1235. consume(_OVERRIDE);
  1236. consume(SEMICOLON);
  1237. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1238. pooverridingmethod or povirtualmethod;
  1239. end;
  1240. end;
  1241. if idtoken=_abstract then
  1242. begin
  1243. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  1244. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or poabstractmethod
  1245. else
  1246. Message(parser_e_only_virtual_methods_abstract);
  1247. consume(_ABSTRACT);
  1248. consume(SEMICOLON);
  1249. { the method is defined }
  1250. aktprocsym^.definition^.forwarddef:=false;
  1251. end;
  1252. if (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  1253. begin
  1254. consume(_STATIC);
  1255. consume(SEMICOLON);
  1256. aktprocsym^.properties:=aktprocsym^.properties or sp_static;
  1257. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or postaticmethod;
  1258. end;
  1259. end;
  1260. _CONSTRUCTOR : begin
  1261. if actmembertype<>sp_public then
  1262. Message(parser_w_constructor_should_be_public);
  1263. oldparse_only:=parse_only;
  1264. parse_only:=true;
  1265. constructor_head;
  1266. parse_only:=oldparse_only;
  1267. case idtoken of
  1268. _DYNAMIC,
  1269. _VIRTUAL : begin
  1270. if not(aktclass^.isclass) then
  1271. Message(parser_e_constructor_cannot_be_not_virtual)
  1272. else
  1273. begin
  1274. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1275. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1276. end;
  1277. consume(idtoken);
  1278. consume(SEMICOLON);
  1279. end;
  1280. _OVERRIDE : begin
  1281. if (aktclass^.options and oo_is_class=0) then
  1282. Message(parser_e_constructor_cannot_be_not_virtual)
  1283. else
  1284. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1285. pooverridingmethod or povirtualmethod;
  1286. consume(_OVERRIDE);
  1287. consume(SEMICOLON);
  1288. end;
  1289. end;
  1290. end;
  1291. _DESTRUCTOR : begin
  1292. if there_is_a_destructor then
  1293. Message(parser_n_only_one_destructor);
  1294. there_is_a_destructor:=true;
  1295. if actmembertype<>sp_public then
  1296. Message(parser_w_destructor_should_be_public);
  1297. oldparse_only:=parse_only;
  1298. parse_only:=true;
  1299. destructor_head;
  1300. parse_only:=oldparse_only;
  1301. case idtoken of
  1302. _DYNAMIC,
  1303. _VIRTUAL : begin
  1304. consume(idtoken);
  1305. consume(SEMICOLON);
  1306. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1307. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1308. end;
  1309. _OVERRIDE : begin
  1310. consume(_OVERRIDE);
  1311. consume(SEMICOLON);
  1312. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1313. pooverridingmethod or povirtualmethod;
  1314. end;
  1315. end;
  1316. end;
  1317. _END : begin
  1318. consume(_END);
  1319. break;
  1320. end;
  1321. else
  1322. consume(ID); { Give a ident expected message, like tp7 }
  1323. end;
  1324. until false;
  1325. current_object_option:=sp_public;
  1326. end;
  1327. testcurobject:=0;
  1328. curobjectname:='';
  1329. typecanbeforward:=storetypeforwardsallowed;
  1330. { generate vmt space if needed }
  1331. if ((aktclass^.options and
  1332. (oo_hasvirtual or oo_hasconstructor or
  1333. oo_hasdestructor or oo_is_class))<>0) and
  1334. ((aktclass^.options and
  1335. oo_hasvmt)=0) then
  1336. aktclass^.insertvmt;
  1337. if (cs_smartlink in aktmoduleswitches) then
  1338. datasegment^.concat(new(pai_cut,init));
  1339. { write extended info for classes }
  1340. if is_a_class then
  1341. begin
  1342. if (aktclass^.options and oo_can_have_published)<>0 then
  1343. aktclass^.generate_rtti;
  1344. { write class name }
  1345. getlabel(classnamelabel);
  1346. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1347. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.name^))));
  1348. datasegment^.concat(new(pai_string,init(aktclass^.name^)));
  1349. { interface table }
  1350. datasegment^.concat(new(pai_const,init_32bit(0)));
  1351. { auto table }
  1352. datasegment^.concat(new(pai_const,init_32bit(0)));
  1353. { inittable for con-/destruction }
  1354. if aktclass^.needs_inittable then
  1355. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(aktclass^.get_inittable_label)))))
  1356. else
  1357. datasegment^.concat(new(pai_const,init_32bit(0)));
  1358. { pointer to type info of published section }
  1359. if (aktclass^.options and oo_can_have_published)<>0 then
  1360. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.rtti_name))))
  1361. else
  1362. datasegment^.concat(new(pai_const,init_32bit(0)));
  1363. { pointer to field table }
  1364. datasegment^.concat(new(pai_const,init_32bit(0)));
  1365. { pointer to method table }
  1366. datasegment^.concat(new(pai_const,init_32bit(0)));
  1367. { pointer to dynamic table }
  1368. datasegment^.concat(new(pai_const,init_32bit(0)));
  1369. { pointer to class name string }
  1370. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(classnamelabel)))));
  1371. end;
  1372. {$ifdef GDB}
  1373. { generate the VMT }
  1374. if (cs_debuginfo in aktmoduleswitches) and
  1375. ((aktclass^.options and oo_hasvmt)<>0) then
  1376. begin
  1377. do_count_dbx:=true;
  1378. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1379. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1380. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1381. end;
  1382. {$endif GDB}
  1383. if ((aktclass^.options and oo_hasvmt)<>0) then
  1384. begin
  1385. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  1386. { determine the size with publicsyms^.datasize, because }
  1387. { size gives back 4 for classes }
  1388. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  1389. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  1390. { write pointer to parent VMT, this isn't implemented in TP }
  1391. { but this is not used in FPC ? (PM) }
  1392. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1393. { it is not written for parents that don't have any vmt !! }
  1394. if assigned(aktclass^.childof) and
  1395. ((aktclass^.childof^.options and oo_hasvmt)<>0) then
  1396. begin
  1397. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  1398. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  1399. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  1400. end
  1401. else
  1402. datasegment^.concat(new(pai_const,init_32bit(0)));
  1403. { this generates the entries }
  1404. genvmt(aktclass);
  1405. end;
  1406. { restore old state }
  1407. symtablestack:=symtablestack^.next;
  1408. procinfo._class:=nil;
  1409. aktobjectdef:=nil;
  1410. {Restore the aktprocsym.}
  1411. aktprocsym:=oldprocsym;
  1412. object_dec:=aktclass;
  1413. end;
  1414. { reads a record declaration }
  1415. function record_dec : pdef;
  1416. var
  1417. symtable : psymtable;
  1418. storetypeforwardsallowed : boolean;
  1419. begin
  1420. symtable:=new(psymtable,init(recordsymtable));
  1421. symtable^.next:=symtablestack;
  1422. symtablestack:=symtable;
  1423. consume(_RECORD);
  1424. storetypeforwardsallowed:=typecanbeforward;
  1425. if m_tp in aktmodeswitches then
  1426. typecanbeforward:=false;
  1427. read_var_decs(true,false);
  1428. { may be scale record size to a size of n*4 ? }
  1429. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  1430. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  1431. consume(_END);
  1432. typecanbeforward:=storetypeforwardsallowed;
  1433. symtablestack:=symtable^.next;
  1434. record_dec:=new(precdef,init(symtable));
  1435. end;
  1436. { reads a type definition and returns a pointer to it }
  1437. function read_type(const name : stringid) : pdef;
  1438. function handle_procvar:Pprocvardef;
  1439. var
  1440. sc : pstringcontainer;
  1441. s : string;
  1442. p : pdef;
  1443. varspez : tvarspez;
  1444. procvardef : pprocvardef;
  1445. begin
  1446. procvardef:=new(pprocvardef,init);
  1447. if token=LKLAMMER then
  1448. begin
  1449. consume(LKLAMMER);
  1450. inc(testcurobject);
  1451. repeat
  1452. case token of
  1453. _VAR :
  1454. begin
  1455. consume(_VAR);
  1456. varspez:=vs_var;
  1457. end;
  1458. _CONST :
  1459. begin
  1460. consume(_CONST);
  1461. varspez:=vs_const;
  1462. end;
  1463. else
  1464. varspez:=vs_value;
  1465. end;
  1466. sc:=idlist;
  1467. if (token=COLON) or (varspez=vs_value) then
  1468. begin
  1469. consume(COLON);
  1470. if token=_ARRAY then
  1471. begin
  1472. consume(_ARRAY);
  1473. consume(_OF);
  1474. { define range and type of range }
  1475. p:=new(Parraydef,init(0,-1,s32bitdef));
  1476. { array of const ? }
  1477. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  1478. begin
  1479. consume(_CONST);
  1480. srsym:=nil;
  1481. if assigned(objpasunit) then
  1482. getsymonlyin(objpasunit,'TVARREC');
  1483. if not assigned(srsym) then
  1484. InternalError(1234124);
  1485. Parraydef(p)^.definition:=ptypesym(srsym)^.definition;
  1486. Parraydef(p)^.IsArrayOfConst:=true;
  1487. end
  1488. else
  1489. begin
  1490. { define field type }
  1491. Parraydef(p)^.definition:=single_type(s);
  1492. end;
  1493. end
  1494. else
  1495. p:=single_type(s);
  1496. end
  1497. else
  1498. p:=new(pformaldef,init);
  1499. while not sc^.empty do
  1500. begin
  1501. s:=sc^.get;
  1502. procvardef^.concatdef(p,varspez);
  1503. end;
  1504. dispose(sc,done);
  1505. if token=SEMICOLON then
  1506. consume(SEMICOLON)
  1507. else
  1508. break;
  1509. until false;
  1510. dec(testcurobject);
  1511. consume(RKLAMMER);
  1512. end;
  1513. handle_procvar:=procvardef;
  1514. end;
  1515. var
  1516. hp1,p : pdef;
  1517. aufdef : penumdef;
  1518. aufsym : penumsym;
  1519. ap : parraydef;
  1520. s : stringid;
  1521. l,v,oldaktpackrecords : longint;
  1522. hs : string;
  1523. procedure expr_type;
  1524. var
  1525. pt1,pt2 : ptree;
  1526. begin
  1527. { use of current parsed object ? }
  1528. if (token=ID) and (testcurobject=2) and (curobjectname=pattern) then
  1529. begin
  1530. consume(ID);
  1531. p:=aktobjectdef;
  1532. exit;
  1533. end;
  1534. { we can't accept a equal in type }
  1535. pt1:=comp_expr(not(ignore_equal));
  1536. do_firstpass(pt1);
  1537. if (token=POINTPOINT) then
  1538. begin
  1539. consume(POINTPOINT);
  1540. { get high value of range }
  1541. pt2:=comp_expr(not(ignore_equal));
  1542. do_firstpass(pt2);
  1543. { both must be evaluated to constants now }
  1544. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1545. Message(sym_e_error_in_type_def)
  1546. else
  1547. begin
  1548. { check types }
  1549. if not is_equal(pt1^.resulttype,pt2^.resulttype) then
  1550. Message(type_e_mismatch)
  1551. else
  1552. begin
  1553. { Check bounds }
  1554. if pt2^.value<pt1^.value then
  1555. Message(cg_e_upper_lower_than_lower)
  1556. else
  1557. begin
  1558. { All checks passed, create the new def }
  1559. case pt1^.resulttype^.deftype of
  1560. enumdef : p:=new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value));
  1561. orddef : begin
  1562. if is_char(pt1^.resulttype) then
  1563. p:=new(porddef,init(uchar,pt1^.value,pt2^.value))
  1564. else
  1565. if is_boolean(pt1^.resulttype) then
  1566. p:=new(porddef,init(bool8bit,pt1^.value,pt2^.value))
  1567. else
  1568. p:=new(porddef,init(uauto,pt1^.value,pt2^.value));
  1569. end;
  1570. end;
  1571. end;
  1572. end;
  1573. end;
  1574. disposetree(pt2);
  1575. end
  1576. else
  1577. begin
  1578. { a simple type renaming }
  1579. if (pt1^.treetype=typen) then
  1580. p:=pt1^.resulttype
  1581. else
  1582. Message(sym_e_error_in_type_def);
  1583. end;
  1584. disposetree(pt1);
  1585. end;
  1586. var
  1587. pt : ptree;
  1588. procedure array_dec;
  1589. var
  1590. lowval,
  1591. highval : longint;
  1592. arraytype : pdef;
  1593. begin
  1594. consume(_ARRAY);
  1595. consume(LECKKLAMMER);
  1596. { defaults }
  1597. arraytype:=generrordef;
  1598. lowval:=$80000000;
  1599. highval:=$7fffffff;
  1600. p:=nil;
  1601. repeat
  1602. { read the expression and check it }
  1603. pt:=expr;
  1604. if pt^.treetype=typen then
  1605. begin
  1606. case pt^.resulttype^.deftype of
  1607. enumdef : begin
  1608. lowval:=penumdef(pt^.resulttype)^.min;
  1609. highval:=penumdef(pt^.resulttype)^.max;
  1610. arraytype:=pt^.resulttype;
  1611. end;
  1612. orddef : begin
  1613. case porddef(pt^.resulttype)^.typ of
  1614. s8bit,u8bit,
  1615. s16bit,u16bit,
  1616. s32bit : begin
  1617. lowval:=porddef(pt^.resulttype)^.low;
  1618. highval:=porddef(pt^.resulttype)^.high;
  1619. arraytype:=pt^.resulttype;
  1620. end;
  1621. bool8bit,
  1622. bool16bit,
  1623. bool32bit : begin
  1624. lowval:=0;
  1625. highval:=1;
  1626. arraytype:=pt^.resulttype;
  1627. end;
  1628. uchar : begin
  1629. lowval:=0;
  1630. highval:=255;
  1631. arraytype:=pt^.resulttype;
  1632. end;
  1633. else
  1634. Message(sym_e_error_in_type_def);
  1635. end;
  1636. end;
  1637. else
  1638. Message(sym_e_error_in_type_def);
  1639. end
  1640. end
  1641. else
  1642. begin
  1643. do_firstpass(pt);
  1644. if (pt^.treetype<>rangen) or
  1645. (pt^.left^.treetype<>ordconstn) then
  1646. Message(sym_e_error_in_type_def)
  1647. else
  1648. begin
  1649. {$ifndef GDB}
  1650. if pt^.right^.resulttype=pdef(s32bitdef) then
  1651. pt^.right^.resulttype:=new(porddef,init(s32bit,$80000000,$7fffffff));
  1652. {$endif GDB}
  1653. lowval:=pt^.left^.value;
  1654. highval:=pt^.right^.value;
  1655. arraytype:=pt^.right^.resulttype;
  1656. end;
  1657. end;
  1658. disposetree(pt);
  1659. { create arraydef }
  1660. if p=nil then
  1661. begin
  1662. ap:=new(parraydef,init(lowval,highval,arraytype));
  1663. p:=ap;
  1664. end
  1665. else
  1666. begin
  1667. ap^.definition:=new(parraydef,init(lowval,highval,arraytype));
  1668. ap:=parraydef(ap^.definition);
  1669. end;
  1670. if token=COMMA then
  1671. consume(COMMA)
  1672. else
  1673. break;
  1674. until false;
  1675. consume(RECKKLAMMER);
  1676. consume(_OF);
  1677. hp1:=read_type('');
  1678. { if no error, set element type }
  1679. if assigned(ap) then
  1680. ap^.definition:=hp1;
  1681. end;
  1682. begin
  1683. p:=nil;
  1684. case token of
  1685. _STRING,_FILE:
  1686. p:=single_type(hs);
  1687. LKLAMMER:
  1688. begin
  1689. consume(LKLAMMER);
  1690. { allow negativ value_str }
  1691. l:=-1;
  1692. aufsym := Nil;
  1693. aufdef:=new(penumdef,init);
  1694. repeat
  1695. s:=pattern;
  1696. consume(ID);
  1697. if token=ASSIGNMENT then
  1698. begin
  1699. consume(ASSIGNMENT);
  1700. v:=get_intconst;
  1701. { please leave that a note, allows type save }
  1702. { declarations in the win32 units ! }
  1703. if v<=l then
  1704. Message(parser_n_duplicate_enum);
  1705. l:=v;
  1706. end
  1707. else
  1708. inc(l);
  1709. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1710. if token=COMMA then
  1711. consume(COMMA)
  1712. else
  1713. break;
  1714. until false;
  1715. {aufdef^.max:=l;
  1716. if we allow unordered enums
  1717. this can be wrong
  1718. min and max are now set in tenumsym.init PM }
  1719. p:=aufdef;
  1720. consume(RKLAMMER);
  1721. end;
  1722. _ARRAY:
  1723. array_dec;
  1724. _SET:
  1725. begin
  1726. consume(_SET);
  1727. consume(_OF);
  1728. hp1:=read_type('');
  1729. if assigned(hp1) then
  1730. begin
  1731. case hp1^.deftype of
  1732. { don't forget that min can be negativ PM }
  1733. enumdef : if penumdef(hp1)^.min>=0 then
  1734. p:=new(psetdef,init(hp1,penumdef(hp1)^.max))
  1735. else
  1736. Message(sym_e_ill_type_decl_set);
  1737. orddef : begin
  1738. case porddef(hp1)^.typ of
  1739. uchar : p:=new(psetdef,init(hp1,255));
  1740. u8bit,s8bit,u16bit,s16bit,s32bit :
  1741. begin
  1742. if (porddef(hp1)^.low>=0) then
  1743. p:=new(psetdef,init(hp1,porddef(hp1)^.high))
  1744. else Message(sym_e_ill_type_decl_set);
  1745. end;
  1746. else Message(sym_e_ill_type_decl_set);
  1747. end;
  1748. end;
  1749. else Message(sym_e_ill_type_decl_set);
  1750. end;
  1751. end
  1752. else
  1753. p:=generrordef;
  1754. end;
  1755. CARET:
  1756. begin
  1757. consume(CARET);
  1758. { forwards allowed only inside TYPE statements }
  1759. if typecanbeforward then
  1760. forwardsallowed:=true;
  1761. hp1:=single_type(hs);
  1762. p:=new(ppointerdef,init(hp1));
  1763. {I add big troubles here
  1764. with var p : ^byte in graph.putimage
  1765. because a save_forward was called and
  1766. no resolve forward
  1767. => so the definition was rewritten after
  1768. having been disposed !!
  1769. Strange problems appeared !!!!}
  1770. {Anyhow forwards should only be allowed
  1771. inside a type statement ??
  1772. don't you think so }
  1773. if (lasttypesym<>nil)
  1774. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1775. lasttypesym^.forwardpointer:=ppointerdef(p);
  1776. forwardsallowed:=false;
  1777. end;
  1778. _RECORD:
  1779. p:=record_dec;
  1780. _PACKED:
  1781. begin
  1782. consume(_PACKED);
  1783. if token=_ARRAY then
  1784. array_dec
  1785. else
  1786. begin
  1787. oldaktpackrecords:=aktpackrecords;
  1788. aktpackrecords:=1;
  1789. if token in [_CLASS,_OBJECT] then
  1790. p:=object_dec(name,nil)
  1791. else
  1792. p:=record_dec;
  1793. aktpackrecords:=oldaktpackrecords;
  1794. end;
  1795. end;
  1796. _CLASS,
  1797. _OBJECT:
  1798. p:=object_dec(name,nil);
  1799. _PROCEDURE:
  1800. begin
  1801. consume(_PROCEDURE);
  1802. p:=handle_procvar;
  1803. if token=_OF then
  1804. begin
  1805. consume(_OF);
  1806. consume(_OBJECT);
  1807. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1808. end;
  1809. end;
  1810. _FUNCTION:
  1811. begin
  1812. consume(_FUNCTION);
  1813. p:=handle_procvar;
  1814. consume(COLON);
  1815. pprocvardef(p)^.retdef:=single_type(hs);
  1816. if token=_OF then
  1817. begin
  1818. consume(_OF);
  1819. consume(_OBJECT);
  1820. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1821. end;
  1822. end;
  1823. else
  1824. expr_type;
  1825. end;
  1826. if p=nil then
  1827. p:=generrordef;
  1828. read_type:=p;
  1829. end;
  1830. { reads a type declaration to the symbol table }
  1831. procedure type_dec;
  1832. var
  1833. typename : stringid;
  1834. newtype : ptypesym;
  1835. {$ifdef dummy}
  1836. olddef,newdef : pdef;
  1837. s : string;
  1838. {$endif dummy}
  1839. begin
  1840. block_type:=bt_type;
  1841. consume(_TYPE);
  1842. typecanbeforward:=true;
  1843. repeat
  1844. typename:=pattern;
  1845. consume(ID);
  1846. consume(EQUAL);
  1847. { here you loose the strictness of pascal
  1848. for which a redefinition like
  1849. childtype = parenttype;
  1850. child2type = parenttype;
  1851. does not make the two child types equal !!
  1852. here all vars from childtype and child2type
  1853. get the definition of parenttype !! }
  1854. {$ifdef testequaltype}
  1855. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1856. begin
  1857. olddef := single_type(s);
  1858. { make a clone of olddef }
  1859. { is that ok ??? }
  1860. getmem(newdef,SizeOf(olddef));
  1861. move(olddef^,newdef^,SizeOf(olddef));
  1862. newtype:=new(ptypesym,init(typename,newdef));
  1863. symtablestack^.insert(newtype);
  1864. end
  1865. else
  1866. {$endif testequaltype}
  1867. begin
  1868. getsym(typename,false);
  1869. { check if it is the definition of a forward defined class }
  1870. if assigned(srsym) and (token=_CLASS) and
  1871. (srsym^.typ=typesym) and
  1872. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1873. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1874. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_is_class)<>0) then
  1875. begin
  1876. { we can ignore the result }
  1877. { the definition is modified }
  1878. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1879. newtype:=ptypesym(srsym);
  1880. end
  1881. else
  1882. begin
  1883. newtype:=new(ptypesym,init(typename,read_type(typename)));
  1884. { load newtype with the new pointer to the inserted type
  1885. because it can be an already defined forwarded type !! }
  1886. newtype:=ptypesym(symtablestack^.insert(newtype));
  1887. end;
  1888. end;
  1889. consume(SEMICOLON);
  1890. if assigned(newtype^.definition) and (newtype^.definition^.deftype=procvardef) then
  1891. parse_var_proc_directives(newtype);
  1892. until token<>ID;
  1893. typecanbeforward:=false;
  1894. {$ifdef tp}
  1895. symtablestack^.foreach(testforward_type);
  1896. {$else}
  1897. symtablestack^.foreach(@testforward_type);
  1898. {$endif}
  1899. resolve_forwards;
  1900. block_type:=bt_general;
  1901. end;
  1902. procedure var_dec;
  1903. { parses varaible declarations and inserts them in }
  1904. { the top symbol table of symtablestack }
  1905. begin
  1906. consume(_VAR);
  1907. read_var_decs(false,false);
  1908. end;
  1909. procedure Not_supported_for_inline(t : ttoken);
  1910. begin
  1911. if assigned(aktprocsym) and
  1912. ((aktprocsym^.definition^.options and poinline)<>0) then
  1913. Begin
  1914. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1915. Message(parser_w_inlining_disabled);
  1916. aktprocsym^.definition^.options:= aktprocsym^.definition^.options and not poinline;
  1917. End;
  1918. end;
  1919. procedure read_declarations(islibrary : boolean);
  1920. begin
  1921. repeat
  1922. case token of
  1923. _LABEL:
  1924. begin
  1925. Not_supported_for_inline(token);
  1926. label_dec;
  1927. end;
  1928. _CONST:
  1929. begin
  1930. Not_supported_for_inline(token);
  1931. const_dec;
  1932. end;
  1933. _TYPE:
  1934. begin
  1935. Not_supported_for_inline(token);
  1936. type_dec;
  1937. end;
  1938. _VAR:
  1939. var_dec;
  1940. _CONSTRUCTOR,_DESTRUCTOR,
  1941. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1942. begin
  1943. Not_supported_for_inline(token);
  1944. read_proc;
  1945. end;
  1946. _EXPORTS:
  1947. begin
  1948. Not_supported_for_inline(token);
  1949. { here we should be at lexlevel 1, no ? PM }
  1950. if (lexlevel<>main_program_level) or not islibrary then
  1951. begin
  1952. Message(parser_e_syntax_error);
  1953. consume_all_until(SEMICOLON);
  1954. end
  1955. else if islibrary then
  1956. read_exports;
  1957. end
  1958. else break;
  1959. end;
  1960. until false;
  1961. end;
  1962. procedure read_interface_declarations;
  1963. begin
  1964. {Since the body is now parsed at lexlevel 1, and the declarations
  1965. must be parsed at the same lexlevel we increase the lexlevel.}
  1966. inc(lexlevel);
  1967. repeat
  1968. case token of
  1969. _CONST : const_dec;
  1970. _TYPE : type_dec;
  1971. _VAR : var_dec;
  1972. _FUNCTION,
  1973. _PROCEDURE,
  1974. _OPERATOR : read_proc;
  1975. else
  1976. break;
  1977. end;
  1978. until false;
  1979. dec(lexlevel);
  1980. end;
  1981. end.
  1982. {
  1983. $Log$
  1984. Revision 1.84 1998-11-17 10:40:15 peter
  1985. * H+ fixes
  1986. Revision 1.83 1998/11/16 11:28:59 pierre
  1987. * stackcheck removed for i386_win32
  1988. * exportlist does not crash at least !!
  1989. (was need for tests dir !)z
  1990. Revision 1.82 1998/11/16 10:18:07 peter
  1991. * fixes for ansistrings
  1992. Revision 1.81 1998/11/13 15:40:22 pierre
  1993. + added -Se in Makefile cvstest target
  1994. + lexlevel cleanup
  1995. normal_function_level main_program_level and unit_init_level defined
  1996. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  1997. (test added in code !)
  1998. * -Un option was wrong
  1999. * _FAIL and _SELF only keyword inside
  2000. constructors and methods respectively
  2001. Revision 1.80 1998/11/13 10:18:09 peter
  2002. + nil constants
  2003. Revision 1.79 1998/11/05 12:02:51 peter
  2004. * released useansistring
  2005. * removed -Sv, its now available in fpc modes
  2006. Revision 1.78 1998/10/27 13:45:33 pierre
  2007. * classes get a vmt allways
  2008. * better error info (tried to remove
  2009. several error strings introduced by the tpexcept handling)
  2010. Revision 1.77 1998/10/26 22:58:20 florian
  2011. * new introduded problem with classes fix, the parent class wasn't set
  2012. correct, if the class was defined forward before
  2013. Revision 1.76 1998/10/25 23:31:18 peter
  2014. * procvar parsing updated just like psub.pas routine
  2015. Revision 1.75 1998/10/21 08:39:59 florian
  2016. + ansistring operator +
  2017. + $h and string[n] for n>255 added
  2018. * small problem with TP fixed
  2019. Revision 1.74 1998/10/20 13:09:13 peter
  2020. * fixed object(unknown) crash
  2021. Revision 1.73 1998/10/19 08:54:56 pierre
  2022. * wrong stabs info corrected once again !!
  2023. + variable vmt offset with vmt field only if required
  2024. implemented now !!!
  2025. Revision 1.72 1998/10/16 13:12:51 pierre
  2026. * added vmt_offsets in destructors code also !!!
  2027. * vmt_offset code for m68k
  2028. Revision 1.71 1998/10/15 15:13:25 pierre
  2029. + added oo_hasconstructor and oo_hasdestructor
  2030. for objects options
  2031. Revision 1.70 1998/10/13 13:10:22 peter
  2032. * new style for m68k/i386 infos and enums
  2033. Revision 1.69 1998/10/09 12:07:49 pierre
  2034. * typo error for propertyparas dispose corrected
  2035. Revision 1.68 1998/10/09 11:47:54 pierre
  2036. * still more memory leaks fixes !!
  2037. Revision 1.67 1998/10/08 13:48:46 peter
  2038. * fixed memory leaks for do nothing source
  2039. * fixed unit interdependency
  2040. Revision 1.66 1998/10/06 20:43:31 peter
  2041. * fixed set of bugs. like set of false..true set of #1..#255 and
  2042. set of #1..true which was allowed
  2043. Revision 1.65 1998/10/05 22:43:35 peter
  2044. * commited the wrong file :(
  2045. Revision 1.64 1998/10/05 21:33:24 peter
  2046. * fixed 161,165,166,167,168
  2047. Revision 1.63 1998/10/05 13:57:13 peter
  2048. * crash preventions
  2049. Revision 1.62 1998/10/02 17:06:02 peter
  2050. * better error message for unresolved forward types
  2051. Revision 1.61 1998/10/02 09:23:24 peter
  2052. * fixed error msg with type l=<var>
  2053. * block_type bt_const is now set in read_const_dec
  2054. Revision 1.60 1998/09/30 07:40:33 florian
  2055. * better error recovering
  2056. Revision 1.59 1998/09/26 17:45:33 peter
  2057. + idtoken and only one token table
  2058. Revision 1.58 1998/09/25 00:04:01 florian
  2059. * problems when calling class methods fixed
  2060. Revision 1.57 1998/09/24 23:49:09 peter
  2061. + aktmodeswitches
  2062. Revision 1.56 1998/09/23 15:39:09 pierre
  2063. * browser bugfixes
  2064. was adding a reference when looking for the symbol
  2065. if -bSYM_NAME was used
  2066. Revision 1.55 1998/09/21 13:24:44 daniel
  2067. * Memory leak fixed.
  2068. Revision 1.54 1998/09/17 13:41:16 pierre
  2069. sizeof(TPOINT) problem
  2070. Revision 1.53.2.1 1998/09/17 13:12:09 pierre
  2071. * virtual destructor did not set oo_hasvirtual
  2072. (detected with the sizeof(TPoint) problem
  2073. * genloadcallnode was missing
  2074. Revision 1.53 1998/09/09 11:50:52 pierre
  2075. * forward def are not put in record or objects
  2076. + added check for forwards also in record and objects
  2077. * dummy parasymtable for unit initialization removed from
  2078. symtable stack
  2079. Revision 1.52 1998/09/07 23:10:22 florian
  2080. * a lot of stuff fixed regarding rtti and publishing of properties,
  2081. basics should now work
  2082. Revision 1.51 1998/09/07 19:33:22 florian
  2083. + some stuff for property rtti added:
  2084. - NameIndex of the TPropInfo record is now written correctly
  2085. - the DEFAULT/NODEFAULT keyword is supported now
  2086. - the default value and the storedsym/def are now written to
  2087. the PPU fiel
  2088. Revision 1.50 1998/09/07 18:46:08 peter
  2089. * update smartlinking, uses getdatalabel
  2090. * renamed ptree.value vars to value_str,value_real,value_set
  2091. Revision 1.49 1998/09/07 17:37:00 florian
  2092. * first fixes for published properties
  2093. Revision 1.48 1998/09/04 08:42:02 peter
  2094. * updated some error messages
  2095. Revision 1.47 1998/09/03 16:03:18 florian
  2096. + rtti generation
  2097. * init table generation changed
  2098. Revision 1.46 1998/09/01 17:39:48 peter
  2099. + internal constant functions
  2100. Revision 1.45 1998/08/31 12:20:28 peter
  2101. * fixed array_dec when unknown type was used
  2102. Revision 1.44 1998/08/28 10:57:01 peter
  2103. * removed warnings
  2104. Revision 1.43 1998/08/25 13:09:25 pierre
  2105. * corrected mangling sheme :
  2106. cvar add Cprefix to the mixed case name whereas
  2107. export or public use direct name
  2108. Revision 1.42 1998/08/25 12:42:41 pierre
  2109. * CDECL changed to CVAR for variables
  2110. specifications are read in structures also
  2111. + started adding GPC compatibility mode ( option -Sp)
  2112. * names changed to lowercase
  2113. Revision 1.41 1998/08/23 21:04:36 florian
  2114. + rtti generation for classes added
  2115. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2116. Revision 1.40 1998/08/21 15:48:58 pierre
  2117. * more cdecl chagnes
  2118. - better line info
  2119. - changes the definition options of a procvar
  2120. if it is a unnamed type
  2121. Revision 1.39 1998/08/19 00:42:40 peter
  2122. + subrange types for enums
  2123. + checking for bounds type with ranges
  2124. Revision 1.38 1998/08/12 19:20:39 peter
  2125. + public is the same as export for c_vars
  2126. * a exported/public c_var incs now the refcount
  2127. Revision 1.37 1998/08/11 15:31:38 peter
  2128. * write extended to ppu file
  2129. * new version 0.99.7
  2130. Revision 1.36 1998/08/10 14:50:09 peter
  2131. + localswitches, moduleswitches, globalswitches splitting
  2132. Revision 1.35 1998/07/26 21:59:00 florian
  2133. + better support for switch $H
  2134. + index access to ansi strings added
  2135. + assigment of data (records/arrays) containing ansi strings
  2136. Revision 1.34 1998/07/20 22:17:15 florian
  2137. * hex constants in numeric char (#$54#$43 ...) are now allowed
  2138. * there was a bug in record_var_dec which prevents the used
  2139. of nested variant records (for example drivers.tevent of tv)
  2140. Revision 1.33 1998/07/18 17:11:11 florian
  2141. + ansi string constants fixed
  2142. + switch $H partial implemented
  2143. Revision 1.32 1998/07/14 21:46:50 peter
  2144. * updated messages file
  2145. Revision 1.31 1998/07/14 14:46:53 peter
  2146. * released NEWINPUT
  2147. Revision 1.30 1998/07/10 00:00:00 peter
  2148. * fixed ttypesym bug finally
  2149. * fileinfo in the symtable and better using for unused vars
  2150. Revision 1.29 1998/06/25 14:04:21 peter
  2151. + internal inc/dec
  2152. Revision 1.28 1998/06/24 12:26:45 peter
  2153. * stricter var parsing like tp7 and some optimizes with directive
  2154. parsing
  2155. Revision 1.27 1998/06/12 16:15:34 pierre
  2156. * external name 'C_var';
  2157. export name 'intern_C_var';
  2158. cdecl;
  2159. cdecl;external;
  2160. are now supported only with -Sv switch
  2161. Revision 1.25 1998/06/09 16:01:45 pierre
  2162. + added procedure directive parsing for procvars
  2163. (accepted are popstack cdecl and pascal)
  2164. + added C vars with the following syntax
  2165. var C calias 'true_c_name';(can be followed by external)
  2166. reason is that you must add the Cprefix
  2167. which is target dependent
  2168. Revision 1.24 1998/06/05 14:37:32 pierre
  2169. * fixes for inline for operators
  2170. * inline procedure more correctly restricted
  2171. Revision 1.23 1998/06/04 23:51:50 peter
  2172. * m68k compiles
  2173. + .def file creation moved to gendef.pas so it could also be used
  2174. for win32
  2175. Revision 1.22 1998/06/03 22:48:59 peter
  2176. + wordbool,longbool
  2177. * rename bis,von -> high,low
  2178. * moved some systemunit loading/creating to psystem.pas
  2179. Revision 1.21 1998/06/03 22:14:19 florian
  2180. * problem with sizes of classes fixed (if the anchestor was declared
  2181. forward, the compiler doesn't update the child classes size)
  2182. Revision 1.20 1998/05/28 14:35:54 peter
  2183. * nicer error message when no id is used after var
  2184. Revision 1.19 1998/05/23 01:21:19 peter
  2185. + aktasmmode, aktoptprocessor, aktoutputformat
  2186. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2187. + $LIBNAME to set the library name where the unit will be put in
  2188. * splitted cgi386 a bit (codeseg to large for bp7)
  2189. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2190. Revision 1.18 1998/05/20 09:42:35 pierre
  2191. + UseTokenInfo now default
  2192. * unit in interface uses and implementation uses gives error now
  2193. * only one error for unknown symbol (uses lastsymknown boolean)
  2194. the problem came from the label code !
  2195. + first inlined procedures and function work
  2196. (warning there might be allowed cases were the result is still wrong !!)
  2197. * UseBrower updated gives a global list of all position of all used symbols
  2198. with switch -gb
  2199. Revision 1.17 1998/05/11 13:07:55 peter
  2200. + $ifdef NEWPPU for the new ppuformat
  2201. + $define GDB not longer required
  2202. * removed all warnings and stripped some log comments
  2203. * no findfirst/findnext anymore to remove smartlink *.o files
  2204. Revision 1.16 1998/05/05 12:05:42 florian
  2205. * problems with properties fixed
  2206. * crash fixed: i:=l when i and l are undefined, was a problem with
  2207. implementation of private/protected
  2208. Revision 1.15 1998/05/01 09:01:23 florian
  2209. + correct semantics of private and protected
  2210. * small fix in variable scope:
  2211. a id can be used in a parameter list of a method, even it is used in
  2212. an anchestor class as field id
  2213. Revision 1.14 1998/05/01 07:43:56 florian
  2214. + basics for rtti implemented
  2215. + switch $m (generate rtti for published sections)
  2216. Revision 1.13 1998/04/30 15:59:41 pierre
  2217. * GDB works again better :
  2218. correct type info in one pass
  2219. + UseTokenInfo for better source position
  2220. * fixed one remaining bug in scanner for line counts
  2221. * several little fixes
  2222. Revision 1.12 1998/04/29 10:33:57 pierre
  2223. + added some code for ansistring (not complete nor working yet)
  2224. * corrected operator overloading
  2225. * corrected nasm output
  2226. + started inline procedures
  2227. + added starstarn : use ** for exponentiation (^ gave problems)
  2228. + started UseTokenInfo cond to get accurate positions
  2229. Revision 1.11 1998/04/28 11:45:52 florian
  2230. * make it compilable with TP
  2231. + small COM problems solved to compile classes.pp
  2232. Revision 1.10 1998/04/27 23:10:28 peter
  2233. + new scanner
  2234. * $makelib -> if smartlink
  2235. * small filename fixes pmodule.setfilename
  2236. * moved import from files.pas -> import.pas
  2237. Revision 1.9 1998/04/10 21:36:56 florian
  2238. + some stuff to support method pointers (procedure of object) added
  2239. (declaration, parameter handling)
  2240. Revision 1.8 1998/04/10 15:39:48 florian
  2241. * more fixes to get classes.pas compiled
  2242. Revision 1.7 1998/04/09 23:02:15 florian
  2243. * small problems solved to get remake3 work
  2244. Revision 1.6 1998/04/09 22:16:35 florian
  2245. * problem with previous REGALLOC solved
  2246. * improved property support
  2247. Revision 1.5 1998/04/08 14:59:20 florian
  2248. * problem with new expr_type solved
  2249. Revision 1.4 1998/04/08 10:26:09 florian
  2250. * correct error handling of virtual constructors
  2251. * problem with new type declaration handling fixed
  2252. Revision 1.3 1998/04/07 22:45:05 florian
  2253. * bug0092, bug0115 and bug0121 fixed
  2254. + packed object/class/array
  2255. Revision 1.2 1998/04/05 13:58:35 peter
  2256. * fixed the -Ss bug
  2257. + warning for Virtual constructors
  2258. * helppages updated with -TGO32V1
  2259. }