(FieldInstance field, ClassFeatureExtractor context)
| 1972 | } |
| 1973 | |
| 1974 | static void checkInitializer(FieldInstance field, ClassFeatureExtractor context) { |
| 1975 | if (field.getType().isPrimitive()) return; |
| 1976 | |
| 1977 | MethodInstance method = field.writeRefs.iterator().next(); |
| 1978 | MethodNode asmNode = method.getAsmNode(); |
| 1979 | InsnList il = asmNode.instructions; |
| 1980 | AbstractInsnNode fieldWrite = null; |
| 1981 | |
| 1982 | //dump(method.asmNode); |
| 1983 | //Matcher.LOGGER.debug("\n------------------------\n"); |
| 1984 | |
| 1985 | for (Iterator<AbstractInsnNode> it = il.iterator(); it.hasNext(); ) { |
| 1986 | AbstractInsnNode aInsn = it.next(); |
| 1987 | |
| 1988 | if (aInsn.getOpcode() == Opcodes.PUTFIELD || aInsn.getOpcode() == Opcodes.PUTSTATIC) { |
| 1989 | FieldInsnNode in = (FieldInsnNode) aInsn; |
| 1990 | ClassInstance cls; |
| 1991 | |
| 1992 | if (in.name.equals(field.origName) |
| 1993 | && in.desc.equals(field.getDesc()) |
| 1994 | && (in.owner.equals(field.cls.getName()) || (cls = context.getLocalClsByName(in.owner)) != null && cls.resolveField(in.name, in.desc) == field)) { |
| 1995 | fieldWrite = in; |
| 1996 | break; |
| 1997 | } |
| 1998 | } |
| 1999 | } |
| 2000 | |
| 2001 | if (fieldWrite == null) { |
| 2002 | dump(asmNode); |
| 2003 | throw new IllegalStateException("can't find field write insn for "+field+" in "+method); |
| 2004 | } |
| 2005 | |
| 2006 | Interpreter<SourceValue> interpreter = new SourceInterpreter(); |
| 2007 | Analyzer<SourceValue> analyzer = new Analyzer<>(interpreter); |
| 2008 | Frame<SourceValue>[] frames; |
| 2009 | |
| 2010 | try { |
| 2011 | frames = analyzer.analyze(method.cls.getName(), asmNode); |
| 2012 | if (frames.length != asmNode.instructions.size()) throw new RuntimeException("invalid frame count"); |
| 2013 | } catch (AnalyzerException e) { |
| 2014 | throw new RuntimeException(e); |
| 2015 | } |
| 2016 | |
| 2017 | BitSet tracedPositions = new BitSet(il.size()); |
| 2018 | Queue<AbstractInsnNode> positionsToTrace = new ArrayDeque<>(); |
| 2019 | |
| 2020 | tracedPositions.set(il.indexOf(fieldWrite)); |
| 2021 | positionsToTrace.add(fieldWrite); |
| 2022 | AbstractInsnNode in; |
| 2023 | |
| 2024 | while ((in = positionsToTrace.poll()) != null) { |
| 2025 | int pos = il.indexOf(in); |
| 2026 | Frame<SourceValue> frame = frames[pos]; |
| 2027 | int stackConsumed = getStackDemand(in, frame); |
| 2028 | |
| 2029 | for (int i = 0; i < stackConsumed; i++) { |
| 2030 | SourceValue value = frame.getStack(frame.getStackSize() - i - 1); |
| 2031 |
no test coverage detected