ptconst.pas 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. {$ifdef newcg}
  37. cgbase,
  38. {$else}
  39. hcodegen,
  40. {$endif}
  41. hcgdata;
  42. { this procedure reads typed constants }
  43. procedure readtypedconst(def : pdef;sym : ptypedconstsym;no_change_allowed : boolean);
  44. var
  45. {$ifdef m68k}
  46. j : longint;
  47. {$endif m68k}
  48. len,base : longint;
  49. p,hp : ptree;
  50. i,l,offset,
  51. strlength : longint;
  52. curconstsegment : paasmoutput;
  53. ll : pasmlabel;
  54. s : string;
  55. ca : pchar;
  56. aktpos : longint;
  57. obj : pobjectdef;
  58. symt : psymtable;
  59. value : bestreal;
  60. procedure check_range;
  61. begin
  62. if ((p^.value>porddef(def)^.high) or
  63. (p^.value<porddef(def)^.low)) then
  64. begin
  65. if (cs_check_range in aktlocalswitches) then
  66. Message(parser_e_range_check_error)
  67. else
  68. Message(parser_w_range_check_error);
  69. end;
  70. end;
  71. (* function is_po_equal(o1,o2:longint):boolean;
  72. begin
  73. { assembler does not affect }
  74. is_po_equal:=(o1 and not(poassembler))=
  75. (o2 and not(poassembler));
  76. end; *)
  77. {$R-} {Range check creates problem with init_8bit(-1) !!}
  78. begin
  79. if no_change_allowed then
  80. curconstsegment:=consts
  81. else
  82. curconstsegment:=datasegment;
  83. case def^.deftype of
  84. orddef:
  85. begin
  86. p:=comp_expr(true);
  87. do_firstpass(p);
  88. case porddef(def)^.typ of
  89. s8bit,
  90. u8bit : begin
  91. if not is_constintnode(p) then
  92. { is't an int expected }
  93. Message(cg_e_illegal_expression)
  94. else
  95. begin
  96. curconstsegment^.concat(new(pai_const,init_8bit(p^.value)));
  97. check_range;
  98. end;
  99. end;
  100. s32bit : begin
  101. if not is_constintnode(p) then
  102. Message(cg_e_illegal_expression)
  103. else
  104. begin
  105. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)));
  106. check_range;
  107. end;
  108. end;
  109. u32bit : begin
  110. if not is_constintnode(p) then
  111. Message(cg_e_illegal_expression)
  112. else
  113. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)));
  114. end;
  115. bool8bit : begin
  116. if not is_constboolnode(p) then
  117. Message(cg_e_illegal_expression);
  118. curconstsegment^.concat(new(pai_const,init_8bit(p^.value)));
  119. end;
  120. bool16bit : begin
  121. if not is_constboolnode(p) then
  122. Message(cg_e_illegal_expression);
  123. curconstsegment^.concat(new(pai_const,init_16bit(p^.value)));
  124. end;
  125. bool32bit : begin
  126. if not is_constboolnode(p) then
  127. Message(cg_e_illegal_expression);
  128. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)));
  129. end;
  130. uchar : begin
  131. if not is_constcharnode(p) then
  132. Message(cg_e_illegal_expression);
  133. curconstsegment^.concat(new(pai_const,init_8bit(p^.value)));
  134. end;
  135. u16bit,
  136. s16bit : begin
  137. if not is_constintnode(p) then
  138. Message(cg_e_illegal_expression);
  139. curconstsegment^.concat(new(pai_const,init_16bit(p^.value)));
  140. check_range;
  141. end;
  142. s64bit,
  143. u64bit:
  144. begin
  145. if not is_constintnode(p) then
  146. Message(cg_e_illegal_expression)
  147. else
  148. begin
  149. {!!!!! hmmm, we can write yet only consts til 2^32-1 :( (FK) }
  150. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)));
  151. curconstsegment^.concat(new(pai_const,init_32bit(0)));
  152. end;
  153. end;
  154. else
  155. internalerror(3799);
  156. end;
  157. disposetree(p);
  158. end;
  159. floatdef:
  160. begin
  161. p:=comp_expr(true);
  162. do_firstpass(p);
  163. if is_constrealnode(p) then
  164. value:=p^.value_real
  165. else if is_constintnode(p) then
  166. value:=p^.value
  167. else
  168. Message(cg_e_illegal_expression);
  169. case pfloatdef(def)^.typ of
  170. s32real : curconstsegment^.concat(new(pai_real_32bit,init(value)));
  171. s64real : curconstsegment^.concat(new(pai_real_64bit,init(value)));
  172. s80real : curconstsegment^.concat(new(pai_real_80bit,init(value)));
  173. s64comp : curconstsegment^.concat(new(pai_comp_64bit,init(value)));
  174. f32bit : curconstsegment^.concat(new(pai_const,init_32bit(trunc(value*65536))));
  175. else internalerror(18);
  176. end;
  177. disposetree(p);
  178. end;
  179. pointerdef:
  180. begin
  181. p:=comp_expr(true);
  182. do_firstpass(p);
  183. if (p^.treetype=typeconvn) and
  184. ((p^.left^.treetype=addrn) or (p^.left^.treetype=niln)) and
  185. is_equal(def,p^.resulttype) then
  186. begin
  187. hp:=p^.left;
  188. putnode(p);
  189. p:=hp;
  190. end;
  191. { allows horrible ofs(typeof(TButton)^) code !! }
  192. if (p^.treetype=addrn) and (p^.left^.treetype=derefn) then
  193. begin
  194. hp:=p^.left^.left;
  195. p^.left^.left:=nil;
  196. disposetree(p);
  197. p:=hp;
  198. end;
  199. { nil pointer ? }
  200. if p^.treetype=niln then
  201. curconstsegment^.concat(new(pai_const,init_32bit(0)))
  202. { maybe pchar ? }
  203. else
  204. if (ppointerdef(def)^.definition^.deftype=orddef) and
  205. (porddef(ppointerdef(def)^.definition)^.typ=uchar) and
  206. (p^.treetype<>addrn) then
  207. begin
  208. getdatalabel(ll);
  209. curconstsegment^.concat(new(pai_const_symbol,init(ll)));
  210. consts^.concat(new(pai_label,init(ll)));
  211. if p^.treetype=stringconstn then
  212. begin
  213. getmem(ca,p^.length+2);
  214. move(p^.value_str^,ca^,p^.length+1);
  215. consts^.concat(new(pai_string,init_length_pchar(ca,p^.length+1)));
  216. end
  217. else
  218. if is_constcharnode(p) then
  219. consts^.concat(new(pai_string,init(char(byte(p^.value))+#0)))
  220. else
  221. Message(cg_e_illegal_expression);
  222. end
  223. else
  224. if p^.treetype=addrn then
  225. begin
  226. hp:=p^.left;
  227. while assigned(hp) and (hp^.treetype in [subscriptn,vecn]) do
  228. hp:=hp^.left;
  229. if (is_equal(ppointerdef(p^.resulttype)^.definition,ppointerdef(def)^.definition) or
  230. (is_equal(ppointerdef(p^.resulttype)^.definition,voiddef)) or
  231. (is_equal(ppointerdef(def)^.definition,voiddef))) and
  232. (hp^.treetype=loadn) then
  233. begin
  234. do_firstpass(p^.left);
  235. hp:=p^.left;
  236. offset:=0;
  237. while assigned(hp) and (hp^.treetype<>loadn) do
  238. begin
  239. case hp^.treetype of
  240. vecn :
  241. begin
  242. if (hp^.left^.resulttype^.deftype=stringdef) then
  243. begin
  244. { this seems OK for shortstring and ansistrings PM }
  245. { it is wrong for widestrings !! }
  246. len:=1;
  247. base:=0;
  248. end
  249. else if (hp^.left^.resulttype^.deftype=arraydef) then
  250. begin
  251. len:=parraydef(hp^.left^.resulttype)^.elesize;
  252. base:=parraydef(hp^.left^.resulttype)^.lowrange;
  253. end
  254. else
  255. Message(cg_e_illegal_expression);
  256. if is_constintnode(hp^.right) then
  257. inc(offset,len*(get_ordinal_value(hp^.right)-base))
  258. else
  259. Message(cg_e_illegal_expression);
  260. {internalerror(9779);}
  261. end;
  262. subscriptn : inc(offset,hp^.vs^.address)
  263. else
  264. Message(cg_e_illegal_expression);
  265. end;
  266. hp:=hp^.left;
  267. end;
  268. if hp^.symtableentry^.typ=constsym then
  269. Message(type_e_variable_id_expected);
  270. curconstsegment^.concat(new(pai_const_symbol,initname_offset(hp^.symtableentry^.mangledname,offset)));
  271. (*if token=POINT then
  272. begin
  273. offset:=0;
  274. while token=_POINT do
  275. begin
  276. consume(_POINT);
  277. lsym:=pvarsym(precdef(
  278. ppointerdef(p^.resulttype)^.definition)^.symtable^.search(pattern));
  279. if assigned(sym) then
  280. offset:=offset+lsym^.address
  281. else
  282. begin
  283. Message1(sym_e_illegal_field,pattern);
  284. end;
  285. consume(_ID);
  286. end;
  287. curconstsegment^.concat(new(pai_const_symbol_offset,init(
  288. strpnew(p^.left^.symtableentry^.mangledname),offset)));
  289. end
  290. else
  291. begin
  292. curconstsegment^.concat(new(pai_const,init_symbol(
  293. strpnew(p^.left^.symtableentry^.mangledname))));
  294. end; *)
  295. end
  296. else
  297. Message(cg_e_illegal_expression);
  298. end
  299. else
  300. { allow typeof(Object type)}
  301. if (p^.treetype=inlinen) and
  302. (p^.inlinenumber=in_typeof_x) then
  303. begin
  304. if (p^.left^.treetype=typen) then
  305. begin
  306. curconstsegment^.concat(new(pai_const_symbol,
  307. initname(pobjectdef(p^.left^.resulttype)^.vmt_mangledname)));
  308. end
  309. else
  310. Message(cg_e_illegal_expression);
  311. end
  312. else
  313. Message(cg_e_illegal_expression);
  314. disposetree(p);
  315. end;
  316. setdef:
  317. begin
  318. p:=comp_expr(true);
  319. do_firstpass(p);
  320. if p^.treetype=setconstn then
  321. begin
  322. { we only allow const sets }
  323. if assigned(p^.left) then
  324. Message(cg_e_illegal_expression)
  325. else
  326. begin
  327. {$ifdef i386}
  328. for l:=0 to def^.size-1 do
  329. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[l])));
  330. {$endif}
  331. {$ifdef m68k}
  332. j:=0;
  333. for l:=0 to ((def^.size-1) div 4) do
  334. { HORRIBLE HACK because of endian }
  335. { now use intel endian for constant sets }
  336. begin
  337. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+3])));
  338. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+2])));
  339. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j+1])));
  340. curconstsegment^.concat(new(pai_const,init_8bit(p^.value_set^[j])));
  341. Inc(j,4);
  342. end;
  343. {$endif}
  344. end;
  345. end
  346. else
  347. Message(cg_e_illegal_expression);
  348. disposetree(p);
  349. end;
  350. enumdef:
  351. begin
  352. p:=comp_expr(true);
  353. do_firstpass(p);
  354. if p^.treetype=ordconstn then
  355. begin
  356. if is_equal(p^.resulttype,def) then
  357. curconstsegment^.concat(new(pai_const,init_32bit(p^.value)))
  358. else
  359. Message(cg_e_illegal_expression);
  360. end
  361. else
  362. Message(cg_e_illegal_expression);
  363. disposetree(p);
  364. end;
  365. stringdef:
  366. begin
  367. p:=comp_expr(true);
  368. do_firstpass(p);
  369. { first take care of prefixes for long and ansi strings }
  370. case pstringdef(def)^.string_typ of
  371. st_shortstring:
  372. begin
  373. if p^.treetype=stringconstn then
  374. begin
  375. if p^.length>=def^.size then
  376. strlength:=def^.size-1
  377. else
  378. strlength:=p^.length;
  379. curconstsegment^.concat(new(pai_const,init_8bit(strlength)));
  380. { this can also handle longer strings }
  381. getmem(ca,strlength+1);
  382. move(p^.value_str^,ca^,strlength);
  383. ca[strlength]:=#0;
  384. curconstsegment^.concat(new(pai_string,init_length_pchar(ca,strlength)));
  385. end
  386. else if is_constcharnode(p) then
  387. begin
  388. curconstsegment^.concat(new(pai_string,init(#1+char(byte(p^.value)))));
  389. strlength:=1;
  390. end
  391. else Message(cg_e_illegal_expression);
  392. if def^.size>strlength then
  393. begin
  394. getmem(ca,def^.size-strlength);
  395. { def^.size contains also the leading length, so we }
  396. { we have to subtract one }
  397. fillchar(ca[0],def^.size-strlength-1,' ');
  398. ca[def^.size-strlength-1]:=#0;
  399. { this can also handle longer strings }
  400. curconstsegment^.concat(new(pai_string,init_length_pchar(ca,def^.size-strlength-1)));
  401. end;
  402. end;
  403. {$ifdef UseLongString}
  404. st_longstring:
  405. begin
  406. if is_constcharnode(p) then
  407. strlength:=1
  408. else
  409. strlength:=p^.length;
  410. { first write the maximum size }
  411. curconstsegment^.concat(new(pai_const,init_32bit(strlength)))));
  412. { fill byte }
  413. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  414. if p^.treetype=stringconstn then
  415. begin
  416. getmem(ca,strlength+1);
  417. move(p^.value_str^,ca^,strlength);
  418. ca[strlength]:=#0;
  419. generate_pascii(consts,ca,strlength);
  420. end
  421. else if is_constcharnode(p) then
  422. begin
  423. consts^.concat(new(pai_const,init_8bit(p^.value)));
  424. end
  425. else Message(cg_e_illegal_expression);
  426. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  427. end;
  428. {$endif UseLongString}
  429. st_ansistring:
  430. begin
  431. { an empty ansi string is nil! }
  432. if (p^.treetype=stringconstn) and (p^.length=0) then
  433. curconstsegment^.concat(new(pai_const,init_32bit(0)))
  434. else
  435. begin
  436. if is_constcharnode(p) then
  437. strlength:=1
  438. else
  439. strlength:=p^.length;
  440. getdatalabel(ll);
  441. curconstsegment^.concat(new(pai_const_symbol,init(ll)));
  442. { first write the maximum size }
  443. consts^.concat(new(pai_const,init_32bit(strlength)));
  444. { second write the real length }
  445. consts^.concat(new(pai_const,init_32bit(strlength)));
  446. { redondent with maxlength but who knows ... (PM) }
  447. { third write use count (set to -1 for safety ) }
  448. consts^.concat(new(pai_const,init_32bit(-1)));
  449. consts^.concat(new(pai_label,init(ll)));
  450. if p^.treetype=stringconstn then
  451. begin
  452. getmem(ca,strlength+1);
  453. move(p^.value_str^,ca^,strlength);
  454. ca[strlength]:=#0;
  455. consts^.concat(new(pai_string,init_length_pchar(ca,strlength)));
  456. end
  457. else if is_constcharnode(p) then
  458. begin
  459. consts^.concat(new(pai_const,init_8bit(p^.value)));
  460. end
  461. else Message(cg_e_illegal_expression);
  462. consts^.concat(new(pai_const,init_8bit(0)));
  463. end;
  464. end;
  465. end;
  466. disposetree(p);
  467. end;
  468. arraydef:
  469. begin
  470. if token=_LKLAMMER then
  471. begin
  472. consume(_LKLAMMER);
  473. for l:=parraydef(def)^.lowrange to parraydef(def)^.highrange-1 do
  474. begin
  475. readtypedconst(parraydef(def)^.definition,nil,no_change_allowed);
  476. consume(_COMMA);
  477. end;
  478. readtypedconst(parraydef(def)^.definition,nil,no_change_allowed);
  479. consume(_RKLAMMER);
  480. end
  481. else
  482. { if array of char then we allow also a string }
  483. if is_char(parraydef(def)^.definition) then
  484. begin
  485. p:=comp_expr(true);
  486. do_firstpass(p);
  487. if p^.treetype=stringconstn then
  488. begin
  489. if p^.length>255 then
  490. len:=255
  491. else
  492. len:=p^.length;
  493. {$ifndef TP}
  494. {$ifopt H+}
  495. setlength(s,len);
  496. {$else}
  497. s[0]:=chr(len);
  498. {$endif}
  499. {$else}
  500. s[0]:=chr(len);
  501. {$endif}
  502. move(p^.value_str^,s[1],len);
  503. end
  504. else
  505. if is_constcharnode(p) then
  506. s:=char(byte(p^.value))
  507. else
  508. begin
  509. Message(cg_e_illegal_expression);
  510. s:='';
  511. end;
  512. disposetree(p);
  513. l:=length(s);
  514. for i:=Parraydef(def)^.lowrange to Parraydef(def)^.highrange do
  515. begin
  516. if i+1-Parraydef(def)^.lowrange<=l then
  517. begin
  518. curconstsegment^.concat(new(pai_const,init_8bit(byte(s[1]))));
  519. delete(s,1,1);
  520. end
  521. else
  522. {Fill the remaining positions with #0.}
  523. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  524. end;
  525. if length(s)>0 then
  526. Message(parser_e_string_larger_array);
  527. end
  528. else
  529. begin
  530. { we want the ( }
  531. consume(_LKLAMMER);
  532. end;
  533. end;
  534. procvardef:
  535. begin
  536. { Procvars and pointers are no longer compatible. }
  537. { under tp: =nil or =var under fpc: =nil or =@var }
  538. if token=_NIL then
  539. begin
  540. curconstsegment^.concat(new(pai_const,init_32bit(0)));
  541. consume(_NIL);
  542. exit;
  543. end
  544. else
  545. if not(m_tp_procvar in aktmodeswitches) then
  546. if token=_KLAMMERAFFE then
  547. consume(_KLAMMERAFFE);
  548. getprocvar:=true;
  549. getprocvardef:=pprocvardef(def);
  550. p:=comp_expr(true);
  551. getprocvar:=false;
  552. do_firstpass(p);
  553. if codegenerror then
  554. begin
  555. disposetree(p);
  556. exit;
  557. end;
  558. { convert calln to loadn }
  559. if p^.treetype=calln then
  560. begin
  561. if (p^.symtableprocentry^.owner^.symtabletype=objectsymtable) and
  562. (pobjectdef(p^.symtableprocentry^.owner^.defowner)^.is_class) then
  563. hp:=genloadmethodcallnode(pprocsym(p^.symtableprocentry),p^.symtableproc,
  564. getcopy(p^.methodpointer))
  565. else
  566. hp:=genloadcallnode(pprocsym(p^.symtableprocentry),p^.symtableproc);
  567. disposetree(p);
  568. do_firstpass(hp);
  569. p:=hp;
  570. if codegenerror then
  571. begin
  572. disposetree(p);
  573. exit;
  574. end;
  575. end;
  576. { let type conversion check everything needed }
  577. p:=gentypeconvnode(p,def);
  578. do_firstpass(p);
  579. if codegenerror then
  580. begin
  581. disposetree(p);
  582. exit;
  583. end;
  584. { remove typeconvn, that will normally insert a lea
  585. instruction which is not necessary for us }
  586. if p^.treetype=typeconvn then
  587. begin
  588. hp:=p^.left;
  589. putnode(p);
  590. p:=hp;
  591. end;
  592. { remove addrn which we also don't need here }
  593. if p^.treetype=addrn then
  594. begin
  595. hp:=p^.left;
  596. putnode(p);
  597. p:=hp;
  598. end;
  599. { we now need to have a loadn with a procsym }
  600. if (p^.treetype=loadn) and
  601. (p^.symtableentry^.typ=procsym) then
  602. begin
  603. curconstsegment^.concat(new(pai_const_symbol,
  604. initname(pprocsym(p^.symtableentry)^.definition^.mangledname)));
  605. end
  606. else
  607. Message(cg_e_illegal_expression);
  608. end;
  609. { reads a typed constant record }
  610. recorddef:
  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:=precorddef(def)^.symtable^.search(s);
  620. if srsym=nil then
  621. begin
  622. Message1(sym_e_id_not_found,s);
  623. consume_all_until(_SEMICOLON);
  624. end
  625. else
  626. begin
  627. { check position }
  628. if pvarsym(srsym)^.address<aktpos then
  629. Message(parser_e_invalid_record_const);
  630. { if needed fill }
  631. if pvarsym(srsym)^.address>aktpos then
  632. for i:=1 to pvarsym(srsym)^.address-aktpos do
  633. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  634. { new position }
  635. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  636. { read the data }
  637. readtypedconst(pvarsym(srsym)^.definition,nil,no_change_allowed);
  638. if token=_SEMICOLON then
  639. consume(_SEMICOLON)
  640. else break;
  641. end;
  642. end;
  643. for i:=1 to def^.size-aktpos do
  644. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  645. consume(_RKLAMMER);
  646. end;
  647. { reads a typed object }
  648. objectdef:
  649. begin
  650. if ([oo_has_vmt,oo_is_class]*pobjectdef(def)^.objectoptions)<>[] then
  651. begin
  652. Message(parser_e_type_const_not_possible);
  653. consume_all_until(_RKLAMMER);
  654. end
  655. else
  656. begin
  657. consume(_LKLAMMER);
  658. aktpos:=0;
  659. while token<>_RKLAMMER do
  660. begin
  661. s:=pattern;
  662. consume(_ID);
  663. consume(_COLON);
  664. srsym:=nil;
  665. obj:=pobjectdef(def);
  666. symt:=obj^.symtable;
  667. while (srsym=nil) and assigned(symt) do
  668. begin
  669. srsym:=symt^.search(s);
  670. if assigned(obj) then
  671. obj:=obj^.childof;
  672. if assigned(obj) then
  673. symt:=obj^.symtable
  674. else
  675. symt:=nil;
  676. end;
  677. if srsym=nil then
  678. begin
  679. Message1(sym_e_id_not_found,s);
  680. consume_all_until(_SEMICOLON);
  681. end
  682. else
  683. begin
  684. { check position }
  685. if pvarsym(srsym)^.address<aktpos then
  686. Message(parser_e_invalid_record_const);
  687. { if needed fill }
  688. if pvarsym(srsym)^.address>aktpos then
  689. for i:=1 to pvarsym(srsym)^.address-aktpos do
  690. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  691. { new position }
  692. aktpos:=pvarsym(srsym)^.address+pvarsym(srsym)^.definition^.size;
  693. { read the data }
  694. readtypedconst(pvarsym(srsym)^.definition,nil,no_change_allowed);
  695. if token=_SEMICOLON then
  696. consume(_SEMICOLON)
  697. else break;
  698. end;
  699. end;
  700. for i:=1 to def^.size-aktpos do
  701. curconstsegment^.concat(new(pai_const,init_8bit(0)));
  702. consume(_RKLAMMER);
  703. end;
  704. end;
  705. errordef:
  706. begin
  707. { try to consume something useful }
  708. if token=_LKLAMMER then
  709. consume_all_until(_RKLAMMER)
  710. else
  711. consume_all_until(_SEMICOLON);
  712. end;
  713. else Message(parser_e_type_const_not_possible);
  714. end;
  715. end;
  716. end.
  717. {
  718. $Log$
  719. Revision 1.55 1999-11-06 14:34:23 peter
  720. * truncated log to 20 revs
  721. Revision 1.54 1999/10/14 14:57:54 florian
  722. - removed the hcodegen use in the new cg, use cgbase instead
  723. Revision 1.53 1999/09/26 21:30:20 peter
  724. + constant pointer support which can happend with typecasting like
  725. const p=pointer(1)
  726. * better procvar parsing in typed consts
  727. Revision 1.52 1999/08/10 12:30:02 pierre
  728. * avoid unused locals
  729. Revision 1.51 1999/08/04 13:03:02 jonas
  730. * all tokens now start with an underscore
  731. * PowerPC compiles!!
  732. Revision 1.50 1999/08/04 00:23:21 florian
  733. * renamed i386asm and i386base to cpuasm and cpubase
  734. Revision 1.49 1999/08/03 22:03:08 peter
  735. * moved bitmask constants to sets
  736. * some other type/const renamings
  737. Revision 1.48 1999/07/23 16:05:26 peter
  738. * alignment is now saved in the symtable
  739. * C alignment added for records
  740. * PPU version increased to solve .12 <-> .13 probs
  741. Revision 1.47 1999/07/03 14:14:28 florian
  742. + start of val(int64/qword)
  743. * longbool, wordbool constants weren't written, fixed
  744. Revision 1.46 1999/05/27 19:44:54 peter
  745. * removed oldasm
  746. * plabel -> pasmlabel
  747. * -a switches to source writing automaticly
  748. * assembler readers OOPed
  749. * asmsymbol automaticly external
  750. * jumptables and other label fixes for asm readers
  751. Revision 1.45 1999/05/23 18:42:13 florian
  752. * better error recovering in typed constants
  753. * some problems with arrays of const fixed, some problems
  754. due my previous
  755. - the location type of array constructor is now LOC_MEM
  756. - the pushing of high fixed
  757. - parameter copying fixed
  758. - zero temp. allocation removed
  759. * small problem in the assembler writers fixed:
  760. ref to nil wasn't written correctly
  761. Revision 1.44 1999/05/21 13:55:11 peter
  762. * NEWLAB for label as symbol
  763. Revision 1.43 1999/05/12 00:19:54 peter
  764. * removed R_DEFAULT_SEG
  765. * uniform float names
  766. Revision 1.42 1999/05/06 09:05:24 peter
  767. * generic write_float and str_float
  768. * fixed constant float conversions
  769. Revision 1.41 1999/05/01 13:24:39 peter
  770. * merged nasm compiler
  771. * old asm moved to oldasm/
  772. Revision 1.40 1999/04/25 22:42:17 pierre
  773. + code for initialized vars in Delphi mode
  774. Revision 1.39 1999/03/24 23:17:21 peter
  775. * fixed bugs 212,222,225,227,229,231,233
  776. Revision 1.38 1999/02/25 21:02:45 peter
  777. * ag386bin updates
  778. + coff writer
  779. Revision 1.37 1999/02/22 02:44:13 peter
  780. * ag386bin doesn't use i386.pas anymore
  781. Revision 1.36 1999/02/17 10:15:26 peter
  782. * fixed error messages when parsing typed const array
  783. Revision 1.35 1999/01/20 14:09:28 pierre
  784. * fix to bug0191
  785. }