Skip to content

Commit

Permalink
refactor: cleanup structs (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
xensik authored Dec 21, 2024
1 parent ab72aa7 commit 45939b5
Show file tree
Hide file tree
Showing 62 changed files with 119 additions and 107 deletions.
2 changes: 1 addition & 1 deletion gen/arc/parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#pragma warning(disable:4127)
#endif
#include "context.hpp"
namespace xsk::arc { class preprocessor; }
namespace xsk::arc { struct preprocessor; }
}

%code top
Expand Down
2 changes: 1 addition & 1 deletion gen/gsc/parser.ypp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#pragma warning(disable:4127)
#endif
#include "context.hpp"
namespace xsk::gsc { class preprocessor; }
namespace xsk::gsc { struct preprocessor; }
}

%code top
Expand Down
7 changes: 4 additions & 3 deletions include/xsk/arc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
namespace xsk::arc
{

class assembler
struct assembler
{
private:
context const* ctx_;
function const* func_;
assembly const* assembly_;
Expand All @@ -26,7 +27,7 @@ class assembler
u32 devmap_count_;

public:
assembler(context const* ctx);
explicit assembler(context const* ctx);
auto assemble(assembly const& data, std::string const& name = {}) -> std::pair<buffer, buffer>;

private:
Expand All @@ -40,7 +41,7 @@ class assembler
auto process_function(function const& func) -> void;
auto process_instruction(instruction const& inst) -> void;
auto align_instruction(instruction& inst) -> void;
auto resolve_label(std::string const& name) -> usize;
auto resolve_label(std::string const& name) const -> usize;
auto resolve_string(std::string const& name) -> u16;
auto add_stringref(std::string const& str, string_type type, u32 ref) -> void;
auto add_importref(std::vector<std::string> const& data, u32 ref) -> void;
Expand Down
20 changes: 10 additions & 10 deletions include/xsk/arc/common/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@
namespace xsk::arc
{

class error : public std::runtime_error
struct error : public std::runtime_error
{
public:
error(std::string const& what);
explicit error(std::string const& what);
};

class asm_error : public std::runtime_error
struct asm_error : public std::runtime_error
{
public:
asm_error(std::string const& what);
explicit asm_error(std::string const& what);
};

class disasm_error : public std::runtime_error
struct disasm_error : public std::runtime_error
{
public:
disasm_error(std::string const& what);
explicit disasm_error(std::string const& what);
};

class ppr_error : public std::runtime_error
struct ppr_error : public std::runtime_error
{
public:
ppr_error(location const& loc, std::string const& what);
};

class comp_error : public std::runtime_error
struct comp_error : public std::runtime_error
{
public:
comp_error(location const& loc, std::string const& what);
};

class decomp_error : public std::runtime_error
struct decomp_error : public std::runtime_error
{
public:
decomp_error(std::string const& what);
explicit decomp_error(std::string const& what);
};

} // namespace xsk::arc
4 changes: 2 additions & 2 deletions include/xsk/arc/common/location.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace xsk::arc
{

class position
struct position
{
public:
typedef const std::string filename_type;
Expand Down Expand Up @@ -78,7 +78,7 @@ std::basic_ostream<T>& operator<<(std::basic_ostream<T> &ostr, const position &p
return ostr << pos.line << '.' << pos.column;
}

class location
struct location
{
public:
typedef position::filename_type filename_type;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/common/lookahead.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct lookahead

lookahead(char const* data, usize size);
auto advance() -> void;
auto ended() { return available == 0; };
auto ended() const { return available == 0; };
};

} // namespace xsk::arc
2 changes: 1 addition & 1 deletion include/xsk/arc/common/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,6 @@ struct locjmp
};

// fordward decl for modules ref
class context;
struct context;

} // namespace xsk::arc
5 changes: 3 additions & 2 deletions include/xsk/arc/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
namespace xsk::arc
{

class compiler
struct compiler
{
private:
context* ctx_;
assembly::ptr assembly_;
function::ptr function_;
Expand All @@ -28,7 +29,7 @@ class compiler
bool developer_thread_;

public:
compiler(context* ctx);
explicit compiler(context* ctx);
auto compile(program const& data) -> assembly::ptr;
auto compile(std::string const& file, std::vector<u8>& data) -> assembly::ptr;

Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace xsk::arc
{

class context
struct context
{
public:
using fs_callback = std::function<std::vector<u8>(std::string const&)>;
Expand Down
7 changes: 4 additions & 3 deletions include/xsk/arc/decompiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
namespace xsk::arc
{

class decompiler
struct decompiler
{
private:
context const* ctx_;
program::ptr program_;
decl_function::ptr func_;
Expand All @@ -28,7 +29,7 @@ class decompiler
bool retbool_;

public:
decompiler(context const* ctx);
explicit decompiler(context const* ctx);
auto decompile(assembly const& data) -> program::ptr;

private:
Expand All @@ -55,7 +56,7 @@ class decompiler
auto find_location_index(stmt_list const& stm, std::string const& loc) -> usize;
auto last_location_index(stmt_list const& stm, usize index) -> bool;
auto lvalues_match(stmt_expr const& stm1, stmt_expr const& stm2) -> bool;
auto resolve_label(std::string const& name) -> usize;
auto resolve_label(std::string const& name) const -> usize;
auto process_function(decl_function& func) -> void;
auto process_stmt(stmt& stm) -> void;
auto process_stmt_list(stmt_list& stm) -> void;
Expand Down
5 changes: 3 additions & 2 deletions include/xsk/arc/disassembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
namespace xsk::arc
{

class disassembler
struct disassembler
{
private:
context const* ctx_;
function::ptr func_;
assembly::ptr assembly_;
Expand All @@ -22,7 +23,7 @@ class disassembler
std::map<usize, animtree_ref::ptr> anim_refs_;

public:
disassembler(context const* ctx);
explicit disassembler(context const* ctx);
auto disassemble(buffer const& data) -> assembly::ptr;
auto disassemble(std::vector<u8> const& data) -> assembly::ptr;
auto disassemble(u8 const* data, usize data_size) -> assembly::ptr;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/jup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ constexpr usize code_count = 0;
constexpr usize hash_count = 0;
constexpr u64 header_magic = 0x38000A0D43534780;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t6_pc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace xsk::arc::t6::pc

constexpr u64 header_magic = 0x06000A0D43534780;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t6_ps3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace xsk::arc::t6::ps3

constexpr u64 header_magic = 0x804753430D0A0006;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t6_wiiu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace xsk::arc::t6::wiiu

constexpr u64 header_magic = 0x804753430D0A0006;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t6_xb2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace xsk::arc::t6::xb2

constexpr u64 header_magic = 0x804753430D0A0006;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t7.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ constexpr usize code_count = 16384;
constexpr usize hash_count = 178806;
constexpr u64 header_magic = 0x1C000A0D43534780;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t8.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ constexpr usize code_count = 0;
constexpr usize hash_count = 0;
constexpr u64 header_magic = 0x36000A0D43534780;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/engine/t9.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ constexpr usize code_count = 0;
constexpr usize hash_count = 0;
constexpr u64 header_magic = 0x38000A0D43534780;

class context : public arc::context
struct context : public arc::context
{
public:
context();
Expand Down
3 changes: 2 additions & 1 deletion include/xsk/arc/lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
namespace xsk::arc
{

class lexer
struct lexer
{
private:
context const* ctx_;
lookahead reader_;
location loc_;
Expand Down
2 changes: 1 addition & 1 deletion include/xsk/arc/parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#pragma warning(disable:4127)
#endif
#include "context.hpp"
namespace xsk::arc { class preprocessor; }
namespace xsk::arc { struct preprocessor; }

#line 58 "parser.hpp"

Expand Down
3 changes: 2 additions & 1 deletion include/xsk/arc/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
namespace xsk::arc
{

class preprocessor
struct preprocessor
{
private:
context* ctx_;
std::stack<lexer> lexer_;
std::vector<std::string> includes_;
Expand Down
5 changes: 3 additions & 2 deletions include/xsk/arc/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
namespace xsk::arc
{

class source
struct source
{
private:
context* ctx_;
std::vector<u8> buf_;
u32 indent_;

public:
source(context* ctx);
explicit source(context* ctx);
auto parse_assembly(buffer const& data) -> assembly::ptr;
auto parse_assembly(std::vector<u8> const& data) -> assembly::ptr;
auto parse_assembly(u8 const* data, usize size) -> assembly::ptr;
Expand Down
9 changes: 5 additions & 4 deletions include/xsk/gsc/assembler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
namespace xsk::gsc
{

class assembler
struct assembler
{
private:
context const* ctx_;
function const* func_;
assembly const* assembly_;
Expand All @@ -22,7 +23,7 @@ class assembler
u32 devmap_count_;

public:
assembler(context const* ctx);
explicit assembler(context const* ctx);
auto assemble(assembly const& data) -> std::tuple<buffer, buffer, buffer>;

private:
Expand All @@ -38,8 +39,8 @@ class assembler
auto assemble_switch(instruction const& inst) -> void;
auto assemble_switch_table(instruction const& inst) -> void;
auto assemble_offset(i32 offs) -> void;
auto resolve_function(std::string const& name) -> usize;
auto resolve_label(std::string const& name) -> usize;
auto resolve_function(std::string const& name) const -> usize;
auto resolve_label(std::string const& name) const -> usize;
auto encrypt_string(std::string const& str) -> std::string;
};

Expand Down
Loading

0 comments on commit 45939b5

Please sign in to comment.