pdecl.pas 90 KB

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