pdecl.pas 106 KB

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