@Override public boolean preconditionHolds() { return targetStruct.getNumFields() > 1 && targetStruct.hasField(fieldToRemove); } }
private void obfuscateTranslationUnit(TranslationUnit tu) { this.typer = new Typer(tu, tu.getShadingLanguageVersion()); visit(tu); for (VariableDeclInfo declInfo : varDeclMapping.keySet()) { assert varDeclMapping.containsKey(declInfo); declInfo.setName(varDeclMapping.get(declInfo)); } for (ParameterDecl parameterDecl : paramDeclMapping.keySet()) { assert paramDeclMapping.containsKey(parameterDecl); parameterDecl.setName(paramDeclMapping.get(parameterDecl)); } for (StructDefinitionType structDefinitionType : structDefinitionTypes) { if (structDefinitionType.hasStructNameType()) { final StructNameType structNameType = structDefinitionType.getStructNameType(); for (int i = 0; i < structDefinitionType.getNumFields(); i++) { assert structFieldRenaming.get(structNameType) .containsKey(structDefinitionType.getFieldName(i)); structDefinitionType.setFieldName(i, structFieldRenaming.get(structNameType) .get(structDefinitionType.getFieldName(i))); } } } new StandardVisitor() { @Override public void visitStructNameType(StructNameType structNameType) { structNameType.setName(namedStructRenaming.get(structNameType.getName())); } }.visit(tu); }
private Expr makeInitializationExpr(StructDefinitionType structDefinitionType, Expr originalInitializer) { List<Expr> args = new ArrayList<>(); for (int i = 0; i < structDefinitionType.getNumFields(); i++) { if (structDefinitionType.getFieldName(i).startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX)) { final Type fieldType = structDefinitionType.getFieldType(i); args.add(fieldType instanceof StructNameType ? makeInitializationExpr(tu.getStructDefinition((StructNameType) fieldType), originalInitializer) : fieldType.getCanonicalConstant()); } else { args.add(originalInitializer); } } return new TypeConstructorExpr(structDefinitionType.getStructNameType().getName(), args); }
private Expr insertFieldIntoStruct(String enclosingStructName, StructDefinitionType enclosingStruct, IRandom generator) { Expr result = new VariableIdentifierExpr(enclosingStructName); StructDefinitionType currentStruct = enclosingStruct; while (true) { Map<String, StructDefinitionType> structFields = getStructFields(currentStruct); if (!structFields.keySet().isEmpty() && generator.nextBoolean()) { String fieldName = structFields.keySet().stream().collect(Collectors.toList()) .get(generator.nextInt(structFields.size())); result = new MemberLookupExpr(result, fieldName); currentStruct = structFields.get(fieldName); } else { // Choose random position at which to insert the field. currentStruct.insertField(generator.nextInt(currentStruct.getNumFields() + 1), declToTransform.getVariablesDeclaration().getDeclInfo(0).getName(), declToTransform.getVariablesDeclaration().getBaseType()); result = new MemberLookupExpr(result, declToTransform.getVariablesDeclaration() .getDeclInfo(0).getName()); return result; } } }
for (int i = 0; i < structDefinitionType.getNumFields(); i++) {
for (int i = 0; i < innerStruct.getNumFields(); i++) { final String oldFieldName = innerStruct.getFieldName(i); final String newFieldName = oldFieldName.startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX)
private void getOpportunitiesForStruct(StructNameType structType, VisitationDepth visitationDepth) { if (!(structType.getName().startsWith(Constants .STRUCTIFICATION_STRUCT_PREFIX))) { return; } final StructDefinitionType structDefinitionType = currentScope.lookupStructName(structType.getName()); for (String field : structDefinitionType.getFieldNames()) { if (!reachesOriginalVariable(structDefinitionType, field) && structDefinitionType.getNumFields() > 1) { final RemoveStructFieldReductionOpportunity op = new RemoveStructFieldReductionOpportunity( structDefinitionType, field, translationUnit, visitationDepth); if (op.preconditionHolds()) { opportunities.add(op); } } if (structDefinitionType.getFieldType(field).getWithoutQualifiers() instanceof StructNameType) { getOpportunitiesForStruct( (StructNameType) structDefinitionType.getFieldType(field).getWithoutQualifiers(), visitationDepth.deeper()); } } }