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

#include <jive/types/bitstring/constant.h>

#include <string.h>

#include <jive/types/bitstring/type.h>
#include <jive/util/buffer.h>
#include <jive/vsdg/graph.h>
#include <jive/vsdg/node-private.h>
#include <jive/vsdg/operators.h>
#include <jive/vsdg/region.h>

static void
jive_bitconstant_node_init_(
	jive_bitconstant_node * self,
	jive_region * region,
	size_t nbits, const char bits[]);

static void
jive_bitconstant_node_fini_(jive_node * self);

static void
jive_bitconstant_node_get_label_(const jive_node * self, struct jive_buffer * buffer);

static const jive_node_attrs *
jive_bitconstant_node_get_attrs_(const jive_node * self);

static bool
jive_bitconstant_node_match_attrs_(const jive_node * self, const jive_node_attrs * attrs);

static jive_node *
jive_bitconstant_node_create_(struct jive_region * region, const jive_node_attrs * attrs,
	size_t noperands, struct jive_output * const operands[]);

const jive_node_class JIVE_BITCONSTANT_NODE = {
	.parent = &JIVE_NULLARY_OPERATION,
	.fini = jive_bitconstant_node_fini_, /* override */
	.get_default_normal_form = jive_nullary_operation_get_default_normal_form_, /* inherit */
	.get_label = jive_bitconstant_node_get_label_, /* override */
	.get_attrs = jive_bitconstant_node_get_attrs_, /* override */
	.match_attrs = jive_bitconstant_node_match_attrs_, /* override */
	.check_operands = jive_node_check_operands_, /* inherit */
	.create = jive_bitconstant_node_create_, /* override */
	.get_aux_rescls = jive_node_get_aux_rescls_ /* inherit */
};

static void
jive_bitconstant_node_init_(
	jive_bitconstant_node * self,
	jive_region * region,
	size_t nbits, const char bits[])
{
	JIVE_DEBUG_ASSERT(nbits != 0);
	JIVE_DECLARE_BITSTRING_TYPE(type, nbits);
	jive_node_init_(&self->base, region,
		0, NULL, NULL,
		1, &type);
	self->attrs.nbits = nbits;
	self->attrs.bits = jive_context_malloc(region->graph->context, nbits);
	size_t n;
	for(n=0; n<nbits; n++) self->attrs.bits[n] = bits[n];
}

static void
jive_bitconstant_node_fini_(jive_node * self_)
{
	jive_bitconstant_node * self = (jive_bitconstant_node *) self_;
	jive_context_free(self->base.graph->context, self->attrs.bits);
	jive_node_fini_(&self->base);<commit_msg>bitstring: replace debug assertion through run-time error in bitconstant<commit_after>/*
 * Copyright 2011 2012 2013 <NAME> <<EMAIL>>
 * See COPYING for terms of redistribution.
 */

#include <jive/types/bitstring/constant.h>

#include <string.h>

#include <jive/types/bitstring/type.h>
#include <jive/util/buffer.h>
#include <jive/vsdg/graph.h>
#include <jive/vsdg/node-private.h>
#include <jive/vsdg/operators.h>
#include <jive/vsdg/region.h>

static void
jive_bitconstant_node_init_(
	jive_bitconstant_node * self,
	jive_region * region,
	size_t nbits, const char bits[]);

static void
jive_bitconstant_node_fini_(jive_node * self);

static void
jive_bitconstant_node_get_label_(const jive_node * self, struct jive_buffer * buffer);

static const jive_node_attrs *
jive_bitconstant_node_get_attrs_(const jive_node * self);

static bool
jive_bitconstant_node_match_attrs_(const jive_node * self, const jive_node_attrs * attrs);

static jive_node *
jive_bitconstant_node_create_(struct jive_region * region, const jive_node_attrs * attrs,
	size_t noperands, struct jive_output * const operands[]);

const jive_node_class JIVE_BITCONSTANT_NODE = {
	.parent = &JIVE_NULLARY_OPERATION,
	.fini = jive_bitconstant_node_fini_, /* override */
	.get_default_normal_form = jive_nullary_operation_get_default_normal_form_, /* inherit */
	.get_label = jive_bitconstant_node_get_label_, /* override */
	.get_attrs = jive_bitconstant_node_get_attrs_, /* override */
	.match_attrs = jive_bitconstant_node_match_attrs_, /* override */
	.check_operands = jive_node_check_operands_, /* inherit */
	.create = jive_bitconstant_node_create_, /* override */
	.get_aux_rescls = jive_node_get_aux_rescls_ /* inherit */
};

static void
jive_bitconstant_node_init_(
	jive_bitconstant_node * self,
	jive_region * region,
	size_t nbits, const char bits[])
{
	if (nbits == 0)
		jive_context_fatal_error(region->graph->context,
			"bitconstant: number of bits must be greater than zero.");

	JIVE_DECLARE_BITSTRING_TYPE(type, nbits);
	jive_node_init_(&self->base, region,
		0, NULL, NULL,
		1, &type);
	self->attrs.nbits = nbits;
	self->attrs.bits = jive_context_malloc(region->graph->context, nbits);
	size_t n;
	for(n=0; n<nbits; n++) self->attrs.bits[n] = bits[n];
}

static void
jive_bitconstant_node_fini_(jive_node * self_)
{
	jive_bitconstant_node * self = (jive_bitconstant_node *) self_;
	jive_context_free(self->base.graph->context, self->attrs.bits);
	jive_node_fini_(&self->base);
{'fraction_non_alphanumeric': 0.11467505241090147, 'fraction_numerical': 0.0067085953878406705, 'mean_word_length': 6.016176470588236, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, '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': '5084804', 'n_tokens_mistral': 1819, 'n_tokens_neox': 1782, 'n_words': 330}