GP-1361 - Updated auto comments to show user-defined repeatable comments

from the reference destination

Closes #2475
This commit is contained in:
dragonmacher 2021-10-18 17:07:45 -04:00
parent f9463e600d
commit a54d0e28d6
5 changed files with 170 additions and 90 deletions

View file

@ -855,7 +855,7 @@ public final class ReferenceUtils {
// } // }
// //
// Using the reference, we can heck for the 'Extended Markup' style reference, such as: // Using the reference, we can check for the 'Extended Markup' style reference, such as:
// instruction ...=>Foo.bar.baz // instruction ...=>Foo.bar.baz
// ------------- // -------------
// Note: these references are to labels (not sure why the reference isn't to a data // Note: these references are to labels (not sure why the reference isn't to a data

View file

@ -17,6 +17,8 @@ package ghidra.app.util;
import java.util.*; import java.util.*;
import org.apache.commons.lang3.StringUtils;
import docking.widgets.fieldpanel.support.RowColLocation; import docking.widgets.fieldpanel.support.RowColLocation;
import ghidra.program.model.address.*; import ghidra.program.model.address.*;
import ghidra.program.model.data.*; import ghidra.program.model.data.*;
@ -116,7 +118,7 @@ public class DisplayableEol {
/** /**
* Return whether the associated code unit has an end of line comment * Return whether the associated code unit has an end of line comment
* @return whether the associated code unit has an end of line comment * @return whether the associated code unit has an end of line comment
*/ */
public boolean hasEOL() { public boolean hasEOL() {
return (displayCommentArrays[MY_EOLS] != null) && return (displayCommentArrays[MY_EOLS] != null) &&
@ -144,10 +146,10 @@ public class DisplayableEol {
} }
/** /**
* Return whether this code unit has an automatic comment. For example, a memory reference * Return whether this code unit has an automatic comment. For example, a memory reference
* from this code unit has a function defined at the reference's to address, or if the to * from this code unit has a function defined at the reference's to address, or if the to
* address is a pointer. * address is a pointer.
* @return whether this code unit has an automatic comment * @return whether this code unit has an automatic comment
*/ */
public boolean hasAutomatic() { public boolean hasAutomatic() {
return (displayCommentArrays[MY_AUTOMATIC] != null) && return (displayCommentArrays[MY_AUTOMATIC] != null) &&
@ -240,7 +242,10 @@ public class DisplayableEol {
} }
} }
set.add("= " + getDataValueRepresentation(dataAccessAddress, data)); String dataRepresentation = getDataValueRepresentation(dataAccessAddress, data);
if (!StringUtils.isBlank(dataRepresentation)) {
set.add("= " + dataRepresentation);
}
} }
private String getDataValueRepresentation(Address dataAccessAddress, Data data) { private String getDataValueRepresentation(Address dataAccessAddress, Data data) {
@ -249,8 +254,7 @@ public class DisplayableEol {
} }
if (isOffcut(dataAccessAddress, data)) { if (isOffcut(dataAccessAddress, data)) {
String offcut = getOffcutDataString(dataAccessAddress, data); return getOffcutDataString(dataAccessAddress, data);
return offcut;
} }
return data.getDefaultValueRepresentation(); return data.getDefaultValueRepresentation();
@ -516,13 +520,17 @@ public class DisplayableEol {
} }
Address address = memRefs[i].getToAddress(); Address address = memRefs[i].getToAddress();
String repeatableComment = listing.getComment(CodeUnit.REPEATABLE_COMMENT, address);
if (repeatableComment != null) {
set.add(new RefRepeatComment(address, new String[] { repeatableComment }));
}
CodeUnit cu = listing.getCodeUnitAt(address); CodeUnit cu = listing.getCodeUnitAt(address);
if (cu == null) { if (cu == null) {
continue; continue;
} }
String[] comment = new String[0]; String[] comment = new String[0];
Function func = listing.getFunctionAt(address); Function func = listing.getFunctionAt(address);
if (func != null) { if (func != null) {
comment = func.getRepeatableCommentAsArray(); comment = func.getRepeatableCommentAsArray();
@ -643,6 +651,33 @@ public class DisplayableEol {
return (String[]) displayCommentArrays[MY_AUTOMATIC]; return (String[]) displayCommentArrays[MY_AUTOMATIC];
} }
@Override
public String toString() {
StringBuilder buffy = new StringBuilder();
String[] eols = (String[]) displayCommentArrays[MY_EOLS];
if (eols.length != 0) {
buffy.append("EOLs: ").append(Arrays.toString(eols));
}
String[] myRepeatables = (String[]) displayCommentArrays[MY_REPEATABLES];
if (myRepeatables.length != 0) {
buffy.append("My Repeatables: ").append(Arrays.toString(myRepeatables));
}
Object[] refRepeatables = displayCommentArrays[REF_REPEATABLES];
if (refRepeatables.length != 0) {
buffy.append("Ref Repeatables: ").append(Arrays.toString(refRepeatables));
}
String[] myAutomatic = (String[]) displayCommentArrays[MY_AUTOMATIC];
if (myAutomatic.length != 0) {
buffy.append("My Automatic: ").append(Arrays.toString(myAutomatic));
}
return buffy.toString();
}
public int getCommentLineCount(int subType) { public int getCommentLineCount(int subType) {
switch (subType) { switch (subType) {
case MY_EOLS: case MY_EOLS:

View file

@ -81,7 +81,7 @@ public class EolCommentFieldFactory extends FieldFactory {
private int refRepeatableCommentStyle; private int refRepeatableCommentStyle;
// The codeUnitFormatOptions is used to monitor "follow pointer..." option to avoid // The codeUnitFormatOptions is used to monitor "follow pointer..." option to avoid
// duplication of data within auto-comment. We don't bother adding a listener // duplication of data within auto-comment. We don't bother adding a listener
// to kick the model since this is done by the operand field. // to kick the model since this is done by the operand field.
private BrowserCodeUnitFormatOptions codeUnitFormatOptions; private BrowserCodeUnitFormatOptions codeUnitFormatOptions;
@ -310,7 +310,8 @@ public class EolCommentFieldFactory extends FieldFactory {
new DisplayableEol(cu, alwaysShowRepeatable, alwaysShowRefRepeatables, new DisplayableEol(cu, alwaysShowRepeatable, alwaysShowRefRepeatables,
alwaysShowAutomatic, codeUnitFormatOptions.followReferencedPointers(), alwaysShowAutomatic, codeUnitFormatOptions.followReferencedPointers(),
maxDisplayLines, useAbbreviatedAutomatic, showAutomaticFunctions); maxDisplayLines, useAbbreviatedAutomatic, showAutomaticFunctions);
ArrayList<FieldElement> elementList = new ArrayList<>();
List<FieldElement> elementList = new ArrayList<>();
// This Code Unit's End of Line Comment // This Code Unit's End of Line Comment
AttributedString myEolPrefixString = AttributedString myEolPrefixString =
@ -335,7 +336,6 @@ public class EolCommentFieldFactory extends FieldFactory {
if (alwaysShowRefRepeatables || elementList.isEmpty()) { if (alwaysShowRefRepeatables || elementList.isEmpty()) {
AttributedString refRepeatPrefixString = new AttributedString(SEMICOLON_PREFIX, AttributedString refRepeatPrefixString = new AttributedString(SEMICOLON_PREFIX,
refRepeatableCommentColor, getMetrics(refRepeatableCommentStyle), false, null); refRepeatableCommentColor, getMetrics(refRepeatableCommentStyle), false, null);
//int refRepeatLinesSoFar = 0;
int refRepeatCount = displayableEol.getReferencedRepeatableCommentsCount(); int refRepeatCount = displayableEol.getReferencedRepeatableCommentsCount();
for (int subTypeIndex = 0; subTypeIndex < refRepeatCount; subTypeIndex++) { for (int subTypeIndex = 0; subTypeIndex < refRepeatCount; subTypeIndex++) {
RefRepeatComment refRepeatComment = RefRepeatComment refRepeatComment =
@ -345,7 +345,6 @@ public class EolCommentFieldFactory extends FieldFactory {
refRepeatComments, program, refRepeatPrefixString, showSemicolon, isWordWrap, refRepeatComments, program, refRepeatPrefixString, showSemicolon, isWordWrap,
prependRefAddress, refRepeatComment.getAddress(), getNextRow(elementList)); prependRefAddress, refRepeatComment.getAddress(), getNextRow(elementList));
elementList.addAll(refRepeatFieldElements); elementList.addAll(refRepeatFieldElements);
//refRepeatLinesSoFar += refRepeatComments.length;
} }
} }
@ -368,7 +367,7 @@ public class EolCommentFieldFactory extends FieldFactory {
maxDisplayLines, hlProvider); maxDisplayLines, hlProvider);
} }
private int getNextRow(ArrayList<FieldElement> elementList) { private int getNextRow(List<FieldElement> elementList) {
int elementIndex = elementList.size() - 1; int elementIndex = elementList.size() - 1;
if (elementIndex >= 0) { if (elementIndex >= 0) {
FieldElement element = elementList.get(elementIndex); FieldElement element = elementList.get(elementIndex);

View file

@ -15,6 +15,7 @@
*/ */
package ghidra.app.util.viewer.field; package ghidra.app.util.viewer.field;
import static org.hamcrest.core.StringStartsWith.*;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
@ -22,21 +23,17 @@ import javax.swing.SwingUtilities;
import org.junit.*; import org.junit.*;
import docking.widgets.fieldpanel.field.FieldElement; import docking.widgets.fieldpanel.field.FieldElement;
import ghidra.app.plugin.core.blockmodel.BlockModelServicePlugin;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin; import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.plugin.core.navigation.NextPrevAddressPlugin;
import ghidra.framework.options.Options; import ghidra.framework.options.Options;
import ghidra.framework.plugintool.PluginTool;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB; import ghidra.program.database.ProgramDB;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressFactory;
import ghidra.program.model.listing.*; import ghidra.program.model.listing.*;
import ghidra.test.AbstractGhidraHeadedIntegrationTest; import ghidra.test.*;
import ghidra.test.TestEnv;
public class EolCommentFieldFactoryTest extends AbstractGhidraHeadedIntegrationTest { public class EolCommentFieldFactoryTest extends AbstractGhidraHeadedIntegrationTest {
private TestEnv env; private TestEnv env;
private PluginTool tool;
private CodeBrowserPlugin cb; private CodeBrowserPlugin cb;
private Options fieldOptions; private Options fieldOptions;
private Program program; private Program program;
@ -47,12 +44,8 @@ public class EolCommentFieldFactoryTest extends AbstractGhidraHeadedIntegrationT
program = buildProgram(); program = buildProgram();
env = new TestEnv(); env = new TestEnv();
tool = env.showTool(program); env.launchDefaultTool(program);
tool.addPlugin(CodeBrowserPlugin.class.getName());
tool.addPlugin(NextPrevAddressPlugin.class.getName());
cb = env.getPlugin(CodeBrowserPlugin.class); cb = env.getPlugin(CodeBrowserPlugin.class);
tool.addPlugin(BlockModelServicePlugin.class.getName());
fieldOptions = cb.getFormatManager().getFieldOptions(); fieldOptions = cb.getFormatManager().getFieldOptions();
} }
@ -78,15 +71,50 @@ public class EolCommentFieldFactoryTest extends AbstractGhidraHeadedIntegrationT
assertEquals(4, tf.getNumRows()); assertEquals(4, tf.getNumRows());
} }
@Test
public void testRepeatableComment_FunctionCall() throws Exception {
// check existing auto comment
ListingTextField tf = getFieldText(addr("0x010022e6"));
assertEquals(1, tf.getNumRows());
assertThat(tf.getText(), startsWith("undefined ghidra(undefined4 param_1,"));
// set repeatable comment at destination
Address destination = addr("0x01002cf5");
String repeatableComment = "My repeatable comment";
setRepeatableComment(destination, repeatableComment);
// check that the auto comment now matches the updated comment
tf = getFieldText(addr("0x010022e6"));
assertEquals(1, tf.getNumRows());
assertEquals(tf.getText(), repeatableComment);
}
@Test
public void testRepeatableComment_DataAccess() throws Exception {
// check existing auto comment
ListingTextField tf = getFieldText(addr("0x01002265"));
assertEquals(1, tf.getNumRows());
assertThat(tf.getText(), startsWith("= 01h"));
// set repeatable comment at destination
Address destination = addr("0x01002265");
String repeatableComment = "My repeatable comment";
setRepeatableComment(destination, repeatableComment);
// check that the auto comment now matches the updated comment
tf = getFieldText(addr("0x01002265"));
assertEquals(1, tf.getNumRows());
assertEquals(tf.getText(), repeatableComment);
}
//================================================================================================== //==================================================================================================
// Private Methods // Private Methods
//================================================================================================== //==================================================================================================
private ProgramDB buildProgram() throws Exception { private ProgramDB buildProgram() throws Exception {
ProgramBuilder builder = new ProgramBuilder("sample", ProgramBuilder._TOY, this); ClassicSampleX86ProgramBuilder builder = new ClassicSampleX86ProgramBuilder();
builder.createMemory(".text", "0x1001000", 0x6600);
builder.createEmptyFunction(null, "0x1002000", 20, null);
return builder.getProgram(); return builder.getProgram();
} }
@ -111,29 +139,46 @@ public class EolCommentFieldFactoryTest extends AbstractGhidraHeadedIntegrationT
private void changeFieldWidthToHalfCommentLength(Function function) throws Exception { private void changeFieldWidthToHalfCommentLength(Function function) throws Exception {
ListingTextField tf = getFieldText(function); ListingTextField tf = getFieldText(function);
FieldElement fieldElement = tf.getFieldElement(0, 0); FieldElement fieldElement = tf.getFieldElement(0, 0);
int stringWidth = fieldElement.getStringWidth(); int stringWidth = fieldElement.getStringWidth();
setFieldWidth(tf.getFieldFactory(), stringWidth / 2); setFieldWidth(tf.getFieldFactory(), stringWidth / 2);
} }
private ListingTextField getFieldText(Function function) { private ListingTextField getFieldText(Function function) {
assertTrue(cb.goToField(function.getEntryPoint(), EolCommentFieldFactory.FIELD_NAME, 1, 1)); return getFieldText(function.getEntryPoint());
}
private ListingTextField getFieldText(Address address) {
assertTrue(cb.goToField(address, EolCommentFieldFactory.FIELD_NAME, 1, 1));
ListingTextField tf = (ListingTextField) cb.getCurrentField(); ListingTextField tf = (ListingTextField) cb.getCurrentField();
return tf; return tf;
} }
private void setFieldWidth(final FieldFactory fieldFactory, final int width) throws Exception { private void setFieldWidth(final FieldFactory fieldFactory, final int width) throws Exception {
SwingUtilities.invokeAndWait(() -> fieldFactory.setWidth(width)); SwingUtilities.invokeAndWait(() -> fieldFactory.setWidth(width));
waitForPostedSwingRunnables(); waitForSwing();
cb.updateNow(); cb.updateNow();
} }
private void setBooleanOption(final String name, final boolean value) throws Exception { private void setBooleanOption(final String name, final boolean value) throws Exception {
SwingUtilities.invokeAndWait(() -> fieldOptions.setBoolean(name, value)); SwingUtilities.invokeAndWait(() -> fieldOptions.setBoolean(name, value));
waitForPostedSwingRunnables(); waitForSwing();
cb.updateNow(); cb.updateNow();
} }
private Address addr(String address) {
AddressFactory addressFactory = program.getAddressFactory();
return addressFactory.getAddress(address);
}
private void setRepeatableComment(Address a, String comment) {
setComment(a, CodeUnit.REPEATABLE_COMMENT, comment);
}
private void setComment(Address a, int commentType, String comment) {
CodeUnit cu = program.getListing().getCodeUnitAt(a);
tx(program, () -> {
cu.setComment(commentType, comment);
});
}
} }

View file

@ -38,11 +38,11 @@ public interface Composite extends DataType {
public abstract int getNumComponents(); public abstract int getNumComponents();
/** /**
* Returns the number of explicitly defined components in this composite. * Returns the number of explicitly defined components in this composite.
* For Unions and packed Structures this is equivalent to {@link #getNumComponents()} * For Unions and packed Structures this is equivalent to {@link #getNumComponents()}
* since they do not contain undefined components. * since they do not contain undefined components.
* This count will always exclude all undefined filler components which may be present * This count will always exclude all undefined filler components which may be present
* within a Structure whoose packing is disabled (see {@link #isPackingEnabled()}). * within a Structure whose packing is disabled (see {@link #isPackingEnabled()}).
* @return the number of explicitly defined components in this composite * @return the number of explicitly defined components in this composite
*/ */
public abstract int getNumDefinedComponents(); public abstract int getNumDefinedComponents();
@ -66,8 +66,8 @@ public interface Composite extends DataType {
/** /**
* Returns an array of Data Type Components that make up this composite excluding * Returns an array of Data Type Components that make up this composite excluding
* undefined filler components which may be present within Structures where packing is disabled. * undefined filler components which may be present within Structures where packing is disabled.
* The number of components corresponds to {@link #getNumDefinedComponents()}. For Unions and * The number of components corresponds to {@link #getNumDefinedComponents()}. For Unions and
* packed Structures this is equivalent to {@link #getComponents()} * packed Structures this is equivalent to {@link #getComponents()}
* since they do not contain undefined filler components. * since they do not contain undefined filler components.
* @return array all explicitly defined components * @return array all explicitly defined components
*/ */
@ -78,7 +78,7 @@ public interface Composite extends DataType {
* to use for adding components to an aligned structure for fixed-length dataTypes. * to use for adding components to an aligned structure for fixed-length dataTypes.
* @param dataType the datatype to add. * @param dataType the datatype to add.
* @return the DataTypeComponent created. * @return the DataTypeComponent created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be added to this composite data type. * allowed to be added to this composite data type.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
* to add dt1 to dt2 since this would cause a cyclic dependency. * to add dt1 to dt2 since this would cause a cyclic dependency.
@ -87,13 +87,13 @@ public interface Composite extends DataType {
/** /**
* Adds a new datatype to the end of this composite. This is the preferred method * Adds a new datatype to the end of this composite. This is the preferred method
* to use for adding components to an aligned structure for dynamic dataTypes such as * to use for adding components to an aligned structure for dynamic dataTypes such as
* strings whose length must be specified. * strings whose length must be specified.
* @param dataType the datatype to add. * @param dataType the datatype to add.
* @param length the length to associate with the datatype. * @param length the length to associate with the datatype.
* For fixed length types a length &lt;= 0 will use the length of the resolved dataType. * For fixed length types a length &lt;= 0 will use the length of the resolved dataType.
* @return the componentDataType created. * @return the componentDataType created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be added to this composite data type or an invalid length * allowed to be added to this composite data type or an invalid length
* is specified. * is specified.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
@ -108,7 +108,7 @@ public interface Composite extends DataType {
* @param name the field name to associate with this component. * @param name the field name to associate with this component.
* @param comment the comment to associate with this component. * @param comment the comment to associate with this component.
* @return the componentDataType created. * @return the componentDataType created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be added to this composite data type. * allowed to be added to this composite data type.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
* to add dt1 to dt2 since this would cause a cyclic dependency. * to add dt1 to dt2 since this would cause a cyclic dependency.
@ -117,8 +117,8 @@ public interface Composite extends DataType {
throws IllegalArgumentException; throws IllegalArgumentException;
/** /**
* Adds a new bitfield to the end of this composite. This method is intended * Adds a new bitfield to the end of this composite. This method is intended
* to be used with packed structures/unions only where the bitfield will be * to be used with packed structures/unions only where the bitfield will be
* appropriately packed. The minimum storage storage byte size will be applied. * appropriately packed. The minimum storage storage byte size will be applied.
* It will not provide useful results for composites with packing disabled. * It will not provide useful results for composites with packing disabled.
* @param baseDataType the bitfield base datatype (certain restrictions apply). * @param baseDataType the bitfield base datatype (certain restrictions apply).
@ -135,7 +135,7 @@ public interface Composite extends DataType {
/** /**
* Adds a new datatype to the end of this composite. This is the preferred method * Adds a new datatype to the end of this composite. This is the preferred method
* to use for adding components to an aligned structure for dynamic dataTypes such as * to use for adding components to an aligned structure for dynamic dataTypes such as
* strings whose length must be specified. * strings whose length must be specified.
* @param dataType the datatype to add. * @param dataType the datatype to add.
* @param length the length to associate with the datatype. * @param length the length to associate with the datatype.
@ -143,7 +143,7 @@ public interface Composite extends DataType {
* @param name the field name to associate with this component. * @param name the field name to associate with this component.
* @param comment the comment to associate with this component. * @param comment the comment to associate with this component.
* @return the componentDataType created. * @return the componentDataType created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be added to this composite data type or an invalid length is specified. * allowed to be added to this composite data type or an invalid length is specified.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
* to add dt1 to dt2 since this would cause a cyclic dependency. * to add dt1 to dt2 since this would cause a cyclic dependency.
@ -155,10 +155,10 @@ public interface Composite extends DataType {
* Inserts a new datatype at the specified ordinal position in this composite. * Inserts a new datatype at the specified ordinal position in this composite.
* <BR>Note: For an aligned structure the ordinal position will get adjusted * <BR>Note: For an aligned structure the ordinal position will get adjusted
* automatically to provide the proper alignment. * automatically to provide the proper alignment.
* @param ordinal the ordinal where the new datatype is to be inserted. * @param ordinal the ordinal where the new datatype is to be inserted.
* @param dataType the datatype to insert. * @param dataType the datatype to insert.
* @return the componentDataType created. * @return the componentDataType created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be inserted into this composite data type. * allowed to be inserted into this composite data type.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
* to insert dt1 to dt2 since this would cause a cyclic dependency. * to insert dt1 to dt2 since this would cause a cyclic dependency.
@ -171,13 +171,13 @@ public interface Composite extends DataType {
* Inserts a new datatype at the specified ordinal position in this composite. * Inserts a new datatype at the specified ordinal position in this composite.
* <BR>Note: For an aligned structure the ordinal position will get adjusted * <BR>Note: For an aligned structure the ordinal position will get adjusted
* automatically to provide the proper alignment. * automatically to provide the proper alignment.
* @param ordinal the ordinal where the new datatype is to be inserted. * @param ordinal the ordinal where the new datatype is to be inserted.
* @param dataType the datatype to insert. * @param dataType the datatype to insert.
* @param length the length to associate with the datatype. * @param length the length to associate with the datatype.
* For fixed length types a length &lt;= 0 will use the length of the resolved dataType. * For fixed length types a length &lt;= 0 will use the length of the resolved dataType.
* @return the componentDataType created. * @return the componentDataType created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be inserted into this composite data type or an invalid * allowed to be inserted into this composite data type or an invalid
* length is specified. * length is specified.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
* to insert dt1 to dt2 since this would cause a cyclic dependency. * to insert dt1 to dt2 since this would cause a cyclic dependency.
@ -190,14 +190,14 @@ public interface Composite extends DataType {
* Inserts a new datatype at the specified ordinal position in this composite. * Inserts a new datatype at the specified ordinal position in this composite.
* <BR>Note: For an aligned structure the ordinal position will get adjusted * <BR>Note: For an aligned structure the ordinal position will get adjusted
* automatically to provide the proper alignment. * automatically to provide the proper alignment.
* @param ordinal the ordinal where the new datatype is to be inserted. * @param ordinal the ordinal where the new datatype is to be inserted.
* @param dataType the datatype to insert. * @param dataType the datatype to insert.
* @param length the length to associate with the datatype. * @param length the length to associate with the datatype.
* For fixed length types a length &lt;= 0 will use the length of the resolved dataType. * For fixed length types a length &lt;= 0 will use the length of the resolved dataType.
* @param name the field name to associate with this component. * @param name the field name to associate with this component.
* @param comment the comment to associate with this component. * @param comment the comment to associate with this component.
* @return the componentDataType created. * @return the componentDataType created.
* @throws IllegalArgumentException if the specified data type is not * @throws IllegalArgumentException if the specified data type is not
* allowed to be inserted into this composite data type or an invalid length * allowed to be inserted into this composite data type or an invalid length
* is specified. * is specified.
* For example, suppose dt1 contains dt2. Therefore it is not valid * For example, suppose dt1 contains dt2. Therefore it is not valid
@ -209,7 +209,7 @@ public interface Composite extends DataType {
/** /**
* Deletes the component at the given ordinal position. * Deletes the component at the given ordinal position.
* <BR>Note: Removal of bitfields from a structure with packing disabled will * <BR>Note: Removal of bitfields from a structure with packing disabled will
* not shift other components causing vacated bytes to revert to undefined filler. * not shift other components causing vacated bytes to revert to undefined filler.
* @param ordinal the ordinal of the component to be deleted. * @param ordinal the ordinal of the component to be deleted.
* @throws IndexOutOfBoundsException if component ordinal is out of bounds * @throws IndexOutOfBoundsException if component ordinal is out of bounds
@ -218,7 +218,7 @@ public interface Composite extends DataType {
/** /**
* Deletes the specified set of components at the given ordinal positions. * Deletes the specified set of components at the given ordinal positions.
* <BR>Note: Removal of bitfields from a structure with packing disabled will * <BR>Note: Removal of bitfields from a structure with packing disabled will
* not shift other components causing vacated bytes to revert to undefined filler. * not shift other components causing vacated bytes to revert to undefined filler.
* @param ordinals the ordinals of the component to be deleted. * @param ordinals the ordinals of the component to be deleted.
* @throws IndexOutOfBoundsException if any specified component ordinal is out of bounds * @throws IndexOutOfBoundsException if any specified component ordinal is out of bounds
@ -232,7 +232,7 @@ public interface Composite extends DataType {
* <br>containing the data type directly * <br>containing the data type directly
* <br>containing another data type that has the data type as a part of it. * <br>containing another data type that has the data type as a part of it.
* @param dataType the data type to look for. * @param dataType the data type to look for.
* @return true if the indicated data type is part of a sub-component of * @return true if the indicated data type is part of a sub-component of
* this data type. * this data type.
*/ */
public abstract boolean isPartOf(DataType dataType); public abstract boolean isPartOf(DataType dataType);
@ -271,7 +271,7 @@ public interface Composite extends DataType {
} }
/** /**
* Sets whether this data type's internal components are currently packed. The * Sets whether this data type's internal components are currently packed. The
* affect of disabled packing differs between {@link Structure} and {@link Union}. When * affect of disabled packing differs between {@link Structure} and {@link Union}. When
* packing disabled: * packing disabled:
* <ul> * <ul>
@ -280,11 +280,11 @@ public interface Composite extends DataType {
* <li>Unions always place components at offset 0 and do not pad for alignment. * <li>Unions always place components at offset 0 and do not pad for alignment.
* </ul> * </ul>
* In addition, when packing is disabled the default alignment is always 1 unless a * In addition, when packing is disabled the default alignment is always 1 unless a
* different minimum alignment has been set. When packing is enabled the overall * different minimum alignment has been set. When packing is enabled the overall
* composite length infleunced by the composite's minimum alignment setting. * composite length influenced by the composite's minimum alignment setting.
* If a change in enablement occurs, the default alignment and packing behavior * If a change in enablement occurs, the default alignment and packing behavior
* will be used. * will be used.
* @param enabled true enables packing of components respecting component * @param enabled true enables packing of components respecting component
* alignment and pack setting, whereas false disables packing. * alignment and pack setting, whereas false disables packing.
*/ */
public void setPackingEnabled(boolean enabled); public void setPackingEnabled(boolean enabled);
@ -306,19 +306,19 @@ public interface Composite extends DataType {
} }
/** /**
* Gets the current packing value (typically a power of 2). * Gets the current packing value (typically a power of 2).
* If this isn't a packed composite with an explicit packing value (see {@link #hasExplicitPackingValue()}) * If this isn't a packed composite with an explicit packing value (see {@link #hasExplicitPackingValue()})
* then the return value is undefined. * then the return value is undefined.
* @return the current packing value or an undefined non-positive value * @return the current packing value or an undefined non-positive value
*/ */
public int getExplicitPackingValue(); public int getExplicitPackingValue();
/** /**
* Sets the pack value for this composite (positive value, usually a power of 2). * Sets the pack value for this composite (positive value, usually a power of 2).
* If packing was previously disabled, packing will be enabled. This value will * If packing was previously disabled, packing will be enabled. This value will
* establish the maximum effective alignment for this composite and each of the * establish the maximum effective alignment for this composite and each of the
* components during the alignment computation (e.g., a value of 1 will eliminate * components during the alignment computation (e.g., a value of 1 will eliminate
* any padding). The overall composite length may be infleunced by the composite's * any padding). The overall composite length may be influenced by the composite's
* minimum alignment setting. * minimum alignment setting.
* @param packingValue the new positive packing value. * @param packingValue the new positive packing value.
* @throws IllegalArgumentException if a non-positive value is specified. * @throws IllegalArgumentException if a non-positive value is specified.
@ -335,10 +335,10 @@ public interface Composite extends DataType {
} }
/** /**
* Enables default packing behavior. * Enables default packing behavior.
* If packing was previously disabled, packing will be enabled. * If packing was previously disabled, packing will be enabled.
* Composite will automatically pack based upon the alignment requirements * Composite will automatically pack based upon the alignment requirements
* of its components with overall composite length possibly infleunced by the composite's * of its components with overall composite length possibly influenced by the composite's
* minimum alignment setting. * minimum alignment setting.
*/ */
public void setToDefaultPacking(); public void setToDefaultPacking();
@ -358,16 +358,16 @@ public interface Composite extends DataType {
abstract AlignmentType getAlignmentType(); abstract AlignmentType getAlignmentType();
/** /**
* Whether or not this data type is using the default alignment. When Structure packing * Whether or not this data type is using the default alignment. When Structure packing
* is disabled the default alignment is always 1 (see {@link Structure#setPackingEnabled(boolean)}. * is disabled the default alignment is always 1 (see {@link Structure#setPackingEnabled(boolean)}.
* @return true if this data type is using its default alignment. * @return true if this data type is using its default alignment.
*/ */
public default boolean isDefaultAligned() { public default boolean isDefaultAligned() {
return getAlignmentType() == AlignmentType.DEFAULT; return getAlignmentType() == AlignmentType.DEFAULT;
} }
/** /**
* Whether or not this data type is using the machine alignment value, specified by * Whether or not this data type is using the machine alignment value, specified by
* {@link DataOrganization#getMachineAlignment()}, for its alignment. * {@link DataOrganization#getMachineAlignment()}, for its alignment.
* @return true if this data type is using the machine alignment as its alignment. * @return true if this data type is using the machine alignment as its alignment.
*/ */
@ -376,8 +376,9 @@ public interface Composite extends DataType {
} }
/** /**
* Determine if an explicit minimum alignment has been set (see {@link #getExplicitMinimumAlignment()}). * Determine if an explicit minimum alignment has been set (see
* An undefined value is returned if default alignment or machine alignment is enabled. * {@link #getExplicitMinimumAlignment()}). An undefined value is returned if default alignment
* or machine alignment is enabled.
* @return true if an explicit minimum alignment has been set, else false * @return true if an explicit minimum alignment has been set, else false
*/ */
public default boolean hasExplicitMinimumAlignment() { public default boolean hasExplicitMinimumAlignment() {
@ -385,20 +386,20 @@ public interface Composite extends DataType {
} }
/** /**
* Get the explicitminimum alignment setting for this Composite which contributes * Get the explicit minimum alignment setting for this Composite which contributes
* to the actual computed alignment value (see {@link #getAlignment()}. * to the actual computed alignment value (see {@link #getAlignment()}.
* @return the minimum alignment setting for this Composite or an undefined * @return the minimum alignment setting for this Composite or an undefined
* non-positive value if an explicit minimum alignment has not been set. * non-positive value if an explicit minimum alignment has not been set.
*/ */
public int getExplicitMinimumAlignment(); public int getExplicitMinimumAlignment();
/** /**
* Sets this data type's explicit minimum alignment (positive value). * Sets this data type's explicit minimum alignment (positive value).
* Together with the pack setting and component alignments will * Together with the pack setting and component alignments will
* affect the actual computed alignment of this composite. * affect the actual computed alignment of this composite.
* When packing is enabled, the alignment setting may also affect padding * When packing is enabled, the alignment setting may also affect padding
* at the end of the composite and its length. When packing is disabled, * at the end of the composite and its length. When packing is disabled,
* this setting will not affect the length of thhis composite. * this setting will not affect the length of this composite.
* @param minAlignment the minimum alignment for this Composite. * @param minAlignment the minimum alignment for this Composite.
* @throws IllegalArgumentException if a non-positive value is specified * @throws IllegalArgumentException if a non-positive value is specified
*/ */
@ -416,14 +417,14 @@ public interface Composite extends DataType {
/** /**
* Sets this data type's alignment to its default alignment. For packed * Sets this data type's alignment to its default alignment. For packed
* composites, this data type's alignment will be based upon the components it contains and * composites, this data type's alignment will be based upon the components it contains and
* its current pack settings. This is the default state and only needs to be used * its current pack settings. This is the default state and only needs to be used
* when changing from a non-default alignment type. * when changing from a non-default alignment type.
*/ */
public void setToDefaultAligned(); public void setToDefaultAligned();
/** /**
* Sets this data type's minimum alignment to the machine alignment which is * Sets this data type's minimum alignment to the machine alignment which is
* specified by {@link DataOrganization#getMachineAlignment()}. The machine alignment is * specified by {@link DataOrganization#getMachineAlignment()}. The machine alignment is
* defined as the maximum useful alignment for the target machine. * defined as the maximum useful alignment for the target machine.
*/ */
public void setToMachineAligned(); public void setToMachineAligned();