pdecl.pas 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  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 (cs_gpc_compatible in aktmoduleswitches) 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 cs_tp_compatible in aktmoduleswitches 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. aktclass:=new(pobjectdef,init(n,childof));
  1119. end;
  1120. end
  1121. else 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. if (pattern='PRIVATE') then
  1152. begin
  1153. consume(ID);
  1154. actmembertype:=sp_private;
  1155. current_object_option:=sp_private;
  1156. end
  1157. else
  1158. if (pattern='PROTECTED') then
  1159. begin
  1160. consume(ID);
  1161. current_object_option:=sp_protected;
  1162. actmembertype:=sp_protected;
  1163. end
  1164. else
  1165. if (pattern='PUBLIC') then
  1166. begin
  1167. consume(ID);
  1168. current_object_option:=sp_public;
  1169. actmembertype:=sp_public;
  1170. end
  1171. else
  1172. if (pattern='PUBLISHED') then
  1173. begin
  1174. if (aktclass^.options and oo_can_have_published)=0 then
  1175. Message(parser_e_cant_have_published);
  1176. consume(ID);
  1177. current_object_option:=sp_published;
  1178. actmembertype:=sp_published;
  1179. end
  1180. else
  1181. read_var_decs(false,true);
  1182. end;
  1183. _PROPERTY : property_dec;
  1184. _PROCEDURE,
  1185. _FUNCTION,
  1186. _CLASS : begin
  1187. oldparse_only:=parse_only;
  1188. parse_only:=true;
  1189. proc_head;
  1190. parse_only:=oldparse_only;
  1191. if (token=ID) then
  1192. begin
  1193. if (pattern='VIRTUAL') or (pattern='DYNAMIC') then
  1194. begin
  1195. if actmembertype=sp_private then
  1196. Message(parser_w_priv_meth_not_virtual);
  1197. consume(ID);
  1198. consume(SEMICOLON);
  1199. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1200. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1201. end
  1202. else
  1203. if (pattern='OVERRIDE') then
  1204. begin
  1205. consume(ID);
  1206. consume(SEMICOLON);
  1207. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1208. pooverridingmethod or povirtualmethod;
  1209. end;
  1210. { Delphi II extension }
  1211. if (pattern='ABSTRACT') then
  1212. begin
  1213. consume(ID);
  1214. consume(SEMICOLON);
  1215. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  1216. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or poabstractmethod
  1217. else
  1218. Message(parser_e_only_virtual_methods_abstract);
  1219. { the method is defined }
  1220. aktprocsym^.definition^.forwarddef:=false;
  1221. end;
  1222. if (cs_static_keyword in aktglobalswitches) and (pattern='STATIC') then
  1223. begin
  1224. consume(ID);
  1225. consume(SEMICOLON);
  1226. aktprocsym^.properties:=aktprocsym^.properties or sp_static;
  1227. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or postaticmethod;
  1228. end;
  1229. end;
  1230. end;
  1231. _CONSTRUCTOR : begin
  1232. if actmembertype<>sp_public then
  1233. Message(parser_w_constructor_should_be_public);
  1234. oldparse_only:=parse_only;
  1235. parse_only:=true;
  1236. constructor_head;
  1237. parse_only:=oldparse_only;
  1238. if (token=ID) then
  1239. begin
  1240. if (pattern='VIRTUAL') or (pattern='DYNAMIC') then
  1241. begin
  1242. consume(ID);
  1243. consume(SEMICOLON);
  1244. if not(aktclass^.isclass) then
  1245. Message(parser_e_constructor_cannot_be_not_virtual)
  1246. else
  1247. begin
  1248. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1249. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1250. end;
  1251. end
  1252. else
  1253. if (pattern='OVERRIDE') then
  1254. begin
  1255. consume(ID);
  1256. consume(SEMICOLON);
  1257. if (aktclass^.options and oois_class=0) then
  1258. Message(parser_e_constructor_cannot_be_not_virtual)
  1259. else
  1260. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1261. pooverridingmethod or povirtualmethod;
  1262. end;
  1263. end;
  1264. end;
  1265. _DESTRUCTOR : begin
  1266. if there_is_a_destructor then
  1267. Message(parser_n_only_one_destructor);
  1268. there_is_a_destructor:=true;
  1269. if actmembertype<>sp_public then
  1270. Message(parser_w_destructor_should_be_public);
  1271. oldparse_only:=parse_only;
  1272. parse_only:=true;
  1273. destructor_head;
  1274. parse_only:=oldparse_only;
  1275. if (token=ID) then
  1276. begin
  1277. if (pattern='VIRTUAL') or (pattern='DYNAMIC') then
  1278. begin
  1279. consume(ID);
  1280. consume(SEMICOLON);
  1281. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1282. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1283. end
  1284. else
  1285. if (pattern='OVERRIDE') then
  1286. begin
  1287. consume(ID);
  1288. consume(SEMICOLON);
  1289. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1290. pooverridingmethod or povirtualmethod;
  1291. end;
  1292. end;
  1293. end;
  1294. _END : begin
  1295. consume(_END);
  1296. break;
  1297. end;
  1298. else
  1299. consume(ID); { Give a ident expected message, like tp7 }
  1300. end;
  1301. until false;
  1302. current_object_option:=sp_public;
  1303. end;
  1304. testcurobject:=0;
  1305. curobjectname:='';
  1306. typecanbeforward:=storetypeforwardsallowed;
  1307. if (cs_smartlink in aktmoduleswitches) then
  1308. datasegment^.concat(new(pai_cut,init));
  1309. { write extended info for classes }
  1310. if is_a_class then
  1311. begin
  1312. if (aktclass^.options and oo_can_have_published)<>0 then
  1313. aktclass^.generate_rtti;
  1314. { write class name }
  1315. getlabel(classnamelabel);
  1316. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1317. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.name^))));
  1318. datasegment^.concat(new(pai_string,init(aktclass^.name^)));
  1319. { interface table }
  1320. datasegment^.concat(new(pai_const,init_32bit(0)));
  1321. { auto table }
  1322. datasegment^.concat(new(pai_const,init_32bit(0)));
  1323. { inittable for con-/destruction }
  1324. if aktclass^.needs_inittable then
  1325. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(aktclass^.get_inittable_label)))))
  1326. else
  1327. datasegment^.concat(new(pai_const,init_32bit(0)));
  1328. { pointer to type info of published section }
  1329. if (aktclass^.options and oo_can_have_published)<>0 then
  1330. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.rtti_name))))
  1331. else
  1332. datasegment^.concat(new(pai_const,init_32bit(0)));
  1333. { pointer to field table }
  1334. datasegment^.concat(new(pai_const,init_32bit(0)));
  1335. { pointer to method table }
  1336. datasegment^.concat(new(pai_const,init_32bit(0)));
  1337. { pointer to dynamic table }
  1338. datasegment^.concat(new(pai_const,init_32bit(0)));
  1339. { pointer to class name string }
  1340. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(classnamelabel)))));
  1341. end;
  1342. {$ifdef GDB}
  1343. { generate the VMT }
  1344. if cs_debuginfo in aktmoduleswitches then
  1345. begin
  1346. do_count_dbx:=true;
  1347. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1348. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1349. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1350. end;
  1351. {$endif GDB}
  1352. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  1353. { determine the size with publicsyms^.datasize, because }
  1354. { size gives back 4 for CLASSes }
  1355. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  1356. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  1357. { write pointer to parent VMT, this isn't implemented in TP }
  1358. { but this is not used in FPC ? (PM) }
  1359. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1360. if assigned(aktclass^.childof) then
  1361. begin
  1362. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  1363. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  1364. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  1365. end
  1366. else
  1367. datasegment^.concat(new(pai_const,init_32bit(0)));
  1368. { this generates the entries }
  1369. genvmt(aktclass);
  1370. { restore old state }
  1371. symtablestack:=symtablestack^.next;
  1372. procinfo._class:=nil;
  1373. {Restore the aktprocsym.}
  1374. aktprocsym:=oldprocsym;
  1375. object_dec:=aktclass;
  1376. end;
  1377. { reads a record declaration }
  1378. function record_dec : pdef;
  1379. var
  1380. symtable : psymtable;
  1381. storetypeforwardsallowed : boolean;
  1382. begin
  1383. symtable:=new(psymtable,init(recordsymtable));
  1384. symtable^.next:=symtablestack;
  1385. symtablestack:=symtable;
  1386. consume(_RECORD);
  1387. storetypeforwardsallowed:=typecanbeforward;
  1388. if cs_tp_compatible in aktmoduleswitches then
  1389. typecanbeforward:=false;
  1390. read_var_decs(true,false);
  1391. { may be scale record size to a size of n*4 ? }
  1392. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  1393. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  1394. consume(_END);
  1395. typecanbeforward:=storetypeforwardsallowed;
  1396. symtablestack:=symtable^.next;
  1397. record_dec:=new(precdef,init(symtable));
  1398. end;
  1399. { search in symtablestack used, but not defined type }
  1400. procedure testforward_types(p : psym);{$ifndef FPC}far;{$endif}
  1401. var
  1402. recsymtable : psymtable;
  1403. begin
  1404. if (p^.typ=typesym) then
  1405. if ((p^.properties and sp_forwarddef)<>0) then
  1406. Message(sym_e_type_id_not_defined)
  1407. else if (ptypesym(p)^.definition^.deftype=recorddef) or
  1408. (ptypesym(p)^.definition^.deftype=objectdef) then
  1409. begin
  1410. if (ptypesym(p)^.definition^.deftype=recorddef) then
  1411. recsymtable:=precdef(ptypesym(p)^.definition)^.symtable
  1412. else
  1413. recsymtable:=pobjectdef(ptypesym(p)^.definition)^.publicsyms;
  1414. {$ifdef tp}
  1415. recsymtable^.foreach(testforward_types);
  1416. {$else}
  1417. recsymtable^.foreach(@testforward_types);
  1418. {$endif}
  1419. end;
  1420. end;
  1421. { reads a type definition and returns a pointer to it }
  1422. function read_type(const name : stringid) : pdef;
  1423. function handle_procvar:Pprocvardef;
  1424. var
  1425. sc : pstringcontainer;
  1426. s : string;
  1427. p : pdef;
  1428. varspez : tvarspez;
  1429. procvardef : pprocvardef;
  1430. begin
  1431. procvardef:=new(pprocvardef,init);
  1432. if token=LKLAMMER then
  1433. begin
  1434. consume(LKLAMMER);
  1435. inc(testcurobject);
  1436. repeat
  1437. if token=_VAR then
  1438. begin
  1439. consume(_VAR);
  1440. varspez:=vs_var;
  1441. end
  1442. else if token=_CONST then
  1443. begin
  1444. consume(_CONST);
  1445. varspez:=vs_const;
  1446. end
  1447. else varspez:=vs_value;
  1448. sc:=idlist;
  1449. if token=COLON then
  1450. begin
  1451. consume(COLON);
  1452. if token=_ARRAY then
  1453. begin
  1454. {
  1455. if (varspez<>vs_const) and
  1456. (varspez<>vs_var) then
  1457. begin
  1458. varspez:=vs_const;
  1459. Message(parser_e_illegal_open_parameter);
  1460. end;
  1461. }
  1462. consume(_ARRAY);
  1463. consume(_OF);
  1464. { define range and type of range }
  1465. p:=new(parraydef,init(0,-1,s32bitdef));
  1466. { define field type }
  1467. parraydef(p)^.definition:=single_type(s);
  1468. end
  1469. else
  1470. p:=single_type(s);
  1471. end
  1472. else
  1473. p:=new(pformaldef,init);
  1474. s:=sc^.get;
  1475. while s<>'' do
  1476. begin
  1477. procvardef^.concatdef(p,varspez);
  1478. s:=sc^.get;
  1479. end;
  1480. dispose(sc,done);
  1481. if token=SEMICOLON then consume(SEMICOLON)
  1482. else break;
  1483. until false;
  1484. dec(testcurobject);
  1485. consume(RKLAMMER);
  1486. end;
  1487. handle_procvar:=procvardef;
  1488. end;
  1489. var
  1490. hp1,p : pdef;
  1491. aufdef : penumdef;
  1492. aufsym : penumsym;
  1493. ap : parraydef;
  1494. s : stringid;
  1495. l,v,oldaktpackrecords : longint;
  1496. hs : string;
  1497. procedure expr_type;
  1498. var
  1499. pt1,pt2 : ptree;
  1500. begin
  1501. p:=nil;
  1502. { use of current parsed object ? }
  1503. if (token=ID) and (testcurobject=2) and (curobjectname=pattern) then
  1504. begin
  1505. consume(ID);
  1506. p:=aktobjectdef;
  1507. exit;
  1508. end;
  1509. { we can't accept a equal in type }
  1510. pt1:=comp_expr(not(ignore_equal));
  1511. if (pt1^.treetype=typen) and (token<>POINTPOINT) then
  1512. begin
  1513. { a simple type renaming }
  1514. p:=pt1^.resulttype;
  1515. end
  1516. else
  1517. begin
  1518. { range type }
  1519. consume(POINTPOINT);
  1520. { range type declaration }
  1521. do_firstpass(pt1);
  1522. pt2:=comp_expr(not(ignore_equal));
  1523. do_firstpass(pt2);
  1524. { valid expression ? }
  1525. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1526. Message(sym_e_error_in_type_def)
  1527. else
  1528. begin
  1529. { Check bounds }
  1530. if pt2^.value<pt1^.value then
  1531. Message(cg_e_upper_lower_than_lower)
  1532. else
  1533. begin
  1534. { is one an enum ? }
  1535. if (pt1^.resulttype^.deftype=enumdef) or (pt2^.resulttype^.deftype=enumdef) then
  1536. begin
  1537. { both must be the have the same (enumdef) definition, else its a type mismatch }
  1538. if (pt1^.resulttype=pt2^.resulttype) then
  1539. p:=new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value))
  1540. else
  1541. Message(type_e_mismatch);
  1542. end
  1543. else
  1544. begin
  1545. { both must be are orddefs, create an uauto orddef }
  1546. p:=new(porddef,init(uauto,pt1^.value,pt2^.value));
  1547. end;
  1548. end;
  1549. end;
  1550. disposetree(pt2);
  1551. end;
  1552. disposetree(pt1);
  1553. end;
  1554. var
  1555. pt : ptree;
  1556. procedure array_dec;
  1557. var
  1558. lowval,
  1559. highval : longint;
  1560. arraytype : pdef;
  1561. begin
  1562. consume(_ARRAY);
  1563. consume(LECKKLAMMER);
  1564. { defaults }
  1565. arraytype:=generrordef;
  1566. lowval:=$80000000;
  1567. highval:=$7fffffff;
  1568. p:=nil;
  1569. repeat
  1570. { read the expression and check it }
  1571. pt:=expr;
  1572. if pt^.treetype=typen then
  1573. begin
  1574. case pt^.resulttype^.deftype of
  1575. enumdef : begin
  1576. lowval:=penumdef(pt^.resulttype)^.min;
  1577. highval:=penumdef(pt^.resulttype)^.max;
  1578. arraytype:=pt^.resulttype;
  1579. end;
  1580. orddef : begin
  1581. case porddef(pt^.resulttype)^.typ of
  1582. s8bit,u8bit,
  1583. s16bit,u16bit,
  1584. s32bit : begin
  1585. lowval:=porddef(pt^.resulttype)^.low;
  1586. highval:=porddef(pt^.resulttype)^.high;
  1587. arraytype:=pt^.resulttype;
  1588. end;
  1589. bool8bit,
  1590. bool16bit,
  1591. bool32bit : begin
  1592. lowval:=0;
  1593. highval:=1;
  1594. arraytype:=pt^.resulttype;
  1595. end;
  1596. uchar : begin
  1597. lowval:=0;
  1598. highval:=255;
  1599. arraytype:=pt^.resulttype;
  1600. end;
  1601. else
  1602. Message(sym_e_error_in_type_def);
  1603. end;
  1604. end;
  1605. else
  1606. Message(sym_e_error_in_type_def);
  1607. end
  1608. end
  1609. else
  1610. begin
  1611. do_firstpass(pt);
  1612. if (pt^.treetype<>rangen) or
  1613. (pt^.left^.treetype<>ordconstn) then
  1614. Message(sym_e_error_in_type_def)
  1615. else
  1616. begin
  1617. {$ifndef GDB}
  1618. if pt^.right^.resulttype=pdef(s32bitdef) then
  1619. pt^.right^.resulttype:=new(porddef,init(s32bit,$80000000,$7fffffff));
  1620. {$endif GDB}
  1621. lowval:=pt^.left^.value;
  1622. highval:=pt^.right^.value;
  1623. arraytype:=pt^.right^.resulttype;
  1624. end;
  1625. end;
  1626. disposetree(pt);
  1627. { create arraydef }
  1628. if p=nil then
  1629. begin
  1630. ap:=new(parraydef,init(lowval,highval,arraytype));
  1631. p:=ap;
  1632. end
  1633. else
  1634. begin
  1635. ap^.definition:=new(parraydef,init(lowval,highval,arraytype));
  1636. ap:=parraydef(ap^.definition);
  1637. end;
  1638. if token=COMMA then
  1639. consume(COMMA)
  1640. else
  1641. break;
  1642. until false;
  1643. consume(RECKKLAMMER);
  1644. consume(_OF);
  1645. hp1:=read_type('');
  1646. { if no error, set element type }
  1647. if assigned(ap) then
  1648. ap^.definition:=hp1;
  1649. end;
  1650. begin
  1651. case token of
  1652. _STRING,_FILE:
  1653. p:=single_type(hs);
  1654. LKLAMMER:
  1655. begin
  1656. consume(LKLAMMER);
  1657. { allow negativ value_str }
  1658. l:=-1;
  1659. aufsym := Nil;
  1660. aufdef:=new(penumdef,init);
  1661. repeat
  1662. s:=pattern;
  1663. consume(ID);
  1664. if token=ASSIGNMENT then
  1665. begin
  1666. consume(ASSIGNMENT);
  1667. v:=get_intconst;
  1668. { please leave that a note, allows type save }
  1669. { declarations in the win32 units ! }
  1670. if v<=l then
  1671. Message(parser_n_duplicate_enum);
  1672. l:=v;
  1673. end
  1674. else
  1675. inc(l);
  1676. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1677. if token=COMMA then
  1678. consume(COMMA)
  1679. else
  1680. break;
  1681. until false;
  1682. {aufdef^.max:=l;
  1683. if we allow unordered enums
  1684. this can be wrong
  1685. min and max are now set in tenumsym.init PM }
  1686. p:=aufdef;
  1687. consume(RKLAMMER);
  1688. end;
  1689. _ARRAY:
  1690. array_dec;
  1691. _SET:
  1692. begin
  1693. consume(_SET);
  1694. consume(_OF);
  1695. hp1:=read_type('');
  1696. case hp1^.deftype of
  1697. { don't forget that min can be negativ PM }
  1698. enumdef : if penumdef(hp1)^.min>=0 then
  1699. p:=new(psetdef,init(hp1,penumdef(hp1)^.max))
  1700. else
  1701. Message(sym_e_ill_type_decl_set);
  1702. orddef : begin
  1703. case porddef(hp1)^.typ of
  1704. uchar : p:=new(psetdef,init(hp1,255));
  1705. u8bit,s8bit,u16bit,s16bit,s32bit :
  1706. begin
  1707. if (porddef(hp1)^.low>=0) then
  1708. p:=new(psetdef,init(hp1,porddef(hp1)^.high))
  1709. else Message(sym_e_ill_type_decl_set);
  1710. end;
  1711. else Message(sym_e_ill_type_decl_set);
  1712. end;
  1713. end;
  1714. else Message(sym_e_ill_type_decl_set);
  1715. end;
  1716. end;
  1717. CARET:
  1718. begin
  1719. consume(CARET);
  1720. { forwards allowed only inside TYPE statements }
  1721. if typecanbeforward then
  1722. forwardsallowed:=true;
  1723. hp1:=single_type(hs);
  1724. p:=new(ppointerdef,init(hp1));
  1725. {I add big troubles here
  1726. with var p : ^byte in graph.putimage
  1727. because a save_forward was called and
  1728. no resolve forward
  1729. => so the definition was rewritten after
  1730. having been disposed !!
  1731. Strange problems appeared !!!!}
  1732. {Anyhow forwards should only be allowed
  1733. inside a type statement ??
  1734. don't you think so }
  1735. if (lasttypesym<>nil)
  1736. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1737. lasttypesym^.forwardpointer:=ppointerdef(p);
  1738. forwardsallowed:=false;
  1739. end;
  1740. _RECORD:
  1741. p:=record_dec;
  1742. _PACKED:
  1743. begin
  1744. consume(_PACKED);
  1745. if token=_ARRAY then
  1746. array_dec
  1747. else
  1748. begin
  1749. oldaktpackrecords:=aktpackrecords;
  1750. aktpackrecords:=1;
  1751. if token in [_CLASS,_OBJECT] then
  1752. p:=object_dec(name,nil)
  1753. else
  1754. p:=record_dec;
  1755. aktpackrecords:=oldaktpackrecords;
  1756. end;
  1757. end;
  1758. _CLASS,
  1759. _OBJECT:
  1760. p:=object_dec(name,nil);
  1761. _PROCEDURE:
  1762. begin
  1763. consume(_PROCEDURE);
  1764. p:=handle_procvar;
  1765. if token=_OF then
  1766. begin
  1767. consume(_OF);
  1768. consume(_OBJECT);
  1769. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1770. end;
  1771. end;
  1772. _FUNCTION:
  1773. begin
  1774. consume(_FUNCTION);
  1775. p:=handle_procvar;
  1776. consume(COLON);
  1777. pprocvardef(p)^.retdef:=single_type(hs);
  1778. if token=_OF then
  1779. begin
  1780. consume(_OF);
  1781. consume(_OBJECT);
  1782. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1783. end;
  1784. end;
  1785. else
  1786. expr_type;
  1787. end;
  1788. read_type:=p;
  1789. end;
  1790. { reads a type declaration to the symbol table }
  1791. procedure type_dec;
  1792. var
  1793. typename : stringid;
  1794. newtype : ptypesym;
  1795. {$ifdef dummy}
  1796. olddef,newdef : pdef;
  1797. s : string;
  1798. {$endif dummy}
  1799. begin
  1800. block_type:=bt_type;
  1801. consume(_TYPE);
  1802. typecanbeforward:=true;
  1803. repeat
  1804. typename:=pattern;
  1805. consume(ID);
  1806. consume(EQUAL);
  1807. { here you loose the strictness of pascal
  1808. for which a redefinition like
  1809. childtype = parenttype;
  1810. child2type = parenttype;
  1811. does not make the two child types equal !!
  1812. here all vars from childtype and child2type
  1813. get the definition of parenttype !! }
  1814. {$ifdef testequaltype}
  1815. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1816. begin
  1817. olddef := single_type(s);
  1818. { make a clone of olddef }
  1819. { is that ok ??? }
  1820. getmem(newdef,SizeOf(olddef));
  1821. move(olddef^,newdef^,SizeOf(olddef));
  1822. newtype:=new(ptypesym,init(typename,newdef));
  1823. symtablestack^.insert(newtype);
  1824. end
  1825. else
  1826. {$endif testequaltype}
  1827. begin
  1828. getsym(typename,false);
  1829. { check if it is the definition of a forward defined class }
  1830. if assigned(srsym) and (token=_CLASS) and
  1831. (srsym^.typ=typesym) and
  1832. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1833. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1834. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oois_class)<>0) then
  1835. begin
  1836. { we can ignore the result }
  1837. { the definition is modified }
  1838. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1839. newtype:=ptypesym(srsym);
  1840. end
  1841. else
  1842. begin
  1843. newtype:=new(ptypesym,init(typename,read_type(typename)));
  1844. { load newtype with the new pointer to the inserted type
  1845. because it can be an already defined forwarded type !! }
  1846. newtype:=ptypesym(symtablestack^.insert(newtype));
  1847. end;
  1848. end;
  1849. consume(SEMICOLON);
  1850. if assigned(newtype^.definition) and (newtype^.definition^.deftype=procvardef) then
  1851. parse_var_proc_directives(newtype);
  1852. until token<>ID;
  1853. typecanbeforward:=false;
  1854. {$ifdef tp}
  1855. symtablestack^.foreach(testforward_types);
  1856. {$else}
  1857. symtablestack^.foreach(@testforward_types);
  1858. {$endif}
  1859. resolve_forwards;
  1860. block_type:=bt_general;
  1861. end;
  1862. procedure var_dec;
  1863. { parses varaible declarations and inserts them in }
  1864. { the top symbol table of symtablestack }
  1865. begin
  1866. consume(_VAR);
  1867. read_var_decs(false,false);
  1868. end;
  1869. procedure Not_supported_for_inline(t : ttoken);
  1870. begin
  1871. if assigned(aktprocsym) and
  1872. ((aktprocsym^.definition^.options and poinline)<>0) then
  1873. Begin
  1874. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1875. Message(parser_w_inlining_disabled);
  1876. aktprocsym^.definition^.options:= aktprocsym^.definition^.options and not poinline;
  1877. End;
  1878. end;
  1879. procedure read_declarations(islibrary : boolean);
  1880. begin
  1881. repeat
  1882. case token of
  1883. _LABEL:
  1884. begin
  1885. Not_supported_for_inline(token);
  1886. label_dec;
  1887. end;
  1888. _CONST:
  1889. begin
  1890. Not_supported_for_inline(token);
  1891. const_dec;
  1892. end;
  1893. _TYPE:
  1894. begin
  1895. Not_supported_for_inline(token);
  1896. type_dec;
  1897. end;
  1898. _VAR:
  1899. var_dec;
  1900. _CONSTRUCTOR,_DESTRUCTOR,
  1901. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1902. begin
  1903. Not_supported_for_inline(token);
  1904. unter_dec;
  1905. end;
  1906. _EXPORTS:
  1907. begin
  1908. { here we should be at lexlevel 1, no ? PM }
  1909. Not_supported_for_inline(token);
  1910. if islibrary then
  1911. read_exports
  1912. else
  1913. break;
  1914. end
  1915. else break;
  1916. end;
  1917. until false;
  1918. end;
  1919. procedure read_interface_declarations;
  1920. begin
  1921. {Since the body is now parsed at lexlevel 1, and the declarations
  1922. must be parsed at the same lexlevel we increase the lexlevel.}
  1923. inc(lexlevel);
  1924. repeat
  1925. case token of
  1926. _CONST : const_dec;
  1927. _TYPE : type_dec;
  1928. _VAR : var_dec;
  1929. _FUNCTION,
  1930. _PROCEDURE,
  1931. _OPERATOR : unter_dec;
  1932. else
  1933. break;
  1934. end;
  1935. until false;
  1936. dec(lexlevel);
  1937. end;
  1938. end.
  1939. {
  1940. $Log$
  1941. Revision 1.56 1998-09-23 15:39:09 pierre
  1942. * browser bugfixes
  1943. was adding a reference when looking for the symbol
  1944. if -bSYM_NAME was used
  1945. Revision 1.55 1998/09/21 13:24:44 daniel
  1946. * Memory leak fixed.
  1947. Revision 1.54 1998/09/17 13:41:16 pierre
  1948. sizeof(TPOINT) problem
  1949. Revision 1.53.2.1 1998/09/17 13:12:09 pierre
  1950. * virtual destructor did not set oo_hasvirtual
  1951. (detected with the sizeof(TPoint) problem
  1952. * genloadcallnode was missing
  1953. Revision 1.53 1998/09/09 11:50:52 pierre
  1954. * forward def are not put in record or objects
  1955. + added check for forwards also in record and objects
  1956. * dummy parasymtable for unit initialization removed from
  1957. symtable stack
  1958. Revision 1.52 1998/09/07 23:10:22 florian
  1959. * a lot of stuff fixed regarding rtti and publishing of properties,
  1960. basics should now work
  1961. Revision 1.51 1998/09/07 19:33:22 florian
  1962. + some stuff for property rtti added:
  1963. - NameIndex of the TPropInfo record is now written correctly
  1964. - the DEFAULT/NODEFAULT keyword is supported now
  1965. - the default value and the storedsym/def are now written to
  1966. the PPU fiel
  1967. Revision 1.50 1998/09/07 18:46:08 peter
  1968. * update smartlinking, uses getdatalabel
  1969. * renamed ptree.value vars to value_str,value_real,value_set
  1970. Revision 1.49 1998/09/07 17:37:00 florian
  1971. * first fixes for published properties
  1972. Revision 1.48 1998/09/04 08:42:02 peter
  1973. * updated some error messages
  1974. Revision 1.47 1998/09/03 16:03:18 florian
  1975. + rtti generation
  1976. * init table generation changed
  1977. Revision 1.46 1998/09/01 17:39:48 peter
  1978. + internal constant functions
  1979. Revision 1.45 1998/08/31 12:20:28 peter
  1980. * fixed array_dec when unknown type was used
  1981. Revision 1.44 1998/08/28 10:57:01 peter
  1982. * removed warnings
  1983. Revision 1.43 1998/08/25 13:09:25 pierre
  1984. * corrected mangling sheme :
  1985. cvar add Cprefix to the mixed case name whereas
  1986. export or public use direct name
  1987. Revision 1.42 1998/08/25 12:42:41 pierre
  1988. * CDECL changed to CVAR for variables
  1989. specifications are read in structures also
  1990. + started adding GPC compatibility mode ( option -Sp)
  1991. * names changed to lowercase
  1992. Revision 1.41 1998/08/23 21:04:36 florian
  1993. + rtti generation for classes added
  1994. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  1995. Revision 1.40 1998/08/21 15:48:58 pierre
  1996. * more cdecl chagnes
  1997. - better line info
  1998. - changes the definition options of a procvar
  1999. if it is a unnamed type
  2000. Revision 1.39 1998/08/19 00:42:40 peter
  2001. + subrange types for enums
  2002. + checking for bounds type with ranges
  2003. Revision 1.38 1998/08/12 19:20:39 peter
  2004. + public is the same as export for c_vars
  2005. * a exported/public c_var incs now the refcount
  2006. Revision 1.37 1998/08/11 15:31:38 peter
  2007. * write extended to ppu file
  2008. * new version 0.99.7
  2009. Revision 1.36 1998/08/10 14:50:09 peter
  2010. + localswitches, moduleswitches, globalswitches splitting
  2011. Revision 1.35 1998/07/26 21:59:00 florian
  2012. + better support for switch $H
  2013. + index access to ansi strings added
  2014. + assigment of data (records/arrays) containing ansi strings
  2015. Revision 1.34 1998/07/20 22:17:15 florian
  2016. * hex constants in numeric char (#$54#$43 ...) are now allowed
  2017. * there was a bug in record_var_dec which prevents the used
  2018. of nested variant records (for example drivers.tevent of tv)
  2019. Revision 1.33 1998/07/18 17:11:11 florian
  2020. + ansi string constants fixed
  2021. + switch $H partial implemented
  2022. Revision 1.32 1998/07/14 21:46:50 peter
  2023. * updated messages file
  2024. Revision 1.31 1998/07/14 14:46:53 peter
  2025. * released NEWINPUT
  2026. Revision 1.30 1998/07/10 00:00:00 peter
  2027. * fixed ttypesym bug finally
  2028. * fileinfo in the symtable and better using for unused vars
  2029. Revision 1.29 1998/06/25 14:04:21 peter
  2030. + internal inc/dec
  2031. Revision 1.28 1998/06/24 12:26:45 peter
  2032. * stricter var parsing like tp7 and some optimizes with directive
  2033. parsing
  2034. Revision 1.27 1998/06/12 16:15:34 pierre
  2035. * external name 'C_var';
  2036. export name 'intern_C_var';
  2037. cdecl;
  2038. cdecl;external;
  2039. are now supported only with -Sv switch
  2040. Revision 1.25 1998/06/09 16:01:45 pierre
  2041. + added procedure directive parsing for procvars
  2042. (accepted are popstack cdecl and pascal)
  2043. + added C vars with the following syntax
  2044. var C calias 'true_c_name';(can be followed by external)
  2045. reason is that you must add the Cprefix
  2046. which is target dependent
  2047. Revision 1.24 1998/06/05 14:37:32 pierre
  2048. * fixes for inline for operators
  2049. * inline procedure more correctly restricted
  2050. Revision 1.23 1998/06/04 23:51:50 peter
  2051. * m68k compiles
  2052. + .def file creation moved to gendef.pas so it could also be used
  2053. for win32
  2054. Revision 1.22 1998/06/03 22:48:59 peter
  2055. + wordbool,longbool
  2056. * rename bis,von -> high,low
  2057. * moved some systemunit loading/creating to psystem.pas
  2058. Revision 1.21 1998/06/03 22:14:19 florian
  2059. * problem with sizes of classes fixed (if the anchestor was declared
  2060. forward, the compiler doesn't update the child classes size)
  2061. Revision 1.20 1998/05/28 14:35:54 peter
  2062. * nicer error message when no id is used after var
  2063. Revision 1.19 1998/05/23 01:21:19 peter
  2064. + aktasmmode, aktoptprocessor, aktoutputformat
  2065. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2066. + $LIBNAME to set the library name where the unit will be put in
  2067. * splitted cgi386 a bit (codeseg to large for bp7)
  2068. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2069. Revision 1.18 1998/05/20 09:42:35 pierre
  2070. + UseTokenInfo now default
  2071. * unit in interface uses and implementation uses gives error now
  2072. * only one error for unknown symbol (uses lastsymknown boolean)
  2073. the problem came from the label code !
  2074. + first inlined procedures and function work
  2075. (warning there might be allowed cases were the result is still wrong !!)
  2076. * UseBrower updated gives a global list of all position of all used symbols
  2077. with switch -gb
  2078. Revision 1.17 1998/05/11 13:07:55 peter
  2079. + $ifdef NEWPPU for the new ppuformat
  2080. + $define GDB not longer required
  2081. * removed all warnings and stripped some log comments
  2082. * no findfirst/findnext anymore to remove smartlink *.o files
  2083. Revision 1.16 1998/05/05 12:05:42 florian
  2084. * problems with properties fixed
  2085. * crash fixed: i:=l when i and l are undefined, was a problem with
  2086. implementation of private/protected
  2087. Revision 1.15 1998/05/01 09:01:23 florian
  2088. + correct semantics of private and protected
  2089. * small fix in variable scope:
  2090. a id can be used in a parameter list of a method, even it is used in
  2091. an anchestor class as field id
  2092. Revision 1.14 1998/05/01 07:43:56 florian
  2093. + basics for rtti implemented
  2094. + switch $m (generate rtti for published sections)
  2095. Revision 1.13 1998/04/30 15:59:41 pierre
  2096. * GDB works again better :
  2097. correct type info in one pass
  2098. + UseTokenInfo for better source position
  2099. * fixed one remaining bug in scanner for line counts
  2100. * several little fixes
  2101. Revision 1.12 1998/04/29 10:33:57 pierre
  2102. + added some code for ansistring (not complete nor working yet)
  2103. * corrected operator overloading
  2104. * corrected nasm output
  2105. + started inline procedures
  2106. + added starstarn : use ** for exponentiation (^ gave problems)
  2107. + started UseTokenInfo cond to get accurate positions
  2108. Revision 1.11 1998/04/28 11:45:52 florian
  2109. * make it compilable with TP
  2110. + small COM problems solved to compile classes.pp
  2111. Revision 1.10 1998/04/27 23:10:28 peter
  2112. + new scanner
  2113. * $makelib -> if smartlink
  2114. * small filename fixes pmodule.setfilename
  2115. * moved import from files.pas -> import.pas
  2116. Revision 1.9 1998/04/10 21:36:56 florian
  2117. + some stuff to support method pointers (procedure of object) added
  2118. (declaration, parameter handling)
  2119. Revision 1.8 1998/04/10 15:39:48 florian
  2120. * more fixes to get classes.pas compiled
  2121. Revision 1.7 1998/04/09 23:02:15 florian
  2122. * small problems solved to get remake3 work
  2123. Revision 1.6 1998/04/09 22:16:35 florian
  2124. * problem with previous REGALLOC solved
  2125. * improved property support
  2126. Revision 1.5 1998/04/08 14:59:20 florian
  2127. * problem with new expr_type solved
  2128. Revision 1.4 1998/04/08 10:26:09 florian
  2129. * correct error handling of virtual constructors
  2130. * problem with new type declaration handling fixed
  2131. Revision 1.3 1998/04/07 22:45:05 florian
  2132. * bug0092, bug0115 and bug0121 fixed
  2133. + packed object/class/array
  2134. Revision 1.2 1998/04/05 13:58:35 peter
  2135. * fixed the -Ss bug
  2136. + warning for Virtual constructors
  2137. * helppages updated with -TGO32V1
  2138. }