pdecl.pas 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372
  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. aktclass:=fd;
  1108. { we must inherit several options !!
  1109. this was missing !!
  1110. all is now done in set_parent
  1111. including symtable datasize setting PM }
  1112. fd^.set_parent(childof);
  1113. end
  1114. else
  1115. aktclass:=new(pobjectdef,init(n,childof));
  1116. consume(RKLAMMER);
  1117. end
  1118. { if no parent class, then a class get tobject as parent }
  1119. else if is_a_class then
  1120. begin
  1121. { is the current class tobject? }
  1122. { so you could define your own tobject }
  1123. if n='TOBJECT' then
  1124. begin
  1125. if assigned(fd) then
  1126. aktclass:=fd
  1127. else
  1128. aktclass:=new(pobjectdef,init(n,nil));
  1129. class_tobject:=aktclass;
  1130. end
  1131. else
  1132. begin
  1133. childof:=class_tobject;
  1134. if assigned(fd) then
  1135. begin
  1136. { the forward of the child must be resolved to get
  1137. correct field addresses
  1138. }
  1139. if (childof^.options and oo_isforward)<>0 then
  1140. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1141. aktclass:=fd;
  1142. aktclass^.childof:=childof;
  1143. { ajust the size, because the child could be also
  1144. forward defined
  1145. }
  1146. aktclass^.publicsyms^.datasize:=
  1147. aktclass^.publicsyms^.datasize-4+childof^.publicsyms^.datasize;
  1148. end
  1149. else
  1150. begin
  1151. aktclass:=new(pobjectdef,init(n,childof));
  1152. end;
  1153. end;
  1154. end
  1155. else
  1156. aktclass:=new(pobjectdef,init(n,nil));
  1157. { set the class attribute }
  1158. if is_a_class then
  1159. begin
  1160. aktclass^.options:=aktclass^.options or oois_class;
  1161. if (cs_generate_rtti in aktlocalswitches) or
  1162. (assigned(aktclass^.childof) and
  1163. ((aktclass^.childof^.options and oo_can_have_published)<>0)
  1164. ) then
  1165. aktclass^.options:=aktclass^.options or oo_can_have_published;
  1166. end;
  1167. aktobjectdef:=aktclass;
  1168. { default access is public }
  1169. actmembertype:=sp_public;
  1170. aktclass^.publicsyms^.next:=symtablestack;
  1171. symtablestack:=aktclass^.publicsyms;
  1172. procinfo._class:=aktclass;
  1173. testcurobject:=1;
  1174. curobjectname:=n;
  1175. { short class declaration ? }
  1176. if (not is_a_class) or (token<>SEMICOLON) then
  1177. begin
  1178. { Parse componenten }
  1179. repeat
  1180. if actmembertype=sp_private then
  1181. aktclass^.options:=aktclass^.options or oo_hasprivate;
  1182. if actmembertype=sp_protected then
  1183. aktclass^.options:=aktclass^.options or oo_hasprotected;
  1184. case token of
  1185. ID : begin
  1186. case idtoken of
  1187. _PRIVATE : begin
  1188. consume(_PRIVATE);
  1189. actmembertype:=sp_private;
  1190. current_object_option:=sp_private;
  1191. end;
  1192. _PROTECTED : begin
  1193. consume(_PROTECTED);
  1194. current_object_option:=sp_protected;
  1195. actmembertype:=sp_protected;
  1196. end;
  1197. _PUBLIC : begin
  1198. consume(_PUBLIC);
  1199. current_object_option:=sp_public;
  1200. actmembertype:=sp_public;
  1201. end;
  1202. _PUBLISHED : begin
  1203. if (aktclass^.options and oo_can_have_published)=0 then
  1204. Message(parser_e_cant_have_published);
  1205. consume(_PUBLISHED);
  1206. current_object_option:=sp_published;
  1207. actmembertype:=sp_published;
  1208. end;
  1209. else
  1210. read_var_decs(false,true);
  1211. end;
  1212. end;
  1213. _PROPERTY : property_dec;
  1214. _PROCEDURE,
  1215. _FUNCTION,
  1216. _CLASS : begin
  1217. oldparse_only:=parse_only;
  1218. parse_only:=true;
  1219. parse_proc_dec;
  1220. parse_only:=oldparse_only;
  1221. case idtoken of
  1222. _DYNAMIC,
  1223. _VIRTUAL : begin
  1224. if actmembertype=sp_private then
  1225. Message(parser_w_priv_meth_not_virtual);
  1226. consume(idtoken);
  1227. consume(SEMICOLON);
  1228. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1229. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1230. end;
  1231. _OVERRIDE : begin
  1232. consume(_OVERRIDE);
  1233. consume(SEMICOLON);
  1234. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1235. pooverridingmethod or povirtualmethod;
  1236. end;
  1237. end;
  1238. if idtoken=_abstract then
  1239. begin
  1240. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  1241. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or poabstractmethod
  1242. else
  1243. Message(parser_e_only_virtual_methods_abstract);
  1244. consume(_ABSTRACT);
  1245. consume(SEMICOLON);
  1246. { the method is defined }
  1247. aktprocsym^.definition^.forwarddef:=false;
  1248. end;
  1249. if (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  1250. begin
  1251. consume(_STATIC);
  1252. consume(SEMICOLON);
  1253. aktprocsym^.properties:=aktprocsym^.properties or sp_static;
  1254. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or postaticmethod;
  1255. end;
  1256. end;
  1257. _CONSTRUCTOR : begin
  1258. if actmembertype<>sp_public then
  1259. Message(parser_w_constructor_should_be_public);
  1260. oldparse_only:=parse_only;
  1261. parse_only:=true;
  1262. constructor_head;
  1263. parse_only:=oldparse_only;
  1264. case idtoken of
  1265. _DYNAMIC,
  1266. _VIRTUAL : begin
  1267. if not(aktclass^.isclass) then
  1268. Message(parser_e_constructor_cannot_be_not_virtual)
  1269. else
  1270. begin
  1271. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1272. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1273. end;
  1274. consume(idtoken);
  1275. consume(SEMICOLON);
  1276. end;
  1277. _OVERRIDE : begin
  1278. if (aktclass^.options and oois_class=0) then
  1279. Message(parser_e_constructor_cannot_be_not_virtual)
  1280. else
  1281. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1282. pooverridingmethod or povirtualmethod;
  1283. consume(_OVERRIDE);
  1284. consume(SEMICOLON);
  1285. end;
  1286. end;
  1287. end;
  1288. _DESTRUCTOR : begin
  1289. if there_is_a_destructor then
  1290. Message(parser_n_only_one_destructor);
  1291. there_is_a_destructor:=true;
  1292. if actmembertype<>sp_public then
  1293. Message(parser_w_destructor_should_be_public);
  1294. oldparse_only:=parse_only;
  1295. parse_only:=true;
  1296. destructor_head;
  1297. parse_only:=oldparse_only;
  1298. case idtoken of
  1299. _DYNAMIC,
  1300. _VIRTUAL : begin
  1301. consume(idtoken);
  1302. consume(SEMICOLON);
  1303. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1304. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1305. end;
  1306. _OVERRIDE : begin
  1307. consume(_OVERRIDE);
  1308. consume(SEMICOLON);
  1309. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1310. pooverridingmethod or povirtualmethod;
  1311. end;
  1312. end;
  1313. end;
  1314. _END : begin
  1315. consume(_END);
  1316. break;
  1317. end;
  1318. else
  1319. consume(ID); { Give a ident expected message, like tp7 }
  1320. end;
  1321. until false;
  1322. current_object_option:=sp_public;
  1323. end;
  1324. testcurobject:=0;
  1325. curobjectname:='';
  1326. typecanbeforward:=storetypeforwardsallowed;
  1327. if (cs_smartlink in aktmoduleswitches) then
  1328. datasegment^.concat(new(pai_cut,init));
  1329. { write extended info for classes }
  1330. if is_a_class then
  1331. begin
  1332. if (aktclass^.options and oo_can_have_published)<>0 then
  1333. aktclass^.generate_rtti;
  1334. { write class name }
  1335. getlabel(classnamelabel);
  1336. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1337. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.name^))));
  1338. datasegment^.concat(new(pai_string,init(aktclass^.name^)));
  1339. { interface table }
  1340. datasegment^.concat(new(pai_const,init_32bit(0)));
  1341. { auto table }
  1342. datasegment^.concat(new(pai_const,init_32bit(0)));
  1343. { inittable for con-/destruction }
  1344. if aktclass^.needs_inittable then
  1345. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(aktclass^.get_inittable_label)))))
  1346. else
  1347. datasegment^.concat(new(pai_const,init_32bit(0)));
  1348. { pointer to type info of published section }
  1349. if (aktclass^.options and oo_can_have_published)<>0 then
  1350. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.rtti_name))))
  1351. else
  1352. datasegment^.concat(new(pai_const,init_32bit(0)));
  1353. { pointer to field table }
  1354. datasegment^.concat(new(pai_const,init_32bit(0)));
  1355. { pointer to method table }
  1356. datasegment^.concat(new(pai_const,init_32bit(0)));
  1357. { pointer to dynamic table }
  1358. datasegment^.concat(new(pai_const,init_32bit(0)));
  1359. { pointer to class name string }
  1360. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(classnamelabel)))));
  1361. end;
  1362. {$ifdef GDB}
  1363. { generate the VMT }
  1364. if cs_debuginfo in aktmoduleswitches then
  1365. begin
  1366. do_count_dbx:=true;
  1367. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1368. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1369. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1370. end;
  1371. {$endif GDB}
  1372. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  1373. { determine the size with publicsyms^.datasize, because }
  1374. { size gives back 4 for CLASSes }
  1375. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  1376. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  1377. { write pointer to parent VMT, this isn't implemented in TP }
  1378. { but this is not used in FPC ? (PM) }
  1379. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1380. if assigned(aktclass^.childof) then
  1381. begin
  1382. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  1383. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  1384. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  1385. end
  1386. else
  1387. datasegment^.concat(new(pai_const,init_32bit(0)));
  1388. { this generates the entries }
  1389. genvmt(aktclass);
  1390. { restore old state }
  1391. symtablestack:=symtablestack^.next;
  1392. procinfo._class:=nil;
  1393. {Restore the aktprocsym.}
  1394. aktprocsym:=oldprocsym;
  1395. object_dec:=aktclass;
  1396. end;
  1397. { reads a record declaration }
  1398. function record_dec : pdef;
  1399. var
  1400. symtable : psymtable;
  1401. storetypeforwardsallowed : boolean;
  1402. begin
  1403. symtable:=new(psymtable,init(recordsymtable));
  1404. symtable^.next:=symtablestack;
  1405. symtablestack:=symtable;
  1406. consume(_RECORD);
  1407. storetypeforwardsallowed:=typecanbeforward;
  1408. if m_tp in aktmodeswitches then
  1409. typecanbeforward:=false;
  1410. read_var_decs(true,false);
  1411. { may be scale record size to a size of n*4 ? }
  1412. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  1413. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  1414. consume(_END);
  1415. typecanbeforward:=storetypeforwardsallowed;
  1416. symtablestack:=symtable^.next;
  1417. record_dec:=new(precdef,init(symtable));
  1418. end;
  1419. { reads a type definition and returns a pointer to it }
  1420. function read_type(const name : stringid) : pdef;
  1421. function handle_procvar:Pprocvardef;
  1422. var
  1423. sc : pstringcontainer;
  1424. s : string;
  1425. p : pdef;
  1426. varspez : tvarspez;
  1427. procvardef : pprocvardef;
  1428. begin
  1429. procvardef:=new(pprocvardef,init);
  1430. if token=LKLAMMER then
  1431. begin
  1432. consume(LKLAMMER);
  1433. inc(testcurobject);
  1434. repeat
  1435. if token=_VAR then
  1436. begin
  1437. consume(_VAR);
  1438. varspez:=vs_var;
  1439. end
  1440. else if token=_CONST then
  1441. begin
  1442. consume(_CONST);
  1443. varspez:=vs_const;
  1444. end
  1445. else varspez:=vs_value;
  1446. sc:=idlist;
  1447. if token=COLON then
  1448. begin
  1449. consume(COLON);
  1450. if token=_ARRAY then
  1451. begin
  1452. {
  1453. if (varspez<>vs_const) and
  1454. (varspez<>vs_var) then
  1455. begin
  1456. varspez:=vs_const;
  1457. Message(parser_e_illegal_open_parameter);
  1458. end;
  1459. }
  1460. consume(_ARRAY);
  1461. consume(_OF);
  1462. { define range and type of range }
  1463. p:=new(parraydef,init(0,-1,s32bitdef));
  1464. { define field type }
  1465. parraydef(p)^.definition:=single_type(s);
  1466. end
  1467. else
  1468. p:=single_type(s);
  1469. end
  1470. else
  1471. p:=new(pformaldef,init);
  1472. s:=sc^.get;
  1473. while s<>'' do
  1474. begin
  1475. procvardef^.concatdef(p,varspez);
  1476. s:=sc^.get;
  1477. end;
  1478. dispose(sc,done);
  1479. if token=SEMICOLON then consume(SEMICOLON)
  1480. else break;
  1481. until false;
  1482. dec(testcurobject);
  1483. consume(RKLAMMER);
  1484. end;
  1485. handle_procvar:=procvardef;
  1486. end;
  1487. var
  1488. hp1,p : pdef;
  1489. aufdef : penumdef;
  1490. aufsym : penumsym;
  1491. ap : parraydef;
  1492. s : stringid;
  1493. l,v,oldaktpackrecords : longint;
  1494. hs : string;
  1495. procedure expr_type;
  1496. var
  1497. pt1,pt2 : ptree;
  1498. begin
  1499. { use of current parsed object ? }
  1500. if (token=ID) and (testcurobject=2) and (curobjectname=pattern) then
  1501. begin
  1502. consume(ID);
  1503. p:=aktobjectdef;
  1504. exit;
  1505. end;
  1506. { we can't accept a equal in type }
  1507. pt1:=comp_expr(not(ignore_equal));
  1508. do_firstpass(pt1);
  1509. if (token=POINTPOINT) then
  1510. begin
  1511. consume(POINTPOINT);
  1512. { get high value of range }
  1513. pt2:=comp_expr(not(ignore_equal));
  1514. do_firstpass(pt2);
  1515. { both must be evaluated to constants now }
  1516. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1517. Message(sym_e_error_in_type_def)
  1518. else
  1519. begin
  1520. { check types }
  1521. if not is_equal(pt1^.resulttype,pt2^.resulttype) then
  1522. Message(type_e_mismatch)
  1523. else
  1524. begin
  1525. { Check bounds }
  1526. if pt2^.value<pt1^.value then
  1527. Message(cg_e_upper_lower_than_lower)
  1528. else
  1529. begin
  1530. { All checks passed, create the new def }
  1531. case pt1^.resulttype^.deftype of
  1532. enumdef : p:=new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value));
  1533. orddef : begin
  1534. if is_char(pt1^.resulttype) then
  1535. p:=new(porddef,init(uchar,pt1^.value,pt2^.value))
  1536. else
  1537. if is_boolean(pt1^.resulttype) then
  1538. p:=new(porddef,init(bool8bit,pt1^.value,pt2^.value))
  1539. else
  1540. p:=new(porddef,init(uauto,pt1^.value,pt2^.value));
  1541. end;
  1542. end;
  1543. end;
  1544. end;
  1545. end;
  1546. disposetree(pt2);
  1547. end
  1548. else
  1549. begin
  1550. { a simple type renaming }
  1551. if (pt1^.treetype=typen) then
  1552. p:=pt1^.resulttype
  1553. else
  1554. Message(sym_e_error_in_type_def);
  1555. end;
  1556. disposetree(pt1);
  1557. end;
  1558. var
  1559. pt : ptree;
  1560. procedure array_dec;
  1561. var
  1562. lowval,
  1563. highval : longint;
  1564. arraytype : pdef;
  1565. begin
  1566. consume(_ARRAY);
  1567. consume(LECKKLAMMER);
  1568. { defaults }
  1569. arraytype:=generrordef;
  1570. lowval:=$80000000;
  1571. highval:=$7fffffff;
  1572. p:=nil;
  1573. repeat
  1574. { read the expression and check it }
  1575. pt:=expr;
  1576. if pt^.treetype=typen then
  1577. begin
  1578. case pt^.resulttype^.deftype of
  1579. enumdef : begin
  1580. lowval:=penumdef(pt^.resulttype)^.min;
  1581. highval:=penumdef(pt^.resulttype)^.max;
  1582. arraytype:=pt^.resulttype;
  1583. end;
  1584. orddef : begin
  1585. case porddef(pt^.resulttype)^.typ of
  1586. s8bit,u8bit,
  1587. s16bit,u16bit,
  1588. s32bit : begin
  1589. lowval:=porddef(pt^.resulttype)^.low;
  1590. highval:=porddef(pt^.resulttype)^.high;
  1591. arraytype:=pt^.resulttype;
  1592. end;
  1593. bool8bit,
  1594. bool16bit,
  1595. bool32bit : begin
  1596. lowval:=0;
  1597. highval:=1;
  1598. arraytype:=pt^.resulttype;
  1599. end;
  1600. uchar : begin
  1601. lowval:=0;
  1602. highval:=255;
  1603. arraytype:=pt^.resulttype;
  1604. end;
  1605. else
  1606. Message(sym_e_error_in_type_def);
  1607. end;
  1608. end;
  1609. else
  1610. Message(sym_e_error_in_type_def);
  1611. end
  1612. end
  1613. else
  1614. begin
  1615. do_firstpass(pt);
  1616. if (pt^.treetype<>rangen) or
  1617. (pt^.left^.treetype<>ordconstn) then
  1618. Message(sym_e_error_in_type_def)
  1619. else
  1620. begin
  1621. {$ifndef GDB}
  1622. if pt^.right^.resulttype=pdef(s32bitdef) then
  1623. pt^.right^.resulttype:=new(porddef,init(s32bit,$80000000,$7fffffff));
  1624. {$endif GDB}
  1625. lowval:=pt^.left^.value;
  1626. highval:=pt^.right^.value;
  1627. arraytype:=pt^.right^.resulttype;
  1628. end;
  1629. end;
  1630. disposetree(pt);
  1631. { create arraydef }
  1632. if p=nil then
  1633. begin
  1634. ap:=new(parraydef,init(lowval,highval,arraytype));
  1635. p:=ap;
  1636. end
  1637. else
  1638. begin
  1639. ap^.definition:=new(parraydef,init(lowval,highval,arraytype));
  1640. ap:=parraydef(ap^.definition);
  1641. end;
  1642. if token=COMMA then
  1643. consume(COMMA)
  1644. else
  1645. break;
  1646. until false;
  1647. consume(RECKKLAMMER);
  1648. consume(_OF);
  1649. hp1:=read_type('');
  1650. { if no error, set element type }
  1651. if assigned(ap) then
  1652. ap^.definition:=hp1;
  1653. end;
  1654. begin
  1655. p:=nil;
  1656. case token of
  1657. _STRING,_FILE:
  1658. p:=single_type(hs);
  1659. LKLAMMER:
  1660. begin
  1661. consume(LKLAMMER);
  1662. { allow negativ value_str }
  1663. l:=-1;
  1664. aufsym := Nil;
  1665. aufdef:=new(penumdef,init);
  1666. repeat
  1667. s:=pattern;
  1668. consume(ID);
  1669. if token=ASSIGNMENT then
  1670. begin
  1671. consume(ASSIGNMENT);
  1672. v:=get_intconst;
  1673. { please leave that a note, allows type save }
  1674. { declarations in the win32 units ! }
  1675. if v<=l then
  1676. Message(parser_n_duplicate_enum);
  1677. l:=v;
  1678. end
  1679. else
  1680. inc(l);
  1681. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1682. if token=COMMA then
  1683. consume(COMMA)
  1684. else
  1685. break;
  1686. until false;
  1687. {aufdef^.max:=l;
  1688. if we allow unordered enums
  1689. this can be wrong
  1690. min and max are now set in tenumsym.init PM }
  1691. p:=aufdef;
  1692. consume(RKLAMMER);
  1693. end;
  1694. _ARRAY:
  1695. array_dec;
  1696. _SET:
  1697. begin
  1698. consume(_SET);
  1699. consume(_OF);
  1700. hp1:=read_type('');
  1701. if assigned(hp1) then
  1702. begin
  1703. case hp1^.deftype of
  1704. { don't forget that min can be negativ PM }
  1705. enumdef : if penumdef(hp1)^.min>=0 then
  1706. p:=new(psetdef,init(hp1,penumdef(hp1)^.max))
  1707. else
  1708. Message(sym_e_ill_type_decl_set);
  1709. orddef : begin
  1710. case porddef(hp1)^.typ of
  1711. uchar : p:=new(psetdef,init(hp1,255));
  1712. u8bit,s8bit,u16bit,s16bit,s32bit :
  1713. begin
  1714. if (porddef(hp1)^.low>=0) then
  1715. p:=new(psetdef,init(hp1,porddef(hp1)^.high))
  1716. else Message(sym_e_ill_type_decl_set);
  1717. end;
  1718. else Message(sym_e_ill_type_decl_set);
  1719. end;
  1720. end;
  1721. else Message(sym_e_ill_type_decl_set);
  1722. end;
  1723. end
  1724. else
  1725. p:=generrordef;
  1726. end;
  1727. CARET:
  1728. begin
  1729. consume(CARET);
  1730. { forwards allowed only inside TYPE statements }
  1731. if typecanbeforward then
  1732. forwardsallowed:=true;
  1733. hp1:=single_type(hs);
  1734. p:=new(ppointerdef,init(hp1));
  1735. {I add big troubles here
  1736. with var p : ^byte in graph.putimage
  1737. because a save_forward was called and
  1738. no resolve forward
  1739. => so the definition was rewritten after
  1740. having been disposed !!
  1741. Strange problems appeared !!!!}
  1742. {Anyhow forwards should only be allowed
  1743. inside a type statement ??
  1744. don't you think so }
  1745. if (lasttypesym<>nil)
  1746. and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1747. lasttypesym^.forwardpointer:=ppointerdef(p);
  1748. forwardsallowed:=false;
  1749. end;
  1750. _RECORD:
  1751. p:=record_dec;
  1752. _PACKED:
  1753. begin
  1754. consume(_PACKED);
  1755. if token=_ARRAY then
  1756. array_dec
  1757. else
  1758. begin
  1759. oldaktpackrecords:=aktpackrecords;
  1760. aktpackrecords:=1;
  1761. if token in [_CLASS,_OBJECT] then
  1762. p:=object_dec(name,nil)
  1763. else
  1764. p:=record_dec;
  1765. aktpackrecords:=oldaktpackrecords;
  1766. end;
  1767. end;
  1768. _CLASS,
  1769. _OBJECT:
  1770. p:=object_dec(name,nil);
  1771. _PROCEDURE:
  1772. begin
  1773. consume(_PROCEDURE);
  1774. p:=handle_procvar;
  1775. if token=_OF then
  1776. begin
  1777. consume(_OF);
  1778. consume(_OBJECT);
  1779. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1780. end;
  1781. end;
  1782. _FUNCTION:
  1783. begin
  1784. consume(_FUNCTION);
  1785. p:=handle_procvar;
  1786. consume(COLON);
  1787. pprocvardef(p)^.retdef:=single_type(hs);
  1788. if token=_OF then
  1789. begin
  1790. consume(_OF);
  1791. consume(_OBJECT);
  1792. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1793. end;
  1794. end;
  1795. else
  1796. expr_type;
  1797. end;
  1798. if p=nil then
  1799. p:=generrordef;
  1800. read_type:=p;
  1801. end;
  1802. { reads a type declaration to the symbol table }
  1803. procedure type_dec;
  1804. var
  1805. typename : stringid;
  1806. newtype : ptypesym;
  1807. {$ifdef dummy}
  1808. olddef,newdef : pdef;
  1809. s : string;
  1810. {$endif dummy}
  1811. begin
  1812. block_type:=bt_type;
  1813. consume(_TYPE);
  1814. typecanbeforward:=true;
  1815. repeat
  1816. typename:=pattern;
  1817. consume(ID);
  1818. consume(EQUAL);
  1819. { here you loose the strictness of pascal
  1820. for which a redefinition like
  1821. childtype = parenttype;
  1822. child2type = parenttype;
  1823. does not make the two child types equal !!
  1824. here all vars from childtype and child2type
  1825. get the definition of parenttype !! }
  1826. {$ifdef testequaltype}
  1827. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1828. begin
  1829. olddef := single_type(s);
  1830. { make a clone of olddef }
  1831. { is that ok ??? }
  1832. getmem(newdef,SizeOf(olddef));
  1833. move(olddef^,newdef^,SizeOf(olddef));
  1834. newtype:=new(ptypesym,init(typename,newdef));
  1835. symtablestack^.insert(newtype);
  1836. end
  1837. else
  1838. {$endif testequaltype}
  1839. begin
  1840. getsym(typename,false);
  1841. { check if it is the definition of a forward defined class }
  1842. if assigned(srsym) and (token=_CLASS) and
  1843. (srsym^.typ=typesym) and
  1844. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1845. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1846. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oois_class)<>0) then
  1847. begin
  1848. { we can ignore the result }
  1849. { the definition is modified }
  1850. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1851. newtype:=ptypesym(srsym);
  1852. end
  1853. else
  1854. begin
  1855. newtype:=new(ptypesym,init(typename,read_type(typename)));
  1856. { load newtype with the new pointer to the inserted type
  1857. because it can be an already defined forwarded type !! }
  1858. newtype:=ptypesym(symtablestack^.insert(newtype));
  1859. end;
  1860. end;
  1861. consume(SEMICOLON);
  1862. if assigned(newtype^.definition) and (newtype^.definition^.deftype=procvardef) then
  1863. parse_var_proc_directives(newtype);
  1864. until token<>ID;
  1865. typecanbeforward:=false;
  1866. {$ifdef tp}
  1867. symtablestack^.foreach(testforward_type);
  1868. {$else}
  1869. symtablestack^.foreach(@testforward_type);
  1870. {$endif}
  1871. resolve_forwards;
  1872. block_type:=bt_general;
  1873. end;
  1874. procedure var_dec;
  1875. { parses varaible declarations and inserts them in }
  1876. { the top symbol table of symtablestack }
  1877. begin
  1878. consume(_VAR);
  1879. read_var_decs(false,false);
  1880. end;
  1881. procedure Not_supported_for_inline(t : ttoken);
  1882. begin
  1883. if assigned(aktprocsym) and
  1884. ((aktprocsym^.definition^.options and poinline)<>0) then
  1885. Begin
  1886. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1887. Message(parser_w_inlining_disabled);
  1888. aktprocsym^.definition^.options:= aktprocsym^.definition^.options and not poinline;
  1889. End;
  1890. end;
  1891. procedure read_declarations(islibrary : boolean);
  1892. begin
  1893. repeat
  1894. case token of
  1895. _LABEL:
  1896. begin
  1897. Not_supported_for_inline(token);
  1898. label_dec;
  1899. end;
  1900. _CONST:
  1901. begin
  1902. Not_supported_for_inline(token);
  1903. const_dec;
  1904. end;
  1905. _TYPE:
  1906. begin
  1907. Not_supported_for_inline(token);
  1908. type_dec;
  1909. end;
  1910. _VAR:
  1911. var_dec;
  1912. _CONSTRUCTOR,_DESTRUCTOR,
  1913. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1914. begin
  1915. Not_supported_for_inline(token);
  1916. read_proc;
  1917. end;
  1918. _EXPORTS:
  1919. begin
  1920. { here we should be at lexlevel 1, no ? PM }
  1921. Not_supported_for_inline(token);
  1922. if islibrary then
  1923. read_exports
  1924. else
  1925. break;
  1926. end
  1927. else break;
  1928. end;
  1929. until false;
  1930. end;
  1931. procedure read_interface_declarations;
  1932. begin
  1933. {Since the body is now parsed at lexlevel 1, and the declarations
  1934. must be parsed at the same lexlevel we increase the lexlevel.}
  1935. inc(lexlevel);
  1936. repeat
  1937. case token of
  1938. _CONST : const_dec;
  1939. _TYPE : type_dec;
  1940. _VAR : var_dec;
  1941. _FUNCTION,
  1942. _PROCEDURE,
  1943. _OPERATOR : read_proc;
  1944. else
  1945. break;
  1946. end;
  1947. until false;
  1948. dec(lexlevel);
  1949. end;
  1950. end.
  1951. {
  1952. $Log$
  1953. Revision 1.72 1998-10-16 13:12:51 pierre
  1954. * added vmt_offsets in destructors code also !!!
  1955. * vmt_offset code for m68k
  1956. Revision 1.71 1998/10/15 15:13:25 pierre
  1957. + added oo_hasconstructor and oo_hasdestructor
  1958. for objects options
  1959. Revision 1.70 1998/10/13 13:10:22 peter
  1960. * new style for m68k/i386 infos and enums
  1961. Revision 1.69 1998/10/09 12:07:49 pierre
  1962. * typo error for propertyparas dispose corrected
  1963. Revision 1.68 1998/10/09 11:47:54 pierre
  1964. * still more memory leaks fixes !!
  1965. Revision 1.67 1998/10/08 13:48:46 peter
  1966. * fixed memory leaks for do nothing source
  1967. * fixed unit interdependency
  1968. Revision 1.66 1998/10/06 20:43:31 peter
  1969. * fixed set of bugs. like set of false..true set of #1..#255 and
  1970. set of #1..true which was allowed
  1971. Revision 1.65 1998/10/05 22:43:35 peter
  1972. * commited the wrong file :(
  1973. Revision 1.64 1998/10/05 21:33:24 peter
  1974. * fixed 161,165,166,167,168
  1975. Revision 1.63 1998/10/05 13:57:13 peter
  1976. * crash preventions
  1977. Revision 1.62 1998/10/02 17:06:02 peter
  1978. * better error message for unresolved forward types
  1979. Revision 1.61 1998/10/02 09:23:24 peter
  1980. * fixed error msg with type l=<var>
  1981. * block_type bt_const is now set in read_const_dec
  1982. Revision 1.60 1998/09/30 07:40:33 florian
  1983. * better error recovering
  1984. Revision 1.59 1998/09/26 17:45:33 peter
  1985. + idtoken and only one token table
  1986. Revision 1.58 1998/09/25 00:04:01 florian
  1987. * problems when calling class methods fixed
  1988. Revision 1.57 1998/09/24 23:49:09 peter
  1989. + aktmodeswitches
  1990. Revision 1.56 1998/09/23 15:39:09 pierre
  1991. * browser bugfixes
  1992. was adding a reference when looking for the symbol
  1993. if -bSYM_NAME was used
  1994. Revision 1.55 1998/09/21 13:24:44 daniel
  1995. * Memory leak fixed.
  1996. Revision 1.54 1998/09/17 13:41:16 pierre
  1997. sizeof(TPOINT) problem
  1998. Revision 1.53.2.1 1998/09/17 13:12:09 pierre
  1999. * virtual destructor did not set oo_hasvirtual
  2000. (detected with the sizeof(TPoint) problem
  2001. * genloadcallnode was missing
  2002. Revision 1.53 1998/09/09 11:50:52 pierre
  2003. * forward def are not put in record or objects
  2004. + added check for forwards also in record and objects
  2005. * dummy parasymtable for unit initialization removed from
  2006. symtable stack
  2007. Revision 1.52 1998/09/07 23:10:22 florian
  2008. * a lot of stuff fixed regarding rtti and publishing of properties,
  2009. basics should now work
  2010. Revision 1.51 1998/09/07 19:33:22 florian
  2011. + some stuff for property rtti added:
  2012. - NameIndex of the TPropInfo record is now written correctly
  2013. - the DEFAULT/NODEFAULT keyword is supported now
  2014. - the default value and the storedsym/def are now written to
  2015. the PPU fiel
  2016. Revision 1.50 1998/09/07 18:46:08 peter
  2017. * update smartlinking, uses getdatalabel
  2018. * renamed ptree.value vars to value_str,value_real,value_set
  2019. Revision 1.49 1998/09/07 17:37:00 florian
  2020. * first fixes for published properties
  2021. Revision 1.48 1998/09/04 08:42:02 peter
  2022. * updated some error messages
  2023. Revision 1.47 1998/09/03 16:03:18 florian
  2024. + rtti generation
  2025. * init table generation changed
  2026. Revision 1.46 1998/09/01 17:39:48 peter
  2027. + internal constant functions
  2028. Revision 1.45 1998/08/31 12:20:28 peter
  2029. * fixed array_dec when unknown type was used
  2030. Revision 1.44 1998/08/28 10:57:01 peter
  2031. * removed warnings
  2032. Revision 1.43 1998/08/25 13:09:25 pierre
  2033. * corrected mangling sheme :
  2034. cvar add Cprefix to the mixed case name whereas
  2035. export or public use direct name
  2036. Revision 1.42 1998/08/25 12:42:41 pierre
  2037. * CDECL changed to CVAR for variables
  2038. specifications are read in structures also
  2039. + started adding GPC compatibility mode ( option -Sp)
  2040. * names changed to lowercase
  2041. Revision 1.41 1998/08/23 21:04:36 florian
  2042. + rtti generation for classes added
  2043. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2044. Revision 1.40 1998/08/21 15:48:58 pierre
  2045. * more cdecl chagnes
  2046. - better line info
  2047. - changes the definition options of a procvar
  2048. if it is a unnamed type
  2049. Revision 1.39 1998/08/19 00:42:40 peter
  2050. + subrange types for enums
  2051. + checking for bounds type with ranges
  2052. Revision 1.38 1998/08/12 19:20:39 peter
  2053. + public is the same as export for c_vars
  2054. * a exported/public c_var incs now the refcount
  2055. Revision 1.37 1998/08/11 15:31:38 peter
  2056. * write extended to ppu file
  2057. * new version 0.99.7
  2058. Revision 1.36 1998/08/10 14:50:09 peter
  2059. + localswitches, moduleswitches, globalswitches splitting
  2060. Revision 1.35 1998/07/26 21:59:00 florian
  2061. + better support for switch $H
  2062. + index access to ansi strings added
  2063. + assigment of data (records/arrays) containing ansi strings
  2064. Revision 1.34 1998/07/20 22:17:15 florian
  2065. * hex constants in numeric char (#$54#$43 ...) are now allowed
  2066. * there was a bug in record_var_dec which prevents the used
  2067. of nested variant records (for example drivers.tevent of tv)
  2068. Revision 1.33 1998/07/18 17:11:11 florian
  2069. + ansi string constants fixed
  2070. + switch $H partial implemented
  2071. Revision 1.32 1998/07/14 21:46:50 peter
  2072. * updated messages file
  2073. Revision 1.31 1998/07/14 14:46:53 peter
  2074. * released NEWINPUT
  2075. Revision 1.30 1998/07/10 00:00:00 peter
  2076. * fixed ttypesym bug finally
  2077. * fileinfo in the symtable and better using for unused vars
  2078. Revision 1.29 1998/06/25 14:04:21 peter
  2079. + internal inc/dec
  2080. Revision 1.28 1998/06/24 12:26:45 peter
  2081. * stricter var parsing like tp7 and some optimizes with directive
  2082. parsing
  2083. Revision 1.27 1998/06/12 16:15:34 pierre
  2084. * external name 'C_var';
  2085. export name 'intern_C_var';
  2086. cdecl;
  2087. cdecl;external;
  2088. are now supported only with -Sv switch
  2089. Revision 1.25 1998/06/09 16:01:45 pierre
  2090. + added procedure directive parsing for procvars
  2091. (accepted are popstack cdecl and pascal)
  2092. + added C vars with the following syntax
  2093. var C calias 'true_c_name';(can be followed by external)
  2094. reason is that you must add the Cprefix
  2095. which is target dependent
  2096. Revision 1.24 1998/06/05 14:37:32 pierre
  2097. * fixes for inline for operators
  2098. * inline procedure more correctly restricted
  2099. Revision 1.23 1998/06/04 23:51:50 peter
  2100. * m68k compiles
  2101. + .def file creation moved to gendef.pas so it could also be used
  2102. for win32
  2103. Revision 1.22 1998/06/03 22:48:59 peter
  2104. + wordbool,longbool
  2105. * rename bis,von -> high,low
  2106. * moved some systemunit loading/creating to psystem.pas
  2107. Revision 1.21 1998/06/03 22:14:19 florian
  2108. * problem with sizes of classes fixed (if the anchestor was declared
  2109. forward, the compiler doesn't update the child classes size)
  2110. Revision 1.20 1998/05/28 14:35:54 peter
  2111. * nicer error message when no id is used after var
  2112. Revision 1.19 1998/05/23 01:21:19 peter
  2113. + aktasmmode, aktoptprocessor, aktoutputformat
  2114. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2115. + $LIBNAME to set the library name where the unit will be put in
  2116. * splitted cgi386 a bit (codeseg to large for bp7)
  2117. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2118. Revision 1.18 1998/05/20 09:42:35 pierre
  2119. + UseTokenInfo now default
  2120. * unit in interface uses and implementation uses gives error now
  2121. * only one error for unknown symbol (uses lastsymknown boolean)
  2122. the problem came from the label code !
  2123. + first inlined procedures and function work
  2124. (warning there might be allowed cases were the result is still wrong !!)
  2125. * UseBrower updated gives a global list of all position of all used symbols
  2126. with switch -gb
  2127. Revision 1.17 1998/05/11 13:07:55 peter
  2128. + $ifdef NEWPPU for the new ppuformat
  2129. + $define GDB not longer required
  2130. * removed all warnings and stripped some log comments
  2131. * no findfirst/findnext anymore to remove smartlink *.o files
  2132. Revision 1.16 1998/05/05 12:05:42 florian
  2133. * problems with properties fixed
  2134. * crash fixed: i:=l when i and l are undefined, was a problem with
  2135. implementation of private/protected
  2136. Revision 1.15 1998/05/01 09:01:23 florian
  2137. + correct semantics of private and protected
  2138. * small fix in variable scope:
  2139. a id can be used in a parameter list of a method, even it is used in
  2140. an anchestor class as field id
  2141. Revision 1.14 1998/05/01 07:43:56 florian
  2142. + basics for rtti implemented
  2143. + switch $m (generate rtti for published sections)
  2144. Revision 1.13 1998/04/30 15:59:41 pierre
  2145. * GDB works again better :
  2146. correct type info in one pass
  2147. + UseTokenInfo for better source position
  2148. * fixed one remaining bug in scanner for line counts
  2149. * several little fixes
  2150. Revision 1.12 1998/04/29 10:33:57 pierre
  2151. + added some code for ansistring (not complete nor working yet)
  2152. * corrected operator overloading
  2153. * corrected nasm output
  2154. + started inline procedures
  2155. + added starstarn : use ** for exponentiation (^ gave problems)
  2156. + started UseTokenInfo cond to get accurate positions
  2157. Revision 1.11 1998/04/28 11:45:52 florian
  2158. * make it compilable with TP
  2159. + small COM problems solved to compile classes.pp
  2160. Revision 1.10 1998/04/27 23:10:28 peter
  2161. + new scanner
  2162. * $makelib -> if smartlink
  2163. * small filename fixes pmodule.setfilename
  2164. * moved import from files.pas -> import.pas
  2165. Revision 1.9 1998/04/10 21:36:56 florian
  2166. + some stuff to support method pointers (procedure of object) added
  2167. (declaration, parameter handling)
  2168. Revision 1.8 1998/04/10 15:39:48 florian
  2169. * more fixes to get classes.pas compiled
  2170. Revision 1.7 1998/04/09 23:02:15 florian
  2171. * small problems solved to get remake3 work
  2172. Revision 1.6 1998/04/09 22:16:35 florian
  2173. * problem with previous REGALLOC solved
  2174. * improved property support
  2175. Revision 1.5 1998/04/08 14:59:20 florian
  2176. * problem with new expr_type solved
  2177. Revision 1.4 1998/04/08 10:26:09 florian
  2178. * correct error handling of virtual constructors
  2179. * problem with new type declaration handling fixed
  2180. Revision 1.3 1998/04/07 22:45:05 florian
  2181. * bug0092, bug0115 and bug0121 fixed
  2182. + packed object/class/array
  2183. Revision 1.2 1998/04/05 13:58:35 peter
  2184. * fixed the -Ss bug
  2185. + warning for Virtual constructors
  2186. * helppages updated with -TGO32V1
  2187. }