relation_set.cc
//converts the AstConstant to a Variable
//also compresses integer variables to their minimal storage type
converts the AstConstant to a Variable
also compresses integer variables to their minimal storage type
converts the AstConstant to a Variable also compresses integer variables to their minimal storage type
Variable RelationSet::toVariable(AstConstant &constant)  {
    if(constant.type == AstValueType::Integer)  {
        int64_t value = boost::get<int64_t>(constant.value);
        if(value < 0)  { 
            if(value < -2147483648) 
                return toVariableByType(constant, VariableSetType::INT64);
            else if(value < -32768) 
                return toVariableByType(constant, VariableSetType::INT32);
            else if(value < -128) 
                return toVariableByType(constant, VariableSetType::INT16);
            else 
                return toVariableByType(constant, VariableSetType::INT8);
        }
        else  { 
            if(value > 9223372036854775807) 
                throw "The value can't be stored, since unsigned integers with 64 bits are not supported! Maximal type is signed integer with 64 bits.";
            else if(value > 4294967295)  SIGNED integer for integers that can't be stored in an UINT32
                return toVariableByType(constant, VariableSetType::INT64);
            else if(value > 65535) 
                return toVariableByType(constant, VariableSetType::UINT32);
            else if(value > 255) 
                return toVariableByType(constant, VariableSetType::UINT16);
            else 
                return toVariableByType(constant, VariableSetType::UINT8);
        }
    }
    else if(constant.type == AstValueType::Float)
        return toVariableByType(constant, VariableSetType::DOUBLE);
    else if(constant.type == AstValueType::Boolean)
        return toVariableByType(constant, VariableSetType::BOOLEAN);
    else if(constant.type == AstValueType::String)
        return toVariableByType(constant, VariableSetType::STRING);
    else if(constant.type == AstValueType::EnumValue)
        return toVariableByType(constant, VariableSetType::ENUM_VALUE);
    else
        throw "Undefined AstValueType in RelationSet::toVariable()";
}
Variable RelationSet :: toVariable ( AstConstant & constant ) { if ( constant . type == AstValueType :: Integer ) { int64_t value = boost :: get < int64_t > ( constant . value ) ; if ( value < 0 ) { if ( value < -2147483648 ) return toVariableByType ( constant , VariableSetType :: INT64 ) ; else if ( value < -32768 ) return toVariableByType ( constant , VariableSetType :: INT32 ) ; else if ( value < -128 ) return toVariableByType ( constant , VariableSetType :: INT16 ) ; else return toVariableByType ( constant , VariableSetType :: INT8 ) ; } else { if ( value > 9223372036854775807 ) throw " " ; else if ( value > 4294967295 ) return toVariableByType ( constant , VariableSetType :: INT64 ) ; else if ( value > 65535 ) return toVariableByType ( constant , VariableSetType :: UINT32 ) ; else if ( value > 255 ) return toVariableByType ( constant , VariableSetType :: UINT16 ) ; else return toVariableByType ( constant , VariableSetType :: UINT8 ) ; } } else if ( constant . type == AstValueType :: Float ) return toVariableByType ( constant , VariableSetType :: DOUBLE ) ; else if ( constant . type == AstValueType :: Boolean ) return toVariableByType ( constant , VariableSetType :: BOOLEAN ) ; else if ( constant . type == AstValueType :: String ) return toVariableByType ( constant , VariableSetType :: STRING ) ; else if ( constant . type == AstValueType :: EnumValue ) return toVariableByType ( constant , VariableSetType :: ENUM_VALUE ) ; else throw " " ; }
converts the AstConstant to a Variable
also compresses integer variables to their minimal storage type
converts the AstConstant to a Variable also compresses integer variables to their minimal storage type
//get the value as the maximal type possible //then compress it to a smaller one based on its value //use signed integers //use 64 bits //use 32 bits //use 16 bits //use 8 bits //use unsigned integers, but only if it fits into an UINT32 or a smaller type else INT64 is used //use 64 bits //use 64 bits SIGNED integer for integers that can't be stored in an UINT32 //use 32 bits //use 16 bits //use 8 bits