mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-4525 Updated ArrayDataType javadoc and forced use of datatype's DTM
if DTM is not specified.
This commit is contained in:
parent
880631356d
commit
319619c4fc
1 changed files with 38 additions and 16 deletions
|
@ -24,6 +24,9 @@ import ghidra.util.exception.DuplicateNameException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basic implementation of the Array interface.
|
* Basic implementation of the Array interface.
|
||||||
|
*
|
||||||
|
* NOTE: The use of {@link FactoryDataType} and {@link Dynamic}, where
|
||||||
|
* {@link Dynamic#canSpecifyLength()} is false, are not supported for array use.
|
||||||
*/
|
*/
|
||||||
public class ArrayDataType extends DataTypeImpl implements Array {
|
public class ArrayDataType extends DataTypeImpl implements Array {
|
||||||
|
|
||||||
|
@ -33,21 +36,29 @@ public class ArrayDataType extends DataTypeImpl implements Array {
|
||||||
private boolean deleted = false;
|
private boolean deleted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Array dataType.
|
* Constructs a new Array dataType for fixed-length datatypes. The specified datatype's
|
||||||
* @param dataType the dataType of the elements in the array (null is not permitted).
|
* {@link DataTypeManager} will be used for its data organization.
|
||||||
|
* @param dataType the dataType of the elements in the array ({@link FactoryDataType} and
|
||||||
|
* {@link Dynamic} data types are not permitted).
|
||||||
* @param numElements the number of elements in the array (0 is permitted).
|
* @param numElements the number of elements in the array (0 is permitted).
|
||||||
|
* @throws IllegalArgumentException if invalid datatype is specified or required valid
|
||||||
|
* {@code elementLength} required.
|
||||||
*/
|
*/
|
||||||
public ArrayDataType(DataType dataType, int numElements) {
|
public ArrayDataType(DataType dataType, int numElements) {
|
||||||
this(dataType, numElements, -1, null);
|
this(dataType, numElements, -1, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Array dataType.
|
* Constructs a new Array dataType. The specified datatype's {@link DataTypeManager} will
|
||||||
* @param dataType the dataType of the elements in the array (null is not permitted).
|
* be used for its data organization.
|
||||||
|
* @param dataType the dataType of the elements in the array. {@link FactoryDataType} and
|
||||||
|
* {@link Dynamic}, where {@link Dynamic#canSpecifyLength()} is false, are not not permitted.
|
||||||
* @param numElements the number of elements in the array (0 is permitted).
|
* @param numElements the number of elements in the array (0 is permitted).
|
||||||
* @param elementLength the length of an individual element in the array. This value
|
* @param elementLength the length of an individual element in the array. This value
|
||||||
* is only used for {@link Dynamic} dataType where {@link Dynamic#canSpecifyLength()}
|
* is only used for {@link Dynamic} dataType where {@link Dynamic#canSpecifyLength()}
|
||||||
* returns true.
|
* returns true. A -1 value can be specified for fixed-length datatypes.
|
||||||
|
* @throws IllegalArgumentException if invalid datatype is specified or required valid
|
||||||
|
* {@code elementLength} required.
|
||||||
*/
|
*/
|
||||||
public ArrayDataType(DataType dataType, int numElements, int elementLength) {
|
public ArrayDataType(DataType dataType, int numElements, int elementLength) {
|
||||||
this(dataType, numElements, elementLength, null);
|
this(dataType, numElements, elementLength, null);
|
||||||
|
@ -55,19 +66,22 @@ public class ArrayDataType extends DataTypeImpl implements Array {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new Array dataType.
|
* Constructs a new Array dataType.
|
||||||
* @param dataType the dataType of the elements in the array.
|
* @param dataType the dataType of the elements in the array. {@link FactoryDataType} and
|
||||||
|
* {@link Dynamic}, where {@link Dynamic#canSpecifyLength()} is false, are not not permitted.
|
||||||
* @param numElements the number of elements in the array (0 is permitted).
|
* @param numElements the number of elements in the array (0 is permitted).
|
||||||
* @param elementLength the length of an individual element in the array. This value
|
* @param elementLength the length of an individual element in the array. This value
|
||||||
* is only used for {@link Dynamic} dataType where {@link Dynamic#canSpecifyLength()}
|
* is only used for {@link Dynamic} dataType where {@link Dynamic#canSpecifyLength()}
|
||||||
* returns true.
|
* returns true. A -1 value can be specified for fixed-length datatypes.
|
||||||
* @param dtm datatype manager or null
|
* @param dataMgr datatype manager or null. If null, the datatype manager associated with the
|
||||||
|
* specified datatype will be used.
|
||||||
|
* @throws IllegalArgumentException if invalid datatype is specified or required valid
|
||||||
|
* {@code elementLength} required.
|
||||||
*/
|
*/
|
||||||
public ArrayDataType(DataType dataType, int numElements, int elementLength,
|
public ArrayDataType(DataType dataType, int numElements, int elementLength,
|
||||||
DataTypeManager dtm) {
|
DataTypeManager dataMgr) {
|
||||||
super(dataType.getCategoryPath(), "array", dtm);
|
super(dataType.getCategoryPath(), "array", getPreferredDataTypeManager(dataType, dataMgr));
|
||||||
if (dataType instanceof FactoryDataType) {
|
if (dataType instanceof FactoryDataType) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Factory data type not permitted");
|
||||||
"Factory data type not permitted");
|
|
||||||
}
|
}
|
||||||
if (numElements < 0) {
|
if (numElements < 0) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
@ -78,7 +92,7 @@ public class ArrayDataType extends DataTypeImpl implements Array {
|
||||||
baseDt = ((TypeDef) dataType).getBaseDataType();
|
baseDt = ((TypeDef) dataType).getBaseDataType();
|
||||||
}
|
}
|
||||||
validate(baseDt);
|
validate(baseDt);
|
||||||
dataType = dataType.clone(dtm);
|
dataType = dataType.clone(getDataTypeManager());
|
||||||
this.elementLength = -1;
|
this.elementLength = -1;
|
||||||
if (baseDt instanceof Dynamic) {
|
if (baseDt instanceof Dynamic) {
|
||||||
if (elementLength < 0) {
|
if (elementLength < 0) {
|
||||||
|
@ -97,6 +111,13 @@ public class ArrayDataType extends DataTypeImpl implements Array {
|
||||||
dataType.addParent(this);
|
dataType.addParent(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static DataTypeManager getPreferredDataTypeManager(DataType dt, DataTypeManager dtm) {
|
||||||
|
if (dtm != null) {
|
||||||
|
return dtm;
|
||||||
|
}
|
||||||
|
return dt.getDataTypeManager();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a array base datatype to ensure that it is allowed
|
* Validate a array base datatype to ensure that it is allowed
|
||||||
* @param baseDt intended base datatype for array (always pass in typedef's base type if applicable)
|
* @param baseDt intended base datatype for array (always pass in typedef's base type if applicable)
|
||||||
|
@ -114,12 +135,13 @@ public class ArrayDataType extends DataTypeImpl implements Array {
|
||||||
if (baseDt instanceof Dynamic) {
|
if (baseDt instanceof Dynamic) {
|
||||||
if (!((Dynamic) baseDt).canSpecifyLength()) {
|
if (!((Dynamic) baseDt).canSpecifyLength()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Array data-type may not be a non-sizable Dynamic data-type: " + baseDt.getName());
|
"Array data-type may not be a non-sizable Dynamic data-type: " +
|
||||||
|
baseDt.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (baseDt.getLength() < 1) { // not Dynamic
|
else if (baseDt.getLength() < 1) { // not Dynamic
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException("Data type may not report a length less than 1: " +
|
||||||
"Data type may not report a length less than 1: " + baseDt.getClass().getSimpleName());
|
baseDt.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue