Resolving Conflicts ... Still there're errors that should be fixed
[satune.git] / src / AST / boolean.c
1 #include "boolean.h"
2 #include "structs.h"
3 #include "csolver.h"
4 #include "element.h"
5
6 Boolean* allocBoolean(VarType t) {
7         BooleanVar* tmp=(BooleanVar *) ourmalloc(sizeof (BooleanVar));
8         GETBOOLEANTYPE(tmp)=BOOLEANVAR;
9         tmp->vtype=t;
10         tmp->var=NULL;
11         allocInlineDefVectorBoolean(GETBOOLEANPARENTS(tmp));
12         return & tmp->base;
13 }
14
15 Boolean* allocBooleanOrder(Order* order, uint64_t first, uint64_t second) {
16         BooleanOrder* tmp=(BooleanOrder *) ourmalloc(sizeof (BooleanOrder));
17         GETBOOLEANTYPE(tmp)=ORDERCONST;
18         tmp->order=order;
19         tmp->first=first;
20         tmp->second=second;
21         allocInlineDefVectorBoolean(GETBOOLEANPARENTS(tmp));
22         return & tmp -> base;
23 }
24
25 Boolean * allocBooleanPredicate(Predicate * predicate, Element ** inputs, uint numInputs){
26         BooleanPredicate* This = (BooleanPredicate*) ourmalloc(sizeof(BooleanPredicate));
27         GETBOOLEANTYPE(This)= PREDICATEOP;
28         This->predicate=predicate;
29         allocInlineArrayInitElement(&This->inputs, inputs, numInputs);
30         allocInlineDefVectorBoolean(GETBOOLEANPARENTS(This));
31
32         for(uint i=0;i<numInputs;i++) {
33                 pushVectorASTNode(GETELEMENTPARENTS(inputs[i]), (ASTNode *)This);
34         }
35         initPredicateEncoding(&This->encoding, (Boolean *) This);
36
37         return & This->base;
38 }
39
40 Boolean * allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean ** array, uint asize){
41         BooleanLogic * This = ourmalloc(sizeof(BooleanLogic));
42         allocInlineDefVectorBoolean(GETBOOLEANPARENTS(This));
43         allocInlineArrayInitBoolean(&This->inputs, array, asize);
44         pushVectorBoolean(solver->allBooleans, (Boolean *) This);
45         return & This->base;
46 }
47
48 void deleteBoolean(Boolean * This) {
49         switch(GETBOOLEANTYPE(This)){
50         case PREDICATEOP: {
51                 BooleanPredicate *bp=(BooleanPredicate *)This;
52                 deleteInlineArrayElement(& bp->inputs );
53                 deleteFunctionEncoding(& bp->encoding);
54                 break;
55         }
56         default:
57                 break;
58         }
59         deleteVectorArrayBoolean(GETBOOLEANPARENTS(This));
60         ourfree(This);
61 }