pdecl.pas 112 KB

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