Prechádzať zdrojové kódy

* support static fields in nested types in records, by always including
support for nested types when generating an access to a static fied;
we also always do that when generating the mangled name of a static
field declaration in symcreat.make_field_static() (mantis #29030)

git-svn-id: trunk@32517 -

Jonas Maebe 9 rokov pred
rodič
commit
9ea38f4577
4 zmenil súbory, kde vykonal 26 pridanie a 9 odobranie
  1. 1 0
      .gitattributes
  2. 3 6
      compiler/nutils.pas
  3. 3 3
      compiler/pexpr.pas
  4. 19 0
      tests/webtbs/tw29030.pp

+ 1 - 0
.gitattributes

@@ -14875,6 +14875,7 @@ tests/webtbs/tw2899.pp svneol=native#text/plain
 tests/webtbs/tw29010a.pp svneol=native#text/plain
 tests/webtbs/tw29010b.pp svneol=native#text/plain
 tests/webtbs/tw29010c.pp svneol=native#text/plain
+tests/webtbs/tw29030.pp svneol=native#text/plain
 tests/webtbs/tw2904.pp svneol=native#text/plain
 tests/webtbs/tw29040.pp svneol=native#text/plain
 tests/webtbs/tw29053.pp svneol=native#text/pascal

+ 3 - 6
compiler/nutils.pas

@@ -104,7 +104,7 @@ interface
 
     { checks whether sym is a static field and if so, translates the access
       to the appropriate node tree }
-    function handle_staticfield_access(sym: tsym; nested: boolean; var p1: tnode): boolean;
+    function handle_staticfield_access(sym: tsym; var p1: tnode): boolean;
 
     { returns true if n is an array element access of a bitpacked array with
       elements of the which the vitsize mod 8 <> 0, or if is a field access
@@ -1181,7 +1181,7 @@ implementation
       end;
 
 
-    function handle_staticfield_access(sym: tsym; nested: boolean; var p1: tnode): boolean;
+    function handle_staticfield_access(sym: tsym; var p1: tnode): boolean;
 
       function handle_generic_staticfield_access:boolean;
         var
@@ -1228,10 +1228,7 @@ implementation
             result:=true;
             if handle_generic_staticfield_access then
               exit;
-            if not nested then
-              static_name:=lower(sym.owner.name^)+'_'+sym.name
-            else
-             static_name:=lower(generate_nested_name(sym.owner,'_'))+'_'+sym.name;
+            static_name:=lower(generate_nested_name(sym.owner,'_'))+'_'+sym.name;
             if sym.owner.defowner.typ=objectdef then
               searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable,[ssf_search_helper])
             else

+ 3 - 3
compiler/pexpr.pas

@@ -1194,7 +1194,7 @@ implementation
                      fieldvarsym :
                        begin
                          { generate access code }
-                         if not handle_staticfield_access(sym,false,p1) then
+                         if not handle_staticfield_access(sym,p1) then
                            propaccesslist_to_node(p1,st,propaccesslist);
                          include(p1.flags,nf_isproperty);
                          consume(_ASSIGNMENT);
@@ -1224,7 +1224,7 @@ implementation
                      fieldvarsym :
                        begin
                          { generate access code }
-                         if not handle_staticfield_access(sym,false,p1) then
+                         if not handle_staticfield_access(sym,p1) then
                            propaccesslist_to_node(p1,st,propaccesslist);
                          include(p1.flags,nf_isproperty);
                          { catch expressions like "(propx):=1;" }
@@ -1331,7 +1331,7 @@ implementation
                    end;
                  fieldvarsym:
                    begin
-                      if not handle_staticfield_access(sym,true,p1) then
+                      if not handle_staticfield_access(sym,p1) then
                         begin
                           if isclassref then
                             if assigned(p1) and

+ 19 - 0
tests/webtbs/tw29030.pp

@@ -0,0 +1,19 @@
+program fpc_nestedtype_ice;
+
+{$mode delphiunicode}
+
+Type
+ TRec = Record
+  Type
+   NestedType = Record
+    Class Var
+     FVar : Integer;
+    Class Property Variable : Integer Read FVar Write FVar;
+   End;
+  End;
+
+Begin
+ TRec.NestedType.Variable := 1;
+ if TRec.NestedType.Variable<>1 then
+   halt(1);
+End.