pdecl.pas 111 KB

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