ptconst.pas 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  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. cpubase,
  35. { codegen }
  36. hcodegen,hcgdata;
  37. { this procedure reads typed constants }
  38. procedure readtypedconst(def : pdef;sym : ptypedconstsym;no_change_allowed : boolean);
  39. var
  40. {$ifdef m68k}
  41. j : longint;
  42. {$endif m68k}
  43. len,base : longint;
  44. p,hp : ptree;
  45. i,l,offset,
  46. strlength : longint;
  47. curconstsegment : paasmoutput;
  48. ll : pasmlabel;
  49. s : string;
  50. ca : pchar;
  51. aktpos : longint;
  52. pd : pprocdef;
  53. obj : pobjectdef;
  54. symt : psymtable;
  55. value : bestreal;
  56. procedure check_range;
  57. begin
  58. if ((p^.value>porddef(def)^.high) or
  59. (p^.value<porddef(def)^.low)) then
  60. begin
  61. if (cs_check_range in aktlocalswitches) then
  62. Message(parser_e_range_check_error)
  63. else
  64. Message(parser_w_range_check_error);
  65. end;
  66. end;
  67. (* function is_po_equal(o1,o2:longint):boolean;
  68. begin
  69. { assembler does not affect }
  70. is_po_equal:=(o1 and not(poassembler))=
  71. (o2 and not(poassembler));
  72. end; *)
  73. {$R-} {Range check creates problem with init_8bit(-1) !!}
  74. begin
  75. if no_change_allowed then
  76. curconstsegment:=consts
  77. else
  78. curconstsegment:=datasegment;
  79. case def^.deftype of
  80. orddef:
  81. begin
  82. p:=comp_expr(true);
  83. do_firstpass(p);
  84. case porddef(def)^.typ of
  85. s8bit,
  86. u8bit : begin
  87. if not is_constintnode(p) then
  88. { is't an int expected }
  89. Message(cg_e_illegal_expression)
  90. else
  91. begin
  92. curconstsegment^.concat(new(pai_const,init_8bit(p^.value)));
  93. check_range;
  94. end;
  95. end;
  96. s32bit : begin
  97. if not is_constintnode(p) then
  98. Message(cg_e_illegal_expression)
  99. else
  100. begin
  101. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)));
  102. check_range;
  103. end;
  104. end;
  105. u32bit : begin
  106. if not is_constintnode(p) then
  107. Message(cg_e_illegal_expression)
  108. else
  109. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)));
  110. end;
  111. bool8bit : begin
  112. if not is_constboolnode(p) then
  113. Message(cg_e_illegal_expression);
  114. curconstsegment^.concat(new(pai_const,init_8bit(p^.value)));
  115. end;
  116. bool16bit : begin
  117. if not is_constboolnode(p) then
  118. Message(cg_e_illegal_expression);
  119. curconstsegment^.concat(new(pai_const,init_16bit(p^.value)));
  120. end;
  121. bool32bit : begin
  122. if not is_constboolnode(p) then
  123. Message(cg_e_illegal_expression);
  124. curconstsegment^.concat(new(pai_const,init_32bit(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. s64bit,
  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. else
  151. internalerror(3799);
  152. end;
  153. disposetree(p);
  154. end;
  155. floatdef:
  156. begin
  157. p:=comp_expr(true);
  158. do_firstpass(p);
  159. if is_constrealnode(p) then
  160. value:=p^.value_real
  161. else if is_constintnode(p) then
  162. value:=p^.value
  163. else
  164. Message(cg_e_illegal_expression);
  165. case pfloatdef(def)^.typ of
  166. s32real : curconstsegment^.concat(new(pai_real_32bit,init(value)));
  167. s64real : curconstsegment^.concat(new(pai_real_64bit,init(value)));
  168. s80real : curconstsegment^.concat(new(pai_real_80bit,init(value)));
  169. s64comp : curconstsegment^.concat(new(pai_comp_64bit,init(value)));
  170. f32bit : curconstsegment^.concat(new(pai_const,init_32bit(trunc(value*65536))));
  171. else internalerror(18);
  172. end;
  173. disposetree(p);
  174. end;
  175. pointerdef:
  176. begin
  177. p:=comp_expr(true);
  178. do_firstpass(p);
  179. if (p^.treetype=typeconvn) and
  180. ((p^.left^.treetype=addrn) or (p^.left^.treetype=niln)) and
  181. is_equal(def,p^.resulttype) then
  182. begin
  183. hp:=p^.left;
  184. putnode(p);
  185. p:=hp;
  186. end;
  187. { allows horrible ofs(typeof(TButton)^) code !! }
  188. if (p^.treetype=addrn) and (p^.left^.treetype=derefn) then
  189. begin
  190. hp:=p^.left^.left;
  191. p^.left^.left:=nil;
  192. disposetree(p);
  193. p:=hp;
  194. end;
  195. { nil pointer ? }
  196. if p^.treetype=niln then
  197. curconstsegment^.concat(new(pai_const,init_32bit(0)))
  198. { maybe pchar ? }
  199. else
  200. if (ppointerdef(def)^.definition^.deftype=orddef) and
  201. (porddef(ppointerdef(def)^.definition)^.typ=uchar) and
  202. (p^.treetype<>addrn) then
  203. begin
  204. getdatalabel(ll);
  205. curconstsegment^.concat(new(pai_const_symbol,init(ll)));
  206. consts^.concat(new(pai_label,init(ll)));
  207. if p^.treetype=stringconstn then
  208. begin
  209. getmem(ca,p^.length+2);
  210. move(p^.value_str^,ca^,p^.length+1);
  211. consts^.concat(new(pai_string,init_length_pchar(ca,p^.length+1)));
  212. end
  213. else
  214. if is_constcharnode(p) then
  215. consts^.concat(new(pai_string,init(char(byte(p^.value))+#0)))
  216. else
  217. Message(cg_e_illegal_expression);
  218. end
  219. else
  220. if p^.treetype=addrn then
  221. begin
  222. hp:=p^.left;
  223. while assigned(hp) and (hp^.treetype in [subscriptn,vecn]) do
  224. hp:=hp^.left;
  225. if (is_equal(ppointerdef(p^.resulttype)^.definition,ppointerdef(def)^.definition) or
  226. (is_equal(ppointerdef(p^.resulttype)^.definition,voiddef)) or
  227. (is_equal(ppointerdef(def)^.definition,voiddef))) and
  228. (hp^.treetype=loadn) then
  229. begin
  230. do_firstpass(p^.left);
  231. hp:=p^.left;
  232. offset:=0;
  233. while assigned(hp) and (hp^.treetype<>loadn) do
  234. begin
  235. case hp^.treetype of
  236. vecn :
  237. begin
  238. if (hp^.left^.resulttype^.deftype=stringdef) then
  239. begin
  240. { this seems OK for shortstring and ansistrings PM }
  241. { it is wrong for widestrings !! }
  242. len:=1;
  243. base:=0;
  244. end
  245. else if (hp^.left^.resulttype^.deftype=arraydef) then
  246. begin
  247. len:=parraydef(hp^.left^.resulttype)^.elesize;
  248. base:=parraydef(hp^.left^.resulttype)^.lowrange;
  249. end
  250. else
  251. Message(cg_e_illegal_expression);
  252. if is_constintnode(hp^.right) then
  253. inc(offset,len*(get_ordinal_value(hp^.right)-base))
  254. else
  255. Message(cg_e_illegal_expression);
  256. {internalerror(9779);}
  257. end;
  258. subscriptn : inc(offset,hp^.vs^.address)
  259. else
  260. Message(cg_e_illegal_expression);
  261. end;
  262. hp:=hp^.left;
  263. end;
  264. if hp^.symtableentry^.typ=constsym then
  265. Message(type_e_variable_id_expected);
  266. curconstsegment^.concat(new(pai_const_symbol,initname_offset(hp^.symtableentry^.mangledname,offset)));
  267. (*if token=POINT then
  268. begin
  269. offset:=0;
  270. while token=_POINT do
  271. begin
  272. consume(_POINT);
  273. lsym:=pvarsym(precdef(
  274. ppointerdef(p^.resulttype)^.definition)^.symtable^.search(pattern));
  275. if assigned(sym) then
  276. offset:=offset+lsym^.address
  277. else
  278. begin
  279. Message1(sym_e_illegal_field,pattern);
  280. end;
  281. consume(_ID);
  282. end;
  283. curconstsegment^.concat(new(pai_const_symbol_offset,init(
  284. strpnew(p^.left^.symtableentry^.mangledname),offset)));
  285. end
  286. else
  287. begin
  288. curconstsegment^.concat(new(pai_const,init_symbol(
  289. strpnew(p^.left^.symtableentry^.mangledname))));
  290. end; *)
  291. end
  292. else
  293. Message(cg_e_illegal_expression);
  294. end
  295. else
  296. { allow typeof(Object type)}
  297. if (p^.treetype=inlinen) and
  298. (p^.inlinenumber=in_typeof_x) then
  299. begin
  300. if (p^.left^.treetype=typen) then
  301. begin
  302. curconstsegment^.concat(new(pai_const_symbol,
  303. initname(pobjectdef(p^.left^.resulttype)^.vmt_mangledname)));
  304. end
  305. else
  306. Message(cg_e_illegal_expression);
  307. end
  308. else
  309. Message(cg_e_illegal_expression);
  310. disposetree(p);
  311. end;
  312. setdef:
  313. begin
  314. p:=comp_expr(true);
  315. do_firstpass(p);
  316. if p^.treetype=setconstn then
  317. begin
  318. { we only allow const sets }
  319. if assigned(p^.left) then
  320. Message(cg_e_illegal_expression)
  321. else
  322. begin
  323. {$ifdef i386}
  324. for l:=0 to def^.size-1 do
  325. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[l])));
  326. {$endif}
  327. {$ifdef m68k}
  328. j:=0;
  329. for l:=0 to ((def^.size-1) div 4) do
  330. { HORRIBLE HACK because of endian }
  331. { now use intel endian for constant sets }
  332. begin
  333. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+3])));
  334. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+2])));
  335. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+1])));
  336. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j])));
  337. Inc(j,4);
  338. end;
  339. {$endif}
  340. end;
  341. end
  342. else
  343. Message(cg_e_illegal_expression);
  344. disposetree(p);
  345. end;
  346. enumdef:
  347. begin
  348. p:=comp_expr(true);
  349. do_firstpass(p);
  350. if p^.treetype=ordconstn then
  351. begin
  352. if is_equal(p^.resulttype,def) then
  353. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)))
  354. else
  355. Message(cg_e_illegal_expression);
  356. end
  357. else
  358. Message(cg_e_illegal_expression);
  359. disposetree(p);
  360. end;
  361. stringdef:
  362. begin
  363. p:=comp_expr(true);
  364. do_firstpass(p);
  365. { first take care of prefixes for long and ansi strings }
  366. case pstringdef(def)^.string_typ of
  367. st_shortstring:
  368. begin
  369. if p^.treetype=stringconstn then
  370. begin
  371. if p^.length>=def^.size then
  372. strlength:=def^.size-1
  373. else
  374. strlength:=p^.length;
  375. curconstsegment^.concat(new(pai_const,init_8bit(strlength)));
  376. { this can also handle longer strings }
  377. getmem(ca,strlength+1);
  378. move(p^.value_str^,ca^,strlength);
  379. ca[strlength]:=#0;
  380. curconstsegment^.concat(new(pai_string,init_length_pchar(ca,strlength)));
  381. end
  382. else if is_constcharnode(p) then
  383. begin
  384. curconstsegment^.concat(new(pai_string,init(#1+char(byte(p^.value)))));
  385. strlength:=1;
  386. end
  387. else Message(cg_e_illegal_expression);
  388. if def^.size>strlength then
  389. begin
  390. getmem(ca,def^.size-strlength);
  391. { def^.size contains also the leading length, so we }
  392. { we have to subtract one }
  393. fillchar(ca[0],def^.size-strlength-1,' ');
  394. ca[def^.size-strlength-1]:=#0;
  395. { this can also handle longer strings }
  396. curconstsegment^.concat(new(pai_string,init_length_pchar(ca,def^.size-strlength-1)));
  397. end;
  398. end;
  399. {$ifdef UseLongString}
  400. st_longstring:
  401. begin
  402. if is_constcharnode(p) then
  403. strlength:=1
  404. else
  405. strlength:=p^.length;
  406. { first write the maximum size }
  407. curconstsegment^.concat(new(pai_const,init_32bit(strlength)))));
  408. { fill byte }
  409. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  410. if p^.treetype=stringconstn then
  411. begin
  412. getmem(ca,strlength+1);
  413. move(p^.value_str^,ca^,strlength);
  414. ca[strlength]:=#0;
  415. generate_pascii(consts,ca,strlength);
  416. end
  417. else if is_constcharnode(p) then
  418. begin
  419. consts^.concat(new(pai_const,init_8bit(p^.value)));
  420. end
  421. else Message(cg_e_illegal_expression);
  422. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  423. end;
  424. {$endif UseLongString}
  425. st_ansistring:
  426. begin
  427. { an empty ansi string is nil! }
  428. if (p^.treetype=stringconstn) and (p^.length=0) then
  429. curconstsegment^.concat(new(pai_const,init_32bit(0)))
  430. else
  431. begin
  432. if is_constcharnode(p) then
  433. strlength:=1
  434. else
  435. strlength:=p^.length;
  436. getdatalabel(ll);
  437. curconstsegment^.concat(new(pai_const_symbol,init(ll)));
  438. { first write the maximum size }
  439. consts^.concat(new(pai_const,init_32bit(strlength)));
  440. { second write the real length }
  441. consts^.concat(new(pai_const,init_32bit(strlength)));
  442. { redondent with maxlength but who knows ... (PM) }
  443. { third write use count (set to -1 for safety ) }
  444. consts^.concat(new(pai_const,init_32bit(-1)));
  445. consts^.concat(new(pai_label,init(ll)));
  446. if p^.treetype=stringconstn then
  447. begin
  448. getmem(ca,strlength+1);
  449. move(p^.value_str^,ca^,strlength);
  450. ca[strlength]:=#0;
  451. consts^.concat(new(pai_string,init_length_pchar(ca,strlength)));
  452. end
  453. else if is_constcharnode(p) then
  454. begin
  455. consts^.concat(new(pai_const,init_8bit(p^.value)));
  456. end
  457. else Message(cg_e_illegal_expression);
  458. consts^.concat(new(pai_const,init_8bit(0)));
  459. end;
  460. end;
  461. end;
  462. disposetree(p);
  463. end;
  464. arraydef:
  465. begin
  466. if token=_LKLAMMER then
  467. begin
  468. consume(_LKLAMMER);
  469. for l:=parraydef(def)^.lowrange to parraydef(def)^.highrange-1 do
  470. begin
  471. readtypedconst(parraydef(def)^.definition,nil,no_change_allowed);
  472. consume(_COMMA);
  473. end;
  474. readtypedconst(parraydef(def)^.definition,nil,no_change_allowed);
  475. consume(_RKLAMMER);
  476. end
  477. else
  478. { if array of char then we allow also a string }
  479. if is_char(parraydef(def)^.definition) then
  480. begin
  481. p:=comp_expr(true);
  482. do_firstpass(p);
  483. if p^.treetype=stringconstn then
  484. begin
  485. if p^.length>255 then
  486. len:=255
  487. else
  488. len:=p^.length;
  489. {$ifndef TP}
  490. {$ifopt H+}
  491. setlength(s,len);
  492. {$else}
  493. s[0]:=chr(len);
  494. {$endif}
  495. {$else}
  496. s[0]:=chr(len);
  497. {$endif}
  498. move(p^.value_str^,s[1],len);
  499. end
  500. else
  501. if is_constcharnode(p) then
  502. s:=char(byte(p^.value))
  503. else
  504. begin
  505. Message(cg_e_illegal_expression);
  506. s:='';
  507. end;
  508. disposetree(p);
  509. l:=length(s);
  510. for i:=Parraydef(def)^.lowrange to Parraydef(def)^.highrange do
  511. begin
  512. if i+1-Parraydef(def)^.lowrange<=l then
  513. begin
  514. curconstsegment^.concat(new(pai_const,init_8bit(byte(s[1]))));
  515. delete(s,1,1);
  516. end
  517. else
  518. {Fill the remaining positions with #0.}
  519. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  520. end;
  521. if length(s)>0 then
  522. Message(parser_e_string_larger_array);
  523. end
  524. else
  525. begin
  526. { we want the ( }
  527. consume(_LKLAMMER);
  528. end;
  529. end;
  530. procvardef:
  531. begin
  532. { Procvars and pointers are no longer compatible. }
  533. { under tp: =nil or =var under fpc: =nil or =@var }
  534. if token=_NIL then
  535. begin
  536. curconstsegment^.concat(new(pai_const,init_32bit(0)));
  537. consume(_NIL);
  538. exit;
  539. end
  540. else
  541. if not(m_tp_procvar in aktmodeswitches) then
  542. if token=_KLAMMERAFFE then
  543. consume(_KLAMMERAFFE);
  544. getsym(pattern,true);
  545. consume(_ID);
  546. if srsym^.typ=unitsym then
  547. begin
  548. consume(_POINT);
  549. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  550. consume(_ID);
  551. end;
  552. if srsym^.typ<>procsym then
  553. Message(cg_e_illegal_expression)
  554. else
  555. begin
  556. pd:=pprocsym(srsym)^.definition;
  557. if assigned(pd^.nextoverloaded) then
  558. Message(parser_e_no_overloaded_procvars);
  559. if not proc_to_procvar_equal(pd,pprocvardef(def)) then
  560. Message2(type_e_incompatible_types,pd^.typename,pprocvardef(def)^.typename);
  561. curconstsegment^.concat(new(pai_const_symbol,initname(pd^.mangledname)));
  562. end;
  563. end;
  564. { reads a typed constant record }
  565. recorddef:
  566. begin
  567. consume(_LKLAMMER);
  568. aktpos:=0;
  569. while token<>_RKLAMMER do
  570. begin
  571. s:=pattern;
  572. consume(_ID);
  573. consume(_COLON);
  574. srsym:=precorddef(def)^.symtable^.search(s);
  575. if srsym=nil then
  576. begin
  577. Message1(sym_e_id_not_found,s);
  578. consume_all_until(_SEMICOLON);
  579. end
  580. else
  581. begin
  582. { check position }
  583. if pvarsym(srsym)^.address<aktpos then
  584. Message(parser_e_invalid_record_const);
  585. { if needed fill }
  586. if pvarsym(srsym)^.address>aktpos then
  587. for i:=1 to pvarsym(srsym)^.address-aktpos do
  588. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  589. { new position }
  590. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  591. { read the data }
  592. readtypedconst(pvarsym(srsym)^.definition,nil,no_change_allowed);
  593. if token=_SEMICOLON then
  594. consume(_SEMICOLON)
  595. else break;
  596. end;
  597. end;
  598. for i:=1 to def^.size-aktpos do
  599. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  600. consume(_RKLAMMER);
  601. end;
  602. { reads a typed object }
  603. objectdef:
  604. begin
  605. if ([oo_has_vmt,oo_is_class]*pobjectdef(def)^.objectoptions)<>[] then
  606. begin
  607. Message(parser_e_type_const_not_possible);
  608. consume_all_until(_RKLAMMER);
  609. end
  610. else
  611. begin
  612. consume(_LKLAMMER);
  613. aktpos:=0;
  614. while token<>_RKLAMMER do
  615. begin
  616. s:=pattern;
  617. consume(_ID);
  618. consume(_COLON);
  619. srsym:=nil;
  620. obj:=pobjectdef(def);
  621. symt:=obj^.symtable;
  622. while (srsym=nil) and assigned(symt) do
  623. begin
  624. srsym:=symt^.search(s);
  625. if assigned(obj) then
  626. obj:=obj^.childof;
  627. if assigned(obj) then
  628. symt:=obj^.symtable
  629. else
  630. symt:=nil;
  631. end;
  632. if srsym=nil then
  633. begin
  634. Message1(sym_e_id_not_found,s);
  635. consume_all_until(_SEMICOLON);
  636. end
  637. else
  638. begin
  639. { check position }
  640. if pvarsym(srsym)^.address<aktpos then
  641. Message(parser_e_invalid_record_const);
  642. { if needed fill }
  643. if pvarsym(srsym)^.address>aktpos then
  644. for i:=1 to pvarsym(srsym)^.address-aktpos do
  645. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  646. { new position }
  647. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  648. { read the data }
  649. readtypedconst(pvarsym(srsym)^.definition,nil,no_change_allowed);
  650. if token=_SEMICOLON then
  651. consume(_SEMICOLON)
  652. else break;
  653. end;
  654. end;
  655. for i:=1 to def^.size-aktpos do
  656. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  657. consume(_RKLAMMER);
  658. end;
  659. end;
  660. errordef:
  661. begin
  662. { try to consume something useful }
  663. if token=_LKLAMMER then
  664. consume_all_until(_RKLAMMER)
  665. else
  666. consume_all_until(_SEMICOLON);
  667. end;
  668. else Message(parser_e_type_const_not_possible);
  669. end;
  670. end;
  671. end.
  672. {
  673. $Log$
  674. Revision 1.52 1999-08-10 12:30:02 pierre
  675. * avoid unused locals
  676. Revision 1.51 1999/08/04 13:03:02 jonas
  677. * all tokens now start with an underscore
  678. * PowerPC compiles!!
  679. Revision 1.50 1999/08/04 00:23:21 florian
  680. * renamed i386asm and i386base to cpuasm and cpubase
  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. }