[qfcc] Make type_t mostly const-correct

There were a few places where some const-casts were needed, but they're
localized to code that's supposed to manipulate types (but I do want to
come up with something to clean that up).
This commit is contained in:
Bill Currie 2024-02-13 23:09:28 +09:00
parent 6e71aadfa4
commit f0dfe47a32
46 changed files with 451 additions and 450 deletions

View file

@ -65,12 +65,12 @@ typedef struct metric_s {
} metric_t;
typedef struct algebra_s {
type_t *type; ///< underlying type (float or double)
type_t *algebra_type; ///< type for algebra
const type_t *type; ///< underlying type (float or double)
const type_t *algebra_type; ///< type for algebra
metric_t metric;
basis_layout_t layout;
basis_group_t *groups;
type_t **mvec_types;
const type_t **mvec_types;
struct symbol_s *mvec_sym;
int num_components; ///< number of componets (2^d)
int dimension; ///< number of dimensions (plus + minus + zero)
@ -88,12 +88,12 @@ typedef struct multivector_s {
struct attribute_s;
bool is_algebra (const type_t *type) __attribute__((pure));
type_t *algebra_type (type_t *type, const expr_t *params);
type_t *algebra_subtype (type_t *type, struct attribute_s *attr);
type_t *algebra_mvec_type (algebra_t *algebra, pr_uint_t group_mask);
const type_t *algebra_type (const type_t *type, const expr_t *params);
const type_t *algebra_subtype (const type_t *type, struct attribute_s *attr);
const type_t *algebra_mvec_type (algebra_t *algebra, pr_uint_t group_mask);
int algebra_count_flips (const algebra_t *alg, pr_uint_t a, pr_uint_t b) __attribute__((pure));
struct ex_value_s *algebra_blade_value (algebra_t *alg, const char *name);
struct symtab_s *algebra_scope (type_t *type, struct symtab_s *curscope);
struct symtab_s *algebra_scope (const type_t *type, struct symtab_s *curscope);
algebra_t *algebra_context (const type_t *type) __attribute__((pure));
void algebra_print_type_str (struct dstring_s *str, const type_t *type);
void algebra_encode_type (struct dstring_s *encoding, const type_t *type);
@ -104,8 +104,8 @@ int metric_apply (const metric_t *metric, pr_uint_t a, pr_uint_t b) __attribute_
algebra_t *algebra_get (const type_t *type) __attribute__((pure));
int algebra_type_assignable (const type_t *dst, const type_t *src) __attribute__((pure));
type_t *algebra_base_type (const type_t *type) __attribute__((pure));
type_t *algebra_struct_type (const type_t *type) __attribute__((pure));
const type_t *algebra_base_type (const type_t *type) __attribute__((pure));
const type_t *algebra_struct_type (const type_t *type) __attribute__((pure));
bool is_mono_grade (const type_t *type) __attribute__((pure));
int algebra_get_grade (const type_t *type) __attribute__((pure));
int algebra_blade_grade (basis_blade_t blade) __attribute__((const));
@ -117,7 +117,7 @@ const expr_t *algebra_negate (const expr_t *e);
const expr_t *algebra_dual (const expr_t *e);
const expr_t *algebra_undual (const expr_t *e);
const expr_t *algebra_reverse (const expr_t *e);
const expr_t *algebra_cast_expr (type_t *dstType, const expr_t *e);
const expr_t *algebra_cast_expr (const type_t *dstType, const expr_t *e);
const expr_t *algebra_assign_expr (const expr_t *dst, const expr_t *src);
const expr_t *algebra_field_expr (const expr_t *mvec, const expr_t *field_name);
const expr_t *algebra_optimize (const expr_t *e);

View file

@ -56,7 +56,7 @@ typedef struct class_s {
struct methodlist_s *methods;
struct protocollist_s *protocols;
struct def_s *def;
struct type_s *type;
const struct type_s *type;
class_type_t class_type;
} class_t;
@ -147,7 +147,8 @@ void class_finish_ivar_scope (class_type_t *class_type,
struct symtab_s *param_scope);
struct method_s *class_find_method (class_type_t *class_type,
struct method_s *method);
struct method_s *class_message_response (struct type_s *clstype, int class_msg,
struct method_s *class_message_response (const struct type_s *clstype,
int class_msg,
const struct expr_s *sel);
struct symbol_s *class_pointer_symbol (class_t *class_type);
category_t *get_category (struct symbol_s *class_name,

View file

@ -62,7 +62,7 @@ typedef struct dagnode_s {
struct dagnode_s *killed; ///< node is unavailable for cse (by node)
st_type_t type; ///< type of node (st_none = leaf)
daglabel_t *label; ///< ident/const if leaf node, or operator
struct type_s *tl;
const struct type_s *tl;
struct operand_s *value; ///< operand holding the value of this node
/// \name child nodes
/// if \a children[0] is null, the rest must be null as well. Similar for
@ -75,7 +75,7 @@ typedef struct dagnode_s {
/// topological sort of the DAG.
//@{
struct dagnode_s *children[3];
struct type_s *types[3]; ///< desired type of each operand (to alias)
const struct type_s *types[3];///< desired type of each operand (to alias)
struct set_s *edges; ///< includes nodes pointed to by \a children
int offset; ///< for alias nodes
//@}

View file

@ -57,7 +57,7 @@ typedef struct def_s {
struct def_s *next; ///< general purpose linking
struct def_s *temp_next; ///< linked list of "free" temp defs
struct type_s *type; ///< QC type of this def
const struct type_s *type; ///< QC type of this def
const char *name; ///< the def's name
struct defspace_s *space; ///< defspace to which this def belongs
int offset; ///< address of this def in its defspace
@ -139,7 +139,7 @@ typedef enum storage_class_e {
\param storage The storage class for the def.
\return The new def.
*/
def_t *new_def (const char *name, struct type_s *type,
def_t *new_def (const char *name, const struct type_s *type,
struct defspace_s *space, storage_class_t storage);
/** Create a def that aliases another def.
@ -164,10 +164,10 @@ def_t *new_def (const char *name, struct type_s *type,
\todo Make aliasing to the same type a no-op?
*/
def_t *alias_def (def_t *def, struct type_s *type, int offset);
def_t *alias_def (def_t *def, const struct type_s *type, int offset);
//FIXME this probably shouldn't exist (it's for swizzles, so doing proper
//multi-width swizzles will remove the need for it)
def_t *cover_alias_def (def_t *def, struct type_s *type, int offset);
def_t *cover_alias_def (def_t *def, const struct type_s *type, int offset);
/** Free a def.
@ -203,7 +203,7 @@ void free_def (def_t *def);
\bug size of type must be 1 to 4.
\todo support arbitrary sizes
*/
def_t *temp_def (struct type_s *type);
def_t *temp_def (const struct type_s *type);
/** Free a tempary def so it may be recycled.

View file

@ -39,7 +39,7 @@
struct type_s;
struct ex_value_s;
struct ex_value_s *convert_value (struct ex_value_s *value,
struct type_s *type);
const struct type_s *type);
const struct expr_s *evaluate_constexpr (const struct expr_s *e);
void setup_value_progs (void);

View file

@ -90,7 +90,7 @@ typedef struct designator_s {
typedef struct element_s {
struct element_s *next; ///< next in chain
int offset;
type_t *type;
const type_t *type;
const expr_t *expr; ///< initializer expression
designator_t *designator; ///< for labeled initializers
} element_t;
@ -128,7 +128,7 @@ typedef struct {
} ex_temp_t;
typedef struct {
type_t *type; ///< Type of vector (vector/quaternion)
const type_t *type; ///< Type of vector (vector/quaternion)
ex_list_t list; ///< Linked list of element expressions.
} ex_vector_t;
@ -143,14 +143,14 @@ typedef struct {
*/
typedef struct ex_pointer_s {
int val;
type_t *type;
const type_t *type;
struct def_s *def;
struct operand_s *tempop;
} ex_pointer_t;
typedef struct ex_func_s {
int val;
type_t *type;
const type_t *type;
} ex_func_t;
typedef struct {
@ -213,7 +213,7 @@ typedef struct {
typedef struct ex_value_s {
struct ex_value_s *next;
struct daglabel_s *daglabel;///< dag label for this value
type_t *type;
const type_t *type;
etype_t lltype;
union {
const char *string_val; ///< string constant
@ -236,13 +236,13 @@ typedef struct ex_value_s {
} ex_value_t;
typedef struct {
type_t *type; ///< type to view the expression
const type_t *type; ///< type to view the expression
const expr_t *expr; ///< the expression to alias
const expr_t *offset; ///< offset for alias
} ex_alias_t;
typedef struct {
type_t *type; ///< pointer type
const type_t *type; ///< pointer type
const expr_t *lvalue; ///< the lvalue being addressed
const expr_t *offset; ///< offset from the address
} ex_address_t;
@ -258,7 +258,7 @@ typedef struct {
const expr_t *index; ///< index for indirect branches
const expr_t *test; ///< test expression (null for jump/call)
const expr_t *args; ///< only for call
type_t *ret_type; ///< void for non-call
const type_t *ret_type; ///< void for non-call
} ex_branch_t;
typedef struct {
@ -291,18 +291,18 @@ typedef struct {
unsigned source[4]; ///< src component indices
unsigned neg; ///< bitmask of dst components to negate
unsigned zero; ///< bitmask of dst components to 0
type_t *type; ///< result type
const type_t *type; ///< result type
} ex_swizzle_t;
typedef struct {
const expr_t *src; ///< source expression
int extend; ///< extend mode 0: 0, 1: 1, 2: copy/0 3:-1
bool reverse; ///< reverse resultant vector
type_t *type; ///< result type;
const type_t *type; ///< result type;
} ex_extend_t;
typedef struct {
type_t *type; ///< overall type of multivector
const type_t *type; ///< overall type of multivector
algebra_t *algebra; ///< owning algebra
ex_list_t components; ///< multivector components
} ex_multivec_t;
@ -364,8 +364,8 @@ extern const char *expr_names[];
const expr_t *type_mismatch (const expr_t *e1, const expr_t *e2, int op);
const expr_t *param_mismatch (const expr_t *e, int param, const char *fn,
struct type_s *t1, struct type_s *t2);
const expr_t *test_error (const expr_t *e, struct type_s *t);
const type_t *t1, const type_t *t2);
const expr_t *test_error (const expr_t *e, const type_t *t);
extern expr_t *local_expr;
@ -375,7 +375,7 @@ extern expr_t *local_expr;
\return Pointer to the type description, or null if the expression
type (expr_t::type) is inappropriate.
*/
type_t *get_type (const expr_t *e);
const type_t *get_type (const expr_t *e);
/** Get the basic type code of the expression result.
@ -543,7 +543,8 @@ expr_t *new_horizontal_expr (int op, const expr_t *vec, type_t *type);
const expr_t *new_swizzle_expr (const expr_t *src, const char *swizzle);
const expr_t *new_extend_expr (const expr_t *src, type_t *type, int ext, bool rev);
const expr_t *new_extend_expr (const expr_t *src, const type_t *type, int ext,
bool rev);
/** Create a new def reference (non-temporary variable) expression node.
@ -597,7 +598,7 @@ const expr_t *new_value_expr (ex_value_t *value);
\param type The type to use for the zero.
\return The new value expression.
*/
const expr_t *new_zero_expr (type_t *type);
const expr_t *new_zero_expr (const type_t *type);
/** Create a new symbol expression node from a name.
@ -661,7 +662,8 @@ const expr_t *new_entity_expr (int entity_val);
\return The new field constant expression node
(expr_t::e::field_val).
*/
const expr_t *new_field_expr (int field_val, type_t *type, struct def_s *def);
const expr_t *new_field_expr (int field_val, const type_t *type,
struct def_s *def);
struct symbol_s *get_struct_field (const type_t *t1, const expr_t *e1,
const expr_t *e2);
@ -672,7 +674,7 @@ struct symbol_s *get_struct_field (const type_t *t1, const expr_t *e1,
\return The new function constant expression node
(expr_t::e::func_val).
*/
const expr_t *new_func_expr (int func_val, type_t *type);
const expr_t *new_func_expr (int func_val, const type_t *type);
/** Create a new pointer constant expression node.
@ -682,7 +684,7 @@ const expr_t *new_func_expr (int func_val, type_t *type);
\return The new pointer constant expression node
(expr_t::e::pointer_val).
*/
const expr_t *new_pointer_expr (int val, type_t *type, struct def_s *def);
const expr_t *new_pointer_expr (int val, const type_t *type, struct def_s *def);
/** Create a new quaternion constant expression node.
@ -815,8 +817,8 @@ expr_t *new_this_expr (void);
*/
const expr_t *new_ret_expr (type_t *type);
const expr_t *new_alias_expr (type_t *type, const expr_t *expr);
const expr_t *new_offset_alias_expr (type_t *type, const expr_t *expr,
const expr_t *new_alias_expr (const type_t *type, const expr_t *expr);
const expr_t *new_offset_alias_expr (const type_t *type, const expr_t *expr,
int offset);
expr_t *new_address_expr (const type_t *lvtype, const expr_t *lvalue,
@ -833,7 +835,7 @@ expr_t *new_with_expr (int mode, int reg, const expr_t *val);
\param num The index of the parameter (0-7).
\return A new expression referencing the parameter slot.
*/
const expr_t *new_param_expr (type_t *type, int num);
const expr_t *new_param_expr (const type_t *type, int num);
expr_t *new_memset_expr (const expr_t *dst, const expr_t *val,
const expr_t *count);
@ -858,7 +860,7 @@ const expr_t *convert_nil (const expr_t *e, const type_t *t) __attribute__((warn
const expr_t *test_expr (const expr_t *e);
void backpatch (ex_boollist_t *list, const expr_t *label);
const expr_t *convert_bool (const expr_t *e, int block) __attribute__((warn_unused_result));
const expr_t *convert_from_bool (const expr_t *e, type_t *type) __attribute__((warn_unused_result));
const expr_t *convert_from_bool (const expr_t *e, const type_t *type) __attribute__((warn_unused_result));
const expr_t *bool_expr (int op, const expr_t *label, const expr_t *e1,
const expr_t *e2);
const expr_t *binary_expr (int op, const expr_t *e1, const expr_t *e2);
@ -874,7 +876,7 @@ const expr_t *branch_expr (int op, const expr_t *test, const expr_t *label);
const expr_t *goto_expr (const expr_t *label);
const expr_t *jump_table_expr (const expr_t *table, const expr_t *index);
const expr_t *call_expr (const expr_t *func, const expr_t *args,
type_t *ret_type);
const type_t *ret_type);
const expr_t *return_expr (struct function_s *f, const expr_t *e);
const expr_t *at_return_expr (struct function_s *f, const expr_t *e);
const expr_t *conditional_expr (const expr_t *cond, const expr_t *e1,
@ -883,7 +885,7 @@ const expr_t *incop_expr (int op, const expr_t *e, int postop);
const expr_t *array_expr (const expr_t *array, const expr_t *index);
const expr_t *deref_pointer_expr (const expr_t *pointer);
const expr_t *offset_pointer_expr (const expr_t *pointer, const expr_t *offset);
const expr_t *address_expr (const expr_t *e1, type_t *t);
const expr_t *address_expr (const expr_t *e1, const type_t *t);
const expr_t *build_if_statement (int not, const expr_t *test, const expr_t *s1,
const expr_t *els, const expr_t *s2);
const expr_t *build_while_statement (int not, const expr_t *test,
@ -902,8 +904,8 @@ const expr_t *build_state_expr (const expr_t *e);
const expr_t *think_expr (struct symbol_s *think_sym);
int is_lvalue (const expr_t *expr) __attribute__((pure));
const expr_t *assign_expr (const expr_t *dst, const expr_t *src);
const expr_t *cast_expr (type_t *t, const expr_t *e);
const expr_t *cast_error (const expr_t *e, type_t *t1, type_t *t2);
const expr_t *cast_expr (const type_t *t, const expr_t *e);
const expr_t *cast_error (const expr_t *e, const type_t *t1, const type_t *t2);
const char *get_op_string (int op) __attribute__((const));
@ -911,11 +913,11 @@ struct keywordarg_s;
struct class_type_s;
const expr_t *selector_expr (struct keywordarg_s *selector);
const expr_t *protocol_expr (const char *protocol);
const expr_t *encode_expr (type_t *type);
const expr_t *encode_expr (const type_t *type);
const expr_t *super_expr (struct class_type_s *class_type);
const expr_t *message_expr (const expr_t *receiver,
struct keywordarg_s *message);
const expr_t *sizeof_expr (const expr_t *expr, type_t *type);
const expr_t *sizeof_expr (const expr_t *expr, const type_t *type);
const expr_t *fold_constants (const expr_t *e);
@ -929,24 +931,24 @@ bool is_mult (const expr_t *expr) __attribute__((pure));
bool is_neg (const expr_t *expr) __attribute__((pure));
const expr_t *neg_expr (const expr_t *e);
const expr_t *ext_expr (const expr_t *src, type_t *type, int extend,
const expr_t *ext_expr (const expr_t *src, const type_t *type, int extend,
bool reverse);
const expr_t *scale_expr (type_t *type, const expr_t *a, const expr_t *b);
const expr_t *scale_expr (const type_t *type, const expr_t *a, const expr_t *b);
const expr_t *traverse_scale (const expr_t *expr) __attribute__((pure));
const expr_t *typed_binary_expr (type_t *type, int op,
const expr_t *typed_binary_expr (const type_t *type, int op,
const expr_t *e1, const expr_t *e2);
int count_terms (const expr_t *expr) __attribute__((pure));
void scatter_terms (const expr_t *sum,
const expr_t **adds, const expr_t **subs);
const expr_t *gather_terms (type_t *type,
const expr_t *gather_terms (const type_t *type,
const expr_t **adds, const expr_t **subs);
int count_factors (const expr_t *expr) __attribute__((pure));
void scatter_factors (const expr_t *prod, const expr_t **factors);
const expr_t *gather_factors (type_t *type, int op, const expr_t **factors,
int count);
const expr_t *gather_factors (const type_t *type, int op,
const expr_t **factors, int count);
///@}

View file

@ -137,7 +137,7 @@ extern function_t *current_func;
typedef struct param_s {
struct param_s *next;
const char *selector;
struct type_s *type;
const struct type_s *type;
const char *name;
struct symbol_s *symbol; //FIXME what is this for?
} param_t;
@ -146,20 +146,20 @@ struct expr_s;
struct symbol_s;
struct symtab_s;
param_t *new_param (const char *selector, struct type_s *type,
param_t *new_param (const char *selector, const struct type_s *type,
const char *name);
param_t *param_append_identifiers (param_t *params, struct symbol_s *idents,
struct type_s *type);
const struct type_s *type);
param_t *reverse_params (param_t *params);
param_t *append_params (param_t *params, param_t *more_params);
param_t *copy_params (param_t *params);
struct type_s *parse_params (struct type_s *return_type, param_t *params);
const struct type_s *parse_params (const struct type_s *return_type, param_t *params);
param_t *check_params (param_t *params);
enum storage_class_e;
struct defspace_s;
int value_too_large (struct type_s *val_type) __attribute__((pure));
int value_too_large (const struct type_s *val_type) __attribute__((pure));
void make_function (struct symbol_s *sym, const char *nice_name,
struct defspace_s *space, enum storage_class_e storage);
struct symbol_s *function_symbol (struct symbol_s *sym,

View file

@ -32,11 +32,11 @@
#define __linker_h
struct qfo_s;
struct type_s;
typedef struct type_s type_t;
void linker_begin (void);
int linker_add_string (const char *str);
void linker_add_def (const char *name, struct type_s *type, unsigned flags,
void linker_add_def (const char *name, const type_t *type, unsigned flags,
void *val);
struct qfo_def_s *linker_find_def (const char *name);
int linker_add_qfo (struct qfo_s *qfo);

View file

@ -38,7 +38,7 @@ typedef struct method_s {
int instance;
param_t *selector;
param_t *params;
struct type_s *type;
const struct type_s *type;
struct def_s *def;
struct function_s *func;
char *name;
@ -74,7 +74,7 @@ struct class_s;
struct expr_s;
struct dstring_s;
method_t *new_method (struct type_s *ret_type, param_t *selector,
method_t *new_method (const struct type_s *ret_type, param_t *selector,
param_t *opt_parms);
const char *method_name (method_t *method);
method_t *copy_method (method_t *method);

View file

@ -35,8 +35,8 @@
#include "type.h"
struct defspace_s;
struct type_s;
struct def_s *qfo_encode_type (struct type_s *type, struct defspace_s *space);
typedef struct defspace_s defspace_t;
typedef struct type_s type_t;
struct def_s *qfo_encode_type (const type_t *type, defspace_t *space);
#endif//__obj_type_h

View file

@ -67,7 +67,7 @@ typedef struct pseudoop_s {
typedef struct operand_s {
struct operand_s *next;
op_type_e op_type;
struct type_s *type; ///< possibly override def's/nil's type
const struct type_s *type; ///< possibly override def's/nil's type
int size; ///< for structures
int width; ///< for SIMD selection
const struct expr_s *expr; ///< expression generating this operand
@ -146,18 +146,19 @@ extern const char * const st_type_names[];
const char *optype_str (op_type_e type) __attribute__((const));
operand_t *nil_operand (struct type_s *type, const struct expr_s *expr);
operand_t *def_operand (struct def_s *def, struct type_s *type,
operand_t *nil_operand (const struct type_s *type, const struct expr_s *expr);
operand_t *def_operand (struct def_s *def, const struct type_s *type,
const struct expr_s *expr);
operand_t *return_operand (const struct type_s *type,
const struct expr_s *expr);
operand_t *return_operand (struct type_s *type, const struct expr_s *expr);
operand_t *value_operand (struct ex_value_s *value, const struct expr_s *expr);
int tempop_overlap (tempop_t *t1, tempop_t *t2) __attribute__((pure));
operand_t *temp_operand (const struct type_s *type, const struct expr_s *expr);
int tempop_visit_all (tempop_t *tempop, int overlap,
int (*visit) (tempop_t *, void *), void *data);
operand_t *offset_alias_operand (struct type_s *type, int offset,
operand_t *offset_alias_operand (const struct type_s *type, int offset,
operand_t *aop, const struct expr_s *expr);
operand_t *alias_operand (struct type_s *type, operand_t *op,
operand_t *alias_operand (const struct type_s *type, operand_t *op,
const struct expr_s *expr);
operand_t *label_operand (const struct expr_s *label);
void free_operand (operand_t *op);

View file

@ -35,36 +35,36 @@ struct def_s;
enum storage_class_e;
struct symbol_s;
struct symtab_s;
struct type_s;
typedef struct type_s type_t;
typedef struct {
const char *name;
struct type_s *type;
const type_t *type;
void (*emit) (struct def_s *def, void *data, int index);
} struct_def_t;
struct symbol_s *find_handle (struct symbol_s *tag, struct type_s *type);
struct symbol_s *find_handle (struct symbol_s *tag, const type_t *type);
struct symtab_s *start_struct (int *su, struct symbol_s *tag,
struct symtab_s *parent);
struct symbol_s *find_struct (int su, struct symbol_s *tag,
struct type_s *type);
const type_t *type);
struct symbol_s *build_struct (int su, struct symbol_s *tag,
struct symtab_s *symtab, struct type_s *type,
struct symtab_s *symtab, const type_t *type,
int base);
struct symbol_s *find_enum (struct symbol_s *tag);
struct symtab_s *start_enum (struct symbol_s *enm);
struct symbol_s *finish_enum (struct symbol_s *sym);
void add_enum (struct symbol_s *enm, struct symbol_s *name,
const struct expr_s *val);
int enum_as_bool (struct type_s *enm, struct expr_s **zero,
int enum_as_bool (const type_t *enm, struct expr_s **zero,
struct expr_s **one);
struct symbol_s *make_structure (const char *name, int su, struct_def_t *defs,
struct type_s *type);
const type_t *type);
struct defspace_s;
struct def_s * emit_structure (const char *name, int su, struct_def_t *defs,
struct type_s *type, void *data,
const type_t *type, void *data,
struct defspace_s *space,
enum storage_class_e storage);

View file

@ -70,7 +70,7 @@ typedef struct symbol_s {
vis_t visibility; ///< symbol visiblity. defaults to public
const char *name; ///< symbol name
sy_type_e sy_type; ///< symbol type
struct type_s *type; ///< type of object to which symbol refers
const struct type_s *type; ///< type of object to which symbol refers
struct param_s *params; ///< the parameters if a function
unsigned no_auto_init; ///< skip for non-designated initializers
union {
@ -129,7 +129,7 @@ symbol_t *new_symbol (const char *name);
\param type The type of the symbol.
\return The new symbol.
*/
symbol_t *new_symbol_type (const char *name, struct type_s *type);
symbol_t *new_symbol_type (const char *name, const struct type_s *type);
/** Create a new, empty symbol table.
@ -249,7 +249,7 @@ symtab_t *symtab_flat_copy (symtab_t *symtab, symtab_t *parent,
\param storage The storage class for the symbol. Only sc_extern,
sc_global, and sc_static are valid.
*/
symbol_t *make_symbol (const char *name, struct type_s *type,
symbol_t *make_symbol (const char *name, const struct type_s *type,
struct defspace_s *space, enum storage_class_e storage);
struct specifier_s;

View file

@ -36,9 +36,9 @@
#include "def.h"
typedef struct ty_func_s {
struct type_s *type;
const struct type_s *type;
int num_params;
struct type_s **param_types;
const struct type_s **param_types;
union {
struct {
unsigned no_va_list:1;///< don't inject va_list for ... function
@ -49,18 +49,18 @@ typedef struct ty_func_s {
} ty_func_t;
typedef struct ty_fldptr_s {
struct type_s *type;
const struct type_s *type;
} ty_fldptr_t;
typedef struct ty_array_s {
struct type_s *type;
const struct type_s *type;
int base;
int size;
} ty_array_t;
typedef struct ty_alias_s {
struct type_s *aux_type; ///< other aliases stripped
struct type_s *full_type; ///< full alias chain
const struct type_s *aux_type; ///< other aliases stripped
const struct type_s *full_type; ///< full alias chain
} ty_alias_t;
typedef struct type_s {
@ -93,7 +93,7 @@ typedef struct type_s {
} type_t;
typedef struct specifier_s {
type_t *type;
const type_t *type;
struct param_s *params;
struct symbol_s *sym;
storage_class_t storage;
@ -159,15 +159,15 @@ void chain_type (type_t *type);
\return The type chain with the type appended at the deepest
level.
*/
type_t *append_type (type_t *type, type_t *new);
void set_func_type_attrs (type_t *func, specifier_t spec);
const type_t *append_type (const type_t *type, const type_t *new);
void set_func_type_attrs (const type_t *func, specifier_t spec);
specifier_t default_type (specifier_t spec, struct symbol_s *sym);
type_t *find_type (type_t *new);
const type_t *find_type (const type_t *new);
void new_typedef (const char *name, type_t *type);
type_t *field_type (type_t *aux);
type_t *pointer_type (const type_t *aux);
type_t *vector_type (const type_t *ele_type, int width) __attribute__((pure));
type_t *base_type (const type_t *vec_type) __attribute__((pure));
const type_t *field_type (const type_t *aux);
const type_t *pointer_type (const type_t *aux);
const type_t *vector_type (const type_t *ele_type, int width) __attribute__((pure));
const type_t *base_type (const type_t *vec_type) __attribute__((pure));
/** Return an integral type of same size as the provided type.
@ -181,8 +181,8 @@ type_t *base_type (const type_t *vec_type) __attribute__((pure));
\return Matching integral type (int, long, or a vector form), or
null if no such match can be made.
*/
type_t *int_type (const type_t *base) __attribute__((pure));
type_t *uint_type (const type_t *base) __attribute__((pure));
const type_t *int_type (const type_t *base) __attribute__((pure));
const type_t *uint_type (const type_t *base) __attribute__((pure));
/** Return a floating point type of same size as the provided type.
@ -197,11 +197,12 @@ type_t *uint_type (const type_t *base) __attribute__((pure));
\return Matching floating point type (float, double, or a vector
form), or null if no such match can be made.
*/
type_t *float_type (const type_t *base) __attribute__((pure));
const type_t *float_type (const type_t *base) __attribute__((pure));
type_t *array_type (const type_t *aux, int size);
type_t *based_array_type (type_t *aux, int base, int top);
type_t *alias_type (type_t *type, type_t *alias_chain, const char *name);
const type_t *array_type (const type_t *aux, int size);
const type_t *based_array_type (const type_t *aux, int base, int top);
const type_t *alias_type (const type_t *type, const type_t *alias_chain,
const char *name);
const type_t *unalias_type (const type_t *type) __attribute__((pure));
const type_t *dereference_type (const type_t *type) __attribute__((pure));
void print_type_str (struct dstring_s *str, const type_t *type);

View file

@ -48,10 +48,10 @@ struct ex_value_s *new_double_val (double double_val);
struct ex_value_s *new_float_val (float float_val);
struct ex_value_s *new_vector_val (const float *vector_val);
struct ex_value_s *new_entity_val (int entity_val);
struct ex_value_s *new_field_val (int field_val, struct type_s *type,
struct ex_value_s *new_field_val (int field_val, const struct type_s *type,
struct def_s *def);
struct ex_value_s *new_func_val (int func_val, struct type_s *type);
struct ex_value_s *new_pointer_val (int val, struct type_s *type,
struct ex_value_s *new_func_val (int func_val, const struct type_s *type);
struct ex_value_s *new_pointer_val (int val, const struct type_s *type,
struct def_s *def,
struct operand_s *tempop);
struct ex_value_s *new_quaternion_val (const float *quaternion_val);
@ -60,7 +60,7 @@ struct ex_value_s *new_uint_val (int uint_val);
struct ex_value_s *new_long_val (pr_long_t long_val);
struct ex_value_s *new_ulong_val (pr_ulong_t ulong_val);
struct ex_value_s *new_short_val (short short_val);
struct ex_value_s *new_nil_val (struct type_s *type);
struct ex_value_s *new_nil_val (const struct type_s *type);
struct ex_value_s *new_type_value (const struct type_s *type,
const struct pr_type_s *data);
void value_store (pr_type_t *dst, const struct type_s *dstType,
@ -68,7 +68,7 @@ void value_store (pr_type_t *dst, const struct type_s *dstType,
const char *get_value_string (const struct ex_value_s *value);
struct ex_value_s *offset_alias_value (struct ex_value_s *value,
struct type_s *type, int offset);
const struct type_s *type, int offset);
struct ex_value_s *alias_value (struct ex_value_s *value, struct type_s *type);
struct def_s *emit_value (struct ex_value_s *value, struct def_s *def);
struct def_s *emit_value_core (struct ex_value_s *value, struct def_s *def,

View file

@ -221,7 +221,7 @@ metric_apply (const metric_t *metric, pr_uint_t a, pr_uint_t b)
return count_minus (c & metric->minus);
}
static type_t **
static const type_t **
alloc_mvec_types (int num_groups)
{
return calloc (1 << num_groups, sizeof (type_t *));
@ -337,8 +337,8 @@ is_algebra (const type_t *type)
return type->meta == ty_algebra;
}
type_t *
algebra_type (type_t *type, const expr_t *params)
const type_t *
algebra_type (const type_t *type, const expr_t *params)
{
if (!is_float (type) && !is_double (type)) {
error (0, "algebra type must be float or double");
@ -411,8 +411,8 @@ algebra_type (type_t *type, const expr_t *params)
return find_type (t);
}
type_t *
algebra_subtype (type_t *type, attribute_t *attr)
const type_t *
algebra_subtype (const type_t *type, attribute_t *attr)
{
if (!is_algebra (type)) {
internal_error (0, "unexpected type");
@ -489,7 +489,7 @@ mvec_struct (algebra_t *algebra, pr_uint_t group_mask, type_t *type)
return make_structure (0, 's', fields, 0);
}
type_t *
const type_t *
algebra_mvec_type (algebra_t *algebra, pr_uint_t group_mask)
{
if (!group_mask || group_mask > ((1u << algebra->layout.count) - 1)) {
@ -513,7 +513,8 @@ algebra_mvec_type (algebra_t *algebra, pr_uint_t group_mask)
.algebra = algebra,
.mvec_sym = mvec_sym,
};
auto type = algebra->mvec_types[group_mask] = new_type ();
auto type = new_type ();
algebra->mvec_types[group_mask] = type;
*type = (type_t) {
.type = algebra->type->type,
.name = save_string (va (0, "algebra(%s(%d,%d,%d):%04x)",
@ -527,7 +528,7 @@ algebra_mvec_type (algebra_t *algebra, pr_uint_t group_mask)
.freeable = true,
.allocated = true,
};
chain_type (algebra->mvec_types[group_mask]);
chain_type (type);
if (!(group_mask & (group_mask - 1))) {
mvec->mvec_sym = mvec_struct (algebra, group_mask, type);
}
@ -651,7 +652,7 @@ algebra_symbol (const char *name, symtab_t *symtab)
}
symtab_t *
algebra_scope (type_t *type, symtab_t *curscope)
algebra_scope (const type_t *type, symtab_t *curscope)
{
auto scope = new_symtab (curscope, stab_local);
scope->space = curscope->space;
@ -821,7 +822,7 @@ algebra_type_assignable (const type_t *dst, const type_t *src)
return 1;
}
type_t *
const type_t *
algebra_base_type (const type_t *type)
{
if (type->type == ev_invalid) {
@ -830,7 +831,7 @@ algebra_base_type (const type_t *type)
return ev_types[type->type];
}
type_t *
const type_t *
algebra_struct_type (const type_t *type)
{
symbol_t *sym = 0;

View file

@ -83,7 +83,7 @@ type_t type_SEL = {
.meta = ty_basic,
{{&type_selector}},
};
type_t *IMP_params[] = { &type_id, &type_SEL };
const type_t *IMP_params[] = { &type_id, &type_SEL };
type_t type_IMP = {
.type = ev_func,
.name = "IMP",
@ -102,7 +102,7 @@ type_t type_SuperPtr = {
.meta = ty_basic,
{{&type_super}},
};
type_t *supermsg_params[] = { &type_SuperPtr, &type_SEL };
const type_t *supermsg_params[] = { &type_SuperPtr, &type_SEL };
type_t type_supermsg = {
.type = ev_func,
.name = ".supermsg",
@ -138,7 +138,7 @@ type_t type_moduleptr = {
.meta = ty_basic,
{{&type_module}},
};
type_t *obj_exec_class_params[] = {
const type_t *obj_exec_class_params[] = {
&type_moduleptr,
};
type_t type_exec_class = {
@ -353,7 +353,7 @@ emit_static_instances_list (void)
static_instance_t **classes;
int num_classes = 0;
def_t **instance_lists;
type_t *instance_lists_type;
const type_t *instance_lists_type;
symbol_t *instance_lists_sym;
def_t *instance_lists_def;
pr_ptr_t *list;
@ -1228,7 +1228,7 @@ cls_find_method (methodlist_t *methodlist, selector_t *selector,
}
method_t *
class_message_response (type_t *clstype, int class_msg, const expr_t *sel)
class_message_response (const type_t *clstype, int class_msg, const expr_t *sel)
{
selector_t *selector;
method_t *m;
@ -1934,7 +1934,7 @@ class_finish_ivar_scope (class_type_t *class_type, symtab_t *ivar_scope,
symtab_t *param_scope)
{
class_t *class = extract_class (class_type);
type_t *class_ptr = pointer_type (class->type);
const type_t *class_ptr = pointer_type (class->type);
symbol_t *sym;
symbol_t *self;

View file

@ -495,7 +495,7 @@ do_op_vector (int op, const expr_t *e, const expr_t *e1, const expr_t *e2)
static const expr_t *
do_op_entity (int op, const expr_t *e, const expr_t *e1, const expr_t *e2)
{
type_t *type = get_type (e2);
auto type = get_type (e2);
if (op == '.' && type->type == ev_field) {
return e;
@ -908,8 +908,8 @@ do_op_struct (int op, const expr_t *e, const expr_t *e1, const expr_t *e2)
static const expr_t *
do_op_compound (int op, const expr_t *e, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
if (is_struct (t1) && is_struct (t2))
return do_op_struct (op, e, e1, e2);
if (is_union (t1) && is_union (t2))
@ -937,8 +937,8 @@ static operation_t *do_op[ev_type_count];
static const expr_t *
do_op_invalid (int op, const expr_t *e, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
if (is_scalar (t1) && is_scalar (t2)) {
// one or both expressions are an enum, and the other is one of
@ -1257,7 +1257,7 @@ static unaryop_t do_unary_op[ev_type_count];
static const expr_t *
uop_invalid (int op, const expr_t *e, const expr_t *e1)
{
type_t *t1 = get_type (e1);
auto t1 = get_type (e1);
if (is_scalar (t1)) {
// The expression is an enum. Treat the enum as the default type.
etype_t t;
@ -1298,14 +1298,13 @@ static const expr_t *
uop_float (int op, const expr_t *e, const expr_t *e1)
{
static int valid[] = { '+', '-', '!', '~', 'C', 0 };
type_t *type;
if (!valid_op (op, valid))
return error (e1, "invalid unary operator for float: %s",
get_op_string (op));
if (op == '+')
return e1;
type = get_type (e);
auto type = get_type (e);
if (op == 'C' && !is_int(type) && !is_double(type))
return error (e1, "invalid cast of float");
if (!is_constant (e1))
@ -1525,14 +1524,13 @@ static const expr_t *
uop_double (int op, const expr_t *e, const expr_t *e1)
{
static int valid[] = { '+', '-', '!', 'C', 0 };
type_t *type;
if (!valid_op (op, valid))
return error (e1, "invalid unary operator for double: %s",
get_op_string (op));
if (op == '+')
return e1;
type = get_type (e);
auto type = get_type (e);
if (op == 'C' && !is_int(type) && !is_float(type))
return error (e1, "invalid cast of double");
if (!is_constant (e1))
@ -1556,7 +1554,7 @@ uop_double (int op, const expr_t *e, const expr_t *e1)
static const expr_t *
uop_compound (int op, const expr_t *e, const expr_t *e1)
{
type_t *t1 = get_type (e1);
auto t1 = get_type (e1);
if (is_scalar (t1)) {
if (is_enum (t1)) {

View file

@ -1119,7 +1119,7 @@ dag_calc_node_costs (dagnode_t *dagnode)
}
#endif
static operand_t *
fix_op_type (operand_t *op, type_t *type)
fix_op_type (operand_t *op, const type_t *type)
{
if (op && op->op_type != op_label && op->type != type)
op = alias_operand (type, op, op->expr);
@ -1167,7 +1167,6 @@ generate_moveps (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
operand_t *operands[3] = {0, 0, 0};
statement_t *st;
operand_t *dst = 0;
type_t *type;
int offset = 0;
def_t *dstDef;
@ -1187,7 +1186,7 @@ generate_moveps (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
var_iter = set_next (var_iter)) {
var = dag->labels[var_iter->element];
dst = var->op;
type = dst->def->type;
auto type = dst->def->type;
dstDef = dst->def;
if (dstDef->alias) {
offset = dstDef->offset;
@ -1233,7 +1232,6 @@ generate_memsetps (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
operand_t *operands[3] = {0, 0, 0};
statement_t *st;
operand_t *dst = 0;
type_t *type;
int offset = 0;
def_t *dstDef;
@ -1248,7 +1246,7 @@ generate_memsetps (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
var_iter = set_next (var_iter)) {
var = dag->labels[var_iter->element];
dst = var->op;
type = dst->def->type;
auto type = dst->def->type;
dstDef = dst->def;
if (dstDef->alias) {
offset = dstDef->offset;
@ -1302,7 +1300,7 @@ generate_call (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
static operand_t *
generate_assignments (dag_t *dag, sblock_t *block, operand_t *src,
set_iter_t *var_iter, type_t *type)
set_iter_t *var_iter, const type_t *type)
{
statement_t *st;
operand_t *dst = 0;
@ -1330,7 +1328,7 @@ dag_gencode (dag_t *dag, sblock_t *block, dagnode_t *dagnode)
statement_t *st;
set_iter_t *var_iter;
int i;
type_t *type;
const type_t *type;
switch (dagnode->type) {
case st_none:

View file

@ -119,7 +119,7 @@ set_storage_bits (def_t *def, storage_class_t storage)
}
def_t *
new_def (const char *name, type_t *type, defspace_t *space,
new_def (const char *name, const type_t *type, defspace_t *space,
storage_class_t storage)
{
def_t *def;
@ -179,7 +179,7 @@ new_def (const char *name, type_t *type, defspace_t *space,
}
def_t *
cover_alias_def (def_t *def, type_t *type, int offset)
cover_alias_def (def_t *def, const type_t *type, int offset)
{
def_t *alias;
@ -205,7 +205,7 @@ cover_alias_def (def_t *def, type_t *type, int offset)
}
def_t *
alias_def (def_t *def, type_t *type, int offset)
alias_def (def_t *def, const type_t *type, int offset)
{
if (def->alias) {
expr_t e;
@ -221,7 +221,7 @@ alias_def (def_t *def, type_t *type, int offset)
}
def_t *
temp_def (type_t *type)
temp_def (const type_t *type)
{
def_t *temp;
defspace_t *space = current_func->locals->space;
@ -399,7 +399,7 @@ init_elements (struct def_s *def, const expr_t *eles)
reloc_def_op (c->labelref.label, &dummy);
continue;
} else if (c->type == ex_value) {
type_t *ctype = get_type (c);
auto ctype = get_type (c);
if (ctype != element->type
&& type_assignable (element->type, ctype)) {
if (!c->implicit
@ -630,11 +630,10 @@ initialize_def (symbol_t *sym, const expr_t *init, defspace_t *space,
init_elements (sym->s.def, init);
sym->s.def->initialized = 1;
} else {
type_t *init_type;
if (init->type == ex_nil) {
init = convert_nil (init, sym->type);
}
init_type = get_type (init);
auto init_type = get_type (init);
if (!type_assignable (sym->type, init_type)) {
error (init, "type mismatch in initializer: %s = %s",
get_type_string (sym->type), get_type_string (init_type));

View file

@ -49,14 +49,14 @@
#include "tools/qfcc/include/type.h"
#include "tools/qfcc/include/strpool.h"
typedef void (*print_f) (dstring_t *dstr, type_t *, int, int);
static void dot_print_type (dstring_t *dstr, type_t *t, int level, int id);
typedef void (*print_f) (dstring_t *dstr, const type_t *, int, int);
static void dot_print_type (dstring_t *dstr, const type_t *t, int level, int id);
static void
print_pointer (dstring_t *dstr, type_t *t, int level, int id)
print_pointer (dstring_t *dstr, const type_t *t, int level, int id)
{
int indent = level * 2 + 2;
type_t *aux = t->t.fldptr.type;
auto aux = t->t.fldptr.type;
dot_print_type (dstr, aux, level, id);
dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, aux);
@ -78,12 +78,12 @@ print_ellipsis (dstring_t *dstr, int level, int id)
}
static void
print_function (dstring_t *dstr, type_t *t, int level, int id)
print_function (dstring_t *dstr, const type_t *t, int level, int id)
{
int indent = level * 2 + 2;
const ty_func_t *func = &t->t.func;
type_t *ret = func->type;
type_t *param;
const type_t *ret = func->type;
const type_t *param;
dot_print_type (dstr, ret, level + 1, id);
if (func->num_params < 0) {
@ -116,7 +116,7 @@ print_function (dstring_t *dstr, type_t *t, int level, int id)
}
static void
print_basic (dstring_t *dstr, type_t *t, int level, int id)
print_basic (dstring_t *dstr, const type_t *t, int level, int id)
{
if (t->type == ev_ptr || t->type == ev_field) {
print_pointer (dstr, t, level, id);
@ -129,7 +129,7 @@ print_basic (dstring_t *dstr, type_t *t, int level, int id)
}
static void
print_struct (dstring_t *dstr, type_t *t, int level, int id)
print_struct (dstring_t *dstr, const type_t *t, int level, int id)
{
int indent = level * 2 + 2;
const symtab_t *symtab = t->t.symtab;
@ -186,10 +186,10 @@ print_struct (dstring_t *dstr, type_t *t, int level, int id)
}
static void
print_array (dstring_t *dstr, type_t *t, int level, int id)
print_array (dstring_t *dstr, const type_t *t, int level, int id)
{
int indent = level * 2 + 2;
type_t *type = t->t.array.type;
auto type = t->t.array.type;
dot_print_type (dstr, type, level, id);
dasprintf (dstr, "%*st_%p -> \"t_%p\";\n", indent, "", t, type);
@ -204,7 +204,7 @@ print_array (dstring_t *dstr, type_t *t, int level, int id)
}
static void
print_class (dstring_t *dstr, type_t *t, int level, int id)
print_class (dstring_t *dstr, const type_t *t, int level, int id)
{
int indent = level * 2 + 2;
dasprintf (dstr, "%*st_%p [label=\"class '%s'\"];\n", indent, "", t,
@ -212,11 +212,11 @@ print_class (dstring_t *dstr, type_t *t, int level, int id)
}
static void
print_alias (dstring_t *dstr, type_t *t, int level, int id)
print_alias (dstring_t *dstr, const type_t *t, int level, int id)
{
int indent = level * 2 + 2;
type_t *aux = t->t.alias.aux_type;
type_t *full = t->t.alias.full_type;
auto aux = t->t.alias.aux_type;
auto full = t->t.alias.full_type;
dot_print_type (dstr, aux, level, id);
dot_print_type (dstr, full, level, id);
@ -227,7 +227,7 @@ print_alias (dstring_t *dstr, type_t *t, int level, int id)
}
static void
dot_print_type (dstring_t *dstr, type_t *t, int level, int id)
dot_print_type (dstring_t *dstr, const type_t *t, int level, int id)
{
static print_f print_funcs[] = {
print_basic,
@ -246,7 +246,7 @@ dot_print_type (dstring_t *dstr, type_t *t, int level, int id)
}
if (t->printid == id) // already printed this type
return;
t->printid = id;
((type_t *) t)->printid = id;
if ((unsigned) t->meta >= sizeof (print_funcs) / sizeof (print_funcs[0])) {
dasprintf (dstr, "%*se_%p [label=\"(bad type meta)\\n%d\"];\n",

View file

@ -63,7 +63,7 @@ static def_t zero_def;
static def_t *get_operand_def (const expr_t *expr, operand_t *op);
static def_t *
get_tempop_def (const expr_t *expr, operand_t *tmpop, type_t *type)
get_tempop_def (const expr_t *expr, operand_t *tmpop, const type_t *type)
{
tempop_t *tempop = &tmpop->tempop;
if (tempop->def) {
@ -81,7 +81,7 @@ get_tempop_def (const expr_t *expr, operand_t *tmpop, type_t *type)
}
static def_t *
get_value_def (const expr_t *expr, ex_value_t *value, type_t *type)
get_value_def (const expr_t *expr, ex_value_t *value, const type_t *type)
{
def_t *def;

View file

@ -154,7 +154,7 @@ setup_value_progs (void)
}
ex_value_t *
convert_value (ex_value_t *value, type_t *type)
convert_value (ex_value_t *value, const type_t *type)
{
if (!is_math (type) || !is_math (value->type)) {
error (0, "unable to convert non-math value");

View file

@ -118,7 +118,7 @@ convert_name (const expr_t *e)
return e;
}
type_t *
const type_t *
get_type (const expr_t *e)
{
const type_t *type = 0;
@ -202,13 +202,13 @@ get_type (const expr_t *e)
case ex_count:
internal_error (e, "invalid expression");
}
return (type_t *) unalias_type (type);//FIXME cast
return unalias_type (type);
}
etype_t
extract_type (const expr_t *e)
{
type_t *type = get_type (e);
auto type = get_type (e);
if (type)
return type->type;
@ -228,7 +228,8 @@ type_mismatch (const expr_t *e1, const expr_t *e2, int op)
}
const expr_t *
param_mismatch (const expr_t *e, int param, const char *fn, type_t *t1, type_t *t2)
param_mismatch (const expr_t *e, int param, const char *fn,
const type_t *t1, const type_t *t2)
{
return error (e, "type mismatch for parameter %d of %s: "
"expected %s, got %s", param, fn, get_type_string (t1),
@ -236,7 +237,7 @@ param_mismatch (const expr_t *e, int param, const char *fn, type_t *t1, type_t *
}
const expr_t *
test_error (const expr_t *e, type_t *t)
test_error (const expr_t *e, const type_t *t)
{
dstring_t *s = dstring_newstr ();
@ -576,7 +577,7 @@ new_horizontal_expr (int op, const expr_t *vec, type_t *type)
if (vec->type == ex_error) {
return (expr_t *) vec;
}
type_t *vec_type = get_type (vec);
auto vec_type = get_type (vec);
if (!is_math (vec_type) || is_scalar (vec_type)) {
internal_error (vec, "horizontal operand not a vector type");
}
@ -599,7 +600,7 @@ new_swizzle_expr (const expr_t *src, const char *swizzle)
if (src->type == ex_error) {
return (expr_t *) src;
}
type_t *src_type = get_type (src);
auto src_type = get_type (src);
int src_width = type_width (src_type);
ex_swizzle_t swiz = {};
@ -661,7 +662,7 @@ new_swizzle_expr (const expr_t *src, const char *swizzle)
}
const expr_t *
new_extend_expr (const expr_t *src, type_t *type, int ext, bool rev)
new_extend_expr (const expr_t *src, const type_t *type, int ext, bool rev)
{
expr_t *expr = new_expr ();
expr->type = ex_extend;
@ -726,7 +727,7 @@ new_value_expr (ex_value_t *value)
}
const expr_t *
new_zero_expr (type_t *type)
new_zero_expr (const type_t *type)
{
pr_type_t zero[type_size (type)] = {};
return new_value_expr (new_type_value (type, zero));
@ -779,19 +780,19 @@ new_entity_expr (int entity_val)
}
const expr_t *
new_field_expr (int field_val, type_t *type, def_t *def)
new_field_expr (int field_val, const type_t *type, def_t *def)
{
return new_value_expr (new_field_val (field_val, type, def));
}
const expr_t *
new_func_expr (int func_val, type_t *type)
new_func_expr (int func_val, const type_t *type)
{
return new_value_expr (new_func_val (func_val, type));
}
const expr_t *
new_pointer_expr (int val, type_t *type, def_t *def)
new_pointer_expr (int val, const type_t *type, def_t *def)
{
return new_value_expr (new_pointer_val (val, type, def, 0));
}
@ -1232,7 +1233,7 @@ is_math_val (const expr_t *e)
}
const expr_t *
new_alias_expr (type_t *type, const expr_t *expr)
new_alias_expr (const type_t *type, const expr_t *expr)
{
if (is_ptr (type) && expr->type == ex_address) {
auto new = new_address_expr (type, expr->address.lvalue,
@ -1263,7 +1264,7 @@ new_alias_expr (type_t *type, const expr_t *expr)
}
const expr_t *
new_offset_alias_expr (type_t *type, const expr_t *expr, int offset)
new_offset_alias_expr (const type_t *type, const expr_t *expr, int offset)
{
if (expr->type == ex_alias && expr->alias.offset) {
const expr_t *ofs_expr = expr->alias.offset;
@ -1341,7 +1342,7 @@ new_with_expr (int mode, int reg, const expr_t *val)
}
static const expr_t *
param_expr (const char *name, type_t *type)
param_expr (const char *name, const type_t *type)
{
symbol_t *sym;
expr_t *sym_expr;
@ -1360,7 +1361,7 @@ new_ret_expr (type_t *type)
}
const expr_t *
new_param_expr (type_t *type, int num)
new_param_expr (const type_t *type, int num)
{
return param_expr (va (0, ".param_%d", num), type);
}
@ -1562,7 +1563,7 @@ field_expr (const expr_t *e1, const expr_t *e2)
}
const expr_t *
convert_from_bool (const expr_t *e, type_t *type)
convert_from_bool (const expr_t *e, const type_t *type)
{
const expr_t *zero;
const expr_t *one;
@ -1730,7 +1731,7 @@ unary_expr (int op, const expr_t *e)
vec3_t v;
quat_t q;
const char *s;
type_t *t;
const type_t *t;
e = convert_name (e);
if (e->type == ex_error)
@ -2027,7 +2028,7 @@ bitnot_expr:
return binary_expr ('-', n1, e);
} else {
expr_t *n = new_unary_expr (op, e);
type_t *t = get_type (e);
auto t = get_type (e);
if (!is_int(t) && !is_float(t)
&& !is_quaternion(t))
@ -2121,11 +2122,11 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
param_count = ftype->t.func.num_params;
}
type_t *arg_types[arg_count];
const type_t *arg_types[arg_count];
// params is reversed (a, b, c) -> c, b, a
for (int i = 0; i < arg_count; i++) {
auto e = arguments[i];
type_t *t;
const type_t *t;
if (e->type == ex_compound) {
if (i < param_count) {
@ -2244,7 +2245,7 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
//e = expr_file_line (e, arg_exprs[arg_expr_count - 1][0]);
append_expr (call, e);
}
type_t *ret_type = ftype->t.func.type;
auto ret_type = ftype->t.func.type;
call->block.result = call_expr (fexpr, args, ret_type);
return call;
}
@ -2252,8 +2253,6 @@ build_function_call (const expr_t *fexpr, const type_t *ftype, const expr_t *par
const expr_t *
function_expr (const expr_t *fexpr, const expr_t *params)
{
type_t *ftype;
if (params) {
for (auto p = params->list.head; p; p = p->next) {
p->expr = convert_name (p->expr);
@ -2262,7 +2261,7 @@ function_expr (const expr_t *fexpr, const expr_t *params)
fexpr = find_function (fexpr, params);
fexpr = convert_name (fexpr);
ftype = get_type (fexpr);
auto ftype = get_type (fexpr);
if (fexpr->type == ex_error)
return fexpr;
@ -2346,7 +2345,7 @@ jump_table_expr (const expr_t *table, const expr_t *index)
}
const expr_t *
call_expr (const expr_t *func, const expr_t *args, type_t *ret_type)
call_expr (const expr_t *func, const expr_t *args, const type_t *ret_type)
{
expr_t *branch = new_expr ();
branch->type = ex_branch;
@ -2457,7 +2456,7 @@ at_return_expr (function_t *f, const expr_t *e)
return error (e, "@return value not a function");
}
const expr_t *call_expr = e->block.result->branch.target;
const type_t *call_type = get_type (call_expr);
const auto call_type = get_type (call_expr);
if (!is_func (call_type) && !call_type->t.func.void_return) {
return error (e, "@return function not void_return");
}
@ -2481,8 +2480,8 @@ conditional_expr (const expr_t *cond, const expr_t *e1, const expr_t *e2)
return c;
expr_t *block = expr_file_line (new_block_expr (0), cond);
type_t *type1 = get_type (e1);
type_t *type2 = get_type (e2);
auto type1 = get_type (e1);
auto type2 = get_type (e2);
expr_t *tlabel = expr_file_line (new_label_expr (), cond);
expr_t *flabel = expr_file_line (new_label_expr (), cond);
expr_t *elabel = expr_file_line (new_label_expr (), cond);
@ -2532,7 +2531,7 @@ incop_expr (int op, const expr_t *e, int postop)
}
if (postop) {
expr_t *t1, *t2;
type_t *type = get_type (e);
auto type = get_type (e);
expr_t *block = new_block_expr (0);
if (e->type == ex_error) // get_type failed
@ -2557,9 +2556,9 @@ array_expr (const expr_t *array, const expr_t *index)
array = convert_name (array);
index = convert_name (index);
type_t *array_type = get_type (array);
type_t *index_type = get_type (index);
type_t *ele_type;
auto array_type = get_type (array);
auto index_type = get_type (index);
const type_t *ele_type;
const expr_t *base;
const expr_t *ptr;
int ind = 0;
@ -2636,7 +2635,7 @@ array_expr (const expr_t *array, const expr_t *index)
const expr_t *
deref_pointer_expr (const expr_t *pointer)
{
type_t *pointer_type = get_type (pointer);
auto pointer_type = get_type (pointer);
if (pointer->type == ex_error)
return pointer;
@ -2648,7 +2647,7 @@ deref_pointer_expr (const expr_t *pointer)
const expr_t *
offset_pointer_expr (const expr_t *pointer, const expr_t *offset)
{
type_t *ptr_type = get_type (pointer);
auto ptr_type = get_type (pointer);
if (!is_ptr (ptr_type)) {
internal_error (pointer, "not a pointer");
}
@ -2677,7 +2676,7 @@ offset_pointer_expr (const expr_t *pointer, const expr_t *offset)
}
const expr_t *
address_expr (const expr_t *e1, type_t *t)
address_expr (const expr_t *e1, const type_t *t)
{
expr_t *e;
@ -2691,8 +2690,8 @@ address_expr (const expr_t *e1, type_t *t)
switch (e1->type) {
case ex_def:
{
def_t *def = e1->def;
type_t *type = def->type;
auto def = e1->def;
auto type = def->type;
//FIXME this test should be in statements.c
if (options.code.progsversion == PROG_VERSION
@ -2710,8 +2709,8 @@ address_expr (const expr_t *e1, type_t *t)
break;
case ex_symbol:
if (e1->symbol->sy_type == sy_var) {
def_t *def = e1->symbol->s.def;
type_t *type = def->type;
auto def = e1->symbol->s.def;
auto type = def->type;
//FIXME this test should be in statements.c
if (options.code.progsversion == PROG_VERSION
@ -3010,7 +3009,7 @@ think_expr (symbol_t *think_sym)
}
const expr_t *
encode_expr (type_t *type)
encode_expr (const type_t *type)
{
dstring_t *encoding = dstring_newstr ();
@ -3021,7 +3020,7 @@ encode_expr (type_t *type)
}
const expr_t *
sizeof_expr (const expr_t *expr, struct type_s *type)
sizeof_expr (const expr_t *expr, const type_t *type)
{
if (!((!expr) ^ (!type)))
internal_error (0, 0);

View file

@ -43,7 +43,7 @@
#include "tools/qfcc/source/qc-parse.h"
static int __attribute__((pure))
get_group (type_t *type, algebra_t *algebra)
get_group (const type_t *type, algebra_t *algebra)
{
auto layout = &algebra->layout;
if (is_scalar (type) && !is_algebra (type)) {
@ -102,7 +102,7 @@ op_anti_com (int op)
}
const expr_t *
typed_binary_expr (type_t *type, int op, const expr_t *e1, const expr_t *e2)
typed_binary_expr (const type_t *type, int op, const expr_t *e1, const expr_t *e2)
{
auto e = new_binary_expr (op, e1, e2);
e->expr.type = type;
@ -133,7 +133,7 @@ neg_expr (const expr_t *e)
}
const expr_t *
ext_expr (const expr_t *src, type_t *type, int extend, bool reverse)
ext_expr (const expr_t *src, const type_t *type, int extend, bool reverse)
{
if (!src) {
return 0;
@ -164,7 +164,7 @@ is_ext (const expr_t *e)
}
static const expr_t *
alias_expr (type_t *type, const expr_t *e, int offset)
alias_expr (const type_t *type, const expr_t *e, int offset)
{
if (type == get_type (e)) {
if (offset) {
@ -187,7 +187,7 @@ alias_expr (type_t *type, const expr_t *e, int offset)
}
static const expr_t *
offset_cast (type_t *type, const expr_t *expr, int offset)
offset_cast (const type_t *type, const expr_t *expr, int offset)
{
if (type->meta != ty_basic) {
internal_error (expr, "offset cast to non-basic type");
@ -235,7 +235,7 @@ offset_cast (type_t *type, const expr_t *expr, int offset)
}
static symtab_t *
get_mvec_struct (type_t *type)
get_mvec_struct (const type_t *type)
{
symbol_t *sym = 0;
if (type->type == ev_invalid) {
@ -247,7 +247,7 @@ get_mvec_struct (type_t *type)
}
static symbol_t *
get_mvec_sym (type_t *type)
get_mvec_sym (const type_t *type)
{
auto symtab = get_mvec_struct (type);
return symtab ? symtab->symbols : 0;
@ -270,7 +270,7 @@ check_types (const expr_t **e, algebra_t *algebra)
}
static const expr_t *
promote_scalar (type_t *dst_type, const expr_t *scalar)
promote_scalar (const type_t *dst_type, const expr_t *scalar)
{
auto scalar_type = get_type (scalar);
if (scalar_type != dst_type) {
@ -504,7 +504,7 @@ scatter_factors (const expr_t *prod, const expr_t **factors)
}
const expr_t *
gather_factors (type_t *type, int op, const expr_t **factors, int count)
gather_factors (const type_t *type, int op, const expr_t **factors, int count)
{
if (!count) {
internal_error (0, "no factors to collect");
@ -545,7 +545,7 @@ insert_expr (const expr_t **array, const expr_t *e, int count)
}
#endif
static const expr_t *
sort_factors (type_t *type, const expr_t *e)
sort_factors (const type_t *type, const expr_t *e)
{
if (!is_mult (e)) {
internal_error (e, "not a product");
@ -560,7 +560,7 @@ sort_factors (type_t *type, const expr_t *e)
}
static const expr_t *
sum_expr_low (type_t *type, int op, const expr_t *a, const expr_t *b)
sum_expr_low (const type_t *type, int op, const expr_t *a, const expr_t *b)
{
if (!a) {
return op == '-' ? neg_expr (b) : b;
@ -625,7 +625,7 @@ scatter_terms (const expr_t *sum, const expr_t **adds, const expr_t **subs)
}
const expr_t *
gather_terms (type_t *type, const expr_t **adds, const expr_t **subs)
gather_terms (const type_t *type, const expr_t **adds, const expr_t **subs)
{
const expr_t *a = 0;
const expr_t *b = 0;
@ -639,7 +639,8 @@ gather_terms (type_t *type, const expr_t **adds, const expr_t **subs)
return sum;
}
static const expr_t *sum_expr (type_t *type, const expr_t *a, const expr_t *b);
static const expr_t *sum_expr (const type_t *type,
const expr_t *a, const expr_t *b);
static void
merge_extends (const expr_t **adds, const expr_t **subs)
@ -676,7 +677,7 @@ merge_extends (const expr_t **adds, const expr_t **subs)
}
static const expr_t *
sum_expr (type_t *type, const expr_t *a, const expr_t *b)
sum_expr (const type_t *type, const expr_t *a, const expr_t *b)
{
if (!a) {
return cast_expr (type, b);
@ -761,8 +762,8 @@ component_sum (int op, const expr_t **c, const expr_t **a, const expr_t **b,
}
static const expr_t *
distribute_product (type_t *type, const expr_t *a, const expr_t *b,
const expr_t *(*product) (type_t *type,
distribute_product (const type_t *type, const expr_t *a, const expr_t *b,
const expr_t *(*product) (const type_t *type,
const expr_t *a, const expr_t *b),
bool anti_com)
{
@ -867,7 +868,7 @@ extract_scale (const expr_t **expr, const expr_t *prod)
}
static const expr_t *
apply_scale (type_t *type, const expr_t *expr, const expr_t *prod)
apply_scale (const type_t *type, const expr_t *expr, const expr_t *prod)
{
if (expr && prod) {
expr = fold_constants (expr);
@ -878,13 +879,13 @@ apply_scale (type_t *type, const expr_t *expr, const expr_t *prod)
}
static const expr_t *
do_mult (type_t *type, const expr_t *a, const expr_t *b)
do_mult (const type_t *type, const expr_t *a, const expr_t *b)
{
return typed_binary_expr (type, '*', a, b);
}
static const expr_t *
do_scale (type_t *type, const expr_t *a, const expr_t *b)
do_scale (const type_t *type, const expr_t *a, const expr_t *b)
{
const expr_t *prod = extract_scale (&a, b);
if (prod) {
@ -894,7 +895,7 @@ do_scale (type_t *type, const expr_t *a, const expr_t *b)
}
const expr_t *
scale_expr (type_t *type, const expr_t *a, const expr_t *b)
scale_expr (const type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@ -938,7 +939,7 @@ reject_dot (const expr_t *a, const expr_t *b)
}
static const expr_t *
do_dot (type_t *type, const expr_t *a, const expr_t *b)
do_dot (const type_t *type, const expr_t *a, const expr_t *b)
{
if (reject_dot (a, b)) {
return 0;
@ -954,7 +955,7 @@ do_dot (type_t *type, const expr_t *a, const expr_t *b)
}
static const expr_t *
dot_expr (type_t *type, const expr_t *a, const expr_t *b)
dot_expr (const type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@ -972,7 +973,7 @@ reject_cross (const expr_t *a, const expr_t *b)
}
static const expr_t *
do_cross (type_t *type, const expr_t *a, const expr_t *b)
do_cross (const type_t *type, const expr_t *a, const expr_t *b)
{
if (reject_cross (a, b)) {
return 0;
@ -988,7 +989,7 @@ do_cross (type_t *type, const expr_t *a, const expr_t *b)
}
static const expr_t *
cross_expr (type_t *type, const expr_t *a, const expr_t *b)
cross_expr (const type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@ -1006,7 +1007,7 @@ reject_wedge (const expr_t *a, const expr_t *b)
}
static const expr_t *
do_wedge (type_t *type, const expr_t *a, const expr_t *b)
do_wedge (const type_t *type, const expr_t *a, const expr_t *b)
{
if (reject_wedge (a, b)) {
return 0;
@ -1022,7 +1023,7 @@ do_wedge (type_t *type, const expr_t *a, const expr_t *b)
}
static const expr_t *
wedge_expr (type_t *type, const expr_t *a, const expr_t *b)
wedge_expr (const type_t *type, const expr_t *a, const expr_t *b)
{
if (!a || !b) {
// propagated zero
@ -2873,9 +2874,9 @@ algebra_reverse (const expr_t *e)
}
const expr_t *
algebra_cast_expr (type_t *dstType, const expr_t *e)
algebra_cast_expr (const type_t *dstType, const expr_t *e)
{
type_t *srcType = get_type (e);
auto srcType = get_type (e);
if (dstType->type == ev_invalid
|| srcType->type == ev_invalid
|| type_width (dstType) != type_width (srcType)) {
@ -2949,8 +2950,8 @@ assign_extend (expr_t *block, const expr_t *dst, const expr_t *src)
const expr_t *
algebra_assign_expr (const expr_t *dst, const expr_t *src)
{
type_t *srcType = get_type (src);
type_t *dstType = get_type (dst);
auto srcType = get_type (src);
auto dstType = get_type (dst);
if (src->type != ex_multivec) {
if (srcType == dstType) {

View file

@ -170,8 +170,8 @@ check_valid_lvalue (const expr_t *expr)
static const expr_t *
check_types_compatible (const expr_t *dst, const expr_t *src)
{
type_t *dst_type = get_type (dst);
type_t *src_type = get_type (src);
auto dst_type = get_type (dst);
auto src_type = get_type (src);
if (dst_type == src_type) {
if (is_algebra (dst_type) || is_algebra (src_type)) {
@ -318,7 +318,7 @@ const expr_t *
assign_expr (const expr_t *dst, const expr_t *src)
{
const expr_t *expr;
type_t *dst_type, *src_type;
const type_t *dst_type, *src_type;
dst = convert_name (dst);
if (dst->type == ex_error) {

View file

@ -885,7 +885,7 @@ convert_scalar (const expr_t *scalar, int op, const expr_t *vec)
}
// expand the scalar to a vector of the same width as vec
type_t *vec_type = get_type (vec);
auto vec_type = get_type (vec);
if (is_constant (scalar)) {
int width = type_width (get_type (vec));
@ -904,12 +904,12 @@ convert_scalar (const expr_t *scalar, int op, const expr_t *vec)
static const expr_t *
pointer_arithmetic (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
const expr_t *ptr = 0;
const expr_t *offset = 0;
const expr_t *psize;
type_t *ptype = 0;
const type_t *ptype = 0;
if (!is_ptr (t1) && !is_ptr (t2)) {
internal_error (e1, "pointer arithmetic on non-pointers");
@ -944,8 +944,8 @@ pointer_arithmetic (int op, const expr_t *e1, const expr_t *e2)
static const expr_t *
pointer_compare (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
expr_t *e;
if (!type_assignable (t1, t2)) {
@ -1048,8 +1048,8 @@ vector_scale (int op, const expr_t *e1, const expr_t *e2)
static const expr_t *
double_compare (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
expr_t *e;
if (is_constant (e1) && e1->implicit && is_double (t1) && is_float (t2)) {
@ -1083,8 +1083,8 @@ double_compare (int op, const expr_t *e1, const expr_t *e2)
static const expr_t *
uint_compare (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1 = get_type (e1);
type_t *t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
expr_t *e;
if (is_constant (e1) && e1->implicit && is_int (t1)) {
@ -1129,9 +1129,8 @@ static const expr_t *
_invalid_binary_expr (int op, const expr_t *e1, const expr_t *e2,
const char *file, int line, const char *func)
{
type_t *t1, *t2;
t1 = get_type (e1);
t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
return _error (e1, file, line, func, "invalid binary expression: %s %s %s",
get_type_string (t1), get_op_string (op),
get_type_string (t2));
@ -1259,8 +1258,8 @@ is_call (const expr_t *e)
return e->type == ex_block && e->block.is_call;
}
static type_t *
promote_type (type_t *dst, type_t *src)
static const type_t *
promote_type (const type_t *dst, const type_t *src)
{
if (is_vector (dst) || is_quaternion (dst)) {
return dst;
@ -1271,7 +1270,6 @@ promote_type (type_t *dst, type_t *src)
const expr_t *
binary_expr (int op, const expr_t *e1, const expr_t *e2)
{
type_t *t1, *t2;
etype_t et1, et2;
const expr_t *e;
expr_type_t *expr_type;
@ -1315,8 +1313,8 @@ binary_expr (int op, const expr_t *e1, const expr_t *e2)
if ((e = check_precedence (op, e1, e2)))
return e;
t1 = get_type (e1);
t2 = get_type (e2);
auto t1 = get_type (e1);
auto t2 = get_type (e2);
if (!t1 || !t2)
internal_error (e1, "expr with no type");
@ -1374,8 +1372,8 @@ binary_expr (int op, const expr_t *e1, const expr_t *e2)
// are distict types with type.width == 1, but vector and vec3 WILL get
// here because of vec3 being float{3}
if (t1 != t2) {
type_t *pt1 = t1;
type_t *pt2 = t2;
auto pt1 = t1;
auto pt2 = t2;
if (is_float (base_type (t1)) && is_double (base_type (t2))
&& e2->implicit) {
pt2 = promote_type (t1, t2);

View file

@ -70,13 +70,12 @@ const expr_t *
test_expr (const expr_t *e)
{
const expr_t *new = 0;
type_t *type;
e = convert_name (e);
if (e->type == ex_error)
return e;
type = get_type (e);
auto type = get_type (e);
if (e->type == ex_error)
return e;
switch (type->type) {

View file

@ -45,7 +45,7 @@
#include "tools/qfcc/include/value.h"
const expr_t *
cast_error (const expr_t *e, type_t *t1, type_t *t2)
cast_error (const expr_t *e, const type_t *t1, const type_t *t2)
{
e = error (e, "cannot cast from %s to %s", get_type_string (t1),
get_type_string (t2));
@ -53,8 +53,8 @@ cast_error (const expr_t *e, type_t *t1, type_t *t2)
}
static void
do_conversion (pr_type_t *dst_value, type_t *dstType,
pr_type_t *src_value, type_t *srcType, const expr_t *expr)
do_conversion (pr_type_t *dst_value, const type_t *dstType,
pr_type_t *src_value, const type_t *srcType, const expr_t *expr)
{
int from = type_cast_map[base_type (srcType)->type];
int to = type_cast_map[base_type (dstType)->type];
@ -70,7 +70,7 @@ do_conversion (pr_type_t *dst_value, type_t *dstType,
}
static const expr_t *
cast_math (type_t *dstType, type_t *srcType, const expr_t *expr)
cast_math (const type_t *dstType, const type_t *srcType, const expr_t *expr)
{
pr_type_t src_value[type_size (srcType)];
pr_type_t dst_value[type_size (dstType)];
@ -83,9 +83,9 @@ cast_math (type_t *dstType, type_t *srcType, const expr_t *expr)
}
const expr_t *
cast_expr (type_t *dstType, const expr_t *e)
cast_expr (const type_t *dstType, const expr_t *e)
{
type_t *srcType;
const type_t *srcType;
e = convert_name (e);

View file

@ -144,7 +144,7 @@ designator_index (const designator_t *des, int ele_size, int array_size)
}
typedef struct {
type_t *type;
const type_t *type;
symbol_t *field;
int offset;
} initstate_t;
@ -153,7 +153,7 @@ static initstate_t
get_designated_offset (const type_t *type, const designator_t *des)
{
int offset = -1;
type_t *ele_type = 0;
const type_t *ele_type = nullptr;
symbol_t *field = 0;
if (is_struct (type) || is_union (type)) {
@ -308,12 +308,12 @@ assign_elements (expr_t *local_expr, const expr_t *init,
element_chain_t *element_chain)
{
element_t *element;
type_t *init_type = get_type (init);
auto init_type = get_type (init);
set_t *initialized = set_new_size (type_size (init_type));
for (element = element_chain->head; element; element = element->next) {
int offset = element->offset;
type_t *type = element->type;
auto type = element->type;
const expr_t *alias = new_offset_alias_expr (type, init, offset);
const expr_t *c;

View file

@ -187,9 +187,9 @@ message_expr (const expr_t *receiver, keywordarg_t *message)
const expr_t *call;
keywordarg_t *m;
int super = 0, class_msg = 0;
type_t *rec_type = 0;
type_t *return_type;
type_t *method_type = &type_IMP;
const type_t *rec_type = nullptr;
const type_t *return_type;
const type_t *method_type = &type_IMP;
method_t *method;
const expr_t *send_msg;

View file

@ -39,7 +39,7 @@
const expr_t *
new_vector_list (const expr_t *expr_list)
{
type_t *ele_type = type_default;
const type_t *ele_type = type_default;
int count = list_count (&expr_list->list);
const expr_t *elements[count + 1];
list_scatter (&expr_list->list, elements);
@ -76,7 +76,7 @@ new_vector_list (const expr_t *expr_list)
for (int i = 0; i < count; i++) {
auto e = elements[i];
int cast_width = type_width (get_type (e));
type_t *cast_type = vector_type (ele_type, cast_width);
const type_t *cast_type = vector_type (ele_type, cast_width);
all_implicit = all_implicit && e->implicit;
elements[i] = cast_expr (cast_type, fold_constants (e));
all_constant = all_constant && is_constant (elements[i]);
@ -118,11 +118,11 @@ new_vector_list (const expr_t *expr_list)
}
if (all_constant) {
type_t *vec_type = vector_type (ele_type, width);
const type_t *vec_type = vector_type (ele_type, width);
pr_type_t value[type_size (vec_type)];
for (int i = 0, offs = 0; i < count; i++) {
type_t *src_type = get_type (elements[i]);
auto src_type = get_type (elements[i]);
value_store (value + offs, src_type, elements[i]);
offs += type_size (src_type);
}

View file

@ -93,7 +93,7 @@ func_map_get_key (const void *_f, void *unused)
}
param_t *
new_param (const char *selector, type_t *type, const char *name)
new_param (const char *selector, const type_t *type, const char *name)
{
param_t *param;
@ -107,7 +107,7 @@ new_param (const char *selector, type_t *type, const char *name)
}
param_t *
param_append_identifiers (param_t *params, symbol_t *idents, type_t *type)
param_append_identifiers (param_t *params, symbol_t *idents, const type_t *type)
{
param_t **p = &params;
@ -172,8 +172,8 @@ copy_params (param_t *params)
return n_parms;
}
type_t *
parse_params (type_t *return_type, param_t *parms)
const type_t *
parse_params (const type_t *return_type, param_t *parms)
{
param_t *p;
type_t *new;
@ -384,7 +384,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
return e;
}
}
type_t *arg_types[type.t.func.num_params];
const type_t *arg_types[type.t.func.num_params];
type.t.func.param_types = arg_types;
for (int i = 0; i < type.t.func.num_params; i++) {
auto e = args[i];
@ -469,7 +469,7 @@ find_function (const expr_t *fexpr, const expr_t *params)
}
int
value_too_large (type_t *val_type)
value_too_large (const type_t *val_type)
{
if ((options.code.progsversion < PROG_VERSION
&& type_size (val_type) > type_size (&type_param))
@ -489,12 +489,12 @@ check_function (symbol_t *fsym)
if (!type_size (fsym->type->t.func.type)) {
error (0, "return type is an incomplete type");
fsym->type->t.func.type = &type_void;//FIXME better type?
//fsym->type->t.func.type = &type_void;//FIXME better type?
}
if (value_too_large (fsym->type->t.func.type)) {
error (0, "return value too large to be passed by value (%d)",
type_size (&type_param));
fsym->type->t.func.type = &type_void;//FIXME better type?
//fsym->type->t.func.type = &type_void;//FIXME better type?
}
for (p = params, i = 0; p; p = p->next, i++) {
if (!p->selector && !p->type && !p->name)
@ -919,7 +919,7 @@ int
function_parms (function_t *f, byte *parm_size)
{
int count, i;
ty_func_t *func = &f->sym->type->t.func;
auto func = &f->sym->type->t.func;
if (func->num_params >= 0)
count = func->num_params;

View file

@ -618,7 +618,8 @@ add_data_space (qfo_t *qfo, qfo_mspace_t *space)
}
static defref_t *
make_def (int s, const char *name, type_t *type, unsigned flags, void *val)
make_def (int s, const char *name, const type_t *type, unsigned flags,
void *val)
{
qfo_def_t *def;
defref_t *ref;
@ -659,7 +660,7 @@ make_def (int s, const char *name, type_t *type, unsigned flags, void *val)
}
void
linker_add_def (const char *name, type_t *type, unsigned flags, void *val)
linker_add_def (const char *name, const type_t *type, unsigned flags, void *val)
{
make_def (qfo_near_data_space, name, type, flags, val);
}
@ -1270,7 +1271,6 @@ check_defs (void)
linker_add_def (".self", &type_entity, QFOD_GLOBAL, 0);
did_self = 1;
} else if (strcmp (name, ".this") == 0 && !did_this) {
type_t *type;
int flags;
defref_t *this_ref;
@ -1279,7 +1279,7 @@ check_defs (void)
flags = QFOD_GLOBAL | QFOD_NOSAVE;
this_ref = make_def (qfo_entity_space, name, &type_id, flags, 0);
flags |= QFOD_CONSTANT | QFOD_INITIALIZED;
type = field_type (&type_id);
auto type = field_type (&type_id);
linker_add_def (".this", type, flags, &REF (this_ref)->offset);
did_this = 1;
}

View file

@ -82,7 +82,7 @@ method_free (void *_meth, void *unused)
}
method_t *
new_method (type_t *ret_type, param_t *selector, param_t *opt_params)
new_method (const type_t *ret_type, param_t *selector, param_t *opt_params)
{
method_t *meth = malloc (sizeof (method_t));
param_t *cmd = new_param (0, &type_SEL, "_cmd");
@ -505,7 +505,7 @@ emit_selectors (void)
{
symbol_t *sel_sym;
def_t *sel_def;
type_t *sel_type;
const type_t *sel_type;
pr_sel_t *sel;
selector_t **selectors, **s;
@ -705,7 +705,7 @@ method_check_params (method_t *method, const expr_t *args)
{
int i, param_count;
const expr_t *err = 0;
type_t *mtype = method->type;
auto mtype = method->type;
if (mtype->t.func.num_params == -1)
return 0;
@ -725,13 +725,12 @@ method_check_params (method_t *method, const expr_t *args)
list_scatter_rev (&args->list, arg_list);
for (i = 2; i < count; i++) {
const expr_t *e = arg_list[i];
type_t *arg_type = i < param_count ? mtype->t.func.param_types[i] : 0;
type_t *t;
const type_t *arg_type = i < param_count ? mtype->t.func.param_types[i]
: nullptr;
if (e->type == ex_compound) {
e = expr_file_line (initialized_temp_expr (arg_type, e), e);
}
t = get_type (e);
auto t = get_type (e);
if (!t) {
return e;
}

View file

@ -64,7 +64,7 @@
reloc_def_string (&loc); \
} while (0)
typedef def_t *(*encode_f) (type_t *type, defspace_t *space);
typedef def_t *(*encode_f) (const type_t *type, defspace_t *space);
static pr_string_t
encoding_string (const char *string)
@ -76,7 +76,7 @@ encoding_string (const char *string)
}
static def_t *
qfo_new_encoding (type_t *type, int size, defspace_t *space)
qfo_new_encoding (const type_t *type, int size, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -95,7 +95,7 @@ qfo_new_encoding (type_t *type, int size, defspace_t *space)
}
static def_t *
qfo_encode_func (type_t *type, defspace_t *space)
qfo_encode_func (const type_t *type, defspace_t *space)
{
int param_count;
int size;
@ -128,7 +128,7 @@ qfo_encode_func (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_fldptr (type_t *type, defspace_t *space)
qfo_encode_fldptr (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -143,7 +143,7 @@ qfo_encode_fldptr (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_basic (type_t *type, defspace_t *space)
qfo_encode_basic (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -161,7 +161,7 @@ qfo_encode_basic (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_struct (type_t *type, defspace_t *space)
qfo_encode_struct (const type_t *type, defspace_t *space)
{
sy_type_e sy;
int num_fields;
@ -194,7 +194,7 @@ qfo_encode_struct (type_t *type, defspace_t *space)
ENC_STR (strct->tag, type->name);
strct->num_fields = num_fields;
type->type_def = def; // avoid infinite recursion
((type_t *)type)->type_def = def; // avoid infinite recursion
field_types = alloca (num_fields * sizeof (def_t *));
for (i = 0, sym = type->t.symtab->symbols; sym; sym = sym->next) {
@ -228,7 +228,7 @@ qfo_encode_struct (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_array (type_t *type, defspace_t *space)
qfo_encode_array (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -245,7 +245,7 @@ qfo_encode_array (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_class (type_t *type, defspace_t *space)
qfo_encode_class (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -257,7 +257,7 @@ qfo_encode_class (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_alias (type_t *type, defspace_t *space)
qfo_encode_alias (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -279,7 +279,7 @@ qfo_encode_alias (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_handle (type_t *type, defspace_t *space)
qfo_encode_handle (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -292,7 +292,7 @@ qfo_encode_handle (type_t *type, defspace_t *space)
}
static def_t *
qfo_encode_algebra (type_t *type, defspace_t *space)
qfo_encode_algebra (const type_t *type, defspace_t *space)
{
qfot_type_t *enc;
def_t *def;
@ -316,7 +316,7 @@ qfo_encode_algebra (type_t *type, defspace_t *space)
}
def_t *
qfo_encode_type (type_t *type, defspace_t *space)
qfo_encode_type (const type_t *type, defspace_t *space)
{
reloc_t *relocs = 0;
@ -334,15 +334,15 @@ qfo_encode_type (type_t *type, defspace_t *space)
if (type->type_def && type->type_def->external) {
relocs = type->type_def->relocs;
type->type_def = 0;
((type_t *) type)->type_def = 0;
}
if (type->type_def)
return type->type_def;
if (type->meta >= sizeof (funcs) / (sizeof (funcs[0])))
internal_error (0, "bad type meta type");
if (!type->encoding)
type->encoding = type_get_encoding (type);
type->type_def = funcs[type->meta] (type, space);
((type_t *) type)->encoding = type_get_encoding (type);
((type_t *) type)->type_def = funcs[type->meta] (type, space);
reloc_attach_relocs (relocs, &type->type_def->relocs);
return type->type_def;
}

View file

@ -591,7 +591,7 @@ static const expr_t *
parse_int_vector (const char *token, int width)
{
char t1 = 0, t2 = 0;
type_t *type = 0;
const type_t *type = nullptr;
union {
pr_long_t l[4];
@ -713,7 +713,7 @@ static const expr_t *
parse_float_vector (const char *token, int width)
{
char t = 0;
type_t *type = 0;
const type_t *type = nullptr;
union {
pr_double_t d[4];

View file

@ -238,7 +238,7 @@ static const expr_t *break_label;
static const expr_t *continue_label;
static specifier_t
make_spec (type_t *type, storage_class_t storage, int is_typedef,
make_spec (const type_t *type, storage_class_t storage, int is_typedef,
int is_overload)
{
specifier_t spec;
@ -359,13 +359,13 @@ pointer_spec (specifier_t quals, specifier_t spec)
static specifier_t
parse_qc_params (specifier_t spec, param_t *params)
{
type_t **type;
const type_t **type;
// .float () foo; is a field holding a function variable rather
// than a function that returns a float field.
for (type = &spec.type; *type && is_field (*type);
type = &(*type)->t.fldptr.type) {
type = (const type_t **) &(*type)->t.fldptr.type) {
}
type_t *ret_type = *type;
const type_t *ret_type = *type;
*type = 0;
spec.sym = new_symbol (0);
@ -417,7 +417,7 @@ make_param (specifier_t spec)
}
static param_t *
make_selector (const char *selector, struct type_s *type, const char *name)
make_selector (const char *selector, const type_t *type, const char *name)
{
param_t *param = new_param (selector, type, name);
return param;

View file

@ -83,7 +83,7 @@ int yylex (void);
int op;
struct def_s *def;
struct hashtab_s *def_list;
struct type_s *type;
const struct type_s *type;
struct typedef_s *typename;
const struct expr_s *expr;
struct expr_s *mut_expr;

View file

@ -354,7 +354,7 @@ pseudo_operand (pseudoop_t *pseudoop, const expr_t *expr)
}
operand_t *
nil_operand (type_t *type, const expr_t *expr)
nil_operand (const type_t *type, const expr_t *expr)
{
operand_t *op;
op = new_operand (op_nil, expr, __builtin_return_address (0));
@ -365,7 +365,7 @@ nil_operand (type_t *type, const expr_t *expr)
}
operand_t *
def_operand (def_t *def, type_t *type, const expr_t *expr)
def_operand (def_t *def, const type_t *type, const expr_t *expr)
{
operand_t *op;
@ -380,7 +380,7 @@ def_operand (def_t *def, type_t *type, const expr_t *expr)
}
operand_t *
return_operand (type_t *type, const expr_t *expr)
return_operand (const type_t *type, const expr_t *expr)
{
symbol_t *return_symbol;
return_symbol = make_symbol (".return", &type_param, pr.symtab->space,
@ -475,7 +475,8 @@ tempop_visit_all (tempop_t *tempop, int overlap,
}
operand_t *
offset_alias_operand (type_t *type, int offset, operand_t *aop, const expr_t *expr)
offset_alias_operand (const type_t *type, int offset, operand_t *aop,
const expr_t *expr)
{
operand_t *top;
def_t *def;
@ -534,7 +535,7 @@ offset_alias_operand (type_t *type, int offset, operand_t *aop, const expr_t *ex
}
operand_t *
alias_operand (type_t *type, operand_t *op, const expr_t *expr)
alias_operand (const type_t *type, operand_t *op, const expr_t *expr)
{
operand_t *aop;
@ -765,10 +766,9 @@ static operand_t *
operand_address (operand_t *reference, const expr_t *e)
{
def_t *def;
type_t *type;
int offset = 0;
type = reference->type;
auto type = reference->type;
switch (reference->op_type) {
case op_def:
// assumes aliasing is only one level deep which should be the
@ -832,8 +832,8 @@ expr_assign_copy (sblock_t *sblock, const expr_t *e, operand_t **op, operand_t *
statement_t *s;
const expr_t *dst_expr = e->assign.dst;
const expr_t *src_expr = e->assign.src;
type_t *dst_type = get_type (dst_expr);
type_t *src_type = get_type (src_expr);
auto dst_type = get_type (dst_expr);
auto src_type = get_type (src_expr);
unsigned count;
const expr_t *count_expr;
operand_t *dst = 0;
@ -960,7 +960,7 @@ expr_assign (sblock_t *sblock, const expr_t *e, operand_t **op)
statement_t *s;
const expr_t *src_expr = e->assign.src;
const expr_t *dst_expr = e->assign.dst;
type_t *dst_type = get_type (dst_expr);
auto dst_type = get_type (dst_expr);
operand_t *src = 0;
operand_t *dst = 0;
operand_t *ofs = 0;
@ -1184,7 +1184,7 @@ expr_call (sblock_t *sblock, const expr_t *call, operand_t **op)
const char *arg_name = va (0, ".arg%d", arg_num++);
def_t *def = new_def (arg_name, 0, current_func->arguments,
sc_argument);
type_t *arg_type = get_type (a);
auto arg_type = get_type (a);
int size = type_size (arg_type);
int alignment = arg_type->alignment;
if (alignment < 4) {
@ -1339,7 +1339,7 @@ ptr_addressing_mode (sblock_t *sblock, const expr_t *ref,
operand_t **base, operand_t **offset, pr_ushort_t *mode,
operand_t **target)
{
type_t *type = get_type (ref);
auto type = get_type (ref);
if (!is_ptr (type)) {
internal_error (ref, "expected pointer in ref");
}
@ -1361,7 +1361,7 @@ ptr_addressing_mode (sblock_t *sblock, const expr_t *ref,
type = type->t.fldptr.type;
if (offs) {
const expr_t *lv = lvalue->alias.expr;
type_t *lvtype = get_type (lv);
auto lvtype = get_type (lv);
int o = expr_int (offs);
if (o < 0 || o + type_size (type) > type_size (lvtype)) {
// not a valid offset for the type, which technically should
@ -1482,7 +1482,7 @@ statement_return (sblock_t *sblock, const expr_t *e)
if (options.code.progsversion < PROG_VERSION) {
if (e->retrn.ret_val) {
const expr_t *ret_val = e->retrn.ret_val;
type_t *ret_type = get_type (ret_val);
auto ret_type = get_type (ret_val);
// at_return is used for passing the result of a void_return
// function through void. v6 progs always use .return for the
@ -1496,7 +1496,7 @@ statement_return (sblock_t *sblock, const expr_t *e)
} else {
if (!e->retrn.at_return && e->retrn.ret_val) {
const expr_t *ret_val = e->retrn.ret_val;
type_t *ret_type = get_type (ret_val);
auto ret_type = get_type (ret_val);
operand_t *target = 0;
pr_ushort_t ret_crtl = type_size (ret_type) - 1;
pr_ushort_t mode = 0;
@ -1650,13 +1650,12 @@ static sblock_t *
expr_alias (sblock_t *sblock, const expr_t *e, operand_t **op)
{
operand_t *aop = 0;
type_t *type;
int offset = 0;
if (e->alias.offset) {
offset = expr_int (e->alias.offset);
}
type = e->alias.type;
auto type = e->alias.type;
sblock = statement_subexpr (sblock, e->alias.expr, &aop);
*op = offset_alias_operand (type, offset, aop, e);
return sblock;
@ -1780,7 +1779,7 @@ expr_horizontal (sblock_t *sblock, const expr_t *e, operand_t **op)
statement_t *s;
int hop;
type_t *res_type = e->hop.type;
type_t *vec_type = get_type (e->hop.vec);
auto vec_type = get_type (e->hop.vec);
switch (e->hop.op) {
case '&':
@ -1832,7 +1831,7 @@ expr_swizzle (sblock_t *sblock, const expr_t *e, operand_t **op)
const char *opcode = "swizzle";
statement_t *s;
int swiz = 0;
type_t *res_type = e->swizzle.type;
auto res_type = e->swizzle.type;
for (int i = 0; i < 4; i++) {
swiz |= (e->swizzle.source[i] & 3) << (2 * i);
@ -1855,12 +1854,12 @@ expr_swizzle (sblock_t *sblock, const expr_t *e, operand_t **op)
static sblock_t *
expr_extend (sblock_t *sblock, const expr_t *e, operand_t **op)
{
type_t *src_type = get_type (e->extend.src);
type_t *res_type = e->extend.type;
auto src_type = get_type (e->extend.src);
auto res_type = e->extend.type;
int src_width = type_width (src_type);
int res_width = type_width (res_type);
type_t *src_base = base_type (src_type);
type_t *res_base = base_type (res_type);
auto src_base = base_type (src_type);
auto res_base = base_type (res_type);
static int mode[4][4] = {
{-1, 0, 1, 2},
{-1,-1, 3, 4},
@ -1935,7 +1934,7 @@ statement_copy_elements (sblock_t **sblock, const expr_t *dst, const expr_t *src
index += statement_copy_elements (sblock, dst, e, index + base);
} else {
int size = type_size (base_type (get_type (dst)));
type_t *src_type = get_type (e);
auto src_type = get_type (e);
const expr_t *dst_ele = new_offset_alias_expr (src_type, dst,
size * (index + base));
index += type_width (src_type);
@ -1949,7 +1948,7 @@ static sblock_t *
expr_vector_e (sblock_t *sblock, const expr_t *e, operand_t **op)
{
const expr_t *tmp;
type_t *vec_type = get_type (e);
auto vec_type = get_type (e);
int file = pr.source_file;
int line = pr.source_line;

View file

@ -65,7 +65,7 @@
#include "tools/qfcc/include/value.h"
static symbol_t *
find_tag (ty_meta_e meta, symbol_t *tag, type_t *type)
find_tag (ty_meta_e meta, symbol_t *tag, const type_t *type)
{
const char *tag_name;
symbol_t *sym;
@ -87,13 +87,14 @@ find_tag (ty_meta_e meta, symbol_t *tag, type_t *type)
return sym;
}
sym = new_symbol (tag_name);
if (!type)
type = new_type ();
if (!type->name)
type->name = sym->name;
sym->type = type;
sym->type->type = ev_invalid;
sym->type->meta = meta;
type_t *t = (type_t *) type;//FIXME
if (!t)
t = new_type ();
if (!t->name)
t->name = sym->name;
t->type = ev_invalid;
t->meta = meta;
sym->type = t;
sym->sy_type = sy_type;
return sym;
}
@ -126,7 +127,7 @@ start_struct (int *su, symbol_t *tag, symtab_t *parent)
}
symbol_t *
find_handle (symbol_t *tag, type_t *type)
find_handle (symbol_t *tag, const type_t *type)
{
if (type != &type_int && type != &type_long) {
error (0, "@handle type must be int or long");
@ -134,15 +135,16 @@ find_handle (symbol_t *tag, type_t *type)
}
symbol_t *sym = find_tag (ty_handle, tag, 0);
if (sym->type->type == ev_invalid) {
sym->type->type = type->type;
sym->type->width = 1;
sym->type->alignment = type->alignment;
type_t *t = (type_t *) sym->type;//FIXME
t->type = type->type;
t->width = 1;
t->alignment = type->alignment;
}
return sym;
}
symbol_t *
find_struct (int su, symbol_t *tag, type_t *type)
find_struct (int su, symbol_t *tag, const type_t *type)
{
ty_meta_e meta = ty_struct;
@ -153,7 +155,8 @@ find_struct (int su, symbol_t *tag, type_t *type)
}
symbol_t *
build_struct (int su, symbol_t *tag, symtab_t *symtab, type_t *type, int base)
build_struct (int su, symbol_t *tag, symtab_t *symtab, const type_t *type,
int base)
{
symbol_t *sym = find_struct (su, tag, type);
symbol_t *s;
@ -216,12 +219,13 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, type_t *type, int base)
}
if (!type)
sym->type = find_type (sym->type); // checks the tag, not the symtab
sym->type->t.symtab = symtab;
((type_t *) sym->type)->t.symtab = symtab;
if (alignment > sym->type->alignment) {
sym->type->alignment = alignment;
((type_t *) sym->type)->alignment = alignment;
}
if (!type && sym->type->type_def->external) //FIXME should not be necessary
sym->type->type_def = qfo_encode_type (sym->type, pr.type_data);
((type_t *) sym->type)->type_def = qfo_encode_type (sym->type,
pr.type_data);
return sym;
}
@ -238,9 +242,9 @@ start_enum (symbol_t *sym)
error (0, "%s defined as wrong kind of tag", sym->name);
sym = find_enum (0);
}
sym->type->t.symtab = new_symtab (current_symtab, stab_enum);
sym->type->alignment = 1;
sym->type->width = 1;
((type_t *) sym->type)->t.symtab = new_symtab (current_symtab, stab_enum);
((type_t *) sym->type)->alignment = 1;
((type_t *) sym->type)->width = 1;
return sym->type->t.symtab;
}
@ -249,10 +253,9 @@ finish_enum (symbol_t *sym)
{
symbol_t *enum_sym;
symbol_t *name;
type_t *enum_type;
symtab_t *enum_tab;
enum_type = sym->type = find_type (sym->type);
auto enum_type = sym->type = find_type (sym->type);
enum_tab = enum_type->t.symtab;
for (name = enum_tab->symbols; name; name = name->next) {
@ -269,7 +272,7 @@ finish_enum (symbol_t *sym)
void
add_enum (symbol_t *enm, symbol_t *name, const expr_t *val)
{
type_t *enum_type = enm->type;
auto enum_type = enm->type;
symtab_t *enum_tab = enum_type->t.symtab;
int value;
@ -296,7 +299,7 @@ add_enum (symbol_t *enm, symbol_t *name, const expr_t *val)
}
int
enum_as_bool (type_t *enm, expr_t **zero, expr_t **one)
enum_as_bool (const type_t *enm, expr_t **zero, expr_t **one)
{
symtab_t *symtab = enm->t.symtab;
symbol_t *zero_sym = 0;
@ -330,7 +333,8 @@ enum_as_bool (type_t *enm, expr_t **zero, expr_t **one)
}
symbol_t *
make_structure (const char *name, int su, struct_def_t *defs, type_t *type)
make_structure (const char *name, int su, struct_def_t *defs,
const type_t *type)
{
symtab_t *strct;
symbol_t *field;
@ -354,8 +358,9 @@ make_structure (const char *name, int su, struct_def_t *defs, type_t *type)
}
def_t *
emit_structure (const char *name, int su, struct_def_t *defs, type_t *type,
void *data, defspace_t *space, storage_class_t storage)
emit_structure (const char *name, int su, struct_def_t *defs,
const type_t *type, void *data, defspace_t *space,
storage_class_t storage)
{
int i, j;
int saw_null = 0;
@ -414,7 +419,7 @@ emit_structure (const char *name, int su, struct_def_t *defs, type_t *type,
data = &val[type_size (field_def.type)];
} else {
if (is_array (field_def.type)) {
type_t *type = field_def.type->t.array.type;
auto type = dereference_type (field_def.type);
for (j = 0; j < field_def.type->t.array.size; j++) {
defs[i].emit (&field_def, data, j);
field_def.offset += type_size (type);

View file

@ -57,10 +57,10 @@ void def_to_ddef (def_t *def, ddef_t *ddef, int aux) {}
__attribute__((noreturn)) void _internal_error (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {abort();}
__attribute__((const)) const expr_t *_warning (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
__attribute__((const)) const expr_t *_error (const expr_t *e, const char *file, int line, const char *func, const char *fmt, ...) {return 0;}
__attribute__((const)) symbol_t *make_structure (const char *name, int su, struct_def_t *defs, type_t *type) {return 0;}
__attribute__((const)) symbol_t *make_structure (const char *name, int su, struct_def_t *defs, const type_t *type) {return 0;}
__attribute__((const)) symbol_t *symtab_addsymbol (symtab_t *symtab, symbol_t *symbol) {return 0;}
__attribute__((const)) symbol_t *new_symbol_type (const char *name, type_t *type) {return 0;}
__attribute__((const)) def_t *qfo_encode_type (type_t *type, defspace_t *space) {return 0;}
__attribute__((const)) symbol_t *new_symbol_type (const char *name, const type_t *type) {return 0;}
__attribute__((const)) def_t *qfo_encode_type (const type_t *type, defspace_t *space) {return 0;}
__attribute__((const)) int obj_types_assignable (const type_t *dst, const type_t *src) {return 0;}
void print_protocollist (struct dstring_s *dstr, protocollist_t *protocollist) {}
void defspace_sort_defs (defspace_t *space) {}

View file

@ -130,8 +130,8 @@ case_label_expr (switch_block_t *switch_block, const expr_t *value)
if (!switch_block->test)
internal_error (value, "broken switch block");
if (value) {
type_t *type = get_type (switch_block->test);
type_t *val_type = get_type (value);
auto type = get_type (switch_block->test);
auto val_type = get_type (value);
if (!type)
return 0;
if (!type_assignable (type, get_type (value)))
@ -380,7 +380,7 @@ check_enum_switch (switch_block_t *switch_block)
{
case_label_t cl;
symbol_t *enum_val;
type_t *type = get_type (switch_block->test);
auto type = get_type (switch_block->test);
for (enum_val = type->t.symtab->symbols; enum_val;
enum_val = enum_val->next) {
@ -410,7 +410,7 @@ switch_expr (switch_block_t *switch_block, const expr_t *break_label,
case_label_t _default_label;
case_label_t *default_label = &_default_label;
expr_t *sw = new_block_expr (0);
type_t *type = get_type (switch_block->test);
auto type = get_type (switch_block->test);
const expr_t *sw_val = new_temp_def_expr (type);
const expr_t *default_expr;
int num_labels = 0;

View file

@ -83,7 +83,7 @@ new_symbol (const char *name)
}
symbol_t *
new_symbol_type (const char *name, type_t *type)
new_symbol_type (const char *name, const type_t *type)
{
symbol_t *symbol;
symbol = new_symbol (name);
@ -213,7 +213,7 @@ symtab_flat_copy (symtab_t *symtab, symtab_t *parent, stab_type_e type)
}
symbol_t *
make_symbol (const char *name, type_t *type, defspace_t *space,
make_symbol (const char *name, const type_t *type, defspace_t *space,
storage_class_t storage)
{
symbol_t *sym;

View file

@ -248,14 +248,14 @@ free_type (type_t *type)
break;
case ev_field:
case ev_ptr:
free_type (type->t.fldptr.type);
free_type ((type_t *) type->t.fldptr.type);
break;
case ev_func:
free_type (type->t.func.type);
free_type ((type_t *) type->t.func.type);
break;
case ev_invalid:
if (type->meta == ty_array)
free_type (type->t.array.type);
free_type ((type_t *) type->t.array.type);
break;
}
memset (type, 0, sizeof (*type));
@ -291,12 +291,12 @@ copy_chain (type_t *type, type_t *append)
internal_error (0, "copy basic type");
case ev_field:
case ev_ptr:
n = &(*n)->t.fldptr.type;
type = type->t.fldptr.type;
n = (type_t **) &(*n)->t.fldptr.type;
type = (type_t *) type->t.fldptr.type;
break;
case ev_func:
n = &(*n)->t.func.type;
type = type->t.func.type;
n = (type_t **) &(*n)->t.func.type;
type = (type_t *) type->t.func.type;
break;
case ev_invalid:
internal_error (0, "invalid basic type");
@ -304,8 +304,8 @@ copy_chain (type_t *type, type_t *append)
}
break;
case ty_array:
n = &(*n)->t.array.type;
type = type->t.array.type;
n = (type_t **) &(*n)->t.array.type;
type = (type_t *) type->t.array.type;
break;
case ty_struct:
case ty_union:
@ -322,10 +322,10 @@ copy_chain (type_t *type, type_t *append)
return new;
}
type_t *
append_type (type_t *type, type_t *new)
const type_t *
append_type (const type_t *type, const type_t *new)
{
type_t **t = &type;
const type_t **t = &type;
while (*t) {
switch ((*t)->meta) {
@ -348,14 +348,14 @@ append_type (type_t *type, type_t *new)
internal_error (0, "append to basic type");
case ev_field:
case ev_ptr:
t = &(*t)->t.fldptr.type;
type->alignment = 1;
type->width = 1;
t = (const type_t **) &(*t)->t.fldptr.type;
((type_t *) type)->alignment = 1;
((type_t *) type)->width = 1;
break;
case ev_func:
t = &(*t)->t.func.type;
type->alignment = 1;
type->width = 1;
t = (const type_t **) &(*t)->t.func.type;
((type_t *) type)->alignment = 1;
((type_t *) type)->width = 1;
break;
case ev_invalid:
internal_error (0, "invalid basic type");
@ -363,9 +363,9 @@ append_type (type_t *type, type_t *new)
}
break;
case ty_array:
t = &(*t)->t.array.type;
type->alignment = new->alignment;
type->width = new->width;
t = (const type_t **) &(*t)->t.array.type;
((type_t *) type)->alignment = new->alignment;
((type_t *) type)->width = new->width;
break;
case ty_struct:
case ty_union:
@ -379,7 +379,7 @@ append_type (type_t *type, type_t *new)
}
}
if (type && new->meta == ty_alias) {
type_t *chain = find_type (copy_chain (type, new));
auto chain = find_type (copy_chain ((type_t *) type, (type_t *) new));
*t = new->t.alias.aux_type;
type = alias_type (type, chain, 0);
} else {
@ -389,7 +389,7 @@ append_type (type_t *type, type_t *new)
}
static __attribute__((pure)) int
types_same (type_t *a, type_t *b)
types_same (const type_t *a, const type_t *b)
{
int i, count;
@ -454,10 +454,10 @@ types_same (type_t *a, type_t *b)
}
void
set_func_type_attrs (type_t *func, specifier_t spec)
set_func_type_attrs (const type_t *func, specifier_t spec)
{
func->t.func.no_va_list = spec.no_va_list;
func->t.func.void_return = spec.void_return;
((type_t *) func)->t.func.no_va_list = spec.no_va_list;//FIXME
((type_t *) func)->t.func.void_return = spec.void_return;
}
specifier_t
@ -535,8 +535,8 @@ default_type (specifier_t spec, symbol_t *sym)
Returns a preexisting complex type that matches the parm, or allocates
a new one and copies it out.
*/
type_t *
find_type (type_t *type)
const type_t *
find_type (const type_t *type)
{
type_t *check;
int i, count;
@ -550,15 +550,15 @@ find_type (type_t *type)
switch (type->type) {
case ev_field:
case ev_ptr:
type->t.fldptr.type = find_type (type->t.fldptr.type);
((type_t *) type)->t.fldptr.type = find_type (type->t.fldptr.type);
break;
case ev_func:
type->t.func.type = find_type (type->t.func.type);
((type_t *) type)->t.func.type = find_type (type->t.func.type);
count = type->t.func.num_params;
if (count < 0)
count = ~count; // param count is one's complement
for (i = 0; i < count; i++)
type->t.func.param_types[i]
((type_t *) type)->t.func.param_types[i]
= find_type (type->t.func.param_types[i]);
break;
default: // other types don't have aux data
@ -570,13 +570,13 @@ find_type (type_t *type)
case ty_enum:
break;
case ty_array:
type->t.array.type = find_type (type->t.array.type);
((type_t *) type)->t.array.type = find_type (type->t.array.type);
break;
case ty_class:
break;
case ty_alias:
type->t.alias.aux_type = find_type (type->t.alias.aux_type);
type->t.alias.full_type = find_type (type->t.alias.full_type);
((type_t *) type)->t.alias.aux_type = find_type (type->t.alias.aux_type);
((type_t *) type)->t.alias.full_type = find_type (type->t.alias.full_type);
break;
case ty_handle:
break;
@ -616,8 +616,8 @@ find_type (type_t *type)
return check;
}
type_t *
field_type (type_t *aux)
const type_t *
field_type (const type_t *aux)
{
type_t _new;
type_t *new = &_new;
@ -630,12 +630,12 @@ field_type (type_t *aux)
new->alignment = 1;
new->width = 1;
if (aux) {
new = find_type (append_type (new, aux));
return find_type (append_type (new, aux));
}
return new;
}
type_t *
const type_t *
pointer_type (const type_t *aux)
{
type_t _new;
@ -649,12 +649,12 @@ pointer_type (const type_t *aux)
new->alignment = 1;
new->width = 1;
if (aux) {
new = find_type (append_type (new, (type_t *) aux));
return find_type (append_type (new, aux));
}
return new;
}
type_t *
const type_t *
vector_type (const type_t *ele_type, int width)
{
if (width == 1) {
@ -681,7 +681,7 @@ vector_type (const type_t *ele_type, int width)
return 0;
}
type_t *
const type_t *
base_type (const type_t *vec_type)
{
if (is_algebra (vec_type)) {
@ -697,7 +697,7 @@ base_type (const type_t *vec_type)
return ev_types[vec_type->type];
}
type_t *
const type_t *
int_type (const type_t *base)
{
int width = type_width (base);
@ -713,7 +713,7 @@ int_type (const type_t *base)
return vector_type (base, width);
}
type_t *
const type_t *
uint_type (const type_t *base)
{
int width = type_width (base);
@ -729,7 +729,7 @@ uint_type (const type_t *base)
return vector_type (base, width);
}
type_t *
const type_t *
float_type (const type_t *base)
{
int width = type_width (base);
@ -745,7 +745,7 @@ float_type (const type_t *base)
return vector_type (base, width);
}
type_t *
const type_t *
array_type (const type_t *aux, int size)
{
type_t _new;
@ -763,13 +763,13 @@ array_type (const type_t *aux, int size)
}
new->t.array.size = size;
if (aux) {
new = find_type (append_type (new, (type_t *) aux));
return find_type (append_type (new, aux));
}
return new;
}
type_t *
based_array_type (type_t *aux, int base, int top)
const type_t *
based_array_type (const type_t *aux, int base, int top)
{
type_t _new;
type_t *new = &_new;
@ -788,13 +788,13 @@ based_array_type (type_t *aux, int base, int top)
new->t.array.base = base;
new->t.array.size = top - base + 1;
if (aux) {
new = find_type (new);
return find_type (new);
}
return new;
}
type_t *
alias_type (type_t *type, type_t *alias_chain, const char *name)
const type_t *
alias_type (const type_t *type, const type_t *alias_chain, const char *name)
{
type_t *alias = new_type ();
alias->meta = ty_alias;
@ -1543,7 +1543,7 @@ build_vector_struct (type_t *type)
{
ty_meta_e meta = type->meta;
etype_t etype = type->type;
type_t *ele_type = base_type (type);
auto ele_type = base_type (type);
int width = type_width (type);
if (!ele_type || width < 2) {

View file

@ -103,7 +103,7 @@ new_value (void)
}
static void
set_val_type (ex_value_t *val, type_t *type)
set_val_type (ex_value_t *val, const type_t *type)
{
val->type = type;
val->lltype = low_level_type (type);
@ -175,7 +175,7 @@ new_entity_val (int entity_val)
}
ex_value_t *
new_field_val (int field_val, type_t *type, def_t *def)
new_field_val (int field_val, const type_t *type, def_t *def)
{
ex_value_t val;
memset (&val, 0, sizeof (val));
@ -187,7 +187,7 @@ new_field_val (int field_val, type_t *type, def_t *def)
}
ex_value_t *
new_func_val (int func_val, type_t *type)
new_func_val (int func_val, const type_t *type)
{
ex_value_t val;
memset (&val, 0, sizeof (val));
@ -198,7 +198,7 @@ new_func_val (int func_val, type_t *type)
}
ex_value_t *
new_pointer_val (int pointer_val, type_t *type, def_t *def,
new_pointer_val (int pointer_val, const type_t *type, def_t *def,
struct operand_s *tempop)
{
ex_value_t val;
@ -271,7 +271,7 @@ new_short_val (short short_val)
}
ex_value_t *
new_nil_val (type_t *type)
new_nil_val (const type_t *type)
{
ex_value_t val;
memset (&val, 0, sizeof (val));
@ -535,7 +535,7 @@ ReuseString (const char *str)
}
ex_value_t *
offset_alias_value (ex_value_t *value, type_t *type, int offset)
offset_alias_value (ex_value_t *value, const type_t *type, int offset)
{
if (type_size (type) > type_size (value->type)) {
error (0, "unable to alias to a larger sized value");
@ -622,7 +622,7 @@ emit_value (ex_value_t *value, def_t *def)
{
def_t *cn;
hashtab_t *tab = 0;
type_t *type;
const type_t *type;
ex_value_t val = *value;
if (!string_imm_defs) {