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-11 17:40:18 +00:00
|
|
|
struct file {
|
|
|
|
std::string m_fname;
|
|
|
|
std::vector<std::string> m_lines;
|
|
|
|
snapshot_vector m_snapshots;
|
|
|
|
info_manager m_info;
|
|
|
|
|
|
|
|
file(std::string const & fname);
|
|
|
|
unsigned find(unsigned linenum);
|
|
|
|
void replace_line(unsigned linenum, std::string const & new_line);
|
|
|
|
void insert_line(unsigned linenum, std::string const & new_line);
|
|
|
|
void remove_line(unsigned linenum);
|
|
|
|
};
|
|
|
|
typedef std::shared_ptr<file> file_ptr;
|
|
|
|
typedef std::unordered_map<std::string, file_ptr> file_map;
|
|
|
|
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-16 00:24:37 +00:00
|
|
|
std::unique_ptr<interruptible_thread> m_thread_ptr;
|
2014-08-07 01:07:04 +00:00
|
|
|
|
2014-08-11 17:40:18 +00:00
|
|
|
void load_file(std::string const & fname);
|
|
|
|
void visit_file(std::string const & fname);
|
|
|
|
void check_file();
|
2014-08-07 01:07:04 +00:00
|
|
|
void replace_line(unsigned linenum, std::string const & new_line);
|
2014-08-11 02:57:24 +00:00
|
|
|
void insert_line(unsigned linenum, std::string const & new_line);
|
|
|
|
void remove_line(unsigned linenum);
|
2014-08-11 17:40:18 +00:00
|
|
|
void check_line(unsigned linenum, std::string const & line);
|
2014-08-07 01:07:04 +00:00
|
|
|
void show_info(unsigned linenum);
|
|
|
|
void process_from(unsigned linenum);
|
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-08-07 01:07:04 +00:00
|
|
|
unsigned find(unsigned linenum);
|
2014-08-11 02:57:24 +00:00
|
|
|
void read_line(std::istream & in, std::string & line);
|
2014-08-16 00:24:37 +00:00
|
|
|
void reset_thread();
|
|
|
|
void interrupt_thread();
|
2014-08-11 02:57:24 +00:00
|
|
|
unsigned get_linenum(std::string const & line, std::string const & cmd);
|
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);
|
|
|
|
};
|
|
|
|
}
|