ptconst.pas 34 KB

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