#ifndef WONKY_TYPE_H
#define WONKY_TYPE_H WONKY_TYPE_H
#include <type.hh>
#include <denoted.h>
#include <scope.h>
#include <limits.h>
#include <program.h>
#include <map.h>
#include <ast.h>
#include <common.h>
enum Type_Specifier;
enum Type_Constraint;
enum Type_Signedness;
struct Type
{
enum Type_Specifier specifier;
};
struct Type_Error
{
enum Type_Specifier specifier;
struct Type *error;
};
struct Type_Struct_Union
{
enum Type_Specifier specifier;
struct Struct_Union *struct_union;
_Bool is_const:1;
_Bool is_volatile:1;
};
struct Struct_Union
{
enum Type_Specifier specifier;
struct identifier *id;
size_t size;
/* queue of denoted objects for
* preserving the order of the members
* */
struct Queue *members;
struct Normal_Scope *inner_namespace;
_Bool is_finished:1;
_Bool has_constant_member:1;
};
struct Type_Basic
{
enum Type_Specifier specifier;
enum Type_Constraint constraint;
enum Type_Signedness sign;
size_t size;
_Bool is_const:1;
char is_volatile:1;
};
struct Type_Pointer
{
enum Type_Specifier specifier;
size_t size;
struct Type *points_to;
char is_const:1;
char is_volatile:1;
};
struct Type_Array
{
enum Type_Specifier specifier;
size_t size;
size_t number_of_elements;
struct Type *is_array_of;
};
struct Type_Variable_Length_Array
{
enum Type_Specifier specifier;
size_t size;
struct AST_Expression *number_of_elements;
struct Type *is_array_of;
};
struct Type_Function
{
enum Type_Specifier specifier;
struct Type *return_type;
/*types*/
size_t number_of_arguments;
struct Denoted_Object** arguments;
struct Normal_Scope *function_prototype_scope;
_Bool is_variadic;
};
struct Type_Enum
{
enum Type_Specifier specifier;
struct Enum *enumeration;
char is_const:1;
char is_volatile:1;
};
struct Enum
{
enum Type_Specifier specifier;
struct identifier *id;
struct Queue *consts;
char is_finished;
};
struct Type* get_type_error(struct Type *type);
struct Type* get_struct_union_type(struct Denotation_Prototype *prototype);
struct Struct_Union* get_struct_union_base(struct Scope *scope ,enum Type_Specifier struct_or_union,struct identifier *id);
struct Enum *get_enum_base(struct identifier *id);
struct Type* get_basic_type(struct Denotation_Prototype *prototype);
struct Type* get_pointer_type(struct Type *points_to,_Bool is_const,_Bool is_volatile);
struct Type* get_array_type(struct Type *array_of,struct AST* number_of_elements,struct Translation_Data *translation_data);
struct Type* get_array_type_raw(struct Type *array_of,size_t size);
struct Type* get_enum_type(struct Denotation_Prototype *prototype);
struct Type* get_function_type(struct Type *return_type,struct Queue *parameters,struct Normal_Scope* function_prototype_scope,_Bool is_variadic,struct Translation_Data *translation_data);
/*returns 0 if the rebasing of the type makes no sense*/
_Bool rebase_type(struct Type *rebase,struct Type *onto);
struct Type_Basic* get_type_insecure(enum Type_Specifier type_specifier,enum Type_Signedness sign,enum Type_Constraint constraint,size_t type_size);
struct Type* get_type_for_promotion(struct Type *type);
struct Type* get_unqualified_version_of_type(struct Type *type);
void delete_enum(struct Enum *enumeration);
void delete_struct_union(struct Struct_Union *su);
void delete_type(void *type);
_Bool is_type_name(struct Translation_Data *translation_data,struct Scope *scope);
size_t get_type_size(struct Type *type);
_Bool types_are_identical(struct Type *a,struct Type *b);
_Bool types_are_compatible(struct Type *a,struct Type *b);
_Bool types_are_compatible_unqualified(struct Type *a,struct Type *b);
_Bool types_are_compatible_inner(struct Type *a,struct Type *b);
_Bool types_of_pointers_are_compatible_unqualified(struct Type_Pointer *a,struct Type_Pointer *b);
_Bool types_of_arrays_are_compatible_unqualified(struct Type_Array *a,struct Type_Array *b);
_Bool types_of_functions_are_compatible_unqualified(struct Type_Function *a,struct Type_Function *b);
_Bool types_of_struct_unions_are_compatible_unqualified(struct Struct_Union *a,struct Struct_Union *b);
_Bool types_of_bitfields_are_compatible_unqalified(struct Type_Bit_Field *a,struct Type_Bit_Field *b);
_Bool types_of_enum_are_compatible_unqualified(struct Type_Enum *a,struct Type_Enum *b);
_Bool type_is_a_plain_signed_int(struct Type *type);
_Bool type_is_of_object(struct Type *type);
_Bool type_is_complete(struct Type *type);
_Bool type_is_integer_type(struct Type *type);
_Bool type_is_basic(struct Type *type);
_Bool type_is_character(struct Type *type);
_Bool type_is_arithmetic(struct Type *type);
_Bool type_is_scalar(struct Type *type);
_Bool type_is_aggregate(struct Type *type);
_Bool type_is_struct_union(struct Type *type);
_Bool type_is_constant_or_has_constant_member(struct Type *type);
_Bool type_is_qualified(struct Type *type);
_Bool type_is_pointer(struct Type *type);
_Bool type_is_pointer_to_object(struct Type *type);
_Bool type_is_pointer_to_incomplete_type(struct Type *type);
_Bool type_is_pointer_to_void(struct Type *type);
_Bool type_is_pointer_to_function(struct Type *type);
_Bool type_is_real(struct Type *type);
_Bool type_is_floating(struct Type *type);
_Bool type_is_derivative(struct Type *type);
_Bool type_is_a_variable_length_array(struct Type *type);
_Bool type_is_an_array(struct Type *type);
_Bool type_is_a_normal_string(struct Type *type);
/*these return 0 if constant/volatile-ness makes no sense for the type*/
_Bool type_is_constant(struct Type *type);
_Bool type_is_volatile(struct Type *type);
/*these return 0 if constant/volatile-ness makes no sense for the type*/
_Bool type_is_constant(struct Type *type);
_Bool type_is_volatile(struct Type *type);
int type_get_integer_conversion_rank(struct Type_Basic *type);
#endif