Commit 2ab371d0 authored by Sebastian Hack's avatar Sebastian Hack
Browse files

added flag variadicity to type method

[r623]
parent f1fba3a2
......@@ -337,6 +337,7 @@ bool equal_type(type *typ1, type *typ2) {
}
} break;
case tpo_method: {
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++) {
......@@ -429,6 +430,7 @@ bool smaller_type (type *st, type *lt) {
}
} break;
case tpo_method: {
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;
for (i = 0; i < get_method_n_params(st); i++) {
......@@ -765,6 +767,7 @@ INLINE type *new_type_method (ident *name, int n_param, int n_res) {
res->attr.ma.param_type = (type **) xmalloc (sizeof (type *) * n_param);
res->attr.ma.n_res = n_res;
res->attr.ma.res_type = (type **) xmalloc (sizeof (type *) * n_res);
res->attr.ma.variadicity = non_variadic;
return res;
}
type *new_d_type_method (ident *name, int n_param, int n_res, dbg_info* db) {
......@@ -808,6 +811,18 @@ void set_method_res_type(type *method, int pos, type* tp) {
method->attr.ma.res_type[pos] = tp;
}
variadicity get_method_variadicity(type *method)
{
assert(method && (method->type_op == type_method));
return method->attr.ma.variadicity;
}
void set_method_variadicity(type *method, variadicity vari)
{
assert(method && (method->type_op == type_method));
method->attr.ma.variadicity = vari;
}
/* typecheck */
bool is_method_type (type *method) {
assert(method);
......
......@@ -425,6 +425,19 @@ int get_method_n_ress (type *method);
type *get_method_res_type(type *method, int pos);
void set_method_res_type(type *method, int pos, type* tp);
/*
* this enum flags the variadicity of methods (methods with a
* variable amount of arguments (e.g. C's printf). Default is
* non_variadic.
*/
typedef enum variadicity {
non_variadic,
variadic
} variadicity;
variadicity get_method_variadicity(type *method);
void set_method_variadicity(type *method, variadicity vari);
/* typecheck */
bool is_method_type (type *method);
......
......@@ -37,6 +37,7 @@ typedef struct {
methods? */
int n_res; /* number of results */
type **res_type; /* array with result types */
variadicity variadicity; /* variadicity of the method */
} mtd_attr;
typedef struct {
......
Supports Markdown
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