Skip to content

Commit

Permalink
Change Expression "type" to "kind"
Browse files Browse the repository at this point in the history
This convention has bothered me for some time,
but I never had a better name for it.
Using "type" confuses the semantics of types and typedefs in C,
and conflicts with the Python Type object and type function.
So for clarity, use "kind" going forward.
  • Loading branch information
cjdrake committed Mar 20, 2015
1 parent 2e961d1 commit ada0884
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 95 deletions.
18 changes: 9 additions & 9 deletions extension/boolexpr/array2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


/* boolexpr.c */
struct BoolExpr * _opn_new(BoolExprType t, size_t n, ...);
struct BoolExpr * _opn_new(BoolExprKind kind, size_t n, ...);


struct BoolExprArray2 *
Expand Down Expand Up @@ -64,7 +64,7 @@ BoolExprArray2_Equal(struct BoolExprArray2 *self, struct BoolExprArray2 *other)


static struct BoolExprArray *
_multiply(struct BoolExprArray *a, struct BoolExprArray *b, BoolExprType t)
_multiply(struct BoolExprArray *a, struct BoolExprArray *b, BoolExprKind kind)
{
size_t length = a->length * b->length;
struct BoolExpr **items;
Expand All @@ -76,7 +76,7 @@ _multiply(struct BoolExprArray *a, struct BoolExprArray *b, BoolExprType t)

for (size_t i = 0, index = 0; i < a->length; ++i) {
for (size_t j = 0; j < b->length; ++j, ++index) {
items[index] = _opn_new(t, 2, a->items[i], b->items[j]);
items[index] = _opn_new(kind, 2, a->items[i], b->items[j]);
if (items[index] == NULL) {
/* LCOV_EXCL_START */
for (size_t k = 0; k < index; ++k)
Expand All @@ -99,21 +99,21 @@ _multiply(struct BoolExprArray *a, struct BoolExprArray *b, BoolExprType t)


static struct BoolExprArray *
_product(struct BoolExprArray2 *array2, BoolExprType t, size_t n)
_product(struct BoolExprArray2 *array2, BoolExprKind kind, size_t n)
{
if (n == 0) {
struct BoolExpr *items[] = {IDENTITY[t]};
struct BoolExpr *items[] = {IDENTITY[kind]};
return BoolExprArray_New(1, items);
}
else {
struct BoolExprArray *prev;
struct BoolExprArray *prod;

prev = _product(array2, t, n-1);
prev = _product(array2, kind, n-1);
if (prev == NULL)
return NULL; // LCOV_EXCL_LINE

prod = _multiply(array2->items[n-1], prev, t);
prod = _multiply(array2->items[n-1], prev, kind);

BoolExprArray_Del(prev);

Expand All @@ -123,8 +123,8 @@ _product(struct BoolExprArray2 *array2, BoolExprType t, size_t n)


struct BoolExprArray *
BoolExprArray2_Product(struct BoolExprArray2 *self, BoolExprType t)
BoolExprArray2_Product(struct BoolExprArray2 *self, BoolExprKind kind)
{
return _product(self, t, self->length);
return _product(self, kind, self->length);
}

10 changes: 5 additions & 5 deletions extension/boolexpr/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


/* boolexpr.c */
struct BoolExpr * _op_new(BoolExprType t, size_t n, struct BoolExpr **xs);
struct BoolExpr * _op_new(BoolExprKind kind, size_t n, struct BoolExpr **xs);

/* util.c */
struct BoolExpr * _op_transform(struct BoolExpr *op, struct BoolExpr * (*fn)(struct BoolExpr *));
Expand All @@ -39,16 +39,16 @@ _commutative_binify(struct BoolExpr *op)
xs[0] = BoolExpr_IncRef(items0[0]);
}
else {
CHECK_NULL(temp, _op_new(op->type, n0, items0));
CHECK_NULL(temp, _op_new(op->kind, n0, items0));
CHECK_NULL_1(xs[0], _commutative_binify(temp), temp);
BoolExpr_DecRef(temp);
}

CHECK_NULL_1(temp, _op_new(op->type, n1, items1), xs[0]);
CHECK_NULL_1(temp, _op_new(op->kind, n1, items1), xs[0]);
CHECK_NULL_2(xs[1], _commutative_binify(temp), xs[0], temp);
BoolExpr_DecRef(temp);

CHECK_NULL_2(y, _op_new(op->type, 2, xs), xs[0], xs[1]);
CHECK_NULL_2(y, _op_new(op->kind, 2, xs), xs[0], xs[1]);
BoolExpr_DecRef(xs[0]);
BoolExpr_DecRef(xs[1]);

Expand Down Expand Up @@ -142,7 +142,7 @@ BoolExpr_ToBinary(struct BoolExpr *ex)
struct BoolExpr *y;

CHECK_NULL(temp, _op_transform(ex, BoolExpr_ToBinary));
CHECK_NULL_1(y, _op_binify[temp->type](temp), temp);
CHECK_NULL_1(y, _op_binify[temp->kind](temp), temp);
BoolExpr_DecRef(temp);

return y;
Expand Down
20 changes: 10 additions & 10 deletions extension/boolexpr/boolexpr.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ _lit_new(struct BoolExprVector *lits, long uniqid)
return NULL; // LCOV_EXCL_LINE

lit->refcount = 1;
lit->type = uniqid < 0 ? COMP : VAR;
lit->kind = uniqid < 0 ? COMP : VAR;
lit->data.lit.uniqid = uniqid;
lit->data.lit.lits = lits;
lit->flags = NNF | SIMPLE;
Expand All @@ -141,7 +141,7 @@ _lit_del(struct BoolExpr *lit)


struct BoolExpr *
_op_new(BoolExprType t, size_t n, struct BoolExpr **xs)
_op_new(BoolExprKind kind, size_t n, struct BoolExpr **xs)
{
struct BoolExpr *op;

Expand All @@ -156,33 +156,33 @@ _op_new(BoolExprType t, size_t n, struct BoolExpr **xs)
}

op->refcount = 1;
op->type = t;
op->kind = kind;
op->flags = (BoolExprFlags) 0;

return op;
}


struct BoolExpr *
_opn_new(BoolExprType t, size_t n, ...)
_opn_new(BoolExprKind kind, size_t n, ...)
{
struct BoolExpr *xs[n];
READ_ARGS;
return _op_new(t, n, xs);
return _op_new(kind, n, xs);
}


struct BoolExpr *
_orandxor_new(BoolExprType t, size_t n, struct BoolExpr **xs)
_orandxor_new(BoolExprKind kind, size_t n, struct BoolExpr **xs)
{
struct BoolExpr *y;

if (n == 0)
y = BoolExpr_IncRef(IDENTITY[t]);
y = BoolExpr_IncRef(IDENTITY[kind]);
else if (n == 1)
y = BoolExpr_IncRef(xs[0]);
else
CHECK_NULL(y, _op_new(t, n, xs));
CHECK_NULL(y, _op_new(kind, n, xs));

return y;
}
Expand Down Expand Up @@ -345,7 +345,7 @@ static struct BoolExpr * (*_boolexpr_inv[16])(struct BoolExpr *ex) = {
struct BoolExpr *
Not(struct BoolExpr *x)
{
return _boolexpr_inv[x->type](x);
return _boolexpr_inv[x->kind](x);
}


Expand Down Expand Up @@ -483,7 +483,7 @@ BoolExpr_DecRef(struct BoolExpr * ex)
if (ex->refcount == 0) {
/* Constant refcount must never reach zero */
assert(!IS_CONST(ex));
_boolexpr_del[ex->type](ex);
_boolexpr_del[ex->kind](ex);
}
}

Expand Down
40 changes: 20 additions & 20 deletions extension/boolexpr/boolexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,25 @@ do { \
} while (0)


/* Type checks */
#define IS_ZERO(ex) (((ex)->type) == ZERO)
#define IS_ONE(ex) (((ex)->type) == ONE)
#define IS_COMP(ex) (((ex)->type) == COMP)
#define IS_VAR(ex) (((ex)->type) == VAR)
#define IS_OR(ex) (((ex)->type) == OP_OR)
#define IS_AND(ex) (((ex)->type) == OP_AND)
#define IS_XOR(ex) (((ex)->type) == OP_XOR)
#define IS_EQ(ex) (((ex)->type) == OP_EQ)
#define IS_NOT(ex) (((ex)->type) == OP_NOT)
#define IS_IMPL(ex) (((ex)->type) == OP_IMPL)
#define IS_ITE(ex) (((ex)->type) == OP_ITE)
/* Kind checks */
#define IS_ZERO(ex) (((ex)->kind) == ZERO)
#define IS_ONE(ex) (((ex)->kind) == ONE)
#define IS_COMP(ex) (((ex)->kind) == COMP)
#define IS_VAR(ex) (((ex)->kind) == VAR)
#define IS_OR(ex) (((ex)->kind) == OP_OR)
#define IS_AND(ex) (((ex)->kind) == OP_AND)
#define IS_XOR(ex) (((ex)->kind) == OP_XOR)
#define IS_EQ(ex) (((ex)->kind) == OP_EQ)
#define IS_NOT(ex) (((ex)->kind) == OP_NOT)
#define IS_IMPL(ex) (((ex)->kind) == OP_IMPL)
#define IS_ITE(ex) (((ex)->kind) == OP_ITE)


/* Category checks */
#define IS_ATOM(ex) (((ex)->type) >> 3 == 0x0) // 0***
#define IS_CONST(ex) (((ex)->type) >> 2 == 0x0) // 00**
#define IS_LIT(ex) (((ex)->type) >> 1 == 0x2) // 010*
#define IS_OP(ex) (((ex)->type) >> 3 == 0x1) // 1***
#define IS_ATOM(ex) (((ex)->kind) >> 3 == 0x0) // 0***
#define IS_CONST(ex) (((ex)->kind) >> 2 == 0x0) // 00**
#define IS_LIT(ex) (((ex)->kind) >> 1 == 0x2) // 010*
#define IS_OP(ex) (((ex)->kind) >> 3 == 0x1) // 1***


/* Flag definitions */
Expand All @@ -95,7 +95,7 @@ do { \
(IS_LIT(x) && IS_LIT(y) && \
((x)->data.lit.uniqid == -((y)->data.lit.uniqid)))

#define DUAL(t) (OP_OR + OP_AND - t)
#define DUAL(kind) (OP_OR + OP_AND - kind)


/* Expression types */
Expand All @@ -117,7 +117,7 @@ typedef enum {
OP_NOT = 0x0C,
OP_IMPL = 0x0D,
OP_ITE = 0x0E,
} BoolExprType;
} BoolExprKind;


/* Expression flags */
Expand All @@ -127,7 +127,7 @@ typedef unsigned char BoolExprFlags;
struct BoolExpr {
int refcount;

BoolExprType type;
BoolExprKind kind;
BoolExprFlags flags;

union {
Expand Down Expand Up @@ -389,7 +389,7 @@ void BoolExprArray2_Del(struct BoolExprArray2 *);
bool BoolExprArray2_Equal(struct BoolExprArray2 *, struct BoolExprArray2 *);

/* Return the cartesian product of two 2d arrays */
struct BoolExprArray * BoolExprArray2_Product(struct BoolExprArray2 *, BoolExprType t);
struct BoolExprArray * BoolExprArray2_Product(struct BoolExprArray2 *, BoolExprKind kind);


/*
Expand Down
6 changes: 3 additions & 3 deletions extension/boolexpr/compose.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


/* boolexpr.c */
struct BoolExpr * _op_new(BoolExprType t, size_t n, struct BoolExpr **xs);
struct BoolExpr * _op_new(BoolExprKind kind, size_t n, struct BoolExpr **xs);


static struct BoolExpr *
Expand Down Expand Up @@ -67,7 +67,7 @@ _op_compose(struct BoolExpr *op, struct BoolExprDict *var2ex)
}

if (mod_count)
CHECK_NULL_N(y, _op_new(op->type, length, xs), length, xs);
CHECK_NULL_N(y, _op_new(op->kind, length, xs), length, xs);
else
y = BoolExpr_IncRef(op);

Expand Down Expand Up @@ -104,7 +104,7 @@ static struct BoolExpr * (*_compose[16])(struct BoolExpr *ex, struct BoolExprDic
struct BoolExpr *
BoolExpr_Compose(struct BoolExpr *ex, struct BoolExprDict *var2ex)
{
return _compose[ex->type](ex, var2ex);
return _compose[ex->kind](ex, var2ex);
}


Expand Down
12 changes: 6 additions & 6 deletions extension/boolexpr/flatten.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


/* boolexpr.c */
struct BoolExpr * _op_new(BoolExprType t, size_t n, struct BoolExpr **xs);
struct BoolExpr * _op_new(BoolExprKind kind, size_t n, struct BoolExpr **xs);

/* nnf.c */
struct BoolExpr * _to_nnf(struct BoolExpr *ex);
Expand Down Expand Up @@ -53,26 +53,26 @@ _nf2sets(struct BoolExpr *nf)

/* NOTE: Return size is exponential */
static struct BoolExpr *
_distribute(BoolExprType t, struct BoolExpr *nf)
_distribute(BoolExprKind kind, struct BoolExpr *nf)
{
struct BoolExprArray2 *sets;
struct BoolExprArray *product;
struct BoolExpr *temp;
struct BoolExpr *dnf;

assert(nf->type == t);
assert(nf->kind == kind);

sets = _nf2sets(nf);
if (sets == NULL)
return NULL; // LCOV_EXCL_LINE

product = BoolExprArray2_Product(sets, t);
product = BoolExprArray2_Product(sets, kind);
if (product == NULL) {
BoolExprArray2_Del(sets); // LCOV_EXCL_LINE
return NULL; // LCOV_EXCL_LINE
}

temp = _op_new(DUAL(t), product->length, product->items);
temp = _op_new(DUAL(kind), product->length, product->items);
if (temp == NULL) {
BoolExprArray_Del(product); // LCOV_EXCL_LINE
BoolExprArray2_Del(sets); // LCOV_EXCL_LINE
Expand Down Expand Up @@ -193,7 +193,7 @@ _absorb(struct BoolExpr *dnf)
xs[index++] = dnf->data.xs->items[i];
}

CHECK_NULL(temp, _op_new(dnf->type, count, xs));
CHECK_NULL(temp, _op_new(dnf->kind, count, xs));
CHECK_NULL_1(dnf2, _simplify(temp), temp);
BoolExpr_DecRef(temp);

Expand Down
2 changes: 1 addition & 1 deletion extension/boolexpr/nnf.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ _nnfify(struct BoolExpr *ex)
struct BoolExpr *temp;

CHECK_NULL(temp, _op_transform(ex, _nnfify));
CHECK_NULL_1(y, _op_nnfify[temp->type](temp), temp);
CHECK_NULL_1(y, _op_nnfify[temp->kind](temp), temp);
BoolExpr_DecRef(temp);
}

Expand Down

0 comments on commit ada0884

Please sign in to comment.