Browse Source

* access static fields by a absolute sym pointing to the symbol for the space allocation, resolves #14124

git-svn-id: trunk@13512 -
florian 16 years ago
parent
commit
10ede51609
5 changed files with 52 additions and 7 deletions
  1. 2 0
      .gitattributes
  2. 7 1
      compiler/pdecvar.pas
  3. 8 6
      compiler/pexpr.pas
  4. 11 0
      tests/webtbs/tw14124.pp
  5. 24 0
      tests/webtbs/uw14124.pp

+ 2 - 0
.gitattributes

@@ -9215,6 +9215,7 @@ tests/webtbs/tw1407.pp svneol=native#text/plain
 tests/webtbs/tw1408.pp svneol=native#text/plain
 tests/webtbs/tw1408.pp svneol=native#text/plain
 tests/webtbs/tw1409.pp svneol=native#text/plain
 tests/webtbs/tw1409.pp svneol=native#text/plain
 tests/webtbs/tw1412.pp svneol=native#text/plain
 tests/webtbs/tw1412.pp svneol=native#text/plain
+tests/webtbs/tw14124.pp svneol=native#text/plain
 tests/webtbs/tw14134.pp svneol=native#text/plain
 tests/webtbs/tw14134.pp svneol=native#text/plain
 tests/webtbs/tw1414.pp svneol=native#text/plain
 tests/webtbs/tw1414.pp svneol=native#text/plain
 tests/webtbs/tw14143.pp svneol=native#text/plain
 tests/webtbs/tw14143.pp svneol=native#text/plain
@@ -10104,6 +10105,7 @@ tests/webtbs/uw13345b.pp svneol=native#text/plain
 tests/webtbs/uw13345c.pp svneol=native#text/plain
 tests/webtbs/uw13345c.pp svneol=native#text/plain
 tests/webtbs/uw13345y.pp svneol=native#text/plain
 tests/webtbs/uw13345y.pp svneol=native#text/plain
 tests/webtbs/uw13583.pp svneol=native#text/plain
 tests/webtbs/uw13583.pp svneol=native#text/plain
+tests/webtbs/uw14124.pp svneol=native#text/plain
 tests/webtbs/uw2004.inc svneol=native#text/plain
 tests/webtbs/uw2004.inc svneol=native#text/plain
 tests/webtbs/uw2040.pp svneol=native#text/plain
 tests/webtbs/uw2040.pp svneol=native#text/plain
 tests/webtbs/uw2266a.inc svneol=native#text/plain
 tests/webtbs/uw2266a.inc svneol=native#text/plain

+ 7 - 1
compiler/pdecvar.pas

@@ -1315,6 +1315,7 @@ implementation
          tempdef: tdef;
          tempdef: tdef;
          is_first_field: boolean;
          is_first_field: boolean;
 {$endif powerpc or powerpc64}
 {$endif powerpc or powerpc64}
+         sl       : tpropaccesslist;
       begin
       begin
          recst:=tabstractrecordsymtable(symtablestack.top);
          recst:=tabstractrecordsymtable(symtablestack.top);
 {$if defined(powerpc) or defined(powerpc64)}
 {$if defined(powerpc) or defined(powerpc64)}
@@ -1429,9 +1430,14 @@ implementation
                    begin
                    begin
                      fieldvs:=tfieldvarsym(sc[i]);
                      fieldvs:=tfieldvarsym(sc[i]);
                      include(fieldvs.symoptions,sp_static);
                      include(fieldvs.symoptions,sp_static);
-                     hstaticvs:=tstaticvarsym.create('$'+lower(symtablestack.top.name^)+'_'+fieldvs.name,vs_value,hdef,[]);
+                     { generate the symbol which reserves the space }
+                     hstaticvs:=tstaticvarsym.create('$_static_'+lower(symtablestack.top.name^)+'_'+fieldvs.name,vs_value,hdef,[]);
                      recst.defowner.owner.insert(hstaticvs);
                      recst.defowner.owner.insert(hstaticvs);
                      insertbssdata(hstaticvs);
                      insertbssdata(hstaticvs);
+                     { generate the symbol for the access }
+                     sl:=tpropaccesslist.create;
+                     sl.addsym(sl_load,hstaticvs);
+                     recst.insert(tabsolutevarsym.create_ref('$'+lower(symtablestack.top.name^)+'_'+fieldvs.name,hdef,sl));
                    end;
                    end;
                  consume(_SEMICOLON);
                  consume(_SEMICOLON);
                end;
                end;

+ 8 - 6
compiler/pexpr.pas

@@ -1200,12 +1200,14 @@ implementation
                    begin
                    begin
                       if (sp_static in sym.symoptions) then
                       if (sp_static in sym.symoptions) then
                         begin
                         begin
-                           static_name:=lower(sym.owner.name^)+'_'+sym.name;
-                           searchsym(static_name,sym,srsymtable);
-                           if assigned(sym) then
-                             check_hints(sym,sym.symoptions);
-                           p1.free;
-                           p1:=cloadnode.create(sym,srsymtable);
+                          static_name:=lower(sym.owner.name^)+'_'+sym.name;
+                          searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable);
+                          if assigned(sym) then
+                            check_hints(sym,sym.symoptions);
+                          p1.free;
+                          p1:=nil;
+                          { static syms are always stored as absolutevarsym to handle scope and storage properly }
+                          propaccesslist_to_node(p1,nil,tabsolutevarsym(sym).ref);
                         end
                         end
                       else
                       else
                         begin
                         begin

+ 11 - 0
tests/webtbs/tw14124.pp

@@ -0,0 +1,11 @@
+program project1;
+
+uses
+  uw14124;
+
+type
+
+  T = specialize TGenericType<Integer>;
+
+begin
+end.

+ 24 - 0
tests/webtbs/uw14124.pp

@@ -0,0 +1,24 @@
+unit uw14124;
+
+{$mode objfpc}{$H+}
+{$static on}
+
+interface
+
+type
+  generic TGenericType<TParamType> = class
+  var private
+    FDefault: TParamType; static;
+    F: TParamType;
+  public
+    procedure P;
+  end;
+
+implementation
+
+procedure TGenericType.P;
+begin
+  F := FDefault; // <====== unit1.pas(21,16) Fatal: Internal error 200108121
+end;
+
+end.