ptconst.pas 36 KB

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