pdecl.pas 94 KB

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