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

#ifndef MODC_MODULE_mh_reader_H
#define MODC_MODULE_mh_reader_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;

/**
 * mh_reader.mc - Parse modc-mh/1 export talbes for IMPORT ... FROM "*.mh".
 */

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

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

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

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

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

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

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

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

/* === TYPE EXPORT === */
typedef int MhCompleteness;

/** One formal in an export signature: [var|ref|const] [const] [^] Name */

/* === TYPE EXPORT === */
typedef struct MhFormal MhFormal;
typedef struct MhFormal {
    bool is_var;
    bool is_ref;
    bool is_const;
    bool type_is_const;
    bool type_is_pointer;
    char* type_name;
    size_t type_name_len;
    int type_width;
} MhFormal;

/** One field in an export type layout: name: [const] [^] Type */

/* === TYPE EXPORT === */
typedef struct MhField MhField;
typedef struct MhField {
    char* name;
    size_t name_len;
    bool type_is_const;
    bool type_is_pointer;
    char* type_name;
    size_t type_name_len;
    int type_width;
} MhField;

/* === TYPE EXPORT === */
typedef struct MhExport MhExport;
typedef struct MhExport {
    MhExportKind kind;
    bool is_extern;
    MhCompleteness completeness;
    char* name;
    size_t name_len;
    bool is_method;
    bool is_instance;
    char* method_owner;
    size_t method_owner_len;
    bool has_signature;
    MhFormal* formals;
    size_t formal_count;
    bool has_result;
    bool result_is_const;
    bool result_is_pointer;
    char* result_name;
    size_t result_name_len;
    int result_width;
    bool is_struct;
    bool is_union;
    char* extends_name;
    size_t extends_name_len;
    MhField* fields;
    size_t field_count;
    bool is_func_type;
} MhExport;

/* === TYPE EXPORT === */
typedef struct MhModule MhModule;
typedef struct MhModule {
    char* module_name;
    size_t module_name_len;
    int format_version;
    MhExport* exports;
    size_t count;
    size_t capacity;
    char* source;
    size_t source_len;
} MhModule;

/* === TYPE EXPORT === */
typedef char* pchar;

/* === TYPE EXPORT === */
typedef const char* pcchar;

/**
 * Strip optional surrounding quotes from a string-literal token.
 */

/* === PROC/FUNC EXPORT === */
bool mh_strip_string_literal(const char* path, size_t path_len, pcchar* inner, size_t* inner_len);

/**
 * Qualident (unquoted FROM) -> relative filesystem path with .mh suffix.
 e.g. fixtures.minimod -> fixtures/minimod.mh
 */

/* === PROC/FUNC EXPORT === */
bool mh_path_is_mh(const char* path, size_t path_len);

/**
 * Format the C #include path for a Mod-c import source (.mh symtab world).
 * Quoted "*.mh" -> same path with .h; qualident -> sources + .h.
 */

/* === PROC/FUNC EXPORT === */
bool mh_format_h_include(const char* from_path, size_t from_len, char* out, size_t out_cap);

/**
 * Resolve IMPORT apth relative to the compiling .mc file directory.
 */

/* === PROC/FUNC EXPORT === */
bool mh_resolve_import_path(const char* source_path, const char* from_path, size_t from_len, char* out, size_t out_cap);

/* === PROC/FUNC EXPORT === */
SymbolKind mh_export_to_symkind(MhExportKind kind);

/* === PROC/FUNC EXPORT === */
const MhExport* mh_module_find(const MhModule* m, const char* name, size_t name_len);

/* === PROC/FUNC EXPORT === */
void mh_module_free(MhModule* m);

/** --- line parser helpers (kept local) --- **/

/* === PROC/FUNC EXPORT === */
bool mh_reader_load(const char* resolved_path, MhModule* out);

void mh_reader(void);

#endif /* MODC_MODULE_mh_reader_H */
