The pascal.taie.ir.IRBuilder is for keeping the IRs of all methods to prevent cyclic references with too long a path which may make the serialization fail or java.lang.StackOverflowError.
| 39 | * the serialization fail or {@link java.lang.StackOverflowError}. |
| 40 | */ |
| 41 | public class CachedIRBuilder implements IRBuilder { |
| 42 | |
| 43 | private final Map<String, IR> methodSig2IR; |
| 44 | |
| 45 | public CachedIRBuilder(IRBuilder irBuilder, ClassHierarchy hierarchy) { |
| 46 | irBuilder.buildAll(hierarchy); |
| 47 | methodSig2IR = hierarchy.allClasses() |
| 48 | .map(JClass::getDeclaredMethods) |
| 49 | .flatMap(Collection::stream) |
| 50 | .filter(m -> !m.isAbstract() || m.isNative()) |
| 51 | .collect(Collectors.toMap(JMethod::getSignature, JMethod::getIR)); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * This method will be called by {@link JMethod#getIR()} only once, |
| 56 | * so remove the IR from the map after returning it. |
| 57 | */ |
| 58 | @Override |
| 59 | public IR buildIR(JMethod method) { |
| 60 | return methodSig2IR.remove(method.getSignature()); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public void buildAll(ClassHierarchy hierarchy) { |
| 65 | hierarchy.allClasses() |
| 66 | .map(JClass::getDeclaredMethods) |
| 67 | .flatMap(Collection::stream) |
| 68 | .filter(m -> !m.isAbstract() || m.isNative()) |
| 69 | .forEach(JMethod::getIR); |
| 70 | } |
| 71 | } |
nothing calls this directly
no outgoing calls
no test coverage detected