Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add type information for execution difference #240

Closed
wants to merge 1 commit into from

Conversation

algomaster99
Copy link
Member

Fixes #208

image

Comment on lines +241 to +302
private String findType(String prefix, String expectedHash, List<RuntimeValue> candidateRuntimeValues) {
for (RuntimeValue runtimeValue : candidateRuntimeValues) {

RuntimeValue runtimeValueFromHash = getRuntimeValueFromHash(prefix, runtimeValue, expectedHash);

if (runtimeValueFromHash != null) {
return runtimeValueFromHash.getType();
}
}
return null;
}

private RuntimeValue getRuntimeValueFromHash(String prefix, RuntimeValue valueJo, String expectedHash) {
if (Constants.FILE_RELATED_CLASSES.stream().anyMatch(valueJo.getType()::contains)) {
return valueJo;
}

if (valueJo.getFields() != null && !valueJo.getFields().isEmpty()) {
if (valueJo.getKind() == RuntimeValue.Kind.RETURN) {
prefix += ".";
} else {
prefix += (valueJo.getName() == null ? "" : valueJo.getName() + ".");
}
List<RuntimeValue> nestedTypes = valueJo.getFields();

for (RuntimeValue nestedObj : nestedTypes) {
RuntimeValue runtimeValue = getRuntimeValueFromHash(prefix, nestedObj, expectedHash);
if (runtimeValue != null) {
return runtimeValue;
}
}
} else if (valueJo.getArrayElements() != null
&& !valueJo.getArrayElements().isEmpty()) {
List<RuntimeValue> nestedTypes = valueJo.getArrayElements();

prefix += (valueJo.getName() == null ? "" : valueJo.getName());

for (int i = 0; i < nestedTypes.size(); i++) {
RuntimeValue nestedObj = nestedTypes.get(i);
String currentPrefix = prefix + "[" + i + "].";
RuntimeValue runtimeValue = getRuntimeValueFromHash(currentPrefix, nestedObj, expectedHash);
if (runtimeValue != null) {
return runtimeValue;
}
}
} else {
// it's a leaf node
String currentPrefix;
if (valueJo.getKind() == RuntimeValue.Kind.RETURN) {
currentPrefix = prefix;
} else {
currentPrefix = prefix + (valueJo.getName() == null ? "" : valueJo.getName());
}
String value = String.valueOf(valueJo.getValue());
String actualHash = currentPrefix + "=" + value;
if (actualHash.equals(expectedHash)) {
return valueJo;
}
}
return null;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khaes-kth I am not proud of the code I wrote. Can you help me refactor it? Especially this block. It is a duplicate of extractVarVals.

@algomaster99
Copy link
Member Author

This was just an illustration of the concept. Won't integrate it now. Would be done after #230.

@algomaster99 algomaster99 deleted the feat/add-type-information branch July 4, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compute difference in dynamic types
1 participant