ptconst.pas 35 KB

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