Skip to content

Commit

Permalink
Added types for field accesses to referenced types; updated method re…
Browse files Browse the repository at this point in the history
…turn type computation

to account for typecasts

Signed-off-by: Saurabh Sinha <[email protected]>
  • Loading branch information
sinha108 committed Jun 28, 2024
1 parent 7510e5c commit 0d6998f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/main/java/com/ibm/northstar/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,23 @@ private static List<String> getReferencedTypes(Optional<BlockStmt> blockStmt) {
.filter(vd -> vd.getType().isClassOrInterfaceType())
.map(vd -> resolveType(vd.getType()))
.forEach(referencedTypes::add));

// add types of accessed fields to the set of referenced types
blockStmt.ifPresent(bs -> bs.findAll(FieldAccessExpr.class)
.stream()
.filter(faExpr -> faExpr.getParentNode().isPresent() && !(faExpr.getParentNode().get() instanceof FieldAccessExpr))
.map(faExpr -> {
if (faExpr.getParentNode().isPresent() && faExpr.getParentNode().get() instanceof CastExpr) {
return resolveType(((CastExpr)faExpr.getParentNode().get()).getType());
} else {
return resolveExpression(faExpr);
}
})
.filter(type -> !type.isEmpty())
.forEach(referencedTypes::add));

// TODO: add resolved method access expressions

return new ArrayList<>(referencedTypes);
}

Expand Down Expand Up @@ -465,8 +482,15 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
if (declaringTypeName.equals(scopeExpr.toString())) {
isStaticCall = true;
}
}

// compute return type for method call taking into account typecast of return value
if (methodCallExpr.getParentNode().isPresent() && methodCallExpr.getParentNode().get() instanceof CastExpr) {
returnType = resolveType(((CastExpr)methodCallExpr.getParentNode().get()).getType());
} else {
returnType = resolveExpression(methodCallExpr);
}

// resolve arguments of the method call to types
List<String> arguments = methodCallExpr.getArguments().stream()
.map(arg -> resolveExpression(arg)).collect(Collectors.toList());
Expand Down

0 comments on commit 0d6998f

Please sign in to comment.