clean warnings
This commit is contained in:
parent
699227259c
commit
a7cd82508c
@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2296,7 +2296,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2323,7 +2323,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2355,7 +2355,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2405,7 +2405,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2425,7 +2425,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2475,7 +2475,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1814,7 +1814,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1841,7 +1841,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1852,7 +1852,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1927,7 +1927,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2434,7 +2434,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2623,15 +2623,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3141,7 +3145,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3161,7 +3165,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3317,7 +3321,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -127,8 +129,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -643,7 +645,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -660,7 +662,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -694,7 +696,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -728,7 +730,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2295,7 +2295,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2322,7 +2322,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2354,7 +2354,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2404,7 +2404,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2424,7 +2424,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2474,7 +2474,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1814,7 +1814,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1841,7 +1841,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1852,7 +1852,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1927,7 +1927,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2434,7 +2434,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2623,15 +2623,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3141,7 +3145,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3161,7 +3165,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3317,7 +3321,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -127,8 +129,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -643,7 +645,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -660,7 +662,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -694,7 +696,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -728,7 +730,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2286,7 +2286,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2313,7 +2313,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2345,7 +2345,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2395,7 +2395,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2415,7 +2415,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2465,7 +2465,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1808,7 +1808,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1835,7 +1835,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1846,7 +1846,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1921,7 +1921,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2428,7 +2428,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2617,15 +2617,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3135,7 +3139,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3155,7 +3159,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3311,7 +3315,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -126,8 +128,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -479,7 +481,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -642,7 +644,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -659,7 +661,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -693,7 +695,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -727,7 +729,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2286,7 +2286,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2313,7 +2313,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2345,7 +2345,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2395,7 +2395,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2415,7 +2415,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2465,7 +2465,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1808,7 +1808,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1835,7 +1835,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1846,7 +1846,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1921,7 +1921,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2428,7 +2428,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2617,15 +2617,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3135,7 +3139,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3155,7 +3159,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3311,7 +3315,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -126,8 +128,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -479,7 +481,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -642,7 +644,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -659,7 +661,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -693,7 +695,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -727,7 +729,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -769,7 +769,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2286,7 +2286,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2313,7 +2313,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2345,7 +2345,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2395,7 +2395,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2415,7 +2415,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2465,7 +2465,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1808,7 +1808,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1835,7 +1835,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1846,7 +1846,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1921,7 +1921,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2428,7 +2428,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2617,15 +2617,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3135,7 +3139,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3155,7 +3159,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3311,7 +3315,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -85,8 +85,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -126,8 +128,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -479,7 +481,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -642,7 +644,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -659,7 +661,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -693,7 +695,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -727,7 +729,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2346,7 +2346,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2373,7 +2373,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2405,7 +2405,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2455,7 +2455,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2475,7 +2475,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2525,7 +2525,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1845,7 +1845,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1872,7 +1872,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1883,7 +1883,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1958,7 +1958,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2465,7 +2465,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2654,15 +2654,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3178,7 +3182,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3198,7 +3202,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3354,7 +3358,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -129,8 +131,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -482,7 +484,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -587,7 +589,7 @@ lex_name:
|
|||||||
{
|
{
|
||||||
if (buffer_.data[0] != '_')
|
if (buffer_.data[0] != '_')
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < buffer_.length; i++)
|
for (auto i = 0u; i < buffer_.length; i++)
|
||||||
{
|
{
|
||||||
auto c = buffer_.data[i];
|
auto c = buffer_.data[i];
|
||||||
|
|
||||||
@ -656,7 +658,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -673,7 +675,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -707,7 +709,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -741,7 +743,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2295,7 +2295,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2322,7 +2322,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2354,7 +2354,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2404,7 +2404,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2424,7 +2424,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2474,7 +2474,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1814,7 +1814,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1841,7 +1841,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1852,7 +1852,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1927,7 +1927,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2434,7 +2434,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2623,15 +2623,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3141,7 +3145,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3161,7 +3165,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3317,7 +3321,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -127,8 +129,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -643,7 +645,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -660,7 +662,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -694,7 +696,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -728,7 +730,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2295,7 +2295,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2322,7 +2322,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2354,7 +2354,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2404,7 +2404,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2424,7 +2424,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2474,7 +2474,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1821,7 +1821,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1848,7 +1848,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1859,7 +1859,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1934,7 +1934,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2441,7 +2441,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2630,15 +2630,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3148,7 +3152,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3168,7 +3172,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3324,7 +3328,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -86,8 +86,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -127,8 +129,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -480,7 +482,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -643,7 +645,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -660,7 +662,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -694,7 +696,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -728,7 +730,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -777,7 +777,7 @@ void compiler::emit_stmt_switch(const ast::stmt_switch::ptr& stmt, const block::
|
|||||||
bool has_default = false;
|
bool has_default = false;
|
||||||
block* default_ctx = nullptr;
|
block* default_ctx = nullptr;
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[i];
|
auto& entry = stmt->stmt->list[i];
|
||||||
|
|
||||||
@ -2346,7 +2346,7 @@ void compiler::process_stmt_while(const ast::stmt_while::ptr& stmt, const block:
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2373,7 +2373,7 @@ void compiler::process_stmt_dowhile(const ast::stmt_dowhile::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
if (const_cond) blk->append(break_blks_);
|
if (const_cond) blk->append(break_blks_);
|
||||||
@ -2405,7 +2405,7 @@ void compiler::process_stmt_for(const ast::stmt_for::ptr& stmt, const block::ptr
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->blk.get());
|
continue_blks_.push_back(stmt->blk.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_stmt(stmt->iter, stmt->blk_iter);
|
process_stmt(stmt->iter, stmt->blk_iter);
|
||||||
@ -2455,7 +2455,7 @@ void compiler::process_stmt_foreach(const ast::stmt_foreach::ptr& stmt, const bl
|
|||||||
|
|
||||||
continue_blks_.push_back(stmt->ctx.get());
|
continue_blks_.push_back(stmt->ctx.get());
|
||||||
|
|
||||||
for (auto i = 0; i < continue_blks_.size(); i++)
|
for (auto i = 0u; i < continue_blks_.size(); i++)
|
||||||
blk->append({continue_blks_.at(i)});
|
blk->append({continue_blks_.at(i)});
|
||||||
|
|
||||||
process_expr(stmt->key_expr, stmt->ctx_post);
|
process_expr(stmt->key_expr, stmt->ctx_post);
|
||||||
@ -2475,7 +2475,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
|
|
||||||
auto num = stmt->stmt->list.size();
|
auto num = stmt->stmt->list.size();
|
||||||
|
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->stmt->list[0];
|
auto& entry = stmt->stmt->list[0];
|
||||||
|
|
||||||
@ -2525,7 +2525,7 @@ void compiler::process_stmt_switch(const ast::stmt_switch::ptr& stmt, const bloc
|
|||||||
auto old_breaks = break_blks_;
|
auto old_breaks = break_blks_;
|
||||||
break_blks_.clear();
|
break_blks_.clear();
|
||||||
|
|
||||||
for (auto i = 0; i < stmt_list->list.size(); i++)
|
for (auto i = 0u; i < stmt_list->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt_list->list[i];
|
auto& entry = stmt_list->list[i];
|
||||||
|
|
||||||
|
@ -1845,7 +1845,7 @@ void decompiler::decompile_infinites(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1872,7 +1872,7 @@ void decompiler::decompile_loops(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (stmt->list.at(i) == ast::kind::asm_switch)
|
if (stmt->list.at(i) == ast::kind::asm_switch)
|
||||||
{
|
{
|
||||||
@ -1883,7 +1883,7 @@ void decompiler::decompile_switches(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
for (auto i = 0u; i < stmt->list.size(); i++)
|
||||||
{
|
{
|
||||||
auto& entry = stmt->list.at(i);
|
auto& entry = stmt->list.at(i);
|
||||||
|
|
||||||
@ -1958,7 +1958,7 @@ void decompiler::decompile_ifelses(const ast::stmt_list::ptr& stmt)
|
|||||||
|
|
||||||
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
void decompiler::decompile_aborts(const ast::stmt_list::ptr& block)
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < block->list.size(); i++)
|
for (auto i = 0u; i < block->list.size(); i++)
|
||||||
{
|
{
|
||||||
if (block->list.at(i) == ast::kind::asm_jump)
|
if (block->list.at(i) == ast::kind::asm_jump)
|
||||||
{
|
{
|
||||||
@ -2465,7 +2465,7 @@ void decompiler::decompile_switch(const ast::stmt_list::ptr& stmt, std::uint32_t
|
|||||||
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
auto current_case = ast::stmt(std::make_unique<ast::node>());
|
||||||
|
|
||||||
auto num = sw_stmt->list.size();
|
auto num = sw_stmt->list.size();
|
||||||
for (auto i = 0; i < num; i++)
|
for (auto i = 0u; i < num; i++)
|
||||||
{
|
{
|
||||||
auto& entry = sw_stmt->list[0];
|
auto& entry = sw_stmt->list[0];
|
||||||
|
|
||||||
@ -2654,15 +2654,19 @@ void decompiler::process_stmt_list(const ast::stmt_list::ptr& stmt, const block:
|
|||||||
process_stmt(entry, blk);
|
process_stmt(entry, blk);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto i = 0; i < stmt->list.size(); i++)
|
auto i = 0u;
|
||||||
|
|
||||||
|
while (i < stmt->list.size())
|
||||||
{
|
{
|
||||||
auto type = stmt->list.at(i).kind();
|
auto type = stmt->list.at(i).kind();
|
||||||
|
|
||||||
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
if (type == ast::kind::asm_create || type == ast::kind::asm_remove)
|
||||||
{
|
{
|
||||||
stmt->list.erase(stmt->list.begin() + i);
|
stmt->list.erase(stmt->list.begin() + i);
|
||||||
i--;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3178,7 +3182,7 @@ void decompiler::process_expr_binary(const ast::expr_binary::ptr& expr, const bl
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.as_node->kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3198,7 +3202,7 @@ void decompiler::process_expr_and(const ast::expr_and::ptr& expr, const block::p
|
|||||||
|
|
||||||
prec = expr->rvalue.as_node->precedence();
|
prec = expr->rvalue.as_node->precedence();
|
||||||
|
|
||||||
if (prec && prec < expr->precedence() || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
if ((prec && prec < expr->precedence()) || (prec == expr->precedence() && expr->kind() == expr->rvalue.kind()))
|
||||||
{
|
{
|
||||||
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
expr->rvalue = ast::expr(std::make_unique<ast::expr_paren>(std::move(expr->rvalue)));
|
||||||
}
|
}
|
||||||
@ -3354,7 +3358,7 @@ void decompiler::process_var_create(ast::expr& expr, const block::ptr& blk, bool
|
|||||||
|
|
||||||
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
void decompiler::process_var_access(ast::expr& expr, const block::ptr& blk)
|
||||||
{
|
{
|
||||||
if (blk->local_vars.size() <= std::stoi(expr.as_asm_access->index))
|
if (blk->local_vars.size() <= std::stoul(expr.as_asm_access->index))
|
||||||
{
|
{
|
||||||
printf("WARNING: bad local var access\n");
|
printf("WARNING: bad local var access\n");
|
||||||
}
|
}
|
||||||
|
@ -88,8 +88,10 @@ bool buffer::push(char c)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
reader::reader() : state(reader::end), buffer_pos(0),
|
reader::reader() : buffer_pos(0), bytes_remaining(0), last_byte(0), current_byte(0), state(reader::end)
|
||||||
bytes_remaining(0), last_byte(0), current_byte(0) {}
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void reader::init(const char* data, size_t size)
|
void reader::init(const char* data, size_t size)
|
||||||
{
|
{
|
||||||
@ -129,8 +131,8 @@ void reader::advance()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : indev_(false), clean_(true), loc_(location(&name)),
|
lexer::lexer(build mode, const std::string& name, const char* data, size_t size) : loc_(location(&name)),
|
||||||
mode_(mode), header_top_(0), locs_(std::stack<location>()), readers_(std::stack<reader>())
|
locs_(std::stack<location>()), readers_(std::stack<reader>()), header_top_(0), mode_(mode), indev_(false), clean_(true)
|
||||||
{
|
{
|
||||||
reader_.init(data, size);
|
reader_.init(data, size);
|
||||||
}
|
}
|
||||||
@ -482,7 +484,7 @@ auto lexer::lex() -> parser::symbol_type
|
|||||||
default:
|
default:
|
||||||
if (last >= '0' && last <= '9')
|
if (last >= '0' && last <= '9')
|
||||||
goto lex_number;
|
goto lex_number;
|
||||||
else if (last == '_' || last >= 'A' && last <= 'Z' || last >= 'a' && last <= 'z')
|
else if (last == '_' || (last >= 'A' && last <= 'Z') || (last >= 'a' && last <= 'z'))
|
||||||
goto lex_name;
|
goto lex_name;
|
||||||
|
|
||||||
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
throw comp_error(loc_, utils::string::va("bad token: \'%c\'", last));
|
||||||
@ -587,7 +589,7 @@ lex_name:
|
|||||||
{
|
{
|
||||||
if (buffer_.data[0] != '_')
|
if (buffer_.data[0] != '_')
|
||||||
{
|
{
|
||||||
for (auto i = 0; i < buffer_.length; i++)
|
for (auto i = 0u; i < buffer_.length; i++)
|
||||||
{
|
{
|
||||||
auto c = buffer_.data[i];
|
auto c = buffer_.data[i];
|
||||||
|
|
||||||
@ -656,7 +658,7 @@ lex_number:
|
|||||||
if (last == '\'')
|
if (last == '\'')
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot > 1 || flt > 1 || flt && buffer_.data[buffer_.length - 1] != 'f')
|
if (dot > 1 || flt > 1 || (flt && buffer_.data[buffer_.length - 1] != 'f'))
|
||||||
throw comp_error(loc_, "invalid number literal");
|
throw comp_error(loc_, "invalid number literal");
|
||||||
|
|
||||||
if (dot || flt)
|
if (dot || flt)
|
||||||
@ -673,7 +675,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'o') || (curr == 'o' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'o')) || (curr == 'o' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid octal literal");
|
throw comp_error(loc_, "invalid octal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -707,7 +709,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'b') || (curr == 'b' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'b')) || (curr == 'b' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid binary literal");
|
throw comp_error(loc_, "invalid binary literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
@ -741,7 +743,7 @@ lex_number:
|
|||||||
if (state == reader::end)
|
if (state == reader::end)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (curr == '\'' && (last == '\'' || last == 'x') || (curr == 'x' && last == '\''))
|
if ((curr == '\'' && (last == '\'' || last == 'x')) || (curr == 'x' && last == '\''))
|
||||||
throw comp_error(loc_, "invalid hexadecimal literal");
|
throw comp_error(loc_, "invalid hexadecimal literal");
|
||||||
|
|
||||||
if (curr == '\'')
|
if (curr == '\'')
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
int length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
@ -32,9 +32,14 @@ struct reader
|
|||||||
|
|
||||||
reader();
|
reader();
|
||||||
|
|
||||||
reader& operator=(const reader& r)
|
reader(const reader& obj)
|
||||||
{
|
{
|
||||||
std::memcpy(this, &r, sizeof(reader));
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
|
}
|
||||||
|
|
||||||
|
reader& operator=(const reader& obj)
|
||||||
|
{
|
||||||
|
std::memcpy(this, &obj, sizeof(reader));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ constexpr size_t max_buf_size = 0x2000;
|
|||||||
struct buffer
|
struct buffer
|
||||||
{
|
{
|
||||||
char* data;
|
char* data;
|
||||||
std::uint32_t length;
|
size_t length;
|
||||||
|
|
||||||
buffer();
|
buffer();
|
||||||
~buffer();
|
~buffer();
|
||||||
|
@ -448,11 +448,11 @@ stmt_dowhile::stmt_dowhile(const location& loc, expr test, ast::stmt stmt) : nod
|
|||||||
stmt_for::stmt_for(ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
stmt_for::stmt_for(ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
||||||
stmt_for::stmt_for(const location& loc, ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for, loc), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
stmt_for::stmt_for(const location& loc, ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for, loc), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
||||||
|
|
||||||
stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), stmt(std::move(stmt)), use_key(use_key), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(use_key) {}
|
||||||
stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {}
|
||||||
stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {}
|
||||||
stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {}
|
||||||
stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {}
|
||||||
|
|
||||||
stmt_switch::stmt_switch(expr test, stmt_list::ptr stmt) : node(kind::stmt_switch), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
stmt_switch::stmt_switch(expr test, stmt_list::ptr stmt) : node(kind::stmt_switch), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
||||||
stmt_switch::stmt_switch(const location& loc, expr test, stmt_list::ptr stmt) : node(kind::stmt_switch, loc), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
stmt_switch::stmt_switch(const location& loc, expr test, stmt_list::ptr stmt) : node(kind::stmt_switch, loc), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
||||||
@ -999,7 +999,7 @@ auto stmt_list::print() const -> std::string
|
|||||||
|
|
||||||
for (const auto& stmt : list)
|
for (const auto& stmt : list)
|
||||||
{
|
{
|
||||||
if ((&stmt != &list.front() && stmt.as_node->is_special_stmt() || last_special) && stmt != kind::stmt_dev && !last_devblock)
|
if (((&stmt != &list.front() && stmt.as_node->is_special_stmt()) || last_special) && stmt != kind::stmt_dev && !last_devblock)
|
||||||
data += "\n";
|
data += "\n";
|
||||||
|
|
||||||
if (stmt == kind::stmt_dev)
|
if (stmt == kind::stmt_dev)
|
||||||
@ -1041,7 +1041,7 @@ auto stmt_dev::print() const -> std::string
|
|||||||
|
|
||||||
for (const auto& stmt : list->list)
|
for (const auto& stmt : list->list)
|
||||||
{
|
{
|
||||||
if (&stmt != &list->list.front() && stmt.as_node->is_special_stmt() || last_special)
|
if ((&stmt != &list->list.front() && stmt.as_node->is_special_stmt()) || last_special)
|
||||||
data += "\n";
|
data += "\n";
|
||||||
|
|
||||||
data += stmts_pad + stmt.print();
|
data += stmts_pad + stmt.print();
|
||||||
|
@ -1836,8 +1836,8 @@ struct asm_jump_cond : public node
|
|||||||
{
|
{
|
||||||
using ptr = std::unique_ptr<asm_jump_cond>;
|
using ptr = std::unique_ptr<asm_jump_cond>;
|
||||||
|
|
||||||
std::string value;
|
|
||||||
ast::expr expr;
|
ast::expr expr;
|
||||||
|
std::string value;
|
||||||
|
|
||||||
asm_jump_cond(ast::expr expr, const std::string& value);
|
asm_jump_cond(ast::expr expr, const std::string& value);
|
||||||
asm_jump_cond(const location& loc, ast::expr expr, const std::string& value);
|
asm_jump_cond(const location& loc, ast::expr expr, const std::string& value);
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
namespace xsk::gsc
|
namespace xsk::gsc
|
||||||
{
|
{
|
||||||
|
|
||||||
block::block() : is_last(false), abort(abort_t::abort_none),
|
block::block() : local_vars_create_count(0), local_vars_public_count(0),
|
||||||
local_vars_create_count(0), local_vars_public_count(0) { }
|
abort(abort_t::abort_none), is_last(false) { }
|
||||||
|
|
||||||
void block::transfer(const block::ptr& child)
|
void block::transfer(const block::ptr& child)
|
||||||
{
|
{
|
||||||
@ -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));
|
child->local_vars.insert(child->local_vars.begin() + i, this->local_vars.at(i));
|
||||||
}
|
}
|
||||||
else if (pos > i)
|
else if (pos > static_cast<std::int32_t>(i))
|
||||||
{
|
{
|
||||||
auto& v = child->local_vars;
|
auto& v = child->local_vars;
|
||||||
std::rotate(v.rend() - pos - 1, v.rend() - pos, v.rend() - i);
|
std::rotate(v.rend() - pos - 1, v.rend() - pos, v.rend() - i);
|
||||||
|
@ -395,11 +395,11 @@ stmt_dowhile::stmt_dowhile(const location& loc, expr test, ast::stmt stmt) : nod
|
|||||||
stmt_for::stmt_for(ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
stmt_for::stmt_for(ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
||||||
stmt_for::stmt_for(const location& loc, ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for, loc), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
stmt_for::stmt_for(const location& loc, ast::stmt init, expr test, ast::stmt iter, ast::stmt stmt) : node(kind::stmt_for, loc), init(std::move(init)), test(std::move(test)), iter(std::move(iter)), stmt(std::move(stmt)), blk(nullptr), blk_iter(nullptr) {}
|
||||||
|
|
||||||
stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), stmt(std::move(stmt)), use_key(use_key), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(const location& loc, ast::stmt stmt, bool use_key) : node(kind::stmt_foreach, loc), array_expr(nullptr), value_expr(nullptr), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(use_key) {}
|
||||||
stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {}
|
||||||
stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {}
|
||||||
stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(false), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(const location& loc, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(nullptr), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(false) {}
|
||||||
stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), key_expr(std::move(key)), value_expr(std::move(element)), array_expr(std::move(container)), stmt(std::move(stmt)), use_key(true), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), ctx(nullptr), ctx_post(nullptr) {}
|
stmt_foreach::stmt_foreach(const location& loc, ast::expr key, ast::expr element, ast::expr container, ast::stmt stmt) : node(kind::stmt_foreach, loc), array_expr(std::move(container)), value_expr(std::move(element)), key_expr(std::move(key)), array(nullptr), pre_expr(nullptr), cond_expr(nullptr), post_expr(nullptr), stmt0(nullptr), stmt(std::move(stmt)), ctx(nullptr), ctx_post(nullptr), use_key(true) {}
|
||||||
|
|
||||||
stmt_switch::stmt_switch(expr test, stmt_list::ptr stmt) : node(kind::stmt_switch), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
stmt_switch::stmt_switch(expr test, stmt_list::ptr stmt) : node(kind::stmt_switch), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
||||||
stmt_switch::stmt_switch(const location& loc, expr test, stmt_list::ptr stmt) : node(kind::stmt_switch, loc), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
stmt_switch::stmt_switch(const location& loc, expr test, stmt_list::ptr stmt) : node(kind::stmt_switch, loc), test(std::move(test)), stmt(std::move(stmt)), ctx(nullptr) {}
|
||||||
@ -885,7 +885,7 @@ auto stmt_list::print() const -> std::string
|
|||||||
|
|
||||||
for (const auto& stmt : list)
|
for (const auto& stmt : list)
|
||||||
{
|
{
|
||||||
if (&stmt != &list.front() && stmt.as_node->is_special_stmt() || last_special)
|
if ((&stmt != &list.front() && stmt.as_node->is_special_stmt()) || last_special)
|
||||||
data += "\n";
|
data += "\n";
|
||||||
|
|
||||||
if (stmt == kind::stmt_dev)
|
if (stmt == kind::stmt_dev)
|
||||||
@ -921,7 +921,7 @@ auto stmt_dev::print() const -> std::string
|
|||||||
|
|
||||||
for (const auto& stmt : list->list)
|
for (const auto& stmt : list->list)
|
||||||
{
|
{
|
||||||
if (&stmt != &list->list.front() && stmt.as_node->is_special_stmt() || last_special)
|
if ((&stmt != &list->list.front() && stmt.as_node->is_special_stmt()) || last_special)
|
||||||
data += "\n";
|
data += "\n";
|
||||||
|
|
||||||
if (stmt == kind::stmt_dev)
|
if (stmt == kind::stmt_dev)
|
||||||
|
@ -1626,8 +1626,8 @@ struct asm_jump_cond : public node
|
|||||||
{
|
{
|
||||||
using ptr = std::unique_ptr<asm_jump_cond>;
|
using ptr = std::unique_ptr<asm_jump_cond>;
|
||||||
|
|
||||||
std::string value;
|
|
||||||
ast::expr expr;
|
ast::expr expr;
|
||||||
|
std::string value;
|
||||||
|
|
||||||
asm_jump_cond(ast::expr expr, const std::string& value);
|
asm_jump_cond(ast::expr expr, const std::string& value);
|
||||||
asm_jump_cond(const location& loc, ast::expr expr, const std::string& value);
|
asm_jump_cond(const location& loc, ast::expr expr, const std::string& value);
|
||||||
|
@ -245,7 +245,7 @@ auto string::float_string(float value) -> std::string
|
|||||||
|
|
||||||
auto flags = integer | (str[0] == '-' ? negative : none);
|
auto flags = integer | (str[0] == '-' ? negative : none);
|
||||||
|
|
||||||
for (auto i = 1; i < str.size(); i++)
|
for (auto i = 1u; i < str.size(); i++)
|
||||||
{
|
{
|
||||||
if (str[i] == '-') flags |= exp_neg;
|
if (str[i] == '-') flags |= exp_neg;
|
||||||
else if (str[i] == 'e') flags |= has_exp;
|
else if (str[i] == 'e') flags |= has_exp;
|
||||||
@ -261,7 +261,7 @@ auto string::float_string(float value) -> std::string
|
|||||||
|
|
||||||
if (flags & integer)
|
if (flags & integer)
|
||||||
{
|
{
|
||||||
auto i = (flags & negative) ? 1 : 0;
|
auto i = (flags & negative) ? 1u : 0u;
|
||||||
|
|
||||||
while (str[i] != 'e')
|
while (str[i] != 'e')
|
||||||
p_int.push_back(str[i++]);
|
p_int.push_back(str[i++]);
|
||||||
@ -288,7 +288,7 @@ auto string::float_string(float value) -> std::string
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto i = (flags & negative) ? 1 : 0;
|
auto i = (flags & negative) ? 1u : 0u;
|
||||||
|
|
||||||
while (str[i] != '.')
|
while (str[i] != '.')
|
||||||
p_int.push_back(str[i++]);
|
p_int.push_back(str[i++]);
|
||||||
|
Loading…
Reference in New Issue
Block a user