pdecl.pas 90 KB

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