<commit_before>/* 
 * Copyright LWJGL. All rights reserved.
 * License terms: http://lwjgl.org/license.php
 */
package org.lwjgl.generator

import java.nio.*
import org.lwjgl.PointerBuffer

open class NativeType(
	/** The type used in the native API. */
	val name: String,
	/** The type we map the native type to. */
	val mapping: TypeMapping
) {

	// Lets get rid a level of indirection

	/** The JNI function argument type. */
	val jniFunctionType: String
		get() = mapping.jniFunctionType

	/** The native method argument type. */
	val nativeMethodType: Class<out Any>
		get() = mapping.nativeMethodType

	/** The Java method argument type. */
	val javaMethodType: Class<out Any>
		get() = mapping.javaMethodType

}

// Specialization for primitives.
open class PrimitiveType(name: String, mapping: PrimitiveMapping): NativeType(name, mapping)
// Specialization for integers.
open class IntegerType(name: String, mapping: PrimitiveMapping, val unsigned: Boolean = false): PrimitiveType(name, mapping)
open class EnumType(name: String): IntegerType(name, PrimitiveMapping.INT, unsigned = true)
// Specialization for string characters.
class CharType(name: String, mapping: CharMapping): PrimitiveType(name, mapping)
// "typedef"
fun PrimitiveType(name: String, typedef: PrimitiveType) = PrimitiveType(name, typedef.mapping as PrimitiveMapping)
fun PrimitiveType(name: String, typedef: IntegerType) = IntegerType(name, typedef.mapping as PrimitiveMapping, typedef.unsigned)

// Pointers
open class PointerType(
	/** The type used in the native API. */
	name: String,
	/** The type we map the native type to. */
	mapping: PointerMapping = PointerMapping.OPAQUE_POINTER,
	/** If true, the nativeType typedef includes a pointer. */
	val includesPointer: Boolean = false,
	/** Optional element type. See the secondary constructors below. */
	val elementType: NativeType? = null
): NativeType(name, mapping)
/** Converts primitive to array */
fun PointerType(primitiveType: PrimitiveType) = PointerType(
	primitiveType.name,
	when ( primitiveType.mapping as PrimitiveMapping ) {
		PrimitiveMapping.BYTE   -> PointerMapping.DATA_BYTE
		PrimitiveMapping.SHORT  -> PointerMapping.DATA_SHORT
		PrimitiveMapping.INT    -> PointerMapping.DATA_INT
		PrimitiveMapping.LONG   -> PointerMapping.DATA_LONG
		PrimitiveMapping.PTR    -> PointerMapping.DATA_POINTER
		PrimitiveMapping.FLOAT  -> PointerMapping.DATA_FLOAT
		PrimitiveMapping.DOUBLE -> PointerMapping.DATA_DOUBLE
		else                    -> {
			throw IllegalArgumentException()
		}
	},
	elementType = primitiveType
)
/** pointer to pointer. */
fun PointerType(pointerType: PointerType) =
	PointerType(
		if ( pointerType.includesPointer )
			pointerType.name
		else
			"${pointerType.name} *",
		PointerMapping.DATA_POINTER,
		elementType = pointerType
	)

// Objects (pointer wrappers)
class ObjectType(
	/** The Java wrapper class. */
	val className: String,
	/** The type used in the native API. */
	name: String,
	/** If true, the nativeType typedef includes a pointer. */
	includesPointer: Boolean = true
): PointerType(name, PointerMapping.OPAQUE_POINTER, includesPointer)

// Structs
class StructType(
	/** The struct size in bytes. */
	val definition: Struct,
	/** The type used in the native API. */
	name: String = definition.nativeName,<commit_msg>Added support for pointer to const pointer types.<commit_after>/* 
 * Copyright LWJGL. All rights reserved.
 * License terms: http://lwjgl.org/license.php
 */
package org.lwjgl.generator

import java.nio.*
import org.lwjgl.PointerBuffer

open class NativeType(
	/** The type used in the native API. */
	val name: String,
	/** The type we map the native type to. */
	val mapping: TypeMapping
) {

	// Lets get rid a level of indirection

	/** The JNI function argument type. */
	val jniFunctionType: String
		get() = mapping.jniFunctionType

	/** The native method argument type. */
	val nativeMethodType: Class<out Any>
		get() = mapping.nativeMethodType

	/** The Java method argument type. */
	val javaMethodType: Class<out Any>
		get() = mapping.javaMethodType

}

// Specialization for primitives.
open class PrimitiveType(name: String, mapping: PrimitiveMapping): NativeType(name, mapping)
// Specialization for integers.
open class IntegerType(name: String, mapping: PrimitiveMapping, val unsigned: Boolean = false): PrimitiveType(name, mapping)
open class EnumType(name: String): IntegerType(name, PrimitiveMapping.INT, unsigned = true)
// Specialization for string characters.
class CharType(name: String, mapping: CharMapping): PrimitiveType(name, mapping)
// "typedef"
fun PrimitiveType(name: String, typedef: PrimitiveType) = PrimitiveType(name, typedef.mapping as PrimitiveMapping)
fun PrimitiveType(name: String, typedef: IntegerType) = IntegerType(name, typedef.mapping as PrimitiveMapping, typedef.unsigned)

// Pointers
open class PointerType(
	/** The type used in the native API. */
	name: String,
	/** The type we map the native type to. */
	mapping: PointerMapping = PointerMapping.OPAQUE_POINTER,
	/** If true, the nativeType typedef includes a pointer. */
	val includesPointer: Boolean = false,
	/** Optional element type. See the secondary constructors below. */
	val elementType: NativeType? = null
): NativeType(name, mapping)
/** Converts primitive to array */
fun PointerType(primitiveType: PrimitiveType) = PointerType(
	primitiveType.name,
	when ( primitiveType.mapping as PrimitiveMapping ) {
		PrimitiveMapping.BYTE   -> PointerMapping.DATA_BYTE
		PrimitiveMapping.SHORT  -> PointerMapping.DATA_SHORT
		PrimitiveMapping.INT    -> PointerMapping.DATA_INT
		PrimitiveMapping.LONG   -> PointerMapping.DATA_LONG
		PrimitiveMapping.PTR    -> PointerMapping.DATA_POINTER
		PrimitiveMapping.FLOAT  -> PointerMapping.DATA_FLOAT
		PrimitiveMapping.DOUBLE -> PointerMapping.DATA_DOUBLE
		else                    -> {
			throw IllegalArgumentException()
		}
	},
	elementType = primitiveType
)
/** pointer to pointer. */
fun PointerType(pointerType: PointerType, const: Boolean = false) =
	PointerType(
		"${pointerType.name}${if ( pointerType.includesPointer ) "" else " *"}${if ( const ) " const" else ""}",
		PointerMapping.DATA_POINTER,
		elementType = pointerType
	)

// Objects (pointer wrappers)
class ObjectType(
	/** The Java wrapper class. */
	val className: String,
	/** The type used in the native API. */
	name: String,
	/** If true, the nativeType typedef includes a pointer. */
	includesPointer: Boolean = true
): PointerType(name, PointerMapping.OPAQUE_POINTER, includesPointer)

// Structs
class StructType(
	/** The struct size in bytes. */
	val definition: Struct,
	/** The type used in the native API. */
	name: String = definition.nativeName,
{'fraction_non_alphanumeric': 0.10539692031693826, 'fraction_numerical': 0.0, 'mean_word_length': 4.347721822541966, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3619813', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1890, 'n_words': 603}