Keyword mapping refactoring
This commit is contained in:
@@ -653,7 +653,7 @@ begin
|
||||
end
|
||||
else
|
||||
begin
|
||||
var fieldType := TTypes.FromScalarKind(baseType.Definition.Fields[fieldIndex].Value);
|
||||
var fieldType := TTypes.FromScalarKind(baseType.Definition[fieldIndex].Value);
|
||||
if baseType.Kind = TStaticTypeKind.stRecord then
|
||||
elemType := fieldType
|
||||
else
|
||||
@@ -670,7 +670,7 @@ begin
|
||||
FLog.AddError(Format('Member "%s" not found in type %s', [Node.Member.Value.Name, baseType.ToString]), Node);
|
||||
end
|
||||
else
|
||||
elemType := genDef.Fields[fieldIndex].Value;
|
||||
elemType := genDef[fieldIndex].Value;
|
||||
end
|
||||
else
|
||||
begin
|
||||
|
||||
@@ -9,7 +9,8 @@ uses
|
||||
Myc.Data.Scalar,
|
||||
Myc.Data.Value,
|
||||
Myc.Ast.Nodes, // Provides EAstException
|
||||
Myc.Ast.Scope;
|
||||
Myc.Ast.Scope,
|
||||
Myc.Data.Keyword;
|
||||
|
||||
type
|
||||
// Exception for runtime errors during script evaluation
|
||||
@@ -74,7 +75,6 @@ uses
|
||||
System.TypInfo,
|
||||
System.Generics.Defaults,
|
||||
Myc.Ast,
|
||||
Myc.Data.Keyword,
|
||||
Myc.Data.Decimal,
|
||||
Myc.Data.Series,
|
||||
Myc.Data.Scalar.JSON,
|
||||
@@ -381,7 +381,7 @@ begin
|
||||
if def.StartsWith('[') then
|
||||
begin
|
||||
var recordDef := TRttiAstHelper.JsonToRecordDefinition(def);
|
||||
if Length(recordDef.Fields) = 0 then
|
||||
if recordDef.Count = 0 then
|
||||
raise EEvaluatorException.Create('Failed to parse record definition from JSON array.');
|
||||
var recordSeries := TScalarRecordSeries.Create(recordDef);
|
||||
Result := TDataValue.FromRecordSeries(recordSeries);
|
||||
@@ -440,12 +440,12 @@ begin
|
||||
raise EEvaluatorException
|
||||
.CreateFmt('Index %d is out of bounds for series with %d elements.', [index, recSeries.TotalCount]);
|
||||
|
||||
fieldCount := Length(recSeries.Def.Fields);
|
||||
fieldCount := recSeries.Def.Count;
|
||||
SetLength(values, fieldCount);
|
||||
|
||||
for i := 0 to fieldCount - 1 do
|
||||
begin
|
||||
key := recSeries.Def.Fields[i].Key;
|
||||
key := recSeries.Def.Items[i].Key;
|
||||
memberSeries := recSeries[key];
|
||||
scalarValue := memberSeries[index];
|
||||
values[i] := scalarValue.Value;
|
||||
@@ -477,7 +477,7 @@ begin
|
||||
if fieldIndex < 0 then
|
||||
raise EEvaluatorException.CreateFmt('Member ":%s" not found in record.', [Node.Member.Value.Name]);
|
||||
|
||||
Result := rec.Fields[fieldIndex].Value;
|
||||
Result := rec.Items[fieldIndex].Value;
|
||||
end;
|
||||
else
|
||||
raise EEvaluatorException.Create('Member access operator `.` is not supported for this value type.');
|
||||
|
||||
+22
-15
@@ -504,12 +504,12 @@ begin
|
||||
if (not Assigned(Self.FDefinition)) or (not Assigned(otherDef)) then
|
||||
exit(False);
|
||||
|
||||
if Length(Self.FDefinition.Fields) <> Length(otherDef.Fields) then
|
||||
if Self.FDefinition.Count <> otherDef.Count then
|
||||
exit(False);
|
||||
|
||||
for i := 0 to High(Self.FDefinition.Fields) do
|
||||
for i := 0 to Self.FDefinition.Count - 1 do
|
||||
begin
|
||||
if (Self.FDefinition.Fields[i].Key <> otherDef.Fields[i].Key) or (Self.FDefinition.Fields[i].Value <> otherDef.Fields[i].Value) then
|
||||
if (Self.FDefinition[i].Key <> otherDef[i].Key) or (Self.FDefinition[i].Value <> otherDef[i].Value) then
|
||||
exit(False);
|
||||
end;
|
||||
|
||||
@@ -518,13 +518,15 @@ end;
|
||||
|
||||
function TRecordType.GetHashCode: Integer;
|
||||
var
|
||||
i: Integer;
|
||||
field: TPair<IKeyword, TScalar.TKind>;
|
||||
begin
|
||||
Result := Ord(GetKind);
|
||||
if Assigned(FDefinition) then
|
||||
begin
|
||||
for field in FDefinition.Fields do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
field := FDefinition[i];
|
||||
var hash := TEqualityComparer<IKeyword>.Default.GetHashCode(field.Key);
|
||||
Result := THashBobJenkins.GetHashValue(hash, SizeOf(Pointer), Result);
|
||||
var data := Ord(field.Value);
|
||||
@@ -536,14 +538,16 @@ 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 High(FDefinition.Fields) do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
Result := Result + FDefinition.Fields[i].Key.Name + ': ' + FDefinition.Fields[i].Value.ToString;
|
||||
if i < High(FDefinition.Fields) then
|
||||
field := FDefinition[i];
|
||||
Result := Result + field.Key.Name + ': ' + field.Value.ToString;
|
||||
if i < FDefinition.Count - 1 then
|
||||
Result := Result + ', ';
|
||||
end;
|
||||
end;
|
||||
@@ -591,13 +595,12 @@ begin
|
||||
if (not Assigned(Self.FDefinition)) or (not Assigned(otherDef)) then
|
||||
exit(False);
|
||||
|
||||
if Length(Self.FDefinition.Fields) <> Length(otherDef.Fields) then
|
||||
if Self.FDefinition.Count <> otherDef.Count then
|
||||
exit(False);
|
||||
|
||||
for i := 0 to High(Self.FDefinition.Fields) do
|
||||
for i := 0 to Self.FDefinition.Count - 1 do
|
||||
begin
|
||||
if (Self.FDefinition.Fields[i].Key <> otherDef.Fields[i].Key)
|
||||
or (not Self.FDefinition.Fields[i].Value.IsEqual(otherDef.Fields[i].Value)) then
|
||||
if (Self.FDefinition[i].Key <> otherDef[i].Key) or (not Self.FDefinition[i].Value.IsEqual(otherDef[i].Value)) then
|
||||
exit(False);
|
||||
end;
|
||||
|
||||
@@ -606,13 +609,15 @@ end;
|
||||
|
||||
function TGenericRecordType.GetHashCode: Integer;
|
||||
var
|
||||
i: Integer;
|
||||
field: TPair<IKeyword, IStaticType>;
|
||||
begin
|
||||
Result := Ord(stGenericRecord);
|
||||
if Assigned(FDefinition) then
|
||||
begin
|
||||
for field in FDefinition.Fields do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
field := FDefinition[i];
|
||||
var data := TEqualityComparer<IKeyword>.Default.GetHashCode(field.Key);
|
||||
Result := THashBobJenkins.GetHashValue(data, SizeOf(Pointer), Result);
|
||||
if Assigned(field.Value) then
|
||||
@@ -627,14 +632,16 @@ 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 High(FDefinition.Fields) do
|
||||
for i := 0 to FDefinition.Count - 1 do
|
||||
begin
|
||||
Result := Result + FDefinition.Fields[i].Key.Name + ': ' + FDefinition.Fields[i].Value.ToString;
|
||||
if i < High(FDefinition.Fields) then
|
||||
field := FDefinition[i];
|
||||
Result := Result + field.Key.Name + ': ' + field.Value.ToString;
|
||||
if i < FDefinition.Count - 1 then
|
||||
Result := Result + ', ';
|
||||
end;
|
||||
end;
|
||||
|
||||
Reference in New Issue
Block a user