<commit_before>/* Copyright 2016. <NAME>.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2016 <NAME> <<EMAIL>>
 */


#ifndef __TYPES_H
#define __TYPES_H

#define TYPE_CHECK(T, x)	(1 ? (x) : (T)0)
#define CONTAINER_OF(x, T, member)	\
	((T*)((char*)TYPE_CHECK(__typeof__(&((T*)0)->member), x) - offsetof(T, member)))


#define CAST_CONST(T, x)  ((T)TYPE_CHECK(const T, x))
#define CAST_DOWN(T, x)	({ \
	__typeof__(x) __tmp = (x); \
	extern __typeof__(*__tmp->TYPEID) T ## _TYPEID; \
	if (__tmp->TYPEID != &T ## _TYPEID) \
		error("run-time type check failed: %s\n", #T); \
	CONTAINER_OF(__tmp, struct T, INTERFACE);	\
})
#define CAST_UP(x) (&(x)->INTERFACE)

#define INTERFACE(X) X INTERFACE

typedef const struct typeid_s { int:0; } TYPEID;

#define TYPEID(T) T ## _TYPEID
#define DEF_TYPEID(T) TYPEID TYPEID(T)
#define SET_TYPEID(T, x) (TYPE_CHECK(struct T*, x)->INTERFACE.TYPEID = &TYPEID(T))<commit_msg>CAST_MAYBE<commit_after>/* Copyright 2016. <NAME>.
 * All rights reserved. Use of this source code is governed by
 * a BSD-style license which can be found in the LICENSE file.
 *
 * Authors:
 * 2016 <NAME> <<EMAIL>>
 */


#ifndef __TYPES_H
#define __TYPES_H

#define TYPE_CHECK(T, x)	(1 ? (x) : (T)0)
#define CONTAINER_OF(x, T, member)	\
	((T*)((char*)TYPE_CHECK(__typeof__(&((T*)0)->member), x) - offsetof(T, member)))


#define CAST_CONST(T, x)  ((T)TYPE_CHECK(const T, x))
#define CAST_MAYBE(T, x)	({ \
	__typeof__(x) __tmp = (x); \
	extern __typeof__(*__tmp->TYPEID) T ## _TYPEID; \
	(__tmp->TYPEID == &T ## _TYPEID) ?		\
		CONTAINER_OF(__tmp, struct T, INTERFACE)\
		: NULL;	\
})
#define CAST_DOWN(T, x)	({ \
	__typeof__(x) __tmp = (x); \
	extern __typeof__(*__tmp->TYPEID) T ## _TYPEID; \
	if (__tmp->TYPEID != &T ## _TYPEID) \
		error("run-time type check failed: %s\n", #T); \
	CONTAINER_OF(__tmp, struct T, INTERFACE);	\
})
#define CAST_UP(x) (&(x)->INTERFACE)

#define INTERFACE(X) X INTERFACE

typedef const struct typeid_s { int:0; } TYPEID;

#define TYPEID(T) T ## _TYPEID
#define DEF_TYPEID(T) TYPEID TYPEID(T)
#define SET_TYPEID(T, x) (TYPE_CHECK(struct T*, x)->INTERFACE.TYPEID = &TYPEID(T))
{'fraction_non_alphanumeric': 0.18461538461538463, 'fraction_numerical': 0.01085972850678733, 'mean_word_length': 4.5275, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 23, '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': '1599837', 'n_tokens_mistral': 939, 'n_tokens_neox': 901, 'n_words': 229}