mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-04-23 08:29:35 +02:00
* handle booleans correctly in Typinfo.GetEnum*, resolves #11372
git-svn-id: trunk@11284 -
This commit is contained in:
parent
048c7224b0
commit
67e811db60
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -8351,6 +8351,7 @@ tests/webtbs/tw1132.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1133.pp svneol=native#text/plain
|
||||
tests/webtbs/tw11349.pp svneol=native#text/plain
|
||||
tests/webtbs/tw11354.pp svneol=native#text/plain
|
||||
tests/webtbs/tw11372.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1152.pp svneol=native#text/plain
|
||||
tests/webtbs/tw11543.pp svneol=native#text/plain
|
||||
tests/webtbs/tw1157.pp svneol=native#text/plain
|
||||
|
@ -65,7 +65,7 @@ unit typinfo;
|
||||
|
||||
type
|
||||
TTypeKinds = set of TTypeKind;
|
||||
ShortStringBase = string[255];
|
||||
ShortStringBase = string[255];
|
||||
|
||||
{$PACKRECORDS 1}
|
||||
TTypeInfo = record
|
||||
@ -146,14 +146,14 @@ unit typinfo;
|
||||
RawIntfUnit: ShortString;
|
||||
IIDStr: ShortString;
|
||||
);
|
||||
tkDynArray:
|
||||
(
|
||||
elSize : PtrUInt;
|
||||
elType2 : PPTypeInfo;
|
||||
varType : Longint;
|
||||
elType : PPTypeInfo;
|
||||
DynUnitName: ShortStringBase
|
||||
);
|
||||
tkDynArray:
|
||||
(
|
||||
elSize : PtrUInt;
|
||||
elType2 : PPTypeInfo;
|
||||
varType : Longint;
|
||||
elType : PPTypeInfo;
|
||||
DynUnitName: ShortStringBase
|
||||
);
|
||||
end;
|
||||
|
||||
// unsed, just for completeness
|
||||
@ -348,16 +348,26 @@ Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
|
||||
PT : PTypeData;
|
||||
|
||||
begin
|
||||
PT:=GetTypeData(TypeInfo);
|
||||
// ^.BaseType);
|
||||
// If PT^.MinValue<0 then Value:=Ord(Value<>0); {map to 0/1}
|
||||
PS:=@PT^.NameList;
|
||||
While Value>0 Do
|
||||
begin
|
||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||
Dec(Value);
|
||||
end;
|
||||
Result:=PS^;
|
||||
PT:=GetTypeData(TypeInfo);
|
||||
if TypeInfo^.Kind=tkBool then
|
||||
begin
|
||||
case Value of
|
||||
0,1:
|
||||
Result:=BooleanIdents[Boolean(Value)];
|
||||
else
|
||||
Result:='';
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
PS:=@PT^.NameList;
|
||||
While Value>0 Do
|
||||
begin
|
||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||
Dec(Value);
|
||||
end;
|
||||
Result:=PS^;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -375,14 +385,26 @@ begin
|
||||
PT:=GetTypeData(TypeInfo);
|
||||
Count:=0;
|
||||
Result:=-1;
|
||||
PS:=@PT^.NameList;
|
||||
While (Result=-1) and (PByte(PS)^<>0) do
|
||||
|
||||
if TypeInfo^.Kind=tkBool then
|
||||
begin
|
||||
If ShortCompareText(PS^, sName) = 0 then
|
||||
Result:=Count;
|
||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||
Inc(Count);
|
||||
end;
|
||||
If CompareText(BooleanIdents[false],Name)=0 then
|
||||
result:=0
|
||||
else if CompareText(BooleanIdents[true],Name)=0 then
|
||||
result:=1;
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
||||
PS:=@PT^.NameList;
|
||||
While (Result=-1) and (PByte(PS)^<>0) do
|
||||
begin
|
||||
If ShortCompareText(PS^, sName) = 0 then
|
||||
Result:=Count;
|
||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||
Inc(Count);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
@ -393,17 +415,22 @@ var
|
||||
Count: SizeInt;
|
||||
begin
|
||||
PT:=GetTypeData(enum1);
|
||||
Count:=0;
|
||||
Result:=0;
|
||||
|
||||
PS:=@PT^.NameList;
|
||||
While (PByte(PS)^<>0) do
|
||||
if enum1^.Kind=tkBool then
|
||||
Result:=2
|
||||
else
|
||||
begin
|
||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||
Inc(Count);
|
||||
Count:=0;
|
||||
Result:=0;
|
||||
|
||||
PS:=@PT^.NameList;
|
||||
While (PByte(PS)^<>0) do
|
||||
begin
|
||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||
Inc(Count);
|
||||
end;
|
||||
|
||||
Result := Count;
|
||||
end;
|
||||
|
||||
Result := Count;
|
||||
end;
|
||||
|
||||
|
||||
|
46
tests/webtbs/tw11372.pp
Normal file
46
tests/webtbs/tw11372.pp
Normal file
@ -0,0 +1,46 @@
|
||||
program BoolAsEnumTest_FPC;
|
||||
|
||||
{$MODE Delphi}
|
||||
|
||||
{$APPTYPE CONSOLE}
|
||||
|
||||
uses
|
||||
SysUtils,
|
||||
TypInfo;
|
||||
|
||||
procedure Test_GetEnumName;
|
||||
begin
|
||||
writeln('Testing GetEnumName');
|
||||
if TypInfo.GetEnumName(TypeInfo(Boolean),Ord(False))<>'False' then
|
||||
halt(1);
|
||||
if TypInfo.GetEnumName(TypeInfo(Boolean),Ord(True))<>'True' then
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
|
||||
procedure Test_GetEnumValue;
|
||||
begin
|
||||
writeln('Testing GetEnumValue');
|
||||
if TypInfo.GetEnumValue(TypeInfo(Boolean),'false')<>0 then
|
||||
halt(1);
|
||||
if TypInfo.GetEnumValue(TypeInfo(Boolean),'true')<>1 then
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
|
||||
procedure Test_GetEnumCount;
|
||||
begin
|
||||
writeln('Testing GetEnumCount');
|
||||
if TypInfo.GetEnumNameCount(TypeInfo(Boolean))<>Ord(High(Boolean))+1 then
|
||||
halt(1);
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
begin
|
||||
Test_GetEnumCount;
|
||||
Test_GetEnumValue;
|
||||
Test_GetEnumName;
|
||||
writeln('Ok');
|
||||
end.
|
Loading…
Reference in New Issue
Block a user