MCPcopy Create free account
hub / github.com/FabricMC/Matcher / checkInitializer

Method checkInitializer

src/main/java/matcher/type/Analysis.java:1974–2129  ·  view source on GitHub ↗
(FieldInstance field, ClassFeatureExtractor context)

Source from the content-addressed store, hash-verified

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

Callers 1

processClassDMethod · 0.95

Calls 15

getAsmNodeMethod · 0.95
resolveFieldMethod · 0.95
dumpMethod · 0.95
getStackDemandMethod · 0.95
isPrimitiveMethod · 0.80
iteratorMethod · 0.80
hasNextMethod · 0.80
getLocalClsByNameMethod · 0.80
sizeMethod · 0.80
setMethod · 0.80
getNameMethod · 0.65
getTypeMethod · 0.45

Tested by

no test coverage detected