<commit_before>/*
 * Copyright 2010 2011 2012 2014 <NAME> <<EMAIL>>
 * Copyright 2011 2012 2013 2014 2015 2016 <NAME> <<EMAIL>>
 * See COPYING for terms of redistribution.
 */

#ifndef JIVE_RVSDG_NODE_H
#define JIVE_RVSDG_NODE_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <unordered_set>
#include <utility>

#include <jive/rvsdg/operation.h>
#include <jive/rvsdg/resource.h>
#include <jive/util/intrusive-list.h>
#include <jive/util/strfmt.h>

namespace jive {
namespace base {
	class type;
}

class gate;
class graph;
class node_normal_form;
class output;
class substitution_map;

/* inputs */

class input {
	friend jive::node;
	friend jive::region;

	jive::detail::intrusive_list_anchor<
		jive::input
	> gate_input_anchor_;

public:
	typedef jive::detail::intrusive_list_accessor<
		jive::input,
		&jive::input::gate_input_anchor_
	> gate_input_accessor;

	virtual
	~input() noexcept;

	input(
		size_t index,
		jive::output * origin,
		jive::region * region,
		const jive::port & port);

	input(const input &) = delete;

	input(input &&) = delete;

	input &
	operator=(const input &) = delete;

	input &
	operator=(input &&) = delete;

	inline size_t
	index() const noexcept
	{
		return index_;
	}

	jive::output *
	origin() const noexcept
	{
		return origin_;
	}

	void
	divert_to(jive::output * new_origin);

	inline const jive::type &
	type() const noexcept
	{
		return port_.type();
	}

	inline jive::region *
	region() const noexcept
	{
		return region_;
	}

	inline const jive::port &
	port() const noexcept
	{
		return port_;
	}

	virtual jive::node *
	node() const noexcept = 0;

	virtual std::string
	debug_string() const;

	inline void
	replace(const jive::port & port)
	{
		if (port_.type() != port.type())
			throw type_error(port_.type().debug_string(), port.type().debug_string());

		port_ = port;
	}

private:
	size_t index_;
	jive::port port_;
	jive::output * origin_;
	jive::region * region_;
};

/* outputs */

class output {
	friend input;
	friend jive::node;
	friend jive::region;

	typedef std::unordered_set<jive::input*>::const_iterator user_iterator;

	jive::detail::intrusive_list_anchor<
		jive::output
	> gate_output_anchor_;

public:
	typedef jive::detail::intrusive_list_accessor<
		jive::output,
		&jive::output::gate_output_anchor_
	> gate_output_accessor;

	virtual
	~output() noexcept;

	output(
		size_t index,
		jive::region * region,
		const jive::port & port);

	output(const output &) = delete;

	output(output &&) = delete;

	output &
	operator=(const output &) = delete;

	output &
	operator=(output &&) = delete;

	inline size_t
	index() const noexcept
	{
		return index_;
	}

	inline size_t
	nusers() const noexcept
	{
		return users_.size();
	}

	inline void
	divert_users(jive::output * new_origin)
	{
		if (this == new_origin)
			return;

		while (users_.size())
			(*users_.begin())->divert_to(new_origin);
	}

	inline user_iterator
	begin() const noexcept
	{
		return users_.begin();
	}

	inline user_iterator
	end() const noexcept
	{
		return users_.end();
	}

	inline const jive::type &
	type() const noexcept
	{
		return port_.type();
	}

	inline jive::region *
	region() const noexcept
	{
		return region_;
	}

	inline const jive::port &
	port() const noexcept
	{
		return port_;
	}

	virtual jive::node *
	node() const noexcept = 0;

	virtual std::string
	debug_string() const;
<commit_msg>rvsdg: add replace method to output class<commit_after>/*
 * Copyright 2010 2011 2012 2014 <NAME> <<EMAIL>>
 * Copyright 2011 2012 2013 2014 2015 2016 <NAME> <<EMAIL>>
 * See COPYING for terms of redistribution.
 */

#ifndef JIVE_RVSDG_NODE_H
#define JIVE_RVSDG_NODE_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <unordered_set>
#include <utility>

#include <jive/rvsdg/operation.h>
#include <jive/rvsdg/resource.h>
#include <jive/util/intrusive-list.h>
#include <jive/util/strfmt.h>

namespace jive {
namespace base {
	class type;
}

class gate;
class graph;
class node_normal_form;
class output;
class substitution_map;

/* inputs */

class input {
	friend jive::node;
	friend jive::region;

	jive::detail::intrusive_list_anchor<
		jive::input
	> gate_input_anchor_;

public:
	typedef jive::detail::intrusive_list_accessor<
		jive::input,
		&jive::input::gate_input_anchor_
	> gate_input_accessor;

	virtual
	~input() noexcept;

	input(
		size_t index,
		jive::output * origin,
		jive::region * region,
		const jive::port & port);

	input(const input &) = delete;

	input(input &&) = delete;

	input &
	operator=(const input &) = delete;

	input &
	operator=(input &&) = delete;

	inline size_t
	index() const noexcept
	{
		return index_;
	}

	jive::output *
	origin() const noexcept
	{
		return origin_;
	}

	void
	divert_to(jive::output * new_origin);

	inline const jive::type &
	type() const noexcept
	{
		return port_.type();
	}

	inline jive::region *
	region() const noexcept
	{
		return region_;
	}

	inline const jive::port &
	port() const noexcept
	{
		return port_;
	}

	virtual jive::node *
	node() const noexcept = 0;

	virtual std::string
	debug_string() const;

	inline void
	replace(const jive::port & port)
	{
		if (port_.type() != port.type())
			throw type_error(port_.type().debug_string(), port.type().debug_string());

		port_ = port;
	}

private:
	size_t index_;
	jive::port port_;
	jive::output * origin_;
	jive::region * region_;
};

/* outputs */

class output {
	friend input;
	friend jive::node;
	friend jive::region;

	typedef std::unordered_set<jive::input*>::const_iterator user_iterator;

	jive::detail::intrusive_list_anchor<
		jive::output
	> gate_output_anchor_;

public:
	typedef jive::detail::intrusive_list_accessor<
		jive::output,
		&jive::output::gate_output_anchor_
	> gate_output_accessor;

	virtual
	~output() noexcept;

	output(
		size_t index,
		jive::region * region,
		const jive::port & port);

	output(const output &) = delete;

	output(output &&) = delete;

	output &
	operator=(const output &) = delete;

	output &
	operator=(output &&) = delete;

	inline size_t
	index() const noexcept
	{
		return index_;
	}

	inline size_t
	nusers() const noexcept
	{
		return users_.size();
	}

	inline void
	divert_users(jive::output * new_origin)
	{
		if (this == new_origin)
			return;

		while (users_.size())
			(*users_.begin())->divert_to(new_origin);
	}

	inline user_iterator
	begin() const noexcept
	{
		return users_.begin();
	}

	inline user_iterator
	end() const noexcept
	{
		return users_.end();
	}

	inline const jive::type &
	type() const noexcept
	{
		return port_.type();
	}

	inline jive::region *
	region() const noexcept
	{
		return region_;
	}

	inline const jive::port &
	port() const noexcept
	{
		return port_;
	}

	virtual jive::node *
	node() const noexcept = 0;

	virtual std::string
	debug_string() const;

	inline void
	replace(const jive::port & port)
	{
		if (port_.type() != port.type())
			throw type_error(port_.type().debug_string(), port.type().debug_string());

		port_ = port;
	}

{'fraction_non_alphanumeric': 0.1344055140723722, 'fraction_numerical': 0.012062033314187249, 'mean_word_length': 4.276515151515151, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 45, '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': '2851466', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2540, 'n_words': 597}