pdecl.pas 91 KB

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