2014-08-07 01:07:04 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
|
|
|
|
Released under Apache 2.0 license as described in the file LICENSE.
|
|
|
|
|
|
|
|
Author: Leonardo de Moura
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2014-08-11 17:40:18 +00:00
|
|
|
#include <unordered_map>
|
2014-08-16 00:24:37 +00:00
|
|
|
#include "util/interrupt.h"
|
2014-08-15 01:12:12 +00:00
|
|
|
#include "library/definition_cache.h"
|
2014-08-07 01:07:04 +00:00
|
|
|
#include "frontends/lean/parser.h"
|
|
|
|
#include "frontends/lean/info_manager.h"
|
|
|
|
|
|
|
|
namespace lean {
|
|
|
|
/**
|
|
|
|
\brief Class for managing an input stream used to communicate with
|
|
|
|
external processes.
|
|
|
|
*/
|
|
|
|
class server {
|
2014-08-27 21:53:16 +00:00
|
|
|
class worker;
|
|
|
|
class file {
|
|
|
|
friend class server::worker;
|
2014-08-11 17:40:18 +00:00
|
|
|
std::string m_fname;
|
2014-08-27 21:53:16 +00:00
|
|
|
mutable mutex m_lines_mutex;
|
2014-08-11 17:40:18 +00:00
|
|
|
std::vector<std::string> m_lines;
|
|
|
|
snapshot_vector m_snapshots;
|
|
|
|
info_manager m_info;
|
|
|
|
|
2014-09-03 08:35:04 +00:00
|
|
|
unsigned find(unsigned line_num);
|
2014-08-27 21:53:16 +00:00
|
|
|
unsigned copy_to(std::string & block, unsigned starting_from);
|
|
|
|
public:
|
|
|
|
file(std::istream & in, std::string const & fname);
|
2014-09-03 08:35:04 +00:00
|
|
|
void replace_line(unsigned line_num, std::string const & new_line);
|
|
|
|
void insert_line(unsigned line_num, std::string const & new_line);
|
|
|
|
void remove_line(unsigned line_num);
|
2014-08-30 01:12:22 +00:00
|
|
|
void show(std::ostream & out, bool valid);
|
2014-08-30 00:46:17 +00:00
|
|
|
std::string const & get_fname() const { return m_fname; }
|
2014-08-27 21:53:16 +00:00
|
|
|
info_manager const & infom() const { return m_info; }
|
2014-09-17 01:38:23 +00:00
|
|
|
void sync(std::vector<std::string> const & lines);
|
2014-08-11 17:40:18 +00:00
|
|
|
};
|
|
|
|
typedef std::shared_ptr<file> file_ptr;
|
|
|
|
typedef std::unordered_map<std::string, file_ptr> file_map;
|
2014-08-27 21:53:16 +00:00
|
|
|
class worker {
|
|
|
|
snapshot m_empty_snapshot;
|
|
|
|
definition_cache & m_cache;
|
|
|
|
file_ptr m_todo_file;
|
2014-09-03 08:35:04 +00:00
|
|
|
unsigned m_todo_line_num;
|
2014-08-27 21:53:16 +00:00
|
|
|
options m_todo_options;
|
|
|
|
mutex m_todo_mutex;
|
|
|
|
condition_variable m_todo_cv;
|
|
|
|
file_ptr m_last_file;
|
|
|
|
atomic_bool m_terminate;
|
|
|
|
interruptible_thread m_thread;
|
|
|
|
public:
|
|
|
|
worker(environment const & env, io_state const & ios, definition_cache & cache);
|
|
|
|
~worker();
|
2014-09-03 08:35:04 +00:00
|
|
|
void set_todo(file_ptr const & f, unsigned line_num, options const & o);
|
2014-08-27 21:53:16 +00:00
|
|
|
void request_interrupt();
|
2014-09-09 17:28:11 +00:00
|
|
|
bool wait(optional<unsigned> const & ms);
|
2014-08-27 21:53:16 +00:00
|
|
|
};
|
|
|
|
|
2014-08-11 17:40:18 +00:00
|
|
|
file_map m_file_map;
|
|
|
|
file_ptr m_file;
|
2014-08-07 01:07:04 +00:00
|
|
|
environment m_env;
|
|
|
|
io_state m_ios;
|
2014-08-11 17:40:18 +00:00
|
|
|
std::ostream & m_out;
|
2014-08-07 01:07:04 +00:00
|
|
|
unsigned m_num_threads;
|
|
|
|
snapshot m_empty_snapshot;
|
2014-08-15 01:12:12 +00:00
|
|
|
definition_cache m_cache;
|
2014-08-27 21:53:16 +00:00
|
|
|
worker m_worker;
|
2014-08-07 01:07:04 +00:00
|
|
|
|
2014-09-06 19:34:20 +00:00
|
|
|
void load_file(std::string const & fname, bool error_if_nofile = true);
|
2014-09-29 22:17:27 +00:00
|
|
|
void save_olean(std::string const & fname);
|
2014-08-11 17:40:18 +00:00
|
|
|
void visit_file(std::string const & fname);
|
|
|
|
void check_file();
|
2014-09-03 08:35:04 +00:00
|
|
|
void replace_line(unsigned line_num, std::string const & new_line);
|
|
|
|
void insert_line(unsigned line_num, std::string const & new_line);
|
|
|
|
void remove_line(unsigned line_num);
|
2014-09-04 21:02:53 +00:00
|
|
|
void show_info(unsigned line_num, optional<unsigned> const & col_num);
|
2014-09-03 08:35:04 +00:00
|
|
|
void process_from(unsigned line_num);
|
2014-08-14 21:40:46 +00:00
|
|
|
void set_option(std::string const & line);
|
2014-08-27 01:06:37 +00:00
|
|
|
void eval_core(environment const & env, options const & o, std::string const & line);
|
2014-08-14 23:08:43 +00:00
|
|
|
void eval(std::string const & line);
|
2014-09-02 19:57:20 +00:00
|
|
|
void display_decl(name const & short_name, name const & long_name, environment const & env, options const & o);
|
2014-09-06 00:50:55 +00:00
|
|
|
void display_decl(name const & long_name, environment const & env, options const & o);
|
2014-09-05 22:14:05 +00:00
|
|
|
void find_pattern(unsigned line_num, std::string const & pattern);
|
2014-09-03 08:35:04 +00:00
|
|
|
unsigned find(unsigned line_num);
|
2014-08-11 02:57:24 +00:00
|
|
|
void read_line(std::istream & in, std::string & line);
|
2014-08-27 21:53:16 +00:00
|
|
|
void interrupt_worker();
|
2014-08-29 19:59:22 +00:00
|
|
|
void show_options();
|
2014-08-30 01:12:22 +00:00
|
|
|
void show(bool valid);
|
2014-09-17 01:38:23 +00:00
|
|
|
void sync(std::vector<std::string> const & lines);
|
2014-09-09 17:28:11 +00:00
|
|
|
void wait(optional<unsigned> ms);
|
2014-09-03 08:35:04 +00:00
|
|
|
unsigned get_line_num(std::string const & line, std::string const & cmd);
|
2014-09-09 17:28:11 +00:00
|
|
|
optional<unsigned> get_optional_num(std::string const & line, std::string const & cmd);
|
2014-09-17 01:38:23 +00:00
|
|
|
unsigned get_num(std::string const & line, std::string const & cmd);
|
2014-09-04 21:02:53 +00:00
|
|
|
pair<unsigned, optional<unsigned>> get_line_opt_col_num(std::string const & line, std::string const & cmd);
|
2014-09-03 08:35:04 +00:00
|
|
|
pair<unsigned, unsigned> get_line_col_num(std::string const & line, std::string const & cmd);
|
|
|
|
void find_goal_matches(unsigned line_num, unsigned col_num, std::string const & filters);
|
2014-08-07 01:07:04 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
server(environment const & env, io_state const & ios, unsigned num_threads = 1);
|
2014-08-16 00:24:37 +00:00
|
|
|
~server();
|
2014-08-07 01:07:04 +00:00
|
|
|
bool operator()(std::istream & in);
|
|
|
|
};
|
2014-09-24 16:16:59 +00:00
|
|
|
|
|
|
|
void initialize_server();
|
|
|
|
void finalize_server();
|
2014-08-07 01:07:04 +00:00
|
|
|
}
|