ptconst.pas 37 KB

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