Procházet zdrojové kódy

* pdecvar.pas, read_record_fields: don't generate BSS-data for generic static fields (doesn't fix any specific bug, but we don't need space reserved for the field)
* pgenutil.pas, generate_specialization: fix a stupid "don't iterate upwards if deleting/extracting" mistake (twice!); this fixes Mantis #21550 and Mantis #21654 (tests added)

git-svn-id: trunk@21251 -

svenbarth před 13 roky
rodič
revize
5b1b194b47

+ 2 - 0
.gitattributes

@@ -12566,12 +12566,14 @@ tests/webtbs/tw2131.pp svneol=native#text/plain
 tests/webtbs/tw21443.pp svneol=native#text/plain
 tests/webtbs/tw2145.pp svneol=native#text/plain
 tests/webtbs/tw21472.pp svneol=native#text/pascal
+tests/webtbs/tw21550.pp svneol=native#text/pascal
 tests/webtbs/tw21551.pp svneol=native#text/plain
 tests/webtbs/tw2158.pp svneol=native#text/plain
 tests/webtbs/tw2159.pp svneol=native#text/plain
 tests/webtbs/tw21592.pp svneol=native#text/pascal
 tests/webtbs/tw21593.pp svneol=native#text/pascal
 tests/webtbs/tw2163.pp svneol=native#text/plain
+tests/webtbs/tw21654.pp svneol=native#text/pascal
 tests/webtbs/tw21674.pp svneol=native#text/pascal
 tests/webtbs/tw21684.pp svneol=native#text/pascal
 tests/webtbs/tw2176.pp svneol=native#text/plain

+ 2 - 1
compiler/pdecvar.pas

@@ -1773,7 +1773,8 @@ implementation
                      fieldvs:=tfieldvarsym(sc[i]);
                      fieldvs.visibility:=visibility;
                      hstaticvs:=make_field_static(recst,fieldvs);
-                     cnodeutils.insertbssdata(hstaticvs);
+                     if not parse_generic then
+                       cnodeutils.insertbssdata(hstaticvs);
                      if vd_final in options then
                        hstaticvs.varspez:=vs_final;
                    end;

+ 2 - 2
compiler/pgenutil.pas

@@ -490,7 +490,7 @@ uses
 
             { extract all created symbols and defs from the temporary symtable
               and add them to the specializest }
-            for i:=0 to tempst.SymList.Count-1 do
+            for i:=tempst.SymList.Count-1 downto 0 do
               begin
                 item:=tempst.SymList.Items[i];
                 specializest.SymList.Add(tempst.SymList.NameOfIndex(i),item);
@@ -498,7 +498,7 @@ uses
                 tempst.SymList.Extract(item);
               end;
 
-            for i:=0 to tempst.DefList.Count-1 do
+            for i:=tempst.DefList.Count-1 downto 0 do
               begin
                 item:=tempst.DefList.Items[i];
                 specializest.DefList.Add(item);

+ 20 - 0
tests/webtbs/tw21550.pp

@@ -0,0 +1,20 @@
+program tw21550;
+
+{$mode objfpc}
+{$H+}
+
+type
+  generic TEnumMetaClassTemplate<_TEnum> = class
+  private
+    FMetaInfo:pointer;static;
+  public
+  end;
+
+  TRowRenderMethod = (
+  rrmLines
+  );
+  TRowRenderMethodMeta = specialize TEnumMetaClassTemplate<TRowRenderMethod>;
+
+begin
+end.
+

+ 33 - 0
tests/webtbs/tw21654.pp

@@ -0,0 +1,33 @@
+program test;
+
+{$mode objfpc}
+
+Type
+
+{ TMyGeneric }
+
+ Generic TMyGeneric<T> = Class
+  Private
+    bValue: Integer; Static;
+    Function GetValue: Integer;
+  Public
+    Property Value: Integer Read GetValue;
+    Constructor Create(Const aValue: Integer);
+End;
+
+{ TMyGeneric }
+
+Function TMyGeneric.GetValue: Integer;
+Begin
+  Result := bValue;
+end;
+
+Constructor TMyGeneric.Create(Const aValue: Integer);
+Begin
+  bValue := aValue;
+End;
+
+Type TMyClass = Specialize TMyGeneric<TObject>;
+
+begin
+end.