Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix: Properly maintain type index when field is found in base type #37

Merged
merged 1 commit into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AbstractMemorySnapshot/SegmentedHeap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public NativeWord ReadValue(MemoryView objectView, PointerInfo<int> pointerInfo)
}
else
{
fieldNumber = m_typeSystem.GetFieldNumber(typeIndex, fieldName);
(typeIndex, fieldNumber) = m_typeSystem.GetFieldNumber(typeIndex, fieldName);
if (fieldNumber == -1)
{
// TODO: emit warning
Expand Down
18 changes: 11 additions & 7 deletions AbstractMemorySnapshot/TypeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,26 +188,30 @@ public IEnumerable<PointerInfo<int>> GetArrayElementPointerOffsets(int typeIndex
}
}

public int GetFieldNumber(int typeIndex, string fieldName)
public (int typeIndex, int fieldNumber) GetFieldNumber(int typeIndex, string fieldName)
{
if (IsArray(typeIndex))
{
return -1;
return (-1, -1);
}
else if (IsValueType(typeIndex))
{
return GetOwnFieldNumber(typeIndex, fieldName);
return (typeIndex, GetOwnFieldNumber(typeIndex, fieldName));
}

int currentTypeIndex = typeIndex;
int fieldNumber = -1;
while (currentTypeIndex != -1 && fieldNumber == -1)
do
{
fieldNumber = GetOwnFieldNumber(currentTypeIndex, fieldName);
int fieldNumber = GetOwnFieldNumber(currentTypeIndex, fieldName);
if (fieldNumber != -1)
{
return (currentTypeIndex, fieldNumber);
}
currentTypeIndex = BaseOrElementTypeIndex(currentTypeIndex);
}
while (currentTypeIndex != -1);

return fieldNumber;
return (-1, -1);
}

int GetOwnFieldNumber(int typeIndex, string fieldName)
Expand Down
3 changes: 2 additions & 1 deletion ReferenceClassifiers/BoundRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Selector BindSelector(int typeIndex, string[] fieldNames)
}
else
{
fieldNumber = m_typeSystem.GetFieldNumber(currentTypeIndex, fieldNames[i]);
(int baseTypeIndex, fieldNumber) = m_typeSystem.GetFieldNumber(currentTypeIndex, fieldNames[i]);
if (fieldNumber == -1)
{
// TODO: better warning management
Expand All @@ -164,6 +164,7 @@ Selector BindSelector(int typeIndex, string[] fieldNames)
return new Selector { StaticPrefix = fieldPath, DynamicTail = dynamicFieldNames };
}

currentTypeIndex = baseTypeIndex;
fieldTypeIndex = m_typeSystem.FieldType(currentTypeIndex, fieldNumber);
}

Expand Down