pdecl.pas 91 KB

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