Using inline functions instead of macros for accessing function/element encodings
authorHamed <hamed.gorjiara@gmail.com>
Tue, 27 Jun 2017 18:39:07 +0000 (11:39 -0700)
committerHamed <hamed.gorjiara@gmail.com>
Tue, 27 Jun 2017 18:39:07 +0000 (11:39 -0700)
src/AST/element.c
src/AST/element.h
src/Encoders/functionencoding.h
src/Encoders/naiveencoder.c

index 4116cc18960c06ba02f89622b9997522d5f27ad4..f219072f4c8621f76411bbe5510ef48fde4959ba 100644 (file)
@@ -47,9 +47,9 @@ Constraint * getElementValueConstraint(Element* This, uint64_t value) {
                        ElementSet* elemSet= ((ElementSet*)This);
                        uint size = getSetSize(elemSet->set);
                        for(uint i=0; i<size; i++){
-                               if( GETELEMENTENCODING(elemSet)->encodingArray[i]==value){
-                                       return generateBinaryConstraint(GETELEMENTENCODING(elemSet)->numVars,
-                                               GETELEMENTENCODING(elemSet)->variables, i);
+                               if( getElementEncoding(elemSet)->encodingArray[i]==value){
+                                       return generateBinaryConstraint(getElementEncoding(elemSet)->numVars,
+                                               getElementEncoding(elemSet)->variables, i);
                                }
                        }
                        break;
index 3a71686c345a7c1f2f6e7006e271d6009dfcbbe4..c0eeaf52c906e3b913224d257271a548608d3e5d 100644 (file)
 
 #define GETELEMENTTYPE(o) GETASTNODETYPE(o)
 #define GETELEMENTPARENTS(o) (&((Element*)o)->parents)
-#define GETELEMENTENCODING(e) (GETELEMENTTYPE(e)==ELEMSET?     \
-               &((ElementSet*)e)->encoding:    \
-               GETELEMENTTYPE(e)==ELEMFUNCRETURN?      \
-               &((ElementFunction*)e)->domainencoding: NULL)
-// Should be called on the element or boolean
-#define GETFUNCTIONENCODING(f) (GETASTNODETYPE(f) == ELEMFUNCRETURN?   \
-               &((ElementFunction*)f)->functionencoding:       \
-               GETASTNODETYPE(f) == PREDICATEOP?       \
-               &((BooleanPredicate*)f)->encoding: NULL)
                
 struct Element {
        ASTNode base;
@@ -44,6 +35,18 @@ Element * allocElementSet(Set *s);
 Element* allocElementFunction(Function * function, Element ** array, uint numArrays, Boolean * overflowstatus);
 void deleteElement(Element *This);
 
+inline ElementEncoding* getElementEncoding(Element* This){
+       switch(GETELEMENTTYPE(This)){
+               case ELEMSET:
+                       return &((ElementSet*)This)->encoding;
+               case ELEMFUNCRETURN:            
+                       return &((ElementFunction*)This)->domainencoding;
+               default:
+                       ASSERT(0);
+       }
+       return NULL;
+}
+
 uint getElementSize(Element* This);
 Constraint * getElementValueConstraint(Element* This, uint64_t value);
 #endif
index a3521396f04abef9689b7371f4905e88b430dd14..60690e3857a0626433a16fa255e17bb510215649 100644 (file)
@@ -21,6 +21,18 @@ struct FunctionEncoding {
        ElementPredicate op;
 };
 
+inline FunctionEncoding* getFunctionEncoding(ASTNode func){
+       switch(GETASTNODETYPE(func)){
+               case ELEMFUNCRETURN:
+                       return &((ElementFunction*)func)->functionencoding;
+               case PREDICATEOP:
+                       return &((BooleanPredicate*)func)->encoding;
+               default:
+                       ASSERT(0);
+       }
+       return NULL;
+}
+
 void initFunctionEncoding(FunctionEncoding *encoding, Element *function);
 void initPredicateEncoding(FunctionEncoding *encoding, Boolean *predicate);
 void setFunctionEncodingType(FunctionEncoding* encoding, FunctionEncodingType type);
index 1d4455d96216209e6e9c4ca7ef3145fcc5b59a95..a4f46a550d6a53a1465973805ffe1d51adc8f939 100644 (file)
@@ -28,12 +28,12 @@ void naiveEncodingDecision(CSolver* csolver, NaiveEncoder* encoder){
                Element* element = getVectorElement(csolver->allElements, i);
                switch(GETELEMENTTYPE(element)){
                        case ELEMSET:
-                               setElementEncodingType(GETELEMENTENCODING(element), BINARYINDEX);
-                               baseBinaryIndexElementAssign(GETELEMENTENCODING(element));
-                               generateElementEncodingVariables(encoder,GETELEMENTENCODING(element));
+                               setElementEncodingType(getElementEncoding(element), BINARYINDEX);
+                               baseBinaryIndexElementAssign(getElementEncoding(element));
+                               generateElementEncodingVariables(encoder,getElementEncoding(element));
                                break;
                        case ELEMFUNCRETURN: 
-                               setFunctionEncodingType(GETFUNCTIONENCODING(element), ENUMERATEIMPLICATIONS);
+                               setFunctionEncodingType(getFunctionEncoding(element), ENUMERATEIMPLICATIONS);
                                break;
                        default:
                                ASSERT(0);
@@ -45,7 +45,7 @@ void naiveEncodingDecision(CSolver* csolver, NaiveEncoder* encoder){
                Boolean* predicate = getVectorBoolean(csolver->allBooleans, i);
                switch(GETBOOLEANTYPE(predicate)){
                        case PREDICATEOP:
-                               setFunctionEncodingType(GETFUNCTIONENCODING(predicate), ENUMERATEIMPLICATIONS);
+                               setFunctionEncodingType(getFunctionEncoding(predicate), ENUMERATEIMPLICATIONS);
                                break;
                        default:
                                continue;
@@ -104,7 +104,7 @@ void encode(CSolver* csolver){
                Element* element = getVectorElement(csolver->allElements, i);
                switch(GETELEMENTTYPE(element)){
                        case ELEMFUNCRETURN: 
-                               naiveEncodeFunctionPredicate(encoder, GETFUNCTIONENCODING(element));
+                               naiveEncodeFunctionPredicate(encoder, getFunctionEncoding(element));
                                break;
                        default:
                                continue;
@@ -116,7 +116,7 @@ void encode(CSolver* csolver){
                Boolean* predicate = getVectorBoolean(csolver->allBooleans, i);
                switch(GETBOOLEANTYPE(predicate)){
                        case PREDICATEOP:
-                               naiveEncodeFunctionPredicate(encoder, GETFUNCTIONENCODING(predicate));
+                               naiveEncodeFunctionPredicate(encoder, getFunctionEncoding(predicate));
                                break;
                        default:
                                continue;