mirror of
https://github.com/Z3Prover/z3
synced 2025-04-23 17:15:31 +00:00
move to abstract symbols
Signed-off-by: Nikolaj Bjorner <nbjorner@microsoft.com>
This commit is contained in:
parent
78a1736bd2
commit
541658fe02
16 changed files with 117 additions and 93 deletions
|
@ -319,9 +319,22 @@ class params {
|
|||
unsigned m_uint_value;
|
||||
double m_double_value;
|
||||
char const * m_str_value;
|
||||
char const * m_sym_value;
|
||||
symbol m_sym_value;
|
||||
rational * m_rat_value;
|
||||
};
|
||||
value() : m_kind(CPK_BOOL), m_bool_value(false) {}
|
||||
value& operator=(value const& other) {
|
||||
m_kind = other.m_kind;
|
||||
switch (m_kind) {
|
||||
case CPK_BOOL: m_bool_value = other.m_bool_value; break;
|
||||
case CPK_UINT: m_uint_value = other.m_uint_value; break;
|
||||
case CPK_DOUBLE: m_double_value = other.m_double_value; break;
|
||||
case CPK_STRING: m_str_value = other.m_str_value; break;
|
||||
case CPK_SYMBOL: m_sym_value = other.m_sym_value; break;
|
||||
default: m_rat_value = other.m_rat_value; break;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
typedef std::pair<symbol, value> entry;
|
||||
svector<entry> m_entries;
|
||||
|
@ -422,7 +435,7 @@ public:
|
|||
out << " " << *(e.second.m_rat_value);
|
||||
break;
|
||||
case CPK_SYMBOL:
|
||||
out << " " << symbol::mk_symbol_from_c_ptr(e.second.m_sym_value);
|
||||
out << " " << e.second.m_sym_value;
|
||||
break;
|
||||
case CPK_STRING:
|
||||
out << " " << e.second.m_str_value;
|
||||
|
@ -455,7 +468,7 @@ public:
|
|||
out << " " << *(e.second.m_rat_value);
|
||||
break;
|
||||
case CPK_SYMBOL:
|
||||
out << " " << symbol::mk_symbol_from_c_ptr(e.second.m_sym_value);
|
||||
out << " " << e.second.m_sym_value;
|
||||
break;
|
||||
case CPK_STRING:
|
||||
out << " " << e.second.m_str_value;
|
||||
|
@ -486,7 +499,7 @@ public:
|
|||
out << *(e.second.m_rat_value);
|
||||
return;
|
||||
case CPK_SYMBOL:
|
||||
out << symbol::mk_symbol_from_c_ptr(e.second.m_sym_value);
|
||||
out << e.second.m_sym_value;
|
||||
return;
|
||||
case CPK_STRING:
|
||||
out << e.second.m_str_value;
|
||||
|
@ -576,7 +589,7 @@ void params_ref::copy_core(params const * src) {
|
|||
m_params->set_rat(p.first, *(p.second.m_rat_value));
|
||||
break;
|
||||
case CPK_SYMBOL:
|
||||
m_params->set_sym(p.first, symbol::mk_symbol_from_c_ptr(p.second.m_sym_value));
|
||||
m_params->set_sym(p.first, p.second.m_sym_value);
|
||||
break;
|
||||
case CPK_STRING:
|
||||
m_params->set_str(p.first, p.second.m_str_value);
|
||||
|
@ -887,11 +900,11 @@ rational params::get_rat(char const * k, rational const & _default) const {
|
|||
}
|
||||
|
||||
symbol params::get_sym(symbol const & k, symbol const & _default) const {
|
||||
GET_VALUE(return symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);, CPK_SYMBOL);
|
||||
GET_VALUE(return it->second.m_sym_value;, CPK_SYMBOL);
|
||||
}
|
||||
|
||||
symbol params::get_sym(char const * k, symbol const & _default) const {
|
||||
GET_VALUE(return symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);, CPK_SYMBOL);
|
||||
GET_VALUE(return it->second.m_sym_value;, CPK_SYMBOL);
|
||||
}
|
||||
|
||||
#define GET_VALUE2(MATCH_CODE, KIND) { \
|
||||
|
@ -925,7 +938,7 @@ char const * params::get_str(char const * k, params_ref const & fallback, char c
|
|||
}
|
||||
|
||||
symbol params::get_sym(char const * k, params_ref const & fallback, symbol const & _default) const {
|
||||
GET_VALUE2(return symbol::mk_symbol_from_c_ptr(it->second.m_sym_value);, CPK_SYMBOL);
|
||||
GET_VALUE2(return it->second.m_sym_value;, CPK_SYMBOL);
|
||||
return fallback.get_sym(k, _default);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,11 @@ Author:
|
|||
Revision History:
|
||||
|
||||
--*/
|
||||
#if 0
|
||||
|
||||
// include "util/new_symbol.cpp"
|
||||
#else
|
||||
|
||||
#include "util/symbol.h"
|
||||
#include "util/mutex.h"
|
||||
#include "util/str_hashtable.h"
|
||||
|
@ -25,6 +30,7 @@ Revision History:
|
|||
#include <thread>
|
||||
|
||||
|
||||
|
||||
symbol symbol::m_dummy(TAG(void*, nullptr, 2));
|
||||
const symbol symbol::null;
|
||||
|
||||
|
@ -145,7 +151,7 @@ bool symbol::contains(char ch) const {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned symbol::size() const {
|
||||
unsigned symbol::display_size() const {
|
||||
SASSERT(!is_marked());
|
||||
if (GET_TAG(m_data) == 0) {
|
||||
return static_cast<unsigned>(strlen(m_data));
|
||||
|
@ -183,3 +189,5 @@ bool lt(symbol const & s1, symbol const & s2) {
|
|||
SASSERT(cmp != 0);
|
||||
return cmp < 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,6 +16,9 @@ Author:
|
|||
Revision History:
|
||||
|
||||
--*/
|
||||
#if 0
|
||||
// include "util/new_symbol.h"
|
||||
#else
|
||||
#ifndef SYMBOL_H_
|
||||
#define SYMBOL_H_
|
||||
#include<ostream>
|
||||
|
@ -66,6 +69,7 @@ public:
|
|||
friend bool operator==(symbol const & s1, symbol const & s2) { return s1.m_data == s2.m_data; }
|
||||
friend bool operator!=(symbol const & s1, symbol const & s2) { return s1.m_data != s2.m_data; }
|
||||
bool is_numerical() const { return GET_TAG(m_data) == 1; }
|
||||
bool is_null() const { return m_data == nullptr; }
|
||||
unsigned int get_num() const { SASSERT(is_numerical()); return UNBOXINT(m_data); }
|
||||
std::string str() const;
|
||||
friend bool operator==(symbol const & s1, char const * s2) {
|
||||
|
@ -78,11 +82,10 @@ public:
|
|||
return s1.str() == s2;
|
||||
}
|
||||
friend bool operator!=(symbol const & s1, char const * s2) { return !operator==(s1, s2); }
|
||||
void const * c_ptr() const { return m_data; }
|
||||
// Low level function.
|
||||
// It is the inverse of c_ptr().
|
||||
// It was made public to simplify the implementation of the C API.
|
||||
static symbol mk_symbol_from_c_ptr(void const * ptr) {
|
||||
|
||||
// C-API only functions
|
||||
void * c_api_symbol2ext() const { return const_cast<char*>(m_data); }
|
||||
static symbol c_api_ext2symbol(void const * ptr) {
|
||||
return symbol(ptr);
|
||||
}
|
||||
unsigned hash() const {
|
||||
|
@ -91,7 +94,7 @@ public:
|
|||
else return static_cast<unsigned>(reinterpret_cast<size_t const *>(m_data)[-1]);
|
||||
}
|
||||
bool contains(char c) const;
|
||||
unsigned size() const;
|
||||
unsigned display_size() const;
|
||||
char const * bare_str() const { SASSERT(!is_numerical()); return m_data; }
|
||||
friend std::ostream & operator<<(std::ostream & target, symbol s) {
|
||||
SASSERT(!s.is_marked());
|
||||
|
@ -153,3 +156,4 @@ bool lt(symbol const & s1, symbol const & s2);
|
|||
|
||||
#endif /* SYMBOL_H_ */
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue