Skip to content

Commit b347e64

Browse files
ctf: fix variants can have integer selectors
Change-Id: Ie8752173c78caf0d0f5cef3cb1a5d2aa58c1e8d8 Signed-off-by: Matthew Khouzam <[email protected]>
1 parent 4882775 commit b347e64

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/tsdl/variant/VariantParser.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.eclipse.tracecompass.ctf.core.event.metadata.DeclarationScope;
2323
import org.eclipse.tracecompass.ctf.core.event.types.EnumDeclaration;
2424
import org.eclipse.tracecompass.ctf.core.event.types.IDeclaration;
25+
import org.eclipse.tracecompass.ctf.core.event.types.IntegerDeclaration;
2526
import org.eclipse.tracecompass.ctf.core.event.types.VariantDeclaration;
2627
import org.eclipse.tracecompass.ctf.core.trace.CTFTrace;
2728
import org.eclipse.tracecompass.ctf.parser.CTFParser;
@@ -266,7 +267,7 @@ public VariantDeclaration parse(ICTFMetadataNode variant, ICommonTreeParserParam
266267
if (variant instanceof JsonStructureFieldMemberMetadataNode) {
267268
JsonObject fieldClass = ((JsonStructureFieldMemberMetadataNode) variant).getFieldClass().getAsJsonObject();
268269
if (fieldClass.has(SELECTOR_FIELD_LOCATION)) {
269-
JsonArray location = fieldClass.get(SELECTOR_FIELD_LOCATION).getAsJsonArray();
270+
JsonArray location = (fieldClass.get(SELECTOR_FIELD_LOCATION).getAsJsonObject().get(JsonMetadataStrings.PATH)).getAsJsonArray();
270271
variantTag = location.get(location.size() - 1).getAsString();
271272
hasTag = true;
272273
}
@@ -361,13 +362,17 @@ public VariantDeclaration parse(ICTFMetadataNode variant, ICommonTreeParserParam
361362
if (decl == null) {
362363
throw new ParseException("Variant tag not found: " + variantTag); //$NON-NLS-1$
363364
}
364-
if (!(decl instanceof EnumDeclaration)) {
365-
throw new ParseException("Variant tag must be an enum: " + variantTag); //$NON-NLS-1$
366-
}
367-
EnumDeclaration tagDecl = (EnumDeclaration) decl;
368-
if (!intersects(tagDecl.getLabels(), variantDeclaration.getFields().keySet())) {
369-
throw new ParseException("Variant contains no values of the tag, impossible to use: " + variantName); //$NON-NLS-1$
365+
if (decl instanceof EnumDeclaration) {
366+
EnumDeclaration tagDecl = (EnumDeclaration) decl;
367+
if (!intersects(tagDecl.getLabels(), variantDeclaration.getFields().keySet())) {
368+
throw new ParseException("Variant contains no values of the tag, impossible to use: " + variantName); //$NON-NLS-1$
369+
}
370+
} else if (decl instanceof IntegerDeclaration) {
371+
// do nothing
372+
} else {
373+
throw new ParseException("Variant tag must be an enum: " + variantTag);//$NON-NLS-1$
370374
}
375+
371376
}
372377

373378
return variantDeclaration;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ private JsonMetadataStrings() {
173173
*/
174174
public static final String VARIANT = "variant"; //$NON-NLS-1$
175175

176+
/**
177+
* Type string for a structure field class
178+
*/
179+
public static final String PATH = "path"; //$NON-NLS-1$
180+
176181
/**
177182
* Type string for a structure field class
178183
*/

0 commit comments

Comments
 (0)