<commit_before>/* Soot - a J*va Optimization Framework
 * Copyright (C) 2003 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

package soot.shimple.internal;

import soot.*;
import soot.util.*;
import java.util.*;
import soot.shimple.*;
import soot.shimple.toolkits.scalar.*;
import soot.options.*;
import soot.jimple.*;
import soot.jimple.internal.*;
import soot.jimple.toolkits.base.*;
import soot.jimple.toolkits.scalar.*;
import soot.toolkits.graph.*;
import soot.toolkits.scalar.*;

/**
 * This class does the real high-level work.  It takes a Jimple body
 * or Jimple/Shimple hybrid body and produces pure Shimple.
 *
 * <p> The work is done in two main steps:
 *
 * <ol>
 * <li> Trivial Phi nodes are added.
 * <li> A renaming algorithm is executed.
 * </ol>
 *
 * <p> This class can also translate out of Shimple by producing an
 * equivalent Jimple body with all Phi nodes removed.
 *
 * <p> Note that this is an internal class, understanding it should
 * not be necessary from a user point-of-view and relying on it
 * directly is not recommended.
 *
 * @author <NAME>
 * @see soot.shimple.ShimpleBody
 * @see <a
 * href="http://citeseer.nj.nec.com/cytron91efficiently.html">Efficiently
 * Computing Static Single Assignment Form and the Control Dependence
 * Graph</a>
 **/
public class ShimpleBodyBuilder
{
    protected ShimpleBody body;
    protected ShimpleFactory sf;
    protected DominatorTree dt;
    protected DominanceFrontier df;
    protected BlockGraph cfg;

    /**
     * A fixed list of all original Locals.
     **/
    protected List origLocals;

    /**
     * An analysis class that allows us to verify that a variable is
     * guaranteed to be defined at program point P.  Used as an
     * accessory to tweaking our Phi node insertion algorithm.
     **/
    protected GuaranteedDefs gd;

    /**
     * Contains a list of all the Phi nodes added to the body by
     * current invocation.  Pre-existing Phi nodes are treated as
     * normal def/uses in the renaming algorithm.
     **/
    protected Set newPhiNodes;
    
    /**
     * Transforms the provided body to pure SSA form.
     **/
    public ShimpleBodyBuilder(ShimpleBody body)
    {
        this.body = body;
        sf = G.v().shimpleFactory;
        sf.setBody(body);
        initialize();
        transform();
    }
    
    public void initialize()
    {
        sf.clearCache();
        cfg = sf.getBlockGraph();
        dt = sf.getDominatorTree();
        df = sf.getDominanceFrontier();
        gd = new GuaranteedDefs(sf.getUnitGraph());<commit_msg>Fix for bug #7.<commit_after>/* Soot - a J*va Optimization Framework
 * Copyright (C) 2003 <NAME> <<EMAIL>>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */

package soot.shimple.internal;

import soot.*;
import soot.util.*;
import java.util.*;
import soot.shimple.*;
import soot.shimple.toolkits.scalar.*;
import soot.options.*;
import soot.jimple.*;
import soot.jimple.internal.*;
import soot.jimple.toolkits.base.*;
import soot.jimple.toolkits.scalar.*;
import soot.toolkits.graph.*;
import soot.toolkits.scalar.*;

/**
 * This class does the real high-level work.  It takes a Jimple body
 * or Jimple/Shimple hybrid body and produces pure Shimple.
 *
 * <p> The work is done in two main steps:
 *
 * <ol>
 * <li> Trivial Phi nodes are added.
 * <li> A renaming algorithm is executed.
 * </ol>
 *
 * <p> This class can also translate out of Shimple by producing an
 * equivalent Jimple body with all Phi nodes removed.
 *
 * <p> Note that this is an internal class, understanding it should
 * not be necessary from a user point-of-view and relying on it
 * directly is not recommended.
 *
 * @author <NAME>
 * @see soot.shimple.ShimpleBody
 * @see <a
 * href="http://citeseer.nj.nec.com/cytron91efficiently.html">Efficiently
 * Computing Static Single Assignment Form and the Control Dependence
 * Graph</a>
 **/
public class ShimpleBodyBuilder
{
    protected ShimpleBody body;
    protected ShimpleFactory sf;
    protected DominatorTree dt;
    protected DominanceFrontier df;
    protected BlockGraph cfg;

    /**
     * A fixed list of all original Locals.
     **/
    protected List origLocals;

    /**
     * An analysis class that allows us to verify that a variable is
     * guaranteed to be defined at program point P.  Used as an
     * accessory to tweaking our Phi node insertion algorithm.
     **/
    protected GuaranteedDefs gd;

    /**
     * Contains a list of all the Phi nodes added to the body by
     * current invocation.  Pre-existing Phi nodes are treated as
     * normal def/uses in the renaming algorithm.
     **/
    protected Set newPhiNodes;
    
    /**
     * Transforms the provided body to pure SSA form.
     **/
    public ShimpleBodyBuilder(ShimpleBody body)
    {
        this.body = body;

        // Jimple sometimes assigns the same variable name to different locals.
        // Since our local name tables currently index on the String name, this
        // caused bug #7.  By ensuring unique local names we avoid the problem.
        // Jimple probably shouldn't do that though.
        makeUniqueLocalNames(body); 

        sf = G.v().shimpleFactory;
        sf.setBody(body);
        initialize();
        transform();
    }
    
    public void initialize()
    {
        sf.clearCache();
        cfg = sf.getBlockGraph();
        dt = sf.getDominatorTree();
        df = sf.getDominanceFrontier();
        gd = new GuaranteedDefs(sf.getUnitGraph());
{'fraction_non_alphanumeric': 0.08871436881908086, 'fraction_numerical': 0.006689936009307737, 'mean_word_length': 2.965974625144175, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, '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': '5319006', 'n_tokens_mistral': 2037, 'n_tokens_neox': 1901, 'n_words': 807}