Skip to content

Commit 99a9d62

Browse files
ctf: Attempt to correct scopeed lookups
Remove infinite recurstion if something is not found. (due to roles in ctf2) Change-Id: Ifa62ed5807a17e307c044e066399cf15fae2bc74 Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
1 parent d8fed7e commit 99a9d62

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/ScopedDefinition.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,21 @@ public VariantDefinition lookupVariant(String name) {
150150
IDefinition def = lookupDefinition(name);
151151
return (VariantDefinition) ((def instanceof VariantDefinition) ? def : null);
152152
}
153-
}
153+
154+
155+
/**
156+
* Lookup definition while excluding the caller
157+
*
158+
* @param lookupPath
159+
* the path to lookup
160+
* @param defintionToExclude
161+
* the definition to exclude, can be null
162+
* @return the definition or null
163+
* @since 5.1
164+
*/
165+
public @Nullable IDefinition lookupDefinition(@Nullable String lookupPath, @Nullable ScopedDefinition defintionToExclude) {
166+
if(defintionToExclude == this) {
167+
return null;
168+
}
169+
return lookupDefinition(lookupPath, defintionToExclude);
170+
}}

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDeclaration.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
package org.eclipse.tracecompass.ctf.core.event.types;
1616

1717
import java.util.Arrays;
18+
import java.util.HashMap;
1819
import java.util.List;
20+
import java.util.Map;
1921
import java.util.regex.Pattern;
2022

2123
import org.eclipse.jdt.annotation.NonNull;
@@ -54,6 +56,8 @@ public class StructDeclaration extends Declaration {
5456
private @NonNull String[] fFieldNames;
5557
/** Field declarations */
5658
private @NonNull IDeclaration[] fFields;
59+
/** Role declarations */
60+
private final @NonNull Map<String, IDeclaration> fRoles = new HashMap<>();
5761

5862
/** maximum bit alignment */
5963
private long fMaxAlign;
@@ -209,6 +213,10 @@ public void addField(@NonNull String name, @NonNull IDeclaration declaration) {
209213
fields[length] = declaration;
210214
fFieldNames = names;
211215
fFields = fields;
216+
String role = declaration.getRole();
217+
if(null != role && !role.isEmpty()) {
218+
fRoles.put(role, declaration);
219+
}
212220
fMaxAlign = Math.max(fMaxAlign, declaration.getAlignment());
213221
}
214222

@@ -337,6 +345,12 @@ public String toString() {
337345
return sb.toString();
338346
}
339347

348+
@Override
349+
public void setRole(String role) {
350+
super.setRole(role);
351+
fRoles.put(role, this);
352+
}
353+
340354
@Override
341355
public int hashCode() {
342356
final int prime = 31;
@@ -405,4 +419,14 @@ public boolean isBinaryEquivalent(IDeclaration obj) {
405419
return (fMaxAlign == other.fMaxAlign);
406420
}
407421

422+
/**
423+
* Get the child with a role
424+
* @param role the role
425+
* @return the role
426+
* @since 5.1
427+
*/
428+
public @Nullable IDeclaration getRole(String role) {
429+
return fRoles.get(role);
430+
}
431+
408432
}

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/StructDefinition.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,13 @@ public String toString() {
181181
}
182182

183183
/**
184-
* Lookup definition while exclusing the caller
185-
*
186-
* @param lookupPath
187-
* the path to lookup
188-
* @param defintionToExclude
189-
* the definition to exclude, can be null
190-
* @return the definition or null
191184
* @since 1.1
192185
*/
186+
@Override
193187
public Definition lookupDefinition(String lookupPath, ScopedDefinition defintionToExclude) {
188+
if (this.equals(defintionToExclude) || lookupPath == null) {
189+
return null;
190+
}
194191
/*
195192
* The fields are created in order of appearance, so if a variant or
196193
* sequence refers to a field that is after it, the field's definition
@@ -208,7 +205,12 @@ public Definition lookupDefinition(String lookupPath, ScopedDefinition defintion
208205
for (IDefinition child : fDefinitions) {
209206
if (child instanceof ScopedDefinition) {
210207
if (!child.equals(defintionToExclude)) {
211-
IDefinition def = ((ScopedDefinition) child).lookupDefinition(lookupPath);
208+
if (lookupPath.equals(child.getDeclaration().getRole())) {
209+
if (child instanceof Definition) {
210+
return (Definition) child;
211+
}
212+
}
213+
IDefinition def = ((ScopedDefinition) child).lookupDefinition(lookupPath, defintionToExclude);
212214
if (def instanceof Definition) {
213215
return (Definition) def;
214216
}
@@ -218,6 +220,9 @@ public Definition lookupDefinition(String lookupPath, ScopedDefinition defintion
218220
if (getDefinitionScope() instanceof InternalDef) {
219221
return (Definition) ((InternalDef) getDefinitionScope()).lookupDefinitionBreakLoop(lookupPath);
220222
}
223+
if (getDefinitionScope() instanceof ScopedDefinition) {
224+
return (Definition) ((ScopedDefinition) getDefinitionScope()).lookupDefinition(lookupPath, this);
225+
}
221226
return (Definition) getDefinitionScope().lookupDefinition(lookupPath);
222227
}
223228

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/VariantDefinition.java

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,42 @@ public IDefinition lookupDefinition(String lookupPath) {
143143
if (lookupPath.equals(fFieldName)) {
144144
return fDefinition;
145145
}
146+
if (lookupPath.equals(fTagDef.getDeclaration().getRole())) {
147+
return fTagDef;
148+
}
149+
if (lookupPath.equals(fDefinition.getDeclaration().getRole())) {
150+
return fDefinition;
151+
}
152+
if (fDefinition instanceof ScopedDefinition) {
153+
IDefinition def = ((ScopedDefinition) fDefinition).lookupDefinition(lookupPath, this);
154+
if (def != null) {
155+
return def;
156+
}
157+
}
158+
final IDefinitionScope definitionScope = getDefinitionScope();
159+
if (definitionScope instanceof StructDefinition) {
160+
StructDefinition structDefinition = (StructDefinition) definitionScope;
161+
return structDefinition.lookupDefinition(lookupPath, this);
162+
}
163+
return definitionScope.lookupDefinition(lookupPath);
164+
}
165+
166+
@Override
167+
public IDefinition lookupDefinition(String lookupPath, ScopedDefinition definitionToExclude) {
168+
if (lookupPath == null) {
169+
return null;
170+
}
171+
if (lookupPath.equals(fFieldName)) {
172+
return fDefinition;
173+
}
174+
if (lookupPath.equals(fTagDef.getDeclaration().getRole())) {
175+
return fTagDef;
176+
}
177+
if (lookupPath.equals(fDefinition.getDeclaration().getRole())) {
178+
return fDefinition;
179+
}
146180
if (fDefinition instanceof ScopedDefinition) {
147-
IDefinition def = ((ScopedDefinition) fDefinition).lookupDefinition(lookupPath);
181+
IDefinition def = ((ScopedDefinition) fDefinition).lookupDefinition(lookupPath, definitionToExclude);
148182
if (def != null) {
149183
return def;
150184
}

0 commit comments

Comments
 (0)