Make some refactors for name mangling and encapsulation.

This commit is contained in:
2020-09-15 18:51:28 -07:00
parent 6080094c41
commit 55486d511f
18 changed files with 895 additions and 303 deletions

View File

@@ -11,29 +11,46 @@ struct parse_driver;
void scanner_init(parse_driver* d, yyscan_t* scanner);
void scanner_destroy(yyscan_t* scanner);
struct parse_driver {
std::string file_name;
std::ostringstream string_stream;
std::string file_contents;
class file_mgr {
private:
std::ostringstream string_stream;
std::string file_contents;
yy::location location;
size_t file_offset;
std::vector<size_t> line_offsets;
size_t file_offset;
std::vector<size_t> line_offsets;
public:
file_mgr();
definition_group global_defs;
void write(const char* buffer, size_t len);
void mark_line();
void finalize();
parse_driver(const std::string& file)
: file_name(file), file_offset(0) {}
size_t get_index(int line, int column) const;
size_t get_line_end(int line) const;
void print_location(
std::ostream& stream,
const yy::location& loc,
bool highlight = true) const;
};
class parse_driver {
private:
std::string file_name;
yy::location location;
definition_group* global_defs;
file_mgr* file_m;
public:
parse_driver(
file_mgr& mgr,
definition_group& defs,
const std::string& file)
: file_name(file), file_m(&mgr), global_defs(&defs) {}
bool run_parse();
void write(const char* buff, size_t len);
void mark_line();
size_t get_index(int line, int column);
size_t get_line_end(int line);
void print_location(
std::ostream& stream,
const yy::location& loc,
bool highlight = true);
yy::location& get_current_location();
file_mgr& get_file_manager() const;
definition_group& get_global_defs() const;
};
#define YY_DECL yy::parser::symbol_type yylex(yyscan_t yyscanner, parse_driver& drv)