From 45db87d61debb13e252056d3ee68936dc1e72ff8 Mon Sep 17 00:00:00 2001 From: Ellie Kornstaedt Date: Fri, 4 Aug 2023 17:00:30 -0700 Subject: [PATCH] Properly maintain type index when field is found in base type --- AbstractMemorySnapshot/SegmentedHeap.cs | 2 +- AbstractMemorySnapshot/TypeSystem.cs | 18 +++++++++++------- ReferenceClassifiers/BoundRuleset.cs | 3 ++- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/AbstractMemorySnapshot/SegmentedHeap.cs b/AbstractMemorySnapshot/SegmentedHeap.cs index 4b3e305..64c5ef9 100644 --- a/AbstractMemorySnapshot/SegmentedHeap.cs +++ b/AbstractMemorySnapshot/SegmentedHeap.cs @@ -168,7 +168,7 @@ public NativeWord ReadValue(MemoryView objectView, PointerInfo pointerInfo) } else { - fieldNumber = m_typeSystem.GetFieldNumber(typeIndex, fieldName); + (typeIndex, fieldNumber) = m_typeSystem.GetFieldNumber(typeIndex, fieldName); if (fieldNumber == -1) { // TODO: emit warning diff --git a/AbstractMemorySnapshot/TypeSystem.cs b/AbstractMemorySnapshot/TypeSystem.cs index 2744b31..c6b4390 100644 --- a/AbstractMemorySnapshot/TypeSystem.cs +++ b/AbstractMemorySnapshot/TypeSystem.cs @@ -188,26 +188,30 @@ public IEnumerable> 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) diff --git a/ReferenceClassifiers/BoundRuleset.cs b/ReferenceClassifiers/BoundRuleset.cs index cc8992d..cd0a6a9 100644 --- a/ReferenceClassifiers/BoundRuleset.cs +++ b/ReferenceClassifiers/BoundRuleset.cs @@ -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 @@ -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); }