Boolean* allocBoolean(VarType t) {
BooleanVar* tmp=(BooleanVar *) ourmalloc(sizeof (BooleanVar));
GETBOOLEANTYPE(tmp)=BOOLEANVAR;
+ GETSTRUCTTYPE(tmp) = _BOOLEAN;
+ GETPARENTSVECTOR(tmp) = allocDefVectorVoid();
tmp->vtype=t;
tmp->var=NULL;
return & tmp->base;
Boolean* allocBooleanOrder(Order* order, uint64_t first, uint64_t second) {
BooleanOrder* tmp=(BooleanOrder *) ourmalloc(sizeof (BooleanOrder));
GETBOOLEANTYPE(tmp)=ORDERCONST;
+ GETSTRUCTTYPE(tmp) = _BOOLEAN;
+ GETPARENTSVECTOR(tmp) = allocDefVectorVoid();
tmp->order=order;
tmp->first=first;
tmp->second=second;
}
Boolean * allocBooleanPredicate(Predicate * predicate, Element ** inputs, uint numInputs){
- BooleanPredicate* bp = (BooleanPredicate*) ourmalloc(sizeof(BooleanPredicate));
- GETBOOLEANTYPE(bp)= PREDICATEOP;
- bp->predicate=predicate;
- bp->inputs= allocVectorArrayElement (numInputs,inputs);
- return & bp->base;
+ BooleanPredicate* tmp = (BooleanPredicate*) ourmalloc(sizeof(BooleanPredicate));
+ GETBOOLEANTYPE(tmp)= PREDICATEOP;
+ GETSTRUCTTYPE(tmp) = _BOOLEAN;
+ GETPARENTSVECTOR(tmp) = allocDefVectorVoid();
+ tmp->predicate=predicate;
+ tmp->inputs= allocVectorArrayElement (numInputs,inputs);
+ return & tmp->base;
}
Boolean * allocBooleanLogic(LogicOp op, Boolean * left, Boolean* right){
- BooleanLogic* bl = (BooleanLogic*) ourmalloc(sizeof(BooleanLogic));
- GETBOOLEANTYPE(bl) = LOGICOP;
- bl->op=op;
- bl->left=left;
- bl->right=right;
- return &bl->base;
+ BooleanLogic* tmp = (BooleanLogic*) ourmalloc(sizeof(BooleanLogic));
+ GETBOOLEANTYPE(tmp) = LOGICOP;
+ GETSTRUCTTYPE(tmp) = _BOOLEAN;
+ GETPARENTSVECTOR(tmp) = allocDefVectorVoid();
+ tmp->op=op;
+ tmp->left=left;
+ tmp->right=right;
+ return &tmp->base;
}
Boolean * allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean ** array, uint asize){
- ASSERT(asize>=2);
- Boolean* boolean = allocBooleanLogic(op,array[0], array[1]);
- pushVectorBoolean(solver->allBooleans,boolean);
- for(uint i=2; i<asize; i++){
- boolean=allocBooleanLogic(op,boolean, array[i]);
+ ASSERT(asize>=2);
+ Boolean* boolean = allocBooleanLogic(op,array[0], array[1]);
+ ADDNEWPARENT(array[0], boolean);
+ ADDNEWPARENT(array[1], boolean);
pushVectorBoolean(solver->allBooleans,boolean);
- }
- return boolean;
+ for(uint i=2; i<asize; i++){
+ Boolean* oldBoolean = boolean;
+ boolean=allocBooleanLogic(op,oldBoolean, array[i]);
+ ADDNEWPARENT(oldBoolean, boolean);
+ ADDNEWPARENT(array[i], boolean);
+ pushVectorBoolean(solver->allBooleans,boolean);
+ }
+ return boolean;
}
void deleteBoolean(Boolean * This) {
+ switch(GETBOOLEANTYPE(This)){
+ case PREDICATEOP:
+ deleteVectorArrayElement( ((BooleanPredicate*)This)->inputs );
+ break;
+ default:
+ break;
+ }
+ DELETEPARENTSVECTOR(This);
ourfree(This);
}
#include "mymemory.h"
#include "ops.h"
#include "structs.h"
-
+#include "structtype.h"
/**
This is a little sketchy, but apparently legit.
https://www.python.org/dev/peps/pep-3123/ */
#define GETBOOLEANTYPE(o) (((Boolean *)(o))->btype)
struct Boolean {
+ Struct stype;
BooleanType btype;
};
Element *allocElementSet(Set * s) {
ElementSet * tmp=(ElementSet *)ourmalloc(sizeof(ElementSet));
GETELEMENTTYPE(tmp)= ELEMSET;
+ GETPARENTSVECTOR(tmp) = allocDefVectorVoid();
+ GETSTRUCTTYPE(tmp) = _ELEMENT;
tmp->set=s;
tmp->encoding=NULL;
return &tmp->base;
}
Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
- ElementFunction* ef = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
- GETELEMENTTYPE(ef)= ELEMFUNCRETURN;
- ef->function=function;
- ef->overflowstatus = overflowstatus;
- ef->Elements = allocVectorArrayElement(numArrays, array);
- return &ef->base;
+ ElementFunction* tmp = (ElementFunction*) ourmalloc(sizeof(ElementFunction));
+ GETELEMENTTYPE(tmp)= ELEMFUNCRETURN;
+ GETPARENTSVECTOR(tmp) = allocDefVectorVoid();
+ GETSTRUCTTYPE(tmp) = _ELEMENT;
+ tmp->function=function;
+ tmp->overflowstatus = overflowstatus;
+ tmp->Elements = allocVectorArrayElement(numArrays, array);
+ return &tmp->base;
}
void deleteElement(Element *This) {
+ DELETEPARENTSVECTOR(This);
ourfree(This);
}
#include "mymemory.h"
#include "ops.h"
#include "structs.h"
+#include "structtype.h"
#define GETELEMENTTYPE(o) (((Element*)o)->type)
-//FIXME:TALK ABOUT ELEMENT
struct Element {
+ Struct stype;
ElementType type;
};
enum ElementType {ELEMSET, ELEMFUNCRETURN};
typedef enum ElementType ElementType;
+
+enum StructType {_BOOLEAN, _ELEMENT};
+typedef enum StructType StructType;
+
#endif
break;
}
}
-
//need to handle freeing array...
ourfree(predicate);
}
#include "classlist.h"
#include "mymemory.h"
#include "ops.h"
-#include "structs.h"
+
#define GETPREDICATETYPE(o) (((Predicate *)(o))->type)
--- /dev/null
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/*
+ * File: structtype.h
+ * Author: hamed
+ *
+ * Created on June 21, 2017, 10:37 AM
+ */
+
+#ifndef STRUCTTYPE_H
+#define STRUCTTYPE_H
+#include "ops.h"
+#include "structs.h"
+#define GETSTRUCTTYPE(s) (((Struct*)s)->stype)
+#define GETPARENTSVECTOR(s) (((Struct*)s)->parents)
+#define ADDNEWPARENT(obj,par) pushVectorVoid(((Struct*)obj)->parents,(void*) par)
+#define ADDNEWPARENTTOOBJECTARRAY(array,size,par) \
+ do{ \
+ for(int i=0; i<size; i++){ \
+ ADDNEWPARENT(array[i], par); \
+ } \
+ }while(0)
+#define DELETEPARENTSVECTOR(obj) deleteVectorArrayVoid(((Struct*)obj)->parents)
+
+struct Struct {
+ StructType stype;
+ VectorVoid* parents;
+};
+
+#endif /* STRUCTTYPE_H */
+
struct TableEntry;
typedef struct TableEntry TableEntry;
+struct Struct;
+typedef struct Struct Struct;
+
typedef unsigned int uint;
typedef uint64_t VarType;
#endif
Element * applyFunction(CSolver *solver, Function * function, Element ** array, uint numArrays, Boolean * overflowstatus) {
Element* element= allocElementFunction(function,array,numArrays,overflowstatus);
+ ADDNEWPARENTTOOBJECTARRAY(array, numArrays, element);
pushVectorElement(solver->allElements, element);
return element;
}
Boolean * applyPredicate(CSolver *solver, Predicate * predicate, Element ** inputs, uint numInputs) {
Boolean* boolean= allocBooleanPredicate(predicate, inputs, numInputs);
+ ADDNEWPARENTTOOBJECTARRAY(inputs, numInputs, boolean);
pushVectorBoolean(solver->allBooleans, boolean);
return boolean;
}