pdecl.pas 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363
  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. consume(SEMICOLON);
  655. begin
  656. if (aktclass^.options and oois_class)<>0 then
  657. begin
  658. { CLASS constructors return the created instance }
  659. aktprocsym^.definition^.retdef:=aktclass;
  660. end
  661. else
  662. begin
  663. { OBJECT constructors return a boolean }
  664. {$IfDef GDB}
  665. {GDB doesn't like unnamed types !}
  666. aktprocsym^.definition^.retdef:=
  667. globaldef('boolean');
  668. {$Else GDB}
  669. aktprocsym^.definition^.retdef:=
  670. new(porddef,init(bool8bit,0,1));
  671. {$Endif GDB}
  672. end;
  673. end;
  674. end;
  675. procedure property_dec;
  676. var
  677. sym : psym;
  678. propertyparas : pdefcoll;
  679. { returns the matching procedure to access a property }
  680. function get_procdef : pprocdef;
  681. var
  682. p : pprocdef;
  683. begin
  684. p:=pprocsym(sym)^.definition;
  685. get_procdef:=nil;
  686. while assigned(p) do
  687. begin
  688. if equal_paras(p^.para1,propertyparas,true) then
  689. break;
  690. p:=p^.nextoverloaded;
  691. end;
  692. get_procdef:=p;
  693. end;
  694. var
  695. hp2,datacoll : pdefcoll;
  696. p,p2 : ppropertysym;
  697. overriden : psym;
  698. hs : string;
  699. code : word;
  700. varspez : tvarspez;
  701. sc : pstringcontainer;
  702. hp : pdef;
  703. s : string;
  704. declarepos : tfileposinfo;
  705. pp : pprocdef;
  706. pt : ptree;
  707. propname : stringid;
  708. begin
  709. { check for a class }
  710. if (aktclass^.options and oois_class=0) then
  711. Message(parser_e_syntax_error);
  712. consume(_PROPERTY);
  713. propertyparas:=nil;
  714. datacoll:=nil;
  715. if token=ID then
  716. begin
  717. p:=new(ppropertysym,init(pattern));
  718. propname:=pattern;
  719. consume(ID);
  720. { property parameters ? }
  721. if token=LECKKLAMMER then
  722. begin
  723. if current_object_option=sp_published then
  724. Message(parser_e_cant_publish_that_property);
  725. { create a list of the parameters in propertyparas }
  726. consume(LECKKLAMMER);
  727. inc(testcurobject);
  728. repeat
  729. if token=_VAR then
  730. begin
  731. consume(_VAR);
  732. varspez:=vs_var;
  733. end
  734. else if token=_CONST then
  735. begin
  736. consume(_CONST);
  737. varspez:=vs_const;
  738. end
  739. else varspez:=vs_value;
  740. sc:=idlist;
  741. if token=COLON then
  742. begin
  743. consume(COLON);
  744. if token=_ARRAY then
  745. begin
  746. {
  747. if (varspez<>vs_const) and
  748. (varspez<>vs_var) then
  749. begin
  750. varspez:=vs_const;
  751. Message(parser_e_illegal_open_parameter);
  752. end;
  753. }
  754. consume(_ARRAY);
  755. consume(_OF);
  756. { define range and type of range }
  757. hp:=new(parraydef,init(0,-1,s32bitdef));
  758. { define field type }
  759. parraydef(hp)^.definition:=single_type(s);
  760. end
  761. else
  762. hp:=single_type(s);
  763. end
  764. else
  765. hp:=new(pformaldef,init);
  766. s:=sc^.get_with_tokeninfo(declarepos);
  767. while s<>'' do
  768. begin
  769. new(hp2);
  770. hp2^.paratyp:=varspez;
  771. hp2^.data:=hp;
  772. hp2^.next:=propertyparas;
  773. propertyparas:=hp2;
  774. s:=sc^.get_with_tokeninfo(declarepos);
  775. end;
  776. dispose(sc,done);
  777. if token=SEMICOLON then consume(SEMICOLON)
  778. else break;
  779. until false;
  780. dec(testcurobject);
  781. consume(RECKKLAMMER);
  782. end;
  783. { overriden property ? }
  784. { force property interface, if there is a property parameter }
  785. if (token=COLON) or assigned(propertyparas) then
  786. begin
  787. consume(COLON);
  788. p^.proptype:=single_type(hs);
  789. if (idtoken=_INDEX) then
  790. begin
  791. consume(_INDEX);
  792. p^.options:=p^.options or ppo_indexed;
  793. if token=INTCONST then
  794. val(pattern,p^.index,code);
  795. consume(INTCONST);
  796. { concat a longint to the para template }
  797. new(hp2);
  798. hp2^.paratyp:=vs_value;
  799. hp2^.data:=s32bitdef;
  800. hp2^.next:=propertyparas;
  801. propertyparas:=hp2;
  802. end;
  803. end
  804. else
  805. begin
  806. { do an property override }
  807. overriden:=search_class_member(aktclass,propname);
  808. if assigned(overriden) and (overriden^.typ=propertysym) then
  809. begin
  810. { take the whole info: }
  811. p^.options:=ppropertysym(overriden)^.options;
  812. p^.index:=ppropertysym(overriden)^.index;
  813. p^.proptype:=ppropertysym(overriden)^.proptype;
  814. p^.writeaccesssym:=ppropertysym(overriden)^.writeaccesssym;
  815. p^.readaccesssym:=ppropertysym(overriden)^.readaccesssym;
  816. p^.writeaccessdef:=ppropertysym(overriden)^.writeaccessdef;
  817. p^.readaccessdef:=ppropertysym(overriden)^.readaccessdef;
  818. p^.storedsym:=ppropertysym(overriden)^.storedsym;
  819. p^.storeddef:=ppropertysym(overriden)^.storeddef;
  820. p^.default:=ppropertysym(overriden)^.default;
  821. end
  822. else
  823. begin
  824. p^.proptype:=generrordef;
  825. message(parser_e_no_property_found_to_override);
  826. end;
  827. end;
  828. if (current_object_option=sp_published) and
  829. not(p^.proptype^.is_publishable) then
  830. Message(parser_e_cant_publish_that_property);
  831. { create data defcoll to allow correct parameter checks }
  832. new(datacoll);
  833. datacoll^.paratyp:=vs_value;
  834. datacoll^.data:=p^.proptype;
  835. datacoll^.next:=nil;
  836. if (idtoken=_READ) then
  837. begin
  838. consume(_READ);
  839. sym:=search_class_member(aktclass,pattern);
  840. if not(assigned(sym)) then
  841. Message1(sym_e_unknown_id,pattern)
  842. else
  843. begin
  844. { varsym aren't allowed for an indexed property
  845. or an property with parameters }
  846. if ((sym^.typ=varsym) and
  847. { not necessary, an index forces propertyparas
  848. to be assigned
  849. }
  850. { (((p^.options and ppo_indexed)<>0) or }
  851. assigned(propertyparas)) or
  852. not(sym^.typ in [varsym,procsym]) then
  853. Message(parser_e_ill_property_access_sym);
  854. { search the matching definition }
  855. if sym^.typ=procsym then
  856. begin
  857. pp:=get_procdef;
  858. if not(assigned(pp)) or
  859. not(is_equal(pp^.retdef,p^.proptype)) then
  860. Message(parser_e_ill_property_access_sym);
  861. p^.readaccessdef:=pp;
  862. end
  863. else if sym^.typ=varsym then
  864. begin
  865. if not(is_equal(pvarsym(sym)^.definition,
  866. p^.proptype)) then
  867. Message(parser_e_ill_property_access_sym);
  868. end;
  869. p^.readaccesssym:=sym;
  870. end;
  871. consume(ID);
  872. end;
  873. if (idtoken=_WRITE) then
  874. begin
  875. consume(_WRITE);
  876. sym:=search_class_member(aktclass,pattern);
  877. if not(assigned(sym)) then
  878. Message1(sym_e_unknown_id,pattern)
  879. else
  880. begin
  881. if ((sym^.typ=varsym) and
  882. assigned(propertyparas)) or
  883. not(sym^.typ in [varsym,procsym]) then
  884. Message(parser_e_ill_property_access_sym);
  885. { search the matching definition }
  886. if sym^.typ=procsym then
  887. begin
  888. { insert data entry to check access method }
  889. datacoll^.next:=propertyparas;
  890. propertyparas:=datacoll;
  891. pp:=get_procdef;
  892. { ... and remove it }
  893. propertyparas:=propertyparas^.next;
  894. datacoll^.next:=nil;
  895. if not(assigned(pp)) then
  896. Message(parser_e_ill_property_access_sym);
  897. p^.writeaccessdef:=pp;
  898. end
  899. else if sym^.typ=varsym then
  900. begin
  901. if not(is_equal(pvarsym(sym)^.definition,
  902. p^.proptype)) then
  903. Message(parser_e_ill_property_access_sym);
  904. end;
  905. p^.writeaccesssym:=sym;
  906. end;
  907. consume(ID);
  908. end;
  909. if (idtoken=_STORED) then
  910. begin
  911. consume(_STORED);
  912. Message(parser_w_stored_not_implemented);
  913. { !!!!!!!! }
  914. end;
  915. if (idtoken=_DEFAULT) then
  916. begin
  917. consume(_DEFAULT);
  918. if not(is_ordinal(p^.proptype) or
  919. ((p^.proptype^.deftype=setdef) and
  920. (psetdef(p^.proptype)^.settype=smallset)
  921. ) or
  922. assigned(propertyparas)
  923. ) then
  924. Message(parser_e_property_cant_have_a_default_value);
  925. pt:=comp_expr(true);
  926. pt:=gentypeconvnode(pt,p^.proptype);
  927. do_firstpass(pt);
  928. if not(is_constnode(pt)) then
  929. Message(parser_e_property_default_value_must_const);
  930. if pt^.treetype=setconstn then
  931. p^.default:=plongint(pt^.value_set)^
  932. else
  933. p^.default:=pt^.value;
  934. disposetree(pt);
  935. end
  936. else if (idtoken=_NODEFAULT) then
  937. begin
  938. consume(_NODEFAULT);
  939. p^.default:=0;
  940. end;
  941. symtablestack^.insert(p);
  942. { default property ? }
  943. consume(SEMICOLON);
  944. if (idtoken=_DEFAULT) then
  945. begin
  946. consume(_DEFAULT);
  947. p2:=search_default_property(aktclass);
  948. if assigned(p2) then
  949. message1(parser_e_only_one_default_property,
  950. pobjectdef(p2^.owner^.defowner)^.name^)
  951. else
  952. begin
  953. p^.options:=p^.options or ppo_defaultproperty;
  954. if not(assigned(propertyparas)) then
  955. message(parser_e_property_need_paras);
  956. end;
  957. consume(SEMICOLON);
  958. end;
  959. { clean up }
  960. if assigned(datacoll) then
  961. disposepdefcoll(datacoll);
  962. end
  963. else
  964. begin
  965. consume(ID);
  966. consume(SEMICOLON);
  967. end;
  968. if assigned(propertyparas) then
  969. disposepdefcoll(propertyparas);
  970. end;
  971. procedure destructor_head;
  972. begin
  973. consume(_DESTRUCTOR);
  974. parse_proc_head(podestructor);
  975. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  976. Message(parser_e_destructorname_must_be_done);
  977. consume(SEMICOLON);
  978. if assigned(aktprocsym^.definition^.para1) then
  979. Message(parser_e_no_paras_for_destructor);
  980. { no return value }
  981. aktprocsym^.definition^.retdef:=voiddef;
  982. end;
  983. var
  984. hs : string;
  985. pcrd : pclassrefdef;
  986. hp1 : pdef;
  987. oldprocsym : Pprocsym;
  988. oldparse_only : boolean;
  989. classnamelabel : plabel;
  990. storetypeforwardsallowed : boolean;
  991. begin
  992. {Nowadays aktprocsym may already have a value, so we need to save
  993. it.}
  994. oldprocsym:=aktprocsym;
  995. { forward is resolved }
  996. if assigned(fd) then
  997. fd^.options:=fd^.options and not(oo_isforward);
  998. there_is_a_destructor:=false;
  999. actmembertype:=sp_public;
  1000. { objects and class types can't be declared local }
  1001. if (symtablestack^.symtabletype<>globalsymtable) and
  1002. (symtablestack^.symtabletype<>staticsymtable) then
  1003. Message(parser_e_no_local_objects);
  1004. storetypeforwardsallowed:=typecanbeforward;
  1005. if m_tp in aktmodeswitches then
  1006. typecanbeforward:=false;
  1007. { distinguish classes and objects }
  1008. if token=_OBJECT then
  1009. begin
  1010. is_a_class:=false;
  1011. consume(_OBJECT)
  1012. end
  1013. else
  1014. begin
  1015. is_a_class:=true;
  1016. consume(_CLASS);
  1017. if not(assigned(fd)) and (token=_OF) then
  1018. begin
  1019. { a hack, but it's easy to handle }
  1020. { class reference type }
  1021. consume(_OF);
  1022. if typecanbeforward then
  1023. forwardsallowed:=true;
  1024. hp1:=single_type(hs);
  1025. { accept hp1, if is a forward def ...}
  1026. if ((lasttypesym<>nil)
  1027. and ((lasttypesym^.properties and sp_forwarddef)<>0)) or
  1028. { or a class
  1029. (if the foward defined type is a class is checked, when
  1030. the forward is resolved)
  1031. }
  1032. ((hp1^.deftype=objectdef) and (
  1033. (pobjectdef(hp1)^.options and oois_class)<>0)) then
  1034. begin
  1035. pcrd:=new(pclassrefdef,init(hp1));
  1036. object_dec:=pcrd;
  1037. {I add big troubles here
  1038. with var p : ^byte in graph.putimage
  1039. because a save_forward was called and
  1040. no resolve forward
  1041. => so the definition was rewritten after
  1042. having been disposed !!
  1043. Strange problems appeared !!!!}
  1044. {Anyhow forwards should only be allowed
  1045. inside a type statement ??
  1046. don't you think so }
  1047. if (lasttypesym<>nil)
  1048. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1049. lasttypesym^.forwardpointer:=ppointerdef(pcrd);
  1050. forwardsallowed:=false;
  1051. end
  1052. else
  1053. begin
  1054. Message(type_e_class_type_expected);
  1055. object_dec:=new(perrordef,init);
  1056. end;
  1057. exit;
  1058. end
  1059. { forward class }
  1060. else if not(assigned(fd)) and (token=SEMICOLON) then
  1061. begin
  1062. { also anonym objects aren't allow (o : object a : longint; end;) }
  1063. if n='' then
  1064. Message(parser_e_no_anonym_objects);
  1065. if n='TOBJECT' then
  1066. begin
  1067. aktclass:=new(pobjectdef,init(n,nil));
  1068. class_tobject:=aktclass;
  1069. end
  1070. else
  1071. aktclass:=new(pobjectdef,init(n,class_tobject));
  1072. aktclass^.options:=aktclass^.options or oois_class or oo_isforward;
  1073. object_dec:=aktclass;
  1074. exit;
  1075. end;
  1076. end;
  1077. { also anonym objects aren't allow (o : object a : longint; end;) }
  1078. if n='' then
  1079. Message(parser_e_no_anonym_objects);
  1080. { read the parent class }
  1081. if token=LKLAMMER then
  1082. begin
  1083. consume(LKLAMMER);
  1084. { does not allow objects.tobject !! }
  1085. {if token<>ID then
  1086. consume(ID);
  1087. getsym(pattern,true);}
  1088. childof:=pobjectdef(id_type(pattern));
  1089. if (childof^.deftype<>objectdef) then
  1090. begin
  1091. Message(type_e_class_type_expected);
  1092. childof:=nil;
  1093. end;
  1094. { a mix of class and object isn't allowed }
  1095. if (((childof^.options and oois_class)<>0) and not is_a_class) or
  1096. (((childof^.options and oois_class)=0) and is_a_class) then
  1097. Message(parser_e_mix_of_classes_and_objects);
  1098. if assigned(fd) then
  1099. begin
  1100. { the forward of the child must be resolved to get
  1101. correct field addresses
  1102. }
  1103. if (childof^.options and oo_isforward)<>0 then
  1104. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1105. fd^.childof:=childof;
  1106. aktclass:=fd;
  1107. { ajust the size, because the child could be also
  1108. forward defined
  1109. }
  1110. aktclass^.publicsyms^.datasize:=
  1111. aktclass^.publicsyms^.datasize-4+childof^.publicsyms^.datasize;
  1112. end
  1113. else
  1114. aktclass:=new(pobjectdef,init(n,childof));
  1115. consume(RKLAMMER);
  1116. end
  1117. { if no parent class, then a class get tobject as parent }
  1118. else if is_a_class then
  1119. begin
  1120. { is the current class tobject? }
  1121. { so you could define your own tobject }
  1122. if n='TOBJECT' then
  1123. begin
  1124. if assigned(fd) then
  1125. aktclass:=fd
  1126. else
  1127. aktclass:=new(pobjectdef,init(n,nil));
  1128. class_tobject:=aktclass;
  1129. end
  1130. else
  1131. begin
  1132. childof:=class_tobject;
  1133. if assigned(fd) then
  1134. begin
  1135. { the forward of the child must be resolved to get
  1136. correct field addresses
  1137. }
  1138. if (childof^.options and oo_isforward)<>0 then
  1139. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1140. aktclass:=fd;
  1141. aktclass^.childof:=childof;
  1142. { ajust the size, because the child could be also
  1143. forward defined
  1144. }
  1145. aktclass^.publicsyms^.datasize:=
  1146. aktclass^.publicsyms^.datasize-4+childof^.publicsyms^.datasize;
  1147. end
  1148. else
  1149. begin
  1150. aktclass:=new(pobjectdef,init(n,childof));
  1151. end;
  1152. end;
  1153. end
  1154. else
  1155. aktclass:=new(pobjectdef,init(n,nil));
  1156. { set the class attribute }
  1157. if is_a_class then
  1158. begin
  1159. aktclass^.options:=aktclass^.options or oois_class;
  1160. if (cs_generate_rtti in aktlocalswitches) or
  1161. (assigned(aktclass^.childof) and
  1162. ((aktclass^.childof^.options and oo_can_have_published)<>0)
  1163. ) then
  1164. aktclass^.options:=aktclass^.options or oo_can_have_published;
  1165. end;
  1166. aktobjectdef:=aktclass;
  1167. { default access is public }
  1168. actmembertype:=sp_public;
  1169. aktclass^.publicsyms^.next:=symtablestack;
  1170. symtablestack:=aktclass^.publicsyms;
  1171. procinfo._class:=aktclass;
  1172. testcurobject:=1;
  1173. curobjectname:=n;
  1174. { short class declaration ? }
  1175. if (not is_a_class) or (token<>SEMICOLON) then
  1176. begin
  1177. { Parse componenten }
  1178. repeat
  1179. if actmembertype=sp_private then
  1180. aktclass^.options:=aktclass^.options or oo_hasprivate;
  1181. if actmembertype=sp_protected then
  1182. aktclass^.options:=aktclass^.options or oo_hasprotected;
  1183. case token of
  1184. ID : begin
  1185. case idtoken of
  1186. _PRIVATE : begin
  1187. consume(_PRIVATE);
  1188. actmembertype:=sp_private;
  1189. current_object_option:=sp_private;
  1190. end;
  1191. _PROTECTED : begin
  1192. consume(_PROTECTED);
  1193. current_object_option:=sp_protected;
  1194. actmembertype:=sp_protected;
  1195. end;
  1196. _PUBLIC : begin
  1197. consume(_PUBLIC);
  1198. current_object_option:=sp_public;
  1199. actmembertype:=sp_public;
  1200. end;
  1201. _PUBLISHED : begin
  1202. if (aktclass^.options and oo_can_have_published)=0 then
  1203. Message(parser_e_cant_have_published);
  1204. consume(_PUBLISHED);
  1205. current_object_option:=sp_published;
  1206. actmembertype:=sp_published;
  1207. end;
  1208. else
  1209. read_var_decs(false,true);
  1210. end;
  1211. end;
  1212. _PROPERTY : property_dec;
  1213. _PROCEDURE,
  1214. _FUNCTION,
  1215. _CLASS : begin
  1216. oldparse_only:=parse_only;
  1217. parse_only:=true;
  1218. parse_proc_dec;
  1219. parse_only:=oldparse_only;
  1220. case idtoken of
  1221. _DYNAMIC,
  1222. _VIRTUAL : begin
  1223. if actmembertype=sp_private then
  1224. Message(parser_w_priv_meth_not_virtual);
  1225. consume(idtoken);
  1226. consume(SEMICOLON);
  1227. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1228. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1229. end;
  1230. _OVERRIDE : begin
  1231. consume(_OVERRIDE);
  1232. consume(SEMICOLON);
  1233. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1234. pooverridingmethod or povirtualmethod;
  1235. end;
  1236. end;
  1237. if idtoken=_abstract then
  1238. begin
  1239. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  1240. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or poabstractmethod
  1241. else
  1242. Message(parser_e_only_virtual_methods_abstract);
  1243. consume(_ABSTRACT);
  1244. consume(SEMICOLON);
  1245. { the method is defined }
  1246. aktprocsym^.definition^.forwarddef:=false;
  1247. end;
  1248. if (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  1249. begin
  1250. consume(_STATIC);
  1251. consume(SEMICOLON);
  1252. aktprocsym^.properties:=aktprocsym^.properties or sp_static;
  1253. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or postaticmethod;
  1254. end;
  1255. end;
  1256. _CONSTRUCTOR : begin
  1257. if actmembertype<>sp_public then
  1258. Message(parser_w_constructor_should_be_public);
  1259. oldparse_only:=parse_only;
  1260. parse_only:=true;
  1261. constructor_head;
  1262. parse_only:=oldparse_only;
  1263. case idtoken of
  1264. _DYNAMIC,
  1265. _VIRTUAL : begin
  1266. if not(aktclass^.isclass) then
  1267. Message(parser_e_constructor_cannot_be_not_virtual)
  1268. else
  1269. begin
  1270. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1271. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1272. end;
  1273. consume(idtoken);
  1274. consume(SEMICOLON);
  1275. end;
  1276. _OVERRIDE : begin
  1277. if (aktclass^.options and oois_class=0) then
  1278. Message(parser_e_constructor_cannot_be_not_virtual)
  1279. else
  1280. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1281. pooverridingmethod or povirtualmethod;
  1282. consume(_OVERRIDE);
  1283. consume(SEMICOLON);
  1284. end;
  1285. end;
  1286. end;
  1287. _DESTRUCTOR : begin
  1288. if there_is_a_destructor then
  1289. Message(parser_n_only_one_destructor);
  1290. there_is_a_destructor:=true;
  1291. if actmembertype<>sp_public then
  1292. Message(parser_w_destructor_should_be_public);
  1293. oldparse_only:=parse_only;
  1294. parse_only:=true;
  1295. destructor_head;
  1296. parse_only:=oldparse_only;
  1297. case idtoken of
  1298. _DYNAMIC,
  1299. _VIRTUAL : begin
  1300. consume(idtoken);
  1301. consume(SEMICOLON);
  1302. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1303. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1304. end;
  1305. _OVERRIDE : begin
  1306. consume(_OVERRIDE);
  1307. consume(SEMICOLON);
  1308. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1309. pooverridingmethod or povirtualmethod;
  1310. end;
  1311. end;
  1312. end;
  1313. _END : begin
  1314. consume(_END);
  1315. break;
  1316. end;
  1317. else
  1318. consume(ID); { Give a ident expected message, like tp7 }
  1319. end;
  1320. until false;
  1321. current_object_option:=sp_public;
  1322. end;
  1323. testcurobject:=0;
  1324. curobjectname:='';
  1325. typecanbeforward:=storetypeforwardsallowed;
  1326. if (cs_smartlink in aktmoduleswitches) then
  1327. datasegment^.concat(new(pai_cut,init));
  1328. { write extended info for classes }
  1329. if is_a_class then
  1330. begin
  1331. if (aktclass^.options and oo_can_have_published)<>0 then
  1332. aktclass^.generate_rtti;
  1333. { write class name }
  1334. getlabel(classnamelabel);
  1335. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1336. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.name^))));
  1337. datasegment^.concat(new(pai_string,init(aktclass^.name^)));
  1338. { interface table }
  1339. datasegment^.concat(new(pai_const,init_32bit(0)));
  1340. { auto table }
  1341. datasegment^.concat(new(pai_const,init_32bit(0)));
  1342. { inittable for con-/destruction }
  1343. if aktclass^.needs_inittable then
  1344. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(aktclass^.get_inittable_label)))))
  1345. else
  1346. datasegment^.concat(new(pai_const,init_32bit(0)));
  1347. { pointer to type info of published section }
  1348. if (aktclass^.options and oo_can_have_published)<>0 then
  1349. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.rtti_name))))
  1350. else
  1351. datasegment^.concat(new(pai_const,init_32bit(0)));
  1352. { pointer to field table }
  1353. datasegment^.concat(new(pai_const,init_32bit(0)));
  1354. { pointer to method table }
  1355. datasegment^.concat(new(pai_const,init_32bit(0)));
  1356. { pointer to dynamic table }
  1357. datasegment^.concat(new(pai_const,init_32bit(0)));
  1358. { pointer to class name string }
  1359. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(classnamelabel)))));
  1360. end;
  1361. {$ifdef GDB}
  1362. { generate the VMT }
  1363. if cs_debuginfo in aktmoduleswitches then
  1364. begin
  1365. do_count_dbx:=true;
  1366. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1367. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1368. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1369. end;
  1370. {$endif GDB}
  1371. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  1372. { determine the size with publicsyms^.datasize, because }
  1373. { size gives back 4 for CLASSes }
  1374. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  1375. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  1376. { write pointer to parent VMT, this isn't implemented in TP }
  1377. { but this is not used in FPC ? (PM) }
  1378. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1379. if assigned(aktclass^.childof) then
  1380. begin
  1381. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  1382. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  1383. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  1384. end
  1385. else
  1386. datasegment^.concat(new(pai_const,init_32bit(0)));
  1387. { this generates the entries }
  1388. genvmt(aktclass);
  1389. { restore old state }
  1390. symtablestack:=symtablestack^.next;
  1391. procinfo._class:=nil;
  1392. {Restore the aktprocsym.}
  1393. aktprocsym:=oldprocsym;
  1394. object_dec:=aktclass;
  1395. end;
  1396. { reads a record declaration }
  1397. function record_dec : pdef;
  1398. var
  1399. symtable : psymtable;
  1400. storetypeforwardsallowed : boolean;
  1401. begin
  1402. symtable:=new(psymtable,init(recordsymtable));
  1403. symtable^.next:=symtablestack;
  1404. symtablestack:=symtable;
  1405. consume(_RECORD);
  1406. storetypeforwardsallowed:=typecanbeforward;
  1407. if m_tp in aktmodeswitches then
  1408. typecanbeforward:=false;
  1409. read_var_decs(true,false);
  1410. { may be scale record size to a size of n*4 ? }
  1411. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  1412. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  1413. consume(_END);
  1414. typecanbeforward:=storetypeforwardsallowed;
  1415. symtablestack:=symtable^.next;
  1416. record_dec:=new(precdef,init(symtable));
  1417. end;
  1418. { reads a type definition and returns a pointer to it }
  1419. function read_type(const name : stringid) : pdef;
  1420. function handle_procvar:Pprocvardef;
  1421. var
  1422. sc : pstringcontainer;
  1423. s : string;
  1424. p : pdef;
  1425. varspez : tvarspez;
  1426. procvardef : pprocvardef;
  1427. begin
  1428. procvardef:=new(pprocvardef,init);
  1429. if token=LKLAMMER then
  1430. begin
  1431. consume(LKLAMMER);
  1432. inc(testcurobject);
  1433. repeat
  1434. if token=_VAR then
  1435. begin
  1436. consume(_VAR);
  1437. varspez:=vs_var;
  1438. end
  1439. else if token=_CONST then
  1440. begin
  1441. consume(_CONST);
  1442. varspez:=vs_const;
  1443. end
  1444. else varspez:=vs_value;
  1445. sc:=idlist;
  1446. if token=COLON then
  1447. begin
  1448. consume(COLON);
  1449. if token=_ARRAY then
  1450. begin
  1451. {
  1452. if (varspez<>vs_const) and
  1453. (varspez<>vs_var) then
  1454. begin
  1455. varspez:=vs_const;
  1456. Message(parser_e_illegal_open_parameter);
  1457. end;
  1458. }
  1459. consume(_ARRAY);
  1460. consume(_OF);
  1461. { define range and type of range }
  1462. p:=new(parraydef,init(0,-1,s32bitdef));
  1463. { define field type }
  1464. parraydef(p)^.definition:=single_type(s);
  1465. end
  1466. else
  1467. p:=single_type(s);
  1468. end
  1469. else
  1470. p:=new(pformaldef,init);
  1471. s:=sc^.get;
  1472. while s<>'' do
  1473. begin
  1474. procvardef^.concatdef(p,varspez);
  1475. s:=sc^.get;
  1476. end;
  1477. dispose(sc,done);
  1478. if token=SEMICOLON then consume(SEMICOLON)
  1479. else break;
  1480. until false;
  1481. dec(testcurobject);
  1482. consume(RKLAMMER);
  1483. end;
  1484. handle_procvar:=procvardef;
  1485. end;
  1486. var
  1487. hp1,p : pdef;
  1488. aufdef : penumdef;
  1489. aufsym : penumsym;
  1490. ap : parraydef;
  1491. s : stringid;
  1492. l,v,oldaktpackrecords : longint;
  1493. hs : string;
  1494. procedure expr_type;
  1495. var
  1496. pt1,pt2 : ptree;
  1497. begin
  1498. { use of current parsed object ? }
  1499. if (token=ID) and (testcurobject=2) and (curobjectname=pattern) then
  1500. begin
  1501. consume(ID);
  1502. p:=aktobjectdef;
  1503. exit;
  1504. end;
  1505. { we can't accept a equal in type }
  1506. pt1:=comp_expr(not(ignore_equal));
  1507. do_firstpass(pt1);
  1508. if (token=POINTPOINT) then
  1509. begin
  1510. consume(POINTPOINT);
  1511. { get high value of range }
  1512. pt2:=comp_expr(not(ignore_equal));
  1513. do_firstpass(pt2);
  1514. { both must be evaluated to constants now }
  1515. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1516. Message(sym_e_error_in_type_def)
  1517. else
  1518. begin
  1519. { check types }
  1520. if not is_equal(pt1^.resulttype,pt2^.resulttype) then
  1521. Message(type_e_mismatch)
  1522. else
  1523. begin
  1524. { Check bounds }
  1525. if pt2^.value<pt1^.value then
  1526. Message(cg_e_upper_lower_than_lower)
  1527. else
  1528. begin
  1529. { All checks passed, create the new def }
  1530. case pt1^.resulttype^.deftype of
  1531. enumdef : p:=new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value));
  1532. orddef : begin
  1533. if is_char(pt1^.resulttype) then
  1534. p:=new(porddef,init(uchar,pt1^.value,pt2^.value))
  1535. else
  1536. if is_boolean(pt1^.resulttype) then
  1537. p:=new(porddef,init(bool8bit,pt1^.value,pt2^.value))
  1538. else
  1539. p:=new(porddef,init(uauto,pt1^.value,pt2^.value));
  1540. end;
  1541. end;
  1542. end;
  1543. end;
  1544. end;
  1545. disposetree(pt2);
  1546. end
  1547. else
  1548. begin
  1549. { a simple type renaming }
  1550. if (pt1^.treetype=typen) then
  1551. p:=pt1^.resulttype
  1552. else
  1553. Message(sym_e_error_in_type_def);
  1554. end;
  1555. disposetree(pt1);
  1556. end;
  1557. var
  1558. pt : ptree;
  1559. procedure array_dec;
  1560. var
  1561. lowval,
  1562. highval : longint;
  1563. arraytype : pdef;
  1564. begin
  1565. consume(_ARRAY);
  1566. consume(LECKKLAMMER);
  1567. { defaults }
  1568. arraytype:=generrordef;
  1569. lowval:=$80000000;
  1570. highval:=$7fffffff;
  1571. p:=nil;
  1572. repeat
  1573. { read the expression and check it }
  1574. pt:=expr;
  1575. if pt^.treetype=typen then
  1576. begin
  1577. case pt^.resulttype^.deftype of
  1578. enumdef : begin
  1579. lowval:=penumdef(pt^.resulttype)^.min;
  1580. highval:=penumdef(pt^.resulttype)^.max;
  1581. arraytype:=pt^.resulttype;
  1582. end;
  1583. orddef : begin
  1584. case porddef(pt^.resulttype)^.typ of
  1585. s8bit,u8bit,
  1586. s16bit,u16bit,
  1587. s32bit : begin
  1588. lowval:=porddef(pt^.resulttype)^.low;
  1589. highval:=porddef(pt^.resulttype)^.high;
  1590. arraytype:=pt^.resulttype;
  1591. end;
  1592. bool8bit,
  1593. bool16bit,
  1594. bool32bit : begin
  1595. lowval:=0;
  1596. highval:=1;
  1597. arraytype:=pt^.resulttype;
  1598. end;
  1599. uchar : begin
  1600. lowval:=0;
  1601. highval:=255;
  1602. arraytype:=pt^.resulttype;
  1603. end;
  1604. else
  1605. Message(sym_e_error_in_type_def);
  1606. end;
  1607. end;
  1608. else
  1609. Message(sym_e_error_in_type_def);
  1610. end
  1611. end
  1612. else
  1613. begin
  1614. do_firstpass(pt);
  1615. if (pt^.treetype<>rangen) or
  1616. (pt^.left^.treetype<>ordconstn) then
  1617. Message(sym_e_error_in_type_def)
  1618. else
  1619. begin
  1620. {$ifndef GDB}
  1621. if pt^.right^.resulttype=pdef(s32bitdef) then
  1622. pt^.right^.resulttype:=new(porddef,init(s32bit,$80000000,$7fffffff));
  1623. {$endif GDB}
  1624. lowval:=pt^.left^.value;
  1625. highval:=pt^.right^.value;
  1626. arraytype:=pt^.right^.resulttype;
  1627. end;
  1628. end;
  1629. disposetree(pt);
  1630. { create arraydef }
  1631. if p=nil then
  1632. begin
  1633. ap:=new(parraydef,init(lowval,highval,arraytype));
  1634. p:=ap;
  1635. end
  1636. else
  1637. begin
  1638. ap^.definition:=new(parraydef,init(lowval,highval,arraytype));
  1639. ap:=parraydef(ap^.definition);
  1640. end;
  1641. if token=COMMA then
  1642. consume(COMMA)
  1643. else
  1644. break;
  1645. until false;
  1646. consume(RECKKLAMMER);
  1647. consume(_OF);
  1648. hp1:=read_type('');
  1649. { if no error, set element type }
  1650. if assigned(ap) then
  1651. ap^.definition:=hp1;
  1652. end;
  1653. begin
  1654. p:=nil;
  1655. case token of
  1656. _STRING,_FILE:
  1657. p:=single_type(hs);
  1658. LKLAMMER:
  1659. begin
  1660. consume(LKLAMMER);
  1661. { allow negativ value_str }
  1662. l:=-1;
  1663. aufsym := Nil;
  1664. aufdef:=new(penumdef,init);
  1665. repeat
  1666. s:=pattern;
  1667. consume(ID);
  1668. if token=ASSIGNMENT then
  1669. begin
  1670. consume(ASSIGNMENT);
  1671. v:=get_intconst;
  1672. { please leave that a note, allows type save }
  1673. { declarations in the win32 units ! }
  1674. if v<=l then
  1675. Message(parser_n_duplicate_enum);
  1676. l:=v;
  1677. end
  1678. else
  1679. inc(l);
  1680. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1681. if token=COMMA then
  1682. consume(COMMA)
  1683. else
  1684. break;
  1685. until false;
  1686. {aufdef^.max:=l;
  1687. if we allow unordered enums
  1688. this can be wrong
  1689. min and max are now set in tenumsym.init PM }
  1690. p:=aufdef;
  1691. consume(RKLAMMER);
  1692. end;
  1693. _ARRAY:
  1694. array_dec;
  1695. _SET:
  1696. begin
  1697. consume(_SET);
  1698. consume(_OF);
  1699. hp1:=read_type('');
  1700. if assigned(hp1) then
  1701. begin
  1702. case hp1^.deftype of
  1703. { don't forget that min can be negativ PM }
  1704. enumdef : if penumdef(hp1)^.min>=0 then
  1705. p:=new(psetdef,init(hp1,penumdef(hp1)^.max))
  1706. else
  1707. Message(sym_e_ill_type_decl_set);
  1708. orddef : begin
  1709. case porddef(hp1)^.typ of
  1710. uchar : p:=new(psetdef,init(hp1,255));
  1711. u8bit,s8bit,u16bit,s16bit,s32bit :
  1712. begin
  1713. if (porddef(hp1)^.low>=0) then
  1714. p:=new(psetdef,init(hp1,porddef(hp1)^.high))
  1715. else Message(sym_e_ill_type_decl_set);
  1716. end;
  1717. else Message(sym_e_ill_type_decl_set);
  1718. end;
  1719. end;
  1720. else Message(sym_e_ill_type_decl_set);
  1721. end;
  1722. end
  1723. else
  1724. p:=generrordef;
  1725. end;
  1726. CARET:
  1727. begin
  1728. consume(CARET);
  1729. { forwards allowed only inside TYPE statements }
  1730. if typecanbeforward then
  1731. forwardsallowed:=true;
  1732. hp1:=single_type(hs);
  1733. p:=new(ppointerdef,init(hp1));
  1734. {I add big troubles here
  1735. with var p : ^byte in graph.putimage
  1736. because a save_forward was called and
  1737. no resolve forward
  1738. => so the definition was rewritten after
  1739. having been disposed !!
  1740. Strange problems appeared !!!!}
  1741. {Anyhow forwards should only be allowed
  1742. inside a type statement ??
  1743. don't you think so }
  1744. if (lasttypesym<>nil)
  1745. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1746. lasttypesym^.forwardpointer:=ppointerdef(p);
  1747. forwardsallowed:=false;
  1748. end;
  1749. _RECORD:
  1750. p:=record_dec;
  1751. _PACKED:
  1752. begin
  1753. consume(_PACKED);
  1754. if token=_ARRAY then
  1755. array_dec
  1756. else
  1757. begin
  1758. oldaktpackrecords:=aktpackrecords;
  1759. aktpackrecords:=1;
  1760. if token in [_CLASS,_OBJECT] then
  1761. p:=object_dec(name,nil)
  1762. else
  1763. p:=record_dec;
  1764. aktpackrecords:=oldaktpackrecords;
  1765. end;
  1766. end;
  1767. _CLASS,
  1768. _OBJECT:
  1769. p:=object_dec(name,nil);
  1770. _PROCEDURE:
  1771. begin
  1772. consume(_PROCEDURE);
  1773. p:=handle_procvar;
  1774. if token=_OF then
  1775. begin
  1776. consume(_OF);
  1777. consume(_OBJECT);
  1778. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1779. end;
  1780. end;
  1781. _FUNCTION:
  1782. begin
  1783. consume(_FUNCTION);
  1784. p:=handle_procvar;
  1785. consume(COLON);
  1786. pprocvardef(p)^.retdef:=single_type(hs);
  1787. if token=_OF then
  1788. begin
  1789. consume(_OF);
  1790. consume(_OBJECT);
  1791. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1792. end;
  1793. end;
  1794. else
  1795. expr_type;
  1796. end;
  1797. if p=nil then
  1798. p:=generrordef;
  1799. read_type:=p;
  1800. end;
  1801. { reads a type declaration to the symbol table }
  1802. procedure type_dec;
  1803. var
  1804. typename : stringid;
  1805. newtype : ptypesym;
  1806. {$ifdef dummy}
  1807. olddef,newdef : pdef;
  1808. s : string;
  1809. {$endif dummy}
  1810. begin
  1811. block_type:=bt_type;
  1812. consume(_TYPE);
  1813. typecanbeforward:=true;
  1814. repeat
  1815. typename:=pattern;
  1816. consume(ID);
  1817. consume(EQUAL);
  1818. { here you loose the strictness of pascal
  1819. for which a redefinition like
  1820. childtype = parenttype;
  1821. child2type = parenttype;
  1822. does not make the two child types equal !!
  1823. here all vars from childtype and child2type
  1824. get the definition of parenttype !! }
  1825. {$ifdef testequaltype}
  1826. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1827. begin
  1828. olddef := single_type(s);
  1829. { make a clone of olddef }
  1830. { is that ok ??? }
  1831. getmem(newdef,SizeOf(olddef));
  1832. move(olddef^,newdef^,SizeOf(olddef));
  1833. newtype:=new(ptypesym,init(typename,newdef));
  1834. symtablestack^.insert(newtype);
  1835. end
  1836. else
  1837. {$endif testequaltype}
  1838. begin
  1839. getsym(typename,false);
  1840. { check if it is the definition of a forward defined class }
  1841. if assigned(srsym) and (token=_CLASS) and
  1842. (srsym^.typ=typesym) and
  1843. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1844. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1845. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oois_class)<>0) then
  1846. begin
  1847. { we can ignore the result }
  1848. { the definition is modified }
  1849. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1850. newtype:=ptypesym(srsym);
  1851. end
  1852. else
  1853. begin
  1854. newtype:=new(ptypesym,init(typename,read_type(typename)));
  1855. { load newtype with the new pointer to the inserted type
  1856. because it can be an already defined forwarded type !! }
  1857. newtype:=ptypesym(symtablestack^.insert(newtype));
  1858. end;
  1859. end;
  1860. consume(SEMICOLON);
  1861. if assigned(newtype^.definition) and (newtype^.definition^.deftype=procvardef) then
  1862. parse_var_proc_directives(newtype);
  1863. until token<>ID;
  1864. typecanbeforward:=false;
  1865. {$ifdef tp}
  1866. symtablestack^.foreach(testforward_type);
  1867. {$else}
  1868. symtablestack^.foreach(@testforward_type);
  1869. {$endif}
  1870. resolve_forwards;
  1871. block_type:=bt_general;
  1872. end;
  1873. procedure var_dec;
  1874. { parses varaible declarations and inserts them in }
  1875. { the top symbol table of symtablestack }
  1876. begin
  1877. consume(_VAR);
  1878. read_var_decs(false,false);
  1879. end;
  1880. procedure Not_supported_for_inline(t : ttoken);
  1881. begin
  1882. if assigned(aktprocsym) and
  1883. ((aktprocsym^.definition^.options and poinline)<>0) then
  1884. Begin
  1885. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1886. Message(parser_w_inlining_disabled);
  1887. aktprocsym^.definition^.options:= aktprocsym^.definition^.options and not poinline;
  1888. End;
  1889. end;
  1890. procedure read_declarations(islibrary : boolean);
  1891. begin
  1892. repeat
  1893. case token of
  1894. _LABEL:
  1895. begin
  1896. Not_supported_for_inline(token);
  1897. label_dec;
  1898. end;
  1899. _CONST:
  1900. begin
  1901. Not_supported_for_inline(token);
  1902. const_dec;
  1903. end;
  1904. _TYPE:
  1905. begin
  1906. Not_supported_for_inline(token);
  1907. type_dec;
  1908. end;
  1909. _VAR:
  1910. var_dec;
  1911. _CONSTRUCTOR,_DESTRUCTOR,
  1912. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1913. begin
  1914. Not_supported_for_inline(token);
  1915. read_proc;
  1916. end;
  1917. _EXPORTS:
  1918. begin
  1919. { here we should be at lexlevel 1, no ? PM }
  1920. Not_supported_for_inline(token);
  1921. if islibrary then
  1922. read_exports
  1923. else
  1924. break;
  1925. end
  1926. else break;
  1927. end;
  1928. until false;
  1929. end;
  1930. procedure read_interface_declarations;
  1931. begin
  1932. {Since the body is now parsed at lexlevel 1, and the declarations
  1933. must be parsed at the same lexlevel we increase the lexlevel.}
  1934. inc(lexlevel);
  1935. repeat
  1936. case token of
  1937. _CONST : const_dec;
  1938. _TYPE : type_dec;
  1939. _VAR : var_dec;
  1940. _FUNCTION,
  1941. _PROCEDURE,
  1942. _OPERATOR : read_proc;
  1943. else
  1944. break;
  1945. end;
  1946. until false;
  1947. dec(lexlevel);
  1948. end;
  1949. end.
  1950. {
  1951. $Log$
  1952. Revision 1.70 1998-10-13 13:10:22 peter
  1953. * new style for m68k/i386 infos and enums
  1954. Revision 1.69 1998/10/09 12:07:49 pierre
  1955. * typo error for propertyparas dispose corrected
  1956. Revision 1.68 1998/10/09 11:47:54 pierre
  1957. * still more memory leaks fixes !!
  1958. Revision 1.67 1998/10/08 13:48:46 peter
  1959. * fixed memory leaks for do nothing source
  1960. * fixed unit interdependency
  1961. Revision 1.66 1998/10/06 20:43:31 peter
  1962. * fixed set of bugs. like set of false..true set of #1..#255 and
  1963. set of #1..true which was allowed
  1964. Revision 1.65 1998/10/05 22:43:35 peter
  1965. * commited the wrong file :(
  1966. Revision 1.64 1998/10/05 21:33:24 peter
  1967. * fixed 161,165,166,167,168
  1968. Revision 1.63 1998/10/05 13:57:13 peter
  1969. * crash preventions
  1970. Revision 1.62 1998/10/02 17:06:02 peter
  1971. * better error message for unresolved forward types
  1972. Revision 1.61 1998/10/02 09:23:24 peter
  1973. * fixed error msg with type l=<var>
  1974. * block_type bt_const is now set in read_const_dec
  1975. Revision 1.60 1998/09/30 07:40:33 florian
  1976. * better error recovering
  1977. Revision 1.59 1998/09/26 17:45:33 peter
  1978. + idtoken and only one token table
  1979. Revision 1.58 1998/09/25 00:04:01 florian
  1980. * problems when calling class methods fixed
  1981. Revision 1.57 1998/09/24 23:49:09 peter
  1982. + aktmodeswitches
  1983. Revision 1.56 1998/09/23 15:39:09 pierre
  1984. * browser bugfixes
  1985. was adding a reference when looking for the symbol
  1986. if -bSYM_NAME was used
  1987. Revision 1.55 1998/09/21 13:24:44 daniel
  1988. * Memory leak fixed.
  1989. Revision 1.54 1998/09/17 13:41:16 pierre
  1990. sizeof(TPOINT) problem
  1991. Revision 1.53.2.1 1998/09/17 13:12:09 pierre
  1992. * virtual destructor did not set oo_hasvirtual
  1993. (detected with the sizeof(TPoint) problem
  1994. * genloadcallnode was missing
  1995. Revision 1.53 1998/09/09 11:50:52 pierre
  1996. * forward def are not put in record or objects
  1997. + added check for forwards also in record and objects
  1998. * dummy parasymtable for unit initialization removed from
  1999. symtable stack
  2000. Revision 1.52 1998/09/07 23:10:22 florian
  2001. * a lot of stuff fixed regarding rtti and publishing of properties,
  2002. basics should now work
  2003. Revision 1.51 1998/09/07 19:33:22 florian
  2004. + some stuff for property rtti added:
  2005. - NameIndex of the TPropInfo record is now written correctly
  2006. - the DEFAULT/NODEFAULT keyword is supported now
  2007. - the default value and the storedsym/def are now written to
  2008. the PPU fiel
  2009. Revision 1.50 1998/09/07 18:46:08 peter
  2010. * update smartlinking, uses getdatalabel
  2011. * renamed ptree.value vars to value_str,value_real,value_set
  2012. Revision 1.49 1998/09/07 17:37:00 florian
  2013. * first fixes for published properties
  2014. Revision 1.48 1998/09/04 08:42:02 peter
  2015. * updated some error messages
  2016. Revision 1.47 1998/09/03 16:03:18 florian
  2017. + rtti generation
  2018. * init table generation changed
  2019. Revision 1.46 1998/09/01 17:39:48 peter
  2020. + internal constant functions
  2021. Revision 1.45 1998/08/31 12:20:28 peter
  2022. * fixed array_dec when unknown type was used
  2023. Revision 1.44 1998/08/28 10:57:01 peter
  2024. * removed warnings
  2025. Revision 1.43 1998/08/25 13:09:25 pierre
  2026. * corrected mangling sheme :
  2027. cvar add Cprefix to the mixed case name whereas
  2028. export or public use direct name
  2029. Revision 1.42 1998/08/25 12:42:41 pierre
  2030. * CDECL changed to CVAR for variables
  2031. specifications are read in structures also
  2032. + started adding GPC compatibility mode ( option -Sp)
  2033. * names changed to lowercase
  2034. Revision 1.41 1998/08/23 21:04:36 florian
  2035. + rtti generation for classes added
  2036. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2037. Revision 1.40 1998/08/21 15:48:58 pierre
  2038. * more cdecl chagnes
  2039. - better line info
  2040. - changes the definition options of a procvar
  2041. if it is a unnamed type
  2042. Revision 1.39 1998/08/19 00:42:40 peter
  2043. + subrange types for enums
  2044. + checking for bounds type with ranges
  2045. Revision 1.38 1998/08/12 19:20:39 peter
  2046. + public is the same as export for c_vars
  2047. * a exported/public c_var incs now the refcount
  2048. Revision 1.37 1998/08/11 15:31:38 peter
  2049. * write extended to ppu file
  2050. * new version 0.99.7
  2051. Revision 1.36 1998/08/10 14:50:09 peter
  2052. + localswitches, moduleswitches, globalswitches splitting
  2053. Revision 1.35 1998/07/26 21:59:00 florian
  2054. + better support for switch $H
  2055. + index access to ansi strings added
  2056. + assigment of data (records/arrays) containing ansi strings
  2057. Revision 1.34 1998/07/20 22:17:15 florian
  2058. * hex constants in numeric char (#$54#$43 ...) are now allowed
  2059. * there was a bug in record_var_dec which prevents the used
  2060. of nested variant records (for example drivers.tevent of tv)
  2061. Revision 1.33 1998/07/18 17:11:11 florian
  2062. + ansi string constants fixed
  2063. + switch $H partial implemented
  2064. Revision 1.32 1998/07/14 21:46:50 peter
  2065. * updated messages file
  2066. Revision 1.31 1998/07/14 14:46:53 peter
  2067. * released NEWINPUT
  2068. Revision 1.30 1998/07/10 00:00:00 peter
  2069. * fixed ttypesym bug finally
  2070. * fileinfo in the symtable and better using for unused vars
  2071. Revision 1.29 1998/06/25 14:04:21 peter
  2072. + internal inc/dec
  2073. Revision 1.28 1998/06/24 12:26:45 peter
  2074. * stricter var parsing like tp7 and some optimizes with directive
  2075. parsing
  2076. Revision 1.27 1998/06/12 16:15:34 pierre
  2077. * external name 'C_var';
  2078. export name 'intern_C_var';
  2079. cdecl;
  2080. cdecl;external;
  2081. are now supported only with -Sv switch
  2082. Revision 1.25 1998/06/09 16:01:45 pierre
  2083. + added procedure directive parsing for procvars
  2084. (accepted are popstack cdecl and pascal)
  2085. + added C vars with the following syntax
  2086. var C calias 'true_c_name';(can be followed by external)
  2087. reason is that you must add the Cprefix
  2088. which is target dependent
  2089. Revision 1.24 1998/06/05 14:37:32 pierre
  2090. * fixes for inline for operators
  2091. * inline procedure more correctly restricted
  2092. Revision 1.23 1998/06/04 23:51:50 peter
  2093. * m68k compiles
  2094. + .def file creation moved to gendef.pas so it could also be used
  2095. for win32
  2096. Revision 1.22 1998/06/03 22:48:59 peter
  2097. + wordbool,longbool
  2098. * rename bis,von -> high,low
  2099. * moved some systemunit loading/creating to psystem.pas
  2100. Revision 1.21 1998/06/03 22:14:19 florian
  2101. * problem with sizes of classes fixed (if the anchestor was declared
  2102. forward, the compiler doesn't update the child classes size)
  2103. Revision 1.20 1998/05/28 14:35:54 peter
  2104. * nicer error message when no id is used after var
  2105. Revision 1.19 1998/05/23 01:21:19 peter
  2106. + aktasmmode, aktoptprocessor, aktoutputformat
  2107. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2108. + $LIBNAME to set the library name where the unit will be put in
  2109. * splitted cgi386 a bit (codeseg to large for bp7)
  2110. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2111. Revision 1.18 1998/05/20 09:42:35 pierre
  2112. + UseTokenInfo now default
  2113. * unit in interface uses and implementation uses gives error now
  2114. * only one error for unknown symbol (uses lastsymknown boolean)
  2115. the problem came from the label code !
  2116. + first inlined procedures and function work
  2117. (warning there might be allowed cases were the result is still wrong !!)
  2118. * UseBrower updated gives a global list of all position of all used symbols
  2119. with switch -gb
  2120. Revision 1.17 1998/05/11 13:07:55 peter
  2121. + $ifdef NEWPPU for the new ppuformat
  2122. + $define GDB not longer required
  2123. * removed all warnings and stripped some log comments
  2124. * no findfirst/findnext anymore to remove smartlink *.o files
  2125. Revision 1.16 1998/05/05 12:05:42 florian
  2126. * problems with properties fixed
  2127. * crash fixed: i:=l when i and l are undefined, was a problem with
  2128. implementation of private/protected
  2129. Revision 1.15 1998/05/01 09:01:23 florian
  2130. + correct semantics of private and protected
  2131. * small fix in variable scope:
  2132. a id can be used in a parameter list of a method, even it is used in
  2133. an anchestor class as field id
  2134. Revision 1.14 1998/05/01 07:43:56 florian
  2135. + basics for rtti implemented
  2136. + switch $m (generate rtti for published sections)
  2137. Revision 1.13 1998/04/30 15:59:41 pierre
  2138. * GDB works again better :
  2139. correct type info in one pass
  2140. + UseTokenInfo for better source position
  2141. * fixed one remaining bug in scanner for line counts
  2142. * several little fixes
  2143. Revision 1.12 1998/04/29 10:33:57 pierre
  2144. + added some code for ansistring (not complete nor working yet)
  2145. * corrected operator overloading
  2146. * corrected nasm output
  2147. + started inline procedures
  2148. + added starstarn : use ** for exponentiation (^ gave problems)
  2149. + started UseTokenInfo cond to get accurate positions
  2150. Revision 1.11 1998/04/28 11:45:52 florian
  2151. * make it compilable with TP
  2152. + small COM problems solved to compile classes.pp
  2153. Revision 1.10 1998/04/27 23:10:28 peter
  2154. + new scanner
  2155. * $makelib -> if smartlink
  2156. * small filename fixes pmodule.setfilename
  2157. * moved import from files.pas -> import.pas
  2158. Revision 1.9 1998/04/10 21:36:56 florian
  2159. + some stuff to support method pointers (procedure of object) added
  2160. (declaration, parameter handling)
  2161. Revision 1.8 1998/04/10 15:39:48 florian
  2162. * more fixes to get classes.pas compiled
  2163. Revision 1.7 1998/04/09 23:02:15 florian
  2164. * small problems solved to get remake3 work
  2165. Revision 1.6 1998/04/09 22:16:35 florian
  2166. * problem with previous REGALLOC solved
  2167. * improved property support
  2168. Revision 1.5 1998/04/08 14:59:20 florian
  2169. * problem with new expr_type solved
  2170. Revision 1.4 1998/04/08 10:26:09 florian
  2171. * correct error handling of virtual constructors
  2172. * problem with new type declaration handling fixed
  2173. Revision 1.3 1998/04/07 22:45:05 florian
  2174. * bug0092, bug0115 and bug0121 fixed
  2175. + packed object/class/array
  2176. Revision 1.2 1998/04/05 13:58:35 peter
  2177. * fixed the -Ss bug
  2178. + warning for Virtual constructors
  2179. * helppages updated with -TGO32V1
  2180. }