pdecl.pas 84 KB

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