pdecl.pas 87 KB

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