1 #include <isl_obj_list.h>
3 struct isl_list
*isl_list_alloc(struct isl_ctx
*ctx
, int n
)
8 isl_assert(ctx
, n
>= 0, return NULL
);
9 list
= isl_alloc(ctx
, struct isl_list
,
10 sizeof(struct isl_list
) +
11 (n
- 1) * sizeof(struct isl_obj
));
16 isl_ctx_ref(list
->ctx
);
20 for (i
= 0; i
< n
; ++i
) {
21 list
->obj
[i
].type
= isl_obj_none
;
22 list
->obj
[i
].v
= NULL
;
28 struct isl_list
*isl_list_copy(struct isl_list
*list
)
37 void isl_list_free(struct isl_list
*list
)
47 for (i
= 0; i
< list
->n
; ++i
)
48 list
->obj
[i
].type
->free(list
->obj
[i
].v
);
49 isl_ctx_deref(list
->ctx
);
53 static void *isl_obj_list_copy(void *v
)
55 return isl_list_copy((struct isl_list
*)v
);
58 static void isl_obj_list_free(void *v
)
60 isl_list_free((struct isl_list
*)v
);
63 static __isl_give isl_printer
*isl_obj_list_print(__isl_take isl_printer
*p
,
66 struct isl_list
*list
= (struct isl_list
*)v
;
69 isl_printer_print_str(p
, "(");
70 for (i
= 0; i
< list
->n
; ++i
) {
72 isl_printer_print_str(p
, ", ");
73 list
->obj
[i
].type
->print(p
, list
->obj
[i
].v
);
75 isl_printer_print_str(p
, ")");
78 static void *isl_obj_list_add(void *v1
, void *v2
)
81 struct isl_list
*list1
= (struct isl_list
*)v1
;
82 struct isl_list
*list2
= (struct isl_list
*)v2
;
83 struct isl_list
*list
;
88 list
= isl_list_alloc(list1
->ctx
, list1
->n
+ list2
->n
);
92 for (i
= 0; i
< list1
->n
; ++i
) {
93 list
->obj
[i
].type
= list1
->obj
[i
].type
;
94 list
->obj
[i
].v
= list1
->obj
[i
].type
->copy(list1
->obj
[i
].v
);
97 for (i
= 0; i
< list2
->n
; ++i
) {
98 list
->obj
[list1
->n
+ i
].type
= list2
->obj
[i
].type
;
99 list
->obj
[list1
->n
+ i
].v
= list2
->obj
[i
].type
->copy(list2
->obj
[i
].v
);
102 isl_list_free(list1
);
103 isl_list_free(list2
);
107 isl_list_free(list1
);
108 isl_list_free(list2
);
112 struct isl_obj_vtable isl_obj_list_vtable
= {