Skip to content

Commit b6481f5

Browse files
ctf: add double float support for ctf2
made in part by claude sonnet 4.5. Many bad hallucinations needed to be manually fixed. Change-Id: Ibee4b0cf144f2afa922ae968fd17d6065e18b257 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
1 parent f760a5b commit b6481f5

File tree

2 files changed

+69
-32
lines changed

2 files changed

+69
-32
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/tsdl/floatingpoint/FloatDeclarationParser.java

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
import org.eclipse.tracecompass.ctf.core.event.types.FloatDeclaration;
2323
import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
2424
import org.eclipse.tracecompass.ctf.parser.CTFParser;
25+
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.CTFJsonMetadataNode;
2526
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ICommonTreeParser;
27+
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode;
2628
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.MetadataStrings;
2729
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
2830
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.AlignmentParser;
2931
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.ByteOrderParser;
3032
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.UnaryIntegerParser;
3133
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
34+
import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings;
35+
36+
import com.google.gson.JsonObject;
3237

3338
/**
3439
*
@@ -114,49 +119,78 @@ public FloatDeclaration parse(ICTFMetadataNode floatingPoint, ICommonTreeParserP
114119
throw new IllegalArgumentException("Param must be a " + Param.class.getCanonicalName()); //$NON-NLS-1$
115120
}
116121
CTFTrace trace = ((Param) param).fTrace;
117-
List<ICTFMetadataNode> children = floatingPoint.getChildren();
118-
119-
/*
120-
* If the integer has no attributes, then it is missing the size
121-
* attribute which is required
122-
*/
123-
if (children == null) {
124-
throw new ParseException(FLOAT_MISSING_SIZE_ATTRIBUTE);
125-
}
126122

127123
/* The return value */
128124
ByteOrder byteOrder = trace.getByteOrder();
129125
long alignment = 0;
130-
131126
int exponent = DEFAULT_FLOAT_EXPONENT;
132127
int mantissa = DEFAULT_FLOAT_MANTISSA;
133128

134-
/* Iterate on all integer children */
135-
for (ICTFMetadataNode child : children) {
136-
String type = child.getType();
137-
if (CTFParser.tokenNames[CTFParser.CTF_EXPRESSION_VAL].equals(type)) {
138-
ICTFMetadataNode leftNode = child.getChild(0);
139-
ICTFMetadataNode rightNode = child.getChild(1);
140-
List<ICTFMetadataNode> leftStrings = leftNode.getChildren();
141-
if (!isAnyUnaryString(leftStrings.get(0))) {
142-
throw new ParseException(IDENTIFIER_MUST_BE_A_STRING);
129+
if (floatingPoint instanceof JsonStructureFieldMemberMetadataNode) {
130+
JsonStructureFieldMemberMetadataNode member = (JsonStructureFieldMemberMetadataNode) floatingPoint;
131+
JsonObject fieldclass = member.getFieldClass().getAsJsonObject();
132+
133+
if (fieldclass.has(JsonMetadataStrings.LENGTH)) {
134+
int size = fieldclass.get(JsonMetadataStrings.LENGTH).getAsInt();
135+
// Standard IEEE 754 sizes
136+
if (size == 32) {
137+
exponent = 8;
138+
mantissa = 24;
139+
} else if (size == 64) {
140+
exponent = 11;
141+
mantissa = 53;
142+
} else {
143+
throw new ParseException("Unsupported floating point size: " + size);
143144
}
144-
String left = concatenateUnaryStrings(leftStrings);
145-
if (left.equals(MetadataStrings.EXP_DIG)) {
146-
exponent = UnaryIntegerParser.INSTANCE.parse(rightNode.getChild(0), null).intValue();
147-
} else if (left.equals(MetadataStrings.BYTE_ORDER)) {
148-
byteOrder = ByteOrderParser.INSTANCE.parse(rightNode, new ByteOrderParser.Param(trace));
149-
} else if (left.equals(MetadataStrings.MANT_DIG)) {
150-
mantissa = UnaryIntegerParser.INSTANCE.parse(rightNode.getChild(0), null).intValue();
151-
} else if (left.equals(MetadataStrings.ALIGN)) {
152-
alignment = AlignmentParser.INSTANCE.parse(rightNode, null);
145+
}
146+
147+
if (fieldclass.has(JsonMetadataStrings.BYTE_ORDER)) {
148+
CTFJsonMetadataNode bo = new CTFJsonMetadataNode(floatingPoint, CTFParser.tokenNames[CTFParser.UNARY_EXPRESSION_STRING], fieldclass.get("byte-order").getAsString());
149+
byteOrder = ByteOrderParser.INSTANCE.parse(bo, new ByteOrderParser.Param(trace));
150+
}
151+
152+
if (fieldclass.has(JsonMetadataStrings.ALIGNMENT)) {
153+
alignment = fieldclass.get(JsonMetadataStrings.ALIGNMENT).getAsInt();
154+
}
155+
} else {
156+
List<ICTFMetadataNode> children = floatingPoint.getChildren();
157+
158+
/*
159+
* If the integer has no attributes, then it is missing the size
160+
* attribute which is required
161+
*/
162+
if (children == null) {
163+
throw new ParseException(FLOAT_MISSING_SIZE_ATTRIBUTE);
164+
}
165+
166+
/* Iterate on all integer children */
167+
for (ICTFMetadataNode child : children) {
168+
String type = child.getType();
169+
if (CTFParser.tokenNames[CTFParser.CTF_EXPRESSION_VAL].equals(type)) {
170+
ICTFMetadataNode leftNode = child.getChild(0);
171+
ICTFMetadataNode rightNode = child.getChild(1);
172+
List<ICTFMetadataNode> leftStrings = leftNode.getChildren();
173+
if (!isAnyUnaryString(leftStrings.get(0))) {
174+
throw new ParseException(IDENTIFIER_MUST_BE_A_STRING);
175+
}
176+
String left = concatenateUnaryStrings(leftStrings);
177+
if (left.equals(MetadataStrings.EXP_DIG)) {
178+
exponent = UnaryIntegerParser.INSTANCE.parse(rightNode.getChild(0), null).intValue();
179+
} else if (left.equals(MetadataStrings.BYTE_ORDER)) {
180+
byteOrder = ByteOrderParser.INSTANCE.parse(rightNode, new ByteOrderParser.Param(trace));
181+
} else if (left.equals(MetadataStrings.MANT_DIG)) {
182+
mantissa = UnaryIntegerParser.INSTANCE.parse(rightNode.getChild(0), null).intValue();
183+
} else if (left.equals(MetadataStrings.ALIGN)) {
184+
alignment = AlignmentParser.INSTANCE.parse(rightNode, null);
185+
} else {
186+
throw new ParseException(FLOAT_UNKNOWN_ATTRIBUTE + left);
187+
}
153188
} else {
154-
throw new ParseException(FLOAT_UNKNOWN_ATTRIBUTE + left);
189+
throw childTypeError(child);
155190
}
156-
} else {
157-
throw childTypeError(child);
158191
}
159192
}
193+
160194
int size = mantissa + exponent;
161195
if (size == 0) {
162196
throw new ParseException(FLOAT_MISSING_SIZE_ATTRIBUTE);
@@ -167,7 +201,6 @@ public FloatDeclaration parse(ICTFMetadataNode floatingPoint, ICommonTreeParserP
167201
}
168202

169203
return new FloatDeclaration(exponent, mantissa, byteOrder, alignment);
170-
171204
}
172205

173206
}

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/utils/JsonMetadataStrings.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,4 +250,8 @@ private JsonMetadataStrings() {
250250

251251
public static final String MINIMUM_ALIGNMENT = "minimum-alignment"; //$NON-NLS-1$
252252

253+
public static final String ALIGNMENT = "alignment";
254+
255+
public static final String BYTE_ORDER = "byte-order";
256+
253257
}

0 commit comments

Comments
 (0)