@Override public void visit(IAstNode node) { if (node == donorFragment) { assert structDefinitionTypes.isEmpty(); for (String structName : currentScope.namesOfAllStructDefinitionsInScope()) { structDefinitionTypes.add(currentScope.lookupStructName(structName)); } } super.visit(node); }
/** * Look in current scope to see whether we have a struct definition type matching the struct name. * @param structName Name of struct type. * @return Corresponding struct definition, if found, otherwise null. */ public StructDefinitionType lookupStructName(String structName) { if (structMapping.containsKey(structName)) { return structMapping.get(structName); } if (hasParent()) { return getParent().lookupStructName(structName); } return null; }
@Override public void visitStructNameType(StructNameType structNameType) { super.visitStructNameType(structNameType); unusedStructs.remove(currentScope.lookupStructName(structNameType.getName())); }
private boolean reachesOriginalVariable(StructDefinitionType structDefinitionType, String field) { if (!(field.startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX))) { return true; } if (!(structDefinitionType.getFieldType(field).getWithoutQualifiers() instanceof StructNameType)) { return false; } final StructNameType fieldType = (StructNameType) structDefinitionType.getFieldType(field).getWithoutQualifiers(); final StructDefinitionType nestedStruct = currentScope.lookupStructName(fieldType.getName()); return nestedStruct.getFieldNames().stream() .anyMatch(item -> reachesOriginalVariable(nestedStruct, item)); }
public void findInliningOpportunities(StructNameType structType) { assert structType.getName().startsWith(Constants.STRUCTIFICATION_STRUCT_PREFIX); final StructDefinitionType structDefinitionType = currentScope.lookupStructName(structType.getName()); for (String f : structDefinitionType.getFieldNames()) { if (!f.startsWith(Constants.STRUCTIFICATION_FIELD_PREFIX)) { continue; } if (structDefinitionType.getFieldType(f).getWithoutQualifiers() instanceof StructNameType) { final StructNameType innerStructType = (StructNameType) structDefinitionType.getFieldType(f).getWithoutQualifiers(); opportunities.add(new InlineStructifiedFieldReductionOpportunity( structDefinitionType, currentScope.lookupStructName(innerStructType.getName()), f, tu, getVistitationDepth())); findInliningOpportunities(innerStructType); } } }
final String structName = ((StructNameType) targetType).getName(); final StructDefinitionType sdt = fuzzingContext.getCurrentScope().lookupStructName(structName); if (sdt == null) { throw new RuntimeException("Could not find a struct named " + structName + " in scope.");
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()); } } }