@Override public void visitMemberLookupExpr(MemberLookupExpr memberLookupExpr) { super.visitMemberLookupExpr(memberLookupExpr); isUsed |= isComponentAccess(memberLookupExpr, currentScope); }
@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; }
@Override public void visitFunctionDefinition(FunctionDefinition functionDefinition) { currentFunction = functionDefinition; super.visitFunctionDefinition(functionDefinition); currentFunction = null; }
/** * 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 public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); if (inBlock && possiblyShadowedScopeEntry != null && currentScope.lookupScopeEntry(variableIdentifierExpr.getName()) == possiblyShadowedScopeEntry) { ok = false; } }
@Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { assert !currentVariablesDeclaration.isPresent(); currentVariablesDeclaration = Optional.of(variablesDeclaration); super.visitVariablesDeclaration(variablesDeclaration); currentVariablesDeclaration = Optional.empty(); }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { super.visitFunctionCallExpr(functionCallExpr); final String enclosingFunctionName = enclosingFunction.getPrototype().getName(); final String calledFunctionName = functionCallExpr.getCallee(); assert callsIndirectly.containsKey(enclosingFunctionName); if (!callsIndirectly.containsKey(calledFunctionName)) { return; } for (String function : callsIndirectly.keySet()) { if (callsIndirectly.get(function).contains(enclosingFunctionName)) { callsIndirectly.get(function).addAll(callsIndirectly .get(calledFunctionName)); } } }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { super.visitFunctionPrototype(functionPrototype); String name = functionPrototype.getName(); if (!userDefinedFunctions.containsKey(name)) { userDefinedFunctions.put(name, new HashSet<>()); } userDefinedFunctions.get(name).add(functionPrototype); }
@Override public void visitUnaryExpr(UnaryExpr unaryExpr) { super.visitUnaryExpr(unaryExpr); // TODO: need to check, but as a first approximation a unary always returns the same type as // its argument Type argType = types.get(unaryExpr.getExpr()); if (argType != null) { types.put(unaryExpr, argType); } }
@Override public void visitTypeConstructorExpr(TypeConstructorExpr typeConstructorExpr) { super.visitTypeConstructorExpr(typeConstructorExpr); identifyMutationPoints(typeConstructorExpr); }
@Override protected void popScope() { super.popScope(); System.out.println("Leaving a scope"); }
@Override public void visitBlockStmt(BlockStmt stmt) { enterBlockStmt(stmt); super.visitBlockStmt(stmt); leaveBlockStmt(stmt); }
@Override protected void leaveBlockStmt(BlockStmt stmt) { lastExitedBlock = stmt; super.leaveBlockStmt(stmt); }
@Override public void visitVariableIdentifierExpr(VariableIdentifierExpr variableIdentifierExpr) { super.visitVariableIdentifierExpr(variableIdentifierExpr); if (arrayIndexDepth > 0 && currentScope.lookupScopeEntry(variableIdentifierExpr.getName()) == null) { // A free variable that appears under an array index found = true; } }
@Override public void visitVariablesDeclaration(VariablesDeclaration variablesDeclaration) { assert enclosingVariablesDeclarationType == null; enclosingVariablesDeclarationType = variablesDeclaration.getBaseType(); super.visitVariablesDeclaration(variablesDeclaration); enclosingVariablesDeclarationType = null; }
@Override public void visitFunctionCallExpr(FunctionCallExpr functionCallExpr) { functionCallExpr.setCallee(applyFunctionNameMapping(functionCallExpr.getCallee())); super.visitFunctionCallExpr(functionCallExpr); }
@Override public void visitFunctionPrototype(FunctionPrototype functionPrototype) { final Set<String> callSelf = new HashSet<>(); callSelf.add(functionPrototype.getName()); callsIndirectly.put(functionPrototype.getName(), callSelf); super.visitFunctionPrototype(functionPrototype); }
@Override public void visitUnaryExpr(UnaryExpr unaryExpr) { if (unaryExpr.getOp().isSideEffecting()) { enterLValueContext(); } super.visitUnaryExpr(unaryExpr); if (unaryExpr.getOp().isSideEffecting()) { exitLValueContext(); } }