pdecl.pas 86 KB

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