pdecl.pas 94 KB

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