#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) {
default:
break;
}
- DELETEPARENTSVECTOR(This);
+ deleteVectorArrayBoolean(GETBOOLEANPARENTS(This));
ourfree(This);
}
#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 {
struct BooleanLogic {
Boolean base;
LogicOp op;
- Boolean * left;
- Boolean * right;
+ Boolean ** array;
+ uint numArray;
};
struct BooleanPredicate {
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);
}
#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 {
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
+++ /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 */
-
}
Constraint * encodeConstraintSATEncoder(SATEncoder *This, Boolean *constraint) {
- switch(constraint->btype) {
+ switch(GETBOOLEANTYPE(constraint)) {
case ORDERCONST:
return encodeOrderSATEncoder(This, (BooleanOrder *) constraint);
case BOOLEANVAR:
}
Constraint * encodeLogicSATEncoder(SATEncoder *This, BooleanLogic * constraint) {
+ /*
Constraint *left=encodeConstraintSATEncoder(This, constraint->left);
Constraint *right=NULL;
if (constraint->right!=NULL)
}
case L_IMPLIES:
return allocConstraint(IMPLIES, left, right);
- }
+ }*/
return NULL;
}
#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);
#include "classlist.h"
VectorDef(Int, uint64_t, 4);
-VectorDef(Void, void *, 4);
VectorDef(Boolean, Boolean *, 4);
VectorDef(Constraint, Constraint *, 4);
VectorDef(Set, Set *, 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);
typedef struct BooleanLogic BooleanLogic;
typedef struct BooleanPredicate BooleanPredicate;
+struct ASTNode;
+typedef struct ASTNode ASTNode;
+
struct Boolean;
typedef struct Boolean Boolean;
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;
}