minor fixes

This commit is contained in:
xensik
2022-02-15 19:40:05 +01:00
parent 99e830fb93
commit b30644ff9a
84 changed files with 13774 additions and 12964 deletions

View File

@ -98,7 +98,7 @@ void block::merge(const std::vector<block*>& childs)
{
child->local_vars.insert(child->local_vars.begin() + i, this->local_vars.at(i));
}
else if(pos > i)
else if (pos > i)
{
auto& v = child->local_vars;
std::rotate(v.rend() - pos - 1, v.rend() - pos, v.rend() - i);

View File

@ -38,6 +38,23 @@ auto node::is_special_stmt() -> bool
}
}
auto node::is_special_stmt_dev() -> bool
{
switch (kind_)
{
case kind::stmt_dev:
case kind::stmt_if:
case kind::stmt_ifelse:
case kind::stmt_while:
case kind::stmt_for:
case kind::stmt_foreach:
case kind::stmt_switch:
return true;
default:
return false;
}
}
auto node::is_special_stmt_noif() -> bool
{
switch (kind_)
@ -52,6 +69,21 @@ auto node::is_special_stmt_noif() -> bool
}
}
auto node::is_special_stmt_dev_noif() -> bool
{
switch (kind_)
{
case kind::stmt_dev:
case kind::stmt_while:
case kind::stmt_for:
case kind::stmt_foreach:
case kind::stmt_switch:
return true;
default:
return false;
}
}
auto node::is_binary() -> bool
{
switch (kind_)
@ -121,9 +153,6 @@ expr_float::expr_float(const location& loc, const std::string& value) : node(kin
expr_vector::expr_vector(expr x, expr y, expr z) : node(kind::expr_vector), x(std::move(x)), y(std::move(y)), z(std::move(z)) {}
expr_vector::expr_vector(const location& loc, expr x, expr y, expr z) : node(kind::expr_vector, loc), x(std::move(x)), y(std::move(y)), z(std::move(z)) {}
expr_color::expr_color(const std::string& value) : node(kind::expr_color), value(value) {}
expr_color::expr_color(const location& loc, const std::string& value) : node(kind::expr_color, loc), value(value) {}
expr_string::expr_string(const std::string& value) : node(kind::expr_string), value(value) {}
expr_string::expr_string(const location& loc, const std::string& value) : node(kind::expr_string, loc), value(value) {}
@ -318,6 +347,9 @@ expr_assign_bitwise_exor::expr_assign_bitwise_exor(const location& loc, expr lva
stmt_list::stmt_list() : node(kind::stmt_list) {}
stmt_list::stmt_list(const location& loc) : node(kind::stmt_list, loc) {}
stmt_dev::stmt_dev(ast::stmt_list::ptr list) : node(kind::stmt_dev), list(std::move(list)) {}
stmt_dev::stmt_dev(const location& loc, ast::stmt_list::ptr list) : node(kind::stmt_dev, loc), list(std::move(list)) {}
stmt_expr::stmt_expr(ast::expr expr) : node(kind::stmt_expr), expr(std::move(expr)) {}
stmt_expr::stmt_expr(const location& loc, ast::expr expr) : node(kind::stmt_expr, loc), expr(std::move(expr)) {}
@ -486,11 +518,6 @@ auto expr_vector::print() const -> std::string
return "( "s + x.print() + ", " + y.print() + ", " + z.print() + " )";
}
auto expr_color::print() const -> std::string
{
return "#"s += value;
}
auto expr_string::print() const -> std::string
{
return value;
@ -861,7 +888,10 @@ auto stmt_list::print() const -> std::string
if (&stmt != &list.front() && stmt.as_node->is_special_stmt() || last_special)
data += "\n";
data += stmts_pad + stmt.print();
if (stmt == kind::stmt_dev)
data += stmt.print();
else
data += stmts_pad + stmt.print();
if (&stmt != &list.back())
data += "\n";
@ -880,6 +910,39 @@ auto stmt_list::print() const -> std::string
return data;
}
auto stmt_dev::print() const -> std::string
{
std::string data;
bool last_special = false;
auto stmts_pad = indented(indent_);
data += "/#\n";
for (const auto& stmt : list->list)
{
if (&stmt != &list->list.front() && stmt.as_node->is_special_stmt() || last_special)
data += "\n";
if (stmt == kind::stmt_dev)
data += stmt.print();
else
data += stmts_pad + stmt.print();
if (&stmt != &list->list.back())
data += "\n";
if (stmt.as_node->is_special_stmt())
last_special = true;
else
last_special = false;
}
data += "\n#/";
return data;
}
auto stmt_expr::print() const -> std::string
{
return expr.print();
@ -905,7 +968,7 @@ auto stmt_notify::print() const -> std::string
if (args->list.size() == 0)
return obj.print() + " notify( " + event.print() + " );";
else
return obj.print() + " notify( " + event.print() + ", " + args->print() + " );";
return obj.print() + " notify( " + event.print() + "," + args->print() + ");";
};
auto stmt_wait::print() const -> std::string
@ -921,7 +984,7 @@ auto stmt_waittill::print() const -> std::string
if (args->list.size() == 0)
return obj.print() + " waittill( " + event.print() + " );";
else
return obj.print() + " waittill( " + event.print() + ", " + args->print() + " );";
return obj.print() + " waittill( " + event.print() + "," + args->print() + ");";
};
auto stmt_waittillmatch::print() const -> std::string
@ -929,7 +992,7 @@ auto stmt_waittillmatch::print() const -> std::string
if (args->list.size() == 0)
return obj.print() + " waittillmatch( " + event.print() + " );";
else
return obj.print() + " waittillmatch( " + event.print() + ", " + args->print() + " );";
return obj.print() + " waittillmatch( " + event.print() + "," + args->print() + ");";
};
auto stmt_waittillframeend::print() const -> std::string
@ -1228,32 +1291,32 @@ auto asm_loc::print() const -> std::string
auto asm_jump::print() const -> std::string
{
return "jump " + value;
return "__asm_jump( " + value + " );";
}
auto asm_jump_back::print() const -> std::string
{
return "jump_back " + value;
return "__asm_jump_back( " + value + " );";
}
auto asm_jump_cond::print() const -> std::string
{
return "jump_cond( " + expr.print() + " ) " + value;
return "__asm_jump_cond( " + expr.print() + ", " + value + " );";
}
auto asm_jump_true_expr::print() const -> std::string
{
return "expr_true " + value;
return "__asm_jump_expr_true( " + value + " );";
}
auto asm_jump_false_expr::print() const -> std::string
{
return "expr_false " + value;
return "__asm_jump_expr_false( " + value + " );";
}
auto asm_switch::print() const -> std::string
{
return "switch( " + expr.print() + " ) " + value;
return "__asm_switch( " + expr.print() + ", " + value + " );";
}
auto asm_endswitch::print() const -> std::string
@ -1264,37 +1327,37 @@ auto asm_endswitch::print() const -> std::string
{
result += " " + entry;
}
return "endswitch( " + count + " )" + result;
return "__asm_endswitch( " + count + "," + result + ");";
}
auto asm_prescriptcall::print() const -> std::string
{
return "prescriptcall";
return "__asm_prescriptcall();";
}
auto asm_voidcodepos::print() const -> std::string
{
return "voidcodepos";
return "__asm_voidcodepos();";
}
auto asm_create::print() const -> std::string
{
return "var_create_" + index;
return "__asm_var_create( " + index + " );";
}
auto asm_access::print() const -> std::string
{
return "var_access_" + index;
return "__asm_var_access( " + index + " );";
}
auto asm_remove::print() const -> std::string
{
return "var_remove_" + index;
return "__asm_var_remove( " + index + " );";
}
auto asm_clear::print() const -> std::string
{
return "var_clear_" + index;
return "__asm_var_clear( " + index + " );";
}
// operators
@ -1334,11 +1397,6 @@ bool operator==(const expr_vector& lhs, const expr_vector& rhs)
return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
}
bool operator==(const expr_color& lhs, const expr_color& rhs)
{
return lhs.value == rhs.value;
}
bool operator==(const expr_string& lhs, const expr_string& rhs)
{
return lhs.value == rhs.value;
@ -1493,7 +1551,6 @@ expr::~expr()
case kind::expr_integer: as_integer.~unique_ptr(); return;
case kind::expr_float: as_float.~unique_ptr(); return;
case kind::expr_vector: as_vector.~unique_ptr(); return;
case kind::expr_color: as_color.~unique_ptr(); return;
case kind::expr_string: as_string.~unique_ptr(); return;
case kind::expr_istring: as_istring.~unique_ptr(); return;
case kind::expr_path: as_path.~unique_ptr(); return;
@ -1571,7 +1628,7 @@ bool operator==(const expr& lhs, kind rhs)
bool operator==(const expr& lhs, const expr& rhs)
{
if(!(*lhs.as_node == *rhs.as_node)) return false;
if (!(*lhs.as_node == *rhs.as_node)) return false;
switch(lhs.as_node->kind())
{
@ -1580,7 +1637,6 @@ bool operator==(const expr& lhs, const expr& rhs)
case kind::expr_integer: return *lhs.as_integer == *rhs.as_integer;
case kind::expr_float: return *lhs.as_float == *rhs.as_float;
case kind::expr_vector: return *lhs.as_vector == *rhs.as_vector;
case kind::expr_color: return *lhs.as_color == *rhs.as_color;
case kind::expr_string: return *lhs.as_string == *rhs.as_string;
case kind::expr_istring: return *lhs.as_istring == *rhs.as_istring;
case kind::expr_path: return *lhs.as_path == *rhs.as_path;
@ -1640,6 +1696,7 @@ stmt::~stmt()
{
case kind::null: as_node.~unique_ptr(); return;
case kind::stmt_list: as_list.~unique_ptr(); return;
case kind::stmt_dev: as_dev.~unique_ptr(); return;
case kind::stmt_expr: as_expr.~unique_ptr(); return;
case kind::stmt_call: as_call.~unique_ptr(); return;
case kind::stmt_assign: as_assign.~unique_ptr(); return;
@ -1666,9 +1723,9 @@ stmt::~stmt()
case kind::stmt_prof_begin: as_prof_begin.~unique_ptr(); return;
case kind::stmt_prof_end: as_prof_end.~unique_ptr(); return;
case kind::asm_loc: as_loc.~unique_ptr(); return;
case kind::asm_jump_cond: as_cond.~unique_ptr(); return;
case kind::asm_jump: as_jump.~unique_ptr(); return;
case kind::asm_jump_back: as_jump_back.~unique_ptr(); return;
case kind::asm_jump_cond: as_cond.~unique_ptr(); return;
case kind::asm_switch: as_asm_switch.~unique_ptr(); return;
case kind::asm_endswitch: as_asm_endswitch.~unique_ptr(); return;
case kind::asm_create: as_asm_create.~unique_ptr(); return;

View File

@ -16,7 +16,6 @@ enum class kind
expr_integer,
expr_float,
expr_vector,
expr_color,
expr_string,
expr_istring,
expr_path,
@ -79,6 +78,7 @@ enum class kind
expr_assign_bitwise_and,
expr_assign_bitwise_exor,
stmt_list,
stmt_dev,
stmt_expr,
stmt_call,
stmt_assign,
@ -134,7 +134,6 @@ struct expr_false;
struct expr_integer;
struct expr_float;
struct expr_vector;
struct expr_color;
struct expr_string;
struct expr_istring;
struct expr_path;
@ -199,6 +198,7 @@ struct expr_assign_bitwise_or;
struct expr_assign_bitwise_and;
struct expr_assign_bitwise_exor;
struct stmt_list;
struct stmt_dev;
struct stmt_expr;
struct stmt_call;
struct stmt_assign;
@ -273,7 +273,6 @@ union expr
std::unique_ptr<expr_integer> as_integer;
std::unique_ptr<expr_float> as_float;
std::unique_ptr<expr_vector> as_vector;
std::unique_ptr<expr_color> as_color;
std::unique_ptr<expr_string> as_string;
std::unique_ptr<expr_istring> as_istring;
std::unique_ptr<expr_path> as_path;
@ -359,6 +358,7 @@ union stmt
{
std::unique_ptr<node> as_node;
std::unique_ptr<stmt_list> as_list;
std::unique_ptr<stmt_dev> as_dev;
std::unique_ptr<stmt_expr> as_expr;
std::unique_ptr<stmt_call> as_call;
std::unique_ptr<stmt_assign> as_assign;
@ -453,7 +453,9 @@ public:
auto loc() -> location& { return loc_; }
auto is_special_stmt() -> bool;
auto is_special_stmt_dev() -> bool;
auto is_special_stmt_noif() -> bool;
auto is_special_stmt_dev_noif() -> bool;
auto is_binary() -> bool;
auto precedence() -> std::uint8_t;
@ -521,18 +523,6 @@ struct expr_vector : public node
friend bool operator==(const expr_vector& lhs, const expr_vector& rhs);
};
struct expr_color : public node
{
using ptr = std::unique_ptr<expr_color>;
std::string value;
expr_color(const std::string& value);
expr_color(const location& loc, const std::string& value);
auto print() const -> std::string override;
friend bool operator==(const expr_color& lhs, const expr_color& rhs);
};
struct expr_string : public node
{
using ptr = std::unique_ptr<expr_string>;
@ -1199,6 +1189,17 @@ struct stmt_list : public node
auto print() const -> std::string override;
};
struct stmt_dev : public node
{
using ptr = std::unique_ptr<stmt_dev>;
stmt_list::ptr list;
stmt_dev(stmt_list::ptr list);
stmt_dev(const location& loc, stmt_list::ptr list);
auto print() const -> std::string override;
};
struct stmt_expr : public node
{
using ptr = std::unique_ptr<stmt_expr>;

View File

@ -78,14 +78,14 @@ auto byte_buffer::read_c_string() -> std::string
auto byte_buffer::print_bytes(std::size_t pos, std::size_t count) -> std::string
{
std::string shit;
std::string data {};
for (auto i = pos; i < pos + count; i++)
{
shit += utils::string::va("%s %02X", shit.data(), (*reinterpret_cast<std::uint8_t*>(data_.data() + i)));
data = utils::string::va("%s %02X", data.data(), (*reinterpret_cast<std::uint8_t*>(data_.data() + i)));
}
return shit;
return data;
}
auto byte_buffer::pos() -> std::size_t
@ -93,6 +93,23 @@ auto byte_buffer::pos() -> std::size_t
return pos_;
}
void byte_buffer::pos(std::size_t pos)
{
if (pos >= 0 && pos <= size_)
{
pos_ = pos;
}
}
auto byte_buffer::align(std::size_t size) -> std::size_t
{
auto pos = pos_;
pos_ = (pos_ + (size - 1)) & ~(size - 1);
return pos_ - pos;
}
auto byte_buffer::buffer() -> std::vector<std::uint8_t>&
{
return data_;

View File

@ -77,6 +77,8 @@ public:
auto read_c_string() -> std::string;
auto print_bytes(std::size_t pos, std::size_t count) -> std::string;
auto pos() -> std::size_t;
void pos(std::size_t pos);
auto align(std::size_t size) -> std::size_t;
auto buffer() -> std::vector<std::uint8_t>&;
};