pdecl.pas 87 KB

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