private void tryRemoveDeadAssignments ( NodeTraversal t , ControlFlowGraph < Node > cfg , Map < String , Var > allVarsInFn ) { Iterable < DiGraphNode < Node , Branch > > nodes = cfg . getDirectedGraphNodes ( ) ; for ( DiGraphNode < Node , Branch > cfgNode : nodes ) { FlowState < LiveVariableLattice > state = cfgNode . getAnnotation ( ) ; Node n = cfgNode . getValue ( ) ; if ( n == null ) { continue ; } switch ( n . getToken ( ) ) { case IF : case WHILE : case DO : tryRemoveAssignment ( t , NodeUtil . getConditionExpression ( n ) , state , allVarsInFn ) ; continue ; case FOR : case FOR_IN : case FOR_OF : case FOR_AWAIT_OF : if ( n . isVanillaFor ( ) ) { tryRemoveAssignment ( t , NodeUtil . getConditionExpression ( n ) , state , allVarsInFn ) ; } continue ; case SWITCH : case CASE : case RETURN : if ( n . hasChildren ( ) ) { tryRemoveAssignment ( t , n . getFirstChild ( ) , state , allVarsInFn ) ; } continue ; // TODO(user): case VAR: Remove var a=1;a=2;..... default : break ; } tryRemoveAssignment ( t , n , state , allVarsInFn ) ; } }
Try to remove useless assignments from a control flow graph that has been annotated with liveness information .