Skip to content

Commit 04cc6de

Browse files
ctf: make CTF1 parsing more rigid
Do not accept double typealiases with the same value. Change-Id: I2affb15f6faf83cd0292a7310febbad8ae657513 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
1 parent eaa67c8 commit 04cc6de

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void registerType(String name, IDeclaration declaration)
178178
}
179179
IDeclaration originalDeclaration = fTypes.get(name);
180180
if (originalDeclaration != null && !Objects.equals(declaration, originalDeclaration)) {
181-
throw new ParseException("Type has already been defined:" + name); //$NON-NLS-1$
181+
throw new ParseException("Type has already been defined: " + name); //$NON-NLS-1$
182182
}
183183

184184
/* Add it to the register. */

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ public IDeclaration parse(ICTFMetadataNode typealias, ICommonTreeParserParameter
210210
}
211211

212212
aliasString = TypeAliasAliasParser.INSTANCE.parse(alias, null);
213+
if (scope.lookupType(aliasString)!= null) {
214+
throw new ParseException("Type has already been defined: " + aliasString); //$NON-NLS-1$
215+
}
213216
}
214217

215218
scope.registerType(aliasString, targetDeclaration);

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.eclipse.tracecompass.internal.ctf.core.event.metadata.tsdl.TypeDeclaratorParser;
2727
import org.eclipse.tracecompass.internal.ctf.core.event.types.ICTFMetadataNode;
2828

29+
import com.google.common.base.Objects;
30+
2931
/**
3032
* Structures follow the ISO/C standard for structures
3133
*
@@ -92,8 +94,8 @@ public StructDeclaration parse(ICTFMetadataNode declaration, ICommonTreeParserPa
9294
StringBuilder identifierSB = new StringBuilder();
9395
IDeclaration decl = null;
9496
String fieldName = null;
95-
96-
if (declaration instanceof CTFAntlrMetadataNode) {
97+
boolean isCtf1 = declaration instanceof CTFAntlrMetadataNode;
98+
if (isCtf1) {
9799
/* Get the type specifier list node */
98100
ICTFMetadataNode typeSpecifierListNode = declaration.getFirstChildWithType(CTFParser.tokenNames[CTFParser.TYPE_SPECIFIER_LIST]);
99101

@@ -119,6 +121,11 @@ public StructDeclaration parse(ICTFMetadataNode declaration, ICommonTreeParserPa
119121
decl = TypeDeclaratorParser.INSTANCE.parse(typeDeclaratorNode, new TypeDeclaratorParser.Param(trace, typeSpecifierListNode, scope, identifierSB));
120122
}
121123
fieldName = identifierSB.toString();
124+
125+
if (struct.getField(fieldName) != null) {
126+
throw new ParseException("struct: duplicate field " //$NON-NLS-1$
127+
+ fieldName);
128+
}
122129
} else {
123130
decl = TypeAliasParser.INSTANCE.parse(declaration, new TypeAliasParser.Param(trace, scope));
124131
fieldName = ((JsonStructureFieldMemberMetadataNode) declaration).getName();
@@ -129,12 +136,16 @@ public StructDeclaration parse(ICTFMetadataNode declaration, ICommonTreeParserPa
129136

130137
scope.registerIdentifier(fieldName, decl);
131138
IDeclaration current = struct.getField(fieldName);
132-
if (decl != null && current != null && !decl.equals(current)) {
139+
if (decl == null) {
140+
throw new ParseException("struct: Cannot add null field " + fieldName); //$NON-NLS-1$
141+
}
142+
143+
if (current != null && !Objects.equal(decl, current)) {
133144
throw new ParseException("struct: duplicate field " //$NON-NLS-1$
134145
+ fieldName);
135146
}
136147

137-
if (fieldName != null && decl != null) {
148+
if (fieldName != null) {
138149
struct.addField(fieldName, decl);
139150
}
140151

0 commit comments

Comments
 (0)