<commit_before>package natlab.toolkits.analysis;

import ast.*;
import java.util.*;

public abstract class AbstractStructuralForwardAnalysis<A extends FlowSet> extends AbstractStructuralAnalysis<A>
{

    public static boolean DEBUG = false;

    protected Stack<LoopFlowsets> loopStack = new Stack<LoopFlowsets>();

    public AbstractStructuralForwardAnalysis(ASTNode tree){
        super( tree );
    }

    /**
     * 
     * @param node The ASTNode that is being visited
     */
    public void caseASTNode(ASTNode node)
    {
        if( DEBUG ){
            System.out.println( "caseASTNode for node type " + node.getClass());
        }
        //visit each child node in forward order
        for( int i = 0; i<node.getNumChild(); i++ ){
            if( node.getChild(i) != null )
                analyze( node.getChild(i) );
        }
    }

    //program case

    //Break case
    //deal with the break by using the loop stack's breakInSets

    //continue case
    //deal with continues by using the loop stack's continueInSets

    //return case

    public abstract A processBreaks();
    public abstract A processContinues();

    public void caseForStmt( ForStmt node)
    {
        if(DEBUG)
            System.out.println( "caseForStmt" );
        //previousOut is used to track changes in the fixed point computation
        A previousOut;

        AssignStmt loopVar = node.getAssignStmt();
        ASTNode body = node.getStmts();

        //saving the in set of the loop
        A loopInSet = newInitialFlow();
        copy( currentInSet, loopInSet );
        inFlowSets.put( node, loopInSet );

        //process loop variable and store result

        //treat as init
        //note In for loop var as init will bee loopInSet
        caseLoopVarAsInit( loopVar );
        
        //treat as condition
        //note In will be out of loop var as init
        currentInSet = currentOutSet;
        caseLoopVarAsCondition( loopVar );

        //setup loop sets for loopstack 
        LoopFlowsets loopFlowsets = new LoopFlowsets( node );
        loopFlowsets.setLoopInSet( loopInSet );
        loopStack.push( loopFlowsets );
        
        A continueSet;
        A breakSet;
        A mergedOut;
        A newOut;
        
        if(DEBUG)
            System.out.println( "  forstmt: starting fixed point");
        do{
            //Store the current out in previousOut for later
            //comparison
            previousOut = newInitialFlow();
            copy( currentOutSet, previousOut );

            //initialize the continue and break lists
            loopFlowsets.initLists();
            <commit_msg>some minor refactoring<commit_after>package natlab.toolkits.analysis;

import ast.*;
import java.util.*;

public abstract class AbstractStructuralForwardAnalysis<A extends FlowSet> extends AbstractStructuralAnalysis<A>
{

    public static boolean DEBUG = false;

    protected Stack<LoopFlowsets> loopStack = new Stack<LoopFlowsets>();

    public AbstractStructuralForwardAnalysis(ASTNode tree){
        super( tree );
    }

    /**
     * 
     * @param node The ASTNode that is being visited
     */
    public void caseASTNode(ASTNode node)
    {
        if( DEBUG ){
            System.out.println( "caseASTNode for node type " + node.getClass());
        }
        //visit each child node in forward order
        for( int i = 0; i<node.getNumChild(); i++ ){
            if( node.getChild(i) != null )
                analyze( node.getChild(i) );
        }
    }

    //program case

    //Break case
    //deal with the break by using the loop stack's breakInSets

    //continue case
    //deal with continues by using the loop stack's continueInSets

    //return case

    public abstract A processBreaks();
    public abstract A processContinues();

    protected A saveLoopInSet( ForStmt node )
    {
        A inSet = newInitialFlow();
        copy( currentInSet, inSet );
        inFlowSets.put( node, inSet );
        return inSet;
    }
    protected LoopFlowsets setupLoopStack( A loopIn, ForStmt node )
    {
        LoopFlowsets loopFlowsets = new LoopFlowsets( node );
        loopFlowsets.setLoopInSet( loopIn );
        loopStack.push( loopFlowsets );
        return loopFlowsets;
    }
    public void caseForStmt( ForStmt node)
    {
        if(DEBUG)
            System.out.println( "caseForStmt" );
        //previousOut is used to track changes in the fixed point computation
        A previousOut;

        AssignStmt loopVar = node.getAssignStmt();
        ASTNode body = node.getStmts();

        A loopInSet = saveLoopInSet( node );

        //note In for loopVar as init will be loopInSet
        caseLoopVarAsInit( loopVar );
        
        currentInSet = currentOutSet;
        caseLoopVarAsCondition( loopVar );

        LoopFlowsets loopFlowsets = setupLoopStack( loopInSet, node );
        
        A continueSet;
        A breakSet;
        A mergedOut;
        A newOut;
        
        if(DEBUG)
            System.out.println( "  forstmt: starting fixed point");
        do{
            //Store the current out in previousOut for later
            //comparison
            previousOut = newInitialFlow();
            copy( currentOutSet, previousOut );

            //initialize the continue and break lists
            loopFlowsets.initLists();
            
{'fraction_non_alphanumeric': 0.08194574368568756, 'fraction_numerical': 0.00037418147801683815, 'mean_word_length': 2.0531125071387777, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6820209', 'n_tokens_mistral': 1457, 'n_tokens_neox': 1406, 'n_words': 458}