* Alexandre Montplaisir - Initial API and implementation, extend TmfEventField
* Bernd Hufmann - Add Enum field handling
* Geneviève Bastien - Add Struct and Variant field handling
+ * Jean-Christian Kouame - Correct handling of unsigned integer fields
*******************************************************************************/
package org.eclipse.linuxtools.tmf.core.ctfadaptor;
if (fieldDef instanceof IntegerDefinition) {
IntegerDefinition intDef = (IntegerDefinition) fieldDef;
int base = intDef.getDeclaration().getBase();
- field = new CTFIntegerField(fieldName, intDef.getValue(), base);
+ field = new CTFIntegerField(fieldName, intDef.getValue(), base, intDef.getDeclaration().isSigned());
} else if (fieldDef instanceof EnumDefinition) {
EnumDefinition enumDef = (EnumDefinition) fieldDef;
for (int i = 0; i < arrayDecl.getLength(); i++) {
values.add(((IntegerDefinition) arrayDef.getElem(i)).getValue());
}
- field = new CTFIntegerArrayField(fieldName, values, ((IntegerDeclaration) arrayDecl.getElementType()).getBase());
+ field = new CTFIntegerArrayField(fieldName, values, ((IntegerDeclaration) arrayDecl.getElementType()).getBase(),
+ ((IntegerDeclaration) arrayDecl.getElementType()).isSigned());
}
/* Add other types of arrays here */
for (int i = 0; i < seqDef.getLength(); i++) {
values.add(((IntegerDefinition) seqDef.getElem(i)).getValue());
}
- field = new CTFIntegerArrayField(fieldName, values, ((IntegerDeclaration) seqDecl.getElementType()).getBase());
+ field = new CTFIntegerArrayField(fieldName, values, ((IntegerDeclaration) seqDecl.getElementType()).getBase(),
+ ((IntegerDeclaration) seqDecl.getElementType()).isSigned());
}
/* Add other Sequence types here */
}
} else {
- /* Safe-guard, to avoid null exceptions later, field is expected not to be null */
+ /*
+ * Safe-guard, to avoid null exceptions later, field is expected not
+ * to be null
+ */
field = new CTFStringField(fieldName, Messages.TmfEventField_UnsupportedType + fieldDef.getClass().toString());
}
return field;
public String toString() {
return getName() + '=' + getFormattedValue();
}
-
- /**
- * Print a numeric value as a string in a given base
- *
- * @param value
- * The value to print as string
- * @param base
- * The base for this value
- * @return formatted number string
- * @since 2.0
- */
- protected final static String formatNumber(long value, int base) {
- String s;
- /* Format the number correctly according to the integer's base */
- switch (base) {
- case 2:
- s = "0b" + Long.toBinaryString(value); //$NON-NLS-1$
- break;
- case 8:
- s = "0" + Long.toOctalString(value); //$NON-NLS-1$
- break;
- case 10:
- s = Long.toString(value);
- break;
- case 16:
- s = "0x" + Long.toHexString(value); //$NON-NLS-1$
- break;
- default:
- /* Non-standard base, we'll just print it as a decimal number */
- s = Long.toString(value);
- break;
- }
- return s;
- }
-
}
/**
final class CTFIntegerField extends CtfTmfEventField {
private final int base;
+ private final boolean signed;
/**
* A CTF "IntegerDefinition" can be an integer of any byte size, so in the
* Java parser this is interpreted as a long.
*
- * @param longValue
- * The integer value of this field
* @param name
* The name of this field
+ * @param longValue
+ * The integer value of this field
+ * @param signed
+ * Is the value signed or not
*/
- CTFIntegerField(String name, long longValue, int base) {
+ CTFIntegerField(String name, long longValue, int base, boolean signed) {
super(name, longValue, null);
+ this.signed = signed;
this.base = base;
}
@Override
public String getFormattedValue() {
- return formatNumber(getValue(), base);
+ return IntegerDefinition.formatNumber(getValue(), base, signed);
}
}
final class CTFIntegerArrayField extends CtfTmfEventField {
private final int base;
+ private final boolean signed;
private String formattedValue = null;
/**
* Constructor for CTFIntegerArrayField.
*
+ * @param name
+ * The name of this field
* @param longValues
* The array of integers (as longs) that compose this field's
* value
- * @param name
- * The name of this field
+ * @param signed
+ * Are the values in the array signed or not
*/
- CTFIntegerArrayField(String name, List<Long> longValues, int base) {
+ CTFIntegerArrayField(String name, List<Long> longValues, int base, boolean signed) {
super(name, longValues, null);
this.base = base;
+ this.signed = signed;
}
@Override
if (formattedValue == null) {
List<String> strings = new ArrayList<String>();
for (Long value : getValue()) {
- strings.add(formatNumber(value, base));
+ strings.add(IntegerDefinition.formatNumber(value, base, signed));
}
formattedValue = strings.toString();
}
* Constructor for CTFEnumField.
*
* @param enumValue
- * The Enum value consisting of a pair of Enum value name and its long value
+ * The Enum value consisting of a pair of Enum value name and its
+ * long value
* @param name
* The name of this field
*/
CTFEnumField(String name, CtfEnumPair enumValue) {
super(name, new CtfEnumPair(enumValue.getFirst(),
- enumValue.getSecond().longValue()), null);
+ enumValue.getSecond().longValue()), null);
}
@Override
* The name of this field
*/
CTFVariantField(String name, CtfTmfEventField field) {
- super(name, field, new CtfTmfEventField[]{ field });
+ super(name, field, new CtfTmfEventField[] { field });
}
@Override