pdecl.pas 94 KB

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