pdecl.pas 90 KB

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