@Override protected void popScope() { super.popScope(); System.out.println("Leaving a scope"); }
protected void leaveBlockStmt(BlockStmt stmt) { if (stmt.introducesNewScope()) { popScope(); } enclosingBlocks.removeFirst(); }
@Override public void visitWhileStmt(WhileStmt whileStmt) { pushScope(); super.visitWhileStmt(whileStmt); popScope(); }
@Override public void visitForStmt(ForStmt forStmt) { pushScope(); super.visitForStmt(forStmt); popScope(); }
/** * Because WebGL places limits on for loops it can be convenient to only visit the body of a * for loop, skipping the header. Subclasses can call this method to invoke this behaviour * during visitation, instead of calling super.visitForStmt(...). * * @param forStmt For statement whose body should be visited */ protected void visitForStmtBodyOnly(ForStmt forStmt) { pushScope(); visit(forStmt.getBody()); popScope(); }
@Override protected void popScope() { assert lastExitedBlock != null; if (!(parentMap.getParent(lastExitedBlock) instanceof SwitchStmt)) { List<MergeSet> mergeSetsForThisScope = new ArrayList<>(); for (String v : currentScope.keys()) { ScopeEntry entry = currentScope.lookupScopeEntry(v); if (!isCandidateForMerging(entry)) { continue; } List<MergeSet> mergeSetsWithSpace = mergeSetsForThisScope.stream() .filter(mergeSet -> mergeSet .canAccept(entry)).collect(Collectors.toList()); int index = generator.nextInt(mergeSetsWithSpace.size() + 1); if (index == mergeSetsWithSpace.size()) { MergeSet newMergeSet = new MergeSet(entry); mergeSetsForThisScope.add(newMergeSet); } else { mergeSetsWithSpace.get(index).add(entry); } } opportunities.addAll( mergeSetsForThisScope.stream().filter(mergeSet -> mergeSet.getNumVars() > 1) .map(mergeSet -> new VectorizationOpportunity(lastExitedBlock, mergeSet, parentMap)) .collect(Collectors.toList())); } super.popScope(); }
@Override public void visitFunctionDefinition(FunctionDefinition functionDefinition) { assert enclosingFunction == null; enclosingFunction = functionDefinition; pushScope(); addEncounteredParametersToScope = true; visitFunctionPrototype(functionDefinition.getPrototype()); addEncounteredParametersToScope = false; visit(functionDefinition.getBody()); popScope(); enclosingFunction = null; }