ptconst.pas 36 KB

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