Refactoring Keyword mapping, introducing tuples

This commit is contained in:
Michael Schimmel
2026-01-04 15:07:02 +01:00
parent f1733c41a0
commit 0a7a6ea2d0
13 changed files with 245 additions and 93 deletions
+10 -19
View File
@@ -646,7 +646,7 @@ begin
for i := 0 to Self.FDefinition.Count - 1 do
begin
if (Self.FDefinition[i].Key <> otherDef[i].Key) or (Self.FDefinition[i].Value <> otherDef[i].Value) then
if (Self.FDefinition.Keywords[i] <> otherDef.Keywords[i]) or (Self.FDefinition[i] <> otherDef[i]) then
exit(False);
end;
@@ -656,7 +656,6 @@ end;
function TRecordType.GetHashCode: Integer;
var
i, h: Integer;
field: TPair<IKeyword, TScalar.TKind>;
begin
// Seed with Kind
Result := THashBobJenkins.GetHashValue(FKind, SizeOf(TStaticTypeKind), 0);
@@ -665,15 +664,13 @@ begin
begin
for i := 0 to FDefinition.Count - 1 do
begin
field := FDefinition[i];
// Hash Key
// Keyword identities are unique by pointer, but let's hash their internal ID/Index for safety
h := field.Key.Idx;
h := FDefinition.Keywords[i].Idx;
Result := THashBobJenkins.GetHashValue(h, SizeOf(Integer), Result);
// Hash Field Type Kind
h := Ord(field.Value);
h := Ord(FDefinition[i]);
Result := THashBobJenkins.GetHashValue(h, SizeOf(Integer), Result);
end;
end;
@@ -682,15 +679,13 @@ end;
function TRecordType.ToString: string;
var
i: Integer;
field: TPair<IKeyword, TScalar.TKind>;
begin
Result := GetKind.ToString + '{';
if Assigned(FDefinition) then
begin
for i := 0 to FDefinition.Count - 1 do
begin
field := FDefinition[i];
Result := Result + field.Key.Name + ': ' + field.Value.ToString;
Result := Result + FDefinition.Keywords[i].Name + ': ' + FDefinition[i].ToString;
if i < FDefinition.Count - 1 then
Result := Result + ', ';
end;
@@ -746,7 +741,7 @@ begin
for i := 0 to Self.FDefinition.Count - 1 do
begin
// Deep Check of Field Types
if (Self.FDefinition[i].Key <> otherDef[i].Key) or (not Self.FDefinition[i].Value.IsEqual(otherDef[i].Value)) then
if (Self.FDefinition.Keywords[i] <> otherDef.Keywords[i]) or (not Self.FDefinition[i].IsEqual(otherDef[i])) then
exit(False);
end;
@@ -756,7 +751,6 @@ end;
function TGenericRecordType.GetHashCode: Integer;
var
i, h: Integer;
field: TPair<IKeyword, IStaticType>;
begin
h := Ord(stGenericRecord);
Result := THashBobJenkins.GetHashValue(h, SizeOf(TStaticTypeKind), 0);
@@ -765,16 +759,15 @@ begin
begin
for i := 0 to FDefinition.Count - 1 do
begin
field := FDefinition[i];
// Hash Key (using Idx)
h := field.Key.Idx;
h := FDefinition.Keywords[i].Idx;
Result := THashBobJenkins.GetHashValue(h, SizeOf(Integer), Result);
// Hash Value Type
if Assigned(field.Value) then
var val := FDefinition[i];
if Assigned(val) then
begin
h := field.Value.GetHashCode;
h := val.GetHashCode;
Result := THashBobJenkins.GetHashValue(h, SizeOf(Integer), Result);
end;
end;
@@ -784,15 +777,13 @@ end;
function TGenericRecordType.ToString: string;
var
i: Integer;
field: TPair<IKeyword, IStaticType>;
begin
Result := GetKind.ToString + '{';
if Assigned(FDefinition) then
begin
for i := 0 to FDefinition.Count - 1 do
begin
field := FDefinition[i];
Result := Result + field.Key.Name + ': ' + field.Value.ToString;
Result := Result + FDefinition.Keywords[i].Name + ': ' + FDefinition[i].ToString;
if i < FDefinition.Count - 1 then
Result := Result + ', ';
end;