pdecl.pas 109 KB

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