pdecl.pas 86 KB

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