Add Const API to frontend
authorbdemsky <bdemsky@uci.edu>
Fri, 14 Jul 2017 22:22:42 +0000 (15:22 -0700)
committerbdemsky <bdemsky@uci.edu>
Fri, 14 Jul 2017 22:22:42 +0000 (15:22 -0700)
src/AST/element.c
src/AST/element.h
src/AST/ops.h
src/classlist.h
src/csolver.c
src/csolver.h

index 5a056e9e5800c44a338782e5f9c509f2b4b39579..6926ce032f8af7097d1d7663ff046f423826b826 100644 (file)
@@ -28,10 +28,22 @@ Element* allocElementFunction(Function * function, Element ** array, uint numArr
        return &This->base;
 }
 
+Element * allocElementConst(uint64_t value, VarType type) {
+       ElementConst * This=(ElementConst *)ourmalloc(sizeof(ElementConst));
+       GETELEMENTTYPE(This)= ELEMCONST;
+       This->value=value;
+       This->set=allocSet(type, (uint64_t[]){value}, 1);
+       initDefVectorASTNode(GETELEMENTPARENTS(This));
+       initElementEncoding(&This->encoding, (Element *) This);
+       return &This->base;
+}
+
 Set* getElementSet(Element* This){
        switch(GETELEMENTTYPE(This)){
        case ELEMSET:
                return ((ElementSet*)This)->set;
+       case ELEMCONST:
+               return ((ElementConst*)This)->set;
        case ELEMFUNCRETURN: {
                Function* func = ((ElementFunction*)This)->function;
                switch(GETFUNCTIONTYPE(func)){
@@ -64,6 +76,12 @@ void deleteElement(Element *This) {
                deleteElementEncoding(&es->encoding);
                break;
        }
+       case ELEMCONST: {
+               ElementConst *ec = (ElementConst *) This;
+               deleteSet(ec->set);//Client did not create, so we free it
+               deleteElementEncoding(&ec->encoding);
+               break;
+       }
        default:
                ASSERT(0);
        }
index 26d4989c1d26a411fd254a328f8b7883c51338bd..beab5af1e17aa065249afbae95a96c2109ab50d7 100644 (file)
@@ -15,6 +15,13 @@ struct Element {
        VectorASTNode parents;
 };
 
+struct ElementConst {
+       Element base;
+       Set * set;
+       uint64_t value;
+       ElementEncoding encoding;
+};
+
 struct ElementSet {
        Element base;
        Set * set;
@@ -30,6 +37,7 @@ struct ElementFunction {
        ElementEncoding rangeencoding;
 };
 
+Element * allocElementConst(uint64_t value, VarType type);
 Element * allocElementSet(Set *s);
 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
 void deleteElement(Element *This);
index dc0c80a5d6debdce01298d1326530ada2aca6c3e..39fc024b2d88c34eaaa5e0c05b003a3282c01883 100644 (file)
@@ -32,7 +32,7 @@ typedef enum FunctionType FunctionType;
 enum PredicateType {TABLEPRED, OPERATORPRED};
 typedef enum PredicateType PredicateType;
 
-enum ASTNodeType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, ELEMSET, ELEMFUNCRETURN};
+enum ASTNodeType {ORDERCONST, BOOLEANVAR, LOGICOP, PREDICATEOP, ELEMSET, ELEMFUNCRETURN, ELEMCONST};
 typedef enum ASTNodeType ASTNodeType;
 
 #endif
index 4f44aff688db2bfe1578482b5f327dd647837721..fa3e3bdb608058fb3ef3732ee6e9aa4ac260997d 100644 (file)
@@ -41,6 +41,7 @@ typedef struct Set MutableSet;
 
 typedef struct ElementFunction ElementFunction;
 typedef struct ElementSet ElementSet;
+typedef struct ElementConst ElementConst;
 
 struct Element;
 typedef struct Element Element;
index 3d062e4733af1df10eb3285848d7b34da39926ef..36e1d91a0cfad786628c4f160b09c6b1a4cfefd1 100644 (file)
@@ -108,6 +108,12 @@ Element * getElementVar(CSolver *This, Set * set) {
        return element;
 }
 
+Element * getElementConst(CSolver *This, VarType type, uint64_t value) {
+       Element * element=allocElementConst(value, type);
+       pushVectorElement(This->allElements, element);
+       return element;
+}
+
 Boolean * getBooleanVar(CSolver *This, VarType type) {
        Boolean* boolean= allocBooleanVar(type);
        pushVectorBoolean(This->allBooleans, boolean);
index 1adb67932e71d60b8986a21b08b806a6dda21e8d..c45d7ee38c3ab33c9ead806ff1dffe4e10cbd454 100644 (file)
@@ -65,6 +65,9 @@ uint64_t createUniqueItem(CSolver *, MutableSet * set);
 
 Element * getElementVar(CSolver *, Set * set);
 
+/** This function creates an element constrant. */
+Element * getElementConst(CSolver *, VarType type, uint64_t value);
+
 /** This function creates a boolean variable. */
 
 Boolean * getBooleanVar(CSolver *, VarType type);