ptconst.pas 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. begin
  469. p:=comp_expr(true);
  470. do_firstpass(p);
  471. if p^.treetype=stringconstn then
  472. begin
  473. if p^.length>255 then
  474. len:=255
  475. else
  476. len:=p^.length;
  477. {$ifndef TP}
  478. {$ifopt H+}
  479. setlength(s,len);
  480. {$else}
  481. s[0]:=chr(len);
  482. {$endif}
  483. {$else}
  484. s[0]:=chr(len);
  485. {$endif}
  486. move(p^.value_str^,s[1],len);
  487. end
  488. else
  489. if is_constcharnode(p) then
  490. s:=char(byte(p^.value))
  491. else
  492. Message(cg_e_illegal_expression);
  493. disposetree(p);
  494. l:=length(s);
  495. for i:=Parraydef(def)^.lowrange to Parraydef(def)^.highrange do
  496. begin
  497. if i+1-Parraydef(def)^.lowrange<=l then
  498. begin
  499. datasegment^.concat(new(pai_const,init_8bit(byte(s[1]))));
  500. delete(s,1,1);
  501. end
  502. else
  503. {Fill the remaining positions with #0.}
  504. datasegment^.concat(new(pai_const,init_8bit(0)));
  505. end;
  506. if length(s)>0 then
  507. Message(parser_e_invalid_string_size);
  508. end;
  509. end;
  510. procvardef:
  511. begin
  512. { Procvars and pointers are no longer compatible. }
  513. { under tp: =nil or =var under fpc: =nil or =@var }
  514. if token=_NIL then
  515. begin
  516. datasegment^.concat(new(pai_const,init_32bit(0)));
  517. consume(_NIL);
  518. exit;
  519. end
  520. else
  521. if not(m_tp_procvar in aktmodeswitches) then
  522. if token=KLAMMERAFFE then
  523. consume(KLAMMERAFFE);
  524. getsym(pattern,true);
  525. consume(ID);
  526. if srsym^.typ=unitsym then
  527. begin
  528. consume(POINT);
  529. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  530. consume(ID);
  531. end;
  532. if srsym^.typ<>procsym then
  533. Message(cg_e_illegal_expression)
  534. else
  535. begin
  536. pd:=pprocsym(srsym)^.definition;
  537. if assigned(pd^.nextoverloaded) then
  538. Message(parser_e_no_overloaded_procvars);
  539. if is_po_equal(pprocvardef(def)^.options,pd^.options) and
  540. is_equal(pprocvardef(def)^.retdef,pd^.retdef) then
  541. begin
  542. hp1:=pprocvardef(def)^.para1;
  543. hp2:=pd^.para1;
  544. while assigned(hp1) and assigned(hp2) do
  545. begin
  546. if not(is_equal(hp1^.data,hp2^.data)) or
  547. not(hp1^.paratyp=hp2^.paratyp) then
  548. begin
  549. Message(type_e_mismatch);
  550. break;
  551. end;
  552. hp1:=hp1^.next;
  553. hp2:=hp2^.next;
  554. end;
  555. if not((hp1=nil) and (hp2=nil)) then
  556. Message(type_e_mismatch);
  557. end
  558. else
  559. Message(type_e_mismatch);
  560. datasegment^.concat(new(pai_const,init_symbol(strpnew(pd^.mangledname))));
  561. if pd^.owner^.symtabletype=unitsymtable then
  562. concat_external(pd^.mangledname,EXT_NEAR);
  563. end;
  564. end;
  565. { reads a typed constant record }
  566. recorddef:
  567. begin
  568. consume(LKLAMMER);
  569. aktpos:=0;
  570. while token<>RKLAMMER do
  571. begin
  572. s:=pattern;
  573. consume(ID);
  574. consume(COLON);
  575. srsym:=precdef(def)^.symtable^.search(s);
  576. if srsym=nil then
  577. begin
  578. Message1(sym_e_id_not_found,s);
  579. consume_all_until(SEMICOLON);
  580. end
  581. else
  582. begin
  583. { check position }
  584. if pvarsym(srsym)^.address<aktpos then
  585. Message(parser_e_invalid_record_const);
  586. { if needed fill }
  587. if pvarsym(srsym)^.address>aktpos then
  588. for i:=1 to pvarsym(srsym)^.address-aktpos do
  589. datasegment^.concat(new(pai_const,init_8bit(0)));
  590. { new position }
  591. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  592. { read the data }
  593. readtypedconst(pvarsym(srsym)^.definition,nil);
  594. if token=SEMICOLON then
  595. consume(SEMICOLON)
  596. else break;
  597. end;
  598. end;
  599. for i:=1 to def^.size-aktpos do
  600. datasegment^.concat(new(pai_const,init_8bit(0)));
  601. consume(RKLAMMER);
  602. end;
  603. { reads a typed object }
  604. objectdef:
  605. begin
  606. if (pobjectdef(def)^.options and (oo_hasvmt or oo_is_class))<>0 then
  607. begin
  608. Message(parser_e_type_const_not_possible);
  609. consume_all_until(RKLAMMER);
  610. end
  611. else
  612. begin
  613. consume(LKLAMMER);
  614. aktpos:=0;
  615. while token<>RKLAMMER do
  616. begin
  617. s:=pattern;
  618. consume(ID);
  619. consume(COLON);
  620. srsym:=nil;
  621. obj:=pobjectdef(def);
  622. symt:=obj^.publicsyms;
  623. while (srsym=nil) and assigned(symt) do
  624. begin
  625. srsym:=symt^.search(s);
  626. if assigned(obj) then
  627. obj:=obj^.childof;
  628. if assigned(obj) then
  629. symt:=obj^.publicsyms
  630. else
  631. symt:=nil;
  632. end;
  633. if srsym=nil then
  634. begin
  635. Message1(sym_e_id_not_found,s);
  636. consume_all_until(SEMICOLON);
  637. end
  638. else
  639. begin
  640. { check position }
  641. if pvarsym(srsym)^.address<aktpos then
  642. Message(parser_e_invalid_record_const);
  643. { if needed fill }
  644. if pvarsym(srsym)^.address>aktpos then
  645. for i:=1 to pvarsym(srsym)^.address-aktpos do
  646. datasegment^.concat(new(pai_const,init_8bit(0)));
  647. { new position }
  648. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  649. { read the data }
  650. readtypedconst(pvarsym(srsym)^.definition,nil);
  651. if token=SEMICOLON then
  652. consume(SEMICOLON)
  653. else break;
  654. end;
  655. end;
  656. for i:=1 to def^.size-aktpos do
  657. datasegment^.concat(new(pai_const,init_8bit(0)));
  658. consume(RKLAMMER);
  659. end;
  660. end;
  661. else Message(parser_e_type_const_not_possible);
  662. end;
  663. end;
  664. end.
  665. {
  666. $Log$
  667. Revision 1.35 1999-01-20 14:09:28 pierre
  668. * fix to bug0191
  669. Revision 1.34 1999/01/05 08:20:08 florian
  670. * mainly problem with invalid case ranges fixed (reported by Jonas)
  671. Revision 1.33 1998/12/15 17:16:01 peter
  672. * fixed const s : ^string
  673. * first things for const pchar : @string[1]
  674. Revision 1.32 1998/12/11 16:50:23 florian
  675. + typed const int64 and qword
  676. + unary minus-operator q1:=-q2;
  677. + not-operator
  678. Revision 1.31 1998/12/11 00:03:41 peter
  679. + globtype,tokens,version unit splitted from globals
  680. Revision 1.30 1998/11/27 14:34:42 peter
  681. * give error when string[0] decl is found
  682. Revision 1.29 1998/11/23 18:26:44 pierre
  683. * fix for bug0182
  684. Revision 1.28 1998/11/17 10:40:16 peter
  685. * H+ fixes
  686. Revision 1.27 1998/11/16 12:12:23 peter
  687. - generate_pascii which is obsolete
  688. Revision 1.26 1998/11/10 17:53:06 peter
  689. * fixed const string
  690. Revision 1.25 1998/11/10 16:10:47 peter
  691. * fixed const pchar
  692. Revision 1.24 1998/11/05 12:02:55 peter
  693. * released useansistring
  694. * removed -Sv, its now available in fpc modes
  695. Revision 1.23 1998/11/04 10:11:45 peter
  696. * ansistring fixes
  697. Revision 1.22 1998/10/20 08:06:56 pierre
  698. * several memory corruptions due to double freemem solved
  699. => never use p^.loc.location:=p^.left^.loc.location;
  700. + finally I added now by default
  701. that ra386dir translates global and unit symbols
  702. + added a first field in tsymtable and
  703. a nextsym field in tsym
  704. (this allows to obtain ordered type info for
  705. records and objects in gdb !)
  706. Revision 1.21 1998/10/19 08:55:03 pierre
  707. * wrong stabs info corrected once again !!
  708. + variable vmt offset with vmt field only if required
  709. implemented now !!!
  710. Revision 1.20 1998/10/16 08:51:49 peter
  711. + target_os.stackalignment
  712. + stack can be aligned at 2 or 4 byte boundaries
  713. Revision 1.19 1998/10/12 12:20:58 pierre
  714. + added tai_const_symbol_offset
  715. for r : pointer = @var.field;
  716. * better message for different arg names on implementation
  717. of function
  718. Revision 1.18 1998/10/12 09:50:05 florian
  719. + support of <procedure var type>:=<pointer> in delphi mode added
  720. Revision 1.17 1998/10/09 08:56:29 pierre
  721. * several memory leaks fixed
  722. Revision 1.16 1998/09/24 23:49:18 peter
  723. + aktmodeswitches
  724. Revision 1.15 1998/09/07 18:46:11 peter
  725. * update smartlinking, uses getdatalabel
  726. * renamed ptree.value vars to value_str,value_real,value_set
  727. Revision 1.14 1998/09/04 08:42:07 peter
  728. * updated some error messages
  729. Revision 1.13 1998/09/01 09:05:36 peter
  730. * fixed string[4]='.library'
  731. Revision 1.12 1998/08/31 12:26:32 peter
  732. * m68k and palmos updates from surebugfixes
  733. Revision 1.11 1998/08/10 14:50:20 peter
  734. + localswitches, moduleswitches, globalswitches splitting
  735. Revision 1.10 1998/07/21 11:16:25 florian
  736. * bug0147 fixed
  737. Revision 1.9 1998/07/20 22:17:16 florian
  738. * hex constants in numeric char (#$54#$43 ...) are now allowed
  739. * there was a bug in record_var_dec which prevents the used
  740. of nested variant records (for example drivers.tevent of tv)
  741. Revision 1.8 1998/07/20 18:40:15 florian
  742. * handling of ansi string constants should now work
  743. Revision 1.7 1998/07/18 22:54:29 florian
  744. * some ansi/wide/longstring support fixed:
  745. o parameter passing
  746. o returning as result from functions
  747. Revision 1.6 1998/06/08 22:59:52 peter
  748. * smartlinking works for win32
  749. * some defines to exclude some compiler parts
  750. Revision 1.5 1998/06/03 22:49:01 peter
  751. + wordbool,longbool
  752. * rename bis,von -> high,low
  753. * moved some systemunit loading/creating to psystem.pas
  754. Revision 1.4 1998/05/05 12:05:42 florian
  755. * problems with properties fixed
  756. * crash fixed: i:=l when i and l are undefined, was a problem with
  757. implementation of private/protected
  758. Revision 1.3 1998/04/29 10:34:00 pierre
  759. + added some code for ansistring (not complete nor working yet)
  760. * corrected operator overloading
  761. * corrected nasm output
  762. + started inline procedures
  763. + added starstarn : use ** for exponentiation (^ gave problems)
  764. + started UseTokenInfo cond to get accurate positions
  765. }