/* =====================================
 * Generated by Mod-c 0.26.5
 * HEADER ttype MODULE
 * ===================================== */

#ifndef MODC_MODULE_ttype_H
#define MODC_MODULE_ttype_H

#include <stdint.h>
#include <stdbool.h>
#include <assert.h>

#define nil ((void *)0)
#define NIL nil
typedef uint8_t byte;
typedef const char* string;
typedef int integer;
typedef unsigned int cardinal;
typedef float real;

/**
 * Mod-c
 * By M. Scott Reynolds
 * 20 February 2026
 *
 * type.mc - Basic type representations.
 * 13 May 2026 - Extend for floating-point support.
 */

/* === IMPORT === */
#include "arena.h"

/* === IMPORT === */
#include "stddef.h"

/* === IMPORT === */
#include "stdio.h"

/* === IMPORT === */
#include "string.h"

/* === IMPORT === */
#include "stdbool.h"

/**
 * Simple type descriptor (v1 - string-based)
 * Later can become a tagged union with primitive, pointer, record, etc.
 * Future extensions:
 * fields, generics, etc.
 */

/* === TYPE EXPORT === */
typedef struct TType TType;
typedef struct TType {
    const char* name;
    size_t name_len;
    bool is_pointer;
    bool is_array;
    bool is_const;
    bool is_opaque;
    size_t array_size;
    pvoid size_expr;
    TType* element_type;
    TType* base_type;
    TType* resolved_type;
    int width;
} TType;

/* === TYPE EXPORT === */
typedef TType* pTType;

/**
 * Shallow arena copy of src.
 */

/* === PROC/FUNC EXPORT === */
TType* type_copy_shell(Arena* arena, const TType* src);

/**
 * True for a builtin type spelling (grammar prelude). Case-sensitive: only
 * lowercase spellings are reserved; e.g. String may be a user TYPE name.
 */

/* === PROC/FUNC EXPORT === */
bool type_is_builtin_name(const char* name, size_t name_len);

/**
 * Portable names that may be bound once per compilation unit (Language Report 5.5)
 * Not C names -- only integer/ cardinal / real / string.
 */

/* === PROC/FUNC EXPORT === */
bool type_is_portable_rebindable(const char* name, size_t name_len);

/**
 * Width constructors: integer N / cardinal n /real N (Langauge Report 10.1).
 */

/* === PROC/FUNC EXPORT === */
bool type_is_width_base(const char* name, size_t name_len);

/* === PROC/FUNC EXPORT === */
bool type_width_allowed(const char* name, size_t name_len, int n);

/**
 * C spelling for codegen. Width forms -> stdint / float / double.
 * Unqualified names stay as stored (integer, long long, ...).
 */

/* === PROC/FUNC EXPORT === */
bool type_c_spelling(const TType* t, string* out_s, size_t* out_len);

/**
 * Create a simple named type (copies name pointer + length)
 * Uses arena for allocation.
 */

/* === PROC/FUNC EXPORT === */
TType* type_create_named(Arena* arena, const char* name_start, size_t name_len);

/**
 * Create an array type (array_of_T or fixed-size).
 */

/* === PROC/FUNC EXPORT === */
TType* type_create_array(Arena* arena, TType* element, size_t fixed_size);

/**
 * Create a fixed array whose size is a const-expression (folded in semantic).
 * size_expr is a Node* stored as ^void (avoids ttype <==> node import cycle).
 */

/* === PROC/FUNC EXPORT === */
TType* type_create_array_expr(Arena* arena, TType* element, pvoid size_expr);

/**
 * Create opaque
 */

/* === PROC/FUNC EXPORT === */
TType* type_create_opaque(Arena* arena);

/**
 * Compare two types (name + structure).
 */

/* === PROC/FUNC EXPORT === */
bool type_equals(const TType* a, const TType* b);

/**
 * Print type
 */

/* === PROC/FUNC EXPORT === */
void type_print(const TType* t);

void ttype(void);

#endif /* MODC_MODULE_ttype_H */
