pdecl.pas 88 KB

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