pdecl.pas 86 KB

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