Commit 855f9aaa authored by Michael Beck's avatar Michael Beck
Browse files

added first_variadic_param, more doxygen comments

fixed new_type_pointer macro

[r2888]
parent 5823d9ef
......@@ -432,10 +432,23 @@ bool equal_type(type *typ1, type *typ2) {
}
} break;
case tpo_method: {
int n_param1, n_param2;
if (get_method_variadicity(typ1) != get_method_variadicity(typ2)) return false;
if (get_method_n_params(typ1) != get_method_n_params(typ2)) return false;
if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return false;
for (i = 0; i < get_method_n_params(typ1); i++) {
if (get_method_n_ress(typ1) != get_method_n_ress(typ2)) return false;
if (get_method_variadicity(typ1) == variadicity_non_variadic) {
n_param1 = get_method_n_params(typ1);
n_param2 = get_method_n_params(typ2);
}
else {
n_param1 = get_method_first_variadic_param_index(typ1);
n_param2 = get_method_first_variadic_param_index(typ2);
}
if (n_param1 != n_param2) return false;
for (i = 0; i < n_param1; i++) {
if (!equal_type(get_method_param_type(typ1, i), get_method_param_type(typ2, i)))
return false;
}
......@@ -524,6 +537,7 @@ bool smaller_type (type *st, type *lt) {
}
} break;
case tpo_method: {
/** FIXME: is this still true? */
if (get_method_variadicity(st) != get_method_variadicity(lt)) return false;
if (get_method_n_params(st) != get_method_n_params(lt)) return false;
if (get_method_n_ress(st) != get_method_n_ress(lt)) return false;
......@@ -600,9 +614,9 @@ bool smaller_type (type *st, type *lt) {
return true;
}
/*******************************************************************/
/** TYPE_CLASS **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* TYPE_CLASS */
/*-----------------------------------------------------------------*/
/* create a new class type */
type *new_type_class (ident *name) {
......@@ -643,10 +657,12 @@ void add_class_member (type *clss, entity *member) {
assert(clss && (clss->type_op == type_class));
ARR_APP1 (entity *, clss->attr.ca.members, member);
}
int get_class_n_members (type *clss) {
assert(clss && (clss->type_op == type_class));
return (ARR_LEN (clss->attr.ca.members))-1;
}
int get_class_member_index(type *clss, entity *mem) {
int i;
assert(clss && (clss->type_op == type_class));
......@@ -655,11 +671,13 @@ int get_class_member_index(type *clss, entity *mem) {
return i;
return -1;
}
entity *get_class_member (type *clss, int pos) {
assert(clss && (clss->type_op == type_class));
assert(pos >= 0 && pos < get_class_n_members(clss));
return clss->attr.ca.members[pos+1];
}
entity *get_class_member_by_name(type *clss, ident *name) {
int i, n_mem;
assert(clss && (clss->type_op == type_class));
......@@ -829,9 +847,9 @@ bool is_subclass_of(type *low, type *high) {
return false;
}
/*******************************************************************/
/** TYPE_STRUCT **/
/*******************************************************************/
/*----------------------------------------------------------------**/
/* TYPE_STRUCT */
/*----------------------------------------------------------------**/
/* create a new type struct */
type *new_type_struct (ident *name) {
......@@ -861,17 +879,29 @@ int get_struct_n_members (type *strct) {
assert(strct && (strct->type_op == type_struct));
return (ARR_LEN (strct->attr.sa.members))-1;
}
void add_struct_member (type *strct, entity *member) {
assert(strct && (strct->type_op == type_struct));
assert(get_type_tpop(get_entity_type(member)) != type_method);
/* @@@ lowerfirm geht nicht durch */
ARR_APP1 (entity *, strct->attr.sa.members, member);
}
entity *get_struct_member (type *strct, int pos) {
assert(strct && (strct->type_op == type_struct));
assert(pos >= 0 && pos < get_struct_n_members(strct));
return strct->attr.sa.members[pos+1];
}
int get_struct_member_index(type *strct, entity *mem) {
int i;
assert(strct && (strct->type_op == type_struct));
for (i = 0; i < get_struct_n_members(strct); i++)
if (get_struct_member(strct, i) == mem)
return i;
return -1;
}
void set_struct_member (type *strct, int pos, entity *member) {
assert(strct && (strct->type_op == type_struct));
assert(pos >= 0 && pos < get_struct_n_members(strct));
......@@ -900,7 +930,15 @@ bool is_struct_type(type *strct) {
/** TYPE_METHOD **/
/*******************************************************************/
/* Lazy construction of value argument / result representation. */
/**
* Lazy construction of value argument / result representation.
* Constructs a struct type and its member. The types of the members
* are passed in the argument list.
*
* @param name name of the type constructed
* @param len number of fields
* @param tps array of field types with length len
*/
static INLINE type *
build_value_type(ident *name, int len, type **tps) {
int i;
......@@ -919,17 +957,19 @@ build_value_type(ident *name, int len, type **tps) {
N_param is the number of parameters, n_res the number of results. */
type *new_type_method (ident *name, int n_param, int n_res) {
type *res;
res = new_type(type_method, mode_P_mach, name);
res->state = layout_fixed;
assert((get_mode_size_bytes(mode_P_mach) != -1) && "unorthodox modes not implemented");
res->size = get_mode_size_bytes(mode_P_mach);
res->attr.ma.n_params = n_param;
res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
res->attr.ma.value_params = NULL;
res->attr.ma.n_res = n_res;
res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
res->attr.ma.value_ress = NULL;
res->attr.ma.variadicity = variadicity_non_variadic;
res = new_type(type_method, mode_P_mach, name);
res->state = layout_fixed;
res->size = get_mode_size_bytes(mode_P_mach);
res->attr.ma.n_params = n_param;
res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
res->attr.ma.value_params = NULL;
res->attr.ma.n_res = n_res;
res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
res->attr.ma.value_ress = NULL;
res->attr.ma.variadicity = variadicity_non_variadic;
res->attr.ma.first_variadic_param = -1;
return res;
}
......@@ -943,6 +983,7 @@ type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db) {
void free_method_entities(type *method) {
assert(method && (method->type_op == type_method));
}
/* Attention: also frees entities in value parameter subtypes! */
void free_method_attrs(type *method) {
assert(method && (method->type_op == type_method));
......@@ -963,6 +1004,7 @@ int get_method_n_params (type *method) {
assert(method && (method->type_op == type_method));
return method->attr.ma.n_params;
}
type *get_method_param_type(type *method, int pos) {
type *res;
assert(method && (method->type_op == type_method));
......@@ -971,6 +1013,7 @@ type *get_method_param_type(type *method, int pos) {
assert(res != NULL && "empty method param type");
return method->attr.ma.param_type[pos] = skip_tid(res);
}
void set_method_param_type(type *method, int pos, type* tp) {
assert(method && (method->type_op == type_method));
assert(pos >= 0 && pos < get_method_n_params(method));
......@@ -981,6 +1024,7 @@ void set_method_param_type(type *method, int pos, type* tp) {
set_entity_type(get_struct_member(method->attr.ma.value_params, pos), tp);
}
}
/* Returns an entity that represents the copied value argument. Only necessary
for compounds passed by value. */
entity *get_method_value_param_ent(type *method, int pos) {
......@@ -996,16 +1040,20 @@ entity *get_method_value_param_ent(type *method, int pos) {
return get_struct_member(method->attr.ma.value_params, pos);
}
type *get_method_value_res_type(type *method) {
/*
* Returns a type that represents the copied value arguments.
*/
type *get_method_value_param_type(type *method)
{
assert(method && (method->type_op == type_method));
return method->attr.ma.value_params;
}
int get_method_n_ress (type *method) {
assert(method && (method->type_op == type_method));
return method->attr.ma.n_res;
}
type *get_method_res_type(type *method, int pos) {
type *res;
assert(method && (method->type_op == type_method));
......@@ -1014,6 +1062,7 @@ type *get_method_res_type(type *method, int pos) {
assert(res != NULL && "empty method return type");
return method->attr.ma.res_type[pos] = skip_tid(res);
}
void set_method_res_type(type *method, int pos, type* tp) {
assert(method && (method->type_op == type_method));
assert(pos >= 0 && pos < get_method_n_ress(method));
......@@ -1025,6 +1074,7 @@ void set_method_res_type(type *method, int pos, type* tp) {
set_entity_type(get_struct_member(method->attr.ma.value_ress, pos), tp);
}
}
/* Returns an entity that represents the copied value result. Only necessary
for compounds passed by value. */
entity *get_method_value_res_ent(type *method, int pos) {
......@@ -1039,6 +1089,14 @@ entity *get_method_value_res_ent(type *method, int pos) {
return get_struct_member(method->attr.ma.value_ress, pos);
}
/*
* Returns a type that represents the copied value results.
*/
type *get_method_value_res_type(type *method) {
assert(method && (method->type_op == type_method));
return method->attr.ma.value_ress;
}
/* Returns the null-terminated name of this variadicity. */
const char *get_variadicity_name(variadicity vari)
{
......@@ -1064,15 +1122,47 @@ void set_method_variadicity(type *method, variadicity vari)
method->attr.ma.variadicity = vari;
}
/*
* Returns the first variadic parameter index of a type.
* If this index was NOT set, the index of the last parameter
* of the method type plus one is returned for variadic functions.
* Non-variadic function types always return -1 here.
*/
int get_method_first_variadic_param_index(type *method)
{
assert(method && (method->type_op == type_method));
if (method->attr.ma.variadicity == variadicity_non_variadic)
return -1;
if (method->attr.ma.first_variadic_param == -1)
return get_method_n_params(method);
return method->attr.ma.first_variadic_param;
}
/*
* Sets the first variadic parameter index. This allows to specify
* a complete call type (containing the type of all parameters)
* but still have the knowledge, which parameter must be passed as
* variadic one.
*/
void set_method_first_variadic_param_index(type *method, int index)
{
assert(method && (method->type_op == type_method));
assert(index >= 0 && index <= get_method_n_params(method));
method->attr.ma.first_variadic_param = index;
}
/* typecheck */
bool is_method_type (type *method) {
assert(method);
if (method->type_op == type_method) return 1; else return 0;
return (method->type_op == type_method);
}
/*******************************************************************/
/** TYPE_UNION **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* TYPE_UNION */
/*-----------------------------------------------------------------*/
/* create a new type uni */
type *new_type_union (ident *name) {
......@@ -1166,9 +1256,9 @@ bool is_union_type (type *uni) {
if (uni->type_op == type_union) return 1; else return 0;
}
/*******************************************************************/
/** TYPE_ARRAY **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* TYPE_ARRAY */
/*-----------------------------------------------------------------*/
/* create a new type array -- set dimension sizes independently */
......@@ -1319,9 +1409,9 @@ bool is_array_type (type *array) {
if (array->type_op == type_array) return 1; else return 0;
}
/*******************************************************************/
/** TYPE_ENUMERATION **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* TYPE_ENUMERATION */
/*-----------------------------------------------------------------*/
/* create a new type enumeration -- set the enumerators independently */
type *new_type_enumeration (ident *name, int n_enums) {
......@@ -1386,9 +1476,9 @@ bool is_enumeration_type (type *enumeration) {
if (enumeration->type_op == type_enumeration) return 1; else return 0;
}
/*******************************************************************/
/** TYPE_POINTER **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* TYPE_POINTER */
/*-----------------------------------------------------------------*/
/* Create a new type pointer */
type *new_type_pointer_mode (ident *name, type *points_to, ir_mode *ptr_mode) {
......@@ -1443,9 +1533,9 @@ type *find_pointer_type_to_type (type *tp) {
/*******************************************************************/
/** TYPE_PRIMITIVE **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* TYPE_PRIMITIVE */
/*-----------------------------------------------------------------*/
/* create a new type primitive */
type *new_type_primitive (ident *name, ir_mode *mode) {
......@@ -1475,9 +1565,9 @@ bool is_primitive_type (type *primitive) {
if (primitive->type_op == type_primitive) return 1; else return 0;
}
/*******************************************************************/
/** common functionality **/
/*******************************************************************/
/*-----------------------------------------------------------------*/
/* common functionality */
/*-----------------------------------------------------------------*/
int is_atomic_type(type *tp) {
......@@ -1535,9 +1625,6 @@ int is_compound_type(type *tp) {
}
#if 1 || DEBUG_libfirm
int dump_node_opcode(FILE *F, ir_node *n); /* from irdump.c */
......
......@@ -462,10 +462,22 @@ type *new_type_struct (ident *name);
/** Creates a new type struct with debug information. */
type *new_d_type_struct (ident *name, dbg_info* db);
/* manipulate private fields of struct */
/* --- manipulate private fields of struct --- */
/** Adds the entity as member of the struct. */
void add_struct_member (type *strct, entity *member);
/** Returns the number of members of this struct. */
int get_struct_n_members (type *strct);
/** Returns the member at position pos, 0 <= pos < n_member */
entity *get_struct_member (type *strct, int pos);
/** Returns index of member in strct, -1 if not contained. */
int get_struct_member_index(type *strct, entity *member);
/** Overwrites the member at position pos, 0 <= pos < n_member with
the passed entity. */
void set_struct_member (type *strct, int pos, entity *member);
/** Finds member in the list of members and removes it. */
......@@ -547,9 +559,13 @@ type *get_method_param_type(type *method, int pos);
Also changes the type in the pass-by-value representation by just
changing the type of the corresponding entity if the representation is constructed. */
void set_method_param_type(type *method, int pos, type* tp);
/* Returns an entity that represents the copied value argument. Only necessary
/** Returns an entity that represents the copied value argument. Only necessary
for compounds passed by value. This information is constructed only on demand. */
entity *get_method_value_param_ent(type *method, int pos);
/**
* Returns a type that represents the copied value arguments.
*/
type *get_method_value_param_type(type *method);
int get_method_n_ress (type *method);
type *get_method_res_type(type *method, int pos);
......@@ -557,10 +573,11 @@ type *get_method_res_type(type *method, int pos);
Also changes the type in the pass-by-value representation by just
changing the type of the corresponding entity if the representation is constructed. */
void set_method_res_type(type *method, int pos, type* tp);
/* Returns an entity that represents the copied value result. Only necessary
/** Returns an entity that represents the copied value result. Only necessary
for compounds passed by value. This information is constructed only on demand. */
entity *get_method_value_res_ent(type *method, int pos);
/*
/**
* Returns a type that represents the copied value results.
*/
type *get_method_value_res_type(type *method);
......@@ -583,6 +600,22 @@ variadicity get_method_variadicity(type *method);
/** Sets the variadicity of a method. */
void set_method_variadicity(type *method, variadicity vari);
/**
* Returns the first variadic parameter index of a type.
* If this index was NOT set, the index of the last parameter
* of the method type plus one is returned for variadic functions.
* Non-variadic function types always return -1 here.
*/
int get_method_first_variadic_param_index(type *method);
/**
* Sets the first variadic parameter index. This allows to specify
* a complete call type (containing the type of all parameters)
* but still have the knowledge, which parameter must be passed as
* variadic one.
*/
void set_method_first_variadic_param_index(type *method, int index);
/** Returns true if a type is a method type. */
bool is_method_type (type *method);
......@@ -742,8 +775,7 @@ bool is_enumeration_type (type *enumeration);
*/
/** Creates a new type pointer with mode mode_p. */
#define new_type_pointer(N, P) new_type_pointer_mode(N, P, mode_P)
/* type *new_type_pointer (ident *name, type *points_to); */
#define new_type_pointer(N, P) new_type_pointer_mode(N, P, mode_P_mach)
/** Creates a new type pointer with given pointer mode. */
type *new_type_pointer_mode (ident *name, type *points_to, ir_mode *ptr_mode);
......
......@@ -41,13 +41,14 @@ typedef struct {
/** method attributes */
typedef struct {
int n_params; /**< number of parameters */
type **param_type; /**< code generation needs this information. */
type *value_params; /**< A type whose entities represent copied value arguments. */
int n_res; /**< number of results */
type **res_type; /**< array with result types */
type *value_ress; /**< A type whose entities represent copied value results. */
variadicity variadicity; /**< variadicity of the method */
int n_params; /**< number of parameters */
type **param_type; /**< code generation needs this information. */
type *value_params; /**< A type whose entities represent copied value arguments. */
int n_res; /**< number of results */
type **res_type; /**< array with result types */
type *value_ress; /**< A type whose entities represent copied value results. */
variadicity variadicity; /**< variadicity of the method. */
int first_variadic_param; /**< index of the first variadic param or -1 if non-variadic .*/
} mtd_attr;
/** union attributs */
......@@ -95,15 +96,15 @@ typedef struct { * No private attr, must be smaller than others! *
} id_attr;
*/
/** general type attributs */
/** General type attributs. */
typedef union {
cls_attr ca;
stc_attr sa;
mtd_attr ma;
uni_attr ua;
arr_attr aa;
enm_attr ea;
ptr_attr pa;
cls_attr ca; /**< attributes of a class type */
stc_attr sa; /**< attributes of a struct type */
mtd_attr ma; /**< attributes of a method type */
uni_attr ua; /**< attributes of an union type */
arr_attr aa; /**< attributes of an array type */
enm_attr ea; /**< attributes of an enumeration type */
ptr_attr pa; /**< attributes of a pointer type */
} tp_attr;
/** the structure of a type */
......@@ -164,8 +165,6 @@ INLINE void free_pointer_attrs (type *pointer);
INLINE void free_primitive_attrs (type *primitive);
/** initialize the type module */
void init_type (void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment