Skip to content

Commit 4547898

Browse files
ctf: add struct support
Change-Id: I724d84c0b1f5c300ee73c4f2c2b0b9fa3f4ca3d1 Signed-off-by: Matthew Khouzam <[email protected]>
1 parent cbc7bd7 commit 4547898

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/metadata/DeclarationScope.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Arrays;
1818
import java.util.HashMap;
1919
import java.util.Map;
20+
import java.util.Objects;
2021
import java.util.Set;
2122
import java.util.concurrent.atomic.AtomicLong;
2223

@@ -171,7 +172,12 @@ public void setName(String name) {
171172
public void registerType(String name, IDeclaration declaration)
172173
throws ParseException {
173174
/* Check if the type has been defined in the current scope */
174-
if (fTypes.containsKey(name)) {
175+
if (name == null || name.isEmpty()) {
176+
// don't register anonymous types
177+
return;
178+
}
179+
IDeclaration originalDeclaration = fTypes.get(name);
180+
if (originalDeclaration != null && !Objects.equals(declaration, originalDeclaration)) {
175181
throw new ParseException("Type has already been defined:" + name); //$NON-NLS-1$
176182
}
177183

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonFieldClassAliasMetadataNode;
2525
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode;
2626
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
27+
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.dynamicarray.DynamicLengthArrayParser;
2728
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.dynamicstring.DynamicLengthStringParser;
2829
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.enumeration.EnumParser;
2930
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.integer.IntegerDeclarationParser;
3031
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.staticarray.StaticLengthArrayParser;
3132
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.staticstring.StaticLengthStringParser;
3233
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.string.StringDeclarationParser;
34+
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.struct.StructParser;
3335
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.variant.VariantParser;
3436
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
3537
import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings;
@@ -173,6 +175,10 @@ public IDeclaration parse(ICTFMetadataNode typealias, ICommonTreeParserParameter
173175
targetDeclaration = StaticLengthStringParser.INSTANCE.parse(typealias, new StaticLengthStringParser.Param(trace));
174176
} else if (JsonMetadataStrings.STATIC_LENGTH_ARRAY.equals(type)) {
175177
targetDeclaration = StaticLengthArrayParser.INSTANCE.parse(typealias, new StaticLengthArrayParser.Param(trace, scope));
178+
} else if (JsonMetadataStrings.DYNAMIC_LENGTH_ARRAY.equals(type)) {
179+
targetDeclaration = DynamicLengthArrayParser.INSTANCE.parse(typealias, new DynamicLengthArrayParser.Param(trace, scope));
180+
} else if (JsonMetadataStrings.STRUCTURE.equals(type)) {
181+
targetDeclaration = StructParser.INSTANCE.parse(typealias, new StructParser.Param(trace, null, scope));
176182
} else {
177183
throw new ParseException("Invalid field class: " + type); //$NON-NLS-1$
178184
}

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/internal/ctf/core/event/metadata/tsdl/struct/StructParser.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@
2222
import org.eclipse.tracecompass.ctf.parser.CTFParser;
2323
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.AbstractScopedCommonTreeParser;
2424
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.CTFAntlrMetadataNode;
25+
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMemberMetadataNode;
2526
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.JsonStructureFieldMetadataNode;
2627
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.ParseException;
2728
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.AlignmentParser;
2829
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
2930
import org.eclipse.tracecompass.internal.ctf.core.event.types.StructDeclarationFlattener;
31+
import org.eclipse.tracecompass.internal.ctf.core.utils.JsonMetadataStrings;
3032

3133
/**
3234
*
@@ -185,14 +187,29 @@ public StructDeclaration parse(ICTFMetadataNode struct, ICommonTreeParserParamet
185187
structName = identifier.getText();
186188
hasName = true;
187189
}
188-
} else {
189-
if (((JsonStructureFieldMetadataNode) struct).getMinimumAlignment() != 0) {
190+
} else if (struct instanceof JsonStructureFieldMetadataNode) {
191+
JsonStructureFieldMetadataNode structNode = (JsonStructureFieldMetadataNode) struct;
192+
if (structNode.getMinimumAlignment() != 0) {
190193
structAlign = AlignmentParser.INSTANCE.parse(struct, null);
191194
}
192-
if (((JsonStructureFieldMetadataNode) struct).getMemberClasses() != null) {
195+
if (structNode.getMemberClasses() != null) {
193196
hasBody = true;
194197
structBody = struct;
195198
}
199+
} else if (struct instanceof JsonStructureFieldMemberMetadataNode) {
200+
ICTFMetadataNode innerNode = struct.getChild(JsonMetadataStrings.STRUCT);
201+
if (innerNode instanceof JsonStructureFieldMetadataNode) {
202+
JsonStructureFieldMetadataNode structNode = (JsonStructureFieldMetadataNode) struct;
203+
if (structNode.getMinimumAlignment() != 0) {
204+
structAlign = AlignmentParser.INSTANCE.parse(struct, null);
205+
}
206+
if (structNode.getMemberClasses() != null) {
207+
hasBody = true;
208+
structBody = struct;
209+
210+
}
211+
}
212+
196213
}
197214
/*
198215
* If a struct has just a body and no name (just like the song,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ private JsonMetadataStrings() {
201201
*/
202202
public static final String STRUCTURE = "structure"; //$NON-NLS-1$
203203

204+
/**
205+
* Type string for an internal structure field class
206+
*/
207+
public static final String STRUCT = "struct"; //$NON-NLS-1$
204208
/**
205209
* Encodings map
206210
*/
@@ -223,8 +227,14 @@ private JsonMetadataStrings() {
223227
*/
224228
public static final String STATIC_LENGTH_ARRAY = "static-length-array"; //$NON-NLS-1$
225229

230+
/**
231+
* Dynamic length array
232+
*/
233+
public static final String DYNAMIC_LENGTH_ARRAY = "dynamic-length-array"; //$NON-NLS-1$
234+
226235
/**
227236
* Element field class
228237
*/
229238
public static final String ELEMENT_FIELD_CLASS = "element-field-class"; //$NON-NLS-1$
239+
230240
}

0 commit comments

Comments
 (0)