<commit_before>/**
 * Copyright (C) 2013 <NAME>
 * 
 * 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 program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package vasco;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * A generic forward-flow inter-procedural analysis which is fully
 * context-sensitive.
 * 
 * <p>
 * This class essentially captures a forward data flow problem which can be
 * solved using the context-sensitive inter-procedural analysis framework as
 * described in {@link InterProceduralAnalysis}.
 * </p>
 * 
 * <p>
 * This is the class that client analyses will extend in order to perform
 * forward-flow inter-procedural analysis.
 * </p>
 * 
 * @author <NAME>
 * 
 * @param <M> the type of a method
 * @param <N> the type of a node in the CFG
 * @param <A> the type of a data flow value
 */
public abstract class ForwardInterProceduralAnalysis<M,N,A> extends InterProceduralAnalysis<M,N,A> {

	/** Constructs a new forward-flow inter-procedural analysis. */
	public ForwardInterProceduralAnalysis() {
		// Kick-up to the super with the FORWARD direction.
		super(false);

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void doAnalysis() {

		// Initial contexts
		for (M method : programRepresentation().getEntryPoints()) {
			initContext(method, boundaryValue(method));
		}

		// Perform work-list based analysis
		N succ = null;
		while (!worklist.isEmpty()) {
			// Get the newest context on the work-list
			Context<M,N,A> currentContext = worklist.last();
			
			// If this context has no more nodes to analyze, then take it out of the work-list
			if (currentContext.getWorkList().isEmpty()) {
				worklist.remove(currentContext);
				continue;
			}


			// Remove the next node to process from the context's work-list
			N node = currentContext.getWorkList().pollFirst();
			if (!currentContext.getWorkList().isEmpty())
			{
				succ = currentContext.getWorkList().first();
			}

			if (node != null) {
				// Compute the IN data flow value (only for non-entry units).
				List<N> predecessors = currentContext.getControlFlowGraph().getPredsOf(node);
				if (predecessors.size() != 0) {
					// Initialise to the TOP value
					A in = topValue();					
					// Merge OUT values of all predecessors
					for (N pred : predecessors) {
						A predOut = currentContext.getValueAfter(pred);
						in = meet(in, predOut);
					}					
					// Set the IN value at the node to the result
					currentContext.setValueBefore(node, in);
				}
				<commit_msg>then worklist of current context is empty, then the context is analyzed<commit_after>/**
 * Copyright (C) 2013 <NAME>
 * 
 * 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 program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
package vasco;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * A generic forward-flow inter-procedural analysis which is fully
 * context-sensitive.
 * 
 * <p>
 * This class essentially captures a forward data flow problem which can be
 * solved using the context-sensitive inter-procedural analysis framework as
 * described in {@link InterProceduralAnalysis}.
 * </p>
 * 
 * <p>
 * This is the class that client analyses will extend in order to perform
 * forward-flow inter-procedural analysis.
 * </p>
 * 
 * @author <NAME>
 * 
 * @param <M> the type of a method
 * @param <N> the type of a node in the CFG
 * @param <A> the type of a data flow value
 */
public abstract class ForwardInterProceduralAnalysis<M,N,A> extends InterProceduralAnalysis<M,N,A> {

	/** Constructs a new forward-flow inter-procedural analysis. */
	public ForwardInterProceduralAnalysis() {
		// Kick-up to the super with the FORWARD direction.
		super(false);

	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void doAnalysis() {

		// Initial contexts
		for (M method : programRepresentation().getEntryPoints()) {
			initContext(method, boundaryValue(method));
		}

		// Perform work-list based analysis
		N succ = null;
		while (!worklist.isEmpty()) {
			// Get the newest context on the work-list
			Context<M,N,A> currentContext = worklist.last();
			
			// If this context has no more nodes to analyze, then take it out of the work-list
			if (currentContext.getWorkList().isEmpty()) {
				currentContext.markAnalysed();
				worklist.remove(currentContext);
				continue;
			}


			// Remove the next node to process from the context's work-list
			N node = currentContext.getWorkList().pollFirst();
			System.out.println(node);
			if (currentContext.getWorkList().isEmpty()) {
				succ = null;
			} else {
				succ = currentContext.getWorkList().first();
			}
			if (node != null) {
				// Compute the IN data flow value (only for non-entry units).
				List<N> predecessors = currentContext.getControlFlowGraph().getPredsOf(node);
				if (predecessors.size() != 0) {
					// Initialise to the TOP value
					A in = topValue();					
					// Merge OUT values of all predecessors
					for (N pred : predecessors) {
						A predOut = currentContext.getValueAfter(pred);
						in = meet(in, predOut);
					}					
					// Set the IN value at the node to the result
					currentContext.setValueBefore(node, in);
				}
				
{'fraction_non_alphanumeric': 0.1009159823120657, 'fraction_numerical': 0.0022109917877447885, 'mean_word_length': 3.2877454299255247, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '125189', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1763, 'n_words': 702}