int (List<Exprent> list, int index) { Exprent current = list.get(index); if (current.type == Exprent.EXPRENT_ASSIGNMENT) { AssignmentExprent as = (AssignmentExprent)current; if (as.getRight().type == Exprent.EXPRENT_NEW && as.getLeft().type == Exprent.EXPRENT_VAR) { NewExprent newExpr = (NewExprent)as.getRight(); if (newExpr.getExprType().getArrayDim() > 0 && newExpr.getLstDims().size() == 1 && newExpr.getLstArrayElements().isEmpty() && newExpr.getLstDims().get(0).type == Exprent.EXPRENT_CONST) { int size = (Integer)((ConstExprent)newExpr.getLstDims().get(0)).getValue(); if (size == 0) { return 0; } VarExprent arrVar = (VarExprent)as.getLeft(); Map<Integer, Exprent> mapInit = new HashMap<>(); int i = 1; while (index + i < list.size() && i <= size) { boolean found = false; Exprent expr = list.get(index + i); if (expr.type == Exprent.EXPRENT_ASSIGNMENT) { AssignmentExprent aas = (AssignmentExprent)expr; if (aas.getLeft().type == Exprent.EXPRENT_ARRAY) { ArrayExprent arrExpr = (ArrayExprent)aas.getLeft(); if (arrExpr.getArray().type == Exprent.EXPRENT_VAR && arrVar.equals(arrExpr.getArray()) && arrExpr.getIndex().type == Exprent.EXPRENT_CONST) { // TODO: check for a number type. Failure extremely improbable, but nevertheless... int constValue = ((ConstExprent)arrExpr.getIndex()).getIntValue(); if (constValue < size && !mapInit.containsKey(constValue)) { if (!aas.getRight().containsExprent(arrVar)) { mapInit.put(constValue, aas.getRight()); found = true; } } } } } if (!found) { break; } i++; } double fraction = ((double)mapInit.size()) / size; if ((arrVar.isStack() && fraction > 0) || (size <= 7 && fraction >= 0.3) || (size > 7 && fraction >= 0.7)) { List<Exprent> lstRet = new ArrayList<>(); VarType arrayType = newExpr.getNewType().decreaseArrayDim(); ConstExprent defaultVal = ExprProcessor.getDefaultArrayValue(arrayType); for (int j = 0; j < size; j++) { lstRet.add(defaultVal.copy()); } int dims = newExpr.getNewType().getArrayDim(); for (Entry<Integer, Exprent> ent : mapInit.entrySet()) { Exprent tempExpr = ent.getValue(); lstRet.set(ent.getKey(), tempExpr); if (tempExpr.type == Exprent.EXPRENT_NEW) { NewExprent tempNewExpr = (NewExprent)tempExpr; if (dims > 1 && !tempNewExpr.getLstArrayElements().isEmpty()) { tempNewExpr.setDirectArrayInit(true); } } } newExpr.setLstArrayElements(lstRet); return mapInit.size(); } } } } return 0; }