compiler: fix static fields creation and access for records

+ extend test to check class constructor/destructor for records and static fields access

git-svn-id: branches/paul/extended_records@16545 -
This commit is contained in:
paul 2010-12-11 07:48:13 +00:00
parent 7852295f26
commit 52cd624a76
4 changed files with 39 additions and 22 deletions

View File

@ -1530,25 +1530,25 @@ implementation
consume(_SEMICOLON);
include(options, vd_class);
end;
if vd_class in options then
begin
{ add static flag and staticvarsyms }
for i:=0 to sc.count-1 do
begin
fieldvs:=tfieldvarsym(sc[i]);
include(fieldvs.symoptions,sp_static);
{ generate the symbol which reserves the space }
static_name:=lower(generate_nested_name(recst,'_'))+'_'+fieldvs.name;
hstaticvs:=tstaticvarsym.create('$_static_'+static_name,vs_value,hdef,[]);
include(hstaticvs.symoptions,sp_internal);
recst.get_unit_symtable.insert(hstaticvs);
insertbssdata(hstaticvs);
{ generate the symbol for the access }
sl:=tpropaccesslist.create;
sl.addsym(sl_load,hstaticvs);
recst.insert(tabsolutevarsym.create_ref('$'+static_name,hdef,sl));
end;
end;
end;
if vd_class in options then
begin
{ add static flag and staticvarsyms }
for i:=0 to sc.count-1 do
begin
fieldvs:=tfieldvarsym(sc[i]);
include(fieldvs.symoptions,sp_static);
{ generate the symbol which reserves the space }
static_name:=lower(generate_nested_name(recst,'_'))+'_'+fieldvs.name;
hstaticvs:=tstaticvarsym.create('$_static_'+static_name,vs_value,hdef,[]);
include(hstaticvs.symoptions,sp_internal);
recst.get_unit_symtable.insert(hstaticvs);
insertbssdata(hstaticvs);
{ generate the symbol for the access }
sl:=tpropaccesslist.create;
sl.addsym(sl_load,hstaticvs);
recst.insert(tabsolutevarsym.create_ref('$'+static_name,hdef,sl));
end;
end;
if (visibility=vis_published) and
not(is_class(hdef)) then

View File

@ -1241,7 +1241,10 @@ implementation
if (sp_static in sym.symoptions) then
begin
static_name:=lower(generate_nested_name(sym.owner,'_'))+'_'+sym.name;
searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable);
if sym.Owner.defowner.typ=objectdef then
searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable)
else
searchsym_in_record(trecorddef(sym.owner.defowner),static_name,sym,srsymtable);
if assigned(sym) then
check_hints(sym,sym.symoptions,sym.deprecatedmsg);
p1.free;

View File

@ -21,5 +21,7 @@ begin
halt(4);
if F.Test1(4) <> 5 then
halt(5);
if F.F5 <> 6 then
halt(6);
WriteLn('ok');
end.

View File

@ -4,7 +4,6 @@ unit terecs_u1;
{$mode delphi}
interface
type
HWND = integer;
TFoo = record
@ -20,8 +19,12 @@ type
var
F3: TBar;
F4: Byte;
class var
F5: TBar;
function Test(n: TBar): TBar;
class function Test1(n: TBar): TBar;
class constructor Create;
class destructor Destroy;
end;
implementation
@ -36,5 +39,14 @@ begin
Result := C + n;
end;
end.
class constructor TFoo.Create;
begin
F5 := 6;
end;
class destructor TFoo.Destroy;
begin
WriteLn('TFoo.Destroy');
end;
end.