pdecl.pas 85 KB

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