pdecl.pas 93 KB

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