pdecl.pas 88 KB

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