Merge remote-tracking branch

'origin/GP-3608_ryanmkurtz_pointer-to-array' (Closes #5248)
This commit is contained in:
Ryan Kurtz 2023-09-13 07:12:27 -04:00
commit 180b09041c
2 changed files with 35 additions and 0 deletions

View File

@ -531,6 +531,12 @@ public class DataTypeWriter {
name += getArrayDimensions(array);
dataType = getArrayBaseType(array);
}
else if (dataType instanceof Pointer ptr &&
getPointerBaseDataType(ptr) instanceof Array array) {
name = "(%s%s)%s".formatted("*".repeat(getPointerDepth(ptr)), name,
getArrayDimensions(array));
dataType = getArrayBaseType(array);
}
DataType baseDataType = getBaseDataType(dataType);
if (baseDataType instanceof FunctionDefinition) {

View File

@ -577,4 +577,33 @@ public class DataTypeWriterTest extends AbstractGTest {
assertEquals(expected, actual);
}
@Test
public void testArrayPointerInStructure() throws IOException, CancelledException {
DataType dt = new IntegerDataType();
Array array = new ArrayDataType(dt, 300, dt.getLength());
Pointer ptr1 = PointerDataType.getPointer(array, null);
Pointer ptr2 = PointerDataType.getPointer(ptr1, null);
Structure struct = new StructureDataType("MyStruct", 0);
struct.setDescription("this is my structure");
struct.add(ptr1, "myPtr1", "this is my array pointer");
struct.add(ptr2, "myPtr2", "this is my array pointer pointer");
dtWriter.write(struct, TaskMonitor.DUMMY);
String actual = writer.getBuffer().toString();
String expected = """
typedef struct MyStruct MyStruct, *PMyStruct;
struct MyStruct { /* this is my structure */
int (*myPtr1)[300]; /* this is my array pointer */
int (**myPtr2)[300]; /* this is my array pointer pointer */
};
""";
assertEquals(expected, actual);
}
}