pdecl.pas 91 KB

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