public ScopeEntry lookupScopeEntry(String name) { if (variableMapping.containsKey(name)) { return variableMapping.get(name); } if (parent != null) { return parent.lookupScopeEntry(name); } return null; }
/** * 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; }
Map<String, Type> getGlobalsFromShader(TranslationUnit shader) { visit(shader); Map<String, Type> result = new HashMap<>(); for (String globalName : currentScope.keys()) { result.put(globalName, currentScope.lookupType(globalName)); } return result; } }.getGlobalsFromShader(shader);
@Override protected void popScope() { for (String name : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(name); if (entry.hasVariableDeclInfo() && !referencedScopeEntries.peek().contains(entry)) { if (allowedToReduceLocalDecl(entry.getVariableDeclInfo())) { assert currentScope.lookupScopeEntry(name) == entry || currentScope.getParent().lookupScopeEntry(name) == entry; if (!currentScope.keys().contains(name)) { addReferencedScopeEntry(entry);
private void getReductionOpportunitiesForUnusedGlobals() { for (String name : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(name); assert entry.hasVariableDeclInfo(); assert referencedScopeEntries.peek() != null; if (!referencedScopeEntries.peek().contains(entry)) { addOpportunity(new VariableDeclReductionOpportunity(entry.getVariableDeclInfo(), entry.getVariablesDeclaration(), getVistitationDepth())); } } }
@Override public void visitStructNameType(StructNameType structNameType) { super.visitStructNameType(structNameType); unusedStructs.remove(currentScope.lookupStructName(structNameType.getName())); }
private boolean referencesArray(Expr rhs) { return getReferencedVariables(rhs).stream() .anyMatch(item -> scopeOfStmt.lookupType(item) != null && scopeOfStmt.lookupType(item).getWithoutQualifiers() instanceof ArrayType); }
private Stream<IExprTemplate> availableTemplatesFromContext() { List<IExprTemplate> available = new LinkedList<>(); for (String name : fuzzingContext.getCurrentScope().namesOfAllVariablesInScope()) { available.add(new VariableIdentifierExprTemplate(name, fuzzingContext.getCurrentScope().lookupType(name))); } for (FunctionPrototype proto : fuzzingContext.getFunctionPrototypes()) { available.add(new FunctionCallExprTemplate(proto)); } return available.stream(); }
@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); }
/** * Clones the scope, recursively cloning all parents, but does not deep-clone the mappings. * @return Cloned scope */ public Scope shallowClone() { Scope result = new Scope(parent == null ? null : parent.shallowClone()); for (Entry<String, ScopeEntry> entry : variableMapping.entrySet()) { result.variableMapping.put(entry.getKey(), entry.getValue()); } for (Entry<String, StructDefinitionType> entry : structMapping.entrySet()) { result.structMapping.put(entry.getKey(), entry.getValue()); } return result; }
protected void pushScope() { Scope newScope = new Scope(currentScope); currentScope = newScope; }
public List<String> namesOfAllVariablesInScope() { List<String> result = new ArrayList<>(); Scope scope = this; while (scope != null) { result.addAll(scope.keys()); scope = scope.parent; } result.sort(String::compareTo); return Collections.unmodifiableList(result); }
public void leaveScope() { currentScope = currentScope.getParent(); }
final Scope scopeForFuzzing = injectionPoint.scopeAtInjectionPoint().shallowClone(); for (StructDefinitionType sdt : donationContext.getAvailableStructs()) { scopeForFuzzing.addStructDefinition(sdt);
/** * Removes and returns scope entry associated with the given name, if present. Otherwise * delegates removal to parent scope, if one exists. Otherwise returns null to indicate that * nothing was removed. * @param name Name of the key to be removed * @return Scope entry that has been removed, or null if no removal took place */ public ScopeEntry remove(String name) { if (variableMapping.containsKey(name)) { return variableMapping.remove(name); } if (hasParent()) { return parent.remove(name); } return null; }
InjectionPoint(FunctionDefinition enclosingFunction, boolean inLoop, Scope scope) { this.enclosingFunction = enclosingFunction; this.inLoop = inLoop; this.scope = scope.shallowClone(); }
public void addGlobal(String name, Type type) { findRootScope().add(name, type, Optional.empty()); }
protected boolean atGlobalScope() { return !currentScope.hasParent(); }