2
0

pdecl.pas 87 KB

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