mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
GT-2922 cleanup per review comments
This commit is contained in:
parent
802bb8429a
commit
6d2df2281f
7 changed files with 38 additions and 30 deletions
|
@ -2839,12 +2839,9 @@ public class DataTypeMergeManager implements MergeResolver {
|
||||||
try {
|
try {
|
||||||
SwingUtilities.invokeAndWait(() -> Msg.showInfo(getClass(), null, title, msg));
|
SwingUtilities.invokeAndWait(() -> Msg.showInfo(getClass(), null, title, msg));
|
||||||
}
|
}
|
||||||
catch (InterruptedException e) {
|
catch (InterruptedException | InvocationTargetException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -41,7 +41,7 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
super(dataMgr, cache, record);
|
super(dataMgr, cache, record);
|
||||||
this.funDefAdapter = adapter;
|
this.funDefAdapter = adapter;
|
||||||
this.paramAdapter = paramAdapter;
|
this.paramAdapter = paramAdapter;
|
||||||
getParameters();
|
loadParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -54,7 +54,7 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
return record.getLongValue(FunctionDefinitionDBAdapter.FUNCTION_DEF_CAT_ID_COL);
|
return record.getLongValue(FunctionDefinitionDBAdapter.FUNCTION_DEF_CAT_ID_COL);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getParameters() {
|
private void loadParameters() {
|
||||||
parameters = new ArrayList<>();
|
parameters = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
long[] ids = paramAdapter.getParameterIdsInFunctionDef(key);
|
long[] ids = paramAdapter.getParameterIdsInFunctionDef(key);
|
||||||
|
@ -75,7 +75,7 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
Record rec = funDefAdapter.getRecord(key);
|
Record rec = funDefAdapter.getRecord(key);
|
||||||
if (rec != null) {
|
if (rec != null) {
|
||||||
record = rec;
|
record = rec;
|
||||||
getParameters();
|
loadParameters();
|
||||||
return super.refresh();
|
return super.refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -250,13 +250,13 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
parameters.clear();
|
parameters.clear();
|
||||||
for (int i = 0; i < args.length; i++) {
|
for (int i = 0; i < args.length; i++) {
|
||||||
DataType type =
|
DataType type =
|
||||||
ParameterDefinitionImpl.checkDataType(args[i].getDataType(), dataMgr, false);
|
ParameterDefinitionImpl.validateDataType(args[i].getDataType(), dataMgr, false);
|
||||||
DataType resolvedDt = resolve(type);
|
DataType resolvedDt = resolve(type);
|
||||||
paramAdapter.createRecord(dataMgr.getID(resolvedDt), key, i, args[i].getName(),
|
paramAdapter.createRecord(dataMgr.getID(resolvedDt), key, i, args[i].getName(),
|
||||||
args[i].getComment(), args[i].getLength());
|
args[i].getComment(), args[i].getLength());
|
||||||
resolvedDt.addParent(this);
|
resolvedDt.addParent(this);
|
||||||
}
|
}
|
||||||
getParameters();
|
loadParameters();
|
||||||
funDefAdapter.updateRecord(record, true); // update last change time
|
funDefAdapter.updateRecord(record, true); // update last change time
|
||||||
dataMgr.dataTypeChanged(this);
|
dataMgr.dataTypeChanged(this);
|
||||||
}
|
}
|
||||||
|
@ -270,7 +270,7 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReturnType(DataType type) {
|
public void setReturnType(DataType type) {
|
||||||
type = ParameterDefinitionImpl.checkDataType(type, dataMgr, true);
|
type = ParameterDefinitionImpl.validateDataType(type, dataMgr, true);
|
||||||
lock.acquire();
|
lock.acquire();
|
||||||
try {
|
try {
|
||||||
checkDeleted();
|
checkDeleted();
|
||||||
|
@ -396,7 +396,7 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
try {
|
try {
|
||||||
checkDeleted();
|
checkDeleted();
|
||||||
if (newDt == this) {
|
if (newDt == this) {
|
||||||
// TODO: document why this is neccessary
|
// avoid creating circular dependency
|
||||||
newDt = DataType.DEFAULT;
|
newDt = DataType.DEFAULT;
|
||||||
}
|
}
|
||||||
DataType retType = getReturnType();
|
DataType retType = getReturnType();
|
||||||
|
@ -454,7 +454,7 @@ class FunctionDefinitionDB extends DataTypeDB implements FunctionDefinition {
|
||||||
rdt.addParent(this);
|
rdt.addParent(this);
|
||||||
paramAdapter.createRecord(dataMgr.getID(rdt), key, ordinal, name, comment,
|
paramAdapter.createRecord(dataMgr.getID(rdt), key, ordinal, name, comment,
|
||||||
dt.getLength());
|
dt.getLength());
|
||||||
getParameters();
|
loadParameters();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
dataMgr.dbError(e);
|
dataMgr.dbError(e);
|
||||||
|
|
|
@ -64,7 +64,7 @@ final class ParameterDefinitionDB implements ParameterDefinition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDataType(DataType type) {
|
public void setDataType(DataType type) {
|
||||||
type = ParameterDefinitionImpl.checkDataType(type, dataMgr, false);
|
type = ParameterDefinitionImpl.validateDataType(type, dataMgr, false);
|
||||||
|
|
||||||
getDataType().removeParent(parent);
|
getDataType().removeParent(parent);
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public interface FunctionDefinition extends DataType, FunctionSignature {
|
||||||
* @param type the return datatype to be set.
|
* @param type the return datatype to be set.
|
||||||
* @throws IllegalArgumentException if data type is not a fixed length type
|
* @throws IllegalArgumentException if data type is not a fixed length type
|
||||||
*/
|
*/
|
||||||
public void setReturnType(DataType type);
|
public void setReturnType(DataType type) throws IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the function comment
|
* Set the function comment
|
||||||
|
|
|
@ -158,7 +158,7 @@ public class FunctionDefinitionDataType extends GenericDataType implements Funct
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReturnType(DataType type) {
|
public void setReturnType(DataType type) {
|
||||||
returnType = ParameterDefinitionImpl.checkDataType(type, dataMgr, true);
|
returnType = ParameterDefinitionImpl.validateDataType(type, dataMgr, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -337,7 +337,7 @@ public class FunctionDefinitionDataType extends GenericDataType implements Funct
|
||||||
public void dataTypeReplaced(DataType oldDt, DataType newDt) {
|
public void dataTypeReplaced(DataType oldDt, DataType newDt) {
|
||||||
|
|
||||||
if (newDt == this) {
|
if (newDt == this) {
|
||||||
// TODO: document why this is neccessary
|
// avoid creating circular dependency
|
||||||
newDt = DataType.DEFAULT;
|
newDt = DataType.DEFAULT;
|
||||||
}
|
}
|
||||||
DataType retType = getReturnType();
|
DataType retType = getReturnType();
|
||||||
|
|
|
@ -39,11 +39,11 @@ public interface ParameterDefinition extends Comparable<ParameterDefinition> {
|
||||||
public DataType getDataType();
|
public DataType getDataType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Data Type of this variable. The given dataType must have a fixed length.
|
* Set the Data Type of this variable.
|
||||||
* @param type the data type
|
* @param type dataType the fixed-length datatype of the parameter
|
||||||
* @throws IllegalArgumentException if data type is not a fixed length type
|
* @throws IllegalArgumentException if invalid parameter datatype specified
|
||||||
*/
|
*/
|
||||||
public void setDataType(DataType type);
|
public void setDataType(DataType type) throws IllegalArgumentException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Name of this variable.
|
* Get the Name of this variable.
|
||||||
|
@ -79,9 +79,9 @@ public interface ParameterDefinition extends Comparable<ParameterDefinition> {
|
||||||
public void setComment(String comment);
|
public void setComment(String comment);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if a variable corresponds to a parameter which is equivelent to
|
* Determine if a variable corresponds to a parameter which is equivalent to
|
||||||
* this parameter definition by both ordinal and datatype. Name is not considered
|
* this parameter definition by both ordinal and datatype. Name is not considered
|
||||||
* relavent.
|
* relevant.
|
||||||
* @param variable variable to be compared with this parameter definition.
|
* @param variable variable to be compared with this parameter definition.
|
||||||
* @return true if the specified variable represents the same parameter by ordinal
|
* @return true if the specified variable represents the same parameter by ordinal
|
||||||
* and dataType. False will always be returned if specified variable is
|
* and dataType. False will always be returned if specified variable is
|
||||||
|
@ -90,8 +90,8 @@ public interface ParameterDefinition extends Comparable<ParameterDefinition> {
|
||||||
public boolean isEquivalent(Variable variable);
|
public boolean isEquivalent(Variable variable);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if parm is equivelent to this parameter definition by both ordinal
|
* Determine if parm is equivalent to this parameter definition by both ordinal
|
||||||
* and datatype. Name is not considered relavent.
|
* and datatype. Name is not considered relevant.
|
||||||
* @param parm parameter definition to be compared with this parameter definition.
|
* @param parm parameter definition to be compared with this parameter definition.
|
||||||
* @return true if the specified parameter definition represents the same parameter
|
* @return true if the specified parameter definition represents the same parameter
|
||||||
* by ordinal and dataType.
|
* by ordinal and dataType.
|
||||||
|
|
|
@ -31,8 +31,9 @@ public class ParameterDefinitionImpl implements ParameterDefinition {
|
||||||
* Constructs a new ParameterImp with an unassigned ordinal. The ordinal will be
|
* Constructs a new ParameterImp with an unassigned ordinal. The ordinal will be
|
||||||
* established by the function definition.
|
* established by the function definition.
|
||||||
* @param name the name of the parameter.
|
* @param name the name of the parameter.
|
||||||
* @param dataType the datatype of the parameter
|
* @param dataType the fixed-length datatype of the parameter
|
||||||
* @param comment the comment to store about this parameter.
|
* @param comment the comment to store about this parameter.
|
||||||
|
* @throws IllegalArgumentException if invalid parameter datatype specified
|
||||||
*/
|
*/
|
||||||
public ParameterDefinitionImpl(String name, DataType dataType, String comment) {
|
public ParameterDefinitionImpl(String name, DataType dataType, String comment) {
|
||||||
this(name, dataType, comment, Parameter.UNASSIGNED_ORDINAL);
|
this(name, dataType, comment, Parameter.UNASSIGNED_ORDINAL);
|
||||||
|
@ -41,19 +42,29 @@ public class ParameterDefinitionImpl implements ParameterDefinition {
|
||||||
/**
|
/**
|
||||||
* Constructs a new ParameterImp
|
* Constructs a new ParameterImp
|
||||||
* @param name the name of the parameter.
|
* @param name the name of the parameter.
|
||||||
* @param dataType the datatype of the parameter
|
* @param dataType the fixed-length datatype of the parameter
|
||||||
* @param comment the comment to store about this parameter.
|
* @param comment the comment to store about this parameter.
|
||||||
* @param ordinal the index of this parameter within the function signature.
|
* @param ordinal the index of this parameter within the function signature.
|
||||||
|
* @throws IllegalArgumentException if invalid parameter datatype specified
|
||||||
*/
|
*/
|
||||||
protected ParameterDefinitionImpl(String name, DataType dataType, String comment, int ordinal) {
|
protected ParameterDefinitionImpl(String name, DataType dataType, String comment, int ordinal) {
|
||||||
this.dataType = checkDataType(dataType, null, false);
|
this.dataType = validateDataType(dataType, null, false);
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.ordinal = ordinal;
|
this.ordinal = ordinal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DataType checkDataType(DataType dataType, DataTypeManager dtMgr, boolean isReturn)
|
/**
|
||||||
throws IllegalArgumentException {
|
* Validate the specified datatype based upon its' use as a parameter or return type.
|
||||||
|
* Ensure that the datatype has been cloned to the specified datatype manager (dtMgr).
|
||||||
|
* @param dataType datatype to be validated
|
||||||
|
* @param dtMgr target datatype manager
|
||||||
|
* @param isReturn true if checking return datatype, false if parameter datatype.
|
||||||
|
* @return datatype suitable for use within the target {@link FunctionDefinition}.
|
||||||
|
* @throws IllegalArgumentException if invalid datatype specified
|
||||||
|
*/
|
||||||
|
public static DataType validateDataType(DataType dataType, DataTypeManager dtMgr,
|
||||||
|
boolean isReturn) throws IllegalArgumentException {
|
||||||
String kind = isReturn ? "Return" : "Parameter";
|
String kind = isReturn ? "Return" : "Parameter";
|
||||||
if (dataType == null) {
|
if (dataType == null) {
|
||||||
dataType = DataType.DEFAULT;
|
dataType = DataType.DEFAULT;
|
||||||
|
@ -131,7 +142,7 @@ public class ParameterDefinitionImpl implements ParameterDefinition {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDataType(DataType type) {
|
public void setDataType(DataType type) {
|
||||||
this.dataType = checkDataType(type, dataType.getDataTypeManager(), false);
|
this.dataType = validateDataType(type, dataType.getDataTypeManager(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue