From c29455b111c78456c3bf5d06322faed5d7ce704a Mon Sep 17 00:00:00 2001 From: florian <florian@freepascal.org> Date: Tue, 17 Apr 2007 20:34:58 +0000 Subject: [PATCH] * handle rtti for sets with a size of 1 and 2 properly, resolves #8660 git-svn-id: trunk@7125 - --- .gitattributes | 1 + compiler/ncgrtti.pas | 9 ++++++++- compiler/symdef.pas | 2 +- rtl/objpas/typinfo.pp | 3 ++- tests/webtbs/tw8660.pp | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 tests/webtbs/tw8660.pp diff --git a/.gitattributes b/.gitattributes index 048d85ba2d..8a04665fb0 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/ncgrtti.pas b/compiler/ncgrtti.pas index 337753f614..9b4b045700 100644 --- a/compiler/ncgrtti.pas +++ b/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))); diff --git a/compiler/symdef.pas b/compiler/symdef.pas index f9da29e728..57610b0430 100644 --- a/compiler/symdef.pas +++ b/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; diff --git a/rtl/objpas/typinfo.pp b/rtl/objpas/typinfo.pp index a26a7b28d1..9135725b50 100644 --- a/rtl/objpas/typinfo.pp +++ b/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 diff --git a/tests/webtbs/tw8660.pp b/tests/webtbs/tw8660.pp new file mode 100644 index 0000000000..aff8f994a8 --- /dev/null +++ b/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. \ No newline at end of file