Skip to content

Commit

Permalink
Merge branch 'master' into continious-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ftynse committed Sep 1, 2017
2 parents a653287 + 02fa3b9 commit c5c351b
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 48 deletions.
27 changes: 27 additions & 0 deletions doc/interface
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Design guidelines for the isl interfaces
========================================

# Constructors

A function that constructs an isl object can be exposed in two ways, as
an unnamed constructor or as a named static function. Aiming for an interface
that is explicit and close to the isl C interface, all such functions
are exported as named static functions, except in the following cases.
Unnamed constructors are generated for functions where even without the
function name an object is identified uniquely by its arguments. For
example, there is a single isl_val that corresponds to a given integer
(isl_val_int_from_si), but both a NaN or a zero value can be constructed
from an isl_local_space (isl_aff_zero_on_domain and isl_aff_nan_on_domain).
Only function that create objects that are fully constructed by the function
and do not require further information to be added for typical use cases
are exposed as unnamed constructors.
Functions that commonly require more information to be provided
(isl_union_access_info_from_sink, isl_schedule_constraints_on_domain)
are exported as named static functions.
Typical examples of function that are generated as unnamed constructors
are the following:

- Conversion constructors
- Constructors from std::string
- Constructors where all arguments by themselves uniquely identify
a complete object (e.g., isl_val_int_from_si)
8 changes: 4 additions & 4 deletions include/isl/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ __isl_give isl_basic_map *isl_basic_map_less_at(__isl_take isl_space *dim,
unsigned pos);
__isl_give isl_basic_map *isl_basic_map_more_at(__isl_take isl_space *dim,
unsigned pos);
__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *dim);
__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *dim);
__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *space);
__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *space);
__isl_give isl_basic_map *isl_basic_map_nat_universe(__isl_take isl_space *dim);
__isl_give isl_basic_map *isl_basic_map_remove_redundancies(
__isl_take isl_basic_map *bmap);
Expand Down Expand Up @@ -281,9 +281,9 @@ isl_bool isl_basic_map_is_subset(__isl_keep isl_basic_map *bmap1,
isl_bool isl_basic_map_is_strict_subset(__isl_keep isl_basic_map *bmap1,
__isl_keep isl_basic_map *bmap2);

__isl_give isl_map *isl_map_universe(__isl_take isl_space *dim);
__isl_give isl_map *isl_map_universe(__isl_take isl_space *space);
__isl_give isl_map *isl_map_nat_universe(__isl_take isl_space *dim);
__isl_give isl_map *isl_map_empty(__isl_take isl_space *dim);
__isl_give isl_map *isl_map_empty(__isl_take isl_space *space);
__isl_give isl_map *isl_map_identity(__isl_take isl_space *dim);
__isl_give isl_map *isl_map_lex_lt_first(__isl_take isl_space *dim, unsigned n);
__isl_give isl_map *isl_map_lex_le_first(__isl_take isl_space *dim, unsigned n);
Expand Down
8 changes: 4 additions & 4 deletions include/isl/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ int isl_basic_set_is_rational(__isl_keep isl_basic_set *bset);

__isl_null isl_basic_set *isl_basic_set_free(__isl_take isl_basic_set *bset);
__isl_give isl_basic_set *isl_basic_set_copy(__isl_keep isl_basic_set *bset);
__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *dim);
__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *dim);
__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *space);
__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *space);
__isl_give isl_basic_set *isl_basic_set_nat_universe(__isl_take isl_space *dim);
__isl_give isl_basic_set *isl_basic_set_positive_orthant(
__isl_take isl_space *space);
Expand Down Expand Up @@ -236,8 +236,8 @@ isl_bool isl_basic_set_is_subset(__isl_keep isl_basic_set *bset1,
isl_bool isl_basic_set_plain_is_equal(__isl_keep isl_basic_set *bset1,
__isl_keep isl_basic_set *bset2);

__isl_give isl_set *isl_set_empty(__isl_take isl_space *dim);
__isl_give isl_set *isl_set_universe(__isl_take isl_space *dim);
__isl_give isl_set *isl_set_empty(__isl_take isl_space *space);
__isl_give isl_set *isl_set_universe(__isl_take isl_space *space);
__isl_give isl_set *isl_set_nat_universe(__isl_take isl_space *dim);
__isl_give isl_set *isl_set_copy(__isl_keep isl_set *set);
__isl_null isl_set *isl_set_free(__isl_take isl_set *set);
Expand Down
2 changes: 1 addition & 1 deletion include/isl/union_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ __isl_give isl_union_map *isl_union_map_from_basic_map(
__isl_take isl_basic_map *bmap);
__isl_constructor
__isl_give isl_union_map *isl_union_map_from_map(__isl_take isl_map *map);
__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *dim);
__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *space);
__isl_give isl_union_map *isl_union_map_copy(__isl_keep isl_union_map *umap);
__isl_null isl_union_map *isl_union_map_free(__isl_take isl_union_map *umap);

Expand Down
2 changes: 1 addition & 1 deletion include/isl/union_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ __isl_give isl_union_set *isl_union_set_from_basic_set(
__isl_take isl_basic_set *bset);
__isl_constructor
__isl_give isl_union_set *isl_union_set_from_set(__isl_take isl_set *set);
__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *dim);
__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *space);
__isl_give isl_union_set *isl_union_set_copy(__isl_keep isl_union_set *uset);
__isl_null isl_union_set *isl_union_set_free(__isl_take isl_union_set *uset);

Expand Down
36 changes: 23 additions & 13 deletions interface/cpp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ void cpp_generator::print_class(ostream &os, const isl_class &clazz)
print_class_factory_decl(os, clazz);
osprintf(os, "\n");
osprintf(os, "class %s {\n", cppname);
osprintf(os, " friend ");
print_class_factory_decl(os, clazz);
print_class_factory_decl(os, clazz, " friend ");
osprintf(os, "\n");
osprintf(os, " %s *ptr = nullptr;\n", name);
osprintf(os, "\n");
Expand Down Expand Up @@ -187,28 +186,34 @@ void cpp_generator::print_class_forward_decl(ostream &os,
osprintf(os, "class %s;\n", cppname);
}

/* Print global factory function to "os".
/* Print global factory functions to "os".
*
* Each class has one global factory function:
* Each class has two global factory functions:
*
* isl::set manage(__isl_take isl_set *ptr);
*
* The only public way to construct isl C++ objects from a raw pointer is
* through this global factory function. This ensures isl object creation
* is very explicit and pointers are not converted by accident. Due to
* overloading, manage() can be called on any isl raw pointer and the
* corresponding object is automatically created, without the user having
* to choose the right isl object type.
* isl::set manage_copy(__isl_keep isl_set *ptr);
*
* A user can construct isl C++ objects from a raw pointer and indicate whether
* they intend to take the ownership of the object or not through these global
* factory functions. This ensures isl object creation is very explicit and
* pointers are not converted by accident. Thanks to overloading, manage() and
* manage_copy() can be called on any isl raw pointer and the corresponding
* object is automatically created, without the user having to choose the right
* isl object type.
*/
void cpp_generator::print_class_factory_decl(ostream &os,
const isl_class &clazz)
const isl_class &clazz, const std::string &prefix)
{
const char *name = clazz.name.c_str();
std::string cppstring = type2cpp(clazz);
const char *cppname = cppstring.c_str();

os << prefix;
osprintf(os, "inline isl::%s manage(__isl_take %s *ptr);\n", cppname,
name);
os << prefix;
osprintf(os, "inline isl::%s manage_copy(__isl_keep %s *ptr);\n",
cppname, name);
}

/* Print declarations of private constructors for class "clazz" to "os".
Expand All @@ -222,7 +227,7 @@ void cpp_generator::print_class_factory_decl(ostream &os,
* set(__isl_take isl_set *ptr);
*
* The raw pointer constructor is kept private. Object creation is only
* possible through isl::manage().
* possible through isl::manage() or isl::manage_copy().
*/
void cpp_generator::print_private_constructors_decl(ostream &os,
const isl_class &clazz)
Expand Down Expand Up @@ -436,6 +441,11 @@ void cpp_generator::print_class_factory_impl(ostream &os,
osprintf(os, "isl::%s manage(__isl_take %s *ptr) {\n", cppname, name);
osprintf(os, " return %s(ptr);\n", cppname);
osprintf(os, "}\n");

osprintf(os, "isl::%s manage_copy(__isl_keep %s *ptr) {\n", cppname,
name);
osprintf(os, " return %s(%s_copy(ptr));\n", cppname, name);
osprintf(os, "}\n");
}

/* Print implementations of private constructors for class "clazz" to "os".
Expand Down
3 changes: 2 additions & 1 deletion interface/cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class cpp_generator : public generator {
void print_declarations(ostream &os);
void print_class(ostream &os, const isl_class &clazz);
void print_class_forward_decl(ostream &os, const isl_class &clazz);
void print_class_factory_decl(ostream &os, const isl_class &clazz);
void print_class_factory_decl(ostream &os, const isl_class &clazz,
const std::string &prefix = std::string());
void print_private_constructors_decl(ostream &os,
const isl_class &clazz);
void print_copy_assignment_decl(ostream &os, const isl_class &clazz);
Expand Down
7 changes: 7 additions & 0 deletions interface/isl_test_cpp.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/* Copyright 2016-2017 Tobias Grosser
*
* Use of this software is governed by the MIT license
*
* Written by Tobias Grosser, Weststrasse 47, CH-8003, Zurich
*/

#include <vector>
#include <string>
#include <limits.h>
Expand Down
40 changes: 20 additions & 20 deletions isl_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -5924,34 +5924,34 @@ __isl_give isl_map *isl_map_alloc_space(__isl_take isl_space *space, int n,
return NULL;
}

__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *dim)
__isl_give isl_basic_map *isl_basic_map_empty(__isl_take isl_space *space)
{
struct isl_basic_map *bmap;
bmap = isl_basic_map_alloc_space(dim, 0, 1, 0);
bmap = isl_basic_map_alloc_space(space, 0, 1, 0);
bmap = isl_basic_map_set_to_empty(bmap);
return bmap;
}

__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *dim)
__isl_give isl_basic_set *isl_basic_set_empty(__isl_take isl_space *space)
{
struct isl_basic_set *bset;
bset = isl_basic_set_alloc_space(dim, 0, 1, 0);
bset = isl_basic_set_alloc_space(space, 0, 1, 0);
bset = isl_basic_set_set_to_empty(bset);
return bset;
}

__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *dim)
__isl_give isl_basic_map *isl_basic_map_universe(__isl_take isl_space *space)
{
struct isl_basic_map *bmap;
bmap = isl_basic_map_alloc_space(dim, 0, 0, 0);
bmap = isl_basic_map_alloc_space(space, 0, 0, 0);
bmap = isl_basic_map_finalize(bmap);
return bmap;
}

__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *dim)
__isl_give isl_basic_set *isl_basic_set_universe(__isl_take isl_space *space)
{
struct isl_basic_set *bset;
bset = isl_basic_set_alloc_space(dim, 0, 0, 0);
bset = isl_basic_set_alloc_space(space, 0, 0, 0);
bset = isl_basic_set_finalize(bset);
return bset;
}
Expand Down Expand Up @@ -5991,33 +5991,33 @@ __isl_give isl_set *isl_set_nat_universe(__isl_take isl_space *dim)
return isl_map_nat_universe(dim);
}

__isl_give isl_map *isl_map_empty(__isl_take isl_space *dim)
__isl_give isl_map *isl_map_empty(__isl_take isl_space *space)
{
return isl_map_alloc_space(dim, 0, ISL_MAP_DISJOINT);
return isl_map_alloc_space(space, 0, ISL_MAP_DISJOINT);
}

__isl_give isl_set *isl_set_empty(__isl_take isl_space *dim)
__isl_give isl_set *isl_set_empty(__isl_take isl_space *space)
{
return isl_set_alloc_space(dim, 0, ISL_MAP_DISJOINT);
return isl_set_alloc_space(space, 0, ISL_MAP_DISJOINT);
}

__isl_give isl_map *isl_map_universe(__isl_take isl_space *dim)
__isl_give isl_map *isl_map_universe(__isl_take isl_space *space)
{
struct isl_map *map;
if (!dim)
if (!space)
return NULL;
map = isl_map_alloc_space(isl_space_copy(dim), 1, ISL_MAP_DISJOINT);
map = isl_map_add_basic_map(map, isl_basic_map_universe(dim));
map = isl_map_alloc_space(isl_space_copy(space), 1, ISL_MAP_DISJOINT);
map = isl_map_add_basic_map(map, isl_basic_map_universe(space));
return map;
}

__isl_give isl_set *isl_set_universe(__isl_take isl_space *dim)
__isl_give isl_set *isl_set_universe(__isl_take isl_space *space)
{
struct isl_set *set;
if (!dim)
if (!space)
return NULL;
set = isl_set_alloc_space(isl_space_copy(dim), 1, ISL_MAP_DISJOINT);
set = isl_set_add_basic_set(set, isl_basic_set_universe(dim));
set = isl_set_alloc_space(isl_space_copy(space), 1, ISL_MAP_DISJOINT);
set = isl_set_add_basic_set(set, isl_basic_set_universe(space));
return set;
}

Expand Down
8 changes: 4 additions & 4 deletions isl_union_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ static __isl_give isl_union_map *isl_union_map_alloc(
return umap;
}

__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *dim)
__isl_give isl_union_map *isl_union_map_empty(__isl_take isl_space *space)
{
return isl_union_map_alloc(dim, 16);
return isl_union_map_alloc(space, 16);
}

__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *dim)
__isl_give isl_union_set *isl_union_set_empty(__isl_take isl_space *space)
{
return isl_union_map_empty(dim);
return isl_union_map_empty(space);
}

isl_ctx *isl_union_map_get_ctx(__isl_keep isl_union_map *umap)
Expand Down

0 comments on commit c5c351b

Please sign in to comment.