Commits

Leonardo de Moura committed 81df5ca

Moved dead code to dead branch

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>

Comments (0)

Files changed (123)

src/api/dotnet/dead/Microsoft.Z3V3/AssemblyInfo.cpp

-using namespace System;
-using namespace System::Reflection;
-using namespace System::Runtime::CompilerServices;
-using namespace System::Runtime::InteropServices;
-using namespace System::Security::Permissions;
-
-//
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-//
-[assembly:AssemblyTitleAttribute("Z3 .NET Interface")];
-[assembly:AssemblyDescriptionAttribute(".NET Interface to the Z3 Theorem Prover")];
-[assembly:AssemblyConfigurationAttribute("")];
-[assembly:AssemblyCompanyAttribute("Microsoft Corporation")];
-[assembly:AssemblyProductAttribute("Z3")];
-[assembly:AssemblyCopyrightAttribute("Copyright (c) Microsoft Corporation 2006")];
-[assembly:AssemblyTrademarkAttribute("")];
-[assembly:AssemblyCultureAttribute("")];
-
-[assembly:ComVisible(false)];
-[assembly:CLSCompliantAttribute(true)];
-[assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)];
-
-[assembly:AssemblyVersionAttribute("4.2.0.0")];
-[assembly:AssemblyFileVersionAttribute("4.2.0.0")];
-
-//#ifdef DELAYSIGN
-//[assembly:AssemblyKeyFile("35MSSharedLib1024.snk")];
-//[assembly:AssemblyDelaySign(true)];
-//#else
-//[assembly:AssemblyKeyFile("z3.snk")];
-//[assembly:AssemblyDelaySign(true)];
-//#endif

src/api/dotnet/dead/Microsoft.Z3V3/Microsoft.Z3V3.cpp

-/*++
-Copyright (c) 2007 Microsoft Corporation
-
-Module Name:
-
-    Microsoft.Z3V3.cpp
-
-Abstract:
-
-    Z3 Managed API.
-
-Author:
-
-    Nikolaj Bjorner (nbjorner)
-    Leonardo de Moura (leonardo) 2007-06-8
-
-Notes:
-    
---*/
-
-//#include "stdafx.h"
-#include "Microsoft.Z3V3.h"
-#include "..\lib\util.h"
-#include "..\lib\z3_private.h"
-#include <sstream>
-#include <strstream>
-#include <vcclr.h>
-#include "../lib/rational.h"
-#include "../lib/z3_private.h"
-
-
-using namespace System::Text;
-using namespace Microsoft::Z3V3;
-
-// -------------------------------
-// ref_context
-
-ref_context* ref_context::mk(Z3_context ctx, bool owned, bool scoped) { 
-    return alloc(ref_context, ctx, owned, scoped); 
-}
-
-void ref_context::dec_ref() { 
-    --m_count;
-    if (0 == m_count) {
-        if (m_owned) {
-            if (m_dl) {
-                Z3_fixedpoint_dec_ref(m_ctx, m_dl);
-            }
-            Z3_del_context(m_ctx); 
-        }
-        dealloc(this);
-    }
-}
-
-void ref_context::inc_ref() { 
-    ++m_count;
-}
-
-Z3_fixedpoint ref_context::dl() {
-    if (!m_dl) {
-        m_dl = Z3_mk_fixedpoint(m_ctx);
-        Z3_fixedpoint_inc_ref(m_ctx, m_dl);
-    }
-    return m_dl;
-}
-
-
-// -------------------------------
-// static functions
-
-
-static std::string
-CreateString(
-    String^ string
-    )
-{
-    std::string s;
-    array<Byte>^ bytes = 
-        Encoding::Convert(
-            Encoding::Unicode, 
-            Encoding::ASCII, 
-            Encoding::Unicode->GetBytes(string)
-            );
-
-    for (int i = 0; i < bytes->Length; ++i) {
-        s += bytes[i];
-    }
-    return s;
-}
-
-bool Z3Log::Open(String^ filename) {
-    m_open = true;
-    return Z3_TRUE == Z3_open_log(CreateString(filename).c_str());
-}
-
-void Z3Log::Append(String^ s) {
-    Z3_append_log(CreateString(s).c_str());
-}
-
-void Z3Log::Close() {
-    m_open = false;
-    Z3_close_log();
-}
-
-template<class T>
-class scoped_array {
-public:
-    scoped_array(unsigned length)
-        : m_length(length),
-          m_data(new T[length])
-    {
-    }
-
-    scoped_array(array<T>^ a) 
-    {
-        m_length = a?a->Length:0;
-        m_data = a?(new T[m_length]):0;
-        for (unsigned i = 0; i < m_length; ++i) {
-            m_data[i] = a[i];
-        }
-    }
-
-    virtual ~scoped_array() {
-        delete[] m_data;
-    }
-
-    T* c_ptr() { return m_data; }
-
-    T const* c_ptr() const { return m_data; }
-
-    T& operator[](int i) { return m_data[i]; }
-
-    unsigned size() { return m_length; }
-protected:
-    unsigned m_length;
-    T*       m_data;
-};
-
-template<typename T>
-class scoped_Z3_ast_array : public scoped_array<T> {
-public:
-    scoped_Z3_ast_array(array<IntPtr>^ asts)
-        : scoped_array((!asts)?0:asts->Length)
-    {
-        for (unsigned i = 0; i < m_length; ++i) {
-            c_ptr()[i] = static_cast<T>(asts[i].ToPointer());
-        }
-    }
-    scoped_Z3_ast_array(int length)
-        : scoped_array(length) {}
-};
-
-
-class scoped_Z3_symbol_array : public scoped_array<Z3_symbol> {
-public:
-    scoped_Z3_symbol_array(array<Symbol^>^ symbols)
-        : scoped_array((!symbols)?0:symbols->Length)
-    {
-        for (unsigned i = 0; i < m_length; ++i) {
-            c_ptr()[i] = symbols[i]->get();
-        }
-    }
-
-    scoped_Z3_symbol_array(Z3_context ctx, array<String^>^ symbols)
-        : scoped_array((!symbols)?0:symbols->Length)
-    {
-        for (unsigned i = 0; i < m_length; ++i) {
-            c_ptr()[i] = Z3_mk_string_symbol(ctx, CreateString(symbols[i]).c_str());
-        }
-    }
-
-    scoped_Z3_symbol_array(unsigned n): scoped_array(n) {}
-};
-
-static void CopyFuncDecl(scoped_Z3_ast_array<Z3_func_decl>& src,
-                         array<FuncDeclPtr>^ dst) {
-    SASSERT(dst->Length == src.size());
-    for (unsigned i = 0; i < src.size(); ++i) {
-        dst[i] = FuncDeclPtr(src[i]);
-    }
-}
-
-static array<TermPtr>^ MkArray(unsigned n, Z3_ast const* args) {
-    array<TermPtr>^ result = gcnew array<TermPtr>(n);
-    for (unsigned i = 0; i < n; ++i) {
-        result[i] = TermPtr(args[i]);
-    }
-    return result;
-}
-
-static SearchFailureExplanation ConvertExplanation(Z3_search_failure f) {
-    switch(f) {
-    case Z3_NO_FAILURE:
-        return SearchFailureExplanation::NoFailure;
-    case Z3_UNKNOWN:
-        return SearchFailureExplanation::Unknown;
-    case Z3_TIMEOUT:
-        return SearchFailureExplanation::TimeOut;
-    case Z3_MEMOUT_WATERMARK:
-        return SearchFailureExplanation::MemOut;
-    case Z3_CANCELED:      
-        return SearchFailureExplanation::UserCanceled;
-    case Z3_NUM_CONFLICTS: 
-        return SearchFailureExplanation::MaxConflicts;
-    case Z3_THEORY: 
-        return SearchFailureExplanation::Theory;
-    case Z3_QUANTIFIERS: 
-        return SearchFailureExplanation::Quantifiers;
-    }
-    return SearchFailureExplanation::Unknown;
-}
-
-//----------------------------------------
-// Config
-
-Config::Config() { m_config = Z3_mk_config(); }
-
-Config::~Config() { 
-    if (m_config) { 
-        Z3_del_config(m_config); 
-        m_config = 0;
-    } 
-}
-
-Config::!Config() { 
-    if (m_config) {
-        if (RawContext::m_error_handler ) {
-            RawContext::m_error_handler->Handler(ErrorCode::NonDisposedConfig);
-        }
-        else {
-            verbose_stream() << "WARNING: configuration was not disposed\n";
-        }
-    }
-}
-
-
-void Config::SetParamValue(String^ param_id, String^ param_value) {    
-    Z3_set_param_value(m_config, CreateString(param_id).c_str(), CreateString(param_value).c_str());
-}
-
-
-//----------------------------------------
-// Model
-
-RawModel::~RawModel() { 
-    Reset();
-}
-
-RawModel::!RawModel() { 
-    if (m_model) {
-        if (RawContext::m_error_handler ) {
-            RawContext::m_error_handler->Handler(ErrorCode::NonDisposedModel);
-        }
-        else {
-            verbose_stream() << "WARNING: model was not disposed\n";
-        }
-    }
-}
-
-void RawModel::Reset() {
-    if (m_model != 0) { 
-        Z3_del_model(m_context(), m_model); 
-        m_context.dec_ref();
-        m_model = 0;
-    } 
-}
-
-array<FuncDeclPtr>^ RawModel::GetModelConstants() {
-    unsigned num_consts = Z3_get_model_num_constants(m_context(), m_model);
-    array<FuncDeclPtr>^ result = gcnew array<FuncDeclPtr>(num_consts);
-    for (unsigned i = 0; i < num_consts; ++i) {
-        result[i] = FuncDeclPtr(Z3_get_model_constant(m_context(), m_model, i));
-    }
-    return result;
-}
-
-
-String^ RawContext::GetNumeralString(TermPtr v) {
-    return gcnew String(Z3_get_numeral_string(ctx(), get_ast(v)));
-}
-
-int RawContext::GetNumeralInt(TermPtr v) {
-    int result = 0;
-    if (!Z3_get_numeral_int(ctx(), get_ast(v), &result)) {
-        throw gcnew System::ArgumentException("Expecting value of integer type");
-    }
-    return result;
-}
-
-bool RawContext::TryGetNumeralInt(TermPtr v, int% i) {
-    int result = 0;
-    if (!Z3_get_numeral_int(ctx(), get_ast(v), &result)) {
-        return false;
-    }
-    i = result;
-    return true;
-}
-
-unsigned RawContext::GetNumeralUInt(TermPtr v) {
-    unsigned result = 0;
-    if (!Z3_get_numeral_uint(ctx(), get_ast(v), &result)) {
-        throw gcnew System::ArgumentException("Expecting TermPtr of unsigned integer type");
-    }
-    return result;
-}
-
-bool RawContext::TryGetNumeralUInt(TermPtr v, unsigned% u) {
-    unsigned result = 0;
-    if (!Z3_get_numeral_uint(ctx(), get_ast(v), &result)) {
-        return false;
-    }
-    u = result;
-    return true;
-}
-
-
-__int64 RawContext::GetNumeralInt64(TermPtr v) {
-    __int64 result = 0;
-    if (!Z3_get_numeral_int64(ctx(), get_ast(v), &result)) {
-        throw gcnew System::ArgumentException("Expecting value of signed 64 bit integer type");
-    }
-    return result;
-}
-
-bool RawContext::TryGetNumeralInt64(TermPtr v, __int64% i) {
-    __int64 result = 0;
-    if (!Z3_get_numeral_int64(ctx(), get_ast(v), &result)) {
-        return false;
-    }
-    i = result;
-    return true;
-}
-
-
-unsigned __int64 RawContext::GetNumeralUInt64(TermPtr v) {
-    unsigned __int64 result = 0;
-    if (!Z3_get_numeral_uint64(ctx(), get_ast(v), &result)) {
-        throw gcnew System::ArgumentException("Expecting value of unsigned 64 bit integer type");
-    }
-    return result;
-}
-
-bool RawContext::TryGetNumeralUInt64(TermPtr v, unsigned __int64% u) {
-    unsigned __int64 result = 0;
-    if (!Z3_get_numeral_uint64(ctx(), get_ast(v), &result)) {
-        return false;
-    }
-    u = result;
-    return true;
-}
-
-bool RawContext::TryGetNumeral(TermPtr v, [Out] __int64% num, [Out] __int64% den) {
-    __int64 _num, _den;
-    if (!Z3_get_numeral_rational_int64(ctx(), get_ast(v), &_num, &_den)) {
-        return false;
-    }
-    num = _num;
-    den = _den;
-    return true;
-}
-
-
-void RawContext::GetNumeral(TermPtr v, [Out] System::Numerics::BigInteger% num, [Out] System::Numerics::BigInteger% den) {
-    rational r;
-    if (!Z3_get_numeral_rational(ctx(), get_ast(v), r)) {
-        Z3_error_handler(Z3_INVALID_ARG);
-        return;
-    }
-    rational d = denominator(r);
-    rational n = numerator(r);
-    rational ten(10);
-    bool is_neg = false;
-    SASSERT(!d.is_neg());
-    if (n.is_neg()) {
-        is_neg = true;
-        n = -n;
-    }
-    num = 0;
-    System::Numerics::BigInteger mul = 1;
-    while (n.is_pos()) {
-        num += mul * mod(n,ten).get_unsigned();
-        n = div(n,ten);
-        mul *= 10;
-    }
-    if (is_neg) {
-        num = -num;
-    }
-    den = 0;
-    mul = 1;
-    while (d.is_pos()) {
-        den += mul * mod(d,ten).get_unsigned();
-        d = div(d,ten);
-        mul *= 10;
-    }
-}
-
-
-LBool RawContext::GetBoolValue(TermPtr a) {
-    switch (Z3_get_bool_value(ctx(), get_ast(a))) {
-    case Z3_L_FALSE: return LBool::False;
-    case Z3_L_UNDEF: return LBool::Undef;
-    case Z3_L_TRUE:  return LBool::True;
-    default:
-        UNREACHABLE();
-        return LBool::Undef;
-    }
-}
-
-
-bool RawModel::TryGetArrayValue(TermPtr v, RawArrayValue^% av) {
-    unsigned num_entries;
-    if (!Z3_is_array_value(m_context(), m_model, get_ast(v), & num_entries)) {
-        return false;
-    }
-    scoped_Z3_ast_array<Z3_ast> _indices(num_entries);
-    scoped_Z3_ast_array<Z3_ast> _values(num_entries);
-    Z3_ast else_value;
-    Z3_get_array_value(m_context(), m_model, get_ast(v), num_entries, _indices.c_ptr(), _values.c_ptr(), &else_value);   
-    av = gcnew RawArrayValue();
-    av->Domain = gcnew array<TermPtr>(num_entries);
-    av->Range = gcnew array<TermPtr>(num_entries);
-    av->ElseCase = TermPtr(else_value);
-    for (unsigned i = 0; i < num_entries; ++i) {
-        av->Domain[i] = TermPtr(_indices[i]);
-        av->Range[i] = TermPtr(_values[i]);
-    }
-    return true;
-}
-
-TermPtr RawContext::GetAssignments() {
-    return TermPtr(Z3_get_context_assignment(ctx())); 
-}
-
-
-TermPtr RawContext::UpdateTerm(TermPtr t, array<TermPtr>^ new_args) {
-    scoped_Z3_ast_array<Z3_ast> _new_args(new_args);
-    return TermPtr(Z3_update_term(ctx(), get_ast(t), 
-                                  _new_args.size(), _new_args.c_ptr()));
-}
-
-Dictionary<FuncDeclPtr, RawFunctionGraph^>^ RawModel::GetFunctionGraphs() {
-    if (m_graphs) {
-        return m_graphs;
-    }
-    SASSERT(m_model);
-    unsigned _num_funs = Z3_get_model_num_funcs(m_context(), m_model);
-
-    Dictionary<FuncDeclPtr, RawFunctionGraph^>^ graphs = 
-        gcnew Dictionary<FuncDeclPtr, RawFunctionGraph^>();
-
-    for (unsigned i = 0; i < _num_funs; ++i) {        
-        unsigned num_entries = Z3_get_model_func_num_entries(m_context(), m_model, i);
-        FuncDeclPtr decl = FuncDeclPtr(Z3_get_model_func_decl(m_context(), m_model, i));
-        RawFunctionGraph^ graph = gcnew RawFunctionGraph();
-        graphs[decl] = graph;
-        graph->Declaration = decl;
-        graph->Else = TermPtr(Z3_get_model_func_else(m_context(), m_model, i));
-        graph->Entries = gcnew array<RawFunctionEntry^>(num_entries);
-
-        for (unsigned j = 0; j < num_entries; ++j) {
-            unsigned num_args = Z3_get_model_func_entry_num_args(m_context(), m_model, i, j);
-            graph->Entries[j] = gcnew RawFunctionEntry();
-            graph->Entries[j]->Arguments = gcnew array<TermPtr>(num_args);
-            for (unsigned k = 0; k < num_args; ++k) {
-                graph->Entries[j]->Arguments[k] = TermPtr(Z3_get_model_func_entry_arg(m_context(), m_model, i, j, k));
-            }
-            graph->Entries[j]->Result = TermPtr(Z3_get_model_func_entry_value(m_context(), m_model, i, j));
-        }
-    }
-    m_graphs = graphs;
-    return graphs;
-}
-
-TermPtr RawModel::Eval(TermPtr t) {
-    Z3_ast v = 0;
-    if (!Z3_eval(m_context(), m_model, get_ast(t), &v)) {
-        return IntPtr::Zero; 
-    }
-    return TermPtr(v);
-}
-
-TermPtr RawModel::Eval(FuncDeclPtr decl, array<TermPtr>^ args) {
-    Z3_ast v = 0;
-    scoped_Z3_ast_array<Z3_ast> _args(args);
-    
-    if (!Z3_eval_decl(m_context(), m_model, get_func_decl(decl), 
-                      _args.size(), _args.c_ptr(), &v)) {
-        return IntPtr::Zero;
-    }
-    return TermPtr(v);
-}
-
-String^ RawModel::ToString() {
-    return gcnew String(Z3_model_to_string(m_context(), m_model));
-}
-
-void RawModel::Display(System::IO::TextWriter^ w) {
-    w->Write(ToString());
-}
-
-RawTheory^ RawContext::MkTheory(String^ name) {
-    return gcnew RawTheory(*m_context, name);
-}
-
-
-void RawContext::RegisterRelation(FuncDeclPtr r) {
-    Z3_fixedpoint_register_relation(ctx(), dl(), get_func_decl(r));
-}
-
-void RawContext::AddRule(TermPtr term, Symbol^ name) {
-    Z3_fixedpoint_add_rule(ctx(), dl(), get_ast(term), name?name->get():0);
-}
-
-LBool RawContext::Query(TermPtr query) {
-    switch(Z3_fixedpoint_query(ctx(), dl(), get_ast(query))) {
-    case Z3_L_FALSE: return LBool::False;
-    case Z3_L_TRUE:  return LBool::True;
-    default: return LBool::Undef;
-    }
-}
-
-String^ RawContext::GetQueryStatus() {
-    return gcnew String(Z3_fixedpoint_get_reason_unknown(ctx(),dl()));
-}
-
-TermPtr RawContext::GetQueryAnswer() {
-    return TermPtr(Z3_fixedpoint_get_answer(ctx(),dl()));
-}
-
-static void fixedpoint_assign_callback(void* c, Z3_func_decl f, unsigned n, Z3_ast const* _args, unsigned m, Z3_ast const* outs) {
-    RawContext::fixedpoint_assign_callback(c, f, n, _args, m, outs);
-}
-
-static void fixedpoint_apply_callback(void* c, Z3_func_decl f, unsigned n, Z3_ast const* _args, Z3_ast* out) {
-    RawContext::fixedpoint_apply_callback(c, f, n, _args, out);
-}
-
-void RawContext::init_fixedpoint_callbacks() {
-    if (contexts == nullptr) {
-        contexts = gcnew Dictionary<GCHandle, RawContext^>();
-    }
-    if (m_fixedpoint_gch == IntPtr::Zero) {        
-        int id = contexts->Count;
-        GCHandle h = GCHandle::Alloc(id, GCHandleType::Pinned);
-        contexts[h] = this;
-        m_fixedpoint_gch = GCHandle::ToIntPtr(h);        
-        Z3_fixedpoint_init(ctx(), dl(), m_fixedpoint_gch.ToPointer());    
-        Z3_fixedpoint_set_reduce_assign_callback(ctx(), dl(), ::fixedpoint_assign_callback);
-        Z3_fixedpoint_set_reduce_app_callback(ctx(), dl(), ::fixedpoint_apply_callback);
-    }
-}
-
-
-void RawContext::fixedpoint_assign_callback(void* ud, Z3_func_decl f, unsigned n, Z3_ast const* args, unsigned m, Z3_ast const* outs) {
-    RawContext^ ctx = contexts[GCHandle::FromIntPtr(IntPtr(ud))];
-    if (ctx->m_fixedpoint_assign != nullptr) {
-        array<TermPtr>^ _args = MkArray(n, args);
-        array<TermPtr>^ _outs = MkArray(m, outs);
-        ctx->m_fixedpoint_assign(TermPtr(f), _args, _outs);
-    }
-}
-
-void RawContext::fixedpoint_apply_callback(void* ud, Z3_func_decl f, unsigned n, Z3_ast const* args, Z3_ast* out) {
-    RawContext^ ctx = contexts[GCHandle::FromIntPtr(IntPtr(ud))];
-    if (ctx->m_fixedpoint_apply != nullptr) {
-        array<TermPtr>^ _args = MkArray(n, args);
-        TermPtr r = ctx->m_fixedpoint_apply(TermPtr(f), _args);
-        if (out) *out = get_ast(r);
-    }    
-}
-
-String^ RawContext::FixedpointToString(array<TermPtr>^ queries) {
-    scoped_Z3_ast_array<Z3_ast> _queries(queries);
-    return gcnew String(Z3_fixedpoint_to_string(
-                            ctx(), dl(), 
-                            _queries.size(), _queries.c_ptr()));
-}
-
-array<TermPtr>^ RawContext::SimplifyFixedpointRules(array<TermPtr>^ rules, array<FuncDeclPtr>^ output_predicates) {
-    scoped_Z3_ast_array<Z3_ast> _rules(rules);
-    scoped_Z3_ast_array<Z3_func_decl> _outputs(output_predicates);
-    Z3_ast_vector new_rules = Z3_fixedpoint_simplify_rules(
-        ctx(), dl(), _rules.size(), _rules.c_ptr(), 
-        _outputs.size(), _outputs.c_ptr());
-    unsigned num_rules = Z3_ast_vector_size(ctx(), new_rules);
-    Z3_ast_vector_inc_ref(ctx(), new_rules);
-    array<TermPtr>^ result = gcnew array<TermPtr>(num_rules);
-    for (unsigned i = 0; i < num_rules; ++i) {
-        result[i] = TermPtr(Z3_ast_vector_get(ctx(), new_rules, i));
-    }
-    Z3_ast_vector_dec_ref(ctx(), new_rules);
-    return result;
-}
-
-//----------------------------------------
-// RawContext
-
-static void error_handler(Z3_context ctx, Z3_error_code c) {
-    ErrorCode code;
-    switch(c) {
-    case Z3_OK: code = ErrorCode::Ok; break;
-    case Z3_SORT_ERROR: code = ErrorCode::TypeError; break;
-    case Z3_IOB: code = ErrorCode::IndexOutOfBounds; break;
-    case Z3_INVALID_ARG: code = ErrorCode::InvalidArgument; break;
-    case Z3_PARSER_ERROR: code = ErrorCode::ParserError; break;
-    case Z3_NO_PARSER: code = ErrorCode::NoParser; break;
-    case Z3_INVALID_PATTERN: code = ErrorCode::InvalidPattern; break;
-    case Z3_MEMOUT_FAIL: throw gcnew OutOfMemoryException();
-    case Z3_INTERNAL_FATAL: code = ErrorCode::InternalFatal; break;
-    case Z3_INVALID_USAGE: code = ErrorCode::InvalidUsage; break;
-    case Z3_FILE_ACCESS_ERROR: code = ErrorCode::FileAccessError; break;
-    default:
-        UNREACHABLE();
-        code = ErrorCode::InvalidArgument; break;
-    }
-    if (RawContext::m_error_handler ) {
-        RawContext::m_error_handler->Handler(code);
-    }
-    // we throw if you don't
-    throw gcnew Z3Error(code);
-}
-
-
-// -----------------------------
-// LabeledLiterals
-
-
-LabeledLiterals::!LabeledLiterals() { 
-    if (m_labels) {
-        if (RawContext::m_error_handler ) {
-            RawContext::m_error_handler->Handler(ErrorCode::NonDisposedLiterals);
-        }
-        else {
-            verbose_stream() << "WARNING: labeled literals have not been disposed\n"; 
-        }
-    }
-}
-
-// -----------------------------
-// RawTheory
-
-void RawTheory::static_delete_callback(Z3_theory th)
-{
-    RawTheory^ theory = GetTheory(th);
-    if (theory->delete_handler) {
-        theory->delete_handler();
-    }
-    Z3_theory_data td = Z3_theory_get_ext_data(th);
-    theories->Remove(GCHandle::FromIntPtr(IntPtr(td)));
-    GCHandle::FromIntPtr(IntPtr(td)).Free();
-}
-
-static void static_delete_callback(Z3_theory th) {
-    RawTheory::static_delete_callback(th);
-}
-
-RawTheory::RawTheory(ref_context& ctx, String^ name): m_context(ctx), m_name(name)
-{
-    if (!theories) theories = gcnew Dictionary<GCHandle, RawTheory^>();
-    int id = theories->Count;
-    GCHandle h = GCHandle::Alloc(id, GCHandleType::Pinned);
-    theories[h] = this;
-    IntPtr gch = GCHandle::ToIntPtr(h);
-    m_theory = Z3_mk_theory(ctx(), CreateString(name).c_str(), gch.ToPointer());
-    m_context.inc_ref();
-    Z3_set_delete_callback(m_theory, ::static_delete_callback);
-}
-
-RawTheory::~RawTheory() {
-    m_context.dec_ref();
-}
-
-Z3_bool RawTheory::reduce_eq_callback(Z3_theory th, Z3_ast a, Z3_ast b, Z3_ast* r) {
-    RawTheory^ theory = GetTheory(th);
-    TermPtr res = theory->reduce_eq(TermPtr(a), TermPtr(b));
-    if (res != TermPtr::Zero) {
-        *r = get_ast(res);
-    }
-    return res != TermPtr::Zero;
-}
-
-static Z3_bool reduce_eq_callback(Z3_theory th, Z3_ast a, Z3_ast b, Z3_ast* r) {
-    return RawTheory::reduce_eq_callback(th, a, b, r);
-}
-
-void RawTheory::set_reduce_eq(Func2<TermPtr, TermPtr, TermPtr>^ value) {
-    reduce_eq = value;
-    Z3_set_reduce_eq_callback(m_theory, ::reduce_eq_callback);
-}
-
-Z3_bool RawTheory::reduce_app_callback(Z3_theory th, Z3_func_decl f, unsigned num_args, Z3_ast const args[], Z3_ast* r) {
-    RawTheory^ theory = GetTheory(th);
-    array<TermPtr>^ argv = MkArray(num_args, args);
-    TermPtr res = theory->reduce_app(TermPtr(f), argv);
-    if (r && res != TermPtr::Zero) {
-        *r = get_ast(res);
-    }
-    return res != TermPtr::Zero;
-}
-
-static Z3_bool reduce_app_callback(Z3_theory th, Z3_func_decl f, unsigned num_args, Z3_ast const args[], Z3_ast* r) {
-    return RawTheory::reduce_app_callback(th, f, num_args, args, r);
-}
-
-void RawTheory::set_reduce_app(Func2<FuncDeclPtr, array<TermPtr>^, TermPtr>^ value) {
-    reduce_app = value;
-    Z3_set_reduce_app_callback(m_theory, ::reduce_app_callback);
-}
-
-Z3_bool RawTheory::reduce_distinct_callback(Z3_theory th, unsigned n, Z3_ast const args[], Z3_ast* r) {
-    RawTheory^ theory = GetTheory(th);
-    TermPtr res = theory->reduce_distinct(MkArray(n, args));
-    if (r && res != TermPtr::Zero) {
-        *r = get_ast(res);
-    }
-    return res != TermPtr::Zero;
-}
-
-static Z3_bool reduce_distinct_callback(Z3_theory th, unsigned n, Z3_ast const args[], Z3_ast* r) {
-    return RawTheory::reduce_distinct_callback(th, n, args, r);
-}
-
-void RawTheory::set_reduce_distinct(Func1<array<TermPtr>^, TermPtr>^ value) {
-    reduce_distinct = value;
-    Z3_set_reduce_distinct_callback(m_theory, ::reduce_distinct_callback);
-}
-
-static void new_relevant_callback(Z3_theory t, Z3_ast a) {
-    RawTheory::GetTheory(t)->new_relevant(TermPtr(a));
-}
-
-void RawTheory::set_new_relevant(Action<TermPtr>^ value) {
-    new_relevant = value;
-    Z3_set_new_relevant_callback(m_theory, ::new_relevant_callback);
-}
-
-static void new_app_callback(Z3_theory t, Z3_ast a) {
-    RawTheory::GetTheory(t)->new_app(TermPtr(a));
-}
-
-void RawTheory::set_new_app(Action<TermPtr>^ value) {
-    new_app = value;
-    Z3_set_new_app_callback(m_theory, ::new_app_callback);
-}
-
-
-static void new_elem_callback(Z3_theory t, Z3_ast a) {
-    RawTheory::GetTheory(t)->new_elem(TermPtr(a));
-}
-
-void RawTheory::set_new_elem(Action<TermPtr>^ value) {
-    new_elem = value;
-    Z3_set_new_elem_callback(m_theory, ::new_elem_callback);
-}
-
-static void init_search_callback(Z3_theory t) {
-    RawTheory::GetTheory(t)->init_search();
-}
-
-void RawTheory::set_init_search(Action0^ value) {
-    init_search = value;
-    Z3_set_init_search_callback(m_theory, ::init_search_callback);
-}
-
-static void push_callback(Z3_theory t) {
-    RawTheory::GetTheory(t)->push();
-}
-
-void RawTheory::set_push(Action0^ value) {
-    push = value;
-    Z3_set_push_callback(m_theory, ::push_callback);
-}
-
-
-static void pop_callback(Z3_theory t) {
-    RawTheory::GetTheory(t)->pop();
-}
-
-void RawTheory::set_pop(Action0^ value) {
-    pop = value;
-    Z3_set_pop_callback(m_theory, ::pop_callback);
-}
-
-
-static void reset_callback(Z3_theory t) {
-    RawTheory::GetTheory(t)->reset();
-}
-
-void RawTheory::set_reset(Action0^ value) {
-    reset = value;
-    Z3_set_reset_callback(m_theory, ::reset_callback);
-}
-
-
-static void restart_callback(Z3_theory t) {
-    RawTheory::GetTheory(t)->restart();
-}
-
-void RawTheory::set_restart(Action0^ value) {
-    restart = value;
-    Z3_set_restart_callback(m_theory, ::restart_callback);
-}
-
-
-static Z3_bool final_check_callback(Z3_theory t) {
-    return RawTheory::GetTheory(t)->final_check();
-}
-
-void RawTheory::set_final_check(Func0<bool>^ value) {
-    final_check = value;
-    Z3_set_final_check_callback(m_theory, ::final_check_callback);
-}
-
-static void new_eq_callback(Z3_theory t, Z3_ast a, Z3_ast b) {
-    RawTheory::GetTheory(t)->new_eq(TermPtr(a), TermPtr(b));
-}
-
-void RawTheory::set_new_eq(Action2<TermPtr, TermPtr>^ value) {
-    new_eq = value;
-    Z3_set_new_eq_callback(m_theory, ::new_eq_callback);
-}
-
-
-static void new_diseq_callback(Z3_theory t, Z3_ast a, Z3_ast b) {
-    RawTheory::GetTheory(t)->new_diseq(TermPtr(a), TermPtr(b));
-}
-
-void RawTheory::set_new_diseq(Action2<TermPtr, TermPtr>^ value) {
-    new_diseq = value;
-    Z3_set_new_diseq_callback(m_theory, ::new_diseq_callback);
-}
-
-static void new_assignment_callback(Z3_theory t, Z3_ast a, Z3_bool b)
-{
-    RawTheory::GetTheory(t)->new_assignment(TermPtr(a), b?true:false);
-}
-
-void RawTheory::set_new_assignment(Action2<TermPtr, bool>^ value) {
-    new_assignment = value;
-    Z3_set_new_assignment_callback(m_theory, ::new_assignment_callback);
-}
-
-FuncDeclPtr RawTheory::MkFuncDecl(Symbol^ n, array<SortPtr>^ domain, SortPtr range) {
-    scoped_Z3_ast_array<Z3_sort> _domain(domain);
-    return FuncDeclPtr(Z3_theory_mk_func_decl(m_context(), m_theory, n->get(), 
-                                              _domain.size(), _domain.c_ptr(), get_sort(range)));
-}
-
-
-SortPtr RawTheory::MkSort(String^ s) {
-    return SortPtr(Z3_theory_mk_sort(m_context(), m_theory, Z3_mk_string_symbol(m_context(), CreateString(s).c_str())));
-}
-        
-TermPtr RawTheory::MkValue(String^ s, SortPtr srt) {
-    Z3_symbol sym = Z3_mk_string_symbol(m_context(), CreateString(s).c_str());
-    return TermPtr(Z3_theory_mk_value(m_context(), m_theory, sym, get_sort(srt)));
-}
-
-TermPtr RawTheory::MkConstant(String^ s, SortPtr srt) {
-    Z3_symbol sym = Z3_mk_string_symbol(m_context(), CreateString(s).c_str());
-    return TermPtr(Z3_theory_mk_constant(m_context(), m_theory, sym, get_sort(srt)));
-}
-
-FuncDeclPtr RawTheory::MkFuncDecl(String^ s, array<SortPtr>^ domain, SortPtr range) {
-    Z3_symbol sym = Z3_mk_string_symbol(m_context(), CreateString(s).c_str());
-    scoped_Z3_ast_array<Z3_sort> _domain(domain);
-    return FuncDeclPtr(Z3_theory_mk_func_decl(m_context(), m_theory, sym, 
-                                              _domain.size(), _domain.c_ptr(), get_sort(range)));
-
-}
-
-
-// -----------------------------
-// Constructor
-
-Constructor::Constructor(
-    ref_context& context,
-    String^ name,
-    String^ tester,
-    array<String^>^  field_names,
-    array<SortPtr>^  field_sorts,
-    array<unsigned>^ field_refs
-    ): 
-    m_context(context),
-    m_constructor(0),
-    m_name(name),
-    m_tester_name(tester),
-    m_field_names(field_names),
-    m_field_sorts(field_sorts),
-    m_field_refs(field_refs),
-    m_constructor_decl(FuncDeclPtr()),
-    m_tester(FuncDeclPtr()),
-    m_accessors(nullptr)
-{
-    m_context.inc_ref();
-}
-
-
-Z3_constructor Constructor::Get() 
-{
-    if (m_constructor) {
-        return m_constructor;
-    }
-    Z3_symbol _name = Z3_mk_string_symbol(m_context(), CreateString(m_name).c_str());
-    Z3_symbol _tester = Z3_mk_string_symbol(m_context(), CreateString(m_tester_name).c_str());
-    unsigned num_fields = (!m_field_names)?0:m_field_names->Length;
-    scoped_Z3_symbol_array _field_names(m_context(), m_field_names); 
-    scoped_Z3_ast_array<Z3_sort> _field_sorts(m_field_sorts);
-    scoped_array<unsigned> _field_refs(m_field_refs);
-    SASSERT(_field_names.size() == _field_sorts.size());
-    SASSERT(_field_names.size() == _field_refs.size());
-    m_constructor = Z3_mk_constructor(m_context(), _name, _tester, num_fields, 
-                                      _field_names.c_ptr(), _field_sorts.c_ptr(), _field_refs.c_ptr());
-    return m_constructor;
-}
-
-Z3_constructor Constructor::Query() {
-    Z3_constructor result = 0;
-    if (!m_accessors) {
-        SASSERT(m_constructor);
-        result = m_constructor;
-        unsigned num_fields = (!m_field_names)?0:m_field_names->Length;
-        m_accessors = gcnew array<FuncDeclPtr>(num_fields);
-        Z3_func_decl constructor_decl, tester_decl;
-        scoped_array<Z3_func_decl> accs(num_fields);
-        Z3_query_constructor(m_context(), 
-                             m_constructor,
-                             num_fields,
-                             &constructor_decl,
-                             &tester_decl,
-                             accs.c_ptr());
-        m_constructor_decl = FuncDeclPtr(constructor_decl);
-        m_tester = FuncDeclPtr(tester_decl);
-        for (unsigned i = 0; i < num_fields; ++i) {
-            m_accessors[i] = FuncDeclPtr(accs[i]);
-        }
-        m_constructor = 0;
-    }
-    SASSERT(!m_constructor);
-    return result;
-}
-
-Constructor::!Constructor() {
-    SASSERT(!m_constructor);
-}
-
-
-Constructor::~Constructor() {
-    SASSERT(!m_constructor); 
-    m_context.dec_ref();
-}
-
-
-FuncDeclPtr Constructor::GetConstructor() {
-    if (!m_constructor && !m_accessors) {
-        throw gcnew Z3Error(ErrorCode::InvalidUsage);
-    }
-    Z3_constructor c = Query();
-    SASSERT(!c);
-    return FuncDeclPtr(m_constructor_decl);
-}
-
-FuncDeclPtr Constructor::GetTester() {
-    if (!m_constructor && !m_accessors) {
-        throw gcnew Z3Error(ErrorCode::InvalidUsage);
-    }
-    Z3_constructor c = Query();
-    SASSERT(!c);
-    return FuncDeclPtr(m_tester);
-}
-
-array<FuncDeclPtr>^ Constructor::GetAccessors() {
-    if (!m_constructor && !m_accessors) {
-        throw gcnew Z3Error(ErrorCode::InvalidUsage);
-    }
-    Z3_constructor c = Query();
-    SASSERT(!c);
-    return m_accessors;
-}
-
-
-
-
-// -----------------------------
-// RawContext
-
-
-void RawContext::Init() {
-    m_disposed = false;
-    s_nonempty = false;
-    if (s_todec == nullptr) {
-        s_todec = gcnew List<KeyValuePair<IntPtr, RawContext^> >();
-        s_monitor = gcnew IntPtr(0);
-    }
-    Z3_set_error_handler(ctx(), error_handler);
-}
-
-RawContext::RawContext(Config^ config) { 
-    m_context = ref_context::mk(Z3_mk_context(config->get()), true, true);
-    Init();
-}
-
-RawContext::RawContext(Config^ config, ReferenceCounted^ rc) { 
-    m_context = ref_context::mk(Z3_mk_context_rc(config->get()), true, false); 
-    Init();
-}
-
-RawContext::RawContext() {
-    m_context = ref_context::mk(Z3_mk_context(0), true, true);
-    Init();
-}
-
-void RawContext::SetContext(Z3_context ctx) {
-    Reset();
-    m_context = ref_context::mk(ctx, false, true);
-}
-
-RawContext::!RawContext() { 
-    if (!m_disposed) {
-        if (RawContext::m_error_handler ) {
-            RawContext::m_error_handler->Handler(ErrorCode::NonDisposedContext);
-        }
-        else {
-            verbose_stream() << "WARNING: context was not disposed\n";
-        }
-    }
-}
-
-
-void
-RawContext::Reset() {
-    System::Threading::Monitor::Enter(s_monitor);
-    if (!m_disposed) {
-        m_context->dec_ref();
-        m_disposed = true;
-    } 
-    System::Threading::Monitor::Exit(s_monitor);
-}
-
-RawContext::~RawContext() { 
-    Reset();
-}
-
-#include "..\lib\vector.h"
-#include "..\lib\trace.h"
-
-void RawContext::EnableDebugTrace(String^ tag) {
-    static vector<std::string*> pinned;
-    std::string s = CreateString(tag);
-    pinned.push_back(new std::string(s));
-    enable_trace(pinned.back()->c_str());
-}
-
-void RawContext::ToggleWarningMessages(bool enabled) {
-    Z3_toggle_warning_messages(enabled);
-}
-
-void RawContext::UpdateParamValue(String^ p, String^ v) {
-    Z3_update_param_value(ctx(), CreateString(p).c_str(), CreateString(v).c_str());
-}
-
-String^ RawContext::GetParamValue(String^ p) {
-    Z3_string vl = "";
-    if (!Z3_get_param_value(ctx(), CreateString(p).c_str(), &vl)) {
-        throw gcnew Z3Error(ErrorCode::InvalidArgument);
-    }
-    return gcnew String(vl);
-}
-
-bool RawContext::SetLogic(String^ l) {
-    return Z3_TRUE == Z3_set_logic(ctx(), CreateString(l).c_str());
-}
-
-Symbol^ RawContext::MkSymbol(String^ s) {    
-    return gcnew Symbol(ctx(), Z3_mk_string_symbol(ctx(), CreateString(s).c_str()));
-}
-Symbol^ RawContext::MkSymbol(int i) { 
-    return gcnew Symbol(ctx(), Z3_mk_int_symbol(ctx(), i)); 
-}        
-
-SortPtr RawContext::MkSort(Symbol^ s) {
-    return SortPtr(Z3_mk_uninterpreted_sort(ctx(), s->get()));
-}
-
-SortPtr RawContext::MkSort(String^ s) {
-    return SortPtr(Z3_mk_uninterpreted_sort(ctx(), Z3_mk_string_symbol(ctx(), CreateString(s).c_str())));
-}
-
-SortPtr RawContext::MkSort(int i) {
-    return SortPtr(Z3_mk_uninterpreted_sort(ctx(), Z3_mk_int_symbol(ctx(), i)));
-}
-
-SortPtr RawContext::MkBoolSort() { return SortPtr(Z3_mk_bool_sort(ctx())); }
-
-SortPtr RawContext::MkIntSort() { return SortPtr(Z3_mk_int_sort(ctx())); }
-
-SortPtr RawContext::MkRealSort() { return SortPtr(Z3_mk_real_sort(ctx())); }
-
-SortPtr RawContext::MkBvSort(unsigned sz) { return SortPtr(Z3_mk_bv_sort(ctx(), sz)); }
-
-SortPtr RawContext::MkArraySort(SortPtr domain, SortPtr range) {
-    return SortPtr(Z3_mk_array_sort(ctx(), get_sort(domain), get_sort(range)));
-}
-
-SortPtr RawContext::MkFiniteDomainSort(String^ s, unsigned __int64 domain_size) {
-    return SortPtr(Z3_mk_finite_domain_sort(ctx(), Z3_mk_string_symbol(ctx(), CreateString(s).c_str()), domain_size));
-}
-
-SortPtr RawContext::MkTupleSort(
-    Symbol^             mk_tuple_name, 
-    array<Symbol^>^     field_names,
-    array<SortPtr>^     field_types,
-    FuncDeclPtr%        mk_tuple_decl,
-    array<FuncDeclPtr>^ proj_decls
-    )
-{
-    if (!field_names ||
-        !field_types ||
-        !proj_decls ||
-        field_names->Length != field_types->Length ||
-        field_names->Length != proj_decls->Length) {
-        throw gcnew Z3Error(ErrorCode::InvalidArgument);
-    }
-    scoped_Z3_symbol_array syms(field_names);
-    scoped_Z3_ast_array<Z3_sort> types(field_types);
-    scoped_Z3_ast_array<Z3_func_decl> projs(field_names->Length);
-    Z3_func_decl decl;
-
-    Z3_sort ty = 
-        Z3_mk_tuple_sort(
-            ctx(), 
-            mk_tuple_name->get(),
-            syms.size(),
-            syms.c_ptr(),
-            types.c_ptr(),
-            &decl,
-            projs.c_ptr()
-            );
-   
-    mk_tuple_decl = FuncDeclPtr(decl);
-    CopyFuncDecl(projs, proj_decls);
-    return SortPtr(ty);
-}
-
-SortPtr RawContext::MkTupleSort(
-    String^              mk_tuple_name, 
-    array<String^>^      field_names,
-    array<SortPtr>^      field_types,
-    FuncDeclPtr%         mk_tuple_decl,
-    array<FuncDeclPtr>^  proj_decls
-    )
-{
-    Symbol^ tn = MkSymbol(mk_tuple_name);
-    array<Symbol^>^ fields = gcnew array<Symbol^>(field_names->Length);
-    for (int i = 0; i < fields->Length; ++i) {
-        fields[i] = MkSymbol(field_names[i]);
-    }
-    return MkTupleSort(tn, fields, field_types, mk_tuple_decl, proj_decls);
-    
-}
-
-SortPtr RawContext::MkEnumerationSort(
-    String^             name,
-    array<String^>^     enum_names,
-    array<FuncDeclPtr>^ enum_consts,
-    array<FuncDeclPtr>^ enum_testers) {
-    
-    Z3_symbol _name(Z3_mk_string_symbol(ctx(), CreateString(name).c_str()));
-    scoped_Z3_symbol_array _enum_names(ctx(), enum_names); 
-    scoped_Z3_ast_array<Z3_func_decl> _enum_consts(enum_consts);
-    scoped_Z3_ast_array<Z3_func_decl> _enum_testers(enum_testers);
-    unsigned sz = _enum_names.size();
-    SASSERT(sz == _enum_consts.size());
-    SASSERT(sz == _enum_testers.size());
-    Z3_sort s = Z3_mk_enumeration_sort(ctx(), _name, sz, _enum_names.c_ptr(), _enum_consts.c_ptr(), _enum_testers.c_ptr());
-    CopyFuncDecl(_enum_consts, enum_consts);
-    CopyFuncDecl(_enum_testers, enum_testers);
-    return SortPtr(s);
-}
-
-SortPtr RawContext::MkListSort(
-    String^ name,
-    SortPtr elem_sort,
-    FuncDeclPtr% nil_decl,
-    FuncDeclPtr% is_nil_decl,
-    FuncDeclPtr% cons_decl,
-    FuncDeclPtr% is_cons_decl,
-    FuncDeclPtr% head_decl,
-    FuncDeclPtr% tail_decl
-    )
-{
-    Z3_func_decl _nil_decl, _is_nil_decl, _cons_decl, _is_cons_decl, _head_decl, _tail_decl;
-    Z3_symbol _name = Z3_mk_string_symbol(ctx(), CreateString(name).c_str());
-    Z3_sort _elem_sort = get_sort(elem_sort);
-    
-    Z3_sort s = Z3_mk_list_sort(ctx(), _name, _elem_sort, 
-                                &_nil_decl, &_is_nil_decl, &_cons_decl,
-                                &_is_cons_decl, &_head_decl, &_tail_decl);
-
-    is_nil_decl  = FuncDeclPtr(_is_nil_decl);
-    nil_decl     = FuncDeclPtr(_nil_decl);
-    is_cons_decl = FuncDeclPtr(_is_cons_decl);
-    cons_decl    = FuncDeclPtr(_cons_decl);
-    head_decl    = FuncDeclPtr(_head_decl);
-    tail_decl    = FuncDeclPtr(_tail_decl);
-    return SortPtr(s);
-}
-
-
-
-Constructor^ RawContext::MkConstructor(
-    String^ name,
-    String^ tester,
-    array<String^>^  field_names,
-    array<SortPtr>^  field_sorts,
-    array<unsigned>^ field_refs
-    )
-{
-
-    int l1 = (!field_names)?0:field_names->Length;
-    int l2 = (!field_sorts)?0:field_sorts->Length;
-    int l3 = (!field_refs)?0:field_refs->Length;
-    if (l1 != l2 || l1 != l3) {
-        throw gcnew Z3Error(ErrorCode::InvalidArgument);
-    }
-    return gcnew Constructor(*m_context, name, tester, 
-                             field_names, field_sorts, field_refs);
-}
-
-
-SortPtr RawContext::MkDataType(
-    String^ name,
-    array<Constructor^>^ constructors
-    )
-{
-    Z3_symbol _name = Z3_mk_string_symbol(ctx(), CreateString(name).c_str());
-    scoped_array<Z3_constructor> _cons(constructors->Length);
-    for (int i = 0; i < constructors->Length; ++i) {
-        _cons[i] = constructors[i]->Get();
-    }
-    Z3_sort s = Z3_mk_datatype(ctx(), _name, _cons.size(), _cons.c_ptr());
-    for (int i = 0; i < constructors->Length; ++i) {
-        Z3_constructor c = constructors[i]->Query();        
-        Z3_del_constructor(ctx(), c);
-    }
-    return SortPtr(s);
-}
-
-array<SortPtr>^ RawContext::MkDataTypes(
-    array<String^>^ names,
-    array<array<Constructor^>^>^ constructors_list
-    )
-{
-    if (!names ||
-        !constructors_list || 
-        names->Length != constructors_list->Length) {
-        throw gcnew Z3Error(ErrorCode::InvalidArgument);
-
-    }
-    unsigned num_sorts = names->Length;
-    scoped_array<Z3_symbol> sort_names(num_sorts);
-    scoped_array<Z3_constructor_list> clist(num_sorts);
-    scoped_array<Z3_sort> sort_sorts(num_sorts);
-    array<SortPtr>^ result = gcnew array<SortPtr>(num_sorts);
-    unsigned num_constructors = 0;
-    for (unsigned j = 0; j < num_sorts; ++j) {
-        num_constructors += constructors_list[j]->Length;
-    }
-    scoped_array<Z3_constructor> constructor_vec(num_constructors);
-    svector<Z3_constructor> constructors_q;
-    unsigned constructor_idx = 0;
-    
-    for (unsigned j = 0; j < num_sorts; ++j) {
-        String^ name = names[j];
-        array<Constructor^>^ constructors = constructors_list[j];        
-        
-        // add sort name
-        Z3_symbol _name = Z3_mk_string_symbol(ctx(), CreateString(name).c_str());
-        sort_names[j] = _name;
-
-        // create constructor_list
-        scoped_array<Z3_constructor> _cons(constructors->Length);
-        for (int i = 0; i < constructors->Length; ++i) {
-            _cons[i] = constructors[i]->Get();
-            constructor_vec[constructor_idx++] = _cons[i];
-        }
-        Z3_constructor_list cl = Z3_mk_constructor_list(ctx(), _cons.size(), _cons.c_ptr());
-        clist[j] = cl;        
-    }
-    Z3_mk_datatypes(ctx(), num_sorts, sort_names.c_ptr(), sort_sorts.c_ptr(), clist.c_ptr());
-
-    for (unsigned j = 0; j < num_sorts; ++j) {
-        Z3_del_constructor_list(ctx(), clist[j]);
-        result[j] = SortPtr(sort_sorts[j]);
-        // populate the constructors
-        array<Constructor^>^ constructors = constructors_list[j];        
-        for (int i = 0; i < constructors->Length; ++i) {
-            constructors_q.push_back(constructors[i]->Query());
-        }
-    }
-    for (unsigned i = 0; i < constructors_q.size(); ++i) {
-        Z3_constructor c = constructors_q[i];
-        if (c) {
-            Z3_del_constructor(ctx(), c);
-        }
-    }
-    return result;
-}
-
-
-
-FuncDeclPtr RawContext::MkFuncDecl(Symbol^ s, array<SortPtr>^ domain, SortPtr range) {
-    scoped_Z3_ast_array<Z3_sort> types(domain);
-    return FuncDeclPtr(Z3_mk_func_decl(ctx(), s->get(), types.size(), types.c_ptr(), get_sort(range))); 
-}
-
-FuncDeclPtr RawContext::MkFuncDecl(String^ s, array<SortPtr>^ domain, SortPtr range) {
-    scoped_Z3_ast_array<Z3_sort> types(domain);
-    Z3_symbol sym = Z3_mk_string_symbol(ctx(), CreateString(s).c_str());
-    return FuncDeclPtr(Z3_mk_func_decl(ctx(), sym, types.size(), types.c_ptr(), get_sort(range))); 
-}
-
-FuncDeclPtr RawContext::MkFuncDecl(Symbol^ s, SortPtr domain, SortPtr range) {
-    Z3_sort dom[1] = { get_sort(domain) };
-    return FuncDeclPtr(Z3_mk_func_decl(ctx(), s->get(), 1, dom, get_sort(range))); 
-}
-
-FuncDeclPtr RawContext::MkFuncDecl(Symbol^ s, SortPtr d1, SortPtr d2, SortPtr range) {
-    Z3_sort dom[2] = { get_sort(d1), get_sort(d2) };
-    return FuncDeclPtr(Z3_mk_func_decl(ctx(), s->get(), 2, dom, get_sort(range))); 
-}
-
-FuncDeclPtr RawContext::MkFuncDecl(String^ s, SortPtr domain, SortPtr range) {
-    Z3_sort dom[1] = { get_sort(domain) };
-    Z3_symbol sym = Z3_mk_string_symbol(ctx(), CreateString(s).c_str());
-    return FuncDeclPtr(Z3_mk_func_decl(ctx(), sym, 1, dom, get_sort(range))); 
-}
-
-FuncDeclPtr RawContext::MkFuncDecl(String^ s, SortPtr d1, SortPtr d2, SortPtr range) {
-    Z3_symbol sym = Z3_mk_string_symbol(ctx(), CreateString(s).c_str());
-    Z3_sort dom[2] = { get_sort(d1), get_sort(d2) };
-    return FuncDeclPtr(Z3_mk_func_decl(ctx(), sym, 2, dom, get_sort(range))); 
-}
-
-TermPtr RawContext::MkApp(FuncDeclPtr d, array<TermPtr>^ args) {
-    scoped_Z3_ast_array<Z3_ast> z3_args(args);
-    return TermPtr(Z3_mk_app(ctx(), get_func_decl(d), z3_args.size(), z3_args.c_ptr()));
-}
-
-TermPtr RawContext::MkApp(FuncDeclPtr d, TermPtr arg) {
-    Z3_ast args[1] = { get_ast(arg) };
-    return TermPtr(Z3_mk_app(ctx(), get_func_decl(d), 1, args));
-}
-
-TermPtr RawContext::MkApp(FuncDeclPtr d, TermPtr arg1, TermPtr arg2) {
-    Z3_ast args[2] = { get_ast(arg1), get_ast(arg2) };
-    return TermPtr(Z3_mk_app(ctx(), get_func_decl(d), 2, args));
-}
-
-TermPtr RawContext::MkApp(FuncDeclPtr d, TermPtr arg1, TermPtr arg2, TermPtr arg3) {
-    Z3_ast args[3] = { get_ast(arg1), get_ast(arg2), get_ast(arg3) };
-    return TermPtr(Z3_mk_app(ctx(), get_func_decl(d), 3, args));
-}
-
-
-TermPtr RawContext::MkConst(FuncDeclPtr d) {
-    return TermPtr(Z3_mk_app(ctx(),get_func_decl(d), 0, 0));
-}
-
-TermPtr RawContext::MkConst(String^ s, SortPtr ty) {
-    Z3_symbol sym = Z3_mk_string_symbol(ctx(),CreateString(s).c_str());
-    Z3_func_decl d = Z3_mk_func_decl(ctx(), sym, 0, 0, get_sort(ty));
-    return TermPtr(Z3_mk_app(ctx(), d, 0, 0));
-}
-
-TermPtr RawContext::MkConst(Symbol^ s, SortPtr ty) {
-    Z3_func_decl d = Z3_mk_func_decl(ctx(), s->get(), 0, 0, get_sort(ty));
-    return TermPtr(Z3_mk_app(ctx(), d, 0, 0));
-}
-
-FuncDeclPtr RawContext::MkFreshFuncDecl(String^ prefix, array<SortPtr>^ domain, SortPtr range) {
-    scoped_Z3_ast_array<Z3_sort> types(domain);
-    return FuncDeclPtr(Z3_mk_fresh_func_decl(ctx(), CreateString(prefix).c_str(), types.size(), types.c_ptr(), get_sort(range))); 
-}
-
-TermPtr RawContext::MkFreshConst(String^ prefix, SortPtr ty) {
-    return TermPtr(Z3_mk_fresh_const(ctx(), CreateString(prefix).c_str(), get_sort(ty))); 
-}
-
-TermPtr RawContext::MkLabel(Symbol^ name, bool pos, TermPtr fml) {
-    return TermPtr(Z3_mk_label(ctx(), name->get(), pos, get_ast(fml)));
-}
-
-
-TermPtr RawContext::MkEq(TermPtr l, TermPtr r) {
-    return TermPtr(Z3_mk_eq(ctx(), get_ast(l), get_ast(r)));
-}
-
-TermPtr RawContext::MkDistinct(array<TermPtr>^ _args) {
-    scoped_Z3_ast_array<Z3_ast> args(_args);
-    return TermPtr(Z3_mk_distinct(ctx(), args.size(), args.c_ptr()));
-}
-
-TermPtr RawContext::MkNot(TermPtr arg) {
-    return TermPtr(Z3_mk_not(ctx(), get_ast(arg)));
-}
-    
-TermPtr RawContext::MkIte(TermPtr t1, TermPtr t2, TermPtr t3) {
-    return TermPtr(Z3_mk_ite(ctx(), get_ast(t1), get_ast(t2), get_ast(t3)));
-}
-
-#define MK_BINARY(fn, t1, t2) return TermPtr(Z3_mk_ ## fn (ctx(), get_ast(t1), get_ast(t2)))
-
-#define MK_UNARY(fn, t1) return TermPtr(Z3_mk_ ## fn (ctx(), get_ast(t1)))
-
-#define MK_NARY(fn, _args_) { scoped_Z3_ast_array<Z3_ast> my_args(_args_); return TermPtr(Z3_mk_ ## fn (ctx(), my_args.size(), my_args.c_ptr())); }
-
-TermPtr RawContext::MkIff(TermPtr t1, TermPtr t2) {
-    MK_BINARY(iff, t1, t2);
-}
-
-TermPtr RawContext::MkImplies(TermPtr t1, TermPtr t2) {
-    MK_BINARY(implies, t1, t2);
-}
-    
-TermPtr RawContext::MkXor(TermPtr t1, TermPtr t2) {
-    MK_BINARY(xor, t1, t2);
-}
-    
-TermPtr RawContext::MkAnd(array<TermPtr>^ args) {
-    MK_NARY(and, args);
-}
-
-TermPtr RawContext::MkAnd(TermPtr arg1, TermPtr arg2) {
-    Z3_ast args[2] = { get_ast(arg1), get_ast(arg2) };
-    return TermPtr(Z3_mk_and(ctx(), 2, args));
-}
-    
-TermPtr RawContext::MkOr(array<TermPtr>^ args) {
-    MK_NARY(or, args);
-}
-
-TermPtr RawContext::MkOr(TermPtr arg1, TermPtr arg2) {
-    Z3_ast args[2] = { get_ast(arg1), get_ast(arg2) };
-    return TermPtr(Z3_mk_or(ctx(), 2, args));
-}
-
-TermPtr RawContext::MkAdd(array<TermPtr>^ args) {
-    MK_NARY(add, args);
-}
-
-TermPtr RawContext::MkAdd(TermPtr arg1, TermPtr arg2) {
-    Z3_ast args[2] = { get_ast(arg1), get_ast(arg2) };
-    return TermPtr(Z3_mk_add(ctx(), 2, args));
-}
-
-TermPtr RawContext::MkMul(array<TermPtr>^ args) {
-    MK_NARY(mul, args);
-}
-
-TermPtr RawContext::MkMul(TermPtr arg1, TermPtr arg2) {
-    Z3_ast args[2] = { get_ast(arg1), get_ast(arg2) };
-    return TermPtr(Z3_mk_mul(ctx(), 2, args));
-}
-
-TermPtr RawContext::MkSub(array<TermPtr>^ args) {
-    MK_NARY(sub, args);
-}
-
-TermPtr RawContext::MkSub(TermPtr arg1, TermPtr arg2) {
-    Z3_ast args[2] = { get_ast(arg1), get_ast(arg2) };
-    return TermPtr(Z3_mk_sub(ctx(), 2, args));
-}
-
-TermPtr RawContext::MkUnaryMinus(TermPtr arg) {
-    MK_UNARY(unary_minus, arg);
-}
-
-TermPtr RawContext::MkDiv(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(div, arg1, arg2);
-}
-
-TermPtr RawContext::MkMod(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(mod, arg1, arg2);
-}
-
-TermPtr RawContext::MkRem(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(rem, arg1, arg2);
-}
-
-TermPtr RawContext::MkToReal(TermPtr arg) {
-    MK_UNARY(int2real, arg);
-}
-
-
-TermPtr RawContext::MkToInt(TermPtr arg) {
-    MK_UNARY(real2int, arg);
-}
-
-TermPtr RawContext::MkIsInt(TermPtr arg) {
-    MK_UNARY(is_int, arg);
-}
-
-TermPtr RawContext::MkLt(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(lt, arg1, arg2);
-}
-
-TermPtr RawContext::MkLe(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(le, arg1, arg2);
-}
-
-TermPtr RawContext::MkGt(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(gt, arg1, arg2);    
-}
-
-TermPtr RawContext::MkGe(TermPtr arg1, TermPtr arg2) {
-    MK_BINARY(ge, arg1, arg2);    
-}
-
-TermPtr RawContext::MkBvNot(TermPtr t1) {
-    MK_UNARY(bvnot, t1);
-}
-
-TermPtr RawContext::MkBvReduceAnd(TermPtr t1) {
-    MK_UNARY(bvredand, t1);
-}
-
-TermPtr RawContext::MkBvReduceOr(TermPtr t1) {
-    MK_UNARY(bvredor, t1);
-}
-
-TermPtr RawContext::MkBvAnd(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvand, t1, t2);
-}
-
-TermPtr RawContext::MkBvOr(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvor, t1, t2);
-}
-
-TermPtr RawContext::MkBvXor(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvxor, t1, t2);
-}
-
-TermPtr RawContext::MkBvNand(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvnand, t1, t2);
-}
-
-TermPtr RawContext::MkBvNor(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvnor, t1, t2);
-}
-
-TermPtr RawContext::MkBvXnor(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvxnor, t1, t2);
-}
-
-TermPtr RawContext::MkBvNeg(TermPtr t1) {
-    MK_UNARY(bvneg, t1);
-}
-
-TermPtr RawContext::MkBvAdd(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvadd, t1, t2);
-}
-
-TermPtr RawContext::MkBvSub(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsub, t1, t2);
-}
-    
-TermPtr RawContext::MkBvMul(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvmul, t1, t2);
-}
-
-TermPtr RawContext::MkBvUdiv(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvudiv, t1, t2);
-}
-
-TermPtr RawContext::MkBvSdiv(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsdiv, t1, t2);
-}
-
-TermPtr RawContext::MkBvUrem(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvurem, t1, t2);
-}
-TermPtr RawContext::MkBvSrem(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsrem, t1, t2);
-}
-
-TermPtr RawContext::MkBvSmod(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsmod, t1, t2);
-}
-
-TermPtr RawContext::MkBvUlt(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvult, t1, t2);
-}
-
-TermPtr RawContext::MkBvSlt(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvslt, t1, t2);
-}
-
-TermPtr RawContext::MkBvUle(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvule, t1, t2);
-}
-
-TermPtr RawContext::MkBvSle(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsle, t1, t2);
-}
-
-TermPtr RawContext::MkBvUge(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvuge, t1, t2);
-}
-
-TermPtr RawContext::MkBvSge(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsge, t1, t2);
-}
-
-TermPtr RawContext::MkBvUgt(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvugt, t1, t2);
-}
-
-TermPtr RawContext::MkBvSgt(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvsgt, t1, t2);
-}
-
-TermPtr RawContext::MkBvConcat(TermPtr t1, TermPtr t2) {
-    MK_BINARY(concat, t1, t2);
-}
-    
-TermPtr RawContext::MkBvExtract(unsigned high, unsigned low, TermPtr t) {
-    return TermPtr(Z3_mk_extract(ctx(), high, low, get_ast(t)));
-}
-
-TermPtr RawContext::MkBvSignExt(unsigned i, TermPtr t) {
-    return TermPtr(Z3_mk_sign_ext(ctx(), i, get_ast(t)));
-}
-
-TermPtr RawContext::MkBvZeroExt(unsigned i, TermPtr t) {
-    return TermPtr(Z3_mk_zero_ext(ctx(), i, get_ast(t)));    
-}
-
-TermPtr RawContext::MkBvRepeat(unsigned i, TermPtr t) {
-    return TermPtr(Z3_mk_repeat(ctx(), i, get_ast(t)));    
-}
-
-TermPtr RawContext::MkBvShl(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvshl, t1, t2);
-}
-
-TermPtr RawContext::MkBvLshr(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvlshr, t1, t2);
-}
-
-TermPtr RawContext::MkBvAshr(TermPtr t1, TermPtr t2) {
-    MK_BINARY(bvashr, t1, t2);
-}
-    
-TermPtr RawContext::MkBvRotateLeft(unsigned i, TermPtr t1) {
-    return TermPtr(Z3_mk_rotate_left(ctx(), i, get_ast(t1)));    
-}
-    
-TermPtr RawContext::MkBvRotateRight(unsigned i, TermPtr t1) {
-    return TermPtr(Z3_mk_rotate_right(ctx(), i, get_ast(t1)));    
-}
-
-TermPtr RawContext::MkBvRotateLeft(TermPtr t1, TermPtr t2) {
-    return TermPtr(Z3_mk_ext_rotate_left(ctx(), get_ast(t1), get_ast(t2)));    
-}
-    
-TermPtr RawContext::MkBvRotateRight(TermPtr t1, TermPtr t2) {
-    return TermPtr(Z3_mk_ext_rotate_right(ctx(), get_ast(t1), get_ast(t2)));
-}
-
-TermPtr RawContext::MkInt2Bv(unsigned i, TermPtr t1) {
-    return TermPtr(Z3_mk_int2bv(ctx(), i, get_ast(t1)));    
-}
-
-TermPtr RawContext::MkBv2Int(TermPtr t1, bool is_signed) {
-    return TermPtr(Z3_mk_bv2int(ctx(), get_ast(t1), is_signed));
-}
-
-TermPtr RawContext::MkBvAddNoOverflow(TermPtr t1, TermPtr t2, bool is_signed) {
-    return TermPtr(Z3_mk_bvadd_no_overflow(ctx(), get_ast(t1), get_ast(t2), is_signed));
-}
-
-TermPtr RawContext::MkBvAddNoUnderflow(TermPtr t1, TermPtr t2) {
-    return TermPtr(Z3_mk_bvadd_no_underflow(ctx(), get_ast(t1), get_ast(t2)));
-}
-
-TermPtr RawContext::MkBvSubNoOverflow(TermPtr t1, TermPtr t2) {
-    return TermPtr(Z3_mk_bvsub_no_overflow(ctx(), get_ast(t1), get_ast(t2)));
-}
-
-TermPtr RawContext::MkBvSubNoUnderflow(TermPtr t1, TermPtr t2, bool is_signed) {
-    return TermPtr(Z3_mk_bvsub_no_underflow(ctx(), get_ast(t1), get_ast(t2), is_signed));
-}
-
-TermPtr RawContext::MkBvSDivNoOverflow(TermPtr t1, TermPtr t2) {
-    return TermPtr(Z3_mk_bvsdiv_no_overflow(ctx(), get_ast(t1), get_ast(t2)));
-}
-
-TermPtr RawContext::MkBvNegNoOverflow(TermPtr t1) {
-    return TermPtr(Z3_mk_bvneg_no_overflow(ctx(), get_ast(t1)));
-}
-
-TermPtr RawContext::MkBvMulNoOverflow(TermPtr t1, TermPtr t2, bool is_signed) {
-    return TermPtr(Z3_mk_bvmul_no_overflow(ctx(), get_ast(t1), get_ast(t2), is_signed));
-}
-
-TermPtr RawContext::MkBvMulNoUnderflow(TermPtr t1, TermPtr t2) {
-    return TermPtr(Z3_mk_bvmul_no_underflow(ctx(), get_ast(t1), get_ast(t2)));
-}
-
-TermPtr RawContext::MkArraySelect(TermPtr a, TermPtr i) {
-    return TermPtr(Z3_mk_select(ctx(), get_ast(a), get_ast(i)));
-}
-
-TermPtr RawContext::MkArrayStore(TermPtr a, TermPtr i, TermPtr v) {
-    return TermPtr(Z3_mk_store(ctx(), get_ast(a), get_ast(i), get_ast(v)));
-}
-
-TermPtr RawContext::MkArrayMap(FuncDeclPtr d, array<TermPtr>^ args) {
-    scoped_Z3_ast_array<Z3_ast> _args(args);
-    return TermPtr(Z3_mk_map(ctx(), get_func_decl(d), _args.size(), _args.c_ptr()));
-}
-
-TermPtr RawContext::MkArrayConst(SortPtr domain, TermPtr v) {
-    return TermPtr(Z3_mk_const_array(ctx(), get_sort(domain), get_ast(v)));
-}
-
-TermPtr RawContext::MkArrayDefault(TermPtr a) {
-    return TermPtr(Z3_mk_array_default(ctx(), get_ast(a)));
-}
-
-TermPtr RawContext::MkSetUnion(array<TermPtr>^ sets) {
-    scoped_Z3_ast_array<Z3_ast> _sets(sets);
-    return TermPtr(Z3_mk_set_union(ctx(), _sets.size(), _sets.c_ptr()));
-}
-
-TermPtr RawContext::MkSetUnion(TermPtr set1, TermPtr set2) {
-    Z3_ast args[2] = { get_ast(set1), get_ast(set2) };
-    return TermPtr(Z3_mk_set_union(ctx(), 2, args));
-}
-
-TermPtr RawContext::MkSetIntersect(array<TermPtr>^ sets) {
-    scoped_Z3_ast_array<Z3_ast> _sets(sets);
-    return TermPtr(Z3_mk_set_intersect(ctx(), _sets.size(), _sets.c_ptr()));
-}
-
-TermPtr RawContext::MkSetIntersect(TermPtr set1, TermPtr set2) {
-    Z3_ast args[2] = { get_ast(set1), get_ast(set2) };
-    return TermPtr(Z3_mk_set_intersect(ctx(), 2, args));
-}
-
-FuncDeclPtr RawContext::MkInjectiveFunction(String^ name, array<SortPtr>^ domain, SortPtr range) {
-    scoped_Z3_ast_array<Z3_sort> types(domain);
-    Z3_symbol sym = Z3_mk_string_symbol(ctx(), CreateString(name).c_str());
-    return FuncDeclPtr(Z3_mk_injective_function(ctx(), sym, types.size(), types.c_ptr(), get_sort(range)));
-}
-
-FuncDeclPtr RawContext::MkInjectiveFunction(Symbol^ name, array<SortPtr>^ domain, SortPtr range) {
-    scoped_Z3_ast_array<Z3_sort> types(domain);
-    return FuncDeclPtr(Z3_mk_injective_function(ctx(), name->get(), types.size(), types.c_ptr(), get_sort(range)));
-}
-
-
-TermPtr RawContext::MkNumeral(String^ numeral, SortPtr ty) {
-    return TermPtr(Z3_mk_numeral(ctx(), CreateString(numeral).c_str(), get_sort(ty)));
-}
-
-TermPtr RawContext::MkNumeral(int n, SortPtr ty) {
-    return TermPtr(Z3_mk_int(ctx(), n, get_sort(ty)));
-}
-
-TermPtr RawContext::MkNumeral(unsigned n, SortPtr ty) {
-    return TermPtr(Z3_mk_unsigned_int(ctx(), n, get_sort(ty)));
-}
-
-TermPtr RawContext::MkNumeral(__int64 n, SortPtr ty) {
-    return TermPtr(Z3_mk_int64(ctx(), n, get_sort(ty)));