2222import org .eclipse .tracecompass .ctf .core .event .types .FloatDeclaration ;
2323import org .eclipse .tracecompass .ctf .core .trace .CTFTrace ;
2424import org .eclipse .tracecompass .ctf .parser .CTFParser ;
25+ import org .eclipse .tracecompass .internal .ctf .core .event .metadata .CTFJsonMetadataNode ;
2526import org .eclipse .tracecompass .internal .ctf .core .event .metadata .ICommonTreeParser ;
27+ import org .eclipse .tracecompass .internal .ctf .core .event .metadata .JsonStructureFieldMemberMetadataNode ;
2628import org .eclipse .tracecompass .internal .ctf .core .event .metadata .MetadataStrings ;
2729import org .eclipse .tracecompass .internal .ctf .core .event .metadata .ParseException ;
2830import org .eclipse .tracecompass .internal .ctf .core .event .metadata .tsdl .AlignmentParser ;
2931import org .eclipse .tracecompass .internal .ctf .core .event .metadata .tsdl .ByteOrderParser ;
3032import org .eclipse .tracecompass .internal .ctf .core .event .metadata .tsdl .UnaryIntegerParser ;
3133import 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 .JsonElement ;
37+ import com .google .gson .JsonObject ;
3238
3339/**
3440 *
@@ -114,49 +120,84 @@ public FloatDeclaration parse(ICTFMetadataNode floatingPoint, ICommonTreeParserP
114120 throw new IllegalArgumentException ("Param must be a " + Param .class .getCanonicalName ()); //$NON-NLS-1$
115121 }
116122 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- }
126123
127124 /* The return value */
128125 ByteOrder byteOrder = trace .getByteOrder ();
129126 long alignment = 0 ;
130-
131127 int exponent = DEFAULT_FLOAT_EXPONENT ;
132128 int mantissa = DEFAULT_FLOAT_MANTISSA ;
133129
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 );
130+ if (floatingPoint instanceof JsonStructureFieldMemberMetadataNode member ) {
131+ JsonElement fieldClassElement = member .getFieldClass ();
132+ if (fieldClassElement == null || !fieldClassElement .isJsonObject ()) {
133+ throw new ParseException (getClass ().getName () + " fieldclass must be a json object." ); //$NON-NLS-1$
134+ }
135+ JsonObject fieldclass = member .getFieldClass ().getAsJsonObject ();
136+
137+ if (fieldclass .has (JsonMetadataStrings .LENGTH )) {
138+ int size = fieldclass .get (JsonMetadataStrings .LENGTH ).getAsInt ();
139+ // Standard IEEE 754 sizes
140+ if (size == 32 ) {
141+ exponent = 8 ;
142+ mantissa = 24 ;
143+ } else if (size == 64 ) {
144+ exponent = 11 ;
145+ mantissa = 53 ;
146+ } else if (size == 16 || (size - 128 ) % 64 == 0 ) {
147+ // TODO: make it work with 16, 128, and 128 + N*64 sizes.
148+ throw new ParseException ("Unsupported valid floating point size: " + size ); //$NON-NLS-1$
149+ } else {
150+ throw new ParseException ("Unsupported floating point size: " + size ); //$NON-NLS-1$
143151 }
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 );
152+ }
153+
154+ if (fieldclass .has (JsonMetadataStrings .BYTE_ORDER )) {
155+ CTFJsonMetadataNode bo = new CTFJsonMetadataNode (floatingPoint , CTFParser .tokenNames [CTFParser .UNARY_EXPRESSION_STRING ], fieldclass .get (JsonMetadataStrings .BYTE_ORDER ).getAsString ());
156+ byteOrder = ByteOrderParser .INSTANCE .parse (bo , new ByteOrderParser .Param (trace ));
157+ }
158+
159+ if (fieldclass .has (JsonMetadataStrings .ALIGNMENT )) {
160+ alignment = AlignmentParser .INSTANCE .parse (floatingPoint , null );
161+ }
162+ } else {
163+ List <ICTFMetadataNode > children = floatingPoint .getChildren ();
164+
165+ /*
166+ * If the integer has no attributes, then it is missing the size
167+ * attribute which is required
168+ */
169+ if (children == null ) {
170+ throw new ParseException (FLOAT_MISSING_SIZE_ATTRIBUTE );
171+ }
172+
173+ /* Iterate on all integer children */
174+ for (ICTFMetadataNode child : children ) {
175+ String type = child .getType ();
176+ if (CTFParser .tokenNames [CTFParser .CTF_EXPRESSION_VAL ].equals (type )) {
177+ ICTFMetadataNode leftNode = child .getChild (0 );
178+ ICTFMetadataNode rightNode = child .getChild (1 );
179+ List <ICTFMetadataNode > leftStrings = leftNode .getChildren ();
180+ if (!isAnyUnaryString (leftStrings .get (0 ))) {
181+ throw new ParseException (IDENTIFIER_MUST_BE_A_STRING );
182+ }
183+ String left = concatenateUnaryStrings (leftStrings );
184+ if (left .equals (MetadataStrings .EXP_DIG )) {
185+ exponent = UnaryIntegerParser .INSTANCE .parse (rightNode .getChild (0 ), null ).intValue ();
186+ } else if (left .equals (MetadataStrings .BYTE_ORDER )) {
187+ byteOrder = ByteOrderParser .INSTANCE .parse (rightNode , new ByteOrderParser .Param (trace ));
188+ } else if (left .equals (MetadataStrings .MANT_DIG )) {
189+ mantissa = UnaryIntegerParser .INSTANCE .parse (rightNode .getChild (0 ), null ).intValue ();
190+ } else if (left .equals (MetadataStrings .ALIGN )) {
191+ alignment = AlignmentParser .INSTANCE .parse (rightNode , null );
192+ } else {
193+ throw new ParseException (FLOAT_UNKNOWN_ATTRIBUTE + left );
194+ }
153195 } else {
154- throw new ParseException ( FLOAT_UNKNOWN_ATTRIBUTE + left );
196+ throw childTypeError ( child );
155197 }
156- } else {
157- throw childTypeError (child );
158198 }
159199 }
200+
160201 int size = mantissa + exponent ;
161202 if (size == 0 ) {
162203 throw new ParseException (FLOAT_MISSING_SIZE_ATTRIBUTE );
@@ -167,7 +208,6 @@ public FloatDeclaration parse(ICTFMetadataNode floatingPoint, ICommonTreeParserP
167208 }
168209
169210 return new FloatDeclaration (exponent , mantissa , byteOrder , alignment );
170-
171211 }
172212
173213}
0 commit comments