ptconst.pas 35 KB

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