Пример #1
0
 expr_ref scaler::scale(expr* e, bool is_mul) {
     expr* r;
     if (m_cache[is_mul].find(e, r)) {
         return expr_ref(r, m);
     }
     if (!is_app(e)) {
         return expr_ref(e, m);
     }
     app* ap = to_app(e);
     if (m_translate && m_translate->find(ap->get_decl(), r)) {
         return expr_ref(r, m);
     }
     if (!is_mul && a.is_numeral(e)) {
         return expr_ref(a.mk_mul(m_k, e), m);
     }
     expr_ref_vector args(m);
     bool is_mul_rec = is_mul || a.is_mul(e);
     for (unsigned i = 0; i < ap->get_num_args(); ++i) {
         args.push_back(scale(ap->get_arg(i), is_mul_rec));
     }
     expr_ref result(m);
     result = m.mk_app(ap->get_decl(), args.size(), args.c_ptr());
     m_cache[is_mul].insert(e, result);
     return result;
 }
Пример #2
0
 expr_ref complement_lit(expr* e) {
     expr* e1;
     if (m.is_not(e, e1)) {
         return expr_ref(e1, m);
     }
     else {
         return expr_ref(m.mk_not(e), m);
     }
 }
Пример #3
0
void test2() {
    ast_manager m;
    reg_decl_plugins(m);
    bv_util bv(m);
    datatype_util dtutil(m);
    params_ref p;

    datatype_decl_plugin & dt = *(static_cast<datatype_decl_plugin*>(m.get_plugin(m.get_family_id("datatype"))));
    sort_ref_vector new_sorts(m);
    constructor_decl* R = mk_constructor_decl(symbol("R"), symbol("is-R"), 0, nullptr);
    constructor_decl* G = mk_constructor_decl(symbol("G"), symbol("is-G"), 0, nullptr);
    constructor_decl* B = mk_constructor_decl(symbol("B"), symbol("is-B"), 0, nullptr);
    constructor_decl* constrs[3] = { R, G, B };
    datatype_decl * enum_sort = mk_datatype_decl(dtutil, symbol("RGB"), 0, nullptr, 3, constrs);
    VERIFY(dt.mk_datatypes(1, &enum_sort, 0, nullptr, new_sorts));
    sort* rgb = new_sorts[0].get();

    expr_ref x = mk_const(m, "x", rgb), y = mk_const(m, "y", rgb), z = mk_const(m, "z", rgb);
    ptr_vector<func_decl> const& enums = *dtutil.get_datatype_constructors(rgb);
    expr_ref r = expr_ref(m.mk_const(enums[0]), m);
    expr_ref g = expr_ref(m.mk_const(enums[1]), m);
    expr_ref b = expr_ref(m.mk_const(enums[2]), m);

    ref<solver> fd_solver = mk_fd_solver(m, p);
    fd_solver->assert_expr(m.mk_not(m.mk_eq(x, r)));
    fd_solver->assert_expr(m.mk_not(m.mk_eq(x, b)));

    expr_ref_vector asms(m), vars(m), conseq(m);
    vars.push_back(x);
    vars.push_back(y);

    VERIFY(l_true == fd_solver->get_consequences(asms, vars, conseq));
    std::cout << conseq << "\n";
    conseq.reset();

    fd_solver->push();
    fd_solver->assert_expr(m.mk_not(m.mk_eq(x, g)));
    VERIFY(l_false == fd_solver->check_sat(0,nullptr));
    fd_solver->pop(1);

    VERIFY(l_true == fd_solver->get_consequences(asms, vars, conseq));

    std::cout << conseq << "\n";
    conseq.reset();

    model_ref mr;
    fd_solver->get_model(mr);
    model_smt2_pp(std::cout << "model:\n", m, *mr.get(), 0);

    VERIFY(l_true == fd_solver->check_sat(0,nullptr));
    fd_solver->get_model(mr);
    ENSURE(mr.get());
    model_smt2_pp(std::cout, m, *mr.get(), 0);

}
Пример #4
0
 expr_ref context::bind_vars(expr* fml, bool is_forall) {
     if (m_enable_bind_variables) {
         return m_bind_variables(fml, is_forall);
     }
     else {
         return expr_ref(fml, m);
     }
 }
Пример #5
0
expr_ref bind_variables::operator()(expr* fml, bool is_forall) {
    if (m_vars.empty()) {
        return expr_ref(fml, m);
    }
    SASSERT(m_pinned.empty());
    expr_ref result = abstract(fml, m_cache, 0);
    if (!m_names.empty()) {
        m_bound.reverse();
        m_names.reverse();
        result = m.mk_quantifier(is_forall, m_bound.size(), m_bound.c_ptr(), m_names.c_ptr(), result);
    }
    m_pinned.reset();
    m_cache.reset();
    m_names.reset();
    m_bound.reset();
    for (var2bound::iterator it = m_var2bound.begin(); it != m_var2bound.end(); ++it) {
        it->m_value = 0;
    }
    return result;
}
Пример #6
0
 expr_ref mk_rule(expr* body, expr* head) {
     return expr_ref(m.mk_implies(body, head), m);
 }
Пример #7
0
static expr_ref mk_bv(ast_manager& m, char const* name, unsigned sz) {
    bv_util bv(m);
    return expr_ref(m.mk_const(symbol(name), bv.mk_sort(sz)), m);
}
Пример #8
0
static expr_ref mk_bool(ast_manager& m, char const* name) {
    return expr_ref(m.mk_const(symbol(name), m.mk_bool_sort()), m);
}
Пример #9
0
static expr_ref mk_const(ast_manager& m, char const* name, sort* s) {
    return expr_ref(m.mk_const(symbol(name), s), m);
}
Пример #10
0
int run()
{
    int sockfd, new_fd;  // listen on sock_fd, new connection on new_fd
    struct addrinfo hints, *servinfo, *p;
    struct sockaddr_storage their_addr; // connector's address information
    socklen_t sin_size;
    struct sigaction sa;
    int yes=1;
    char s[INET6_ADDRSTRLEN];
    int rv,numbytes;
    char inputBuffer[400];
    CommandLine cl;
    FileUtil util;


    memset(&hints, 0, sizeof hints);
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_flags = AI_PASSIVE; // use my IP

    if ((rv = getaddrinfo(NULL, PORT, &hints, &servinfo)) != 0) {
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
        return 1;
    }

    // loop through all the results and bind to the first we can
    for(p = servinfo; p != NULL; p = p->ai_next) {
        if ((sockfd = socket(p->ai_family, p->ai_socktype,
                p->ai_protocol)) == -1) {
            perror("server: socket");
            continue;
        }

        if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &yes,
                sizeof(int)) == -1) {
            perror("setsockopt");
            exit(1);
        }

        if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
            close(sockfd);
            perror("server: bind");
            continue;
        }

        break;
    }

    if (p == NULL)  {
        fprintf(stderr, "server: failed to bind\n");
        return 2;
    }

    freeaddrinfo(servinfo); // all done with this structure

    if (listen(sockfd, BACKLOG) == -1) {
        perror("listen");
        exit(1);
    }

    sa.sa_handler = sigchld_handler; // reap all dead processes
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = SA_RESTART;
    if (sigaction(SIGCHLD, &sa, NULL) == -1) {
        perror("sigaction");
        exit(1);
    }

    printf("server: waiting for connections...\n");

    while(1) {  // main accept() loop
        sin_size = sizeof their_addr;
        new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size);
        if (new_fd == -1) {
            perror("accept");
            continue;
        }
        //


        numbytes = recv(new_fd, inputBuffer, sizeof inputBuffer, 0);
        inputBuffer[numbytes] = '\0';
        std::string inpbf(inputBuffer);

        //printf("input received:%d  and %s \n",numbytes,inputBuffer);
        //printf("input is:%s \n",inputBuffer[0]);

        std::string inputdata=" ";

        //cout<<"input:"<<inpbf<<endl;

        string::const_iterator start, end;
        boost::match_results<std::string::const_iterator> what;
        boost::match_flag_type flags = boost::match_default;

        //get input from incoming request here
        regex expr_ref("(GET)(\\s+)(\\/)(query=)(.*?)(\\s+)");
        	start = inpbf.begin();
        	end = inpbf.end();
        	while (boost::regex_search(start, end, what, expr_ref, flags)) {
        		inputdata = what[5];
        		break;
        	}

       cout<<"input:"<<inputdata<<endl;

        //input fetch code ends

        inet_ntop(their_addr.ss_family,
            get_in_addr((struct sockaddr *)&their_addr),
            s, sizeof s);
        printf("server: got connection from %s\n", s);
        std::string op;
        std::string response;
        list<size_t> qresp;
        if(inputdata.length()>0){
        	qresp = cl.runQueryWeb(inputdata);
        	response = "data";
        }else{
        	response = "empty";
        }


        std::string html_inner_content;
        std::string html_end_content;

        std::string title = "this is title";
        std::string link = "file path is here";
        std::string description = "description should have come here";

        std::string css = "<style type=\"text/css\">ol,ul,li{border:0;margin:0;padding:0}h3,.med{font-size:medium;font-weight:400}body{color:#222}li.head,li.g,body,html,.std,.c h2,#mbEnd h2,h1{font-size:small;font-family:arial,sans-serif}li.g{margin-top:0;margin-bottom:20px}ol li{list-style:none}li{line-height:1.2}#res h3.r{display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.vsc{display:inline-block;position:relative;width:100%}#ires h3,#res h3,#tads h3,#tadsb h3,#mbEnd h3{font-size:medium}.sl,.r{display:inline;font-weight:400;margin:0}.s{max-width:42em;color:#222}div{display:block}.kv,.kvs{display:block;margin-bottom:2px}.f,.f a:link,.m,.c h2,#mbEnd h2,#tads h2,#tadsb h2,#tadsto h2,.descbox{color:#666}.st,.ac{line-height:1.24}.a,cite,cite a:link,cite a:visited,.cite,.cite:link,#mbEnd cite b,#tads cite b,#tadsb cite b,#tadsto cite b,#ans > i,.bc a:link{color:#093;font-style:normal}a:link,.w,.q:active,.q:visited,.tbotu{color:#12C;cursor:pointer}</style>";


        vector<std::string> outputList;
        op="<html><head><title>Falcon Search Engine</title>" + css + "</head><body><h2>Falcon Search Engine - Team Mango</h2><form name=\"input\" action=\"http://localhost:8888\" method=\"post\" id=\"input\">Query: <input type=\"text\" id=\"queryId\" name=\"query\" value=\"query here\" /><input type=\"submit\" value=\"Submit\" /></form><ol>";


        BOOST_FOREACH(size_t t, qresp){

            html_inner_content="<li class=\"g\"><div class=\"vsc\"><h3 class=\"r\"><a href=\"#\">" + util.getStringValue(t) + "</a></h3><div class=\"s\"><div class=\"f kv\"><cite>" + cl.tutil.fileMap[util.getStringValue(t)] + "</cite></div><span class=\"st\">" + description + "</span></div></div></li>";
            op = op + html_inner_content;

        }

        op = op+ "</ol></body></html>";

        if (!fork()) { // this is the child process
            close(sockfd); // child doesn't need the listener
            if (send(new_fd,op.c_str() , op.length(), 0) == -1)
                perror("send");
            close(new_fd);
            exit(0);
        }
        close(new_fd);  // parent doesn't need this
    }
Пример #11
0
expr_ref bind_variables::abstract(expr* term, cache_t& cache, unsigned scope) {
    unsigned sz = m_todo.size();
    m_todo.push_back(term);
    m_args.reset();
    expr* b, *arg;
    while (m_todo.size() > sz) {
        expr* e = m_todo.back();
        if (cache.contains(e)) {
            m_todo.pop_back();
            continue;
        }
        switch(e->get_kind()) {
        case AST_VAR: {
            SASSERT(to_var(e)->get_idx() < scope); 
            // mixing bound variables and free is possible for the caller, 
            // but not proper use.
            // So we assert here even though we don't check for it.
            cache.insert(e, e);
            m_todo.pop_back();
            break;
        }
        case AST_APP: {
            app* a = to_app(e);
            var2bound::obj_map_entry* w = m_var2bound.find_core(a);
            if (w) {
                var* v = w->get_data().m_value;
                if (!v) {
                    // allocate a bound index.
                    v = m.mk_var(m_names.size(), m.get_sort(a));
                    m_names.push_back(a->get_decl()->get_name());
                    m_bound.push_back(m.get_sort(a));
                    w->get_data().m_value = v;
                    m_pinned.push_back(v);
                }
                if (scope == 0) {
                    cache.insert(e, v);
                }
                else {
                    var* v1 = m.mk_var(scope + v->get_idx(), m.get_sort(v));
                    m_pinned.push_back(v1);
                    cache.insert(e, v1);
                }
                m_todo.pop_back();
                break;
            }
            bool all_visited = true;
            bool some_diff = false;
            m_args.reset();
            for (unsigned i = 0; i < a->get_num_args(); ++i) {
                arg = a->get_arg(i);                
                if (!cache.find(arg, b)) {
                    m_todo.push_back(arg);
                    all_visited = false;
                }
                else if (all_visited) {
                    m_args.push_back(b);
                    if (b != arg) {
                        some_diff = true;
                    }
                }
            }
            if (all_visited) {
                if (some_diff) {
                    b = m.mk_app(a->get_decl(), m_args.size(), m_args.c_ptr());
                    m_pinned.push_back(b);
                }
                else {
                    b = a;
                }
                cache.insert(e, b);
                m_todo.pop_back();
            }
            break;
        }
        case AST_QUANTIFIER: {
            quantifier* q = to_quantifier(e);
            expr_ref_buffer patterns(m);
            expr_ref result1(m);
            unsigned new_scope = scope + q->get_num_decls();
            cache_t new_cache;
            for (unsigned i = 0; i < q->get_num_patterns(); ++i) {
                patterns.push_back(abstract(q->get_pattern(i), new_cache, new_scope));
            }
            result1 = abstract(q->get_expr(), new_cache, new_scope);
            b = m.update_quantifier(q, patterns.size(), patterns.c_ptr(), result1.get());
            m_pinned.push_back(b);            
            cache.insert(e, b);
            m_todo.pop_back();            
            break;
        }
        default:
            UNREACHABLE();
        }
    }
    return expr_ref(cache.find(term), m);
}