edits
authorbdemsky <bdemsky@uci.edu>
Wed, 21 Jun 2017 22:09:34 +0000 (15:09 -0700)
committerbdemsky <bdemsky@uci.edu>
Wed, 21 Jun 2017 22:09:34 +0000 (15:09 -0700)
src/AST/boolean.c
src/AST/boolean.h
src/AST/element.c
src/AST/element.h
src/AST/ops.h
src/AST/structtype.h [deleted file]
src/Backend/satencoder.c
src/Collections/structs.c
src/Collections/structs.h
src/classlist.h
src/csolver.c

index d0cfdddbc131a5be29be790eeed249ca13e6be53..39d7e107a7fce4e9ce96c379e1ae1f336a38afea 100644 (file)
@@ -1,62 +1,50 @@
 #include "boolean.h"
 #include "structs.h"
 #include "csolver.h"
+#include "element.h"
 
 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;
+       allocInlineDefVectorBoolean(GETBOOLEANPARENTS(tmp));
        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;
+       allocInlineDefVectorBoolean(GETBOOLEANPARENTS(tmp));
        return & tmp -> base;
 }
 
 Boolean * allocBooleanPredicate(Predicate * predicate, Element ** inputs, uint numInputs){
-       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;
-}
+       BooleanPredicate* This = (BooleanPredicate*) ourmalloc(sizeof(BooleanPredicate));
+       GETBOOLEANTYPE(This)= PREDICATEOP;
+       This->predicate=predicate;
+       This->inputs= allocVectorArrayElement (numInputs,inputs);
+       allocInlineDefVectorBoolean(GETBOOLEANPARENTS(This));
 
-Boolean * allocBooleanLogic(LogicOp op, Boolean * left, Boolean* right){
-       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;
+       for(uint i=0;i<numInputs;i++) {
+               pushVectorASTNode(GETELEMENTPARENTS(inputs[i]), (ASTNode *)This);
+       }
+       return & This->base;
 }
+
 Boolean * allocBooleanLogicArray(CSolver *solver, LogicOp op, Boolean ** array, uint asize){
-       ASSERT(asize>=2);
-       Boolean* boolean = allocBooleanLogic(op,array[0], array[1]);
-       ADDNEWPARENT(array[0], boolean);
-       ADDNEWPARENT(array[1], boolean);
-       pushVectorBoolean(solver->allBooleans,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);
+       BooleanLogic * This = ourmalloc(sizeof(BooleanLogic));
+       allocInlineDefVectorBoolean(GETBOOLEANPARENTS(This));
+       This->array = ourmalloc(sizeof(Boolean *)*asize);
+       memcpy(This->array, array, sizeof(Boolean *)*asize);
+       for(uint i=0;i<asize;i++) {
+               pushVectorBoolean(GETBOOLEANPARENTS(array[i]), (Boolean *)This);
        }
-       return boolean;
+       pushVectorBoolean(solver->allBooleans, (Boolean *) This);
+       return & This->base;
 }
 
 void deleteBoolean(Boolean * This) {
@@ -67,6 +55,6 @@ void deleteBoolean(Boolean * This) {
                default:
                        break;
        }
-       DELETEPARENTSVECTOR(This);
+       deleteVectorArrayBoolean(GETBOOLEANPARENTS(This));
        ourfree(This);
 }
index cd44c3ca651604a7b6c2345b75baadda4b425ae7..69f5a59a44dc9d3c54785f0784777132c5f2312f 100644 (file)
@@ -4,16 +4,18 @@
 #include "mymemory.h"
 #include "ops.h"
 #include "structs.h"
-#include "structtype.h"
+#include "astnode.h"
+
 /**
     This is a little sketchy, but apparently legit.
     https://www.python.org/dev/peps/pep-3123/ */
 
-#define GETBOOLEANTYPE(o) (((Boolean *)(o))->btype)
+#define GETBOOLEANTYPE(o) GETASTNODETYPE(o)
+#define GETBOOLEANPARENTS(o) (&((Boolean *)(o))->parents)
 
 struct Boolean {
-       Struct stype;
-       BooleanType btype;
+       ASTNode base;
+       VectorBoolean parents;
 };
 
 struct BooleanOrder {
@@ -32,8 +34,8 @@ struct BooleanVar {
 struct BooleanLogic {
        Boolean base;
        LogicOp op;
-       Boolean * left;
-       Boolean * right;
+       Boolean ** array;
+       uint numArray;
 };
 
 struct BooleanPredicate {
index b4b51471b480f1d4767df2b13b29bc18097b5772..3cec4770d3601f34282bd3a74f6a62127b566012 100644 (file)
@@ -4,25 +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;
+       allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
        return &tmp->base;
 }
 
 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus){
        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);
+       allocInlineDefVectorASTNode(GETELEMENTPARENTS(tmp));
+       for(uint i=0;i<numArrays;i++)
+               pushVectorASTNode(GETELEMENTPARENTS(array[i]), (ASTNode *) tmp);
        return &tmp->base;
 }
 
 void deleteElement(Element *This) {
-       DELETEPARENTSVECTOR(This);
+       deleteVectorArrayASTNode(GETELEMENTPARENTS(This));
        ourfree(This);
 }
index d1dabe0b08c09d3f8b8f6c7757a16cff6eafb7ee..56079e9eff889db8783bf52b398a0a943eea71e4 100644 (file)
@@ -2,15 +2,15 @@
 #define ELEMENT_H
 #include "classlist.h"
 #include "mymemory.h"
-#include "ops.h"
 #include "structs.h"
-#include "structtype.h"
+#include "astnode.h"
 
-#define GETELEMENTTYPE(o) (((Element*)o)->type)
+#define GETELEMENTTYPE(o) GETASTNODETYPE(o)
+#define GETELEMENTPARENTS(o) (&((Element*)o)->parents)
 
 struct Element {
-       Struct stype;
-       ElementType type;
+       ASTNode base;
+       VectorASTNode parents;
 };
 
 struct ElementSet {
index e5ccdeb6aead885246081c05eb08cbd291a21099..427b4f2539d5954f659e6f3c22faa674598a5593 100644 (file)
@@ -26,19 +26,13 @@ typedef enum OverFlowBehavior OverFlowBehavior;
 enum UndefinedBehavior {IGNOREBEHAVIOR, FLAGFORCEUNDEFINED, UNDEFINEDSETSFLAG, FLAGIFFUNDEFINED};
 typedef enum UndefinedBehavior UndefinedBehavior;
 
-enum BooleanType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, TABLEPREDICATEOP};
-typedef enum BooleanType BooleanType;
-
 enum FunctionType {TABLEFUNC, OPERATORFUNC};
 typedef enum FunctionType FunctionType;
 
 enum PredicateType {TABLEPRED, OPERATORPRED};
 typedef enum PredicateType PredicateType;
 
-enum ElementType {ELEMSET, ELEMFUNCRETURN};
-typedef enum ElementType ElementType;
-
-enum StructType {_BOOLEAN, _ELEMENT};
-typedef enum StructType StructType;
+enum ASTNodeType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, TABLEPREDICATEOP, ELEMSET, ELEMFUNCRETURN};
+typedef enum ASTNodeType ASTNodeType;
 
 #endif
diff --git a/src/AST/structtype.h b/src/AST/structtype.h
deleted file mode 100644 (file)
index d58d844..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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 */
-
index 0eb23461961a78d8b8958bfee26f5b56e62a9fba..fafd6a3bb0255f516bcefc38cd7c0c0dde51624f 100644 (file)
@@ -24,7 +24,7 @@ void encodeAllSATEncoder(SATEncoder * This, CSolver *csolver) {
 }
 
 Constraint * encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint) {
-       switch(constraint->btype) {
+       switch(GETBOOLEANTYPE(constraint)) {
        case ORDERCONST:
                return encodeOrderSATEncoder(This, (BooleanOrder *) constraint);
        case BOOLEANVAR:
@@ -54,6 +54,7 @@ Constraint * encodeVarSATEncoder(SATEncoder *This, BooleanVar * constraint) {
 }
 
 Constraint * encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint) {
+       /*
        Constraint *left=encodeConstraintSATEncoder(This, constraint->left);
        Constraint *right=NULL;
        if (constraint->right!=NULL)
@@ -74,6 +75,6 @@ Constraint * encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint)
        }
        case L_IMPLIES:
                return allocConstraint(IMPLIES, left, right);
-       }
+               }*/
        return NULL;
 }
index 30bca4217a67e94cba89f58b9f5536fe589a1fe0..4da4995028eb8458b5087757bae2eabc17754f5a 100644 (file)
@@ -2,10 +2,10 @@
 #include "mymemory.h"
 
 VectorImpl(Int, uint64_t, 4);
-VectorImpl(Void, void *, 4);
 VectorImpl(Boolean, Boolean *, 4);
 VectorImpl(Constraint, Constraint *, 4);
 VectorImpl(Set, Set *, 4);
 VectorImpl(Element, Element *, 4);
+VectorImpl(ASTNode, ASTNode *, 4);
 HashTableImpl(Void, void *, void *, Ptr_hash_function, Ptr_equals);
 HashSetImpl(Void, void *, Ptr_hash_function, Ptr_equals);
index bd473d530894189c7667c4b48fb90b92b414b29d..33e86696007502f0665e76bb9e1617ce9ef35f7b 100644 (file)
@@ -6,7 +6,6 @@
 #include "classlist.h"
 
 VectorDef(Int, uint64_t, 4);
-VectorDef(Void, void *, 4);
 VectorDef(Boolean, Boolean *, 4);
 VectorDef(Constraint, Constraint *, 4);
 VectorDef(Set, Set *, 4);
@@ -16,6 +15,7 @@ VectorDef(Predicate, Predicate *, 4);
 VectorDef(Table, Table *, 4);
 VectorDef(Order, Order *, 4);
 VectorDef(Function, Function *, 4);
+VectorDef(ASTNode, ASTNode *, 4);
 
 inline unsigned int Ptr_hash_function(void * hash) {
        return (unsigned int)((uint64_t)hash >> 4);
index c07a428fcd48a6a1b5091f9ba99d11454726c08c..c5eca510e16fe8afd575244169685cbcfad4e47e 100644 (file)
@@ -30,6 +30,9 @@ typedef struct BooleanVar BooleanVar;
 typedef struct BooleanLogic BooleanLogic;
 typedef struct BooleanPredicate BooleanPredicate;
 
+struct ASTNode;
+typedef struct ASTNode ASTNode;
+
 struct Boolean;
 typedef struct Boolean Boolean;
 
index eac2b05efc8aa61e90138f69b21a0a4e0a5b535c..5f330fd6112c70074522c17ac116739bf35746d6 100644 (file)
@@ -140,14 +140,12 @@ 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;
 }