pdecl.pas 89 KB

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