From 4c9d60b6f6c3656ba0426eaca8af69457bf56dee Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 14 Jul 2017 15:22:42 -0700 Subject: [PATCH] Add Const API to frontend --- src/AST/element.c | 18 ++++++++++++++++++ src/AST/element.h | 8 ++++++++ src/AST/ops.h | 2 +- src/classlist.h | 1 + src/csolver.c | 6 ++++++ src/csolver.h | 3 +++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/AST/element.c b/src/AST/element.c index 5a056e9..6926ce0 100644 --- a/src/AST/element.c +++ b/src/AST/element.c @@ -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); } diff --git a/src/AST/element.h b/src/AST/element.h index 26d4989..beab5af 100644 --- a/src/AST/element.h +++ b/src/AST/element.h @@ -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); diff --git a/src/AST/ops.h b/src/AST/ops.h index dc0c80a..39fc024 100644 --- a/src/AST/ops.h +++ b/src/AST/ops.h @@ -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 diff --git a/src/classlist.h b/src/classlist.h index 4f44aff..fa3e3bd 100644 --- a/src/classlist.h +++ b/src/classlist.h @@ -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; diff --git a/src/csolver.c b/src/csolver.c index 3d062e4..36e1d91 100644 --- a/src/csolver.c +++ b/src/csolver.c @@ -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); diff --git a/src/csolver.h b/src/csolver.h index 1adb679..c45d7ee 100644 --- a/src/csolver.h +++ b/src/csolver.h @@ -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); -- 2.34.1