mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-21 14:09:16 +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/tw1133.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw11349.pp svneol=native#text/plain
|
tests/webtbs/tw11349.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw11354.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/tw1152.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw11543.pp svneol=native#text/plain
|
tests/webtbs/tw11543.pp svneol=native#text/plain
|
||||||
tests/webtbs/tw1157.pp svneol=native#text/plain
|
tests/webtbs/tw1157.pp svneol=native#text/plain
|
||||||
|
@ -65,7 +65,7 @@ unit typinfo;
|
|||||||
|
|
||||||
type
|
type
|
||||||
TTypeKinds = set of TTypeKind;
|
TTypeKinds = set of TTypeKind;
|
||||||
ShortStringBase = string[255];
|
ShortStringBase = string[255];
|
||||||
|
|
||||||
{$PACKRECORDS 1}
|
{$PACKRECORDS 1}
|
||||||
TTypeInfo = record
|
TTypeInfo = record
|
||||||
@ -146,14 +146,14 @@ unit typinfo;
|
|||||||
RawIntfUnit: ShortString;
|
RawIntfUnit: ShortString;
|
||||||
IIDStr: ShortString;
|
IIDStr: ShortString;
|
||||||
);
|
);
|
||||||
tkDynArray:
|
tkDynArray:
|
||||||
(
|
(
|
||||||
elSize : PtrUInt;
|
elSize : PtrUInt;
|
||||||
elType2 : PPTypeInfo;
|
elType2 : PPTypeInfo;
|
||||||
varType : Longint;
|
varType : Longint;
|
||||||
elType : PPTypeInfo;
|
elType : PPTypeInfo;
|
||||||
DynUnitName: ShortStringBase
|
DynUnitName: ShortStringBase
|
||||||
);
|
);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// unsed, just for completeness
|
// unsed, just for completeness
|
||||||
@ -348,16 +348,26 @@ Function GetEnumName(TypeInfo : PTypeInfo;Value : Integer) : string;
|
|||||||
PT : PTypeData;
|
PT : PTypeData;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
PT:=GetTypeData(TypeInfo);
|
PT:=GetTypeData(TypeInfo);
|
||||||
// ^.BaseType);
|
if TypeInfo^.Kind=tkBool then
|
||||||
// If PT^.MinValue<0 then Value:=Ord(Value<>0); {map to 0/1}
|
begin
|
||||||
PS:=@PT^.NameList;
|
case Value of
|
||||||
While Value>0 Do
|
0,1:
|
||||||
begin
|
Result:=BooleanIdents[Boolean(Value)];
|
||||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
else
|
||||||
Dec(Value);
|
Result:='';
|
||||||
end;
|
end;
|
||||||
Result:=PS^;
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -375,14 +385,26 @@ begin
|
|||||||
PT:=GetTypeData(TypeInfo);
|
PT:=GetTypeData(TypeInfo);
|
||||||
Count:=0;
|
Count:=0;
|
||||||
Result:=-1;
|
Result:=-1;
|
||||||
PS:=@PT^.NameList;
|
|
||||||
While (Result=-1) and (PByte(PS)^<>0) do
|
if TypeInfo^.Kind=tkBool then
|
||||||
begin
|
begin
|
||||||
If ShortCompareText(PS^, sName) = 0 then
|
If CompareText(BooleanIdents[false],Name)=0 then
|
||||||
Result:=Count;
|
result:=0
|
||||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
else if CompareText(BooleanIdents[true],Name)=0 then
|
||||||
Inc(Count);
|
result:=1;
|
||||||
end;
|
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;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -393,17 +415,22 @@ var
|
|||||||
Count: SizeInt;
|
Count: SizeInt;
|
||||||
begin
|
begin
|
||||||
PT:=GetTypeData(enum1);
|
PT:=GetTypeData(enum1);
|
||||||
Count:=0;
|
if enum1^.Kind=tkBool then
|
||||||
Result:=0;
|
Result:=2
|
||||||
|
else
|
||||||
PS:=@PT^.NameList;
|
|
||||||
While (PByte(PS)^<>0) do
|
|
||||||
begin
|
begin
|
||||||
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
Count:=0;
|
||||||
Inc(Count);
|
Result:=0;
|
||||||
end;
|
|
||||||
|
|
||||||
Result := Count;
|
PS:=@PT^.NameList;
|
||||||
|
While (PByte(PS)^<>0) do
|
||||||
|
begin
|
||||||
|
PS:=PShortString(pointer(PS)+PByte(PS)^+1);
|
||||||
|
Inc(Count);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := Count;
|
||||||
|
end;
|
||||||
end;
|
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