From: Hamed <hamed.gorjiara@gmail.com>
Date: Wed, 21 Jun 2017 21:12:04 +0000 (-0700)
Subject: Keeping the type of Boolean/Element struct, as well as keeping backward edges for... 
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1d6dbb6b9bfc8a2ebfbb29f9bcda4b4127909b00;p=satune.git

Keeping the type of Boolean/Element struct, as well as keeping backward edges for them.
---

diff --git a/src/AST/boolean.c b/src/AST/boolean.c
index 831a200..d0cfddd 100644
--- a/src/AST/boolean.c
+++ b/src/AST/boolean.c
@@ -5,6 +5,8 @@
 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;
@@ -13,6 +15,8 @@ Boolean* allocBoolean(VarType t) {
 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;
@@ -20,32 +24,49 @@ Boolean* allocBooleanOrder(Order* order, uint64_t first, uint64_t 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);
 }
diff --git a/src/AST/boolean.h b/src/AST/boolean.h
index 15ebd52..cd44c3c 100644
--- a/src/AST/boolean.h
+++ b/src/AST/boolean.h
@@ -4,7 +4,7 @@
 #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/ */
@@ -12,6 +12,7 @@
 #define GETBOOLEANTYPE(o) (((Boolean *)(o))->btype)
 
 struct Boolean {
+	Struct stype;
 	BooleanType btype;
 };
 
diff --git a/src/AST/element.c b/src/AST/element.c
index 1fb49aa..b4b5147 100644
--- a/src/AST/element.c
+++ b/src/AST/element.c
@@ -4,20 +4,25 @@
 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);
 }
diff --git a/src/AST/element.h b/src/AST/element.h
index da9b994..d1dabe0 100644
--- a/src/AST/element.h
+++ b/src/AST/element.h
@@ -4,11 +4,12 @@
 #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;
 };
 
diff --git a/src/AST/ops.h b/src/AST/ops.h
index 123617b..e5ccdeb 100644
--- a/src/AST/ops.h
+++ b/src/AST/ops.h
@@ -37,4 +37,8 @@ typedef enum PredicateType PredicateType;
 
 enum ElementType {ELEMSET, ELEMFUNCRETURN};
 typedef enum ElementType ElementType;
+
+enum StructType {_BOOLEAN, _ELEMENT};
+typedef enum StructType StructType;
+
 #endif
diff --git a/src/AST/predicate.c b/src/AST/predicate.c
index 1737681..904fe22 100644
--- a/src/AST/predicate.c
+++ b/src/AST/predicate.c
@@ -23,7 +23,6 @@ void deletePredicate(Predicate* predicate){
 		break;
 	}
 	}
-
 	//need to handle freeing array...
 	ourfree(predicate);
 }
diff --git a/src/AST/predicate.h b/src/AST/predicate.h
index f9af5af..c6dd02b 100644
--- a/src/AST/predicate.h
+++ b/src/AST/predicate.h
@@ -3,7 +3,7 @@
 #include "classlist.h"
 #include "mymemory.h"
 #include "ops.h"
-#include "structs.h"
+
 
 #define GETPREDICATETYPE(o) (((Predicate *)(o))->type)
 
diff --git a/src/AST/structtype.h b/src/AST/structtype.h
new file mode 100644
index 0000000..d58d844
--- /dev/null
+++ b/src/AST/structtype.h
@@ -0,0 +1,35 @@
+/*
+ * 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 */
+
diff --git a/src/classlist.h b/src/classlist.h
index d32af3f..c07a428 100644
--- a/src/classlist.h
+++ b/src/classlist.h
@@ -79,6 +79,9 @@ typedef struct OrderEncoding OrderEncoding;
 struct TableEntry;
 typedef struct TableEntry TableEntry;
 
+struct Struct;
+typedef struct Struct Struct;
+
 typedef unsigned int uint;
 typedef uint64_t VarType;
 #endif
diff --git a/src/csolver.c b/src/csolver.c
index 5f330fd..eac2b05 100644
--- a/src/csolver.c
+++ b/src/csolver.c
@@ -140,12 +140,14 @@ Function * completeTable(CSolver *solver, Table * table) {
 
 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;
 }