Quellcode durchsuchen

* handle rtti for sets with a size of 1 and 2 properly, resolves #8660

git-svn-id: trunk@7125 -
florian vor 18 Jahren
Ursprung
Commit
c29455b111
5 geänderte Dateien mit 46 neuen und 3 gelöschten Zeilen
  1. 1 0
      .gitattributes
  2. 8 1
      compiler/ncgrtti.pas
  3. 1 1
      compiler/symdef.pas
  4. 2 1
      rtl/objpas/typinfo.pp
  5. 34 0
      tests/webtbs/tw8660.pp

+ 1 - 0
.gitattributes

@@ -8153,6 +8153,7 @@ tests/webtbs/tw8513.pp svneol=native#text/plain
 tests/webtbs/tw8525.pp svneol=native#text/plain
 tests/webtbs/tw8573.pp svneol=native#text/plain
 tests/webtbs/tw8615.pp svneol=native#text/plain
+tests/webtbs/tw8660.pp svneol=native#text/plain
 tests/webtbs/tw8664.pp svneol=native#text/plain
 tests/webtbs/ub1873.pp svneol=native#text/plain
 tests/webtbs/ub1883.pp svneol=native#text/plain

+ 8 - 1
compiler/ncgrtti.pas

@@ -506,7 +506,14 @@ implementation
            write_rtti_name(def);
            if (tf_requires_proper_alignment in target_info.flags) then
              current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
-           current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
+           case def.size of
+             1:
+               current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUByte));
+             2:
+               current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otUWord));
+             4:
+               current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_8bit(otULong));
+           end;
            if (tf_requires_proper_alignment in target_info.flags) then
              current_asmdata.asmlists[al_rtti].concat(cai_align.Create(sizeof(TConstPtrUInt)));
            current_asmdata.asmlists[al_rtti].concat(Tai_const.Create_sym(ref_rtti(def.elementdef,rt)));

+ 1 - 1
compiler/symdef.pas

@@ -2094,7 +2094,7 @@ implementation
 
     function tsetdef.is_publishable : boolean;
       begin
-         is_publishable:=(settype=smallset);
+         is_publishable:=savesize in [1,2,4];
       end;
 
 

+ 2 - 1
rtl/objpas/typinfo.pp

@@ -84,7 +84,7 @@ unit typinfo;
          case TTypeKind of
             tkUnKnown,tkLString,tkWString,tkAString,tkVariant:
               ();
-            tkInteger,tkChar,tkEnumeration,tkWChar:
+            tkInteger,tkChar,tkEnumeration,tkWChar,tkSet:
               (OrdType : TOrdType;
                case TTypeKind of
                   tkInteger,tkChar,tkEnumeration,tkBool,tkWChar : (
@@ -754,6 +754,7 @@ begin
       DataSize:=1;
     tkWChar:
       DataSize:=2;
+    tkSet,
     tkEnumeration,
     tkInteger:
       begin

+ 34 - 0
tests/webtbs/tw8660.pp

@@ -0,0 +1,34 @@
+program TestGetSetProp;
+{$APPTYPE CONSOLE}{$PACKSET 1}
+
+uses TypInfo;
+
+{$M+}
+type
+  TEnum = (ckNormal, ckBusiness, ckVip, ckCorporate);
+  TSet = set of TEnum;
+  TClient = class
+  private
+    _Num: byte; // Works if Integer
+    _St: TSet;
+  published
+    property Num: byte read _Num write _Num; // Works if Integer
+    property St: TSet read _St write _St;
+  end;
+
+var
+  C : TClient;
+  V : TSet;
+begin
+  C := TClient.Create;
+  C.Num := 2;
+  C.St := [ckVip, ckNormal]; // the numeric representation is 5
+  V := C.St;
+  writeln(sizeof(V), ' ', byte(V)); // It's OK
+  writeln(sizeof(C.St), ' ', byte(C.St)); // It's OK
+  if GetOrdProp(C, 'St')<>5 then
+    halt(1);
+  if GetSetProp(C, 'St')<>'ckNormal,ckVip' then
+    halt(1);
+  writeln('ok');
+end.