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^.typ:=absolutesym;
  311. abssym^.abstyp:=tovar;
  312. abssym^.ref:=srsym;
  313. tokenpos:=storetokenpos;
  314. symtablestack^.insert(abssym);
  315. end
  316. else
  317. if (token=CSTRING) or (token=CCHAR) then
  318. begin
  319. storetokenpos:=tokenpos;
  320. tokenpos:=declarepos;
  321. abssym:=new(pabsolutesym,init(s,p));
  322. s:=pattern;
  323. consume(token);
  324. abssym^.typ:=absolutesym;
  325. abssym^.abstyp:=toasm;
  326. abssym^.asmname:=stringdup(s);
  327. tokenpos:=storetokenpos;
  328. symtablestack^.insert(abssym);
  329. end
  330. else
  331. { absolute address ?!? }
  332. if token=INTCONST then
  333. begin
  334. if (target_info.target=target_i386_go32v2) then
  335. begin
  336. storetokenpos:=tokenpos;
  337. tokenpos:=declarepos;
  338. abssym:=new(pabsolutesym,init(s,p));
  339. abssym^.typ:=absolutesym;
  340. abssym^.abstyp:=toaddr;
  341. abssym^.absseg:=false;
  342. tokenpos:=storetokenpos;
  343. s:=pattern;
  344. consume(INTCONST);
  345. val(s,abssym^.address,code);
  346. if token=COLON then
  347. begin
  348. consume(token);
  349. s:=pattern;
  350. consume(INTCONST);
  351. val(s,l,code);
  352. abssym^.address:=abssym^.address shl 4+l;
  353. abssym^.absseg:=true;
  354. end;
  355. symtablestack^.insert(abssym);
  356. end
  357. else
  358. Message(parser_e_absolute_only_to_var_or_const);
  359. end
  360. else
  361. Message(parser_e_absolute_only_to_var_or_const);
  362. symdone:=true;
  363. end;
  364. { for a record there doesn't need to be a ; before the END or ) }
  365. if not((is_record or is_object) and (token in [_END,RKLAMMER])) then
  366. consume(SEMICOLON);
  367. { procvar handling }
  368. if (p^.deftype=procvardef) and (p^.sym=nil) then
  369. begin
  370. newtype:=new(ptypesym,init('unnamed',p));
  371. parse_var_proc_directives(newtype);
  372. newtype^.definition:=nil;
  373. p^.sym:=nil;
  374. dispose(newtype,done);
  375. end;
  376. { Check for variable directives }
  377. if not symdone and (token=ID) then
  378. begin
  379. { Check for C Variable declarations }
  380. if (m_cvar_support in aktmodeswitches) and
  381. not(is_record or is_object) and
  382. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR]) then
  383. begin
  384. { only allowed for one var }
  385. s:=sc^.get_with_tokeninfo(declarepos);
  386. if not sc^.empty then
  387. Message(parser_e_absolute_only_one_var);
  388. dispose(sc,done);
  389. { defaults }
  390. is_dll:=false;
  391. is_cdecl:=false;
  392. extern_aktvarsym:=false;
  393. export_aktvarsym:=false;
  394. { cdecl }
  395. if idtoken=_CVAR then
  396. begin
  397. consume(_CVAR);
  398. consume(SEMICOLON);
  399. is_cdecl:=true;
  400. C_name:=target_os.Cprefix+C_name;
  401. end;
  402. { external }
  403. if idtoken=_EXTERNAL then
  404. begin
  405. consume(_EXTERNAL);
  406. extern_aktvarsym:=true;
  407. end;
  408. { export }
  409. if idtoken in [_EXPORT,_PUBLIC] then
  410. begin
  411. consume(ID);
  412. if extern_aktvarsym then
  413. Message(parser_e_not_external_and_export)
  414. else
  415. export_aktvarsym:=true;
  416. end;
  417. { external and export need a name after when no cdecl is used }
  418. if not is_cdecl then
  419. begin
  420. { dll name ? }
  421. if (extern_aktvarsym) and (token=CSTRING) then
  422. begin
  423. is_dll:=true;
  424. dll_name:=pattern;
  425. consume(CSTRING);
  426. end;
  427. consume(_NAME);
  428. C_name:=pattern;
  429. { allow also char }
  430. if token=CCHAR then
  431. consume(CCHAR)
  432. else
  433. consume(CSTRING);
  434. end;
  435. { consume the ; when export or external is used }
  436. if extern_aktvarsym or export_aktvarsym then
  437. consume(SEMICOLON);
  438. { insert in the symtable }
  439. storetokenpos:=tokenpos;
  440. tokenpos:=declarepos;
  441. if is_dll then
  442. aktvarsym:=new(pvarsym,init_dll(s,p))
  443. else
  444. aktvarsym:=new(pvarsym,init_C(s,C_name,p));
  445. tokenpos:=storetokenpos;
  446. { set some vars options }
  447. if export_aktvarsym then
  448. inc(aktvarsym^.refs);
  449. if extern_aktvarsym then
  450. aktvarsym^.var_options:=aktvarsym^.var_options or vo_is_external;
  451. { insert in the stack/datasegment }
  452. symtablestack^.insert(aktvarsym);
  453. { now we can insert it in the import lib if its a dll, or
  454. add it to the externals }
  455. if extern_aktvarsym then
  456. begin
  457. if is_dll then
  458. begin
  459. if not(current_module^.uses_imports) then
  460. begin
  461. current_module^.uses_imports:=true;
  462. importlib^.preparelib(current_module^.modulename^);
  463. end;
  464. importlib^.importvariable(aktvarsym^.mangledname,dll_name,C_name)
  465. end
  466. else
  467. externals^.concat(new(pai_external,init(aktvarsym^.mangledname,EXT_NEAR)));
  468. end;
  469. symdone:=true;
  470. end
  471. else
  472. if (is_object) and (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  473. begin
  474. current_object_option:=current_object_option or sp_static;
  475. insert_syms(symtablestack,sc,p);
  476. current_object_option:=current_object_option - sp_static;
  477. consume(_STATIC);
  478. consume(SEMICOLON);
  479. symdone:=true;
  480. end;
  481. end;
  482. { insert it in the symtable, if not done yet }
  483. if not symdone then
  484. begin
  485. if (current_object_option=sp_published) and
  486. (not((p^.deftype=objectdef) and (pobjectdef(p)^.isclass))) then
  487. Message(parser_e_cant_publish_that);
  488. insert_syms(symtablestack,sc,p);
  489. end;
  490. end;
  491. { Check for Case }
  492. if is_record and (token=_CASE) then
  493. begin
  494. maxsize:=0;
  495. consume(_CASE);
  496. s:=pattern;
  497. getsym(s,false);
  498. { may be only a type: }
  499. if assigned(srsym) and (srsym^.typ in [typesym,unitsym]) then
  500. casedef:=read_type('')
  501. else
  502. begin
  503. consume(ID);
  504. consume(COLON);
  505. casedef:=read_type('');
  506. symtablestack^.insert(new(pvarsym,init(s,casedef)));
  507. end;
  508. if not is_ordinal(casedef) then
  509. Message(type_e_ordinal_expr_expected);
  510. consume(_OF);
  511. startvarrec:=symtablestack^.datasize;
  512. repeat
  513. repeat
  514. pt:=comp_expr(true);
  515. do_firstpass(pt);
  516. if not(pt^.treetype=ordconstn) then
  517. Message(cg_e_illegal_expression);
  518. disposetree(pt);
  519. if token=COMMA then
  520. consume(COMMA)
  521. else
  522. break;
  523. until false;
  524. consume(COLON);
  525. { read the vars }
  526. consume(LKLAMMER);
  527. if token<>RKLAMMER then
  528. read_var_decs(true,false);
  529. consume(RKLAMMER);
  530. { calculates maximal variant size }
  531. maxsize:=max(maxsize,symtablestack^.datasize);
  532. { the items of the next variant are overlayed }
  533. symtablestack^.datasize:=startvarrec;
  534. if (token<>_END) and (token<>RKLAMMER) then
  535. consume(SEMICOLON)
  536. else
  537. break;
  538. until (token=_END) or (token=RKLAMMER);
  539. { at last set the record size to that of the biggest variant }
  540. symtablestack^.datasize:=maxsize;
  541. end;
  542. block_type:=old_block_type;
  543. end;
  544. function stringtype : pdef;
  545. { reads a string type with optional length }
  546. { and returns a pointer to the string }
  547. { definition }
  548. var
  549. p : ptree;
  550. d : pdef;
  551. begin
  552. consume(_STRING);
  553. if token=LECKKLAMMER then
  554. begin
  555. consume(LECKKLAMMER);
  556. p:=comp_expr(true);
  557. do_firstpass(p);
  558. if not is_constintnode(p) then
  559. Message(cg_e_illegal_expression);
  560. if (p^.value<=0) then
  561. begin
  562. Message(parser_e_invalid_string_size);
  563. p^.value:=255;
  564. end;
  565. consume(RECKKLAMMER);
  566. if p^.value>255 then
  567. d:=new(pstringdef,longinit(p^.value))
  568. else
  569. if p^.value<>255 then
  570. d:=new(pstringdef,shortinit(p^.value))
  571. else
  572. d:=cshortstringdef;
  573. disposetree(p);
  574. end
  575. else
  576. begin
  577. if cs_ansistrings in aktlocalswitches then
  578. d:=cansistringdef
  579. else
  580. d:=cshortstringdef;
  581. end;
  582. stringtype:=d;
  583. end;
  584. function id_type(var s : string) : pdef;
  585. { reads a type definition and returns a pointer }
  586. { to a appropriating pdef, s gets the name of }
  587. { the type to allow name mangling }
  588. begin
  589. s:=pattern;
  590. consume(ID);
  591. { classes can be used also in classes }
  592. if (curobjectname=pattern) and aktobjectdef^.isclass then
  593. begin
  594. id_type:=aktobjectdef;
  595. exit;
  596. end;
  597. { objects can be parameters }
  598. if (testcurobject=2) and (curobjectname=pattern) then
  599. begin
  600. id_type:=aktobjectdef;
  601. exit;
  602. end;
  603. getsym(s,true);
  604. if assigned(srsym) then
  605. begin
  606. if srsym^.typ=unitsym then
  607. begin
  608. consume(POINT);
  609. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  610. s:=pattern;
  611. consume(ID);
  612. end;
  613. if srsym^.typ<>typesym then
  614. begin
  615. Message(type_e_type_id_expected);
  616. lasttypesym:=ptypesym(srsym);
  617. id_type:=generrordef;
  618. exit;
  619. end;
  620. if not forwardsallowed then
  621. testforward_type(srsym);
  622. end;
  623. lasttypesym:=ptypesym(srsym);
  624. id_type:=ptypesym(srsym)^.definition;
  625. end;
  626. function single_type(var s : string) : pdef;
  627. { reads a string, file type or a type id and returns a name and }
  628. { pdef }
  629. var
  630. hs : string;
  631. begin
  632. case token of
  633. _STRING:
  634. begin
  635. single_type:=stringtype;
  636. s:='STRING';
  637. lasttypesym:=nil;
  638. end;
  639. _FILE:
  640. begin
  641. consume(_FILE);
  642. if token=_OF then
  643. begin
  644. consume(_OF);
  645. single_type:=new(pfiledef,init(ft_typed,single_type(hs)));
  646. s:='FILE$OF$'+hs;
  647. end
  648. else
  649. begin
  650. { single_type:=new(pfiledef,init(ft_untyped,nil));}
  651. single_type:=cfiledef;
  652. s:='FILE';
  653. end;
  654. lasttypesym:=nil;
  655. end;
  656. else single_type:=id_type(s);
  657. end;
  658. end;
  659. function object_dec(const n : stringid;fd : pobjectdef) : pdef;
  660. { this function parses an object or class declaration }
  661. var
  662. actmembertype : symprop;
  663. there_is_a_destructor : boolean;
  664. is_a_class : boolean;
  665. childof : pobjectdef;
  666. aktclass : pobjectdef;
  667. procedure constructor_head;
  668. begin
  669. consume(_CONSTRUCTOR);
  670. { must be at same level as in implementation }
  671. inc(lexlevel);
  672. parse_proc_head(poconstructor);
  673. dec(lexlevel);
  674. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'INIT') then
  675. Message(parser_e_constructorname_must_be_init);
  676. aktclass^.options:=aktclass^.options or oo_hasconstructor;
  677. consume(SEMICOLON);
  678. begin
  679. if (aktclass^.options and oo_is_class)<>0 then
  680. begin
  681. { CLASS constructors return the created instance }
  682. aktprocsym^.definition^.retdef:=aktclass;
  683. end
  684. else
  685. begin
  686. { OBJECT constructors return a boolean }
  687. {$IfDef GDB}
  688. {GDB doesn't like unnamed types !}
  689. aktprocsym^.definition^.retdef:=
  690. globaldef('boolean');
  691. {$Else GDB}
  692. aktprocsym^.definition^.retdef:=
  693. new(porddef,init(bool8bit,0,1));
  694. {$Endif GDB}
  695. end;
  696. end;
  697. end;
  698. procedure property_dec;
  699. var
  700. sym : psym;
  701. propertyparas : pdefcoll;
  702. { returns the matching procedure to access a property }
  703. function get_procdef : pprocdef;
  704. var
  705. p : pprocdef;
  706. begin
  707. p:=pprocsym(sym)^.definition;
  708. get_procdef:=nil;
  709. while assigned(p) do
  710. begin
  711. if equal_paras(p^.para1,propertyparas,true) then
  712. break;
  713. p:=p^.nextoverloaded;
  714. end;
  715. get_procdef:=p;
  716. end;
  717. var
  718. hp2,datacoll : pdefcoll;
  719. p,p2 : ppropertysym;
  720. overriden : psym;
  721. hs : string;
  722. code : word;
  723. varspez : tvarspez;
  724. sc : pstringcontainer;
  725. hp : pdef;
  726. s : string;
  727. declarepos : tfileposinfo;
  728. pp : pprocdef;
  729. pt : ptree;
  730. propname : stringid;
  731. begin
  732. { check for a class }
  733. if (aktclass^.options and oo_is_class=0) then
  734. Message(parser_e_syntax_error);
  735. consume(_PROPERTY);
  736. propertyparas:=nil;
  737. datacoll:=nil;
  738. if token=ID then
  739. begin
  740. p:=new(ppropertysym,init(pattern));
  741. propname:=pattern;
  742. consume(ID);
  743. { property parameters ? }
  744. if token=LECKKLAMMER then
  745. begin
  746. if current_object_option=sp_published then
  747. Message(parser_e_cant_publish_that_property);
  748. { create a list of the parameters in propertyparas }
  749. consume(LECKKLAMMER);
  750. inc(testcurobject);
  751. repeat
  752. if token=_VAR then
  753. begin
  754. consume(_VAR);
  755. varspez:=vs_var;
  756. end
  757. else if token=_CONST then
  758. begin
  759. consume(_CONST);
  760. varspez:=vs_const;
  761. end
  762. else varspez:=vs_value;
  763. sc:=idlist;
  764. if token=COLON then
  765. begin
  766. consume(COLON);
  767. if token=_ARRAY then
  768. begin
  769. {
  770. if (varspez<>vs_const) and
  771. (varspez<>vs_var) then
  772. begin
  773. varspez:=vs_const;
  774. Message(parser_e_illegal_open_parameter);
  775. end;
  776. }
  777. consume(_ARRAY);
  778. consume(_OF);
  779. { define range and type of range }
  780. hp:=new(parraydef,init(0,-1,s32bitdef));
  781. { define field type }
  782. parraydef(hp)^.definition:=single_type(s);
  783. end
  784. else
  785. hp:=single_type(s);
  786. end
  787. else
  788. hp:=new(pformaldef,init);
  789. s:=sc^.get_with_tokeninfo(declarepos);
  790. while s<>'' do
  791. begin
  792. new(hp2);
  793. hp2^.paratyp:=varspez;
  794. hp2^.data:=hp;
  795. hp2^.next:=propertyparas;
  796. propertyparas:=hp2;
  797. s:=sc^.get_with_tokeninfo(declarepos);
  798. end;
  799. dispose(sc,done);
  800. if token=SEMICOLON then consume(SEMICOLON)
  801. else break;
  802. until false;
  803. dec(testcurobject);
  804. consume(RECKKLAMMER);
  805. end;
  806. { overriden property ? }
  807. { force property interface, if there is a property parameter }
  808. if (token=COLON) or assigned(propertyparas) then
  809. begin
  810. consume(COLON);
  811. p^.proptype:=single_type(hs);
  812. if (idtoken=_INDEX) then
  813. begin
  814. consume(_INDEX);
  815. p^.options:=p^.options or ppo_indexed;
  816. if token=INTCONST then
  817. val(pattern,p^.index,code);
  818. consume(INTCONST);
  819. { concat a longint to the para template }
  820. new(hp2);
  821. hp2^.paratyp:=vs_value;
  822. hp2^.data:=s32bitdef;
  823. hp2^.next:=propertyparas;
  824. propertyparas:=hp2;
  825. end;
  826. end
  827. else
  828. begin
  829. { do an property override }
  830. overriden:=search_class_member(aktclass,propname);
  831. if assigned(overriden) and (overriden^.typ=propertysym) then
  832. begin
  833. { take the whole info: }
  834. p^.options:=ppropertysym(overriden)^.options;
  835. p^.index:=ppropertysym(overriden)^.index;
  836. p^.proptype:=ppropertysym(overriden)^.proptype;
  837. p^.writeaccesssym:=ppropertysym(overriden)^.writeaccesssym;
  838. p^.readaccesssym:=ppropertysym(overriden)^.readaccesssym;
  839. p^.writeaccessdef:=ppropertysym(overriden)^.writeaccessdef;
  840. p^.readaccessdef:=ppropertysym(overriden)^.readaccessdef;
  841. p^.storedsym:=ppropertysym(overriden)^.storedsym;
  842. p^.storeddef:=ppropertysym(overriden)^.storeddef;
  843. p^.default:=ppropertysym(overriden)^.default;
  844. end
  845. else
  846. begin
  847. p^.proptype:=generrordef;
  848. message(parser_e_no_property_found_to_override);
  849. end;
  850. end;
  851. if (current_object_option=sp_published) and
  852. not(p^.proptype^.is_publishable) then
  853. Message(parser_e_cant_publish_that_property);
  854. { create data defcoll to allow correct parameter checks }
  855. new(datacoll);
  856. datacoll^.paratyp:=vs_value;
  857. datacoll^.data:=p^.proptype;
  858. datacoll^.next:=nil;
  859. if (idtoken=_READ) then
  860. begin
  861. consume(_READ);
  862. sym:=search_class_member(aktclass,pattern);
  863. if not(assigned(sym)) then
  864. Message1(sym_e_unknown_id,pattern)
  865. else
  866. begin
  867. { varsym aren't allowed for an indexed property
  868. or an property with parameters }
  869. if ((sym^.typ=varsym) and
  870. { not necessary, an index forces propertyparas
  871. to be assigned
  872. }
  873. { (((p^.options and ppo_indexed)<>0) or }
  874. assigned(propertyparas)) or
  875. not(sym^.typ in [varsym,procsym]) then
  876. Message(parser_e_ill_property_access_sym);
  877. { search the matching definition }
  878. if sym^.typ=procsym then
  879. begin
  880. pp:=get_procdef;
  881. if not(assigned(pp)) or
  882. not(is_equal(pp^.retdef,p^.proptype)) then
  883. Message(parser_e_ill_property_access_sym);
  884. p^.readaccessdef:=pp;
  885. end
  886. else if sym^.typ=varsym then
  887. begin
  888. if not(is_equal(pvarsym(sym)^.definition,
  889. p^.proptype)) then
  890. Message(parser_e_ill_property_access_sym);
  891. end;
  892. p^.readaccesssym:=sym;
  893. end;
  894. consume(ID);
  895. end;
  896. if (idtoken=_WRITE) then
  897. begin
  898. consume(_WRITE);
  899. sym:=search_class_member(aktclass,pattern);
  900. if not(assigned(sym)) then
  901. Message1(sym_e_unknown_id,pattern)
  902. else
  903. begin
  904. if ((sym^.typ=varsym) and
  905. assigned(propertyparas)) or
  906. not(sym^.typ in [varsym,procsym]) then
  907. Message(parser_e_ill_property_access_sym);
  908. { search the matching definition }
  909. if sym^.typ=procsym then
  910. begin
  911. { insert data entry to check access method }
  912. datacoll^.next:=propertyparas;
  913. propertyparas:=datacoll;
  914. pp:=get_procdef;
  915. { ... and remove it }
  916. propertyparas:=propertyparas^.next;
  917. datacoll^.next:=nil;
  918. if not(assigned(pp)) then
  919. Message(parser_e_ill_property_access_sym);
  920. p^.writeaccessdef:=pp;
  921. end
  922. else if sym^.typ=varsym then
  923. begin
  924. if not(is_equal(pvarsym(sym)^.definition,
  925. p^.proptype)) then
  926. Message(parser_e_ill_property_access_sym);
  927. end;
  928. p^.writeaccesssym:=sym;
  929. end;
  930. consume(ID);
  931. end;
  932. if (idtoken=_STORED) then
  933. begin
  934. consume(_STORED);
  935. Message(parser_w_stored_not_implemented);
  936. { !!!!!!!! }
  937. end;
  938. if (idtoken=_DEFAULT) then
  939. begin
  940. consume(_DEFAULT);
  941. if not(is_ordinal(p^.proptype) or
  942. ((p^.proptype^.deftype=setdef) and
  943. (psetdef(p^.proptype)^.settype=smallset)
  944. ) or
  945. assigned(propertyparas)
  946. ) then
  947. Message(parser_e_property_cant_have_a_default_value);
  948. pt:=comp_expr(true);
  949. pt:=gentypeconvnode(pt,p^.proptype);
  950. do_firstpass(pt);
  951. if not(is_constnode(pt)) then
  952. Message(parser_e_property_default_value_must_const);
  953. if pt^.treetype=setconstn then
  954. p^.default:=plongint(pt^.value_set)^
  955. else
  956. p^.default:=pt^.value;
  957. disposetree(pt);
  958. end
  959. else if (idtoken=_NODEFAULT) then
  960. begin
  961. consume(_NODEFAULT);
  962. p^.default:=0;
  963. end;
  964. symtablestack^.insert(p);
  965. { default property ? }
  966. consume(SEMICOLON);
  967. if (idtoken=_DEFAULT) then
  968. begin
  969. consume(_DEFAULT);
  970. p2:=search_default_property(aktclass);
  971. if assigned(p2) then
  972. message1(parser_e_only_one_default_property,
  973. pobjectdef(p2^.owner^.defowner)^.name^)
  974. else
  975. begin
  976. p^.options:=p^.options or ppo_defaultproperty;
  977. if not(assigned(propertyparas)) then
  978. message(parser_e_property_need_paras);
  979. end;
  980. consume(SEMICOLON);
  981. end;
  982. { clean up }
  983. if assigned(datacoll) then
  984. disposepdefcoll(datacoll);
  985. end
  986. else
  987. begin
  988. consume(ID);
  989. consume(SEMICOLON);
  990. end;
  991. if assigned(propertyparas) then
  992. disposepdefcoll(propertyparas);
  993. end;
  994. procedure destructor_head;
  995. begin
  996. consume(_DESTRUCTOR);
  997. inc(lexlevel);
  998. parse_proc_head(podestructor);
  999. dec(lexlevel);
  1000. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  1001. Message(parser_e_destructorname_must_be_done);
  1002. aktclass^.options:=aktclass^.options or oo_hasdestructor;
  1003. consume(SEMICOLON);
  1004. if assigned(aktprocsym^.definition^.para1) then
  1005. Message(parser_e_no_paras_for_destructor);
  1006. { no return value }
  1007. aktprocsym^.definition^.retdef:=voiddef;
  1008. end;
  1009. var
  1010. hs : string;
  1011. pcrd : pclassrefdef;
  1012. hp1 : pdef;
  1013. oldprocsym : pprocsym;
  1014. oldparse_only : boolean;
  1015. classnamelabel : plabel;
  1016. storetypeforwardsallowed : boolean;
  1017. begin
  1018. {Nowadays aktprocsym may already have a value, so we need to save
  1019. it.}
  1020. oldprocsym:=aktprocsym;
  1021. { forward is resolved }
  1022. if assigned(fd) then
  1023. fd^.options:=fd^.options and not(oo_isforward);
  1024. there_is_a_destructor:=false;
  1025. actmembertype:=sp_public;
  1026. { objects and class types can't be declared local }
  1027. if (symtablestack^.symtabletype<>globalsymtable) and
  1028. (symtablestack^.symtabletype<>staticsymtable) then
  1029. Message(parser_e_no_local_objects);
  1030. storetypeforwardsallowed:=typecanbeforward;
  1031. if m_tp in aktmodeswitches then
  1032. typecanbeforward:=false;
  1033. { distinguish classes and objects }
  1034. if token=_OBJECT then
  1035. begin
  1036. is_a_class:=false;
  1037. consume(_OBJECT)
  1038. end
  1039. else
  1040. begin
  1041. is_a_class:=true;
  1042. consume(_CLASS);
  1043. if not(assigned(fd)) and (token=_OF) then
  1044. begin
  1045. { a hack, but it's easy to handle }
  1046. { class reference type }
  1047. consume(_OF);
  1048. if typecanbeforward then
  1049. forwardsallowed:=true;
  1050. hp1:=single_type(hs);
  1051. { accept hp1, if is a forward def ...}
  1052. if ((lasttypesym<>nil)
  1053. and ((lasttypesym^.properties and sp_forwarddef)<>0)) or
  1054. { or a class
  1055. (if the foward defined type is a class is checked, when
  1056. the forward is resolved)
  1057. }
  1058. ((hp1^.deftype=objectdef) and (
  1059. (pobjectdef(hp1)^.options and oo_is_class)<>0)) then
  1060. begin
  1061. pcrd:=new(pclassrefdef,init(hp1));
  1062. object_dec:=pcrd;
  1063. {I add big troubles here
  1064. with var p : ^byte in graph.putimage
  1065. because a save_forward was called and
  1066. no resolve forward
  1067. => so the definition was rewritten after
  1068. having been disposed !!
  1069. Strange problems appeared !!!!}
  1070. {Anyhow forwards should only be allowed
  1071. inside a type statement ??
  1072. don't you think so }
  1073. if (lasttypesym<>nil)
  1074. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1075. lasttypesym^.forwardpointer:=ppointerdef(pcrd);
  1076. forwardsallowed:=false;
  1077. end
  1078. else
  1079. begin
  1080. Message(type_e_class_type_expected);
  1081. object_dec:=new(perrordef,init);
  1082. end;
  1083. exit;
  1084. end
  1085. { forward class }
  1086. else if not(assigned(fd)) and (token=SEMICOLON) then
  1087. begin
  1088. { also anonym objects aren't allow (o : object a : longint; end;) }
  1089. if n='' then
  1090. begin
  1091. Message(parser_f_no_anonym_objects)
  1092. end;
  1093. if n='TOBJECT' then
  1094. begin
  1095. aktclass:=new(pobjectdef,init(n,nil));
  1096. class_tobject:=aktclass;
  1097. end
  1098. else
  1099. aktclass:=new(pobjectdef,init(n,nil));
  1100. aktclass^.options:=aktclass^.options or oo_is_class or oo_isforward;
  1101. { all classes must have a vmt !! at offset zero }
  1102. if (aktclass^.options and oo_hasvmt)=0 then
  1103. aktclass^.insertvmt;
  1104. object_dec:=aktclass;
  1105. exit;
  1106. end;
  1107. end;
  1108. { also anonym objects aren't allow (o : object a : longint; end;) }
  1109. if n='' then
  1110. Message(parser_f_no_anonym_objects);
  1111. { read the parent class }
  1112. if token=LKLAMMER then
  1113. begin
  1114. consume(LKLAMMER);
  1115. { does not allow objects.tobject !! }
  1116. {if token<>ID then
  1117. consume(ID);
  1118. getsym(pattern,true);}
  1119. childof:=pobjectdef(id_type(pattern));
  1120. if (childof^.deftype<>objectdef) then
  1121. begin
  1122. Message(type_e_class_type_expected);
  1123. childof:=nil;
  1124. end
  1125. else
  1126. begin
  1127. { a mix of class and object isn't allowed }
  1128. if (((childof^.options and oo_is_class)<>0) and not is_a_class) or
  1129. (((childof^.options and oo_is_class)=0) and is_a_class) then
  1130. Message(parser_e_mix_of_classes_and_objects);
  1131. end;
  1132. if assigned(fd) then
  1133. begin
  1134. { the forward of the child must be resolved to get
  1135. correct field addresses
  1136. }
  1137. if (childof^.options and oo_isforward)<>0 then
  1138. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1139. aktclass:=fd;
  1140. { we must inherit several options !!
  1141. this was missing !!
  1142. all is now done in set_parent
  1143. including symtable datasize setting PM }
  1144. fd^.set_parent(childof);
  1145. end
  1146. else
  1147. aktclass:=new(pobjectdef,init(n,childof));
  1148. consume(RKLAMMER);
  1149. end
  1150. { if no parent class, then a class get tobject as parent }
  1151. else if is_a_class then
  1152. begin
  1153. { is the current class tobject? }
  1154. { so you could define your own tobject }
  1155. if n='TOBJECT' then
  1156. begin
  1157. if assigned(fd) then
  1158. aktclass:=fd
  1159. else
  1160. aktclass:=new(pobjectdef,init(n,nil));
  1161. class_tobject:=aktclass;
  1162. end
  1163. else
  1164. begin
  1165. childof:=class_tobject;
  1166. if assigned(fd) then
  1167. begin
  1168. { the forward of the child must be resolved to get
  1169. correct field addresses
  1170. }
  1171. if (childof^.options and oo_isforward)<>0 then
  1172. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1173. aktclass:=fd;
  1174. aktclass^.set_parent(childof);
  1175. end
  1176. else
  1177. begin
  1178. aktclass:=new(pobjectdef,init(n,childof));
  1179. aktclass^.set_parent(childof);
  1180. end;
  1181. end;
  1182. end
  1183. else
  1184. aktclass:=new(pobjectdef,init(n,nil));
  1185. { set the class attribute }
  1186. if is_a_class then
  1187. begin
  1188. aktclass^.options:=aktclass^.options or oo_is_class;
  1189. if (cs_generate_rtti in aktlocalswitches) or
  1190. (assigned(aktclass^.childof) and
  1191. ((aktclass^.childof^.options and oo_can_have_published)<>0)
  1192. ) then
  1193. aktclass^.options:=aktclass^.options or oo_can_have_published;
  1194. end;
  1195. aktobjectdef:=aktclass;
  1196. { default access is public }
  1197. actmembertype:=sp_public;
  1198. aktclass^.publicsyms^.next:=symtablestack;
  1199. symtablestack:=aktclass^.publicsyms;
  1200. procinfo._class:=aktclass;
  1201. testcurobject:=1;
  1202. curobjectname:=n;
  1203. { short class declaration ? }
  1204. if (not is_a_class) or (token<>SEMICOLON) then
  1205. begin
  1206. { Parse componenten }
  1207. repeat
  1208. if actmembertype=sp_private then
  1209. aktclass^.options:=aktclass^.options or oo_hasprivate;
  1210. if actmembertype=sp_protected then
  1211. aktclass^.options:=aktclass^.options or oo_hasprotected;
  1212. case token of
  1213. ID : begin
  1214. case idtoken of
  1215. _PRIVATE : begin
  1216. consume(_PRIVATE);
  1217. actmembertype:=sp_private;
  1218. current_object_option:=sp_private;
  1219. end;
  1220. _PROTECTED : begin
  1221. consume(_PROTECTED);
  1222. current_object_option:=sp_protected;
  1223. actmembertype:=sp_protected;
  1224. end;
  1225. _PUBLIC : begin
  1226. consume(_PUBLIC);
  1227. current_object_option:=sp_public;
  1228. actmembertype:=sp_public;
  1229. end;
  1230. _PUBLISHED : begin
  1231. if (aktclass^.options and oo_can_have_published)=0 then
  1232. Message(parser_e_cant_have_published);
  1233. consume(_PUBLISHED);
  1234. current_object_option:=sp_published;
  1235. actmembertype:=sp_published;
  1236. end;
  1237. else
  1238. read_var_decs(false,true);
  1239. end;
  1240. end;
  1241. _PROPERTY : property_dec;
  1242. _PROCEDURE,
  1243. _FUNCTION,
  1244. _CLASS : begin
  1245. oldparse_only:=parse_only;
  1246. parse_only:=true;
  1247. parse_proc_dec;
  1248. parse_only:=oldparse_only;
  1249. case idtoken of
  1250. _DYNAMIC,
  1251. _VIRTUAL : begin
  1252. if actmembertype=sp_private then
  1253. Message(parser_w_priv_meth_not_virtual);
  1254. consume(idtoken);
  1255. consume(SEMICOLON);
  1256. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1257. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1258. end;
  1259. _OVERRIDE : begin
  1260. consume(_OVERRIDE);
  1261. consume(SEMICOLON);
  1262. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1263. pooverridingmethod or povirtualmethod;
  1264. end;
  1265. end;
  1266. if idtoken=_abstract then
  1267. begin
  1268. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  1269. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or poabstractmethod
  1270. else
  1271. Message(parser_e_only_virtual_methods_abstract);
  1272. consume(_ABSTRACT);
  1273. consume(SEMICOLON);
  1274. { the method is defined }
  1275. aktprocsym^.definition^.forwarddef:=false;
  1276. end;
  1277. if (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  1278. begin
  1279. consume(_STATIC);
  1280. consume(SEMICOLON);
  1281. aktprocsym^.properties:=aktprocsym^.properties or sp_static;
  1282. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or postaticmethod;
  1283. end;
  1284. end;
  1285. _CONSTRUCTOR : begin
  1286. if actmembertype<>sp_public then
  1287. Message(parser_w_constructor_should_be_public);
  1288. oldparse_only:=parse_only;
  1289. parse_only:=true;
  1290. constructor_head;
  1291. parse_only:=oldparse_only;
  1292. case idtoken of
  1293. _DYNAMIC,
  1294. _VIRTUAL : begin
  1295. if not(aktclass^.isclass) then
  1296. Message(parser_e_constructor_cannot_be_not_virtual)
  1297. else
  1298. begin
  1299. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1300. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1301. end;
  1302. consume(idtoken);
  1303. consume(SEMICOLON);
  1304. end;
  1305. _OVERRIDE : begin
  1306. if (aktclass^.options and oo_is_class=0) then
  1307. Message(parser_e_constructor_cannot_be_not_virtual)
  1308. else
  1309. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1310. pooverridingmethod or povirtualmethod;
  1311. consume(_OVERRIDE);
  1312. consume(SEMICOLON);
  1313. end;
  1314. end;
  1315. end;
  1316. _DESTRUCTOR : begin
  1317. if there_is_a_destructor then
  1318. Message(parser_n_only_one_destructor);
  1319. there_is_a_destructor:=true;
  1320. if actmembertype<>sp_public then
  1321. Message(parser_w_destructor_should_be_public);
  1322. oldparse_only:=parse_only;
  1323. parse_only:=true;
  1324. destructor_head;
  1325. parse_only:=oldparse_only;
  1326. case idtoken of
  1327. _DYNAMIC,
  1328. _VIRTUAL : begin
  1329. consume(idtoken);
  1330. consume(SEMICOLON);
  1331. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1332. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1333. end;
  1334. _OVERRIDE : begin
  1335. consume(_OVERRIDE);
  1336. consume(SEMICOLON);
  1337. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1338. pooverridingmethod or povirtualmethod;
  1339. end;
  1340. end;
  1341. end;
  1342. _END : begin
  1343. consume(_END);
  1344. break;
  1345. end;
  1346. else
  1347. consume(ID); { Give a ident expected message, like tp7 }
  1348. end;
  1349. until false;
  1350. current_object_option:=sp_public;
  1351. end;
  1352. testcurobject:=0;
  1353. curobjectname:='';
  1354. typecanbeforward:=storetypeforwardsallowed;
  1355. { generate vmt space if needed }
  1356. if ((aktclass^.options and
  1357. (oo_hasvirtual or oo_hasconstructor or
  1358. oo_hasdestructor or oo_is_class))<>0) and
  1359. ((aktclass^.options and
  1360. oo_hasvmt)=0) then
  1361. aktclass^.insertvmt;
  1362. if (cs_smartlink in aktmoduleswitches) then
  1363. datasegment^.concat(new(pai_cut,init));
  1364. { write extended info for classes }
  1365. if is_a_class then
  1366. begin
  1367. if (aktclass^.options and oo_can_have_published)<>0 then
  1368. aktclass^.generate_rtti;
  1369. { write class name }
  1370. getlabel(classnamelabel);
  1371. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1372. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.name^))));
  1373. datasegment^.concat(new(pai_string,init(aktclass^.name^)));
  1374. { interface table }
  1375. datasegment^.concat(new(pai_const,init_32bit(0)));
  1376. { auto table }
  1377. datasegment^.concat(new(pai_const,init_32bit(0)));
  1378. { inittable for con-/destruction }
  1379. if aktclass^.needs_inittable then
  1380. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(aktclass^.get_inittable_label)))))
  1381. else
  1382. datasegment^.concat(new(pai_const,init_32bit(0)));
  1383. { pointer to type info of published section }
  1384. if (aktclass^.options and oo_can_have_published)<>0 then
  1385. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.rtti_name))))
  1386. else
  1387. datasegment^.concat(new(pai_const,init_32bit(0)));
  1388. { pointer to field table }
  1389. datasegment^.concat(new(pai_const,init_32bit(0)));
  1390. { pointer to method table }
  1391. datasegment^.concat(new(pai_const,init_32bit(0)));
  1392. { pointer to dynamic table }
  1393. datasegment^.concat(new(pai_const,init_32bit(0)));
  1394. { pointer to class name string }
  1395. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(classnamelabel)))));
  1396. end;
  1397. {$ifdef GDB}
  1398. { generate the VMT }
  1399. if (cs_debuginfo in aktmoduleswitches) and
  1400. ((aktclass^.options and oo_hasvmt)<>0) then
  1401. begin
  1402. do_count_dbx:=true;
  1403. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1404. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1405. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1406. end;
  1407. {$endif GDB}
  1408. if ((aktclass^.options and oo_hasvmt)<>0) then
  1409. begin
  1410. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  1411. { determine the size with publicsyms^.datasize, because }
  1412. { size gives back 4 for classes }
  1413. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  1414. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  1415. { write pointer to parent VMT, this isn't implemented in TP }
  1416. { but this is not used in FPC ? (PM) }
  1417. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1418. { it is not written for parents that don't have any vmt !! }
  1419. if assigned(aktclass^.childof) and
  1420. ((aktclass^.childof^.options and oo_hasvmt)<>0) then
  1421. begin
  1422. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  1423. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  1424. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  1425. end
  1426. else
  1427. datasegment^.concat(new(pai_const,init_32bit(0)));
  1428. { this generates the entries }
  1429. genvmt(aktclass);
  1430. end;
  1431. { restore old state }
  1432. symtablestack:=symtablestack^.next;
  1433. procinfo._class:=nil;
  1434. aktobjectdef:=nil;
  1435. {Restore the aktprocsym.}
  1436. aktprocsym:=oldprocsym;
  1437. object_dec:=aktclass;
  1438. end;
  1439. { reads a record declaration }
  1440. function record_dec : pdef;
  1441. var
  1442. symtable : psymtable;
  1443. storetypeforwardsallowed : boolean;
  1444. begin
  1445. symtable:=new(psymtable,init(recordsymtable));
  1446. symtable^.next:=symtablestack;
  1447. symtablestack:=symtable;
  1448. consume(_RECORD);
  1449. storetypeforwardsallowed:=typecanbeforward;
  1450. if m_tp in aktmodeswitches then
  1451. typecanbeforward:=false;
  1452. read_var_decs(true,false);
  1453. { may be scale record size to a size of n*4 ? }
  1454. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  1455. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  1456. consume(_END);
  1457. typecanbeforward:=storetypeforwardsallowed;
  1458. symtablestack:=symtable^.next;
  1459. record_dec:=new(precdef,init(symtable));
  1460. end;
  1461. { reads a type definition and returns a pointer to it }
  1462. function read_type(const name : stringid) : pdef;
  1463. function handle_procvar:Pprocvardef;
  1464. var
  1465. sc : pstringcontainer;
  1466. s : string;
  1467. p : pdef;
  1468. varspez : tvarspez;
  1469. procvardef : pprocvardef;
  1470. begin
  1471. procvardef:=new(pprocvardef,init);
  1472. if token=LKLAMMER then
  1473. begin
  1474. consume(LKLAMMER);
  1475. inc(testcurobject);
  1476. repeat
  1477. case token of
  1478. _VAR :
  1479. begin
  1480. consume(_VAR);
  1481. varspez:=vs_var;
  1482. end;
  1483. _CONST :
  1484. begin
  1485. consume(_CONST);
  1486. varspez:=vs_const;
  1487. end;
  1488. else
  1489. varspez:=vs_value;
  1490. end;
  1491. sc:=idlist;
  1492. if (token=COLON) or (varspez=vs_value) then
  1493. begin
  1494. consume(COLON);
  1495. if token=_ARRAY then
  1496. begin
  1497. consume(_ARRAY);
  1498. consume(_OF);
  1499. { define range and type of range }
  1500. p:=new(Parraydef,init(0,-1,s32bitdef));
  1501. { array of const ? }
  1502. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  1503. begin
  1504. consume(_CONST);
  1505. srsym:=nil;
  1506. if assigned(objpasunit) then
  1507. getsymonlyin(objpasunit,'TVARREC');
  1508. if not assigned(srsym) then
  1509. InternalError(1234124);
  1510. Parraydef(p)^.definition:=ptypesym(srsym)^.definition;
  1511. Parraydef(p)^.IsArrayOfConst:=true;
  1512. end
  1513. else
  1514. begin
  1515. { define field type }
  1516. Parraydef(p)^.definition:=single_type(s);
  1517. end;
  1518. end
  1519. else
  1520. p:=single_type(s);
  1521. end
  1522. else
  1523. p:=new(pformaldef,init);
  1524. while not sc^.empty do
  1525. begin
  1526. s:=sc^.get;
  1527. procvardef^.concatdef(p,varspez);
  1528. end;
  1529. dispose(sc,done);
  1530. if token=SEMICOLON then
  1531. consume(SEMICOLON)
  1532. else
  1533. break;
  1534. until false;
  1535. dec(testcurobject);
  1536. consume(RKLAMMER);
  1537. end;
  1538. handle_procvar:=procvardef;
  1539. end;
  1540. var
  1541. hp1,p : pdef;
  1542. aufdef : penumdef;
  1543. aufsym : penumsym;
  1544. ap : parraydef;
  1545. s : stringid;
  1546. l,v,oldaktpackrecords : longint;
  1547. hs : string;
  1548. procedure expr_type;
  1549. var
  1550. pt1,pt2 : ptree;
  1551. begin
  1552. { use of current parsed object ? }
  1553. if (token=ID) and (testcurobject=2) and (curobjectname=pattern) then
  1554. begin
  1555. consume(ID);
  1556. p:=aktobjectdef;
  1557. exit;
  1558. end;
  1559. { we can't accept a equal in type }
  1560. pt1:=comp_expr(not(ignore_equal));
  1561. do_firstpass(pt1);
  1562. if (token=POINTPOINT) then
  1563. begin
  1564. consume(POINTPOINT);
  1565. { get high value of range }
  1566. pt2:=comp_expr(not(ignore_equal));
  1567. do_firstpass(pt2);
  1568. { both must be evaluated to constants now }
  1569. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1570. Message(sym_e_error_in_type_def)
  1571. else
  1572. begin
  1573. { check types }
  1574. if not is_equal(pt1^.resulttype,pt2^.resulttype) then
  1575. Message(type_e_mismatch)
  1576. else
  1577. begin
  1578. { Check bounds }
  1579. if pt2^.value<pt1^.value then
  1580. Message(cg_e_upper_lower_than_lower)
  1581. else
  1582. begin
  1583. { All checks passed, create the new def }
  1584. case pt1^.resulttype^.deftype of
  1585. enumdef : p:=new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value));
  1586. orddef : begin
  1587. if is_char(pt1^.resulttype) then
  1588. p:=new(porddef,init(uchar,pt1^.value,pt2^.value))
  1589. else
  1590. if is_boolean(pt1^.resulttype) then
  1591. p:=new(porddef,init(bool8bit,pt1^.value,pt2^.value))
  1592. else
  1593. p:=new(porddef,init(uauto,pt1^.value,pt2^.value));
  1594. end;
  1595. end;
  1596. end;
  1597. end;
  1598. end;
  1599. disposetree(pt2);
  1600. end
  1601. else
  1602. begin
  1603. { a simple type renaming }
  1604. if (pt1^.treetype=typen) then
  1605. p:=pt1^.resulttype
  1606. else
  1607. Message(sym_e_error_in_type_def);
  1608. end;
  1609. disposetree(pt1);
  1610. end;
  1611. var
  1612. pt : ptree;
  1613. procedure array_dec;
  1614. var
  1615. lowval,
  1616. highval : longint;
  1617. arraytype : pdef;
  1618. begin
  1619. consume(_ARRAY);
  1620. consume(LECKKLAMMER);
  1621. { defaults }
  1622. arraytype:=generrordef;
  1623. lowval:=$80000000;
  1624. highval:=$7fffffff;
  1625. p:=nil;
  1626. repeat
  1627. { read the expression and check it }
  1628. pt:=expr;
  1629. if pt^.treetype=typen then
  1630. begin
  1631. case pt^.resulttype^.deftype of
  1632. enumdef : begin
  1633. lowval:=penumdef(pt^.resulttype)^.min;
  1634. highval:=penumdef(pt^.resulttype)^.max;
  1635. arraytype:=pt^.resulttype;
  1636. end;
  1637. orddef : begin
  1638. case porddef(pt^.resulttype)^.typ of
  1639. s8bit,u8bit,
  1640. s16bit,u16bit,
  1641. s32bit : begin
  1642. lowval:=porddef(pt^.resulttype)^.low;
  1643. highval:=porddef(pt^.resulttype)^.high;
  1644. arraytype:=pt^.resulttype;
  1645. end;
  1646. bool8bit,
  1647. bool16bit,
  1648. bool32bit : begin
  1649. lowval:=0;
  1650. highval:=1;
  1651. arraytype:=pt^.resulttype;
  1652. end;
  1653. uchar : begin
  1654. lowval:=0;
  1655. highval:=255;
  1656. arraytype:=pt^.resulttype;
  1657. end;
  1658. else
  1659. Message(sym_e_error_in_type_def);
  1660. end;
  1661. end;
  1662. else
  1663. Message(sym_e_error_in_type_def);
  1664. end
  1665. end
  1666. else
  1667. begin
  1668. do_firstpass(pt);
  1669. if (pt^.treetype=rangen) then
  1670. begin
  1671. if (pt^.left^.treetype=ordconstn) and
  1672. (pt^.right^.treetype=ordconstn) then
  1673. begin
  1674. lowval:=pt^.left^.value;
  1675. highval:=pt^.right^.value;
  1676. arraytype:=pt^.right^.resulttype;
  1677. end
  1678. else
  1679. Message(type_e_cant_eval_constant_expr);
  1680. end
  1681. else
  1682. Message(sym_e_error_in_type_def)
  1683. end;
  1684. disposetree(pt);
  1685. { create arraydef }
  1686. if p=nil then
  1687. begin
  1688. ap:=new(parraydef,init(lowval,highval,arraytype));
  1689. p:=ap;
  1690. end
  1691. else
  1692. begin
  1693. ap^.definition:=new(parraydef,init(lowval,highval,arraytype));
  1694. ap:=parraydef(ap^.definition);
  1695. end;
  1696. if token=COMMA then
  1697. consume(COMMA)
  1698. else
  1699. break;
  1700. until false;
  1701. consume(RECKKLAMMER);
  1702. consume(_OF);
  1703. hp1:=read_type('');
  1704. { if no error, set element type }
  1705. if assigned(ap) then
  1706. ap^.definition:=hp1;
  1707. end;
  1708. begin
  1709. p:=nil;
  1710. case token of
  1711. _STRING,_FILE:
  1712. p:=single_type(hs);
  1713. LKLAMMER:
  1714. begin
  1715. consume(LKLAMMER);
  1716. { allow negativ value_str }
  1717. l:=-1;
  1718. aufsym := Nil;
  1719. aufdef:=new(penumdef,init);
  1720. repeat
  1721. s:=pattern;
  1722. consume(ID);
  1723. if token=ASSIGNMENT then
  1724. begin
  1725. consume(ASSIGNMENT);
  1726. v:=get_intconst;
  1727. { please leave that a note, allows type save }
  1728. { declarations in the win32 units ! }
  1729. if v<=l then
  1730. Message(parser_n_duplicate_enum);
  1731. l:=v;
  1732. end
  1733. else
  1734. inc(l);
  1735. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1736. if token=COMMA then
  1737. consume(COMMA)
  1738. else
  1739. break;
  1740. until false;
  1741. {aufdef^.max:=l;
  1742. if we allow unordered enums
  1743. this can be wrong
  1744. min and max are now set in tenumsym.init PM }
  1745. p:=aufdef;
  1746. consume(RKLAMMER);
  1747. end;
  1748. _ARRAY:
  1749. array_dec;
  1750. _SET:
  1751. begin
  1752. consume(_SET);
  1753. consume(_OF);
  1754. hp1:=read_type('');
  1755. if assigned(hp1) then
  1756. begin
  1757. case hp1^.deftype of
  1758. { don't forget that min can be negativ PM }
  1759. enumdef : if penumdef(hp1)^.min>=0 then
  1760. p:=new(psetdef,init(hp1,penumdef(hp1)^.max))
  1761. else
  1762. Message(sym_e_ill_type_decl_set);
  1763. orddef : begin
  1764. case porddef(hp1)^.typ of
  1765. uchar : p:=new(psetdef,init(hp1,255));
  1766. u8bit,s8bit,u16bit,s16bit,s32bit :
  1767. begin
  1768. if (porddef(hp1)^.low>=0) then
  1769. p:=new(psetdef,init(hp1,porddef(hp1)^.high))
  1770. else Message(sym_e_ill_type_decl_set);
  1771. end;
  1772. else Message(sym_e_ill_type_decl_set);
  1773. end;
  1774. end;
  1775. else Message(sym_e_ill_type_decl_set);
  1776. end;
  1777. end
  1778. else
  1779. p:=generrordef;
  1780. end;
  1781. CARET:
  1782. begin
  1783. consume(CARET);
  1784. { forwards allowed only inside TYPE statements }
  1785. if typecanbeforward then
  1786. forwardsallowed:=true;
  1787. hp1:=single_type(hs);
  1788. p:=new(ppointerdef,init(hp1));
  1789. {I add big troubles here
  1790. with var p : ^byte in graph.putimage
  1791. because a save_forward was called and
  1792. no resolve forward
  1793. => so the definition was rewritten after
  1794. having been disposed !!
  1795. Strange problems appeared !!!!}
  1796. {Anyhow forwards should only be allowed
  1797. inside a type statement ??
  1798. don't you think so }
  1799. if (lasttypesym<>nil)
  1800. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1801. lasttypesym^.forwardpointer:=ppointerdef(p);
  1802. forwardsallowed:=false;
  1803. end;
  1804. _RECORD:
  1805. p:=record_dec;
  1806. _PACKED:
  1807. begin
  1808. consume(_PACKED);
  1809. if token=_ARRAY then
  1810. array_dec
  1811. else
  1812. begin
  1813. oldaktpackrecords:=aktpackrecords;
  1814. aktpackrecords:=1;
  1815. if token in [_CLASS,_OBJECT] then
  1816. p:=object_dec(name,nil)
  1817. else
  1818. p:=record_dec;
  1819. aktpackrecords:=oldaktpackrecords;
  1820. end;
  1821. end;
  1822. _CLASS,
  1823. _OBJECT:
  1824. p:=object_dec(name,nil);
  1825. _PROCEDURE:
  1826. begin
  1827. consume(_PROCEDURE);
  1828. p:=handle_procvar;
  1829. if token=_OF then
  1830. begin
  1831. consume(_OF);
  1832. consume(_OBJECT);
  1833. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1834. end;
  1835. end;
  1836. _FUNCTION:
  1837. begin
  1838. consume(_FUNCTION);
  1839. p:=handle_procvar;
  1840. consume(COLON);
  1841. pprocvardef(p)^.retdef:=single_type(hs);
  1842. if token=_OF then
  1843. begin
  1844. consume(_OF);
  1845. consume(_OBJECT);
  1846. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1847. end;
  1848. end;
  1849. else
  1850. expr_type;
  1851. end;
  1852. if p=nil then
  1853. p:=generrordef;
  1854. read_type:=p;
  1855. end;
  1856. { reads a type declaration to the symbol table }
  1857. procedure type_dec;
  1858. var
  1859. typename : stringid;
  1860. newtype : ptypesym;
  1861. {$ifdef dummy}
  1862. olddef,newdef : pdef;
  1863. s : string;
  1864. {$endif dummy}
  1865. begin
  1866. block_type:=bt_type;
  1867. consume(_TYPE);
  1868. typecanbeforward:=true;
  1869. repeat
  1870. typename:=pattern;
  1871. consume(ID);
  1872. consume(EQUAL);
  1873. { here you loose the strictness of pascal
  1874. for which a redefinition like
  1875. childtype = parenttype;
  1876. child2type = parenttype;
  1877. does not make the two child types equal !!
  1878. here all vars from childtype and child2type
  1879. get the definition of parenttype !! }
  1880. {$ifdef testequaltype}
  1881. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1882. begin
  1883. olddef := single_type(s);
  1884. { make a clone of olddef }
  1885. { is that ok ??? }
  1886. getmem(newdef,SizeOf(olddef));
  1887. move(olddef^,newdef^,SizeOf(olddef));
  1888. newtype:=new(ptypesym,init(typename,newdef));
  1889. symtablestack^.insert(newtype);
  1890. end
  1891. else
  1892. {$endif testequaltype}
  1893. begin
  1894. getsym(typename,false);
  1895. { check if it is the definition of a forward defined class }
  1896. if assigned(srsym) and (token=_CLASS) and
  1897. (srsym^.typ=typesym) and
  1898. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1899. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1900. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_is_class)<>0) then
  1901. begin
  1902. { we can ignore the result }
  1903. { the definition is modified }
  1904. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1905. newtype:=ptypesym(srsym);
  1906. end
  1907. else
  1908. begin
  1909. newtype:=new(ptypesym,init(typename,read_type(typename)));
  1910. { load newtype with the new pointer to the inserted type
  1911. because it can be an already defined forwarded type !! }
  1912. newtype:=ptypesym(symtablestack^.insert(newtype));
  1913. end;
  1914. end;
  1915. consume(SEMICOLON);
  1916. if assigned(newtype^.definition) and (newtype^.definition^.deftype=procvardef) then
  1917. parse_var_proc_directives(newtype);
  1918. until token<>ID;
  1919. typecanbeforward:=false;
  1920. {$ifdef tp}
  1921. symtablestack^.foreach(testforward_type);
  1922. {$else}
  1923. symtablestack^.foreach(@testforward_type);
  1924. {$endif}
  1925. resolve_forwards;
  1926. block_type:=bt_general;
  1927. end;
  1928. procedure var_dec;
  1929. { parses varaible declarations and inserts them in }
  1930. { the top symbol table of symtablestack }
  1931. begin
  1932. consume(_VAR);
  1933. read_var_decs(false,false);
  1934. end;
  1935. procedure Not_supported_for_inline(t : ttoken);
  1936. begin
  1937. if assigned(aktprocsym) and
  1938. ((aktprocsym^.definition^.options and poinline)<>0) then
  1939. Begin
  1940. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1941. Message(parser_w_inlining_disabled);
  1942. aktprocsym^.definition^.options:= aktprocsym^.definition^.options and not poinline;
  1943. End;
  1944. end;
  1945. procedure read_declarations(islibrary : boolean);
  1946. begin
  1947. repeat
  1948. case token of
  1949. _LABEL:
  1950. begin
  1951. Not_supported_for_inline(token);
  1952. label_dec;
  1953. end;
  1954. _CONST:
  1955. begin
  1956. Not_supported_for_inline(token);
  1957. const_dec;
  1958. end;
  1959. _TYPE:
  1960. begin
  1961. Not_supported_for_inline(token);
  1962. type_dec;
  1963. end;
  1964. _VAR:
  1965. var_dec;
  1966. _CONSTRUCTOR,_DESTRUCTOR,
  1967. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1968. begin
  1969. Not_supported_for_inline(token);
  1970. read_proc;
  1971. end;
  1972. _EXPORTS:
  1973. begin
  1974. Not_supported_for_inline(token);
  1975. { here we should be at lexlevel 1, no ? PM }
  1976. if (lexlevel<>main_program_level) or
  1977. (not islibrary and not DLLsource) then
  1978. begin
  1979. Message(parser_e_syntax_error);
  1980. consume_all_until(SEMICOLON);
  1981. end
  1982. else if islibrary then
  1983. read_exports;
  1984. end
  1985. else break;
  1986. end;
  1987. until false;
  1988. end;
  1989. procedure read_interface_declarations;
  1990. begin
  1991. {Since the body is now parsed at lexlevel 1, and the declarations
  1992. must be parsed at the same lexlevel we increase the lexlevel.}
  1993. inc(lexlevel);
  1994. repeat
  1995. case token of
  1996. _CONST : const_dec;
  1997. _TYPE : type_dec;
  1998. _VAR : var_dec;
  1999. _FUNCTION,
  2000. _PROCEDURE,
  2001. _OPERATOR : read_proc;
  2002. else
  2003. break;
  2004. end;
  2005. until false;
  2006. dec(lexlevel);
  2007. end;
  2008. end.
  2009. {
  2010. $Log$
  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. }