ptconst.pas 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. {
  2. $Id$
  3. Copyright (c) 1998 by Florian Klaempfl
  4. Reads typed constants
  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 ptconst;
  19. interface
  20. uses symtable;
  21. { this procedure reads typed constants }
  22. { sym is only needed for ansi strings }
  23. { the assembler label is in the middle (PM) }
  24. procedure readtypedconst(def : pdef;sym : ptypedconstsym);
  25. implementation
  26. uses
  27. globtype,systems,tokens,
  28. cobjects,globals,scanner,aasm,tree,pass_1,
  29. hcodegen,types,verbose
  30. { parser specific stuff }
  31. ,pbase,pexpr
  32. { processor specific stuff }
  33. {$ifdef i386}
  34. ,i386
  35. {$endif}
  36. {$ifdef m68k}
  37. ,m68k
  38. {$endif}
  39. ;
  40. { this procedure reads typed constants }
  41. procedure readtypedconst(def : pdef;sym : ptypedconstsym);
  42. var
  43. {$ifdef m68k}
  44. j : longint;
  45. {$endif m68k}
  46. len,base : longint;
  47. p,hp : ptree;
  48. i,l,offset,
  49. strlength : longint;
  50. ll : plabel;
  51. s : string;
  52. ca : pchar;
  53. aktpos : longint;
  54. pd : pprocdef;
  55. obj : pobjectdef;
  56. symt : psymtable;
  57. hp1,hp2 : pdefcoll;
  58. value : bestreal;
  59. procedure check_range;
  60. begin
  61. if ((p^.value>porddef(def)^.high) or
  62. (p^.value<porddef(def)^.low)) then
  63. begin
  64. if (cs_check_range in aktlocalswitches) then
  65. Message(parser_e_range_check_error)
  66. else
  67. Message(parser_w_range_check_error);
  68. end;
  69. end;
  70. function is_po_equal(o1,o2:longint):boolean;
  71. begin
  72. { assembler does not affect }
  73. is_po_equal:=(o1 and not(poassembler))=
  74. (o2 and not(poassembler));
  75. end;
  76. {$R-} {Range check creates problem with init_8bit(-1) !!}
  77. begin
  78. case def^.deftype of
  79. orddef:
  80. begin
  81. p:=comp_expr(true);
  82. do_firstpass(p);
  83. case porddef(def)^.typ of
  84. s8bit,
  85. u8bit : begin
  86. if not is_constintnode(p) then
  87. { is't an int expected }
  88. Message(cg_e_illegal_expression)
  89. else
  90. begin
  91. datasegment^.concat(new(pai_const,init_8bit(p^.value)));
  92. check_range;
  93. end;
  94. end;
  95. s32bit : begin
  96. if not is_constintnode(p) then
  97. Message(cg_e_illegal_expression)
  98. else
  99. begin
  100. datasegment^.concat(new(pai_const,init_32bit(p^.value)));
  101. check_range;
  102. end;
  103. end;
  104. u32bit : begin
  105. if not is_constintnode(p) then
  106. Message(cg_e_illegal_expression)
  107. else
  108. datasegment^.concat(new(pai_const,init_32bit(p^.value)));
  109. end;
  110. bool8bit : begin
  111. if not is_constboolnode(p) then
  112. Message(cg_e_illegal_expression);
  113. datasegment^.concat(new(pai_const,init_8bit(p^.value)));
  114. end;
  115. uchar : begin
  116. if not is_constcharnode(p) then
  117. Message(cg_e_illegal_expression);
  118. datasegment^.concat(new(pai_const,init_8bit(p^.value)));
  119. end;
  120. u16bit,
  121. s16bit : begin
  122. if not is_constintnode(p) then
  123. Message(cg_e_illegal_expression);
  124. datasegment^.concat(new(pai_const,init_16bit(p^.value)));
  125. check_range;
  126. end;
  127. s64bitint,
  128. u64bit:
  129. begin
  130. if not is_constintnode(p) then
  131. Message(cg_e_illegal_expression)
  132. else
  133. begin
  134. {!!!!! hmmm, we can write yet only consts til 2^32-1 :( (FK) }
  135. datasegment^.concat(new(pai_const,init_32bit(p^.value)));
  136. datasegment^.concat(new(pai_const,init_32bit(0)));
  137. end;
  138. end;
  139. end;
  140. disposetree(p);
  141. end;
  142. floatdef:
  143. begin
  144. p:=comp_expr(true);
  145. do_firstpass(p);
  146. if is_constrealnode(p) then
  147. value:=p^.value_real
  148. else if is_constintnode(p) then
  149. value:=p^.value
  150. else
  151. Message(cg_e_illegal_expression);
  152. case pfloatdef(def)^.typ of
  153. s64real : datasegment^.concat(new(pai_double,init(value)));
  154. s32real : datasegment^.concat(new(pai_single,init(value)));
  155. s80real : datasegment^.concat(new(pai_extended,init(value)));
  156. s64bit : datasegment^.concat(new(pai_comp,init(value)));
  157. f32bit : datasegment^.concat(new(pai_const,init_32bit(trunc(value*65536))));
  158. else internalerror(18);
  159. end;
  160. disposetree(p);
  161. end;
  162. pointerdef:
  163. begin
  164. p:=comp_expr(true);
  165. do_firstpass(p);
  166. if (p^.treetype=typeconvn) and
  167. ((p^.left^.treetype=addrn) or (p^.left^.treetype=niln)) and
  168. is_equal(def,p^.resulttype) then
  169. begin
  170. hp:=p^.left;
  171. putnode(p);
  172. p:=hp;
  173. end;
  174. { allows horrible ofs(typeof(TButton)^) code !! }
  175. if (p^.treetype=addrn) and (p^.left^.treetype=derefn) then
  176. begin
  177. hp:=p^.left^.left;
  178. p^.left^.left:=nil;
  179. disposetree(p);
  180. p:=hp;
  181. end;
  182. { nil pointer ? }
  183. if p^.treetype=niln then
  184. datasegment^.concat(new(pai_const,init_32bit(0)))
  185. { maybe pchar ? }
  186. else
  187. if (ppointerdef(def)^.definition^.deftype=orddef) and
  188. (porddef(ppointerdef(def)^.definition)^.typ=uchar) and
  189. (p^.treetype<>addrn) then
  190. begin
  191. getdatalabel(ll);
  192. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(ll)))));
  193. consts^.concat(new(pai_label,init(ll)));
  194. if p^.treetype=stringconstn then
  195. begin
  196. getmem(ca,p^.length+2);
  197. move(p^.value_str^,ca^,p^.length+1);
  198. consts^.concat(new(pai_string,init_length_pchar(ca,p^.length+1)));
  199. end
  200. else
  201. if is_constcharnode(p) then
  202. consts^.concat(new(pai_string,init(char(byte(p^.value))+#0)))
  203. else
  204. Message(cg_e_illegal_expression);
  205. end
  206. else
  207. if p^.treetype=addrn then
  208. begin
  209. hp:=p^.left;
  210. while assigned(hp) and (hp^.treetype in [subscriptn,vecn]) do
  211. hp:=hp^.left;
  212. if (is_equal(ppointerdef(p^.resulttype)^.definition,ppointerdef(def)^.definition) or
  213. (is_equal(ppointerdef(p^.resulttype)^.definition,voiddef)) or
  214. (is_equal(ppointerdef(def)^.definition,voiddef))) and
  215. (hp^.treetype=loadn) then
  216. begin
  217. do_firstpass(p^.left);
  218. hp:=p^.left;
  219. offset:=0;
  220. while assigned(hp) and (hp^.treetype<>loadn) do
  221. begin
  222. case hp^.treetype of
  223. vecn :
  224. begin
  225. if (hp^.left^.resulttype^.deftype=stringdef) then
  226. begin
  227. { this seems OK for shortstring and ansistrings PM }
  228. { it is wrong for widestrings !! }
  229. len:=1;
  230. base:=0;
  231. end
  232. else if (hp^.left^.resulttype^.deftype=arraydef) then
  233. begin
  234. len:=parraydef(hp^.left^.resulttype)^.elesize;
  235. base:=parraydef(hp^.left^.resulttype)^.lowrange;
  236. end
  237. else
  238. Message(cg_e_illegal_expression);
  239. if is_constintnode(hp^.right) then
  240. inc(offset,len*(get_ordinal_value(hp^.right)-base))
  241. else
  242. Message(cg_e_illegal_expression);
  243. {internalerror(9779);}
  244. end;
  245. subscriptn : inc(offset,hp^.vs^.address)
  246. else
  247. Message(cg_e_illegal_expression);
  248. end;
  249. hp:=hp^.left;
  250. end;
  251. datasegment^.concat(new(pai_const_symbol_offset,init(
  252. strpnew(hp^.symtableentry^.mangledname),offset)));
  253. (*if token=POINT then
  254. begin
  255. offset:=0;
  256. while token=POINT do
  257. begin
  258. consume(POINT);
  259. lsym:=pvarsym(precdef(
  260. ppointerdef(p^.resulttype)^.definition)^.symtable^.search(pattern));
  261. if assigned(sym) then
  262. offset:=offset+lsym^.address
  263. else
  264. begin
  265. Message1(sym_e_illegal_field,pattern);
  266. end;
  267. consume(ID);
  268. end;
  269. datasegment^.concat(new(pai_const_symbol_offset,init(
  270. strpnew(p^.left^.symtableentry^.mangledname),offset)));
  271. end
  272. else
  273. begin
  274. datasegment^.concat(new(pai_const,init_symbol(
  275. strpnew(p^.left^.symtableentry^.mangledname))));
  276. end; *)
  277. maybe_concat_external(hp^.symtableentry^.owner,
  278. hp^.symtableentry^.mangledname);
  279. end
  280. else
  281. Message(cg_e_illegal_expression);
  282. end
  283. else
  284. { allow typeof(Object type)}
  285. if (p^.treetype=inlinen) and
  286. (p^.inlinenumber=in_typeof_x) then
  287. begin
  288. if (p^.left^.treetype=typen) then
  289. begin
  290. datasegment^.concat(new(pai_const,init_symbol(
  291. strpnew(pobjectdef(p^.left^.resulttype)^.vmt_mangledname))));
  292. if pobjectdef(p^.left^.resulttype)^.owner^.symtabletype=unitsymtable then
  293. concat_external(pobjectdef(p^.left^.resulttype)^.vmt_mangledname,EXT_NEAR);
  294. end
  295. else
  296. Message(cg_e_illegal_expression);
  297. end
  298. else
  299. Message(cg_e_illegal_expression);
  300. disposetree(p);
  301. end;
  302. setdef:
  303. begin
  304. p:=comp_expr(true);
  305. do_firstpass(p);
  306. if p^.treetype=setconstn then
  307. begin
  308. { we only allow const sets }
  309. if assigned(p^.left) then
  310. Message(cg_e_illegal_expression)
  311. else
  312. begin
  313. {$ifdef i386}
  314. for l:=0 to def^.savesize-1 do
  315. datasegment^.concat(new(pai_const,init_8bit(p^.value_set^[l])));
  316. {$endif}
  317. {$ifdef m68k}
  318. j:=0;
  319. for l:=0 to ((def^.savesize-1) div 4) do
  320. { HORRIBLE HACK because of endian }
  321. { now use intel endian for constant sets }
  322. begin
  323. datasegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+3])));
  324. datasegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+2])));
  325. datasegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+1])));
  326. datasegment^.concat(new(pai_const,init_8bit(p^.value_set^[j])));
  327. Inc(j,4);
  328. end;
  329. {$endif}
  330. end;
  331. end
  332. else
  333. Message(cg_e_illegal_expression);
  334. disposetree(p);
  335. end;
  336. enumdef:
  337. begin
  338. p:=comp_expr(true);
  339. do_firstpass(p);
  340. if p^.treetype=ordconstn then
  341. begin
  342. if is_equal(p^.resulttype,def) then
  343. datasegment^.concat(new(pai_const,init_32bit(p^.value)))
  344. else
  345. Message(cg_e_illegal_expression);
  346. end
  347. else
  348. Message(cg_e_illegal_expression);
  349. disposetree(p);
  350. end;
  351. stringdef:
  352. begin
  353. p:=comp_expr(true);
  354. do_firstpass(p);
  355. { first take care of prefixes for long and ansi strings }
  356. case pstringdef(def)^.string_typ of
  357. st_shortstring:
  358. begin
  359. if p^.treetype=stringconstn then
  360. begin
  361. if p^.length>=def^.size then
  362. strlength:=def^.size-1
  363. else
  364. strlength:=p^.length;
  365. datasegment^.concat(new(pai_const,init_8bit(strlength)));
  366. { this can also handle longer strings }
  367. getmem(ca,strlength+1);
  368. move(p^.value_str^,ca^,strlength);
  369. ca[strlength]:=#0;
  370. datasegment^.concat(new(pai_string,init_length_pchar(ca,strlength)));
  371. end
  372. else if is_constcharnode(p) then
  373. begin
  374. datasegment^.concat(new(pai_string,init(#1+char(byte(p^.value)))));
  375. strlength:=1;
  376. end
  377. else Message(cg_e_illegal_expression);
  378. if def^.size>strlength then
  379. begin
  380. getmem(ca,def^.size-strlength);
  381. { def^.size contains also the leading length, so we }
  382. { we have to subtract one }
  383. fillchar(ca[0],def^.size-strlength-1,' ');
  384. ca[def^.size-strlength-1]:=#0;
  385. { this can also handle longer strings }
  386. datasegment^.concat(new(pai_string,init_length_pchar(ca,def^.size-strlength-1)));
  387. end;
  388. end;
  389. {$ifdef UseLongString}
  390. st_longstring:
  391. begin
  392. if is_constcharnode(p) then
  393. strlength:=1
  394. else
  395. strlength:=p^.length;
  396. { first write the maximum size }
  397. datasegment^.concat(new(pai_const,init_32bit(strlength)))));
  398. { fill byte }
  399. datasegment^.concat(new(pai_const,init_8bit(0)));
  400. if p^.treetype=stringconstn then
  401. begin
  402. getmem(ca,strlength+1);
  403. move(p^.value_str^,ca^,strlength);
  404. ca[strlength]:=#0;
  405. generate_pascii(consts,ca,strlength);
  406. end
  407. else if is_constcharnode(p) then
  408. begin
  409. consts^.concat(new(pai_const,init_8bit(p^.value)));
  410. end
  411. else Message(cg_e_illegal_expression);
  412. datasegment^.concat(new(pai_const,init_8bit(0)));
  413. end;
  414. {$endif UseLongString}
  415. st_ansistring:
  416. begin
  417. { an empty ansi string is nil! }
  418. if (p^.treetype=stringconstn) and (p^.length=0) then
  419. datasegment^.concat(new(pai_const,init_32bit(0)))
  420. else
  421. begin
  422. if is_constcharnode(p) then
  423. strlength:=1
  424. else
  425. strlength:=p^.length;
  426. getdatalabel(ll);
  427. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(ll)))));
  428. { first write the maximum size }
  429. consts^.concat(new(pai_const,init_32bit(strlength)));
  430. { second write the real length }
  431. consts^.concat(new(pai_const,init_32bit(strlength)));
  432. { redondent with maxlength but who knows ... (PM) }
  433. { third write use count (set to -1 for safety ) }
  434. consts^.concat(new(pai_const,init_32bit(-1)));
  435. consts^.concat(new(pai_label,init(ll)));
  436. if p^.treetype=stringconstn then
  437. begin
  438. getmem(ca,strlength+1);
  439. move(p^.value_str^,ca^,strlength);
  440. ca[strlength]:=#0;
  441. consts^.concat(new(pai_string,init_length_pchar(ca,strlength)));
  442. end
  443. else if is_constcharnode(p) then
  444. begin
  445. consts^.concat(new(pai_const,init_8bit(p^.value)));
  446. end
  447. else Message(cg_e_illegal_expression);
  448. consts^.concat(new(pai_const,init_8bit(0)));
  449. end;
  450. end;
  451. end;
  452. disposetree(p);
  453. end;
  454. arraydef:
  455. begin
  456. if token=LKLAMMER then
  457. begin
  458. consume(LKLAMMER);
  459. for l:=parraydef(def)^.lowrange to parraydef(def)^.highrange-1 do
  460. begin
  461. readtypedconst(parraydef(def)^.definition,nil);
  462. consume(COMMA);
  463. end;
  464. readtypedconst(parraydef(def)^.definition,nil);
  465. consume(RKLAMMER);
  466. end
  467. else
  468. { if array of char then we allow also a string }
  469. if is_char(parraydef(def)^.definition) then
  470. begin
  471. p:=comp_expr(true);
  472. do_firstpass(p);
  473. if p^.treetype=stringconstn then
  474. begin
  475. if p^.length>255 then
  476. len:=255
  477. else
  478. len:=p^.length;
  479. {$ifndef TP}
  480. {$ifopt H+}
  481. setlength(s,len);
  482. {$else}
  483. s[0]:=chr(len);
  484. {$endif}
  485. {$else}
  486. s[0]:=chr(len);
  487. {$endif}
  488. move(p^.value_str^,s[1],len);
  489. end
  490. else
  491. if is_constcharnode(p) then
  492. s:=char(byte(p^.value))
  493. else
  494. begin
  495. Message(cg_e_illegal_expression);
  496. s:='';
  497. end;
  498. disposetree(p);
  499. l:=length(s);
  500. for i:=Parraydef(def)^.lowrange to Parraydef(def)^.highrange do
  501. begin
  502. if i+1-Parraydef(def)^.lowrange<=l then
  503. begin
  504. datasegment^.concat(new(pai_const,init_8bit(byte(s[1]))));
  505. delete(s,1,1);
  506. end
  507. else
  508. {Fill the remaining positions with #0.}
  509. datasegment^.concat(new(pai_const,init_8bit(0)));
  510. end;
  511. if length(s)>0 then
  512. Message(parser_e_string_larger_array);
  513. end
  514. else
  515. begin
  516. { we want the ( }
  517. consume(LKLAMMER);
  518. end;
  519. end;
  520. procvardef:
  521. begin
  522. { Procvars and pointers are no longer compatible. }
  523. { under tp: =nil or =var under fpc: =nil or =@var }
  524. if token=_NIL then
  525. begin
  526. datasegment^.concat(new(pai_const,init_32bit(0)));
  527. consume(_NIL);
  528. exit;
  529. end
  530. else
  531. if not(m_tp_procvar in aktmodeswitches) then
  532. if token=KLAMMERAFFE then
  533. consume(KLAMMERAFFE);
  534. getsym(pattern,true);
  535. consume(ID);
  536. if srsym^.typ=unitsym then
  537. begin
  538. consume(POINT);
  539. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  540. consume(ID);
  541. end;
  542. if srsym^.typ<>procsym then
  543. Message(cg_e_illegal_expression)
  544. else
  545. begin
  546. pd:=pprocsym(srsym)^.definition;
  547. if assigned(pd^.nextoverloaded) then
  548. Message(parser_e_no_overloaded_procvars);
  549. if is_po_equal(pprocvardef(def)^.options,pd^.options) and
  550. is_equal(pprocvardef(def)^.retdef,pd^.retdef) then
  551. begin
  552. hp1:=pprocvardef(def)^.para1;
  553. hp2:=pd^.para1;
  554. while assigned(hp1) and assigned(hp2) do
  555. begin
  556. if not(is_equal(hp1^.data,hp2^.data)) or
  557. not(hp1^.paratyp=hp2^.paratyp) then
  558. begin
  559. Message(type_e_mismatch);
  560. break;
  561. end;
  562. hp1:=hp1^.next;
  563. hp2:=hp2^.next;
  564. end;
  565. if not((hp1=nil) and (hp2=nil)) then
  566. Message(type_e_mismatch);
  567. end
  568. else
  569. Message(type_e_mismatch);
  570. datasegment^.concat(new(pai_const,init_symbol(strpnew(pd^.mangledname))));
  571. if pd^.owner^.symtabletype=unitsymtable then
  572. concat_external(pd^.mangledname,EXT_NEAR);
  573. end;
  574. end;
  575. { reads a typed constant record }
  576. recorddef:
  577. begin
  578. consume(LKLAMMER);
  579. aktpos:=0;
  580. while token<>RKLAMMER do
  581. begin
  582. s:=pattern;
  583. consume(ID);
  584. consume(COLON);
  585. srsym:=precdef(def)^.symtable^.search(s);
  586. if srsym=nil then
  587. begin
  588. Message1(sym_e_id_not_found,s);
  589. consume_all_until(SEMICOLON);
  590. end
  591. else
  592. begin
  593. { check position }
  594. if pvarsym(srsym)^.address<aktpos then
  595. Message(parser_e_invalid_record_const);
  596. { if needed fill }
  597. if pvarsym(srsym)^.address>aktpos then
  598. for i:=1 to pvarsym(srsym)^.address-aktpos do
  599. datasegment^.concat(new(pai_const,init_8bit(0)));
  600. { new position }
  601. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  602. { read the data }
  603. readtypedconst(pvarsym(srsym)^.definition,nil);
  604. if token=SEMICOLON then
  605. consume(SEMICOLON)
  606. else break;
  607. end;
  608. end;
  609. for i:=1 to def^.size-aktpos do
  610. datasegment^.concat(new(pai_const,init_8bit(0)));
  611. consume(RKLAMMER);
  612. end;
  613. { reads a typed object }
  614. objectdef:
  615. begin
  616. if (pobjectdef(def)^.options and (oo_hasvmt or oo_is_class))<>0 then
  617. begin
  618. Message(parser_e_type_const_not_possible);
  619. consume_all_until(RKLAMMER);
  620. end
  621. else
  622. begin
  623. consume(LKLAMMER);
  624. aktpos:=0;
  625. while token<>RKLAMMER do
  626. begin
  627. s:=pattern;
  628. consume(ID);
  629. consume(COLON);
  630. srsym:=nil;
  631. obj:=pobjectdef(def);
  632. symt:=obj^.publicsyms;
  633. while (srsym=nil) and assigned(symt) do
  634. begin
  635. srsym:=symt^.search(s);
  636. if assigned(obj) then
  637. obj:=obj^.childof;
  638. if assigned(obj) then
  639. symt:=obj^.publicsyms
  640. else
  641. symt:=nil;
  642. end;
  643. if srsym=nil then
  644. begin
  645. Message1(sym_e_id_not_found,s);
  646. consume_all_until(SEMICOLON);
  647. end
  648. else
  649. begin
  650. { check position }
  651. if pvarsym(srsym)^.address<aktpos then
  652. Message(parser_e_invalid_record_const);
  653. { if needed fill }
  654. if pvarsym(srsym)^.address>aktpos then
  655. for i:=1 to pvarsym(srsym)^.address-aktpos do
  656. datasegment^.concat(new(pai_const,init_8bit(0)));
  657. { new position }
  658. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  659. { read the data }
  660. readtypedconst(pvarsym(srsym)^.definition,nil);
  661. if token=SEMICOLON then
  662. consume(SEMICOLON)
  663. else break;
  664. end;
  665. end;
  666. for i:=1 to def^.size-aktpos do
  667. datasegment^.concat(new(pai_const,init_8bit(0)));
  668. consume(RKLAMMER);
  669. end;
  670. end;
  671. else Message(parser_e_type_const_not_possible);
  672. end;
  673. end;
  674. end.
  675. {
  676. $Log$
  677. Revision 1.36 1999-02-17 10:15:26 peter
  678. * fixed error messages when parsing typed const array
  679. Revision 1.35 1999/01/20 14:09:28 pierre
  680. * fix to bug0191
  681. Revision 1.34 1999/01/05 08:20:08 florian
  682. * mainly problem with invalid case ranges fixed (reported by Jonas)
  683. Revision 1.33 1998/12/15 17:16:01 peter
  684. * fixed const s : ^string
  685. * first things for const pchar : @string[1]
  686. Revision 1.32 1998/12/11 16:50:23 florian
  687. + typed const int64 and qword
  688. + unary minus-operator q1:=-q2;
  689. + not-operator
  690. Revision 1.31 1998/12/11 00:03:41 peter
  691. + globtype,tokens,version unit splitted from globals
  692. Revision 1.30 1998/11/27 14:34:42 peter
  693. * give error when string[0] decl is found
  694. Revision 1.29 1998/11/23 18:26:44 pierre
  695. * fix for bug0182
  696. Revision 1.28 1998/11/17 10:40:16 peter
  697. * H+ fixes
  698. Revision 1.27 1998/11/16 12:12:23 peter
  699. - generate_pascii which is obsolete
  700. Revision 1.26 1998/11/10 17:53:06 peter
  701. * fixed const string
  702. Revision 1.25 1998/11/10 16:10:47 peter
  703. * fixed const pchar
  704. Revision 1.24 1998/11/05 12:02:55 peter
  705. * released useansistring
  706. * removed -Sv, its now available in fpc modes
  707. Revision 1.23 1998/11/04 10:11:45 peter
  708. * ansistring fixes
  709. Revision 1.22 1998/10/20 08:06:56 pierre
  710. * several memory corruptions due to double freemem solved
  711. => never use p^.loc.location:=p^.left^.loc.location;
  712. + finally I added now by default
  713. that ra386dir translates global and unit symbols
  714. + added a first field in tsymtable and
  715. a nextsym field in tsym
  716. (this allows to obtain ordered type info for
  717. records and objects in gdb !)
  718. Revision 1.21 1998/10/19 08:55:03 pierre
  719. * wrong stabs info corrected once again !!
  720. + variable vmt offset with vmt field only if required
  721. implemented now !!!
  722. Revision 1.20 1998/10/16 08:51:49 peter
  723. + target_os.stackalignment
  724. + stack can be aligned at 2 or 4 byte boundaries
  725. Revision 1.19 1998/10/12 12:20:58 pierre
  726. + added tai_const_symbol_offset
  727. for r : pointer = @var.field;
  728. * better message for different arg names on implementation
  729. of function
  730. Revision 1.18 1998/10/12 09:50:05 florian
  731. + support of <procedure var type>:=<pointer> in delphi mode added
  732. Revision 1.17 1998/10/09 08:56:29 pierre
  733. * several memory leaks fixed
  734. Revision 1.16 1998/09/24 23:49:18 peter
  735. + aktmodeswitches
  736. Revision 1.15 1998/09/07 18:46:11 peter
  737. * update smartlinking, uses getdatalabel
  738. * renamed ptree.value vars to value_str,value_real,value_set
  739. Revision 1.14 1998/09/04 08:42:07 peter
  740. * updated some error messages
  741. Revision 1.13 1998/09/01 09:05:36 peter
  742. * fixed string[4]='.library'
  743. Revision 1.12 1998/08/31 12:26:32 peter
  744. * m68k and palmos updates from surebugfixes
  745. Revision 1.11 1998/08/10 14:50:20 peter
  746. + localswitches, moduleswitches, globalswitches splitting
  747. Revision 1.10 1998/07/21 11:16:25 florian
  748. * bug0147 fixed
  749. Revision 1.9 1998/07/20 22:17:16 florian
  750. * hex constants in numeric char (#$54#$43 ...) are now allowed
  751. * there was a bug in record_var_dec which prevents the used
  752. of nested variant records (for example drivers.tevent of tv)
  753. Revision 1.8 1998/07/20 18:40:15 florian
  754. * handling of ansi string constants should now work
  755. Revision 1.7 1998/07/18 22:54:29 florian
  756. * some ansi/wide/longstring support fixed:
  757. o parameter passing
  758. o returning as result from functions
  759. Revision 1.6 1998/06/08 22:59:52 peter
  760. * smartlinking works for win32
  761. * some defines to exclude some compiler parts
  762. Revision 1.5 1998/06/03 22:49:01 peter
  763. + wordbool,longbool
  764. * rename bis,von -> high,low
  765. * moved some systemunit loading/creating to psystem.pas
  766. Revision 1.4 1998/05/05 12:05:42 florian
  767. * problems with properties fixed
  768. * crash fixed: i:=l when i and l are undefined, was a problem with
  769. implementation of private/protected
  770. Revision 1.3 1998/04/29 10:34:00 pierre
  771. + added some code for ansistring (not complete nor working yet)
  772. * corrected operator overloading
  773. * corrected nasm output
  774. + started inline procedures
  775. + added starstarn : use ** for exponentiation (^ gave problems)
  776. + started UseTokenInfo cond to get accurate positions
  777. }