blob: af988eabfa9e7d2d22c407405f3f83729e367008 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
int
(libnormalform_expression_to_term__)(struct libnormalform_term *out, struct expression *this)
{
size_t i;
out->type = this->type;
out->reduced = this->reduced;
switch (this->type) {
case LIBNORMALFORM_CONJUNCTION:
case LIBNORMALFORM_DISJUNCTION:
case LIBNORMALFORM_EXCLUSIVE_DISJUNCTION:
out->term.clause.nterms = 0;
out->term.clause.terms = calloc(this->nterms, sizeof(*out->term.clause.terms));
if (!out->term.clause.terms)
return -1;
for (i = 0; i < this->nterms; i++)
if (libnormalform_expression_to_term__(&out->term.clause.terms[out->term.clause.nterms++], this->terms[i]))
return -1;
break;
case LIBNORMALFORM_TRANSFORMATION:
out->term.transformation.transformer = this->user_item;
out->term.transformation.sentence = calloc(1, sizeof(*out->term.transformation.sentence));
if (!out->term.transformation.sentence ||
libnormalform_expression_to_term__(out->term.transformation.sentence, this->terms[0]))
return -1;
break;
case LIBNORMALFORM_VARIABLE:
case LIBNORMALFORM_NEGATED_VARIABLE:
out->term.variable = this->user_item;
break;
case LIBNORMALFORM_FUNCTION:
case LIBNORMALFORM_NEGATED_FUNCTION:
out->term.function = this->user_item;
break;
case LIBNORMALFORM_FOR_ALL:
case LIBNORMALFORM_NEGATED_FOR_ALL:
case LIBNORMALFORM_FOR_ANY:
case LIBNORMALFORM_NEGATED_FOR_ANY:
case LIBNORMALFORM_FOR_ONE:
case LIBNORMALFORM_NEGATED_FOR_ONE:
out->term.qualification.domain = this->user_item;
if (this->nterms == 1) {
out->term.qualification.antecedent = NULL;
out->term.qualification.predicate = calloc(1, sizeof(*out->term.qualification.predicate));
if (!out->term.qualification.predicate ||
libnormalform_expression_to_term__(out->term.qualification.predicate, this->terms[0]))
return -1;
} else {
out->term.qualification.antecedent = calloc(1, sizeof(*out->term.qualification.antecedent));
if (!out->term.qualification.antecedent)
return -1;
out->term.qualification.predicate = calloc(1, sizeof(*out->term.qualification.predicate));
if (!out->term.qualification.predicate ||
libnormalform_expression_to_term__(out->term.qualification.antecedent, this->terms[0]) ||
libnormalform_expression_to_term__(out->term.qualification.predicate, this->terms[1]))
return -1;
}
break;
default:
abort();
}
return 0;
}
#else
TODO_TEST
#endif
|