set(s) {
}
+ElementSet::ElementSet(ASTNodeType _type, Set *s) :
+ Element(_type),
+ set(s) {
+}
+
ElementFunction::ElementFunction(Function *_function, Element **array, uint numArrays, BooleanEdge _overflowstatus) :
Element(ELEMFUNCRETURN),
function(_function),
functionencoding(this) {
}
-ElementConst::ElementConst(uint64_t _value, VarType _type, Set *_set) :
- Element(ELEMCONST),
- set(_set),
+ElementConst::ElementConst(uint64_t _value, Set *_set) :
+ ElementSet(ELEMCONST, _set),
value(_value) {
}
-Set *getElementSet(Element *This) {
- switch (This->type) {
- case ELEMSET:
- return ((ElementSet *)This)->set;
- case ELEMCONST:
- return ((ElementConst *)This)->set;
- case ELEMFUNCRETURN: {
- Function *func = ((ElementFunction *)This)->function;
- return func->getRange();
- }
- default:
- ASSERT(0);
- }
- ASSERT(0);
- return NULL;
-}
-
Element *ElementConst::clone(CSolver *solver, CloneMap *map) {
return solver->getElementConst(type, value);
}
void ElementFunction::updateParents() {
for(uint i=0;i < inputs.getSize(); i++) inputs.get(i)->parents.push(this);
}
+
+Set * ElementFunction::getRange() {
+ return function->getRange();
+}
ElementEncoding encoding;
virtual Element *clone(CSolver *solver, CloneMap *map) {ASSERT(0); return NULL;};
virtual void updateParents() {}
-
+ virtual Set * getRange() = 0;
CMEMALLOC;
};
-class ElementConst : public Element {
+class ElementSet : public Element {
public:
- ElementConst(uint64_t value, VarType type, Set *_set);
- Set *set;
- uint64_t value;
- Element *clone(CSolver *solver, CloneMap *map);
+ ElementSet(ASTNodeType type, Set *s);
+ ElementSet(Set *s);
+ virtual Element *clone(CSolver *solver, CloneMap *map);
CMEMALLOC;
+ Set *getRange() {return set;}
+ private:
+ Set *set;
+
};
-class ElementSet : public Element {
+class ElementConst : public ElementSet {
public:
- ElementSet(Set *s);
- Set *set;
+ ElementConst(uint64_t value, Set *_set);
+ uint64_t value;
Element *clone(CSolver *solver, CloneMap *map);
CMEMALLOC;
};
BooleanEdge overflowstatus;
FunctionEncoding functionencoding;
Element *clone(CSolver *solver, CloneMap *map);
+ Set * getRange();
void updateParents();
CMEMALLOC;
};
-Set *getElementSet(Element *This);
-
static inline ElementEncoding *getElementEncoding(Element *e) {
return &e->encoding;
}
uint64_t vals[numDomains];//setup value array
for (uint i = 0; i < numDomains; i++) {
- Set *set = getElementSet(func->inputs.get(i));
+ Set *set = func->inputs.get(i)->getRange();
vals[i] = set->getElement(indices[i]);
}
notfinished = false;
for (uint i = 0; i < numDomains; i++) {
uint index = ++indices[i];
- Set *set = getElementSet(func->inputs.get(i));
+ Set *set = func->inputs.get(i)->getRange();
if (index < set->getSize()) {
vals[i] = set->getElement(index);
}
void ElementEncoding::encodingArrayInitialization() {
- Set *set = getElementSet(element);
+ Set *set = element->getRange();
uint size = set->getSize();
uint encSize = getSizeEncodingArray(size);
allocEncodingArrayElement(encSize);
uint64_t getElementValueSATTranslator(CSolver *This, Element *element) {
ElementEncoding *elemEnc = getElementEncoding(element);
if (elemEnc->numVars == 0)//case when the set has only one item
- return getElementSet(element)->getElement(0);
+ return element->getRange()->getElement(0);
switch (elemEnc->type) {
case ONEHOT:
return getElementValueOneHotSATTranslator(This, elemEnc);
Element *CSolver::getElementConst(VarType type, uint64_t value) {
uint64_t array[] = {value};
Set *set = new Set(type, array, 1);
- Element *element = new ElementConst(value, type, set);
+ Element *element = new ElementConst(value, set);
Element *e = elemMap.get(element);
if (e == NULL) {
allSets.push(set);